Search in sources :

Example 46 with TruffleObject

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

the class JavaInteropTest method testNewClass.

@Test
public void testNewClass() throws InteropException {
    TruffleObject hashMapClass = JavaInterop.asTruffleObject(HashMap.class);
    Object hashMap = ForeignAccess.sendNew(Message.createNew(0).createNode(), hashMapClass);
    assertThat(hashMap, CoreMatchers.instanceOf(TruffleObject.class));
    assertTrue(JavaInterop.isJavaObject(HashMap.class, (TruffleObject) hashMap));
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test) ValueHostInteropTest(com.oracle.truffle.api.test.polyglot.ValueHostInteropTest)

Example 47 with TruffleObject

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

the class OverloadedTest method testVarArgs.

@Test
public void testVarArgs() throws InteropException {
    TruffleObject stringClass = JavaInterop.asTruffleObject(String.class);
    assertEquals("bla", ForeignAccess.sendInvoke(Message.createInvoke(1).createNode(), stringClass, "format", "bla"));
    assertEquals("42", ForeignAccess.sendInvoke(Message.createInvoke(2).createNode(), stringClass, "format", "%d", 42));
    assertEquals("1337", ForeignAccess.sendInvoke(Message.createInvoke(3).createNode(), stringClass, "format", "%d%d", 13, 37));
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test)

Example 48 with TruffleObject

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

the class OverloadedTest method testWidening.

@Test
public void testWidening() throws InteropException {
    Node n = Message.createInvoke(1).createNode();
    Num num = new Num();
    TruffleObject numobj = JavaInterop.asTruffleObject(num);
    ForeignAccess.sendInvoke(n, numobj, "d", (byte) 42);
    assertEquals("int", num.parameter);
    ForeignAccess.sendInvoke(n, numobj, "d", (short) 42);
    assertEquals("int", num.parameter);
    ForeignAccess.sendInvoke(n, numobj, "d", 42);
    assertEquals("int", num.parameter);
    ForeignAccess.sendInvoke(n, numobj, "d", 42.1f);
    assertEquals("double", num.parameter);
    ForeignAccess.sendInvoke(n, numobj, "d", 42.1d);
    assertEquals("double", num.parameter);
    ForeignAccess.sendInvoke(n, numobj, "d", 0x8000_0000L);
    assertEquals("double", num.parameter);
    ForeignAccess.sendInvoke(n, numobj, "d", 42L);
    assertEquals("int", num.parameter);
    ForeignAccess.sendInvoke(n, numobj, "f", 42L);
    assertEquals("int", num.parameter);
}
Also used : Node(com.oracle.truffle.api.nodes.Node) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test)

Example 49 with TruffleObject

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

the class CallbackWithOverloadConvertTest method callWithCharTest.

@Test
public void callWithCharTest() {
    TruffleObject truffle = JavaInterop.asTruffleObject(this);
    CallWithChar callback = JavaInterop.asJavaObject(CallWithChar.class, truffle);
    callback.callback('A');
    assertEquals('A', ch);
    assertEquals("Int remains zero", 0, i);
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test)

Example 50 with TruffleObject

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

the class CallbackWithOverloadConvertTest method callWithIntTest.

@Test
public void callWithIntTest() {
    TruffleObject truffle = JavaInterop.asTruffleObject(this);
    CallWithInt callback = JavaInterop.asJavaObject(CallWithInt.class, truffle);
    callback.callback(32);
    assertEquals("Char not changed", 0, ch);
    assertEquals("Int changed", 32, i);
}
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