Search in sources :

Example 16 with TruffleObject

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

the class HostLanguage method findMetaObject.

@Override
protected Object findMetaObject(HostContext context, Object value) {
    if (value instanceof TruffleObject) {
        TruffleObject to = (TruffleObject) value;
        if (VMAccessor.JAVAINTEROP.isHostObject(to)) {
            Object javaObject = VMAccessor.JAVAINTEROP.asHostObject(to);
            Class<?> javaType;
            if (javaObject == null) {
                javaType = Void.class;
            } else {
                javaType = javaObject.getClass();
            }
            return javaClassToGuestObject(javaType, context.internalContext);
        } else if (PolyglotProxy.isProxyGuestObject(to)) {
            Proxy proxy = PolyglotProxy.toProxyHostObject(to);
            return javaClassToGuestObject(proxy.getClass(), context.internalContext);
        } else if (VMAccessor.JAVAINTEROP.isHostFunction(value)) {
            return "Bound Method";
        } else {
            return "Foreign Object";
        }
    } else {
        return javaClassToGuestObject(value.getClass(), context.internalContext);
    }
}
Also used : Proxy(org.graalvm.polyglot.proxy.Proxy) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) TruffleObject(com.oracle.truffle.api.interop.TruffleObject)

Example 17 with TruffleObject

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

the class LoadNFILibraryTest method loadDefault.

@Test
public void loadDefault() {
    TruffleObject library = eval("default");
    Assert.assertNotNull(library);
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test)

Example 18 with TruffleObject

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

the class LoadNFILibraryTest method loadLazy.

@Test
public void loadLazy() {
    TruffleObject library = eval("load(RTLD_LAZY) '%s'", nativeTestLib);
    Assert.assertNotNull(library);
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test)

Example 19 with TruffleObject

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

the class LoadNFILibraryTest method loadUnknownFlag.

@Test
public void loadUnknownFlag() {
    TruffleObject library = eval("load(_UNKNOWN_FLAG) '%s'", nativeTestLib);
    Assert.assertNotNull(library);
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test)

Example 20 with TruffleObject

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

the class LoadNFILibraryTest method eval.

private static TruffleObject eval(String format, Object... args) {
    Source source = Source.newBuilder(String.format(format, args)).name("LoadLibraryTest").mimeType("application/x-native").build();
    CallTarget target = runWithPolyglot.getTruffleTestEnv().parse(source);
    return (TruffleObject) target.call();
}
Also used : CallTarget(com.oracle.truffle.api.CallTarget) Source(com.oracle.truffle.api.source.Source) TruffleObject(com.oracle.truffle.api.interop.TruffleObject)

Aggregations

TruffleObject (com.oracle.truffle.api.interop.TruffleObject)201 Test (org.junit.Test)135 ValueHostInteropTest (com.oracle.truffle.api.test.polyglot.ValueHostInteropTest)34 InteropException (com.oracle.truffle.api.interop.InteropException)18 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)17 Specialization (com.oracle.truffle.api.dsl.Specialization)16 UnknownIdentifierException (com.oracle.truffle.api.interop.UnknownIdentifierException)14 LLVMTruffleObject (com.oracle.truffle.llvm.runtime.LLVMTruffleObject)12 ArrayTruffleObject (com.oracle.truffle.api.test.polyglot.ValueHostInteropTest.ArrayTruffleObject)10 Node (com.oracle.truffle.api.nodes.Node)9 UnsupportedTypeException (com.oracle.truffle.api.interop.UnsupportedTypeException)8 CallTarget (com.oracle.truffle.api.CallTarget)7 StackPointer (com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer)7 TestCallback (com.oracle.truffle.nfi.test.interop.TestCallback)7 LinkedHashMap (java.util.LinkedHashMap)7 Source (com.oracle.truffle.api.source.Source)6 Method (java.lang.reflect.Method)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)5