use of com.oracle.truffle.api.interop.TruffleObject in project graal by oracle.
the class TruffleTCK method testPrimitiveReturnTypeInt.
/**
* @since 0.8 or earlier
*/
@Test
public void testPrimitiveReturnTypeInt() throws Exception {
PolyglotEngine.Value apply = findGlobalSymbol(applyNumbers());
int value = RANDOM.nextInt(100);
TruffleObject fn = JavaInterop.asTruffleFunction(ObjectBinaryOperation.class, new ConstantFunction(value));
Number n = apply.execute(fn).as(Number.class);
assertEquals("The same value returned (" + value + " + 10): ", value + 10, n.intValue());
}
use of com.oracle.truffle.api.interop.TruffleObject in project graal by oracle.
the class TruffleTCK method testPrimitiveReturnTypeShort.
/**
* @since 0.8 or earlier
*/
@Test
public void testPrimitiveReturnTypeShort() throws Exception {
PolyglotEngine.Value apply = findGlobalSymbol(applyNumbers());
short value = (short) RANDOM.nextInt(100);
TruffleObject fn = JavaInterop.asTruffleFunction(ObjectBinaryOperation.class, new ConstantFunction(value));
Number n = apply.execute(fn).as(Number.class);
assertEquals("The same value returned (" + value + " + 10): ", value + 10, n.shortValue());
}
use of com.oracle.truffle.api.interop.TruffleObject in project graal by oracle.
the class TruffleTCK method testMaxOrMinValue.
/**
* @since 0.8 or earlier
*/
@Test
public void testMaxOrMinValue() throws Exception {
PolyglotEngine.Value apply = findGlobalSymbol(applyNumbers());
TruffleObject fn = JavaInterop.asTruffleFunction(LongBinaryOperation.class, new MaxMinObject(true));
Object res = apply.execute(fn).get();
assert res instanceof Number : "result should be a number: " + res;
Number n = (Number) res;
assert 42 == n.intValue() : "32 > 18 and plus 10";
}
use of com.oracle.truffle.api.interop.TruffleObject in project graal by oracle.
the class TruffleTCK method testReadFromObjectWithValueProperty.
/**
* @since 0.16
*/
@Test
public void testReadFromObjectWithValueProperty() 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);
}
use of com.oracle.truffle.api.interop.TruffleObject in project graal by oracle.
the class InstrumentableNodeTest method assertProperties.
private static void assertProperties(Object receiver, Object... properties) {
try {
assertTrue(receiver instanceof TruffleObject);
TruffleObject obj = (TruffleObject) receiver;
Node hasKeysNode = Message.HAS_KEYS.createNode();
Node keysNode = Message.KEYS.createNode();
assertTrue(ForeignAccess.sendHasKeys(hasKeysNode, obj));
TruffleObject keys = ForeignAccess.sendKeys(keysNode, obj);
for (int i = 0; i < properties.length; i = i + 2) {
String expectedKey = (String) properties[i];
Object expectedValue = properties[i + 1];
Node readNode = Message.READ.createNode();
Object key = ForeignAccess.sendRead(readNode, keys, i / 2);
assertEquals(expectedKey, key);
assertEquals(expectedValue, ForeignAccess.sendRead(readNode, obj, key));
}
} catch (InteropException e) {
throw e.raise();
}
}
Aggregations