Search in sources :

Example 6 with UnsupportedMessageException

use of com.oracle.truffle.api.interop.UnsupportedMessageException 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 7 with UnsupportedMessageException

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

the class JavaInteropTest method testRemoveMessage.

@Test
public void testRemoveMessage() {
    data.arr = new String[] { "Hello", "World", "!" };
    TruffleObject truffleList = JavaInterop.asTruffleObject(new ArrayList<>(Arrays.asList(data.arr)));
    assertEquals(3, message(Message.GET_SIZE, truffleList));
    assertEquals(true, message(Message.REMOVE, truffleList, 1));
    assertEquals(2, message(Message.GET_SIZE, truffleList));
    try {
        message(Message.REMOVE, truffleList, 10);
        fail("Out of bounds.");
    } catch (Exception e) {
        assertTrue(e.toString(), e instanceof UnknownIdentifierException);
        assertEquals("10", ((UnknownIdentifierException) e).getUnknownIdentifier());
    }
    Object arrObj = message(Message.READ, obj, "arr");
    TruffleObject truffleArr = (TruffleObject) arrObj;
    try {
        message(Message.REMOVE, truffleArr, 0);
        fail("Remove of elements of an array is not supported.");
    } catch (Exception e) {
        assertTrue(e.toString(), e instanceof UnsupportedMessageException);
        assertEquals(Message.REMOVE, ((UnsupportedMessageException) e).getUnsupportedMessage());
    }
    Map<String, String> map = new HashMap<>();
    map.put("a", "aa");
    map.put("b", "bb");
    TruffleObject truffleMap = JavaInterop.asTruffleObject(map);
    assertEquals(true, message(Message.REMOVE, truffleMap, "a"));
    assertEquals(1, map.size());
    try {
        message(Message.REMOVE, truffleMap, "a");
        fail("UnknownIdentifierException");
    } catch (Exception e) {
        assertTrue(e.toString(), e instanceof UnknownIdentifierException);
        assertEquals("a", ((UnknownIdentifierException) e).getUnknownIdentifier());
    }
}
Also used : UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) UnknownIdentifierException(com.oracle.truffle.api.interop.UnknownIdentifierException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) 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 8 with UnsupportedMessageException

use of com.oracle.truffle.api.interop.UnsupportedMessageException 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 9 with UnsupportedMessageException

use of com.oracle.truffle.api.interop.UnsupportedMessageException 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)

Example 10 with UnsupportedMessageException

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

the class ContextAPITest method testExecute.

private static void testExecute(Context context) {
    ContextAPITestLanguage.runinside = (env) -> new ProxyInteropObject() {

        @Override
        public boolean isExecutable() {
            return true;
        }

        @Override
        public Object execute(Object[] args) throws UnsupportedTypeException, ArityException, UnsupportedMessageException {
            return 42;
        }
    };
    Value executable = context.eval(ContextAPITestLanguage.ID, "");
    assertEquals(42, executable.execute().asInt());
    assertEquals(42, executable.execute(42).asInt());
    executable.executeVoid();
    executable.executeVoid(42);
}
Also used : UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) Value(org.graalvm.polyglot.Value) UnsupportedTypeException(com.oracle.truffle.api.interop.UnsupportedTypeException) ArityException(com.oracle.truffle.api.interop.ArityException)

Aggregations

UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)15 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)13 UnsupportedTypeException (com.oracle.truffle.api.interop.UnsupportedTypeException)7 LLVMTruffleObject (com.oracle.truffle.llvm.runtime.LLVMTruffleObject)7 Specialization (com.oracle.truffle.api.dsl.Specialization)6 UnknownIdentifierException (com.oracle.truffle.api.interop.UnknownIdentifierException)6 ArityException (com.oracle.truffle.api.interop.ArityException)4 Test (org.junit.Test)4 ExplodeLoop (com.oracle.truffle.api.nodes.ExplodeLoop)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