diff options
Diffstat (limited to 'core/src/main/scala')
-rw-r--r-- | core/src/main/scala/forge/define/Applicative.scala | 2 | ||||
-rw-r--r-- | core/src/main/scala/forge/define/Target.scala | 12 | ||||
-rw-r--r-- | core/src/main/scala/forge/discover/Router.scala | 7 | ||||
-rw-r--r-- | core/src/main/scala/forge/eval/Evaluator.scala | 25 |
4 files changed, 27 insertions, 19 deletions
diff --git a/core/src/main/scala/forge/define/Applicative.scala b/core/src/main/scala/forge/define/Applicative.scala index 6a4d1d0c..dfa0cf84 100644 --- a/core/src/main/scala/forge/define/Applicative.scala +++ b/core/src/main/scala/forge/define/Applicative.scala @@ -7,7 +7,7 @@ import scala.collection.mutable import scala.reflect.macros.blackbox.Context object Applicative { - trait Applyable[T]{ + trait Applyable[+T]{ @compileTimeOnly("Target#apply() can only be used with a T{...} block") def apply(): T = ??? } diff --git a/core/src/main/scala/forge/define/Target.scala b/core/src/main/scala/forge/define/Target.scala index 98bd1b7c..753a63e8 100644 --- a/core/src/main/scala/forge/define/Target.scala +++ b/core/src/main/scala/forge/define/Target.scala @@ -9,7 +9,7 @@ import play.api.libs.json.{Format, Json} import scala.language.experimental.macros import scala.reflect.macros.blackbox.Context -abstract class Target[T] extends Target.Ops[T] with Applyable[T]{ +abstract class Target[+T] extends Target.Ops[T] with Applyable[T]{ /** * What other Targets does this Target depend on? */ @@ -27,8 +27,10 @@ abstract class Target[T] extends Target.Ops[T] with Applyable[T]{ def sideHash: Int = 0 } + object Target extends Applicative.Applyer[Target, Target]{ def underlying[A](v: Target[A]) = v + type Cacher = forge.define.Cacher[Target[_]] class Target0[T](t: T) extends Target[T]{ lazy val t0 = t @@ -46,7 +48,7 @@ object Target extends Applicative.Applyer[Target, Target]{ ) } - abstract class Ops[T]{ this: Target[T] => + abstract class Ops[+T]{ this: Target[T] => def map[V](f: T => V) = new Target.Mapped(this, f) def filter(f: T => Boolean) = this @@ -58,18 +60,18 @@ object Target extends Applicative.Applyer[Target, Target]{ def traverse[T](source: Seq[Target[T]]) = { new Traverse[T](source) } - class Traverse[T](val inputs: Seq[Target[T]]) extends Target[Seq[T]]{ + class Traverse[+T](val inputs: Seq[Target[T]]) extends Target[Seq[T]]{ def evaluate(args: Args) = { for (i <- 0 until args.length) yield args(i).asInstanceOf[T] } } - class Mapped[T, V](source: Target[T], f: T => V) extends Target[V]{ + class Mapped[+T, +V](source: Target[T], f: T => V) extends Target[V]{ def evaluate(args: Args) = f(args(0)) val inputs = List(source) } - class Zipped[T, V](source1: Target[T], source2: Target[V]) extends Target[(T, V)]{ + class Zipped[+T, +V](source1: Target[T], source2: Target[V]) extends Target[(T, V)]{ def evaluate(args: Args) = (args(0), args(1)) val inputs = List(source1, source2) } diff --git a/core/src/main/scala/forge/discover/Router.scala b/core/src/main/scala/forge/discover/Router.scala index 3d054e29..afb526c7 100644 --- a/core/src/main/scala/forge/discover/Router.scala +++ b/core/src/main/scala/forge/discover/Router.scala @@ -1,6 +1,7 @@ package forge.discover import ammonite.main.Compat +import forge.define.Target import sourcecode.Compat.Context import scala.annotation.StaticAnnotation @@ -56,8 +57,8 @@ object Router{ argSignatures: Seq[ArgSig[T]], doc: Option[String], varargs: Boolean, - invoke0: (T, Map[String, String], Seq[String]) => Result[Any]){ - def invoke(target: T, groupedArgs: Seq[(String, Option[String])]): Result[Any] = { + invoke0: (T, Map[String, String], Seq[String]) => Result[Target[Any]]){ + def invoke(target: T, groupedArgs: Seq[(String, Option[String])]): Result[Target[Any]] = { var remainingArgSignatures = argSignatures.toList @@ -375,7 +376,7 @@ class Router [C <: Context](val c: C) { forge.discover.Router.validate(Seq(..$readArgs)) match{ case forge.discover.Router.Result.Success(List(..$argNames)) => forge.discover.Router.Result.Success($arg.${meth.name.toTermName}(..$argNameCasts)) - case x => x + case x: forge.discover.Router.Result.Error => x } ) """ diff --git a/core/src/main/scala/forge/eval/Evaluator.scala b/core/src/main/scala/forge/eval/Evaluator.scala index 19cd3236..590b5534 100644 --- a/core/src/main/scala/forge/eval/Evaluator.scala +++ b/core/src/main/scala/forge/eval/Evaluator.scala @@ -48,13 +48,16 @@ class Evaluator(workspacePath: Path, externalInputs.toIterator.map(results).toVector.hashCode + group.toIterator.map(_.sideHash).toVector.hashCode() - val primeLabel = labeling(terminals.items(0)).segments - - - val targetDestPath = workspacePath / primeLabel - val metadataPath = targetDestPath / up / (targetDestPath.last + ".forge.json") + val (targetDestPath, metadataPath) = labeling.get(terminals.items(0)) match{ + case Some(labeling) => + val targetDestPath = workspacePath / labeling.segments + val metadataPath = targetDestPath / up / (targetDestPath.last + ".forge.json") + (targetDestPath, Some(metadataPath)) + case None => (null, None) + } val cached = for{ + metadataPath <- metadataPath json <- scala.util.Try(Json.parse(read.getInputStream(metadataPath))).toOption (cachedHash, terminalResults) <- Json.fromJson[(Int, Seq[JsValue])](json).asOpt if cachedHash == inputsHash @@ -71,11 +74,13 @@ class Evaluator(workspacePath: Path, case _ => val (newResults, newEvaluated, terminalResults) = evaluateGroup(group, results, targetDestPath) - write.over( - metadataPath, - Json.prettyPrint( - Json.toJson(inputsHash -> terminals.toList.map(terminalResults)) - ), + metadataPath.foreach( + write.over( + _, + Json.prettyPrint( + Json.toJson(inputsHash -> terminals.toList.map(terminalResults)) + ), + ) ) (newResults, newEvaluated) |