Class SLLanguage
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:
- Number: arbitrary precision integer numbers. The implementation uses the Java primitive type
longto represent numbers that fit into the 64 bit range, andSLBigIntegerfor numbers that exceed the range. Using a primitive type such aslongis crucial for performance. - Boolean: implemented as the Java primitive type
boolean. - String: implemented as the Java standard type
String. - Function: implementation type
SLFunction. - Object: efficient implementation using the object model provided by Truffle. The
implementation type of objects is a subclass of
DynamicObject. - Null (with only one value
null): implemented as the singletonSLNull.SINGLETON.
SLTypes lists these types for the Truffle DSL, i.e., for type-specialized
operations that are specified using Truffle DSL annotations.
Language concepts:
- Literals for
numbers,strings, andfunctions. - Basic arithmetic, logical, and comparison operations:
+,-,*,/,logical and,logical or,==, !=,<,≤, >, ≥. - Local variables: local variables must be defined (via a
write) before they can be used (by aread). Local variables are not visible outside of the block where they were first defined. - Basic control flow statements:
blocks,if,whilewithbreakandcontinue,return. - Debugging control:
debuggerstatement usesDebuggerTags.AlwaysHalttag to halt the execution when run under the debugger. - Function calls:
invocationsare efficiently implemented withpolymorphic inline caches. - Object access:
SLReadPropertyNodeandSLWritePropertyNodeuse a cachedDynamicObjectLibraryas the polymorphic inline cache for property reads and writes, respectively.
Syntax and parsing:
The syntax is described by an ANTLR 4 grammar. The
parser and
lexer are automatically generated by
ANTLR 4. SL converts the AST to a Truffle interpreter using an AST visitor. All functions found
in SL source are added to the SLFunctionRegistry, which is accessible from the
SLContext.
AST vs. Bytecode interpreter:
SL has an AST interpreter and a bytecode
interpreter. The interpreter used depends on the UseBytecode flag (by
default, the AST interpreter is used).
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 thestandard input.println: Write a value to thestandard 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.
-
Nested Class Summary
Nested classes/interfaces inherited from class com.oracle.truffle.api.TruffleLanguage
com.oracle.truffle.api.TruffleLanguage.ContextLocalFactory<C,T>, com.oracle.truffle.api.TruffleLanguage.ContextLocalProvider<C>, 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 -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic intstatic final org.graalvm.options.OptionKey<com.oracle.truffle.api.bytecode.BytecodeTier> static final Stringstatic final Stringstatic final com.oracle.truffle.api.strings.TruffleString.Encodingstatic final org.graalvm.options.OptionKey<Boolean> Fields inherited from class com.oracle.truffle.api.TruffleLanguage
locals -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanareOptionsCompatible(org.graalvm.options.OptionValues firstOptions, org.graalvm.options.OptionValues newOptions) protected SLContextcreateContext(com.oracle.truffle.api.TruffleLanguage.Env env) createObject(com.oracle.truffle.api.instrumentation.AllocationReporter reporter) Allocate an empty object.protected voidexitContext(SLContext context, com.oracle.truffle.api.TruffleLanguage.ExitMode exitMode, int exitCode) static SLLanguageget(com.oracle.truffle.api.nodes.Node node) com.oracle.truffle.api.bytecode.BytecodeTierprotected ObjectgetLanguageView(SLContext context, Object value) protected org.graalvm.options.OptionDescriptorscom.oracle.truffle.api.RootCallTargetgetOrCreateUndefinedFunction(com.oracle.truffle.api.strings.TruffleString name) com.oracle.truffle.api.object.Shapeprotected Objectprotected voidSLLanguage specifies theTruffleLanguage.ContextPolicy.SHAREDinTruffleLanguage.Registration.contextPolicy().static voidinstallBuiltin(com.oracle.truffle.api.dsl.NodeFactory<? extends SLBuiltinNode> builtin) booleanbooleanprotected booleancom.oracle.truffle.api.RootCallTargetlookupBuiltin(com.oracle.truffle.api.dsl.NodeFactory<? extends SLBuiltinNode> factory) static com.oracle.truffle.api.nodes.NodeInfolookupNodeInfo(Class<?> clazz) protected com.oracle.truffle.api.CallTargetparse(com.oracle.truffle.api.TruffleLanguage.ParsingRequest request) protected booleanpatchContext(SLContext context, com.oracle.truffle.api.TruffleLanguage.Env newEnv) static voidprintInstrumentationTree(PrintStream w, String indent, com.oracle.truffle.api.nodes.Node node) Methods inherited from class com.oracle.truffle.api.TruffleLanguage
createContextLocal, createContextThreadLocal, disposeContext, disposeThread, finalizeContext, finalizeThread, getAsynchronousStackDepth, getCurrentContext, getCurrentLanguage, getLanguageHome, initializeContext, initializeMultiThreading, initializeThread, isThreadAccessAllowed, parse
-
Field Details
-
counter
public static volatile int counter -
ID
- See Also:
-
MIME_TYPE
- See Also:
-
STRING_ENCODING
public static final com.oracle.truffle.api.strings.TruffleString.Encoding STRING_ENCODING -
UseBytecode
-
ForceBytecodeTier
public static final org.graalvm.options.OptionKey<com.oracle.truffle.api.bytecode.BytecodeTier> ForceBytecodeTier
-
-
Constructor Details
-
SLLanguage
public SLLanguage()
-
-
Method Details
-
createContext
- Specified by:
createContextin classcom.oracle.truffle.api.TruffleLanguage<SLContext>
-
patchContext
protected boolean patchContext(SLContext context, com.oracle.truffle.api.TruffleLanguage.Env newEnv) - Overrides:
patchContextin classcom.oracle.truffle.api.TruffleLanguage<SLContext>
-
getOptionDescriptors
protected org.graalvm.options.OptionDescriptors getOptionDescriptors()- Overrides:
getOptionDescriptorsin classcom.oracle.truffle.api.TruffleLanguage<SLContext>
-
isUseBytecode
public boolean isUseBytecode() -
getForceBytecodeTier
public com.oracle.truffle.api.bytecode.BytecodeTier getForceBytecodeTier() -
areOptionsCompatible
protected boolean areOptionsCompatible(org.graalvm.options.OptionValues firstOptions, org.graalvm.options.OptionValues newOptions) - Overrides:
areOptionsCompatiblein classcom.oracle.truffle.api.TruffleLanguage<SLContext>
-
getOrCreateUndefinedFunction
public com.oracle.truffle.api.RootCallTarget getOrCreateUndefinedFunction(com.oracle.truffle.api.strings.TruffleString name) -
lookupBuiltin
public com.oracle.truffle.api.RootCallTarget lookupBuiltin(com.oracle.truffle.api.dsl.NodeFactory<? extends SLBuiltinNode> factory) -
lookupNodeInfo
-
parse
protected com.oracle.truffle.api.CallTarget parse(com.oracle.truffle.api.TruffleLanguage.ParsingRequest request) throws Exception -
printInstrumentationTree
public static void printInstrumentationTree(PrintStream w, String indent, com.oracle.truffle.api.nodes.Node node) -
initializeMultipleContexts
protected void initializeMultipleContexts()SLLanguage specifies theTruffleLanguage.ContextPolicy.SHAREDinTruffleLanguage.Registration.contextPolicy(). This means that a singleTruffleLanguageinstance can be reused for multiple language contexts. Before this happens the Truffle framework notifies the language by invokinginitializeMultipleContexts(). This allows the language to invalidate certain assumptions taken for the single context case. One assumption SL takes for single context case is located inSLEvalRootNode. 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 withTruffleLanguage.ContextPolicy.EXCLUSIVEand as the language gets more mature switch toTruffleLanguage.ContextPolicy.SHARED.- Overrides:
initializeMultipleContextsin classcom.oracle.truffle.api.TruffleLanguage<SLContext>
-
isSingleContext
public boolean isSingleContext() -
getLanguageView
- Overrides:
getLanguageViewin classcom.oracle.truffle.api.TruffleLanguage<SLContext>
-
isVisible
- Overrides:
isVisiblein classcom.oracle.truffle.api.TruffleLanguage<SLContext>
-
getScope
- Overrides:
getScopein classcom.oracle.truffle.api.TruffleLanguage<SLContext>
-
getRootShape
public com.oracle.truffle.api.object.Shape getRootShape() -
createObject
Allocate an empty object. All new objects initially have no properties. Properties are added when they are first stored, i.e., the store triggers a shape change of the object. -
get
-
installBuiltin
public static void installBuiltin(com.oracle.truffle.api.dsl.NodeFactory<? extends SLBuiltinNode> builtin) -
exitContext
protected void exitContext(SLContext context, com.oracle.truffle.api.TruffleLanguage.ExitMode exitMode, int exitCode) - Overrides:
exitContextin classcom.oracle.truffle.api.TruffleLanguage<SLContext>
-