@Retention(value=CLASS) @Target(value=PARAMETER) public @interface CachedContext
TruffleLanguage subclass in
order to identify the language uniquely. The parameter type must be the language context type of
the language or a TruffleLanguage.ContextReference that provides it. The latter parameter allows to
lookup the context lazily, e.g. in a conditional branch. Using this annotation always allows to
generate uncached versions of the node.
This annotation can be used in two different ways:
@GenerateUncached
abstract static class ExampleNode extends Node {
abstract Object execute(Object argument);
@Specialization
static int doInt(int value,
@CachedContext(MyLanguage.class) MyContext context) {
// use context
return value;
}
}
@GenerateUncached
abstract class ExampleNode extends Node {
abstract Object execute(Object argument);
@Specialization
static int doInt(int value,
@CachedContext(MyLanguage.class) ContextReference ref) {
if (value == 42) {
// use context conditionally
MyContext context = ref.get();
}
return value;
}
}
The generated code uses the Node.lookupContextReference(Class) method to implement this
feature. This method may also be used manually.
| Modifier and Type | Required Element and Description |
|---|---|
Class<? extends TruffleLanguage> |
value
Specifies the language the context should be looked up for.
|
public abstract Class<? extends TruffleLanguage> value
TruffleLanguage.Registration.