Class SLContext

java.lang.Object
com.oracle.truffle.sl.runtime.SLContext

public final class SLContext extends Object
The run-time state of SL during execution. The context is created by the SLLanguage. It is used, for example, by the eval builtin function.

It would be an error to have two different context instances during the execution of one script. However, if two separate scripts run in one Java VM at the same time, they have a different context. Therefore, the context is not a singleton.

  • Constructor Details

    • SLContext

      public SLContext(SLLanguage language, com.oracle.truffle.api.TruffleLanguage.Env env, List<com.oracle.truffle.api.dsl.NodeFactory<? extends SLBuiltinNode>> externalBuiltins)
  • Method Details

    • patchContext

      public void patchContext(com.oracle.truffle.api.TruffleLanguage.Env newEnv)
      Patches the SLContext to use a new TruffleLanguage.Env. The method is called during the native image execution as a consequence of Context.create(java.lang.String...).
      Parameters:
      newEnv - the new TruffleLanguage.Env to use.
      See Also:
      • TruffleLanguage.patchContext(Object, Env)
    • getEnv

      public com.oracle.truffle.api.TruffleLanguage.Env getEnv()
      Return the current Truffle environment.
    • getInput

      public BufferedReader getInput()
      Returns the default input, i.e., the source for the SLReadlnBuiltin. To allow unit testing, we do not use System.in directly.
    • getOutput

      public PrintWriter getOutput()
      The default default, i.e., the output for the SLPrintlnBuiltin. To allow unit testing, we do not use System.out directly.
    • getFunctionRegistry

      public SLFunctionRegistry getFunctionRegistry()
      Returns the registry of all functions that are currently defined.
    • installBuiltin

      public void installBuiltin(com.oracle.truffle.api.dsl.NodeFactory<? extends SLBuiltinNode> factory)
    • getAllocationReporter

      public com.oracle.truffle.api.instrumentation.AllocationReporter getAllocationReporter()
    • fromForeignValue

      public static Object fromForeignValue(Object a)
    • parse

      public com.oracle.truffle.api.CallTarget parse(com.oracle.truffle.api.source.Source source)
    • getPolyglotBindings

      public com.oracle.truffle.api.interop.TruffleObject getPolyglotBindings()
      Returns an object that contains bindings that were exported across all used languages. To read or write from this object the interop API can be used.
    • get

      public static SLContext get(com.oracle.truffle.api.nodes.Node node)
    • registerShutdownHook

      public void registerShutdownHook(SLFunction func)
      Register a function as a shutdown hook. Only no-parameter functions are supported.
      Parameters:
      func - no-parameter function to be registered as a shutdown hook
    • runShutdownHooks

      public void runShutdownHooks()
      Run registered shutdown hooks. This method is designed to be executed in TruffleLanguage.exitContext(Object, TruffleLanguage.ExitMode, int).