public final class SLContext extends Object
SLLanguage. It
is used, for example, by builtin functions.
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 and Description |
|---|
SLContext(SLLanguage language,
com.oracle.truffle.api.TruffleLanguage.Env env,
List<com.oracle.truffle.api.dsl.NodeFactory<? extends SLBuiltinNode>> externalBuiltins) |
| Modifier and Type | Method and Description |
|---|---|
static Object |
fromForeignValue(Object a) |
static SLContext |
get(com.oracle.truffle.api.nodes.Node node) |
com.oracle.truffle.api.instrumentation.AllocationReporter |
getAllocationReporter() |
com.oracle.truffle.api.TruffleLanguage.Env |
getEnv()
Return the current Truffle environment.
|
SLFunctionRegistry |
getFunctionRegistry()
Returns the registry of all functions that are currently defined.
|
BufferedReader |
getInput()
Returns the default input, i.e., the source for the
SLReadlnBuiltin. |
PrintWriter |
getOutput()
The default default, i.e., the output for the
SLPrintlnBuiltin. |
com.oracle.truffle.api.interop.TruffleObject |
getPolyglotBindings()
Returns an object that contains bindings that were exported across all used languages.
|
void |
installBuiltin(com.oracle.truffle.api.dsl.NodeFactory<? extends SLBuiltinNode> factory) |
com.oracle.truffle.api.CallTarget |
parse(com.oracle.truffle.api.source.Source source) |
void |
patchContext(com.oracle.truffle.api.TruffleLanguage.Env newEnv)
Patches the
SLContext to use a new TruffleLanguage.Env. |
void |
registerShutdownHook(SLFunction func)
Register a function as a shutdown hook.
|
void |
runShutdownHooks()
Run registered shutdown hooks.
|
public SLContext(SLLanguage language, com.oracle.truffle.api.TruffleLanguage.Env env, List<com.oracle.truffle.api.dsl.NodeFactory<? extends SLBuiltinNode>> externalBuiltins)
public void patchContext(com.oracle.truffle.api.TruffleLanguage.Env newEnv)
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...).newEnv - the new TruffleLanguage.Env to use.TruffleLanguage.patchContext(Object, Env)public com.oracle.truffle.api.TruffleLanguage.Env getEnv()
public BufferedReader getInput()
SLReadlnBuiltin. To allow unit
testing, we do not use System.in directly.public PrintWriter getOutput()
SLPrintlnBuiltin. To allow unit
testing, we do not use System.out directly.public SLFunctionRegistry getFunctionRegistry()
public void installBuiltin(com.oracle.truffle.api.dsl.NodeFactory<? extends SLBuiltinNode> factory)
public com.oracle.truffle.api.instrumentation.AllocationReporter getAllocationReporter()
public com.oracle.truffle.api.CallTarget parse(com.oracle.truffle.api.source.Source source)
public com.oracle.truffle.api.interop.TruffleObject getPolyglotBindings()
interop API can be used.public static SLContext get(com.oracle.truffle.api.nodes.Node node)
public void registerShutdownHook(SLFunction func)
func - no-parameter function to be registered as a shutdown hookpublic void runShutdownHooks()
TruffleLanguage.exitContext(Object, TruffleLanguage.ExitMode, int).