Skip to content

Commit 88c0826

Browse files
committed
wip
1 parent 833fadb commit 88c0826

File tree

5 files changed

+37
-5
lines changed

5 files changed

+37
-5
lines changed

compiler/src/dotty/tools/dotc/quoted/QuoteCompiler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class QuoteCompiler extends Compiler {
3737
new ExprRun(this, ctx.addMode(Mode.ReadPositions))
3838
}
3939

40-
def outputClassName: TypeName = "Quoted".toTypeName
40+
def outputClassName: TypeName = "$Quoted$".toTypeName
4141

4242
/** Frontend that receives a scala.quoted.Expr or scala.quoted.Type as input */
4343
class QuotedFrontend(putInClass: Boolean) extends Phase {

compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,17 @@ class QuoteDriver extends Driver {
2626
new VirtualDirectory("<quote compilation output>")
2727
}
2828

29+
println("ToolboxImpl")
30+
settings.compilerArgs.foreach(println)
31+
2932
val (_, ctx0: Context) = setup(settings.compilerArgs.toArray :+ "dummy.scala", initCtx.fresh)
3033
val ctx = setToolboxSettings(ctx0.fresh.setSetting(ctx0.settings.outputDir, outDir), settings)
3134

3235
val driver = new QuoteCompiler
3336
driver.newRun(ctx).compileExpr(expr)
3437

38+
assert(!ctx.reporter.hasErrors)
39+
3540
val classLoader = new AbstractFileClassLoader(outDir, this.getClass.getClassLoader)
3641

3742
val clazz = classLoader.loadClass(driver.outputClassName.toString)

library/src/scala/quoted/Toolbox.scala

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,25 @@ object Toolbox {
1515
implicit def make(implicit settings: Settings): Toolbox = Toolbox.make
1616
}
1717

18+
def make2(cl: ClassLoader)(implicit settings: Settings): Toolbox = {
19+
try {
20+
val toolboxImplCls = cl.loadClass("dotty.tools.dotc.quoted.ToolboxImpl")
21+
val makeMeth = toolboxImplCls.getMethod("make", classOf[Settings])
22+
makeMeth.invoke(null, settings).asInstanceOf[Toolbox]
23+
}
24+
catch {
25+
case ex: ClassNotFoundException =>
26+
throw new ToolboxNotFoundException(
27+
s"""Could not load the Toolbox class `${ex.getMessage}` from the JVM classpath. Make sure that the compiler is on the JVM classpath.""",
28+
ex
29+
)
30+
}
31+
}
32+
1833
def make(implicit settings: Settings): Toolbox = {
1934
val cl = getClass.getClassLoader
20-
println(">>>>>")
35+
println("Toolbox CL")
36+
println(cl.asInstanceOf[java.net.URLClassLoader])
2137
cl.asInstanceOf[java.net.URLClassLoader].getURLs().toList.foreach(println)
2238

2339
try {

sbt-dotty/sbt-test/sbt-dotty/quoted-example-project/src/main/scala/hello/Hello.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ import scala.quoted._
66
object Main {
77

88
// Needed to run or show quotes
9-
implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make
9+
val cl = getClass.getClassLoader
10+
println("BEFORE")
11+
println(cl.asInstanceOf[java.net.URLClassLoader])
12+
cl.asInstanceOf[java.net.URLClassLoader].getURLs().toList.foreach(println)
13+
14+
implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make2(cl)
1015

1116
def main(args: Array[String]): Unit = {
1217
val square = stagedPower(2)
@@ -27,7 +32,7 @@ object Main {
2732
val code = '{ (x: Double) => ${powerCode(n, '{x})}}
2833

2934
println(s"staged power for n=" + n + ":")
30-
println(code.show)
35+
// println(code.show)
3136

3237
// Evaluate the contents of the code and return it's value
3338
code.run

sbt-dotty/src/dotty/tools/sbtplugin/DottyPlugin.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,14 @@ object DottyPlugin extends AutoPlugin {
374374
def makeScalaInstance(
375375
state: State, dottyVersion: String, scalaLibrary: File, dottyLibrary: File, compiler: File, all: Seq[File]
376376
): ScalaInstance = {
377+
println("all")
378+
all.foreach(println)
377379
val loader = state.classLoaderCache(all.toList)
378-
val loaderLibraryOnly = state.classLoaderCache(List(dottyLibrary, scalaLibrary))
380+
println("DottyPlugin: " + loader)
381+
val dottyInterfaces = all.find(a => a.toString.contains("dotty-interfaces")).get
382+
val loaderLibraryOnly = state.classLoaderCache(List(compiler, dottyInterfaces, dottyLibrary, scalaLibrary))
383+
println("DottyPlugin lib: " + loaderLibraryOnly)
384+
379385
new ScalaInstance(
380386
dottyVersion,
381387
loader,

0 commit comments

Comments
 (0)