From 46ad05fe0bbb23ab77013f27d68926d2daed3f2b Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sun, 14 Feb 2016 10:39:58 +0100 Subject: newCompiler now takes a context parameter Makes side-effecting initialization of interpreter unnecessary. --- src/dotty/tools/dotc/Bench.scala | 2 +- src/dotty/tools/dotc/Driver.scala | 4 ++-- src/dotty/tools/dotc/FromTasty.scala | 2 +- src/dotty/tools/dotc/Main.scala | 3 +-- src/dotty/tools/dotc/REPL.scala | 2 +- src/dotty/tools/dotc/Resident.scala | 2 +- src/dotty/tools/dotc/repl/Interpreter.scala | 17 ++++++----------- src/dotty/tools/dotc/repl/InterpreterLoop.scala | 1 - 8 files changed, 13 insertions(+), 20 deletions(-) (limited to 'src/dotty/tools') diff --git a/src/dotty/tools/dotc/Bench.scala b/src/dotty/tools/dotc/Bench.scala index 47b5fd6dd..2fc38d78c 100644 --- a/src/dotty/tools/dotc/Bench.scala +++ b/src/dotty/tools/dotc/Bench.scala @@ -12,7 +12,7 @@ object Bench extends Driver { @sharable private var numRuns = 1 - def newCompiler(): Compiler = new Compiler + def newCompiler(implicit ctx: Context): Compiler = new Compiler private def ntimes(n: Int)(op: => Reporter): Reporter = (emptyReporter /: (0 until n)) ((_, _) => op) diff --git a/src/dotty/tools/dotc/Driver.scala b/src/dotty/tools/dotc/Driver.scala index 7f22fc774..3437b86fc 100644 --- a/src/dotty/tools/dotc/Driver.scala +++ b/src/dotty/tools/dotc/Driver.scala @@ -10,7 +10,7 @@ abstract class Driver extends DotClass { val prompt = "\ndotc> " - protected def newCompiler(): Compiler + protected def newCompiler(implicit ctx: Context): Compiler protected def emptyReporter: Reporter = new StoreReporter(null) @@ -90,7 +90,7 @@ abstract class Driver extends DotClass { */ def process(args: Array[String], rootCtx: Context): Reporter = { val (fileNames, ctx) = setup(args, rootCtx) - doCompile(newCompiler(), fileNames)(ctx) + doCompile(newCompiler(ctx), fileNames)(ctx) } def main(args: Array[String]): Unit = { diff --git a/src/dotty/tools/dotc/FromTasty.scala b/src/dotty/tools/dotc/FromTasty.scala index d8d8b8b1e..8f29c882c 100644 --- a/src/dotty/tools/dotc/FromTasty.scala +++ b/src/dotty/tools/dotc/FromTasty.scala @@ -30,7 +30,7 @@ import ast.tpd._ * scala dotty.tools.dotc.FromTasty -Xprint:front extMethods.T */ object FromTasty extends Driver { - override def newCompiler(): Compiler = new TASTYCompiler + override def newCompiler(implicit ctx: Context): Compiler = new TASTYCompiler class TASTYCompiler extends Compiler { diff --git a/src/dotty/tools/dotc/Main.scala b/src/dotty/tools/dotc/Main.scala index 699a57234..6c473d8bb 100644 --- a/src/dotty/tools/dotc/Main.scala +++ b/src/dotty/tools/dotc/Main.scala @@ -2,10 +2,9 @@ package dotty.tools package dotc import core.Contexts.Context -import reporting.Reporter /* To do: */ object Main extends Driver { - override def newCompiler(): Compiler = new Compiler + override def newCompiler(implicit ctx: Context): Compiler = new Compiler } diff --git a/src/dotty/tools/dotc/REPL.scala b/src/dotty/tools/dotc/REPL.scala index a0255efa6..fdc8f690d 100644 --- a/src/dotty/tools/dotc/REPL.scala +++ b/src/dotty/tools/dotc/REPL.scala @@ -36,7 +36,7 @@ class REPL extends Driver { def output: PrintWriter = new NewLinePrintWriter(new ConsoleWriter, true) - override def newCompiler(): Compiler = new repl.Interpreter(output) + override def newCompiler(implicit ctx: Context): Compiler = new repl.Interpreter(output, ctx) override def sourcesRequired = false diff --git a/src/dotty/tools/dotc/Resident.scala b/src/dotty/tools/dotc/Resident.scala index 3ae369f27..18bb2ff4f 100644 --- a/src/dotty/tools/dotc/Resident.scala +++ b/src/dotty/tools/dotc/Resident.scala @@ -25,7 +25,7 @@ class Resident extends Driver { object residentCompiler extends Compiler - override def newCompiler(): Compiler = ??? + override def newCompiler(implicit ctx: Context): Compiler = ??? override def sourcesRequired = false diff --git a/src/dotty/tools/dotc/repl/Interpreter.scala b/src/dotty/tools/dotc/repl/Interpreter.scala index b9853e18b..bac912d33 100644 --- a/src/dotty/tools/dotc/repl/Interpreter.scala +++ b/src/dotty/tools/dotc/repl/Interpreter.scala @@ -62,7 +62,7 @@ import Interpreter._ * @author Moez A. Abdel-Gawad * @author Lex Spoon */ -class Interpreter(out: PrintWriter) extends Compiler { +class Interpreter(out: PrintWriter, ictx: Context) extends Compiler { import ast.untpd._ import Interpreter._ @@ -110,7 +110,7 @@ class Interpreter(out: PrintWriter) extends Compiler { private val prevRequests = new ArrayBuffer[Request]() /** the compiler's classpath, as URL's */ - var compilerClasspath: List[URL] = _ + val compilerClasspath: List[URL] = ictx.platform.classPath(ictx).asURLs /* A single class loader is used for all commands interpreted by this Interpreter. It would also be possible to create a new class loader for each command @@ -126,18 +126,13 @@ class Interpreter(out: PrintWriter) extends Compiler { definitions. */ /** class loader used to load compiled code */ - var classLoader: ClassLoader = _ + val classLoader: ClassLoader = { + val parent = new URLClassLoader(compilerClasspath.toArray, parentClassLoader) + new AbstractFileClassLoader(virtualDirectory, parent) + } protected def parentClassLoader: ClassLoader = classOf[Interpreter].getClassLoader - def init()(implicit ctx: Context) = { - compilerClasspath = ctx.platform.classPath.asURLs - classLoader = { - val parent = new URLClassLoader(compilerClasspath.toArray, parentClassLoader) - new AbstractFileClassLoader(virtualDirectory, parent) - } - } - /** Set the current Java "context" class loader to this * interpreter's class loader */ diff --git a/src/dotty/tools/dotc/repl/InterpreterLoop.scala b/src/dotty/tools/dotc/repl/InterpreterLoop.scala index b97ef3599..1a7a6d115 100644 --- a/src/dotty/tools/dotc/repl/InterpreterLoop.scala +++ b/src/dotty/tools/dotc/repl/InterpreterLoop.scala @@ -35,7 +35,6 @@ class InterpreterLoop( out: PrintWriter)(implicit ctx: Context) { val interpreter = compiler.asInstanceOf[Interpreter] - interpreter.init() /** The context class loader at the time this object was created */ protected val originalClassLoader = -- cgit v1.2.3