A class loader that loads files from a
An interpreter for Scala code which is based on the
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.
Utility methods for the Interpreter.
A Writer that writes onto the Scala Console.
The current Scala REPL know how to do this flexibly.
Reads lines from an input stream
This object defines the type of interpreter results
The exported functionality of the interpreter
The interactive shell. It provides a read-eval-print loop around
the Interpreter class.
After instantiation, clients should call the
The main entry point of the REPL
A compiler which stays resident between runs. Usage:
dotc> "more options and files to compile"
dotc> :reset // reset all options to the ones passed on the command line
dotc> :q // quit
Reads using standard JDK API