summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build.sbt33
-rw-r--r--src/main/scala/forge/Implicits.scala71
-rw-r--r--src/main/scala/forge/Target.scala4
-rw-r--r--src/test/scala/forge/Main.scala16
-rw-r--r--src/test/scala/forge/TestMain.scala100
5 files changed, 102 insertions, 122 deletions
diff --git a/build.sbt b/build.sbt
index 469308c7..93175419 100644
--- a/build.sbt
+++ b/build.sbt
@@ -16,39 +16,10 @@ libraryDependencies ++= Seq(
"com.lihaoyi" %% "sourcecode" % "0.1.4",
"com.lihaoyi" %% "pprint" % "0.5.3",
"com.lihaoyi" % "ammonite" % "1.0.3" cross CrossVersion.full,
- "com.typesafe.play" %% "play-json" % "2.6.6"
+ "com.typesafe.play" %% "play-json" % "2.6.6",
+ "org.scala-sbt" %% "zinc" % "1.0.3"
)
-sourceGenerators in Compile += Def.task {
- val dir = (sourceManaged in Compile).value
- val file = dir/"fasterparser"/"SequencerGen.scala"
- // Only go up to 21, because adding the last element makes it 22
- val tuples = (2 to 21).map{ i =>
- val ts = (1 to i) map ("T" + _)
- val chunks = (1 to i) map { n =>
- s"t._$n"
- }
- val tsD = (ts :+ "D").mkString(",")
- s"""
- implicit def Sequencer$i[$tsD]: Sequencer[(${ts.mkString(", ")}), D, ($tsD)] =
- Sequencer0((t, d) => (${chunks.mkString(", ")}, d))
- """
- }
- val output = s"""
- package forge
- trait SequencerGen[Sequencer[_, _, _]] extends LowestPriSequencer[Sequencer]{
- protected[this] def Sequencer0[A, B, C](f: (A, B) => C): Sequencer[A, B, C]
- ${tuples.mkString("\n")}
- }
- trait LowestPriSequencer[Sequencer[_, _, _]]{
- protected[this] def Sequencer0[A, B, C](f: (A, B) => C): Sequencer[A, B, C]
- implicit def Sequencer1[T1, T2]: Sequencer[T1, T2, (T1, T2)] = Sequencer0{case (t1, t2) => (t1, t2)}
- }
- """.stripMargin
- IO.write(file, output)
- Seq(file)
-}
-
test in assembly := {}
assemblyOption in assembly := (assemblyOption in assembly).value.copy(
diff --git a/src/main/scala/forge/Implicits.scala b/src/main/scala/forge/Implicits.scala
deleted file mode 100644
index 3295ce38..00000000
--- a/src/main/scala/forge/Implicits.scala
+++ /dev/null
@@ -1,71 +0,0 @@
-package forge
-
-
-import scala.collection.mutable
-
-/**
- * Container for all the type-level logic around appending things
- * to tuples or flattening `Seq[Unit]`s into `Unit`s.
- *
- * Some of these implicits make liberal use of mutable state, so as
- * to minimize allocations while parsing.
- */
-object Implicits {
- trait Sequencer[-T, V, R]{
- def apply(t: T, v: V): R
- }
- object Sequencer extends LowPriSequencer{
- def apply[T, V, R](f: (T, V) => R) = new Sequencer[T, V, R]{
- def apply(t: T, v: V): R = f(t, v)
- }
- implicit def SingleSequencer[T]: Sequencer[Unit, T, T] = Sequencer( (_, t) => t )
- }
- trait LowPriSequencer extends LowerPriSequencer{
- implicit def UnitSequencer[T]: Sequencer[T, Unit, T] = Sequencer( (t, _) => t )
- }
- trait LowerPriSequencer extends SequencerGen[Sequencer]{
- protected[this] def Sequencer0[A, B, C](f: (A, B) => C) = Sequencer(f)
- }
- trait Repeater[-T, R]{
- type Acc
- def initial: Acc
- def accumulate(t: T, acc: Acc): Unit
- def result(acc: Acc): R
- }
- object Repeater extends LowPriRepeater{
- implicit object UnitRepeater extends Repeater[Unit, Unit]{
- type Acc = Unit
- def initial = ()
- def accumulate(t: Unit, acc: Unit) = acc
- def result(acc: Unit) = ()
- }
- }
- trait LowPriRepeater{
- implicit def GenericRepeaterImplicit[T] = GenericRepeater[T]()
- case class GenericRepeater[T]() extends Repeater[T, Seq[T]]{
- type Acc = mutable.Buffer[T]
- def initial = mutable.Buffer.empty[T]
- def accumulate(t: T, acc: mutable.Buffer[T]) = acc += t
- def result(acc: mutable.Buffer[T]) = acc
- }
- }
-
- trait Optioner[-T, R]{
- def none: R
- def some(value: T): R
- }
-
- object Optioner extends LowPriOptioner{
- implicit object UnitOptioner extends Optioner[Unit, Unit]{
- def none = ()
- def some(value: Unit) = ()
- }
- }
- trait LowPriOptioner{
- implicit def GenericOptionerImplicit[T] = GenericOptioner[T]()
- case class GenericOptioner[T]() extends Optioner[T, Option[T]]{
- def none = None
- def some(value: T) = Some(value)
- }
- }
-} \ No newline at end of file
diff --git a/src/main/scala/forge/Target.scala b/src/main/scala/forge/Target.scala
index 9dd3f8ab..c6908d1d 100644
--- a/src/main/scala/forge/Target.scala
+++ b/src/main/scala/forge/Target.scala
@@ -36,10 +36,6 @@ object Target{
def zip[V: Format](other: Target[V]) = {
new Target.Zipped(this, other)
}
- def ~[V: Format, R: Format](other: Target[V])
- (implicit s: Implicits.Sequencer[T, V, R]): Target[R] = {
- this.zip(other).map(s.apply _ tupled)
- }
}
def test(inputs: Target[Int]*) = {
new Test(inputs, pure = inputs.nonEmpty)
diff --git a/src/test/scala/forge/Main.scala b/src/test/scala/forge/Main.scala
deleted file mode 100644
index 51aaa3bd..00000000
--- a/src/test/scala/forge/Main.scala
+++ /dev/null
@@ -1,16 +0,0 @@
-package forge
-import java.io.FileOutputStream
-import java.util.jar.JarEntry
-
-import collection.JavaConverters._
-import ammonite.ops._
-import forge.util.{Args, OSet, PathRef}
-object Main{
-
-
- def main(args: Array[String]): Unit = {
-
- }
-
-
-}
diff --git a/src/test/scala/forge/TestMain.scala b/src/test/scala/forge/TestMain.scala
new file mode 100644
index 00000000..c94e13f0
--- /dev/null
+++ b/src/test/scala/forge/TestMain.scala
@@ -0,0 +1,100 @@
+package forge
+import ammonite.ops._
+import java.io.File
+
+import coursier._
+import sbt.internal.inc.{FreshCompilerCache, ScalaInstance, ZincUtil}
+import sbt.internal.util.{ConsoleOut, MainAppender}
+import sbt.util.LogExchange
+import xsbti.api.{ClassLike, DependencyContext}
+import xsbti.compile._
+
+import scalaz.concurrent.Task
+
+object TestMain {
+ def main(args: Array[String]): Unit = {
+ val scalaVersion = "2.12.4"
+ val start = Resolution(
+ Set(
+ Dependency(Module("org.scala-lang", "scala-reflect"), scalaVersion),
+ Dependency(Module("org.scala-lang", "scala-compiler"), scalaVersion),
+ Dependency(Module("org.scala-lang", "scala-reflect"), scalaVersion),
+ Dependency(Module("org.scala-sbt", "compiler-bridge_2.12"), "1.0.3"),
+ Dependency(Module("com.lihaoyi", "sourcecode_2.12"), "0.1.4"),
+ Dependency(Module("com.lihaoyi", "pprint_2.12"), "0.5.3"),
+ Dependency(Module("com.lihaoyi", "ammonite_2.12.4"), "1.0.3"),
+ Dependency(Module("com.typesafe.play", "play-json_2.12"), "2.6.6"),
+ Dependency(Module("org.scala-sbt", "zinc_2.12"), "1.0.3")
+ )
+ )
+ val repositories = Seq(
+ Cache.ivy2Local,
+ MavenRepository("https://repo1.maven.org/maven2")
+ )
+
+ val fetch = Fetch.from(repositories, Cache.fetch())
+ val resolution = start.process.run(fetch).unsafePerformSync
+
+
+ val localArtifacts: Seq[File] = Task.gatherUnordered(
+ resolution.artifacts.map(Cache.file(_).run)
+ ).unsafePerformSync.flatMap(_.toOption)
+
+ pprint.log(localArtifacts)
+ def grepJar(s: String) = localArtifacts.find(_.toString.endsWith(s)).get
+
+ val scalac = ZincUtil.scalaCompiler(
+ new ScalaInstance(
+ version = scalaVersion,
+ loader = getClass.getClassLoader,
+ libraryJar = grepJar(s"scala-library-$scalaVersion.jar"),
+ compilerJar = grepJar(s"scala-compiler-$scalaVersion.jar"),
+ allJars = localArtifacts.toArray,
+ explicitActual = None
+ ),
+ grepJar("compiler-bridge_2.12-1.0.3.jar")
+ )
+
+ val outputDir = pwd/'target/'zinc
+ mkdir(outputDir)
+ val scalaFiles = ls.rec(pwd/'src/'main/'scala/'forge).filter(_.ext == "scala").map(_.toIO).toArray
+
+ pprint.log(scalaFiles)
+ scalac.apply(
+ sources = scalaFiles,
+ changes = new DependencyChanges {
+ def isEmpty = true
+ def modifiedBinaries() = Array[File]()
+ def modifiedClasses() = Array[String]()
+ },
+ classpath = localArtifacts.toArray,
+ singleOutput = outputDir.toIO,
+ options = Array(),
+ callback = new xsbti.AnalysisCallback {
+ def startSource(source: File) = ()
+ def apiPhaseCompleted() = ()
+ def enabled() = true
+ def binaryDependency(onBinaryEntry: File, onBinaryClassName: String, fromClassName: String, fromSourceFile: File, context: DependencyContext) = ()
+ def generatedNonLocalClass(source: File, classFile: File, binaryClassName: String, srcClassName: String) = ()
+ def problem(what: String, pos: xsbti.Position, msg: String, severity: xsbti.Severity, reported: Boolean) = ()
+ def dependencyPhaseCompleted() = ()
+ def classDependency(onClassName: String, sourceClassName: String, context: DependencyContext) = ()
+ def generatedLocalClass(source: File, classFile: File) = ()
+ def api(sourceFile: File, classApi: ClassLike) = ()
+
+ def mainClass(sourceFile: File, className: String) = ()
+ def usedName(className: String, name: String, useScopes: java.util.EnumSet[xsbti.UseScope]) = ()
+ },
+ maximumErrors = 10,
+ cache = new FreshCompilerCache(),
+ log = {
+ val console = ConsoleOut.systemOut
+ val consoleAppender = MainAppender.defaultScreen(console)
+ val l = LogExchange.logger("Hello")
+ LogExchange.unbindLoggerAppenders("Hello")
+ LogExchange.bindLoggerAppenders("Hello", (consoleAppender -> sbt.util.Level.Warn) :: Nil)
+ l
+ }
+ )
+ }
+}