Module ch.turic
Package ch.turic

Class Interpreter

java.lang.Object
ch.turic.Interpreter

public class Interpreter extends Object
Interprets and executes source code written in the programming language.

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 Details

    • Interpreter

      public Interpreter(String source)
    • Interpreter

      public Interpreter(ch.turic.analyzer.Input source)
  • Method Details

    • getImportContext

      public Context getImportContext()
    • execute

      public Object execute() throws BadSyntax, ExecutionException
      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 errors
      ExecutionException - if an error occurs during execution