Search in sources :

Example 86 with TruffleObject

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());
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test)

Example 87 with TruffleObject

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());
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test)

Example 88 with TruffleObject

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";
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) TestObject(com.oracle.truffle.tck.impl.TestObject) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test)

Example 89 with TruffleObject

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);
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test)

Example 90 with TruffleObject

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();
    }
}
Also used : Node(com.oracle.truffle.api.nodes.Node) ExpressionNode(com.oracle.truffle.api.instrumentation.test.InstrumentationTestLanguage.ExpressionNode) MaterializeChildExpressionNode(com.oracle.truffle.api.instrumentation.test.InstrumentationTestLanguage.MaterializeChildExpressionNode) MaterializedChildExpressionNode(com.oracle.truffle.api.instrumentation.test.InstrumentationTestLanguage.MaterializedChildExpressionNode) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) InteropException(com.oracle.truffle.api.interop.InteropException) 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