Search in sources :

Example 36 with InteropLibrary

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));
    }
}
Also used : InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary)

Example 37 with InteropLibrary

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;
}
Also used : InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary)

Example 38 with InteropLibrary

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);
}
Also used : InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary)

Example 39 with InteropLibrary

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);
    }
}
Also used : UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary) Test(org.junit.Test)

Example 40 with InteropLibrary

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);
    }
}
Also used : InvalidArrayIndexException(com.oracle.truffle.api.interop.InvalidArrayIndexException) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary) TruffleObject(com.oracle.truffle.api.interop.TruffleObject)

Aggregations

InteropLibrary (com.oracle.truffle.api.interop.InteropLibrary)158 Test (org.junit.Test)76 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)60 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)51 UnknownIdentifierException (com.oracle.truffle.api.interop.UnknownIdentifierException)18 UnsupportedTypeException (com.oracle.truffle.api.interop.UnsupportedTypeException)18 ArityException (com.oracle.truffle.api.interop.ArityException)16 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)15 WasmInstance (org.graalvm.wasm.WasmInstance)15 WebAssembly (org.graalvm.wasm.api.WebAssembly)15 VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)12 RootNode (com.oracle.truffle.api.nodes.RootNode)12 InteropException (com.oracle.truffle.api.interop.InteropException)11 InvalidArrayIndexException (com.oracle.truffle.api.interop.InvalidArrayIndexException)11 Dictionary (org.graalvm.wasm.api.Dictionary)8 SourceSection (com.oracle.truffle.api.source.SourceSection)6 CallTarget (com.oracle.truffle.api.CallTarget)5 Node (com.oracle.truffle.api.nodes.Node)5 ProxyObject (org.graalvm.polyglot.proxy.ProxyObject)5 WasmJsApiException (org.graalvm.wasm.exception.WasmJsApiException)5