public final class SLLanguage extends com.oracle.truffle.api.TruffleLanguage<SLContext>
SL is dynamically typed, i.e., there are no type names specified by the programmer. SL is
strongly typed, i.e., there is no automatic conversion between types. If an operation is not
available for the types encountered at run time, a type error is reported and execution is
stopped. For example, 4 - "2" results in a type error because subtraction is only defined
for numbers.
Types:
long to represent numbers that fit into the 64 bit range, and SLBigNumber for
numbers that exceed the range. Using a primitive type such as long is crucial for
performance.
boolean.
String.
SLFunction.
DynamicObject.
null): implemented as the singleton
SLNull.SINGLETON.
SLTypes lists these types for the Truffle DSL, i.e., for type-specialized
operations that are specified using Truffle DSL annotations.
Language concepts:
numbers , strings,
and functions.
+, -, *, /, logical and,
logical or, ==, !=, <,
≤, >, ≥.
write) before they can be used (by a read). Local variables are
not visible outside of the block where they were first defined.
blocks, if,
while with break and continue,
return.
debugger statement uses
DebuggerTags#AlwaysHalt tag to halt the execution when run under the debugger.
invocations are efficiently implemented with
polymorphic inline caches.
SLReadPropertyNode and SLWritePropertyNode use a cached
DynamicObjectLibrary as the polymorphic inline cache for property reads and writes,
respectively.
Syntax and parsing:
The syntax is described as an attributed grammar. The SimpleLanguageParser and
SimpleLanguageLexer are automatically generated by ANTLR 4. The grammar contains semantic
actions that build the AST for a method. To keep these semantic actions short, they are mostly
calls to the SLNodeFactory that performs the actual node creation. All functions found in
the SL source are added to the SLFunctionRegistry, which is accessible from the
SLContext.
Builtin functions:
Library functions that are available to every SL source without prior definition are called
builtin functions. They are added to the SLFunctionRegistry when the SLContext is
created. Some of the current builtin functions are
readln: Read a String from the standard
input.
println: Write a value to the standard
output.
nanoTime: Returns the value of a high-resolution time, in
nanoseconds.
defineFunction: Parses the functions provided as a String
argument and adds them to the function registry. Functions that are already defined are replaced
with the new version.
stckTrace: Print all function activations with all local
variables.
com.oracle.truffle.api.TruffleLanguage.ContextLocalFactory<C,T>, com.oracle.truffle.api.TruffleLanguage.ContextPolicy, com.oracle.truffle.api.TruffleLanguage.ContextReference<C>, com.oracle.truffle.api.TruffleLanguage.ContextThreadLocalFactory<C,T>, com.oracle.truffle.api.TruffleLanguage.Env, com.oracle.truffle.api.TruffleLanguage.ExitMode, com.oracle.truffle.api.TruffleLanguage.InlineParsingRequest, com.oracle.truffle.api.TruffleLanguage.LanguageReference<L extends com.oracle.truffle.api.TruffleLanguage>, com.oracle.truffle.api.TruffleLanguage.ParsingRequest, com.oracle.truffle.api.TruffleLanguage.Provider, com.oracle.truffle.api.TruffleLanguage.Registration| Modifier and Type | Field and Description |
|---|---|
static int |
counter |
static String |
ID |
static String |
MIME_TYPE |
static com.oracle.truffle.api.strings.TruffleString.Encoding |
STRING_ENCODING |
| Constructor and Description |
|---|
SLLanguage() |
| Modifier and Type | Method and Description |
|---|---|
protected SLContext |
createContext(com.oracle.truffle.api.TruffleLanguage.Env env) |
SLObject |
createObject(com.oracle.truffle.api.instrumentation.AllocationReporter reporter)
Allocate an empty object.
|
protected void |
exitContext(SLContext context,
com.oracle.truffle.api.TruffleLanguage.ExitMode exitMode,
int exitCode) |
static SLLanguage |
get(com.oracle.truffle.api.nodes.Node node) |
protected Object |
getLanguageView(SLContext context,
Object value) |
com.oracle.truffle.api.RootCallTarget |
getOrCreateUndefinedFunction(com.oracle.truffle.api.strings.TruffleString name) |
com.oracle.truffle.api.object.Shape |
getRootShape() |
protected Object |
getScope(SLContext context) |
protected void |
initializeMultipleContexts()
SLLanguage specifies the
TruffleLanguage.ContextPolicy.SHARED in
Registration#contextPolicy(). |
static void |
installBuiltin(com.oracle.truffle.api.dsl.NodeFactory<? extends SLBuiltinNode> builtin) |
boolean |
isSingleContext() |
protected boolean |
isVisible(SLContext context,
Object value) |
com.oracle.truffle.api.RootCallTarget |
lookupBuiltin(com.oracle.truffle.api.dsl.NodeFactory<? extends SLBuiltinNode> factory) |
static com.oracle.truffle.api.nodes.NodeInfo |
lookupNodeInfo(Class<?> clazz) |
protected com.oracle.truffle.api.CallTarget |
parse(com.oracle.truffle.api.TruffleLanguage.ParsingRequest request) |
protected boolean |
patchContext(SLContext context,
com.oracle.truffle.api.TruffleLanguage.Env newEnv) |
areOptionsCompatible, createContextLocal, createContextThreadLocal, disposeContext, disposeThread, finalizeContext, getAsynchronousStackDepth, getLanguageHome, getOptionDescriptors, initializeContext, initializeMultiThreading, initializeThread, isThreadAccessAllowed, parsepublic static volatile int counter
public static final String ID
public static final String MIME_TYPE
public static final com.oracle.truffle.api.strings.TruffleString.Encoding STRING_ENCODING
protected SLContext createContext(com.oracle.truffle.api.TruffleLanguage.Env env)
createContext in class com.oracle.truffle.api.TruffleLanguage<SLContext>protected boolean patchContext(SLContext context, com.oracle.truffle.api.TruffleLanguage.Env newEnv)
patchContext in class com.oracle.truffle.api.TruffleLanguage<SLContext>public com.oracle.truffle.api.RootCallTarget getOrCreateUndefinedFunction(com.oracle.truffle.api.strings.TruffleString name)
public com.oracle.truffle.api.RootCallTarget lookupBuiltin(com.oracle.truffle.api.dsl.NodeFactory<? extends SLBuiltinNode> factory)
public static com.oracle.truffle.api.nodes.NodeInfo lookupNodeInfo(Class<?> clazz)
protected com.oracle.truffle.api.CallTarget parse(com.oracle.truffle.api.TruffleLanguage.ParsingRequest request)
throws Exception
protected void initializeMultipleContexts()
TruffleLanguage.ContextPolicy.SHARED in
Registration#contextPolicy(). This means that a single TruffleLanguage
instance can be reused for multiple language contexts. Before this happens the Truffle
framework notifies the language by invoking SLLanguage.initializeMultipleContexts(). This
allows the language to invalidate certain assumptions taken for the single context case. One
assumption SL takes for single context case is located in SLEvalRootNode. There
functions are only tried to be registered once in the single context case, but produce a
boundary call in the multi context case, as function registration is expected to happen more
than once.
Value identity caches should be avoided and invalidated for the multiple contexts case as no
value will be the same. Instead, in multi context case, a language should only use types,
shapes and code to speculate.
For a new language it is recommended to start with TruffleLanguage.ContextPolicy.EXCLUSIVE and as the
language gets more mature switch to TruffleLanguage.ContextPolicy.SHARED.initializeMultipleContexts in class com.oracle.truffle.api.TruffleLanguage<SLContext>public boolean isSingleContext()
protected Object getLanguageView(SLContext context, Object value)
getLanguageView in class com.oracle.truffle.api.TruffleLanguage<SLContext>protected boolean isVisible(SLContext context, Object value)
isVisible in class com.oracle.truffle.api.TruffleLanguage<SLContext>protected Object getScope(SLContext context)
getScope in class com.oracle.truffle.api.TruffleLanguage<SLContext>public com.oracle.truffle.api.object.Shape getRootShape()
public SLObject createObject(com.oracle.truffle.api.instrumentation.AllocationReporter reporter)
public static SLLanguage get(com.oracle.truffle.api.nodes.Node node)
public static void installBuiltin(com.oracle.truffle.api.dsl.NodeFactory<? extends SLBuiltinNode> builtin)