The output to use for diagnostics
The context to use for initialization of the interpreter, needed to access the current classpath.
Temporarily be quiet
Temporarily be quiet
This bind is implemented by creating an object with a set method and a
field value
.
This bind is implemented by creating an object with a set method and a
field value
. The value is then set via Java reflection.
Example: We want to bind a value List(1,2,3)
to identifier list
from
sbt. The bind method accomplishes this by creating the following:
object ContainerObjectWithUniqueID { var value: List[Int] = _ def set(x: Any) = value = x.asInstanceOf[List[Int]] } val list = ContainerObjectWithUniqueID.value
Between the object being created and the value being assigned, the value inside the object is set via reflection.
class loader used to load compiled code
Compile a SourceFile.
Compile a SourceFile. Returns the root context of the run that compiled the file.
Compile a string.
Compile a string. Returns true if there are no compilation errors, or false otherwise.
the compiler's classpath, as URL's
Suppresses output and saves it for lastOutput
to collect
Suppresses output and saves it for lastOutput
to collect
Interpret one line of input.
Interpret one line of input. All feedback, including parse errors and evaluation results, are printed via the context's reporter. Values defined are available for future interpreted strings.
Gets the last output not printed immediately
Gets the last output not printed immediately
Phases of this compiler use REPLGenBCode
instead of GenBCode
.
Phases of this compiler use REPLGenBCode
instead of GenBCode
.
Produces the following contexts, from outermost to innermost
Produces the following contexts, from outermost to innermost
bootStrap: A context with next available runId and a scope consisting of the RootPackage _root_ start A context with RootClass as owner and the necessary initializations for type checking. imports For each element of RootImports, an import context
directory to save .class files to
An interpreter for Scala code which is based on the
dotc
compiler.The overall approach is based on compiling the requested code and then using a Java classloader and Java reflection to run the code and access its results.
In more detail, a single compiler instance is used to accumulate all successfully compiled or interpreted Scala code. To "interpret" a line of code, the compiler generates a fresh object that includes the line of code and which has public definition(s) to export all variables defined by that code. To extract the result of an interpreted line to show the user, a second "result object" is created which imports the variables exported by the above object and then exports a single definition named "result". To accommodate user expressions that read from variables or methods defined in previous statements, "import" statements are used.
This interpreter shares the strengths and weaknesses of using the full compiler-to-Java. The main strength is that interpreted code behaves exactly as does compiled code, including running at full speed. The main weakness is that redefining classes and methods is not handled properly, because rebinding at the Java level is technically difficult.