diff options
author | Lex Spoon <lex@lexspoon.org> | 2008-05-11 22:41:38 +0000 |
---|---|---|
committer | Lex Spoon <lex@lexspoon.org> | 2008-05-11 22:41:38 +0000 |
commit | 1be24726a02f521b97e534ab418d2b61f500b619 (patch) | |
tree | 49a2f52927e3e8cbd3c32c80e7fad3291e85dd5e | |
parent | 1be78ed23283a885c9e83439c6482b56e7f415cb (diff) | |
download | scala-1be24726a02f521b97e534ab418d2b61f500b619.tar.gz scala-1be24726a02f521b97e534ab418d2b61f500b619.tar.bz2 scala-1be24726a02f521b97e534ab418d2b61f500b619.zip |
Three small Interpreter improvements:
- include jars from -Ycodebase on the classpath to run interpreted
- make isettings a lazy val, because it is used during logging, and
initialization of the class can require logging if an error happens -
updated the class comment to mention bind() as one of the main public
methods of the class
-rw-r--r-- | src/compiler/scala/tools/nsc/Interpreter.scala | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/src/compiler/scala/tools/nsc/Interpreter.scala b/src/compiler/scala/tools/nsc/Interpreter.scala index 713b4c7b99..c5fbd57354 100644 --- a/src/compiler/scala/tools/nsc/Interpreter.scala +++ b/src/compiler/scala/tools/nsc/Interpreter.scala @@ -8,7 +8,7 @@ package scala.tools.nsc import java.io.{File, PrintWriter, StringWriter, Writer} import java.lang.{Class, ClassLoader} -import java.net.{URL, URLClassLoader} +import java.net.{MalformedURLException, URL, URLClassLoader} import scala.collection.immutable.ListSet import scala.collection.mutable @@ -26,10 +26,13 @@ import scala.tools.nsc.interpreter._ * An interpreter for Scala code. * </p> * <p> - * The main public entry points are <code>compile()</code> and - * <code>interpret()</code>. The <code>compile()</code> method loads a + * The main public entry points are <code>compile()</code>, + * <code>interpret()</code>, and <code>bind()</code>. + * The <code>compile()</code> method loads a * complete Scala file. The <code>interpret()</code> method executes one - * line of Scala code at the request of the user. + * line of Scala code at the request of the user. The <code>bind()</code> + * method binds an object to a variable that can then be used by later + * interpreted code. * </p> * <p> * The overall approach is based on compiling the requested code and then @@ -111,7 +114,7 @@ class Interpreter(val settings: Settings, out: PrintWriter) { } /** interpreter settings */ - val isettings = new InterpreterSettings + lazy val isettings = new InterpreterSettings object reporter extends ConsoleReporter(settings, null, out) { //override def printMessage(msg: String) { out.println(clean(msg)) } @@ -128,9 +131,16 @@ class Interpreter(val settings: Settings, out: PrintWriter) { /** the compiler's classpath, as URL's */ - val compilerClasspath: List[URL] = - ClassPath.expandPath(compiler.settings.classpath.value). - map(s => new File(s).toURL) + val compilerClasspath: List[URL] = { + val classpathPart = + (ClassPath.expandPath(compiler.settings.classpath.value). + map(s => new File(s).toURL)) + def parseURL(s: String): Option[URL] = + try { Some(new URL(s)) } + catch { case _:MalformedURLException => None } + val codebasePart = (compiler.settings.Xcodebase.value.split(" ")).toList.flatMap(parseURL) + classpathPart ::: codebasePart + } /* 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 |