Search in sources :

Example 1 with UnsupportedTypeException

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

the class LanguageSPITest method testPolyglotBindingsPreserveLanguage.

@Test
public void testPolyglotBindingsPreserveLanguage() {
    ProxyLanguage.setDelegate(new ProxyLanguage() {

        @Override
        protected CallTarget parse(ParsingRequest request) throws Exception {
            return Truffle.getRuntime().createCallTarget(new RootNode(languageInstance) {

                @Override
                public Object execute(VirtualFrame frame) {
                    Object bindings = getCurrentContext(ProxyLanguage.class).env.getPolyglotBindings();
                    try {
                        ForeignAccess.sendWrite(Message.WRITE.createNode(), (TruffleObject) bindings, "exportedValue", "convertOnToString");
                    } catch (UnknownIdentifierException | UnsupportedTypeException | UnsupportedMessageException e) {
                        throw new AssertionError(e);
                    }
                    return bindings;
                }
            });
        }

        @Override
        protected String toString(LanguageContext context, Object value) {
            if (value.equals("convertOnToString")) {
                return "myStringToString";
            }
            return super.toString(context, value);
        }
    });
    Context c = Context.create();
    c.eval(ProxyLanguage.ID, "");
    assertEquals("Make sure language specific toString was invoked.", "myStringToString", c.getPolyglotBindings().getMember("exportedValue").toString());
}
Also used : Context(org.graalvm.polyglot.Context) LanguageContext(com.oracle.truffle.api.test.polyglot.LanguageSPITestLanguage.LanguageContext) TruffleContext(com.oracle.truffle.api.TruffleContext) RootNode(com.oracle.truffle.api.nodes.RootNode) CallTarget(com.oracle.truffle.api.CallTarget) RootCallTarget(com.oracle.truffle.api.RootCallTarget) LanguageContext(com.oracle.truffle.api.test.polyglot.LanguageSPITestLanguage.LanguageContext) TimeoutException(java.util.concurrent.TimeoutException) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) TruffleException(com.oracle.truffle.api.TruffleException) PolyglotException(org.graalvm.polyglot.PolyglotException) UnsupportedTypeException(com.oracle.truffle.api.interop.UnsupportedTypeException) UnknownIdentifierException(com.oracle.truffle.api.interop.UnknownIdentifierException) ExecutionException(java.util.concurrent.ExecutionException) VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) UnknownIdentifierException(com.oracle.truffle.api.interop.UnknownIdentifierException) UnsupportedTypeException(com.oracle.truffle.api.interop.UnsupportedTypeException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test)

Example 2 with UnsupportedTypeException

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

the class LLVMTruffleExecute method doExecute.

@ExplodeLoop
private Object doExecute(VirtualFrame frame, TruffleObject value, LLVMContext context, LLVMGetStackNode getStack) {
    Object[] evaluatedArgs = new Object[args.length];
    for (int i = 0; i < args.length; i++) {
        evaluatedArgs[i] = prepareValuesForEscape[i].executeWithTarget(args[i].executeGeneric(frame));
    }
    try {
        LLVMStack stack = getStack.executeWithTarget(getThreadingStack(context), Thread.currentThread());
        Object rawValue;
        try (StackPointer save = stack.newFrame()) {
            rawValue = ForeignAccess.sendExecute(foreignExecute, value, evaluatedArgs);
        }
        return toLLVM.executeWithTarget(rawValue);
    } catch (UnsupportedMessageException | UnsupportedTypeException | ArityException e) {
        CompilerDirectives.transferToInterpreter();
        throw new IllegalStateException(e);
    }
}
Also used : UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) UnsupportedTypeException(com.oracle.truffle.api.interop.UnsupportedTypeException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) LLVMTruffleObject(com.oracle.truffle.llvm.runtime.LLVMTruffleObject) StackPointer(com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer) ArityException(com.oracle.truffle.api.interop.ArityException) LLVMStack(com.oracle.truffle.llvm.runtime.memory.LLVMStack) ExplodeLoop(com.oracle.truffle.api.nodes.ExplodeLoop)

Example 3 with UnsupportedTypeException

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

the class ValidTruffleObject15Test method expectUnsupportedSpecializationException.

@Test(expected = UnsupportedSpecializationException.class)
public void expectUnsupportedSpecializationException() {
    ValidTruffleObject15 object = new ValidTruffleObject15();
    Node read = Message.WRITE.createNode();
    try {
        ForeignAccess.sendWrite(read, object, "name", new UnknownObject());
    } catch (UnknownIdentifierException e) {
        Assert.fail();
    } catch (UnsupportedMessageException e) {
        Assert.fail();
    } catch (UnsupportedTypeException e) {
        Assert.fail();
    }
}
Also used : UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) UnknownIdentifierException(com.oracle.truffle.api.interop.UnknownIdentifierException) Node(com.oracle.truffle.api.nodes.Node) UnsupportedTypeException(com.oracle.truffle.api.interop.UnsupportedTypeException) Test(org.junit.Test)

Example 4 with UnsupportedTypeException

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

