Search in sources :

Example 76 with TruffleObject

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

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

the class NativeAPIImpl method getClosureObject.

@CEntryPoint
@CEntryPointOptions(prologue = EnterNativeTruffleEnvPrologue.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class)
static TruffleObjectHandle getClosureObject(NativeTruffleEnv env, PointerBase closure) {
    TruffleNFISupport support = ImageSingletons.lookup(TruffleNFISupport.class);
    Target_com_oracle_truffle_nfi_impl_NFIContext context = lookupContext(env.context());
    TruffleObject ret = context.getClosureObject(closure.rawValue());
    return support.createGlobalHandle(ret);
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPointOptions(com.oracle.svm.core.c.function.CEntryPointOptions)

Example 78 with TruffleObject

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

the class PolyglotLanguageContext method lookupGuest.

Object lookupGuest(String symbolName) {
    ensureInitialized(null);
    Iterable<?> topScopes = VMAccessor.instrumentAccess().findTopScopes(env);
    for (Object topScope : topScopes) {
        Scope scope = (Scope) topScope;
        TruffleObject variables = (TruffleObject) scope.getVariables();
        int symbolInfo = ForeignAccess.sendKeyInfo(keyInfoNode, variables, symbolName);
        if (KeyInfo.isExisting(symbolInfo) && KeyInfo.isReadable(symbolInfo)) {
            try {
                return ForeignAccess.sendRead(readNode, variables, symbolName);
            } catch (InteropException ex) {
                throw new AssertionError(symbolName, ex);
            }
        }
    }
    return null;
}
Also used : Scope(com.oracle.truffle.api.Scope) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) InteropException(com.oracle.truffle.api.interop.InteropException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject)

Example 79 with TruffleObject

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

the class TruffleRunnerSnippets method warmupTest.

// END: TruffleRunnerSnippets#ExampleTest
// BEGIN: TruffleRunnerSnippets#warmupTest
@Test
@Warmup(5)
public void warmupTest(@Inject(TestExecuteNode.class) CallTarget target) {
    TruffleObject receiver = prepareArgumentValue();
    Object ret = target.call(receiver);
    Assert.assertEquals(expectedRetValue(), ret);
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Warmup(com.oracle.truffle.tck.TruffleRunner.Warmup) Test(org.junit.Test)

Example 80 with TruffleObject

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

the class TruffleTCK method testWriteToObjectWithValueProperty.

/**
 * @since 0.16
 */
@Test
public void testWriteToObjectWithValueProperty() throws Exception {
    String id = objectWithValueProperty();
    if (id == null) {
        return;
    }
    PolyglotEngine.Value apply = findGlobalSymbol(id);
    TruffleObject truffleObject = (TruffleObject) apply.execute().get();
    assertIsObjectOfLanguage(truffleObject);
    ObjectWithValueInterface object = JavaInterop.asJavaObject(ObjectWithValueInterface.class, truffleObject);
    Assert.assertEquals(42.0, object.value(), 0.1);
    object.value(13.0);
    Assert.assertEquals(13.0, object.value(), 0.1);
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test)

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