While this class is designed to be used from a single thread, it implements thread-safe compilation of the source code using double-checked locking pattern. This means that even if multiple threads accidentally execute the same interpreter instance, the source code will be compiled exactly once and the compiled code will be properly visible to all threads.
However, note that each execution creates a new Context instance, which
means that concurrent executions will not share state. This is not the recommended
usage pattern, and the interpreter should ideally be used from a single thread.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionexecute()Executes the source code, compiling it first if necessary.
-
Constructor Details
-
Interpreter
-
Interpreter
public Interpreter(ch.turic.analyzer.Input source)
-
-
Method Details
-
getImportContext
-
execute
Executes the source code, compiling it first if necessary.While this method implements thread-safe compilation using double-checked locking, it is not designed for concurrent use. Each call creates a new execution context, so concurrent executions will not share state. It is recommended to use each Interpreter instance from a single thread.
- Returns:
- The result of executing the code
- Throws:
BadSyntax- if the source code contains syntax errorsExecutionException- if an error occurs during execution
-