use of com.oracle.truffle.api.interop.TruffleObject in project graal by oracle.
the class TruffleTCK method testPrimitiveReturnTypeDouble.
/**
* @since 0.8 or earlier
*/
@Test
public void testPrimitiveReturnTypeDouble() throws Exception {
PolyglotEngine.Value apply = findGlobalSymbol(applyNumbers());
double value = RANDOM.nextInt(1000) + RANDOM.nextDouble();
TruffleObject fn = JavaInterop.asTruffleFunction(ObjectBinaryOperation.class, new ConstantFunction(value));
Number n = apply.execute(fn).as(Number.class);
assertDouble("The same value returned (" + value + " + 10): ", value + 10, n.doubleValue());
}
use of com.oracle.truffle.api.interop.TruffleObject in project graal by oracle.
the class TruffleTCK method unwrapTruffleObject.
private static Object unwrapTruffleObject(Object obj) {
try {
if (obj instanceof TruffleObject) {
Class<?> eto = Class.forName("com.oracle.truffle.api.vm.EngineTruffleObject");
if (eto.isInstance(obj)) {
final Field field = eto.getDeclaredField("delegate");
field.setAccessible(true);
return field.get(obj);
}
}
return obj;
} catch (Exception ex) {
throw new IllegalStateException(ex);
}
}
use of com.oracle.truffle.api.interop.TruffleObject in project graal by oracle.
the class TruffleTCK method testIsExecutable.
/**
* @since 0.16
*/
@Test
public void testIsExecutable() throws Exception {
String id = functionAddNumbers();
if (id == null) {
return;
}
PolyglotEngine.Value apply = findGlobalSymbol(id);
TruffleObject truffleObject = (TruffleObject) apply.execute().get();
assertIsObjectOfLanguage(truffleObject);
MessageInterface object = JavaInterop.asJavaObject(MessageInterface.class, truffleObject);
Assert.assertEquals(true, object.isExecutable());
}
use of com.oracle.truffle.api.interop.TruffleObject in project graal by oracle.
the class TruffleTCK method testObjectWithKeyInfoAttributes.
/**
* @since 0.26
*/
@Test
public void testObjectWithKeyInfoAttributes() throws Exception {
String id = objectWithKeyInfoAttributes();
if (id == null) {
return;
}
PolyglotEngine.Value apply = findGlobalSymbol(id);
TruffleObject obj = (TruffleObject) apply.execute().get();
assertIsObjectOfLanguage(obj);
KeyInfoInterface object = JavaInterop.asJavaObject(KeyInfoInterface.class, obj);
int numKeys = KeyInfo.NONE;
int keyInfo = object.unknown();
assertFalse("An unknown property", KeyInfo.isExisting(keyInfo));
int ro = object.ro();
if (KeyInfo.isExisting(ro)) {
assertTrue(KeyInfo.isReadable(ro));
assertFalse(KeyInfo.isWritable(ro));
assertFalse(KeyInfo.isInternal(ro));
numKeys++;
}
int wo = object.wo();
if (KeyInfo.isExisting(wo)) {
assertFalse(KeyInfo.isReadable(wo));
assertTrue(KeyInfo.isWritable(wo));
assertFalse(KeyInfo.isInternal(wo));
numKeys++;
}
int rw = object.rw();
if (KeyInfo.isExisting(rw)) {
assertTrue(KeyInfo.isReadable(rw));
assertTrue(KeyInfo.isWritable(rw));
assertFalse(KeyInfo.isInternal(rw));
numKeys++;
}
int rm = object.rm();
if (KeyInfo.isExisting(rm)) {
assertTrue(KeyInfo.isRemovable(rm));
numKeys++;
}
int invocable = object.invocable();
if (KeyInfo.isExisting(invocable)) {
assertTrue(KeyInfo.isInvocable(invocable));
assertFalse(KeyInfo.isInternal(invocable));
numKeys++;
}
int intern = object.intern();
if (KeyInfo.isExisting(intern)) {
assertTrue(KeyInfo.isInternal(intern));
}
Map map = JavaInterop.asJavaObject(Map.class, obj);
assertEquals(map.toString(), numKeys, map.size());
if (KeyInfo.isExisting(ro)) {
assertTrue(map.containsKey("ro"));
}
if (KeyInfo.isExisting(wo)) {
assertTrue(map.containsKey("wo"));
}
if (KeyInfo.isExisting(rw)) {
assertTrue(map.containsKey("rw"));
}
if (KeyInfo.isExisting(rm)) {
assertTrue(map.containsKey("rm"));
}
if (KeyInfo.isExisting(invocable)) {
assertTrue(map.containsKey("invocable"));
}
assertFalse(map.containsKey("intern"));
map = JavaInterop.getMapView(map, true);
if (KeyInfo.isExisting(intern)) {
assertEquals(numKeys + 1, map.size());
assertTrue(map.containsKey("intern"));
} else {
assertEquals(numKeys, map.size());
}
}
use of com.oracle.truffle.api.interop.TruffleObject in project graal by oracle.
the class TruffleTCK method testRootNodeName.
/**
* @since 0.15
*/
@Test
public void testRootNodeName() throws Exception {
final int[] haltCount = new int[1];
final String name = applyNumbers();
final String[] actualName = new String[1];
final PolyglotEngine engine = prepareVM(PolyglotEngine.newBuilder());
final PolyglotEngine.Value apply = engine.findGlobalSymbol(name);
final int value = RANDOM.nextInt(100);
final TruffleObject fn = JavaInterop.asTruffleFunction(ObjectBinaryOperation.class, new ConstantFunction(value));
try (DebuggerSession session = Debugger.find(engine).startSession(new SuspendedCallback() {
public void onSuspend(SuspendedEvent ev) {
actualName[0] = ev.getTopStackFrame().getName();
haltCount[0] = haltCount[0] + 1;
}
})) {
session.suspendNextExecution();
apply.execute(fn).as(Number.class);
}
assertEquals(1, haltCount[0]);
assertEquals(name, actualName[0]);
}
Aggregations