use of com.oracle.truffle.api.interop.InteropLibrary in project graal by oracle.
the class WasmJsApiSuite method checkCustomSections.
private static void checkCustomSections(byte[][] expected, Sequence<ByteArrayBuffer> actual) throws InvalidArrayIndexException, UnsupportedMessageException {
InteropLibrary interop = InteropLibrary.getUncached(actual);
Assert.assertEquals("Custom section count", expected.length, (int) interop.getArraySize(actual));
for (int i = 0; i < expected.length; i++) {
checkCustomSection(expected[i], (ByteArrayBuffer) interop.readArrayElement(actual, i));
}
}
use of com.oracle.truffle.api.interop.InteropLibrary in project graal by oracle.
the class HostExecuteNode method compareByPriority.
private static int compareByPriority(HostContext context, Class<?> t1, Class<?> t2, Object arg, int priority) {
if (priority <= HostToTypeNode.STRICT) {
return 0;
}
InteropLibrary argInterop = InteropLibrary.getFactory().getUncached(arg);
HostTargetMappingNode mapping = HostTargetMappingNode.getUncached();
for (int p : HostToTypeNode.PRIORITIES) {
if (p > priority) {
break;
}
boolean p1 = HostToTypeNode.canConvert(arg, t1, t1, null, context, p, argInterop, mapping);
boolean p2 = HostToTypeNode.canConvert(arg, t2, t2, null, context, p, argInterop, mapping);
if (p1 != p2) {
return p1 ? -1 : 1;
}
}
return 0;
}
use of com.oracle.truffle.api.interop.InteropLibrary in project graal by oracle.
the class ExternalPluginHandler method create.
public static ExternalPluginHandler create(StaticObject guestHandler) throws IllegalArgumentException {
InteropLibrary library = InteropLibrary.getUncached(guestHandler);
boolean invocable = library.isMemberInvocable(guestHandler, RERUN_CLINIT) && library.isMemberInvocable(guestHandler, POST_HOTSWAP);
if (!invocable) {
throw new IllegalArgumentException("guest handler does not implement expected API");
}
return new ExternalPluginHandler(guestHandler, library);
}
use of com.oracle.truffle.api.interop.InteropLibrary in project graal by oracle.
the class PointerArithmeticTest method test.
@Test
public void test(@Inject(PointerArithmeticNode.class) CallTarget function) {
Object ret = function.call(a, b);
try {
InteropLibrary lib = InteropLibrary.getFactory().getUncached(ret);
lib.toNative(ret);
Assert.assertEquals("ret", expected, lib.asPointer(ret));
} catch (UnsupportedMessageException ex) {
throw new AssertionError("ret is not a pointer", ex);
}
}
use of com.oracle.truffle.api.interop.InteropLibrary in project graal by oracle.
the class PolyglotArrayTestBase method polyglotArrayToJavaArray.
protected static Object[] polyglotArrayToJavaArray(Object expected) {
try {
InteropLibrary expectedInterop = InteropLibrary.getUncached(expected);
int length = Math.toIntExact(expectedInterop.getArraySize(expected));
Object[] array = new Object[length];
for (int i = 0; i < length; i++) {
array[i] = expectedInterop.readArrayElement(expected, i);
}
return array;
} catch (UnsupportedMessageException | InvalidArrayIndexException e) {
throw new AssertionError(e);
}
}
Aggregations