Skip to content

Commit

Permalink
add dotty compiler class
Browse files Browse the repository at this point in the history
  • Loading branch information
Marek Żarnowski committed Mar 7, 2019
1 parent ae2eb54 commit df342cd
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
2 changes: 2 additions & 0 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -845,10 +845,12 @@ object Build {

val scalacClasspath = toClasspath(scalaLibrary, scalaCompiler, scalaReflect)
val pluginClasspath = toClasspath(pluginJar, dottyLibrary, dottyCompiler, dottyInterfaces)
val dottyClasspath = toClasspath(scalaLibrary, dottyLibrary, dottyCompiler, dottyInterfaces)

Seq(
"-Dscalac.classpath=" + scalacClasspath,
"-Dscalac.plugin.classpath=" + pluginClasspath,
"-Ddotty.classpath=" + dottyClasspath,
"-Dtest.root.directory=" + (baseDirectory.value / "test-resources")
)
}
Expand Down
1 change: 1 addition & 0 deletions tasty4scalac/integration/src/tasty4scalac/Compiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ trait Compiler {
}

object Compiler {
def dotty(): Compiler = Dotty()
def scalac(): Compiler = Scalac()

trait Factory {
Expand Down
28 changes: 28 additions & 0 deletions tasty4scalac/integration/src/tasty4scalac/Dotty.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package tasty4scalac

import dotty.tools.dotc.core.Comments.{ContextDoc, ContextDocstrings}
import dotty.tools.dotc.core.Contexts
import dotty.tools.dotc.core.Contexts.ContextBase
import dotty.tools.dotc.reporting.Reporter.NoReporter
import dotty.tools.io.VirtualDirectory
import tasty4scalac.Compiler.Factory

final class Dotty(val ctx: Contexts.Context) extends dotty.tools.dotc.Compiler with Compiler {
override def compile(code: String): Unit = newRun(ctx.fresh).compile(code)
}

object Dotty extends Factory {
private val classpath = System.getProperty("dotty.classpath")

override def apply(): Compiler = {
implicit val ctx: Contexts.FreshContext = new ContextBase().initialCtx.fresh
ctx.setSetting(ctx.settings.classpath, classpath)
ctx.setSetting(ctx.settings.YtestPickler, true)
ctx.setSetting(ctx.settings.encoding, "UTF8")
ctx.setSetting(ctx.settings.outputDir, new VirtualDirectory("<quote compilation output>"))

ctx.setReporter(NoReporter)
ctx.setProperty(ContextDoc, new ContextDocstrings)
new Dotty(ctx)
}
}
3 changes: 2 additions & 1 deletion tasty4scalac/integration/test/tasty4scalac/CompilerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public CompilerTest(Compiler factory) {
@Parameterized.Parameters(name = "{index}: {0}")
public static Collection<Compiler[]> parameters() {
return Arrays.asList(new Compiler[][]{
{Scalac$.MODULE$.apply()}
{Scalac$.MODULE$.apply()},
{Dotty$.MODULE$.apply()}
});
}

Expand Down

0 comments on commit df342cd

Please sign in to comment.