Class InteropLibrary
- All Implemented Interfaces:
NodeInterface
,Cloneable
The interop API differentiates between the source and the target language. The source language is
the language that implements/exports the message implementations. The implementations map types
of the source language to the interop protocol as it is specified by the protocol. For example,
language values that represent arrays or array like structures should implement the messages for
array based access
. This allows the target language to call the
protocol without knowledge of the concrete source language. The target language embeds the
interop protocol semantics as part of their existing language semantics. For example, language
operations that access array elements in the target language should call
array access
messages for interop values.
The interop protocol only allows interop values to be used as receivers, return values or parameters of messages. Allowed Java types of interop values are:
TruffleObject
: Any object that implements theTruffleObject
interface is interpreted according to the interop messages itexports
. Truffle objects are expected but not required to export interop library messages.String
andCharacter
are interpreted asstring
value.Boolean
is interpreted asboolean
value.Byte
,Short
,Integer
,Long
,Float
andDouble
are interpreted asnumber
values.
null
is never a valid interop value. Instead, use a
TruffleObject
which implements isNull(Object)
message.
The following type combinations are mutually exclusive and cannot return true
for
the type check message of the same receiver value:
executable
instantiable
pointer
members
hash entries
array elements
buffer elements
language
associated metaobject
metaobject parents as array elements
declaring meta object
source location
identity
scope parent
executable name
exception message
exception cause
exception stack trace
iterator
Naive and aware dates and times
If a date or time value has a timezone
then it is called aware
, otherwise naive
An aware time and date has sufficient knowledge of applicable algorithmic and political time adjustments, such as time zone and daylight saving time information, to locate itself relative to other aware objects. An aware object is used to represent a specific moment in time that is not open to interpretation.
A naive time and date does not contain enough information to unambiguously locate itself relative to other date/time objects. Whether a naive object represents Coordinated Universal Time (UTC), local time, or time in some other timezone is purely up to the program, just like it is up to the program whether a particular number represents metres, miles, or mass. Naive objects are easy to understand and to work with, at the cost of ignoring some aspects of reality.
Interop messages throw checked exceptions
to indicate error states. The
target language is supposed to always catch those exceptions and translate them into guest
language errors of the target language. Interop message contracts are verified only if assertions
(-ea) are enabled.
- Since:
- 19.0
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.oracle.truffle.api.nodes.Node
Node.Child, Node.Children
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionasBigInteger
(Object receiver) Returns the receiver value as Java BigInteger if the number fits without loss of precision.boolean
Returns the Java boolean value if the receiver represents aboolean
like value.byte
Returns the receiver value as Java byte primitive if the number fits without loss of precision.Returns the receiver as date if this object represents adate
.double
Returns the receiver value as Java double primitive if the number fits without loss of precision.asDuration
(Object receiver) Returns the receiver as duration if this object represents aduration
.float
Returns the receiver value as Java float primitive if the number fits without loss of precision.Returns the receiver as instant if this object represents aninstant
.int
Returns the receiver value as Java int primitive if the number fits without loss of precision.long
Returns the receiver value as Java long primitive if the number fits without loss of precision.long
Returns the pointer value as long value if the receiver represents a pointer like value.protected final boolean
Utility for libraries to require adoption before cached versions of nodes can be executed.short
Returns the receiver value as Java short primitive if the number fits without loss of precision.Returns the Java string value if the receiver represents astring
like value.Returns the receiver as time if this object represents atime
.asTimeZone
(Object receiver) Returns the receiver as timestamp if this object represents atimezone
.asTruffleString
(Object receiver) Returns theTruffleString
value if the receiver represents astring
like value.Executes an executable value with the given arguments.boolean
fitsInBigInteger
(Object receiver) Returnstrue
if the receiver represents anumber
and its value fits in a Java BigInteger without loss of precision, elsefalse
.boolean
fitsInByte
(Object receiver) Returnstrue
if the receiver represents anumber
and its value fits in a Java byte primitive without loss of precision, elsefalse
.boolean
fitsInDouble
(Object receiver) Returnstrue
if the receiver represents anumber
and its value fits in a Java double primitive without loss of precision, elsefalse
.boolean
fitsInFloat
(Object receiver) Returnstrue
if the receiver represents anumber
and its value fits in a Java float primitive without loss of precision, elsefalse
.boolean
Returnstrue
if the receiver represents anumber
and its value fits in a Java int primitive without loss of precision, elsefalse
.boolean
fitsInLong
(Object receiver) Returnstrue
if the receiver represents anumber
and its value fits in a Java long primitive without loss of precision, elsefalse
.boolean
fitsInShort
(Object receiver) Returnstrue
if the receiver represents anumber
and its value fits in a Java short primitive without loss of precision, elsefalse
.long
getArraySize
(Object receiver) Returns the array size of the receiver.long
getBufferSize
(Object receiver) Returns the buffer size of the receiver, in bytes.getDeclaringMetaObject
(Object receiver) Returns declaring meta object.getExceptionCause
(Object receiver) Returns the internal cause of the receiver.int
getExceptionExitStatus
(Object receiver) Returns exception exit status of the receiver.getExceptionMessage
(Object receiver) Returns exception message of the receiver.getExceptionStackTrace
(Object receiver) Returns the exception stack trace of the receiver that is of type exception.getExceptionType
(Object receiver) Returnsexception type
of the receiver.getExecutableName
(Object receiver) Returns executable name of the receiver.static LibraryFactory
<InteropLibrary> Returns the library factory for the interop library.getHashEntriesIterator
(Object receiver) Returns the hash entries iterator for the receiver.getHashKeysIterator
(Object receiver) Returns the hash keys iterator for the receiver.long
getHashSize
(Object receiver) Returns the number of receiver entries.getHashValuesIterator
(Object receiver) Returns the hash values iterator for the receiver.getIterator
(Object receiver) Returns the iterator for the receiver.getIteratorNextElement
(Object receiver) Returns the next element in the iteration.Class
<? extends TruffleLanguage<?>> getLanguage
(Object receiver) Returns the the original language of the receiver value.final Object
getMembers
(Object receiver) Short-cut forgetMembers(receiver, false)
.getMembers
(Object receiver, boolean includeInternal) Returns an array of member name strings.getMetaObject
(Object receiver) Returns the metaobject that is associated with this value.getMetaParents
(Object receiver) Returns an array likehasArrayElements(Object)
of metaobjects that are direct parents (super types) of this metaobject.getMetaQualifiedName
(Object metaObject) Returns the qualified name of a metaobject asstring
.getMetaSimpleName
(Object metaObject) Returns the simple name of a metaobject asstring
.getScopeParent
(Object receiver) Returns the parent scope object if ithas the parent
.getSourceLocation
(Object receiver) Returns the declared source location of the receiver value.static InteropLibrary
Returns the uncached automatically dispatched version of the interop library.static InteropLibrary
Returns the uncached manually dispatched version of the interop library.boolean
hasArrayElements
(Object receiver) Returnstrue
if the receiver may have array elements.boolean
hasBufferElements
(Object receiver) Returnstrue
if the receiver may have buffer elements.boolean
hasDeclaringMetaObject
(Object receiver) Returnstrue
if the receiver has a declaring meta object.boolean
hasExceptionCause
(Object receiver) Returnstrue
if the receiver is an exception with an attached internal cause.boolean
hasExceptionMessage
(Object receiver) Returnstrue
if the receiver is an exception that has an exception message.boolean
hasExceptionStackTrace
(Object receiver) Returnstrue
if the receiver is an exception and has a stack trace.boolean
hasExecutableName
(Object receiver) Returnstrue
if the receiver has an executable name.boolean
hasHashEntries
(Object receiver) Returnstrue
if the receiver may have hash entries.final boolean
hasIdentity
(Object receiver) Returnstrue
if and only if the receiver specifies identity, elsefalse
.boolean
hasIterator
(Object receiver) Returnstrue
if the receiver provides an iterator.boolean
hasIteratorNextElement
(Object receiver) Returnstrue
if the receiver is an iterator which has more elements, elsefalse
.boolean
hasLanguage
(Object receiver) Returnstrue
if the receiver originates from a language, elsefalse
.boolean
hasMemberReadSideEffects
(Object receiver, String member) Returnstrue
if reading a member may cause a side-effect.boolean
hasMembers
(Object receiver) Returnstrue
if the receiver may have members.boolean
hasMemberWriteSideEffects
(Object receiver, String member) Returnstrue
if writing a member may cause a side-effect, besides the write operation of the member.boolean
hasMetaObject
(Object receiver) Returnstrue
if the receiver value has a metaobject associated.boolean
hasMetaParents
(Object receiver) Returnstrue
if the receiver valueis a metaobject
which has parents (super types).boolean
hasScopeParent
(Object receiver) Returnstrue
if this scope has an enclosing parent scope, elsefalse
.boolean
hasSourceLocation
(Object receiver) Returnstrue
if the receiver value has a declared source location attached, elsefalse
.int
identityHashCode
(Object receiver) Returns an identity hash code for the receiver if it hasidentity
.instantiate
(Object receiver, Object... arguments) Instantiates the receiver value with the given arguments.invokeMember
(Object receiver, String member, Object... arguments) Invokes a member for a given receiver and arguments.final boolean
isArrayElementExisting
(Object receiver, long index) Returns true if the array element is existing.boolean
isArrayElementInsertable
(Object receiver, long index) Returnstrue
if a given array element index is not existing andinsertable
.boolean
isArrayElementModifiable
(Object receiver, long index) Returnstrue
if a given array element index is existing andwritable
.boolean
isArrayElementReadable
(Object receiver, long index) Returnstrue
if a given array element isreadable
.boolean
isArrayElementRemovable
(Object receiver, long index) Returnstrue
if a given array element index is existing andremovable
.final boolean
isArrayElementWritable
(Object receiver, long index) Returns true if the array element ismodifiable
orinsertable
.boolean
Returnstrue
if the receiver represents aboolean
like value, elsefalse
.boolean
isBufferWritable
(Object receiver) Returnstrue
if the receiver is a modifiable buffer.boolean
Returnstrue
if this object represents a date, elsefalse
.boolean
isDuration
(Object receiver) Returnstrue
if this object represents a duration, elsefalse
.boolean
isException
(Object receiver) Returnstrue
if the receiver value represents a throwable exception/error}.boolean
isExceptionIncompleteSource
(Object receiver) Returnstrue
if receiver value represents an incomplete source exception.boolean
isExecutable
(Object receiver) Returnstrue
if the receiver represents anexecutable
value, elsefalse
.boolean
isHashEntryExisting
(Object receiver, Object key) Returnstrue
if mapping for a given key is existing.boolean
isHashEntryInsertable
(Object receiver, Object key) Returnstrue
if mapping for the specified key does not exist and iswritable
.boolean
isHashEntryModifiable
(Object receiver, Object key) Returnstrue
if mapping for the specified key exists and iswritable
.boolean
isHashEntryReadable
(Object receiver, Object key) Returnstrue
if mapping for the specified key exists and isreadable
.boolean
isHashEntryRemovable
(Object receiver, Object key) Returnstrue
if mapping for the specified key exists and is removable.boolean
isHashEntryWritable
(Object receiver, Object key) boolean
isIdentical
(Object receiver, Object other, InteropLibrary otherInterop) Returnstrue
if two values represent the the identical value, elsefalse
.protected TriState
isIdenticalOrUndefined
(Object receiver, Object other) final boolean
Returnstrue
if the receiver represents an instant.boolean
isInstantiable
(Object receiver) Returnstrue
if the receiver represents aninstantiable
value, elsefalse
.boolean
isIterator
(Object receiver) Returnstrue
if the receiver represents an iterator.final boolean
isMemberExisting
(Object receiver, String member) Returns true if the member is existing.boolean
isMemberInsertable
(Object receiver, String member) Returnstrue
if a given member is not existing andwritable
.boolean
isMemberInternal
(Object receiver, String member) Returns true if a member is internal.boolean
isMemberInvocable
(Object receiver, String member) Returnstrue
if a given member is invocable.boolean
isMemberModifiable
(Object receiver, String member) Returnstrue
if a given member is existing andwritable
.boolean
isMemberReadable
(Object receiver, String member) Returnstrue
if a given member isreadable
.boolean
isMemberRemovable
(Object receiver, String member) Returnstrue
if a given member is existing and removable.final boolean
isMemberWritable
(Object receiver, String member) Returns true if the member ismodifiable
orinsertable
.boolean
isMetaInstance
(Object receiver, Object instance) Returnstrue
if the given instance is of the provided receiver metaobject, elsefalse
.boolean
isMetaObject
(Object receiver) Returnstrue
if the receiver value represents a metaobject.boolean
Returnstrue
if the receiver represents anull
like value, elsefalse
.boolean
Returnstrue
if the receiver represents anumber
value, elsefalse
.boolean
Returnstrue
if the receiver value represents a native pointer.boolean
Returnstrue
if the value represents a scope object, elsefalse
.boolean
Returnstrue
if the receiver represents astring
value, elsefalse
.boolean
Returnstrue
if this object represents a time, elsefalse
.boolean
isTimeZone
(Object receiver) Returnstrue
if this object represents a timezone, elsefalse
.static boolean
isValidProtocolValue
(Object value) Utility to check whether a value is a valid interop protocol value.static boolean
isValidValue
(Object receiver) Utility to check whether a value is a valid interop value.readArrayElement
(Object receiver, long index) Reads the value of an array element by index.void
readBuffer
(Object receiver, long byteOffset, byte[] destination, int destinationOffset, int length) Reads bytes from the receiver object into the specified byte array.byte
readBufferByte
(Object receiver, long byteOffset) Reads the byte from the receiver object at the given byte offset from the start of the buffer.double
readBufferDouble
(Object receiver, ByteOrder order, long byteOffset) Reads the double from the receiver object in the given byte order at the given byte offset from the start of the buffer.float
readBufferFloat
(Object receiver, ByteOrder order, long byteOffset) Reads the float from the receiver object in the given byte order at the given byte offset from the start of the buffer.int
readBufferInt
(Object receiver, ByteOrder order, long byteOffset) Reads the int from the receiver object in the given byte order at the given byte offset from the start of the buffer.long
readBufferLong
(Object receiver, ByteOrder order, long byteOffset) Reads the long from the receiver object in the given byte order at the given byte offset from the start of the buffer.short
readBufferShort
(Object receiver, ByteOrder order, long byteOffset) Reads the short from the receiver object in the given byte order at the given byte offset from the start of the buffer.readHashValue
(Object receiver, Object key) Reads the value for the specified key.readHashValueOrDefault
(Object receiver, Object key, Object defaultValue) Reads the value for the specified key or returns thedefaultValue
when the mapping for the specified key does not exist or is not readable.readMember
(Object receiver, String member) Reads the value of a given member.void
removeArrayElement
(Object receiver, long index) Remove an array element from the receiver object.void
removeHashEntry
(Object receiver, Object key) Removes the mapping for a given key from the receiver.void
removeMember
(Object receiver, String member) Removes a member from the receiver object.throwException
(Object receiver) Throws the receiver object as an exception of the source language, as if it was thrown by the source language itself.final Object
toDisplayString
(Object receiver) Converts the receiver to a human readablestring
of the language.toDisplayString
(Object receiver, boolean allowSideEffects) Converts the receiver to a human readablestring
.void
Attempts to transform areceiver
to a value that represents a raw native pointer.void
writeArrayElement
(Object receiver, long index, Object value) Writes the value of an array element by index.void
writeBufferByte
(Object receiver, long byteOffset, byte value) Writes the given byte from the receiver object at the given byte offset from the start of the buffer.void
writeBufferDouble
(Object receiver, ByteOrder order, long byteOffset, double value) Writes the given double from the receiver object in the given byte order at the given byte offset from the start of the buffer.void
writeBufferFloat
(Object receiver, ByteOrder order, long byteOffset, float value) Writes the given float from the receiver object in the given byte order at the given byte offset from the start of the buffer.void
writeBufferInt
(Object receiver, ByteOrder order, long byteOffset, int value) Writes the given int from the receiver object in the given byte order at the given byte offset from the start of the buffer.void
writeBufferLong
(Object receiver, ByteOrder order, long byteOffset, long value) Writes the given long from the receiver object in the given byte order at the given byte offset from the start of the buffer.void
writeBufferShort
(Object receiver, ByteOrder order, long byteOffset, short value) Writes the given short from the receiver object in the given byte order at the given byte offset from the start of the buffer.void
writeHashEntry
(Object receiver, Object key, Object value) Associates the specified value with the specified key in the receiver.void
writeMember
(Object receiver, String member, Object value) Writes the value of a given member.Methods inherited from class com.oracle.truffle.api.nodes.Node
accept, adoptChildren, atomic, atomic, copy, deepCopy, getChildren, getCost, getDebugProperties, getDescription, getEncapsulatingSourceSection, getLock, getParent, getRootNode, getSourceSection, insert, insert, isAdoptable, isSafelyReplaceableBy, notifyInserted, onReplace, replace, replace, reportPolymorphicSpecialize, reportReplace, toString
-
Constructor Details
-
InteropLibrary
protected InteropLibrary()- Since:
- 19.0
-
-
Method Details
-
isNull
Returnstrue
if the receiver represents anull
like value, elsefalse
. Most object oriented languages have one or many values representing null values. Invoking this message does not cause any observable side-effects.- Since:
- 19.0
-
isBoolean
Returnstrue
if the receiver represents aboolean
like value, elsefalse
. Invoking this message does not cause any observable side-effects.- Since:
- 19.0
- See Also:
-
asBoolean
Returns the Java boolean value if the receiver represents aboolean
like value.- Throws:
UnsupportedMessageException
- if and only ifisBoolean(Object)
returnsfalse
for the same receiver.- Since:
- 19.0
- See Also:
-
isExecutable
Returnstrue
if the receiver represents anexecutable
value, elsefalse
. Functions, methods or closures are common examples of executable values. Invoking this message does not cause any observable side-effects. Note that receiver values which areexecutable
might also beinstantiable
.- Since:
- 19.0
- See Also:
-
execute
public Object execute(Object receiver, Object... arguments) throws UnsupportedTypeException, ArityException, UnsupportedMessageException Executes an executable value with the given arguments.- Throws:
UnsupportedTypeException
- if one of the arguments is not compatible to the executable signature. The exception is thrown on best effort basis, dynamic languages may throw their own exceptions if the arguments are wrong.ArityException
- if the number of expected arguments does not match the number of actual arguments.UnsupportedMessageException
- if and only ifisExecutable(Object)
returnsfalse
for the same receiver.- Since:
- 19.0
- See Also:
-
hasExecutableName
Returnstrue
if the receiver has an executable name. Invoking this message does not cause any observable side-effects. Returnsfalse
by default.- Since:
- 20.3
- See Also:
-
getExecutableName
Returns executable name of the receiver. ThrowsUnsupportedMessageException
when the receiver is has noexecutable name
. The return value is an interop value that is guaranteed to returntrue
forisString(Object)
.- Throws:
UnsupportedMessageException
- Since:
- 20.3
- See Also:
-
hasDeclaringMetaObject
Returnstrue
if the receiver has a declaring meta object. The declaring meta object is the meta object of the executable or meta object that declares the receiver value. Invoking this message does not cause any observable side-effects. Returnsfalse
by default.- Since:
- 20.3
- See Also:
-
getDeclaringMetaObject
Returns declaring meta object. The declaring meta object is the meta object of declaring executable or meta object. ThrowsUnsupportedMessageException
when the receiver is has nodeclaring meta object
. The return value is an interop value that is guaranteed to returntrue
forisMetaObject(Object)
.- Throws:
UnsupportedMessageException
- Since:
- 20.3
- See Also:
-
isInstantiable
Returnstrue
if the receiver represents aninstantiable
value, elsefalse
. Contructors ormetaobjects
are typical examples of instantiable values. Invoking this message does not cause any observable side-effects. Note that receiver values which areexecutable
might also beinstantiable
.- Since:
- 19.0
- See Also:
-
instantiate
public Object instantiate(Object receiver, Object... arguments) throws UnsupportedTypeException, ArityException, UnsupportedMessageException Instantiates the receiver value with the given arguments. The returned object must be initialized correctly according to the language specification (e.g. by calling the constructor or initialization routine).- Throws:
UnsupportedTypeException
- if one of the arguments is not compatible to the executable signatureArityException
- if the number of expected arguments does not match the number of actual arguments.UnsupportedMessageException
- if and only ifisInstantiable(Object)
returnsfalse
for the same receiver.- Since:
- 19.0
- See Also:
-
isString
Returnstrue
if the receiver represents astring
value, elsefalse
. Invoking this message does not cause any observable side-effects.- Since:
- 19.0
- See Also:
-
asString
Returns the Java string value if the receiver represents astring
like value.- Throws:
UnsupportedMessageException
- if and only ifisString(Object)
returnsfalse
for the same receiver.- Since:
- 19.0
- See Also:
-
asTruffleString
Returns theTruffleString
value if the receiver represents astring
like value.- Throws:
UnsupportedMessageException
- if and only ifisString(Object)
returnsfalse
for the same receiver.- Since:
- 21.3
- See Also:
-
isNumber
Returnstrue
if the receiver represents anumber
value, elsefalse
. Invoking this message does not cause any observable side-effects.- Since:
- 19.0
- See Also:
-
fitsInByte
Returnstrue
if the receiver represents anumber
and its value fits in a Java byte primitive without loss of precision, elsefalse
. Invoking this message does not cause any observable side-effects.- Since:
- 19.0
- See Also:
-
fitsInShort
Returnstrue
if the receiver represents anumber
and its value fits in a Java short primitive without loss of precision, elsefalse
. Invoking this message does not cause any observable side-effects.- Since:
- 19.0
- See Also:
-
fitsInInt
Returnstrue
if the receiver represents anumber
and its value fits in a Java int primitive without loss of precision, elsefalse
. Invoking this message does not cause any observable side-effects.- Since:
- 19.0
- See Also:
-
fitsInLong
Returnstrue
if the receiver represents anumber
and its value fits in a Java long primitive without loss of precision, elsefalse
. Invoking this message does not cause any observable side-effects.- Since:
- 19.0
- See Also:
-
fitsInBigInteger
Returnstrue
if the receiver represents anumber
and its value fits in a Java BigInteger without loss of precision, elsefalse
. Invoking this message does not cause any observable side-effects.- Since:
- 23.0
- See Also:
-
fitsInFloat
Returnstrue
if the receiver represents anumber
and its value fits in a Java float primitive without loss of precision, elsefalse
. Invoking this message does not cause any observable side-effects.- Since:
- 19.0
- See Also:
-
fitsInDouble
Returnstrue
if the receiver represents anumber
and its value fits in a Java double primitive without loss of precision, elsefalse
. Invoking this message does not cause any observable side-effects.- Since:
- 19.0
- See Also:
-
asByte
Returns the receiver value as Java byte primitive if the number fits without loss of precision. Invoking this message does not cause any observable side-effects.- Throws:
UnsupportedMessageException
- if and only if the receiver is not aisNumber(Object)
or it does not fit without loss of precision.- Since:
- 19.0
- See Also:
-
asShort
Returns the receiver value as Java short primitive if the number fits without loss of precision. Invoking this message does not cause any observable side-effects.- Throws:
UnsupportedMessageException
- if and only if the receiver is not aisNumber(Object)
or it does not fit without loss of precision.- Since:
- 19.0
- See Also:
-
asInt
Returns the receiver value as Java int primitive if the number fits without loss of precision. Invoking this message does not cause any observable side-effects.- Throws:
UnsupportedMessageException
- if and only if the receiver is not aisNumber(Object)
or it does not fit without loss of precision.- Since:
- 19.0
- See Also:
-
asLong
Returns the receiver value as Java long primitive if the number fits without loss of precision. Invoking this message does not cause any observable side-effects.- Throws:
UnsupportedMessageException
- if and only if the receiver is not aisNumber(Object)
or it does not fit without loss of precision.- Since:
- 19.0
- See Also:
-
asBigInteger
Returns the receiver value as Java BigInteger if the number fits without loss of precision. Invoking this message does not cause any observable side-effects.- Throws:
UnsupportedMessageException
- if and only if the receiver is not aisNumber(Object)
or it does not fit without loss of precision.- Since:
- 23.0
- See Also:
-
asFloat
Returns the receiver value as Java float primitive if the number fits without loss of precision. Invoking this message does not cause any observable side-effects.- Throws:
UnsupportedMessageException
- if and only if the receiver is not aisNumber(Object)
or it does not fit without loss of precision.- Since:
- 19.0
- See Also:
-
asDouble
Returns the receiver value as Java double primitive if the number fits without loss of precision. Invoking this message does not cause any observable side-effects.- Throws:
UnsupportedMessageException
- if and only if the receiver is not aisNumber(Object)
or it does not fit without loss of precision.- Since:
- 19.0
- See Also:
-
hasMembers
Returnstrue
if the receiver may have members. Therefore, at least one ofreadMember(Object, String)
,writeMember(Object, String, Object)
,removeMember(Object, String)
,invokeMember(Object, String, Object...)
must not throwUnsupportedMessageException
. Members are structural elements of a class. For example, a method or field is a member of a class. Invoking this message does not cause any observable side-effects. Returnsfalse
by default.- Since:
- 19.0
- See Also:
-
getMembers
public Object getMembers(Object receiver, boolean includeInternal) throws UnsupportedMessageException Returns an array of member name strings. The returned value must returntrue
forhasArrayElements(Object)
and every array element must be of typestring
. The member elements may also provide additional information likesource location
in case ofscope
variables, etc.The order of member names needs to be:
- deterministic, assuming the program execution is deterministic,
- in the declaration order, when applicable,
- multiple invocations of this method must return the same members in the same order as long as no side-effecting operations were performed.
true
then internal member names are returned as well. Internal members are implementation specific and should not be exposed to guest language application. An example of internal members are internal slots in ECMAScript.- Throws:
UnsupportedMessageException
- if and only if the receiver does not have anymembers
.- Since:
- 19.0
- See Also:
-
getMembers
Short-cut forgetMembers(receiver, false)
. Invoking this message does not cause any observable side-effects.- Throws:
UnsupportedMessageException
- if and only if the receiver has nomembers
.- Since:
- 19.0
- See Also:
-
isMemberReadable
Returnstrue
if a given member isreadable
. This method may only returntrue
ifhasMembers(Object)
returnstrue
as well andisMemberInsertable(Object, String)
returnsfalse
. Invoking this message does not cause any observable side-effects. Returnsfalse
by default.- Since:
- 19.0
- See Also:
-
readMember
public Object readMember(Object receiver, String member) throws UnsupportedMessageException, UnknownIdentifierException Reads the value of a given member.In case of a method-like member, we recommend that languages return a bound method (or an artificial receiver-method binding) to improve cross-language portability. In this case, the member should be
readable
andinvocable
and the result of reading the member should beexecutable
and bound to the receiver.This message must have not observable side-effects unless
hasMemberReadSideEffects(Object, String)
returnstrue
.- Throws:
UnsupportedMessageException
- if when the receiver does not support reading at all. An empty receiver with no readable members supports the read operation (even though there is nothing to read), therefore it throwsUnknownIdentifierException
for all arguments instead.UnknownIdentifierException
- if the given member cannot be read, e.g. because it is not (or no longer)readable
such as when the member with the given name does not exist or has been removed.- Since:
- 19.0
- See Also:
-
isMemberModifiable
Returnstrue
if a given member is existing andwritable
. This method may only returntrue
ifhasMembers(Object)
returnstrue
as well andisMemberInsertable(Object, String)
returnsfalse
. Invoking this message does not cause any observable side-effects. Returnsfalse
by default.- Since:
- 19.0
- See Also:
-
isMemberInsertable
Returnstrue
if a given member is not existing andwritable
. This method may only returntrue
ifhasMembers(Object)
returnstrue
as well andisMemberExisting(Object, String)
returnsfalse
. Invoking this message does not cause any observable side-effects. Returnsfalse
by default.- Since:
- 19.0
- See Also:
-
writeMember
public void writeMember(Object receiver, String member, Object value) throws UnsupportedMessageException, UnknownIdentifierException, UnsupportedTypeException Writes the value of a given member. Writing a member is allowed if is existing andmodifiable
, or not existing andinsertable
. This method must have no observable side-effects other than the changed member unlessside-effects
are allowed.- Throws:
UnsupportedMessageException
- when the receiver does not support writing at all, e.g. when it is immutable.UnknownIdentifierException
- if the given member is notmodifiable
norinsertable
.UnsupportedTypeException
- if the provided value type is not allowed to be written.- Since:
- 19.0
- See Also:
-
isMemberRemovable
Returnstrue
if a given member is existing and removable. This method may only returntrue
ifhasMembers(Object)
returnstrue
as well andisMemberInsertable(Object, String)
returnsfalse
. Invoking this message does not cause any observable side-effects. Returnsfalse
by default.- Since:
- 19.0
- See Also:
-
removeMember
public void removeMember(Object receiver, String member) throws UnsupportedMessageException, UnknownIdentifierException Removes a member from the receiver object. Removing member is allowed if isremovable
. This method does not have not observable side-effects other than the removed member.- Throws:
UnsupportedMessageException
- when the receiver does not support removing at all, e.g. when it is immutable.UnknownIdentifierException
- if the given member is notisMemberRemovable(Object, String)
removable}, e.g. the receiver does not have a member with the given name.- Since:
- 19.0
- See Also:
-
isMemberInvocable
Returnstrue
if a given member is invocable. This method may only returntrue
ifhasMembers(Object)
returnstrue
as well andisMemberInsertable(Object, String)
returnsfalse
. Invoking this message does not cause any observable side-effects. Returnsfalse
by default.- Since:
- 19.0
- See Also:
-
invokeMember
public Object invokeMember(Object receiver, String member, Object... arguments) throws UnsupportedMessageException, ArityException, UnknownIdentifierException, UnsupportedTypeException Invokes a member for a given receiver and arguments.- Throws:
UnknownIdentifierException
- if the given member does not exist or is notinvocable
.UnsupportedTypeException
- if one of the arguments is not compatible to the executable signature. The exception is thrown on best effort basis, dynamic languages may throw their own exceptions if the arguments are wrong.ArityException
- if the number of expected arguments does not match the number of actual arguments.UnsupportedMessageException
- when the receiver does not support invoking at all, e.g. when storing executable members is not allowed.- Since:
- 19.0
- See Also:
-
isMemberInternal
Returns true if a member is internal. Internal members are not enumerated bygetMembers(Object, boolean)
by default. Internal members are only relevant to guest language implementations and tools, but not to guest applications or embedders. An example of internal members are internal slots in ECMAScript. Invoking this message does not cause any observable side-effects. Returnsfalse
by default.- Since:
- 19.0
- See Also:
-
isMemberWritable
Returns true if the member ismodifiable
orinsertable
.- Since:
- 19.0
-
isMemberExisting
Returns true if the member is existing. A member is existing if it ismodifiable
,readable
,removable
orinvocable
.- Since:
- 19.0
-
hasMemberReadSideEffects
Returnstrue
if reading a member may cause a side-effect. Invoking this message does not cause any observable side-effects. A member read does not cause any side-effects by default.For instance in JavaScript a property read may have side-effects if the property has a getter function.
- Since:
- 19.0
- See Also:
-
hasMemberWriteSideEffects
Returnstrue
if writing a member may cause a side-effect, besides the write operation of the member. Invoking this message does not cause any observable side-effects. A member write does not cause any side-effects by default.For instance in JavaScript a property write may have side-effects if the property has a setter function.
- Since:
- 19.0
- See Also:
-
hasHashEntries
Returnstrue
if the receiver may have hash entries. Therefore, at least one ofreadHashValue(Object, Object)
,writeHashEntry(Object, Object, Object)
,removeHashEntry(Object, Object)
must not throwUnsupportedMessageException
. For example, the contents of a map data structure could be interpreted as hash elements. Invoking this message does not cause any observable side-effects. Returnsfalse
by default.- Since:
- 21.1
- See Also:
-
getHashSize
Returns the number of receiver entries.- Throws:
UnsupportedMessageException
- if and only ifhasHashEntries(Object)
returnsfalse
.- Since:
- 21.1
-
isHashEntryReadable
Returnstrue
if mapping for the specified key exists and isreadable
. This method may only returntrue
ifhasHashEntries(Object)
returnstrue
as well andisHashEntryInsertable(Object, Object)
returnsfalse
. Invoking this message does not cause any observable side-effects. Returnsfalse
by default.- Since:
- 21.1
- See Also:
-
readHashValue
public Object readHashValue(Object receiver, Object key) throws UnsupportedMessageException, UnknownKeyException Reads the value for the specified key.- Throws:
UnsupportedMessageException
- if the receiver does not support reading at all. An empty receiver with no readable hash entries supports the read operation (even though there is nothing to read), therefore it throwsUnknownKeyException
for all arguments instead.UnknownKeyException
- if mapping for the specified key is notreadable
, e.g. when the hash does not contain specified key.- Since:
- 21.1
- See Also:
-
readHashValueOrDefault
public Object readHashValueOrDefault(Object receiver, Object key, Object defaultValue) throws UnsupportedMessageException Reads the value for the specified key or returns thedefaultValue
when the mapping for the specified key does not exist or is not readable.- Throws:
UnsupportedMessageException
- if the receiver does not support reading at all. An empty receiver with no readable hash entries supports the read operation (even though there is nothing to read), therefore it returns thedefaultValue
for all arguments instead.- Since:
- 21.1
- See Also:
-
isHashEntryModifiable
Returnstrue
if mapping for the specified key exists and iswritable
. This method may only returntrue
ifhasHashEntries(Object)
returnstrue
as well andisHashEntryInsertable(Object, Object)
returnsfalse
. Invoking this message does not cause any observable side-effects. Returnsfalse
by default.- Since:
- 21.1
- See Also:
-
isHashEntryInsertable
Returnstrue
if mapping for the specified key does not exist and iswritable
. This method may only returntrue
ifhasHashEntries(Object)
returnstrue
as well andisHashEntryExisting(Object, Object)
returnsfalse
. Invoking this message does not cause any observable side-effects. Returnsfalse
by default.- Since:
- 21.1
- See Also:
-
isHashEntryWritable
- Since:
- 21.1
-
writeHashEntry
public void writeHashEntry(Object receiver, Object key, Object value) throws UnsupportedMessageException, UnknownKeyException, UnsupportedTypeException Associates the specified value with the specified key in the receiver. Writing the entry is allowed if is existing andmodifiable
, or not existing andinsertable
.- Throws:
UnsupportedMessageException
- when the receiver does not support writing at all, e.g. when it is immutable.UnknownKeyException
- if mapping for the specified key is notmodifiable
norinsertable
.UnsupportedTypeException
- if the provided key type or value type is not allowed to be written.- Since:
- 21.1
-
isHashEntryRemovable
Returnstrue
if mapping for the specified key exists and is removable. This method may only returntrue
ifhasHashEntries(Object)
returnstrue
as well andisHashEntryInsertable(Object, Object)
returnsfalse
. Invoking this message does not cause any observable side-effects. Returnsfalse
by default.- Since:
- 21.1
- See Also:
-
removeHashEntry
public void removeHashEntry(Object receiver, Object key) throws UnsupportedMessageException, UnknownKeyException Removes the mapping for a given key from the receiver. Mapping removing is allowed if it isremovable
.- Throws:
UnsupportedMessageException
- when the receiver does not support removing at all, e.g. when it is immutable.UnknownKeyException
- if the given mapping is notremovable
, e.g. the receiver does not have a mapping for given key.- Since:
- 21.1
- See Also:
-
isHashEntryExisting
Returnstrue
if mapping for a given key is existing. The mapping is existing if it ismodifiable
,readable
orremovable
.- Since:
- 21.1
-
getHashEntriesIterator
Returns the hash entries iterator for the receiver. The return value is always aniterator
ofarray
elements. The first array element is a key, the second array element is an associated value. Array returned by the iterator may be modifiable but detached from the hash, updating the array elements may not update the hash. So even if array elements aremodifiable
always usewriteHashEntry(Object, Object, Object)
to update the hash mapping.- Throws:
UnsupportedMessageException
- if and only ifhasHashEntries(Object)
returnsfalse
for the same receiver.- Since:
- 21.1
-
getHashKeysIterator
Returns the hash keys iterator for the receiver. The return value is always aniterator
.- Throws:
UnsupportedMessageException
- if and only ifhasHashEntries(Object)
returnsfalse
for the same receiver.- Since:
- 21.1
-
getHashValuesIterator
Returns the hash values iterator for the receiver. The return value is always aniterator
.- Throws:
UnsupportedMessageException
- if and only ifhasHashEntries(Object)
returnsfalse
for the same receiver.- Since:
- 21.1
-
hasArrayElements
Returnstrue
if the receiver may have array elements. Therefore, At least one ofreadArrayElement(Object, long)
,writeArrayElement(Object, long, Object)
,removeArrayElement(Object, long)
must not throw {#linkUnsupportedMessageException
. For example, the contents of an array or list datastructure could be interpreted as array elements. Invoking this message does not cause any observable side-effects. Returnsfalse
by default.- Since:
- 19.0
- See Also:
-
readArrayElement
public Object readArrayElement(Object receiver, long index) throws UnsupportedMessageException, InvalidArrayIndexException Reads the value of an array element by index. This method must have not observable side-effect.- Throws:
UnsupportedMessageException
- when the receiver does not support reading at all. An empty receiver with no readable array elements supports the read operation (even though there is nothing to read), therefore it throwsUnknownIdentifierException
for all arguments instead.InvalidArrayIndexException
- if the given index is notreadable
, e.g. when the index is invalid or the index is out of bounds.- Since:
- 19.0
-
getArraySize
Returns the array size of the receiver.- Throws:
UnsupportedMessageException
- if and only ifhasArrayElements(Object)
returnsfalse
.- Since:
- 19.0
-
isArrayElementReadable
Returnstrue
if a given array element isreadable
. This method may only returntrue
ifhasArrayElements(Object)
returnstrue
as well. Invoking this message does not cause any observable side-effects. Returnsfalse
by default.- Since:
- 19.0
- See Also:
-
writeArrayElement
public void writeArrayElement(Object receiver, long index, Object value) throws UnsupportedMessageException, UnsupportedTypeException, InvalidArrayIndexException Writes the value of an array element by index. Writing an array element is allowed if is existing andmodifiable
, or not existing andinsertable
. This method must have not observable side-effects other than the changed array element.- Throws:
UnsupportedMessageException
- when the receiver does not support writing at all, e.g. when it is immutable.InvalidArrayIndexException
- if the given index is notinsertable
normodifiable
, e.g. when the index is invalid or the index is out of bounds and the array does not support growing.UnsupportedTypeException
- if the provided value type is not allowed to be written.- Since:
- 19.0
-
removeArrayElement
public void removeArrayElement(Object receiver, long index) throws UnsupportedMessageException, InvalidArrayIndexException Remove an array element from the receiver object. Removing member is allowed if the array element isremovable
. This method may only returntrue
ifhasArrayElements(Object)
returnstrue
as well andisArrayElementInsertable(Object, long)
returnsfalse
. This method does not have observable side-effects other than the removed array element and shift of remaining elements. If shifting is not supported then the array might allow only removal of last element.- Throws:
UnsupportedMessageException
- when the receiver does not support removing at all, e.g. when it is immutable.InvalidArrayIndexException
- if the given index is notremovable
, e.g. when the index is invalid, the index is out of bounds, or the array does not support shifting of remaining elements.- Since:
- 19.0
- See Also:
-
isArrayElementModifiable
Returnstrue
if a given array element index is existing andwritable
. This method may only returntrue
ifhasArrayElements(Object)
returnstrue
as well andisArrayElementInsertable(Object, long)
returnsfalse
. Invoking this message does not cause any observable side-effects. Returnsfalse
by default.- Since:
- 19.0
- See Also:
-
isArrayElementInsertable
Returnstrue
if a given array element index is not existing andinsertable
. This method may only returntrue
ifhasArrayElements(Object)
returnstrue
as well andisArrayElementExisting(Object, long)
} returnsfalse
. Invoking this message does not cause any observable side-effects. Returnsfalse
by default.- Since:
- 19.0
- See Also:
-
isArrayElementRemovable
Returnstrue
if a given array element index is existing andremovable
. This method may only returntrue
ifhasArrayElements(Object)
returnstrue
as well andisArrayElementInsertable(Object, long)
} returnsfalse
. Invoking this message does not cause any observable side-effects. Returnsfalse
by default.- Since:
- 19.0
- See Also:
-
isArrayElementWritable
Returns true if the array element ismodifiable
orinsertable
.- Since:
- 19.0
-
isArrayElementExisting
Returns true if the array element is existing. An array element is existing if it is,modifiable
,readable
orremovable
.- Since:
- 19.0
-
hasBufferElements
Returnstrue
if the receiver may have buffer elements.If this message returns
true
, thengetBufferSize(Object)
,readBufferByte(Object, long)
,readBufferShort(Object, ByteOrder, long)
,readBufferInt(Object, ByteOrder, long)
,readBufferLong(Object, ByteOrder, long)
,readBufferFloat(Object, ByteOrder, long)
andreadBufferDouble(Object, ByteOrder, long)
must not throwUnsupportedMessageException
.Invoking this message does not cause any observable side-effects.
By default, it returns
false
.- Since:
- 21.1
-
isBufferWritable
Returnstrue
if the receiver is a modifiable buffer.If this message returns
true
, thengetBufferSize(Object)
,writeBufferByte(Object, long, byte)
,writeBufferShort(Object, ByteOrder, long, short)
,writeBufferInt(Object, ByteOrder, long, int)
,writeBufferLong(Object, ByteOrder, long, long)
,writeBufferFloat(Object, ByteOrder, long, float)
andwriteBufferDouble(Object, ByteOrder, long, double)
must not throwUnsupportedMessageException
.Invoking this message does not cause any observable side-effects.
By default, it returns
false
ifhasBufferElements(Object)
returntrue
, and throwsUnsupportedMessageException
otherwise.- Throws:
UnsupportedMessageException
- if and only ifhasBufferElements(Object)
returnsfalse
- Since:
- 21.1
-
getBufferSize
Returns the buffer size of the receiver, in bytes.Invoking this message does not cause any observable side-effects.
- Throws:
UnsupportedMessageException
- if and only ifhasBufferElements(Object)
returnsfalse
- Since:
- 21.1
-
readBufferByte
public byte readBufferByte(Object receiver, long byteOffset) throws UnsupportedMessageException, InvalidBufferOffsetException Reads the byte from the receiver object at the given byte offset from the start of the buffer.The access is not guaranteed to be atomic. Therefore, this message is not thread-safe.
Invoking this message does not cause any observable side-effects.
- Returns:
- the byte at the given index
- Throws:
InvalidBufferOffsetException
- if and only ifbyteOffset < 0 || byteOffset >=
getBufferSize(Object)
UnsupportedMessageException
- if and only ifhasBufferElements(Object)
returnsfalse
- Since:
- 21.1
-
readBuffer
public void readBuffer(Object receiver, long byteOffset, byte[] destination, int destinationOffset, int length) throws UnsupportedMessageException, InvalidBufferOffsetException Reads bytes from the receiver object into the specified byte array.The access is not guaranteed to be atomic. Therefore, this message is not thread-safe.
Invoking this message does not cause any observable side-effects.
- Parameters:
byteOffset
- offset in the buffer to start reading from.destination
- byte array to write the read bytes into.destinationOffset
- offset in the destination array to start writing from.length
- number of bytes to read.- Throws:
InvalidBufferOffsetException
- if and only ifbyteOffset < 0 || length < 0 || byteOffset + length >
getBufferSize(Object)
UnsupportedMessageException
- if and only ifhasBufferElements(Object)
returnsfalse
- Since:
- 24.0
-
writeBufferByte
public void writeBufferByte(Object receiver, long byteOffset, byte value) throws UnsupportedMessageException, InvalidBufferOffsetException Writes the given byte from the receiver object at the given byte offset from the start of the buffer.The access is not guaranteed to be atomic. Therefore, this message is not thread-safe.
- Throws:
InvalidBufferOffsetException
- if and only ifbyteOffset < 0 || byteOffset >=
getBufferSize(Object)
UnsupportedMessageException
- if and only if eitherhasBufferElements(Object)
orisBufferWritable(java.lang.Object)
returnsfalse
- Since:
- 21.1
-
readBufferShort
public short readBufferShort(Object receiver, ByteOrder order, long byteOffset) throws UnsupportedMessageException, InvalidBufferOffsetException Reads the short from the receiver object in the given byte order at the given byte offset from the start of the buffer.Unaligned accesses are supported.
The access is not guaranteed to be atomic. Therefore, this message is not thread-safe.
Invoking this message does not cause any observable side-effects.
- Returns:
- the short at the given byte offset from the start of the buffer
- Throws:
InvalidBufferOffsetException
- if and only ifbyteOffset < 0 || byteOffset >=
getBufferSize(Object)
- 1UnsupportedMessageException
- if and only ifhasBufferElements(Object)
returnsfalse
- Since:
- 21.1
-
writeBufferShort
public void writeBufferShort(Object receiver, ByteOrder order, long byteOffset, short value) throws UnsupportedMessageException, InvalidBufferOffsetException Writes the given short from the receiver object in the given byte order at the given byte offset from the start of the buffer.Unaligned accesses are supported.
The access is not guaranteed to be atomic. Therefore, this message is not thread-safe.
- Throws:
InvalidBufferOffsetException
- if and only ifbyteOffset < 0 || byteOffset >=
getBufferSize(Object)
- 1UnsupportedMessageException
- if and only if eitherhasBufferElements(Object)
orisBufferWritable(java.lang.Object)
returnsfalse
- Since:
- 21.1
-
readBufferInt
public int readBufferInt(Object receiver, ByteOrder order, long byteOffset) throws UnsupportedMessageException, InvalidBufferOffsetException Reads the int from the receiver object in the given byte order at the given byte offset from the start of the buffer.Unaligned accesses are supported.
The access is not guaranteed to be atomic. Therefore, this message is not thread-safe.
Invoking this message does not cause any observable side-effects.
- Returns:
- the int at the given byte offset from the start of the buffer
- Throws:
InvalidBufferOffsetException
- if and only ifbyteOffset < 0 || byteOffset >=
getBufferSize(Object)
- 3UnsupportedMessageException
- if and only ifhasBufferElements(Object)
returnsfalse
- Since:
- 21.1
-
writeBufferInt
public void writeBufferInt(Object receiver, ByteOrder order, long byteOffset, int value) throws UnsupportedMessageException, InvalidBufferOffsetException Writes the given int from the receiver object in the given byte order at the given byte offset from the start of the buffer.Unaligned accesses are supported.
The access is not guaranteed to be atomic. Therefore, this message is not thread-safe.
- Throws:
InvalidBufferOffsetException
- if and only ifbyteOffset < 0 || byteOffset >=
getBufferSize(Object)
- 3UnsupportedMessageException
- if and only if eitherhasBufferElements(Object)
orisBufferWritable(java.lang.Object)
returnsfalse
- Since:
- 21.1
-
readBufferLong
public long readBufferLong(Object receiver, ByteOrder order, long byteOffset) throws UnsupportedMessageException, InvalidBufferOffsetException Reads the long from the receiver object in the given byte order at the given byte offset from the start of the buffer.Unaligned accesses are supported.
The access is not guaranteed to be atomic. Therefore, this message is not thread-safe.
Invoking this message does not cause any observable side-effects.
- Returns:
- the int at the given byte offset from the start of the buffer
- Throws:
InvalidBufferOffsetException
- if and only ifbyteOffset < 0 || byteOffset >=
getBufferSize(Object)
- 7UnsupportedMessageException
- if and only ifhasBufferElements(Object)
returnsfalse
- Since:
- 21.1
-
writeBufferLong
public void writeBufferLong(Object receiver, ByteOrder order, long byteOffset, long value) throws UnsupportedMessageException, InvalidBufferOffsetException Writes the given long from the receiver object in the given byte order at the given byte offset from the start of the buffer.Unaligned accesses are supported.
The access is not guaranteed to be atomic. Therefore, this message is not thread-safe.
- Throws:
InvalidBufferOffsetException
- if and only ifbyteOffset < 0 || byteOffset >=
getBufferSize(Object)
- 7UnsupportedMessageException
- if and only if eitherhasBufferElements(Object)
orisBufferWritable(java.lang.Object)
returnsfalse
- Since:
- 21.1
-
readBufferFloat
public float readBufferFloat(Object receiver, ByteOrder order, long byteOffset) throws UnsupportedMessageException, InvalidBufferOffsetException Reads the float from the receiver object in the given byte order at the given byte offset from the start of the buffer.Unaligned accesses are supported.
The access is not guaranteed to be atomic. Therefore, this message is not thread-safe.
Invoking this message does not cause any observable side-effects.
- Returns:
- the float at the given byte offset from the start of the buffer
- Throws:
InvalidBufferOffsetException
- if and only ifbyteOffset < 0 || byteOffset >=
getBufferSize(Object)
- 3UnsupportedMessageException
- if and only ifhasBufferElements(Object)
returnsfalse
- Since:
- 21.1
-
writeBufferFloat
public void writeBufferFloat(Object receiver, ByteOrder order, long byteOffset, float value) throws UnsupportedMessageException, InvalidBufferOffsetException Writes the given float from the receiver object in the given byte order at the given byte offset from the start of the buffer.Unaligned accesses are supported.
The access is not guaranteed to be atomic. Therefore, this message is not thread-safe.
- Throws:
InvalidBufferOffsetException
- if and only ifbyteOffset < 0 || byteOffset >=
getBufferSize(Object)
- 3UnsupportedMessageException
- if and only if eitherhasBufferElements(Object)
orisBufferWritable(java.lang.Object)
returnsfalse
- Since:
- 21.1
-
readBufferDouble
public double readBufferDouble(Object receiver, ByteOrder order, long byteOffset) throws UnsupportedMessageException, InvalidBufferOffsetException Reads the double from the receiver object in the given byte order at the given byte offset from the start of the buffer.Unaligned accesses are supported.
The access is not guaranteed to be atomic. Therefore, this message is not thread-safe.
Invoking this message does not cause any observable side-effects.
- Returns:
- the double at the given byte offset from the start of the buffer
- Throws:
InvalidBufferOffsetException
- if and only ifbyteOffset < 0 || byteOffset >=
getBufferSize(Object)
- 7UnsupportedMessageException
- if and only ifhasBufferElements(Object)
returnsfalse
- Since:
- 21.1
-
writeBufferDouble
public void writeBufferDouble(Object receiver, ByteOrder order, long byteOffset, double value) throws UnsupportedMessageException, InvalidBufferOffsetException Writes the given double from the receiver object in the given byte order at the given byte offset from the start of the buffer.Unaligned accesses are supported.
The access is not guaranteed to be atomic. Therefore, this message is not thread-safe.
- Throws:
InvalidBufferOffsetException
- if and only ifbyteOffset < 0 || byteOffset >=
getBufferSize(Object)
- 7UnsupportedMessageException
- if and only if eitherhasBufferElements(Object)
orisBufferWritable(java.lang.Object)
returnsfalse
- Since:
- 21.1
-
isPointer
Returnstrue
if the receiver value represents a native pointer. Native pointers are represented as 64 bit pointers. Invoking this message does not cause any observable side-effects. Returnsfalse
by default.It is expected that objects should only return
true
if the native pointer value corresponding to this object already exists, and obtaining it is a cheap operation. If an object can be transformed to a pointer representation, but this hasn't happened yet, the object is expected to returnfalse
withisPointer(Object)
, and wait for thetoNative(Object)
message to trigger the transformation.- Since:
- 19.0
- See Also:
-
asPointer
Returns the pointer value as long value if the receiver represents a pointer like value.- Throws:
UnsupportedMessageException
- if and only ifisPointer(Object)
returnsfalse
for the same receiver.- Since:
- 19.0
- See Also:
-
toNative
Attempts to transform areceiver
to a value that represents a raw native pointer. After a successful transformation, the provided receiver returns true forisPointer(Object)
and can be unwrapped using theasPointer(Object)
message. If transformation cannot be doneisPointer(Object)
will keep returning false.- Since:
- 19.0
- See Also:
-
asInstant
Returns the receiver as instant if this object represents aninstant
. If a value is an instant then it is also adate
,time
andtimezone
. Using this method may be more efficient than reconstructing the timestamp from the date, time and timezone data.Implementers should implement this method if they can provide a more efficient conversion to Instant than reconstructing it from date, time and timezone date. Implementers must ensure that the following Java code snippet always holds:
ZoneId zone = getTimeZone(receiver); LocalDate date = getDate(receiver); LocalTime time = getTime(receiver); assert ZonedDateTime.of(date, time, zone).toInstant().equals(getInstant(receiver));
- Throws:
UnsupportedMessageException
- if and only ifisInstant(Object)
returnsfalse
.- Since:
- 20.0.0 beta 2
- See Also:
-
isInstant
Returnstrue
if the receiver represents an instant. If a value is an instant then it is also adate
,time
andtimezone
. This method is short-hand for:isDate(v) &&
isTime
(v) &&isTimeZone
(v)- Since:
- 20.0.0 beta 2
- See Also:
-
isTimeZone
Returnstrue
if this object represents a timezone, elsefalse
. The interpretation of timezone objects may vary:- If
isDate(Object)
andisTime(Object)
returntrue
, then the returned date or time information is aware of this timezone. - If
isDate(Object)
andisTime(Object)
returnsfalse
, then it represents just timezone information.
fixed zone
only. If this rule is violated then anAssertionError
is thrown if assertions are enabled.If this method is implemented then also
asTimeZone(Object)
must be implemented.- Since:
- 20.0.0 beta 2
- See Also:
- If
-
asTimeZone
Returns the receiver as timestamp if this object represents atimezone
.- Throws:
UnsupportedMessageException
- if and only ifisTimeZone(Object)
returnsfalse
.- Since:
- 20.0.0 beta 2
- See Also:
-
isDate
Returnstrue
if this object represents a date, elsefalse
. If the receiver is also atimezone
then the date is aware, otherwise it is naive.- Since:
- 20.0.0 beta 2
- See Also:
-
asDate
Returns the receiver as date if this object represents adate
. The returned date is either aware if the receiver has atimezone
otherwise it is naive.- Throws:
UnsupportedMessageException
- if and only ifisDate(Object)
returnsfalse
.- Since:
- 20.0.0 beta 2
- See Also:
-
isTime
Returnstrue
if this object represents a time, elsefalse
. If the receiver is also atimezone
then the time is aware, otherwise it is naive.- Since:
- 20.0.0 beta 2
- See Also:
-
asTime
Returns the receiver as time if this object represents atime
. The returned time is either aware if the receiver has atimezone
otherwise it is naive.- Throws:
UnsupportedMessageException
- if and only ifisTime(Object)
returnsfalse
.- Since:
- 20.0.0 beta 2
- See Also:
-
isDuration
Returnstrue
if this object represents a duration, elsefalse
.- Since:
- 20.0.0 beta 2
- See Also:
-
asDuration
Returns the receiver as duration if this object represents aduration
.- Throws:
UnsupportedMessageException
- if and only ifisDuration(Object)
returnsfalse
.- Since:
- 20.0.0 beta 2
- See Also:
-
isException
Returnstrue
if the receiver value represents a throwable exception/error}. Invoking this message does not cause any observable side-effects. Returnsfalse
by default.Objects must only return
true
if they supportthrowException(java.lang.Object)
as well. If this method is implemented then alsothrowException(Object)
must be implemented. The following simplifiedTryCatchNode
shows how the exceptions should be handled by languages.static final class TryCatchNode extends StatementNode { @Node.Child private BlockNode block; @Node.Child private BlockNode catchBlock; @Node.Child private BlockNode finallyBlock; private final BranchProfile exceptionProfile; TryCatchNode(BlockNode block, BlockNode catchBlock, BlockNode finallyBlock) { this.block = block; this.catchBlock = catchBlock; this.finallyBlock = finallyBlock; this.exceptionProfile = BranchProfile.create(); } @Override void executeVoid(VirtualFrame frame) { RuntimeException rethrowException = null; try { block.executeVoid(frame); } catch (AbstractTruffleException ex) { exceptionProfile.enter(); try { if (catchBlock != null) { catchBlock.executeVoid(frame); // do not rethrow if handled rethrowException = null; } else { // rethrow if not handled rethrowException = ex; } } catch (AbstractTruffleException e) { rethrowException = e; } } catch (ControlFlowException cfe) { // run finally blocks for control flow rethrowException = cfe; } // Java finally blocks that execute nodes are not allowed for // compilation as code in finally blocks is duplicated // by the Java bytecode compiler. This can lead to // exponential code growth in worst cases. if (finallyBlock != null) { finallyBlock.executeVoid(frame); } if (rethrowException != null) { throw rethrowException; } } }
- Since:
- 19.3
- See Also:
-
throwException
Throws the receiver object as an exception of the source language, as if it was thrown by the source language itself. Allows rethrowing exceptions caught by another language. If this method is implemented then alsoisException(Object)
must be implemented.Any interop value can be an exception value and export
throwException(Object)
. The exception thrown by this message must extendAbstractTruffleException
. In future versions this contract will be enforced using an assertion.For a sample
TryCatchNode
implementation seeisException
.- Throws:
UnsupportedMessageException
- if and only ifisException(Object)
returnsfalse
for the same receiver.- Since:
- 19.3
- See Also:
-
getExceptionType
Returnsexception type
of the receiver. ThrowsUnsupportedMessageException
when the receiver is not anexception
.For a sample
TryCatchNode
implementation seeisException
.- Throws:
UnsupportedMessageException
- Since:
- 20.3
- See Also:
-
isExceptionIncompleteSource
Returnstrue
if receiver value represents an incomplete source exception. ThrowsUnsupportedMessageException
when the receiver is not anexception
or the exception is not aExceptionType.PARSE_ERROR
.- Throws:
UnsupportedMessageException
- Since:
- 20.3
- See Also:
-
getExceptionExitStatus
Returns exception exit status of the receiver. ThrowsUnsupportedMessageException
when the receiver is not anexception
of theexit type
. See Context Exit for further information. A return value zero indicates that the execution of the application was successful, a non-zero value that it failed. The individual interpretation of non-zero values depends on the application.- Throws:
UnsupportedMessageException
- Since:
- 20.3
- See Also:
-
hasExceptionCause
Returnstrue
if the receiver is an exception with an attached internal cause. Invoking this message does not cause any observable side-effects. Returnsfalse
by default.- Since:
- 20.3
- See Also:
-
getExceptionCause
Returns the internal cause of the receiver. ThrowsUnsupportedMessageException
when the receiver is not anexception
or has no internal cause. The return value of this message is guaranteed to returntrue
forisException(Object)
.- Throws:
UnsupportedMessageException
- Since:
- 20.3
- See Also:
-
hasExceptionMessage
Returnstrue
if the receiver is an exception that has an exception message. Invoking this message does not cause any observable side-effects. Returnsfalse
by default.- Since:
- 20.3
- See Also:
-
getExceptionMessage
Returns exception message of the receiver. ThrowsUnsupportedMessageException
when the receiver is not anexception
or has no exception message. The return value of this message is guaranteed to returntrue
forisString(Object)
.- Throws:
UnsupportedMessageException
- Since:
- 20.3
- See Also:
-
hasExceptionStackTrace
Returnstrue
if the receiver is an exception and has a stack trace. Invoking this message does not cause any observable side-effects. Returnsfalse
by default.- Since:
- 20.3
- See Also:
-
getExceptionStackTrace
Returns the exception stack trace of the receiver that is of type exception. Returns anarray
of objects with potentiallyexecutable name
,declaring meta object
andsource location
of the caller. ThrowsUnsupportedMessageException
when the receiver is not anexception
or has no stack trace. Invoking this message or accessing the stack trace elements array must not cause any observable side-effects.The default implementation of
getExceptionStackTrace(Object)
callsTruffleStackTrace.getStackTrace(Throwable)
on the underlying exception object andTruffleStackTraceElement.getGuestObject()
to access an interop capable object of the underlying stack trace element.- Throws:
UnsupportedMessageException
- Since:
- 20.3
- See Also:
-
hasIterator
Returnstrue
if the receiver provides an iterator. For example, an array or a list provide an iterator over their content. Invoking this message does not cause any observable side-effects. By default returnstrue
for receivers that havearray elements
.- Since:
- 21.1
- See Also:
-
getIterator
Returns the iterator for the receiver. The return value is always aniterator
. Invoking this message does not cause any observable side-effects.- Throws:
UnsupportedMessageException
- if and only ifhasIterator(Object)
returnsfalse
for the same receiver.- Since:
- 21.1
-
isIterator
Returnstrue
if the receiver represents an iterator. Invoking this message does not cause any observable side-effects. Returnsfalse
by default.- Since:
- 21.1
- See Also:
-
hasIteratorNextElement
Returnstrue
if the receiver is an iterator which has more elements, elsefalse
. Multiple calls to thehasIteratorNextElement(Object)
might lead to different results if the underlying data structure is modified.The following example shows how the
hasIteratorNextElement
message can be emulated in languages where iterators only have a next method and throw an exception if there are no further elements.@ExportLibrary(InteropLibrary.class) abstract class InteropIterator implements TruffleObject { @SuppressWarnings("serial") public static final class Stop extends AbstractTruffleException { } private static final Object STOP = new Object(); private Object next; protected InteropIterator() { } protected abstract Object next() throws Stop; @ExportMessage @SuppressWarnings("static-method") boolean isIterator() { return true; } @ExportMessage boolean hasIteratorNextElement() { fetchNext(); return next != STOP; } @ExportMessage Object getIteratorNextElement() throws StopIterationException { fetchNext(); Object res = next; if (res == STOP) { throw StopIterationException.create(); } else { next = null; } return res; } private void fetchNext() { if (next == null) { try { next = next(); } catch (Stop stop) { next = STOP; } } } }
- Throws:
UnsupportedMessageException
- if and only ifisIterator(Object)
returnsfalse
for the same receiver.- Since:
- 21.1
- See Also:
-
getIteratorNextElement
public Object getIteratorNextElement(Object receiver) throws UnsupportedMessageException, StopIterationException Returns the next element in the iteration. When the underlying data structure is modified thegetIteratorNextElement(Object)
may throw theStopIterationException
despite thehasIteratorNextElement(Object)
returnedtrue
.- Throws:
UnsupportedMessageException
- ifisIterator(Object)
returnsfalse
for the same receiver or when the underlying iterator element exists but is not readable.StopIterationException
- if the iteration has no more elements. Even if theStopIterationException
was thrown it might not be thrown again by a nextgetIteratorNextElement(Object)
invocation on the same receiver due to a modification of an underlying iterable.- Since:
- 21.1
- See Also:
-
hasSourceLocation
Returnstrue
if the receiver value has a declared source location attached, elsefalse
. Returning a source location for a value is optional and typically impacts the capabilities of tools like debuggers to jump to the declaration of a value.Examples for values that may provide a source location:
Metaobjects
like classes or types.- First class
executables
, like functions, closures or promises. - Allocation sites for instances. Note that in most languages it is very expensive to track
the allocation site of an instance and it is therefore not recommended to support this
feature by default, but ideally behind an optional language option.
This method must not cause any observable side-effects. If this method is implemented then also
getSourceLocation(Object)
must be implemented.
- Since:
- 20.1
- See Also:
-
getSourceLocation
Returns the declared source location of the receiver value. Throws anUnsupportedMessageException
if the value does not have a declared source location. SeehasSourceLocation(Object)
for further details on potential interpretations. ThrowsUnsupportedMessageException
by default.This method must not cause any observable side-effects. If this method is implemented then also
hasSourceLocation(Object)
must be implemented.- Throws:
UnsupportedMessageException
- if and only ifhasSourceLocation(Object)
returnsfalse
for the same receiver.- Since:
- 20.1
-
hasLanguage
Returnstrue
if the receiver originates from a language, elsefalse
. Primitive values or other shared interop value representations that are not associated with a language may returnfalse
. Values that originate from a language should returntrue
. Returnsfalse
by default.The associated language allows tools to identify the original language of a value. If an instrument requests a
language view
then values that are already associated with a language will just return the same value. OtherwiseTruffleLanguage.getLanguageView(Object, Object)
will be invoked on the language. The returned language may be also exposed to embedders in the future.This method must not cause any observable side-effects. If this method is implemented then also
getLanguage(Object)
andtoDisplayString(Object, boolean)
must be implemented.- Since:
- 20.1
- See Also:
-
getLanguage
public Class<? extends TruffleLanguage<?>> getLanguage(Object receiver) throws UnsupportedMessageException Returns the the original language of the receiver value. The returned language class must be non-null and represent a validregistered
language class. For more details seehasLanguage(Object)
.This method must not cause any observable side-effects. If this method is implemented then also
hasLanguage(Object)
must be implemented.- Throws:
UnsupportedMessageException
- if and only ifhasLanguage(Object)
returnsfalse
for the same receiver.- Since:
- 20.1
-
hasMetaObject
Returnstrue
if the receiver value has a metaobject associated. The metaobject represents a description of the object, reveals its kind and its features. Some information that a metaobject might define includes the base object's type, interface, class, methods, attributes, etc. Should returnfalse
when no metaobject is known for this type. Returnsfalse
by default.An example, for Java objects the returned metaobject is the
class
instance. In JavaScript this could be the function or class that is associated with the object.Metaobjects for primitive values or values of other languages may be provided using
language views
. While an object is associated with a metaobject in one language, the metaobject might be a different when viewed from another language.This method must not cause any observable side-effects. If this method is implemented then also
getMetaObject(Object)
must be implemented.- Since:
- 20.1
- See Also:
-
getMetaObject
Returns the metaobject that is associated with this value. The metaobject represents a description of the object, reveals its kind and its features. Some information that a metaobject might define includes the base object's type, interface, class, methods, attributes, etc. When no metaobject is known for this type. ThrowsUnsupportedMessageException
by default.The returned object must return
true
forisMetaObject(Object)
and provide implementations forgetMetaSimpleName(Object)
,getMetaQualifiedName(Object)
, andisMetaInstance(Object, Object)
. For all values with metaobjects it must at hold thatisMetaInstance(getMetaObject(value), value) == true
.This method must not cause any observable side-effects. If this method is implemented then also
hasMetaObject(Object)
must be implemented.- Throws:
UnsupportedMessageException
- if and only ifhasMetaObject(Object)
returnsfalse
for the same receiver.- Since:
- 20.1
- See Also:
-
toDisplayString
Converts the receiver to a human readablestring
. Each language may have special formating conventions - even primitive values may not follow the traditional Java rules. The format of the returned string is intended to be interpreted by humans not machines and should therefore not be relied upon by machines. By default the receiver class name and itsidentity hash code
is used as string representation.String representations for primitive values or values of other languages may be provided using
language views
. It is common that languages provide different string representations for primitive and foreign values. To convert the result value to a Java string useasString(Object)
.- Parameters:
allowSideEffects
- whether side-effects are allowed in the production of the string.- Since:
- 20.1
- See Also:
-
toDisplayString
Converts the receiver to a human readablestring
of the language. Short-cut for
.toDisplayString(Object, true)
- Since:
- 20.1
- See Also:
-
isMetaObject
Returnstrue
if the receiver value represents a metaobject. Metaobjects may be values that naturally occur in a language or they may be returned bygetMetaObject(Object)
. A metaobject represents a description of the object, reveals its kind and its features. If a receiver is a metaobject it is often alsoinstantiable
, but this is not a requirement.Sample interpretations: In Java an instance of the type
Class
is a metaobject. In JavaScript any function instance is a metaobject. For example, the metaobject of a JavaScript class is the associated constructor function.This method must not cause any observable side-effects. If this method is implemented then also
getMetaQualifiedName(Object)
,getMetaSimpleName(Object)
andisMetaInstance(Object, Object)
must be implemented as well.- Since:
- 20.1
-
getMetaQualifiedName
Returns the qualified name of a metaobject asstring
.Sample interpretations: The qualified name of a Java class includes the package name and its class name. JavaScript does not have the notion of qualified name and therefore returns the
simple name
instead.This method must not cause any observable side-effects. If this method is implemented then also
isMetaObject(Object)
must be implemented as well.- Throws:
UnsupportedMessageException
- if and only ifisMetaObject(Object)
returnsfalse
for the same receiver.- Since:
- 20.1
-
getMetaSimpleName
Returns the simple name of a metaobject asstring
.Sample interpretations: The simple name of a Java class is the class name.
This method must not cause any observable side-effects. If this method is implemented then also
isMetaObject(Object)
must be implemented as well.- Throws:
UnsupportedMessageException
- if and only ifisMetaObject(Object)
returnsfalse
for the same receiver.- Since:
- 20.1
-
isMetaInstance
Returnstrue
if the given instance is of the provided receiver metaobject, elsefalse
.Sample interpretations: A Java object is an instance of its returned
class
.This method must not cause any observable side-effects. If this method is implemented then also
isMetaObject(Object)
must be implemented as well.- Parameters:
instance
- the instance object to check.- Throws:
UnsupportedMessageException
- if and only ifisMetaObject(Object)
returnsfalse
for the same receiver.- Since:
- 20.1
-
hasMetaParents
Returnstrue
if the receiver valueis a metaobject
which has parents (super types).This method must not cause any observable side-effects. If this method is implemented then also
getMetaParents(Object)
must be implemented.- Parameters:
receiver
- a metaobject- Since:
- 22.2
- See Also:
-
getMetaParents
Returns an array likehasArrayElements(Object)
of metaobjects that are direct parents (super types) of this metaobject.The returned object is an
array
of objects that returntrue
fromisMetaObject(Object)
.- Parameters:
receiver
- a metaobject- Throws:
UnsupportedMessageException
- if and only ifhasMetaParents(Object)
returnsfalse
for the same receiver.- Since:
- 22.2
- See Also:
-
isIdenticalOrUndefined
ReturnsTRUE
if the receiver is orFALSE
if the receiver is not identical to theother
value. ReturnsUNDEFINED
if the operation is not specified.Sample interpretations:
- A Java object might be of the identical instance as another Java object. Typically
compared using the
==
operator.
Any implementation, with the exception of an implementation that returns
UNDEFINED
unconditionally, must guarantee the following properties:- It is reflexive: for any value
x
,lib.isIdenticalOrUndefined(x, x)
always returnsTRUE
. This is necessary to ensure that thehasIdentity(Object)
contract has reliable results. - It is symmetric: for any values
x
andy
,lib.isIdenticalOrUndefined(x, y)
returnsTRUE
if and only iflib.isIdenticalOrUndefined(y, x)
returnsTRUE
. - It is transitive: for any values
x
,y
, andz
, iflib.isIdenticalOrUndefined(x, y)
returnsTRUE
andlib.isIdenticalOrUndefined(y, z)
returnsTRUE
, thenlib.isIdentical(x, z, zLib)
returnsTRUE
. - It is consistent: for any values
x
andy
, multiple invocations oflib.isIdenticalOrUndefined(x, y)
consistently returns the same value.
Note that the target language identical semantics typically does not map directly to interop identical implementation. Instead target language identity is specified by the language operation, may take multiple other rules into account and may only fallback to interop identical for values without dedicated interop type. For example, in many languages primitives like numbers or strings may be identical, in the target language sense, still identity can only be exposed for objects and non-primitive values. Primitive values like
Integer
can never be interop identical to other boxed language integers as this would violate the symmetric property.Example receiver class MyObject which uses an explicit identity field to compute whether two values are identical.
static class MyObject { final Object identity; MyObject(Object identity) { this.identity = identity; } @ExportMessage static final class IsIdenticalOrUndefined { @Specialization static TriState doMyObject(MyObject receiver, MyObject other) { return receiver.identity == other.identity ? TriState.TRUE : TriState.FALSE; } @Fallback static TriState doOther(MyObject receiver, Object other) { return TriState.UNDEFINED; } } // ... }
This method must not cause any observable side-effects. If this method is implemented then also
identityHashCode(Object)
must be implemented.- Parameters:
other
- the other value to compare to- Since:
- 20.2
- A Java object might be of the identical instance as another Java object. Typically
compared using the
-
isIdentical
Returnstrue
if two values represent the the identical value, elsefalse
. Two values are identical if and only if they have specified identity semantics in the target language and refer to the identical instance.By default, an interop value does not support identical comparisons, and will return
false
for any invocation of this method. UsehasIdentity(Object)
to find out whether a receiver supports identity comparisons.This method has the following properties:
- It is not reflexive: for any value
x
,lib.isIdentical(x, x, lib)
may returnfalse
if the object does not support identity, elsetrue
. This method is reflexive ifx
supports identity. A value supports identity iflib.isIdentical(x, x, lib)
returnstrue
. The methodhasIdentity(Object)
may be used to document this intent explicitly. - It is symmetric: for any values
x
andy
,lib.isIdentical(x, y, yLib)
returnstrue
if and only iflib.isIdentical(y, x, xLib)
returnstrue
. - It is transitive: for any values
x
,y
, andz
, iflib.isIdentical(x, y, yLib)
returnstrue
andlib.isIdentical(y, z, zLib)
returnstrue
, thenlib.isIdentical(x, z, zLib)
returnstrue
. - It is consistent: for any values
x
andy
, multiple invocations oflib.isIdentical(x, y, yLib)
consistently returnstrue
or consistently returnfalse
.
Note that the target language identical semantics typically does not map directly to interop identical implementation. Instead target language identity is specified by the language operation, may take multiple other rules into account and may only fallback to interop identical for values without dedicated interop type. For example, in many languages primitives like numbers or strings may be identical, in the target language sense, still identity can only be exposed for objects and non-primitive values. Primitive values like
Integer
can never be interop identical to other boxed language integers as this would violate the symmetric property.This method performs double dispatch by forwarding calls to
isIdenticalOrUndefined(Object, Object)
with receiver and other value first and then with reversed parameters if the result wasundefined
. This allows the receiver and the other value to negotiate identity semantics. This method is supposed to be exported only if the receiver represents a wrapper that forwards messages. In such a case the isIdentical message should be forwarded to the delegate value. Otherwise, theisIdenticalOrUndefined(Object, Object)
should be exported instead.This method must not cause any observable side-effects.
Cached usage example:
abstract class IsIdenticalUsage extends Node { abstract boolean execute(Object left, Object right); @Specialization(limit = "3") public boolean isIdentical(Object left, Object right, @CachedLibrary("left") InteropLibrary leftInterop, @CachedLibrary("right") InteropLibrary rightInterop) { return leftInterop.isIdentical(left, right, rightInterop); } }
Uncached usage example:
@TruffleBoundary public static boolean isIdentical(Object left, Object right) { return InteropLibrary.getUncached(left).isIdentical(left, right, InteropLibrary.getUncached(right)); }
For a full example please refer to the SLEqualNode of the SimpleLanguage example implementation.- Since:
- 20.2
- It is not reflexive: for any value
-
hasIdentity
Returnstrue
if and only if the receiver specifies identity, elsefalse
. This method is a short-cut forthis.isIdentical(receiver, receiver, this) != TriState.UNDEFINED
. This message cannot be exported. To add identity support to the receiver exportisIdenticalOrUndefined(Object, Object)
instead.- Since:
- 20.2
- See Also:
-
identityHashCode
Returns an identity hash code for the receiver if it hasidentity
. If the receiver has no identity then anUnsupportedMessageException
is thrown. The identity hash code may be used by languages to store foreign values with identity in an identity hash map.- Whenever it is invoked on the same object more than once during an execution of a guest context, the identityHashCode method must consistently return the same integer. This integer need not remain consistent from one execution context of a guest application to another execution context of the same application.
- If two objects are the same according to the
isIdentical(Object, Object, InteropLibrary)
message, then calling the identityHashCode method on each of the two objects must produce the same integer result. - As much as is reasonably practical, the identityHashCode message does return distinct integers for objects that are not the same.
isIdenticalOrUndefined(Object, Object)
must be implemented.- Throws:
UnsupportedMessageException
- if and only ifhasIdentity(Object)
returnsfalse
for the same receiver.- Since:
- 20.2
- See Also:
-
isScope
Returnstrue
if the value represents a scope object, elsefalse
. The scope object contains variables asmembers
and has ascope display name
. It needs to be associated with alanguage
. The scope may return asource location
that indicates the range of the scope in the source code. The scope may haveparent scopes
.The
members
of a scope represent all visible flattened variables, including all parent scopes, if any. The variables of the current scope must be listed first ingetMembers(Object)
. Variables of theparent scope
must be listed afterwards, even if they contain duplicates. This allows to resolve which variables are redeclared in sub scopes.Every
member
may not be just a String literal, but astring object
that provides also asource location
of its declaration. When different variables of the same name are in different scopes, they will be represented by different member elements providing the samename
.This method must not cause any observable side-effects. If this method is implemented then also
hasMembers(Object)
andtoDisplayString(Object, boolean)
must be implemented andhasSourceLocation(Object)
is recommended.- Since:
- 20.3
- See Also:
-
hasScopeParent
Returnstrue
if this scope has an enclosing parent scope, elsefalse
.This method must not cause any observable side-effects. If this method is implemented then also
isScope(Object)
andgetScopeParent(Object)
must be implemented.- Since:
- 20.3
- See Also:
-
getScopeParent
Returns the parent scope object if ithas the parent
. The returned object must be ascope
and must provide a reduced list ofmember
variables, omitting all variables that are local to the current scope.This method must not cause any observable side-effects. If this method is implemented then also
isScope(Object)
andgetScopeParent(Object)
must be implemented.- Throws:
UnsupportedMessageException
- if and only ifhasScopeParent(Object)
returnsfalse
for the same receiver.- Since:
- 20.3
- See Also:
-
getFactory
Returns the library factory for the interop library. Short-cut forResolvedLibrary.resolve(InteropLibrary.class)
.- Since:
- 19.0
- See Also:
-
getUncached
Returns the uncached automatically dispatched version of the interop library. This is a short-cut for callingInteropLibrary.getFactory().getUncached()
.- Since:
- 20.2
- See Also:
-
getUncached
Returns the uncached manually dispatched version of the interop library. This is a short-cut for callingInteropLibrary.getFactory().getUncached(v)
.- Since:
- 20.2
- See Also:
-
assertAdopted
protected final boolean assertAdopted()Utility for libraries to require adoption before cached versions of nodes can be executed. Only fails if assertions (-ea) are enabled.- Since:
- 19.0
-
isValidValue
Utility to check whether a value is a valid interop value. Interop values are all values that can flow through the language implementation freely and are intended to be used as receivers for theInteropLibrary
. This method will be extended with more checked types as interop is extended with further allowed values.It is not recommended to make assumptions about the types of interop values. It is recommended to use instance methods in
InteropLibrary
to check for interop types instead. However, it can be useful to make such assumptions for performance reasons. To verify that these assumptions continue to hold this method can be used.- Since:
- 21.3
-
isValidProtocolValue
Utility to check whether a value is a valid interop protocol value. An interop protocol value is either aninterop value
or a value that might be returned or passed as parameter by any of the methods inInteropLibrary
. This can be useful to validate all values received or returned by a wrapper that usesReflectionLibrary
to delegate all interop protocol parameters and return values. This method will be extended with more checked types as interop is extended with further allowed values.- Since:
- 21.3
- See Also:
-