diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2017-10-17 06:03:36 -0700 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2017-10-17 06:11:28 -0700 |
commit | aa5eb186c044e0c00d512e0c009e9d519a753e0c (patch) | |
tree | c4d28c2132c303578b3038deac1b36752520b5ed /src/main/scala/hbt/Main.scala | |
parent | def1d68ebacc38cc93f4de83f5ed08ee6014d806 (diff) | |
download | mill-aa5eb186c044e0c00d512e0c009e9d519a753e0c.tar.gz mill-aa5eb186c044e0c00d512e0c009e9d519a753e0c.tar.bz2 mill-aa5eb186c044e0c00d512e0c009e9d519a753e0c.zip |
Include Tarjan's algorithm, for doing a topological sort which elegantly handles cycles
Diffstat (limited to 'src/main/scala/hbt/Main.scala')
-rw-r--r-- | src/main/scala/hbt/Main.scala | 57 |
1 files changed, 44 insertions, 13 deletions
diff --git a/src/main/scala/hbt/Main.scala b/src/main/scala/hbt/Main.scala index fb86cecf..b4b5757c 100644 --- a/src/main/scala/hbt/Main.scala +++ b/src/main/scala/hbt/Main.scala @@ -6,8 +6,18 @@ import java.nio.{file => jnio} import java.util.jar.JarEntry import sourcecode.Enclosing +class Args(val args: IndexedSeq[_]){ + def length = args.length + def apply[T](index: Int): T = { + if (index >= 0 && index < args.length) args(index).asInstanceOf[T] + else throw new IndexOutOfBoundsException(s"Index $index outside of range 0 - ${args.length}") + } +} sealed trait Target[T]{ - def label: String + val label: String + def evaluate(args: Args): T + val inputs: Seq[Target[_]] + def map[V](f: T => V)(implicit path: Enclosing) = { Target.Mapped(this, f, path.value) } @@ -25,21 +35,36 @@ object Target{ def traverse[T](source: Seq[Target[T]])(implicit path: Enclosing) = { Traverse(source, path.value) } - case class Traverse[T](source: Seq[Target[T]], label: String) extends Target[Seq[T]] + case class Traverse[T](inputs: Seq[Target[T]], label: String) extends Target[Seq[T]]{ + def evaluate(args: Args) = { + for (i <- 0 until args.length) + yield args(i) + } + + } case class Mapped[T, V](source: Target[T], f: T => V, - label: String) extends Target[V] - case class Zipped[T, V](source: Target[T], + label: String) extends Target[V]{ + def evaluate(args: Args) = f(args(0)) + val inputs = List(source) + } + case class Zipped[T, V](source1: Target[T], source2: Target[V], - label: String) extends Target[(T, V)] - case class Path(path: jnio.Path, label: String) extends Target[jnio.Path] - case class Command(inputs: Seq[Target[jnio.Path]], - output: Seq[Target[jnio.Path]], - label: String) extends Target[Command.Result] - object Command{ - case class Result(stdout: String, - stderr: String, - writtenFiles: Seq[jnio.Path]) + label: String) extends Target[(T, V)]{ + def evaluate(args: Args) = (args(0), args(0)) + val inputs = List(source1, source1) + } + case class Path(path: jnio.Path, label: String) extends Target[jnio.Path]{ + def evaluate(args: Args) = path + val inputs = Nil } +// case class Command(inputs: Seq[Target[jnio.Path]], +// output: Seq[Target[jnio.Path]], +// label: String) extends Target[Command.Result] +// object Command{ +// case class Result(stdout: String, +// stderr: String, +// writtenFiles: Seq[jnio.Path]) +// } } object Main{ def compileAll(sources: Target[Seq[jnio.Path]]) @@ -87,4 +112,10 @@ object Main{ val classFiles = compileAll(allSources) val jar = jarUp(resourceRoot, classFiles) } + + def evaluateTargetGraph[T](t: Target[T]): T = { + ??? +// val evaluated = collection.mutable.Map.empty[Target[_], Any] +// val forwardEdges + } }
\ No newline at end of file |