public abstract static class TruffleLanguage.LanguageReference<L extends TruffleLanguage> extends Object
TruffleLanguage.LanguageReference.create(Class)
and are intended to be stored in static
final fields and accessed at runtime using TruffleLanguage.LanguageReference.get(Node)
with the
current Node
, if available, as parameter.
Example intended usage:
See TruffleLanguage.ContextReference
for a full usage example.
Modifier | Constructor and Description |
---|---|
protected |
LanguageReference()
Constructors for subclasses.
|
Modifier and Type | Method and Description |
---|---|
static <T extends TruffleLanguage<?>> |
create(Class<T> languageClass)
Creates a new instance of a langauge reference for an registered language.
|
abstract L |
get(Node node)
Returns the current language instance associated with the current thread.
|
protected LanguageReference()
public abstract L get(Node node)
null
may be
provided. This method is designed to be called safely from compiled code paths. In order
to maximize efficiency in compiled code paths, a partial evaluation constant and adopted
node should be passed as parameter. If this is the case then the return context will get
constant folded in compiled code paths if there is a only single context instance for the
enclosing engine or lookup location/node.
The current language will not change for executions
of roots
of the current language. For roots of other
languages, e.g. if invoked through the interoperability protocol, the language might
change between consecutive executions. It is recommended to *not* cache values of the
language in the AST to reduce footprint. Getting it through a language reference will
either constant fold or be very efficient in compiled code paths.
If a context is accessed during context
creation
, on an unknown Thread, or in the language class constructor an
IllegalStateException
is thrown.
for a full usage example
public static <T extends TruffleLanguage<?>> TruffleLanguage.LanguageReference<T> create(Class<T> languageClass)
IllegalArgumentException
if the provided language class is not
registered
. Guaranteed to always return the same context reference
for a given language class.
See TruffleLanguage.LanguageReference
for a usage example.