Package com.oracle.truffle.api
Class TruffleLanguage.LanguageReference<L extends TruffleLanguage>
java.lang.Object
com.oracle.truffle.api.TruffleLanguage.LanguageReference<L>
- Enclosing class:
TruffleLanguage<C>
public abstract static class TruffleLanguage.LanguageReference<L extends TruffleLanguage>
extends Object
Represents a reference to the current language instance. The current language is a thread
local value that potentially changes when polyglot context is entered or left. Language
references are created using
create(Class)
and are intended to be stored in static
final fields and accessed at runtime using get(Node)
with the
current Node
, if available, as parameter.
Example intended usage:
See TruffleLanguage.ContextReference
for a full usage example.
- Since:
- 0.25 revised in 21.3
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends TruffleLanguage<?>>
TruffleLanguage.LanguageReference<T> Creates a new instance of a langauge reference for an registered language.abstract L
Returns the current language instance associated with the current thread.
-
Constructor Details
-
LanguageReference
protected LanguageReference()Constructors for subclasses.- Since:
- 19.0
-
-
Method Details
-
get
Returns the current language instance associated with the current thread. An enclosing node should be provided as parameter if available, otherwisenull
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 language will get constant folded in compiled code paths.The current language is fixed per
RootNode
. 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 language is accessed on an unknown Thread, or in the language class constructor an
IllegalStateException
is thrown.- Since:
- 21.3
- See Also:
-
create
public static <T extends TruffleLanguage<?>> TruffleLanguage.LanguageReference<T> create(Class<T> languageClass) Creates a new instance of a langauge reference for an registered language. ThrowsIllegalArgumentException
if the provided language class is notregistered
. Guaranteed to always return the same context reference for a given language class.See
TruffleLanguage.LanguageReference
for a usage example.- Since:
- 21.3
-