public final class ForeignAccess extends Object
TruffleObject. If you want to expose your own objects to
foreign language implementations, you need to implement TruffleObject and its
TruffleObject.getForeignAccess() method. To create instance of ForeignAccess
, use one of the factory methods available in this class.| Modifier and Type | Class and Description |
|---|---|
static interface |
ForeignAccess.Factory
Interface of a factory that produces AST snippets that can access a foreign
TruffleObject. |
static interface |
ForeignAccess.StandardFactory
|
| Modifier and Type | Method and Description |
|---|---|
static ForeignAccess |
create(Class<? extends TruffleObject> baseClass,
ForeignAccess.StandardFactory factory)
Creates new instance of
ForeignAccess that delegates to provided factory. |
static ForeignAccess |
create(ForeignAccess.Factory factory)
Creates new instance of
ForeignAccess that delegates to provided factory. |
static ForeignAccess |
create(ForeignAccess.StandardFactory factory,
RootNode languageCheck)
Creates new instance of
ForeignAccess that delegates to provided factory. |
static List<Object> |
getArguments(Frame frame)
Read only access to foreign call arguments inside of a frame.
|
static TruffleObject |
getReceiver(Frame frame)
The foreign receiver in the frame.
|
static Object |
send(Node foreignNode,
TruffleObject receiver,
Object... arguments)
Sends a
Message to the foreign receiver object by executing the
foreign node. |
static long |
sendAsPointer(Node asPointerNode,
TruffleObject receiver)
Sends an
AS_POINTER message to the foreign receiver object by
executing the asPointerNode . |
static Object |
sendExecute(Node executeNode,
TruffleObject receiver,
Object... arguments)
Sends an EXECUTE
Message to the foreign receiver object by executing the
executeNode . |
static Object |
sendGetSize(Node getSizeNode,
TruffleObject receiver)
Sends a
GET_SIZE message to the foreign receiver object by executing
the getSizeNode . |
static boolean |
sendHasKeys(Node hasKeysNode,
TruffleObject receiver)
Sends an
HAS_KEYS message to the foreign receiver object by
executing the hasKeysNode. |
static boolean |
sendHasSize(Node hasSizeNode,
TruffleObject receiver)
Sends an
HAS_SIZE message to the foreign receiver object by
executing the hasSizeNode . |
static Object |
sendInvoke(Node invokeNode,
TruffleObject receiver,
String identifier,
Object... arguments)
Sends an INVOKE
Message to the foreign receiver object by executing the
invokeNode . |
static boolean |
sendIsBoxed(Node isBoxedNode,
TruffleObject receiver)
Sends an
IS_BOXED message to the foreign receiver object by
executing the isNullNode . |
static boolean |
sendIsExecutable(Node isExecutableNode,
TruffleObject receiver)
Sends an
IS_EXECUTABLE message to the foreign receiver object
by executing the isExecutableNode . |
static boolean |
sendIsInstantiable(Node isInstantiableNode,
TruffleObject receiver)
Sends an
IS_INSTANTIABLE message to the foreign receiver
object by executing the isInstantiableNode. |
static boolean |
sendIsNull(Node isNullNode,
TruffleObject receiver)
Sends an
IS_NULL message to the foreign receiver object by executing
the isNullNode . |
static boolean |
sendIsPointer(Node isPointerNode,
TruffleObject receiver)
Sends an
IS_POINTER message to the foreign receiver object by
executing the isPointerNode . |
static int |
sendKeyInfo(Node keyInfoNode,
TruffleObject receiver,
Object identifier)
Sends a
KEY_INFO message to the foreign receiver object by executing
the keyInfoNode. |
static TruffleObject |
sendKeys(Node keysNode,
TruffleObject receiver)
Sends a
Message.KEYS message to the foreign receiver object. |
static TruffleObject |
sendKeys(Node keysNode,
TruffleObject receiver,
boolean includeInternal)
Sends a
Message.KEYS message to the foreign receiver object, with a specification of
whether internal keys should be included in the result, or not. |
static Object |
sendNew(Node newNode,
TruffleObject receiver,
Object... arguments)
Sends an NEW
Message to the foreign receiver object by executing the
newNode . |
static Object |
sendRead(Node readNode,
TruffleObject receiver,
Object identifier)
Sends a
READ message to the foreign receiver object by executing the
readNode . |
static boolean |
sendRemove(Node removeNode,
TruffleObject receiver,
Object identifier)
Sends a
REMOVE message to the foreign receiver object by executing the
removeNode . |
static Object |
sendToNative(Node toNativeNode,
TruffleObject receiver)
Sends an
TO_NATIVE message to the foreign receiver object by
executing the toNativeNode . |
static Object |
sendUnbox(Node unboxNode,
TruffleObject receiver)
Sends an
UNBOX message to the foreign receiver object by executing the
unboxNode . |
static Object |
sendWrite(Node writeNode,
TruffleObject receiver,
Object identifier,
Object value)
Sends a
WRITE message to the foreign receiver object by executing the
writeNode . |
String |
toString() |
public static ForeignAccess create(Class<? extends TruffleObject> baseClass, ForeignAccess.StandardFactory factory)
ForeignAccess that delegates to provided factory.baseClass - the super class of all TruffleObjects handled by this factory (if
null then the second interface must also implement ForeignAccess.Factory)factory - the factory that handles access requests to Messagesfactorypublic static ForeignAccess create(ForeignAccess.StandardFactory factory, RootNode languageCheck)
ForeignAccess that delegates to provided factory.factory - the factory that handles access requests to MessageslanguageCheck - a RootNode that performs the language check on receiver objects,
can be null, but then the factory must also implement ForeignAccess.Factory
interfacefactorypublic static ForeignAccess create(ForeignAccess.Factory factory)
ForeignAccess that delegates to provided factory.factory - the factory that handles various access requests Messages.factorypublic static Object send(Node foreignNode, TruffleObject receiver, Object... arguments) throws InteropException
Message to the foreign receiver object by executing the
foreign node.foreignNode - the createNode created by Message.createNode()receiver - foreign object to receive the message passed to Message.createNode()
methodarguments - parameters for the receiverClassCastException - if the createNode has not been created by
Message.createNode() method.InteropException - if any error occurred while accessing the receiver
objectpublic static Object sendRead(Node readNode, TruffleObject receiver, Object identifier) throws UnknownIdentifierException, UnsupportedMessageException
READ message to the foreign receiver object by executing the
readNode .readNode - the createNode created by Message.createNode()receiver - foreign object to receive the message passed to Message.createNode()
methodidentifier - name of the property to be readClassCastException - if the createNode has not been created by
Message.createNode() method.UnsupportedMessageException - if the receiver does not support the
message represented by readNodeUnknownIdentifierException - if the receiver does not allow reading a
property for the given identifierpublic static Object sendWrite(Node writeNode, TruffleObject receiver, Object identifier, Object value) throws UnknownIdentifierException, UnsupportedTypeException, UnsupportedMessageException
WRITE message to the foreign receiver object by executing the
writeNode .writeNode - the createNode created by Message.createNode()receiver - foreign object to receive the message passed to Message.createNode()
methodidentifier - name of the property to be writtenvalue - value to be writtenClassCastException - if the createNode has not been created by
Message.createNode() method.UnsupportedMessageException - if the receiver does not support the
message represented by writeNodeUnknownIdentifierException - if the receiver does not allow writing a
property for the given identifierUnsupportedTypeException - if value has an unsupported typepublic static boolean sendRemove(Node removeNode, TruffleObject receiver, Object identifier) throws UnknownIdentifierException, UnsupportedMessageException
REMOVE message to the foreign receiver object by executing the
removeNode .removeNode - the node created by Message.createNode()receiver - foreign object to receive the message passed to Message.createNode()
methodidentifier - name of the property to be removedtrue if the property was successfully removed, false
otherwiseClassCastException - if the createNode has not been created by
Message.createNode() method.UnsupportedMessageException - if the receiver does not support the
message represented by readNodeUnknownIdentifierException - if the receiver does not allow removing a
property for the given identifierpublic static Object sendUnbox(Node unboxNode, TruffleObject receiver) throws UnsupportedMessageException
UNBOX message to the foreign receiver object by executing the
unboxNode .unboxNode - the createNode created by Message.createNode()receiver - foreign object to receive the message passed to Message.createNode()
methodClassCastException - if the createNode has not been created by
Message.createNode() method.UnsupportedMessageException - if the receiver does not support the
message represented by unboxNodepublic static boolean sendIsPointer(Node isPointerNode, TruffleObject receiver)
IS_POINTER message to the foreign receiver object by
executing the isPointerNode .isPointerNode - the createNode created by Message.createNode()receiver - foreign object to receive the message passed to Message.createNode()
methodClassCastException - if the createNode has not been created by
Message.createNode() method.public static long sendAsPointer(Node asPointerNode, TruffleObject receiver) throws UnsupportedMessageException
AS_POINTER message to the foreign receiver object by
executing the asPointerNode .asPointerNode - the createNode created by Message.createNode()receiver - foreign object to receive the message passed to Message.createNode()
methodClassCastException - if the createNode has not been created by
Message.createNode() method.UnsupportedMessageException - if the receiver does not support the
message represented by asPointerNodepublic static Object sendToNative(Node toNativeNode, TruffleObject receiver) throws UnsupportedMessageException
TO_NATIVE message to the foreign receiver object by
executing the toNativeNode .toNativeNode - the createNode created by Message.createNode()receiver - foreign object to receive the message passed to Message.createNode()
methodClassCastException - if the createNode has not been created by
Message.createNode() method.UnsupportedMessageException - if the receiver does not support the
message represented by toNativeNodepublic static Object sendExecute(Node executeNode, TruffleObject receiver, Object... arguments) throws UnsupportedTypeException, ArityException, UnsupportedMessageException
Message to the foreign receiver object by executing the
executeNode .executeNode - the createNode created by Message.createNode()receiver - foreign function object to receive the message passed to
Message.createNode() methodarguments - arguments passed to the foreign functionClassCastException - if the createNode has not been created by
Message.createNode() method.UnsupportedTypeException - if one of element of the arguments has an
unsupported typeArityException - if the arguments array does not contain the right number
of arguments for the foreign functionUnsupportedMessageException - if the receiver does not support the
message represented by executeNodepublic static boolean sendIsExecutable(Node isExecutableNode, TruffleObject receiver)
IS_EXECUTABLE message to the foreign receiver object
by executing the isExecutableNode .isExecutableNode - the createNode created by Message.createNode()receiver - foreign object to receive the message passed to Message.createNode()
methodClassCastException - if the createNode has not been created by
Message.createNode() method.public static boolean sendIsInstantiable(Node isInstantiableNode, TruffleObject receiver)
IS_INSTANTIABLE message to the foreign receiver
object by executing the isInstantiableNode.isInstantiableNode - the createNode created by Message.createNode()receiver - foreign object to receive the message passed to Message.createNode()
methodClassCastException - if the createNode has not been created by
Message.createNode() method.public static Object sendInvoke(Node invokeNode, TruffleObject receiver, String identifier, Object... arguments) throws UnsupportedTypeException, ArityException, UnknownIdentifierException, UnsupportedMessageException
Message to the foreign receiver object by executing the
invokeNode .invokeNode - the createNode created by Message.createNode()receiver - foreign function object to receive the message passed to
Message.createNode() methodarguments - arguments passed to the foreign functionClassCastException - if the createNode has not been created by
Message.createNode() method.UnsupportedTypeException - if one of element of the arguments has an
unsupported typeUnknownIdentifierException - if the receiver does not have a property for
the given identifier that can be invokedArityException - if the arguments array does not contain the right number
of arguments for the foreign functionUnsupportedMessageException - if the receiver does not support the
message represented by invokeNodepublic static Object sendNew(Node newNode, TruffleObject receiver, Object... arguments) throws UnsupportedTypeException, ArityException, UnsupportedMessageException
Message to the foreign receiver object by executing the
newNode .newNode - the createNode created by Message.createNode()receiver - foreign function object to receive the message passed to
Message.createNode() methodarguments - arguments passed to the foreign functionClassCastException - if the createNode has not been created by
Message.createNode() method.UnsupportedTypeException - if one of element of the arguments has an
unsupported typeArityException - if the arguments array does not contain the right number
of arguments for the foreign functionUnsupportedMessageException - if the receiver does not support the
message represented by newNodepublic static boolean sendIsNull(Node isNullNode, TruffleObject receiver)
IS_NULL message to the foreign receiver object by executing
the isNullNode .isNullNode - the createNode created by Message.createNode()receiver - foreign object to receive the message passed to Message.createNode()
methodClassCastException - if the createNode has not been created by
Message.createNode() method.public static boolean sendHasSize(Node hasSizeNode, TruffleObject receiver)
HAS_SIZE message to the foreign receiver object by
executing the hasSizeNode .hasSizeNode - the createNode created by Message.createNode()receiver - foreign object to receive the message passed to Message.createNode()
methodClassCastException - if the createNode has not been created by
Message.createNode() method.public static Object sendGetSize(Node getSizeNode, TruffleObject receiver) throws UnsupportedMessageException
GET_SIZE message to the foreign receiver object by executing
the getSizeNode .getSizeNode - the createNode created by Message.createNode()receiver - foreign object to receive the message passed to Message.createNode()
methodClassCastException - if the createNode has not been created by
Message.createNode() method.UnsupportedMessageException - if the receiver does not support the
message represented by getSizeNodepublic static boolean sendIsBoxed(Node isBoxedNode, TruffleObject receiver)
IS_BOXED message to the foreign receiver object by
executing the isNullNode .isBoxedNode - the createNode created by Message.createNode()receiver - foreign object to receive the message passed to Message.createNode()
methodClassCastException - if the createNode has not been created by
Message.createNode() method.public static int sendKeyInfo(Node keyInfoNode, TruffleObject receiver, Object identifier)
KEY_INFO message to the foreign receiver object by executing
the keyInfoNode. If the object does not support the message, the presence of the
key is found by iteration over it's keys on a slow path and a default info is returned.keyInfoNode - the createNode created by Message.createNode()receiver - foreign object to receive the message passed to Message.createNode()
methodidentifier - name of the property to get the info of.KeyInfo.ClassCastException - if the createNode has not been created by
Message.createNode() method.public static boolean sendHasKeys(Node hasKeysNode, TruffleObject receiver)
HAS_KEYS message to the foreign receiver object by
executing the hasKeysNode. If the object does not support the message, a
Message.KEYS message is sent to test the presence of keys.hasKeysNode - the createNode created by Message.createNode()receiver - foreign object to receive the message passed to Message.createNode()
methodClassCastException - if the createNode has not been created by
Message.createNode() method.public static TruffleObject sendKeys(Node keysNode, TruffleObject receiver) throws UnsupportedMessageException
Message.KEYS message to the foreign receiver object.keysNode - the createNode created by Message.createNode()receiver - foreign object to receive the message passed to Message.createNode()
methodTruffleObject that responds to Message.HAS_SIZE
and Message.GET_SIZE and its 0 to size - 1 indexes
contain String names of the properties of the receiver objectUnsupportedMessageException - if the message isn't handledClassCastException - if the createNode has not been created by
Message.createNode() method.public static TruffleObject sendKeys(Node keysNode, TruffleObject receiver, boolean includeInternal) throws UnsupportedMessageException
Message.KEYS message to the foreign receiver object, with a specification of
whether internal keys should be included in the result, or not.keysNode - the createNode created by Message.createNode()receiver - foreign object to receive the message passed to Message.createNode()
methodincludeInternal - true to include internal keys in the result,
false to abandon them.TruffleObject that responds to Message.HAS_SIZE
and Message.GET_SIZE and its 0 to size - 1 indexes
contain String names of the properties of the receiver objectUnsupportedMessageException - if the message isn't handledClassCastException - if the createNode has not been created by
Message.createNode() method.public static List<Object> getArguments(Frame frame)
frame - the frame that was called via
ForeignAccess.send(com.oracle.truffle.api.nodes.Node, com.oracle.truffle.api.interop.TruffleObject, java.lang.Object...)public static TruffleObject getReceiver(Frame frame)
frame - the frame that was called via
ForeignAccess.send(com.oracle.truffle.api.nodes.Node, com.oracle.truffle.api.interop.TruffleObject, java.lang.Object...)