Search in sources :

Example 56 with TruffleObject

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

the class JavaInteropTest method conversionToClass2.

@Test
public void conversionToClass2() {
    TruffleObject expected = JavaInterop.asTruffleObject(Class.class);
    TruffleObject computed = JavaInterop.toJavaClass(JavaInterop.asTruffleObject(Data.class));
    assertEquals("Both class objects are the same", expected, computed);
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test) ValueHostInteropTest(com.oracle.truffle.api.test.polyglot.ValueHostInteropTest)

Example 57 with TruffleObject

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

the class JavaInteropTest method executableAsFunctionalInterface2.

@Test
public void executableAsFunctionalInterface2() throws Exception {
    TruffleObject executable = new FunctionObject();
    FunctionalWithObjectMethodOverrides f = JavaInterop.asJavaFunction(FunctionalWithObjectMethodOverrides.class, executable);
    assertEquals(50, f.call(13, 37));
    f.hashCode();
    f.equals(null);
    f.toString();
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test) ValueHostInteropTest(com.oracle.truffle.api.test.polyglot.ValueHostInteropTest)

Example 58 with TruffleObject

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

the class JavaInteropTest method testExecuteClass.

@Test
public void testExecuteClass() {
    TruffleObject hashMapClass = JavaInterop.asTruffleObject(HashMap.class);
    assertThrowsExceptionWithCause(() -> ForeignAccess.sendExecute(Message.createExecute(0).createNode(), hashMapClass), UnsupportedMessageException.class);
    assertFalse("IS_EXECUTABLE", ForeignAccess.sendIsExecutable(Message.IS_EXECUTABLE.createNode(), hashMapClass));
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test) ValueHostInteropTest(com.oracle.truffle.api.test.polyglot.ValueHostInteropTest)

Example 59 with TruffleObject

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

the class JavaInteropTest method conversionToClassNull.

@Test
public void conversionToClassNull() {
    TruffleObject expected = JavaInterop.asTruffleObject(null);
    TruffleObject computed = JavaInterop.toJavaClass(expected);
    assertEquals(expected, computed);
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test) ValueHostInteropTest(com.oracle.truffle.api.test.polyglot.ValueHostInteropTest)

Example 60 with TruffleObject

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

the class JavaInteropTest method invokeJavaLangObjectFields.

@Test
public void invokeJavaLangObjectFields() throws InteropException {
    Object string = ForeignAccess.sendInvoke(Message.createInvoke(0).createNode(), obj, "toString");
    assertTrue(string instanceof String && ((String) string).startsWith(Data.class.getName() + "@"));
    Object clazz = ForeignAccess.sendInvoke(Message.createInvoke(0).createNode(), obj, "getClass");
    assertTrue(clazz instanceof TruffleObject && JavaInterop.asJavaObject((TruffleObject) clazz) == Data.class);
    assertEquals(true, ForeignAccess.sendInvoke(Message.createInvoke(1).createNode(), obj, "equals", obj));
    assertTrue(ForeignAccess.sendInvoke(Message.createInvoke(0).createNode(), obj, "hashCode") instanceof Integer);
    for (String m : new String[] { "notify", "notifyAll", "wait" }) {
        assertThrowsExceptionWithCause(() -> ForeignAccess.sendInvoke(Message.createInvoke(0).createNode(), obj, m), IllegalMonitorStateException.class);
    }
}
Also used : 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)

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