summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/scala/forge/Evaluator.scala9
-rw-r--r--src/test/scala/forge/ForgeTests.scala42
2 files changed, 43 insertions, 8 deletions
diff --git a/src/main/scala/forge/Evaluator.scala b/src/main/scala/forge/Evaluator.scala
index b0c8bf12..f341c9cb 100644
--- a/src/main/scala/forge/Evaluator.scala
+++ b/src/main/scala/forge/Evaluator.scala
@@ -9,7 +9,7 @@ import scala.collection.mutable
class Evaluator(workspacePath: jnio.Path,
enclosingBase: DefCtx){
- val resultCache = mutable.Map.empty[Target[_], (Int, Any)]
+ val resultCache = mutable.Map.empty[String, (Int, Any)]
def evaluate(targets: Seq[Target[_]]): Evaluator.Results = {
jnio.Files.createDirectories(workspacePath)
@@ -27,17 +27,20 @@ class Evaluator(workspacePath: jnio.Path,
)
deleteRec(targetDestPath)
targetDestPath
+
case None => jnio.Files.createTempDirectory(null)
}
val inputsHash = inputResults.hashCode
- resultCache.get(target) match{
+ target.defCtx.staticEnclosing.flatMap(resultCache.get) match{
case Some((hash, res)) if hash == inputsHash && !target.dirty =>
results(target) = res
case _ =>
evaluated.append(target)
val res = target.evaluate(new Args(inputResults, targetDestPath))
- resultCache(target) = (inputsHash, res)
+ for(label <- target.defCtx.staticEnclosing) {
+ resultCache(label) = (inputsHash, res)
+ }
results(target) = res
}
diff --git a/src/test/scala/forge/ForgeTests.scala b/src/test/scala/forge/ForgeTests.scala
index a869ae4a..07e753c6 100644
--- a/src/test/scala/forge/ForgeTests.scala
+++ b/src/test/scala/forge/ForgeTests.scala
@@ -15,13 +15,17 @@ object ForgeTests extends TestSuite{
val up = test()
val down = test(up)
}
+ object AnonTriple{
+ val up = test()
+ val down = test(test(up))
+ }
object Diamond{
val up = test()
val left = test(up)
val right = test(up)
val down = test(left, right)
}
- object AnonymousDiamond{
+ object AnonDiamond{
val up = test()
val down = test(test(up), test(up))
}
@@ -39,6 +43,10 @@ object ForgeTests extends TestSuite{
targets = Seq(Pair.down),
expected = Seq(Pair.up, Pair.down)
)
+ 'anonTriple - check(
+ targets = Seq(AnonTriple.down),
+ expected = Seq(AnonTriple.up, AnonTriple.down.inputs(0), AnonTriple.down)
+ )
'diamond - check(
targets = Seq(Diamond.down),
expected = Seq(Diamond.up, Diamond.left, Diamond.right, Diamond.down)
@@ -70,15 +78,39 @@ object ForgeTests extends TestSuite{
check(Seq(single), values = Seq(0), evaluated = Seq(single))
// Second time the value is already cached, so no evaluation needed
check(Seq(single), values = Seq(0), evaluated = Seq())
- Singleton.single.counter += 1
+ single.counter += 1
// After incrementing the counter, it forces re-evaluation
check(Seq(single), values = Seq(1), evaluated = Seq(single))
// Then it's cached again
check(Seq(single), values = Seq(1), evaluated = Seq())
}
-// 'pair - {
-//
-// }
+ 'pair - {
+ import Pair._
+ check(Seq(down), values = Seq(0), evaluated = Seq(up, down))
+ check(Seq(down), values = Seq(0), evaluated = Seq())
+
+ down.counter += 1
+ check(Seq(down), values = Seq(1), evaluated = Seq(down))
+ check(Seq(down), values = Seq(1), evaluated = Seq())
+
+ up.counter += 1
+ check(Seq(down), values = Seq(2), evaluated = Seq(up, down))
+ check(Seq(down), values = Seq(2), evaluated = Seq())
+ }
+ 'anonTriple - {
+ import AnonTriple._
+ val middle = down.inputs(0)
+ check(Seq(down), values = Seq(0), evaluated = Seq(up, middle, down))
+ check(Seq(down), values = Seq(0), evaluated = Seq())
+
+ down.counter += 1
+ check(Seq(down), values = Seq(1), evaluated = Seq(middle, down))
+ check(Seq(down), values = Seq(1), evaluated = Seq())
+
+ up.counter += 1
+ check(Seq(down), values = Seq(2), evaluated = Seq(up, middle, down))
+ check(Seq(down), values = Seq(2), evaluated = Seq())
+ }
}
}