Search in sources :

Example 11 with UnsupportedMessageException

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

Example 12 with UnsupportedMessageException

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

the class LLVMTruffleReadNBytes method interop.

@Specialization
protected Object interop(LLVMTruffleObject objectWithOffset, int n, @Cached("createForeignReadNode()") Node foreignRead, @Cached("createToByteNode()") ForeignToLLVM toLLVM, @Cached("getContextReference()") ContextReference<LLVMContext> ctxRef) {
    long offset = objectWithOffset.getOffset();
    TruffleObject object = objectWithOffset.getObject();
    byte[] chars = new byte[n];
    for (int i = 0; i < n; i++) {
        Object rawValue;
        try {
            rawValue = ForeignAccess.sendRead(foreignRead, object, offset + i);
        } catch (UnknownIdentifierException | UnsupportedMessageException e) {
            CompilerDirectives.transferToInterpreter();
            throw new IllegalStateException(e);
        }
        chars[i] = (byte) toLLVM.executeWithTarget(rawValue);
    }
    TruffleObject ret = (TruffleObject) ctxRef.get().getEnv().asGuestValue(chars);
    return new LLVMTruffleObject(LLVMTypedForeignObject.createUnknown(ret));
}
Also used : UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) UnknownIdentifierException(com.oracle.truffle.api.interop.UnknownIdentifierException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) LLVMTruffleObject(com.oracle.truffle.llvm.runtime.LLVMTruffleObject) LLVMTypedForeignObject(com.oracle.truffle.llvm.runtime.interop.LLVMTypedForeignObject) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) LLVMTruffleObject(com.oracle.truffle.llvm.runtime.LLVMTruffleObject) LLVMTruffleObject(com.oracle.truffle.llvm.runtime.LLVMTruffleObject) Specialization(com.oracle.truffle.api.dsl.Specialization)

Example 13 with UnsupportedMessageException

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

the class LLVMToDoubleNode method doTruffleObject.

@Specialization
protected double doTruffleObject(LLVMTruffleObject from) {
    TruffleObject base = from.getObject();
    if (ForeignAccess.sendIsNull(isNull, base)) {
        return from.getOffset();
    } else if (ForeignAccess.sendIsBoxed(isBoxed, base)) {
        try {
            double unboxed = (double) toDouble.executeWithTarget(ForeignAccess.sendUnbox(unbox, base));
            return unboxed + from.getOffset();
        } catch (UnsupportedMessageException e) {
            CompilerDirectives.transferToInterpreter();
            throw new IllegalStateException(e);
        }
    }
    CompilerDirectives.transferToInterpreter();
    throw new IllegalStateException("Not convertable");
}
Also used : UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) LLVMTruffleObject(com.oracle.truffle.llvm.runtime.LLVMTruffleObject) Specialization(com.oracle.truffle.api.dsl.Specialization)

Example 14 with UnsupportedMessageException

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

the class LLVMToFloatNode method doTruffleObject.

@Specialization
protected float doTruffleObject(LLVMTruffleObject from) {
    TruffleObject base = from.getObject();
    if (ForeignAccess.sendIsNull(isNull, base)) {
        return from.getOffset();
    } else if (ForeignAccess.sendIsBoxed(isBoxed, base)) {
        try {
            float ptr = (float) toFloat.executeWithTarget(ForeignAccess.sendUnbox(unbox, base));
            return ptr + from.getOffset();
        } catch (UnsupportedMessageException e) {
            CompilerDirectives.transferToInterpreter();
            throw new IllegalStateException(e);
        }
    }
    CompilerDirectives.transferToInterpreter();
    throw new IllegalStateException("Not convertable");
}
Also used : UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) LLVMTruffleObject(com.oracle.truffle.llvm.runtime.LLVMTruffleObject) Specialization(com.oracle.truffle.api.dsl.Specialization)

Example 15 with UnsupportedMessageException

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

the class LLVMToI1Node method doTruffleObject.

@Specialization
protected boolean doTruffleObject(LLVMTruffleObject from) {
    TruffleObject base = from.getObject();
    if (ForeignAccess.sendIsNull(isNull, base)) {
        return (from.getOffset() & 1) != 0;
    } else if (ForeignAccess.sendIsBoxed(isBoxed, base)) {
        try {
            boolean ptr = (boolean) toBool.executeWithTarget(ForeignAccess.sendUnbox(unbox, base));
            return ptr ^ ((from.getOffset() & 1) != 0);
        } catch (UnsupportedMessageException e) {
            CompilerDirectives.transferToInterpreter();
            throw new IllegalStateException(e);
        }
    }
    CompilerDirectives.transferToInterpreter();
    throw new IllegalStateException("Not convertable");
}
Also used : UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) LLVMTruffleObject(com.oracle.truffle.llvm.runtime.LLVMTruffleObject) Specialization(com.oracle.truffle.api.dsl.Specialization)

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