@Target(value=TYPE) @Retention(value=SOURCE) public @interface MessageResolution
messages.
This class contains the node implementations for all messages that the receiver object should
resolve. Elements in the super class that are annotated with Resolve will be ignored. For
example:
@The receiver object needs to implement a static methodMessageResolution(receiverType = ExampleTruffleObject.class) public static class ExampleTruffleObjectMR { @Resolve(message = "READ") public abstract static class ExampleReadNode extendsNode{ protectedObjectaccess(ExampleTruffleObject receiver,Stringname) { if (ExampleTruffleObject.MEMBER_NAME.equals(name)) { return receiver.getValue(); } throwUnknownIdentifierException.raise(name); } } @Resolve(message = "WRITE") public abstract static class ExampleWriteNode extendsNode{ protected static int access(ExampleTruffleObject receiver,Stringname, int value) { if (ExampleTruffleObject.MEMBER_NAME.equals(name)) { receiver.setValue(value); return value; } throwUnknownIdentifierException.raise(name); } } @CanResolvepublic abstract static class Check extendsNode{ protected static boolean test(TruffleObjectreceiver) { return receiver instanceof ExampleTruffleObject; } } }
isInstance, which checks if a
given foreign object is an instance of the given receiver type and can therefore be accessed by
this node. For example:
public static boolean isInstance(TruffleObject obj) {
return obj instanceof ExampleTruffleObject;
}
Alternatively, one can also define a language check node (see CanResolve.
From this class a ForeignAccess will be generated. The receiver object can then return a
singleton instance of this access. For example: public ForeignAccess getForeignAccess() {
return ExampleTruffleObjectMRForeign.ACCESS;
}
| Modifier and Type | Required Element and Description |
|---|---|
Class<?> |
receiverType
The receiver object class that this message implementation belongs to.
|
public abstract Class<?> receiverType
ForeignAccess class, which the
TruffleObject can use to implement TruffleObject.getForeignAccess().