Search in sources :

Example 6 with InteropException

use of com.oracle.truffle.api.interop.InteropException in project graal by oracle.

the class InstrumentableNodeTest method assertProperties.

private static void assertProperties(Object receiver, Object... properties) {
    try {
        assertTrue(receiver instanceof TruffleObject);
        TruffleObject obj = (TruffleObject) receiver;
        Node hasKeysNode = Message.HAS_KEYS.createNode();
        Node keysNode = Message.KEYS.createNode();
        assertTrue(ForeignAccess.sendHasKeys(hasKeysNode, obj));
        TruffleObject keys = ForeignAccess.sendKeys(keysNode, obj);
        for (int i = 0; i < properties.length; i = i + 2) {
            String expectedKey = (String) properties[i];
            Object expectedValue = properties[i + 1];
            Node readNode = Message.READ.createNode();
            Object key = ForeignAccess.sendRead(readNode, keys, i / 2);
            assertEquals(expectedKey, key);
            assertEquals(expectedValue, ForeignAccess.sendRead(readNode, obj, key));
        }
    } catch (InteropException e) {
        throw e.raise();
    }
}
Also used : Node(com.oracle.truffle.api.nodes.Node) ExpressionNode(com.oracle.truffle.api.instrumentation.test.InstrumentationTestLanguage.ExpressionNode) MaterializeChildExpressionNode(com.oracle.truffle.api.instrumentation.test.InstrumentationTestLanguage.MaterializeChildExpressionNode) MaterializedChildExpressionNode(com.oracle.truffle.api.instrumentation.test.InstrumentationTestLanguage.MaterializedChildExpressionNode) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) InteropException(com.oracle.truffle.api.interop.InteropException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject)

Example 7 with InteropException

use of com.oracle.truffle.api.interop.InteropException in project sulong by graalvm.

the class LLVMPolyglotExport method doExport.

@Specialization
protected Object doExport(Object name, Object value, @Cached("getContextReference()") ContextReference<LLVMContext> ctxRef) {
    String symbolName = readString.executeWithTarget(name);
    LLVMContext ctx = ctxRef.get();
    Object escaped = escape.executeWithTarget(value);
    try {
        ForeignAccess.sendWrite(write, (TruffleObject) ctx.getEnv().getPolyglotBindings(), symbolName, escaped);
    } catch (InteropException ex) {
        throw ex.raise();
    }
    return null;
}
Also used : LLVMContext(com.oracle.truffle.llvm.runtime.LLVMContext) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) InteropException(com.oracle.truffle.api.interop.InteropException) Specialization(com.oracle.truffle.api.dsl.Specialization)

Example 8 with InteropException

use of com.oracle.truffle.api.interop.InteropException in project sulong by graalvm.

the class NFIContextExtension method createNativeWrapper.

@TruffleBoundary
public TruffleObject createNativeWrapper(LLVMFunctionDescriptor descriptor) {
    TruffleObject wrapper = null;
    try {
        String signature = getNativeSignature(descriptor.getType(), 0);
        TruffleObject createNativeWrapper = getNativeFunction(descriptor.getContext(), "@createNativeWrapper", String.format("(env, %s):object", signature));
        try {
            wrapper = (TruffleObject) ForeignAccess.sendExecute(Message.createExecute(1).createNode(), createNativeWrapper, descriptor);
        } catch (InteropException ex) {
            throw new AssertionError(ex);
        }
    } catch (UnsupportedNativeTypeException ex) {
    // ignore, fall back to tagged id
    }
    return wrapper;
}
Also used : InteropException(com.oracle.truffle.api.interop.InteropException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 9 with InteropException

use of com.oracle.truffle.api.interop.InteropException in project graal by oracle.

the class ObjectNFITest method deleteAPI.

@AfterClass
public static void deleteAPI() {
    TruffleObject deleteAPI = lookupAndBind("delete_api", "(env, pointer):void");
    try {
        ForeignAccess.sendExecute(Message.createExecute(1).createNode(), deleteAPI, nativeAPI);
        nativeAPI = null;
    } catch (InteropException ex) {
        throw new AssertionError(ex);
    }
}
Also used : InteropException(com.oracle.truffle.api.interop.InteropException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) AfterClass(org.junit.AfterClass)

Example 10 with InteropException

use of com.oracle.truffle.api.interop.InteropException in project graal by oracle.

the class GlobalNFITest method initContext.

@BeforeClass
public static void initContext() {
    registerGlobalCallback = lookupAndBind("registerGlobalCallback", "((double):double):object");
    testGlobalCallback = lookupAndBind("testGlobalCallback", "(double):double");
    TruffleObject initializeGlobalContext = lookupAndBind("initializeGlobalContext", "(env):void");
    try {
        ForeignAccess.sendExecute(Message.createExecute(0).createNode(), initializeGlobalContext);
    } catch (InteropException ex) {
        throw new AssertionError(ex);
    }
}
Also used : InteropException(com.oracle.truffle.api.interop.InteropException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) BeforeClass(org.junit.BeforeClass)

Aggregations

InteropException (com.oracle.truffle.api.interop.InteropException)14 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)14 Test (org.junit.Test)4 UnknownIdentifierException (com.oracle.truffle.api.interop.UnknownIdentifierException)3 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)2 Specialization (com.oracle.truffle.api.dsl.Specialization)2 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)2 UnsupportedTypeException (com.oracle.truffle.api.interop.UnsupportedTypeException)2 Node (com.oracle.truffle.api.nodes.Node)2 ValueHostInteropTest (com.oracle.truffle.api.test.polyglot.ValueHostInteropTest)2 LLVMContext (com.oracle.truffle.llvm.runtime.LLVMContext)2 TestCallback (com.oracle.truffle.nfi.test.interop.TestCallback)2 NoSuchElementException (java.util.NoSuchElementException)2 BeforeClass (org.junit.BeforeClass)2 Scope (com.oracle.truffle.api.Scope)1 ExpressionNode (com.oracle.truffle.api.instrumentation.test.InstrumentationTestLanguage.ExpressionNode)1 MaterializeChildExpressionNode (com.oracle.truffle.api.instrumentation.test.InstrumentationTestLanguage.MaterializeChildExpressionNode)1 MaterializedChildExpressionNode (com.oracle.truffle.api.instrumentation.test.InstrumentationTestLanguage.MaterializedChildExpressionNode)1 ForeignAccess (com.oracle.truffle.api.interop.ForeignAccess)1 Message (com.oracle.truffle.api.interop.Message)1