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;
}
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);
}
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;
}
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);
}
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);
}
Aggregations