Search in sources :

Example 1 with ArityException

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

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

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

Example 4 with ArityException

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

the class LLVMTruffleInvoke method doInvoke.

@ExplodeLoop
private Object doInvoke(VirtualFrame frame, TruffleObject value, String id, ContextReference<LLVMContext> contextReference, 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 {
        LLVMContext context = contextReference.get();
        LLVMStack stack = getStack.executeWithTarget(getThreadingStack(context), Thread.currentThread());
        Object rawValue;
        try (StackPointer save = stack.newFrame()) {
            rawValue = ForeignAccess.sendInvoke(foreignInvoke, value, id, evaluatedArgs);
        }
        return toLLVM.executeWithTarget(rawValue);
    } catch (UnknownIdentifierException | UnsupportedMessageException | UnsupportedTypeException | ArityException e) {
        CompilerDirectives.transferToInterpreter();
        throw new IllegalStateException(e);
    }
}
Also used : LLVMContext(com.oracle.truffle.llvm.runtime.LLVMContext) 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) 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)

Aggregations

ArityException (com.oracle.truffle.api.interop.ArityException)4 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)4 UnsupportedTypeException (com.oracle.truffle.api.interop.UnsupportedTypeException)4 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)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 UnknownIdentifierException (com.oracle.truffle.api.interop.UnknownIdentifierException)1 LLVMContext (com.oracle.truffle.llvm.runtime.LLVMContext)1 Value (org.graalvm.polyglot.Value)1