Search in sources :

Example 1 with UnsupportedMessageException

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

the class ObjectStructures method asMap.

static Map<Object, Object> asMap(MessageNodes nodes, TruffleObject object) {
    TruffleObject keys;
    try {
        keys = ForeignAccess.sendKeys(nodes.keys, object, true);
        boolean hasSize = ForeignAccess.sendHasSize(nodes.hasSize, keys);
        if (!hasSize) {
            return null;
        }
    } catch (UnsupportedMessageException ex) {
        return null;
    }
    return new ObjectMap(nodes, object, keys);
}
Also used : UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject)

Example 2 with UnsupportedMessageException

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

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

the class TestMemberAccess method testObjectReadIndex.

@Test
public void testObjectReadIndex() throws InteropException {
    TruffleObject arrayObject = JavaInterop.asTruffleObject(new TestClass());
    try {
        ForeignAccess.sendRead(readNode, arrayObject, 0);
        fail();
    } catch (UnsupportedMessageException e) {
    }
}
Also used : UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test)

Example 4 with UnsupportedMessageException

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

the class SlowPathSerializeArgumentNode method genericWithPrepare.

@Specialization(replaces = "cacheType", guards = { "value != null" })
protected Object genericWithPrepare(NativeArgumentBuffer buffer, LibFFIType type, TruffleObject value, @Cached("createUnbox()") Node unbox, @Cached("createIsExecutable()") Node isExecutable, @Cached("createAsPointer()") AsPointerNode asPointer, @Cached("createRecursive()") SlowPathSerializeArgumentNode recursive) {
    Object prepared = type.slowpathPrepareArgument(value);
    if (prepared == PrepareArgument.EXECUTABLE) {
        if (ForeignAccess.sendIsExecutable(isExecutable, value)) {
            prepared = value;
        } else {
            prepared = PrepareArgument.POINTER;
        }
    }
    if (prepared == PrepareArgument.POINTER) {
        prepared = asPointer.execute(value);
    } else if (prepared == PrepareArgument.UNBOX) {
        Object unboxed;
        try {
            unboxed = ForeignAccess.sendUnbox(unbox, value);
        } catch (UnsupportedMessageException ex) {
            throw UnsupportedTypeException.raise(ex, new Object[] { value });
        }
        return recursive.execute(buffer, type, unboxed);
    }
    slowPathSerialize(buffer, type, prepared);
    return null;
}
Also used : UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Specialization(com.oracle.truffle.api.dsl.Specialization)

Example 5 with UnsupportedMessageException

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

the class LLVMTruffleReadNString method interop.

@Specialization
protected Object interop(LLVMTruffleObject objectWithOffset, int n, @Cached("createForeignReadNode()") Node foreignRead, @Cached("createToByteNode()") ForeignToLLVM toLLVM) {
    long offset = objectWithOffset.getOffset();
    TruffleObject object = objectWithOffset.getObject();
    char[] chars = new char[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);
        }
        byte byteValue = (byte) toLLVM.executeWithTarget(rawValue);
        chars[i] = (char) Byte.toUnsignedInt(byteValue);
    }
    return new String(chars);
}
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) 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