Here is where we:
One line of code submitted by the user for interpretation
Compute imports that allow definitions from previous requests to be visible in a new request.
Compute imports that allow definitions from previous requests to be visible in a new request. Returns three pieces of related code:
2. A code fragment that should go after the code of the new request.
3. An access path which can be traversed to access any bindings inside code wrapped by #1 and #2 .
The argument is a set of Names that need to be imported.
Limitations: This method is not as precise as it could be. (1) It does not process wildcard imports to see what exactly they import. (2) If it imports any names from a request, it imports all of them, which is not really necessary. (3) It imports multiple same-named implicits, but only the last one imported is actually usable.
Captures the session names (which are set by system properties) once, instead of for each line.
Executes an import statement per "id" provided
Executes an import statement per "id" provided
The series of "id" strings used for import statements
The results of importing the series of "id" strings
addImports("org.apache.spark.SparkContext")
Adds any specified jars to the compile and runtime classpaths.
Adds any specified jars to the compile and runtime classpaths.
The list of items to add to the compile and runtime classpaths
Currently only supports jars, not directories
Retrieves all simple names contained in the current instance.
Retrieves all simple names contained in the current instance.
A list of sorted names
Suppresses overwriting print results during the operation.
Suppresses overwriting print results during the operation.
The return type of the block
The block to execute
The result from executing the block
Completely masks all output during the operation (minus JVM standard out and error).
Completely masks all output during the operation (minus JVM standard out and error).
The return type of the block
The block to execute
The result from executing the block
Bind a specified name to a specified value.
Bind a specified name to a specified value. The name may later be used by expressions passed to interpret.
The variable name to bind
The type of the variable, as a string
The object value to bind to it
An indication of whether the binding succeeded or failed using interpreter results
This binds via compilation and interpretation
Retrieves the class representing the id (variable name, method name, class name, etc) provided.
Retrieves the class representing the id (variable name, method name, class name, etc) provided.
The id (variable name, method name, class name, etc) whose associated class to retrieve
Some containing term name (id) class if exists, else None
URI of the class server used to feed REPL compiled classes.
URI of the class server used to feed REPL compiled classes.
The string representing the class server uri
Retrieves the Symbols representing classes in the compiler.
Retrieves the Symbols representing classes in the compiler.
The list of matching ClassSymbol instances
Clears the code used as a wrapper around all code executed by this instance.
Clears the code used as a wrapper around all code executed by this instance.
Stops the underlying REPL class server and flushes the reporter used for compiler output.
Stops the underlying REPL class server and flushes the reporter used for compiler output.
Compiles specified source files.
Compiles specified source files.
The sequence of source files to compile
True if successful, otherwise false
Compiles a string of code.
Compiles a string of code.
The string of code to compile
True if successful, otherwise false
Retrieves the list of public symbols in the compiler.
Retrieves the list of public symbols in the compiler.
The list of public Symbol instances
Retrieves the defined symbols in the compiler.
Retrieves the defined symbols in the compiler.
The set of matching Symbol instances
Retrieves the defined, public names in the compiler.
Retrieves the defined, public names in the compiler.
The list of matching "term" names
Retrieves the defined type names in the compiler.
Retrieves the defined type names in the compiler.
The list of matching type names
Bind a specified name to a specified value directly.
Bind a specified name to a specified value directly.
The variable name to bind
The type of the variable, as a string
The object value to bind to it
An indication of whether the binding succeeded or failed using interpreter results
This updates internal bound names directly
Contains the code (in string form) representing a wrapper around all code executed by this instance.
Contains the code (in string form) representing a wrapper around all code executed by this instance.
The wrapper code as a string
Returns the real name of a class based on its repl-defined name.
Returns the real name of a class based on its repl-defined name.
Given a simple repl-defined name, returns the real name of the class representing it, e.g. for "Bippy" it may return
$line19.$read$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$Bippy
The repl-defined name whose real name to retrieve
Some real name if the simple name exists, else None
Returns the path to the output directory containing all generated class files that will be served by the REPL class server.
The underlying compiler used to generate ASTs and execute code.
Tuples of (source, imported symbols) in the order they were imported.
Tuples of (source, imported symbols) in the order they were imported.
Initializes the underlying compiler/interpreter in a blocking fashion.
Initializes the underlying compiler/interpreter in a blocking fashion.
Must be executed before using SparkIMain!
Interpret one line of input.
Interpret one line of input. All feedback, including parse errors and evaluation results, are printed via the supplied compiler's reporter. Values defined are available for future interpreted strings.
The line representing the code to interpret
Whether the line was interpreted successfully, or failed due to incomplete code, compilation error, or runtime error
This assigns variables with user name structure like "res0"
Interpret one line of input.
Interpret one line of input. All feedback, including parse errors and evaluation results, are printed via the supplied compiler's reporter. Values defined are available for future interpreted strings.
The line representing the code to interpret
Whether the line was interpreted successfully, or failed due to incomplete code, compilation error, or runtime error
This assigns variables with synthetic (generated) name structure like "$ires0"
Determines if errors were reported (typically during compilation).
Determines if errors were reported (typically during compilation).
True if had errors, otherwise false
This is not for runtime errors
Symbols whose contents are language-defined to be imported.
Symbols whose contents are language-defined to be imported.
Returns a list of recent warnings from compiler execution.
Returns a list of recent warnings from compiler execution.
The list of tuples (compiler position, warning)
Retrieves the Symbols representing methods in the compiler.
Retrieves the Symbols representing methods in the compiler.
The list of matching MethodSymbol instances
Returns the name of the most recent interpreter result.
Returns the name of the most recent interpreter result. Useful for for extracting information regarding the previous result.
The simple name of the result (such as res0)
Retrieves defined, public names that are not res0 or the result of a direct bind.
Retrieves defined, public names that are not res0 or the result of a direct bind.
The list of matching "term" names
Instantiates a new compiler used by SparkIMain.
Instantiates a new compiler used by SparkIMain. Overridable to provide own instance of a compiler.
The settings to provide the compiler
The reporter to use for compiler output
The compiler as a Global
Represents the parent classloader used by this instance.
Represents the parent classloader used by this instance. Can be overridden to provide alternative classloader.
The classloader used as the parent loader of this instance
Constructs a list of abstract syntax trees representing the provided code.
Constructs a list of abstract syntax trees representing the provided code.
The line of code to parse and construct into ASTs
Some list of ASTs if the line is valid, else None
Retrieves the full code path to access the specified simple name content.
Retrieves the full code path to access the specified simple name content.
The simple name of the target whose path to determine
The full path used to access the specified target (name)
Overwrites previously-bound val with a new instance.
Overwrites previously-bound val with a new instance.
The named parameters used to provide the name, value, and type
The results of rebinding the named val
Reset this interpreter, forgetting all user-specified requests.
Reset this interpreter, forgetting all user-specified requests.
Retrieves the runtime class and type representing the id (variable name, method name, class name, etc) provided.
Retrieves the runtime class and type representing the id (variable name, method name, class name, etc) provided.
The id (variable name, method name, class name, etc) whose associated runtime class and type to retrieve
Some runtime class and Type information as a tuple for the provided term name if it exists, else None
Retrieves the runtime type representing the id (variable name, method name, class name, etc) provided.
Retrieves the runtime type representing the id (variable name, method name, class name, etc) provided.
The id (variable name, method name, class name, etc) whose associated runtime type to retrieve
The runtime Type information about the term name (id) provided
Types which have been wildcard imported, such as: val x = "abc" ; import x.
Types which have been wildcard imported, such as: val x = "abc" ; import x._ // type java.lang.String import java.lang.String._ // object java.lang.String
Used by tab completion.
XXX right now this gets import x._ and import java.lang.String._, but doesn't figure out import String._. There's a lot of ad hoc scope twiddling which should be swept away in favor of digging into the compiler scopes.
Sets the code to use as a wrapper around all code executed by this instance.
Sets the code to use as a wrapper around all code executed by this instance.
The wrapper code as a string
Constructs a Symbol representing the final result of the expression provided or representing the definition provided.
Constructs a Symbol representing the final result of the expression provided or representing the definition provided.
The line of code
The Symbol or NoSymbol (found under scala.reflect.internal)
Retrieves the symbol representing the id (variable name, method name, class name, etc) provided.
Retrieves the symbol representing the id (variable name, method name, class name, etc) provided.
The id (variable name, method name, class name, etc) whose associated symbol to retrieve
The Symbol information about the term name (id) provided
Constucts type information based on the provided expression's final result or the definition provided.
Constucts type information based on the provided expression's final result or the definition provided.
The expression or definition
Whether to output information while constructing the type
The type information or an error
Retrieves the type representing the id (variable name, method name, class name, etc) provided.
Retrieves the type representing the id (variable name, method name, class name, etc) provided.
The id (variable name, method name, class name, etc) whose associated type to retrieve
The Type information about the term name (id) provided
Retrieves the object representing the id (variable name, method name, class name, etc) provided.
Retrieves the object representing the id (variable name, method name, class name, etc) provided.
The id (variable name, method name, class name, etc) whose associated content to retrieve
Some containing term name (id) representation if exists, else None
Retrieves a list of unique defined and imported names in the compiler.
Retrieves a list of unique defined and imported names in the compiler.
The list of "term" names
An interpreter for Scala code. It is slighlty modified for H2O purposes so it can be used in the environemnt where multiple interpretrs exist and are using the same http class server.
The main public entry points are compile(), interpret(), and bind(). The compile() method loads a complete Scala file. The interpret() method executes one line of Scala code at the request of the user. The bind() method binds an object to a variable that can then be used by later interpreted code.
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 member(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 members called "$eval" and "$print". To accomodate 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.