@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. Use Resolve to annotate Node implementations of messages. Those messages
for which no Resolve is provided are either left unsupported, or in case of
HAS/IS messages they get a default boolean value depending on presence of
corresponding messages. E.g. HAS_SIZE is true if and only if GET_SIZE
is provided, IS_EXECUTABLE is true if and only if EXECUTE is provided,
etc. If objects support some messages conditionally, they should provide their own implementation
of HAS/IS messages. 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().