Annotation to put on your node to simplify handling of incoming inter-operability
messages.
This node needs to be an abstract class. Sub-classes will be automatically generated, which is
similar to Truffle's DSL for node specialization. The node needs to define
accept
methods, which implement the node's behaviour. The first argument of
accept can be a
VirtualFrame (optional). The second argument of
accept needs to be the
receiver object, i.e., a
TruffleObject. Afterwards, the arguments of the message follow.
For example:
@MessageResolution(receiverType = ExampleTruffleObject.class)
public static class ExampleTruffleObjectMR {
@Resolve(message = "READ")
public abstract static class ExampleReadNode extends Node {
protected Object access(ExampleTruffleObject receiver,
String name) {
if (ExampleTruffleObject.MEMBER_NAME.equals(name)) {
return receiver.getValue();
}
throw UnknownIdentifierException.raise(name);
}
}
@Resolve(message = "WRITE")
public abstract static class ExampleWriteNode extends Node {
protected static int access(ExampleTruffleObject receiver,
String name, int value) {
if (ExampleTruffleObject.MEMBER_NAME.equals(name)) {
receiver.setValue(value);
return value;
}
throw UnknownIdentifierException.raise(name);
}
}
@CanResolve
public abstract static class Check extends Node {
protected static boolean test(TruffleObject receiver) {
return receiver instanceof ExampleTruffleObject;
}
}
}