the class JavaInteropTest method testException2.

@Test
public void testException2() throws InteropException {
    TruffleObject hashMapClass = JavaInterop.asTruffleObject(HashMap.class);
    try {
        ForeignAccess.sendNew(Message.createNew(0).createNode(), hashMapClass, -1);
        fail("expected an exception but none was thrown");
    } catch (InteropException ex) {
        throw ex;
    } catch (Exception ex) {
        assertTrue("expected HostException but was: " + ex.getClass(), JavaInterop.isHostException(ex));
        assertThat(JavaInterop.asHostException(ex), CoreMatchers.instanceOf(IllegalArgumentException.class));
    }
    try {
        ForeignAccess.sendNew(Message.createNew(0).createNode(), hashMapClass, "");
        fail("expected an exception but none was thrown");
    } catch (UnsupportedTypeException ex) {
    }
}
Also used : UnsupportedTypeException(com.oracle.truffle.api.interop.UnsupportedTypeException) InteropException(com.oracle.truffle.api.interop.InteropException) InteropException(com.oracle.truffle.api.interop.InteropException) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) UnsupportedTypeException(com.oracle.truffle.api.interop.UnsupportedTypeException) UnknownIdentifierException(com.oracle.truffle.api.interop.UnknownIdentifierException) NoSuchElementException(java.util.NoSuchElementException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test) ValueHostInteropTest(com.oracle.truffle.api.test.polyglot.ValueHostInteropTest)

Example 5 with UnsupportedTypeException

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

the class TruffleExecuteNode method execute.

public Object execute(Object languageContext, TruffleObject function, Object functionArgsObject, Class<?> resultClass, Type resultType) {
    Object[] argsArray;
    if (functionArgsObject instanceof Object[]) {
        argsArray = (Object[]) functionArgsObject;
    } else {
        if (functionArgsObject == null) {
            argsArray = EMPTY;
        } else {
            argsArray = new Object[] { functionArgsObject };
        }
    }
    Object[] functionArgs = toGuests.apply(languageContext, argsArray);
    Object result;
    boolean executable = condition.profile(sendIsExecutable(isExecutable, function));
    try {
        if (executable) {
            result = sendExecute(execute, function, functionArgs);
        } else if (sendIsInstantiable(isInstantiable, function)) {
            result = sendNew(instantiate, function, functionArgs);
        } else {
            CompilerDirectives.transferToInterpreter();
            throw JavaInteropErrors.executeUnsupported(languageContext, function);
        }
    } catch (UnsupportedTypeException e) {
        CompilerDirectives.transferToInterpreter();
        if (executable) {
            throw JavaInteropErrors.invalidExecuteArgumentType(languageContext, function, functionArgs);
        } else {
            throw JavaInteropErrors.invalidInstantiateArgumentType(languageContext, function, functionArgs);
        }
    } catch (ArityException e) {
        CompilerDirectives.transferToInterpreter();
        if (executable) {
            throw JavaInteropErrors.invalidExecuteArity(languageContext, function, functionArgs, e.getExpectedArity(), e.getActualArity());
        } else {
            throw JavaInteropErrors.invalidInstantiateArity(languageContext, function, functionArgs, e.getExpectedArity(), e.getActualArity());
        }
    } catch (UnsupportedMessageException e) {
        CompilerDirectives.transferToInterpreter();
        throw JavaInteropErrors.executeUnsupported(languageContext, function);
    }
    return toHost.execute(result, resultClass, resultType, languageContext);
}
Also used : UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) UnsupportedTypeException(com.oracle.truffle.api.interop.UnsupportedTypeException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) ArityException(com.oracle.truffle.api.interop.ArityException)

Aggregations

UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)7 UnsupportedTypeException (com.oracle.truffle.api.interop.UnsupportedTypeException)7 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)5 ArityException (com.oracle.truffle.api.interop.ArityException)4 UnknownIdentifierException (com.oracle.truffle.api.interop.UnknownIdentifierException)4 Test (org.junit.Test)3 ExplodeLoop (com.oracle.truffle.api.nodes.ExplodeLoop)2 LLVMTruffleObject (com.oracle.truffle.llvm.runtime.LLVMTruffleObject)2 LLVMStack (com.oracle.truffle.llvm.runtime.memory.LLVMStack)2 StackPointer (com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer)2 CallTarget (com.oracle.truffle.api.CallTarget)1 RootCallTarget (com.oracle.truffle.api.RootCallTarget)1 TruffleContext (com.oracle.truffle.api.TruffleContext)1 TruffleException (com.oracle.truffle.api.TruffleException)1 VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)1 InteropException (com.oracle.truffle.api.interop.InteropException)1 Node (com.oracle.truffle.api.nodes.Node)1 RootNode (com.oracle.truffle.api.nodes.RootNode)1 LanguageContext (com.oracle.truffle.api.test.polyglot.LanguageSPITestLanguage.LanguageContext)1 ValueHostInteropTest (com.oracle.truffle.api.test.polyglot.ValueHostInteropTest)1