Search in sources :

Example 41 with TruffleObject

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

the class JavaInteropTest method noNonStaticPropertiesForAClass.

@SuppressWarnings("unchecked")
@Test
public void noNonStaticPropertiesForAClass() {
    TruffleObject pojo = JavaInterop.asTruffleObject(PublicPOJO.class);
    TruffleObject result = sendKeys(pojo);
    List<Object> propertyNames = JavaInterop.asJavaObject(List.class, result);
    assertEquals("3 members: static field 'y', static method 'readY', plus 'class'", 3, propertyNames.size());
    assertThat(propertyNames, CoreMatchers.hasItems("y", "readY", "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)

Example 42 with TruffleObject

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

the class JavaInteropTest method executableAsFunctionalInterface3.

@Ignore("Interface not accessible")
@Test
public void executableAsFunctionalInterface3() throws Exception {
    assumeTrue("JDK 9 or later", System.getProperty("java.specification.version").compareTo("1.9") >= 0);
    TruffleObject executable = new FunctionObject();
    FunctionalWithDefaults f = JavaInterop.asJavaFunction(FunctionalWithDefaults.class, executable);
    assertEquals(42, f.call((Object) 13, (Object) 29));
    assertEquals(50, f.call(13, 37));
    f.hashCode();
    f.equals(null);
    f.toString();
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Ignore(org.junit.Ignore) Test(org.junit.Test) ValueHostInteropTest(com.oracle.truffle.api.test.polyglot.ValueHostInteropTest)

Example 43 with TruffleObject

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

the class JavaInteropTest method testRecursiveListMarshalling.

@Test
public void testRecursiveListMarshalling() throws UnknownIdentifierException, UnsupportedMessageException {
    List<GregorianCalendar> testList = Arrays.asList(new GregorianCalendar());
    TruffleObject list = JavaInterop.asTruffleObject(testList);
    Object firstElement = ForeignAccess.sendRead(Message.READ.createNode(), list, 0);
    assertTrue(JavaInterop.isJavaObject(firstElement));
}
Also used : GregorianCalendar(java.util.GregorianCalendar) 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 44 with TruffleObject

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

the class JavaInteropTest method accessAllProperties.

@Test
public void accessAllProperties() {
    TruffleObject pojo = JavaInterop.asTruffleObject(new PrivatePOJO());
    Map<?, ?> map = JavaInterop.asJavaObject(Map.class, pojo);
    int cnt = 0;
    for (Map.Entry<?, ?> entry : map.entrySet()) {
        Object key = entry.getKey();
        Object value = entry.getValue();
        assertNotNull(key);
        assertNotNull(value);
        cnt++;
    }
    assertEquals("No properties", 0, cnt);
    assertEquals("Empty: " + map, 0, map.size());
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) AbstractMap(java.util.AbstractMap) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test) ValueHostInteropTest(com.oracle.truffle.api.test.polyglot.ValueHostInteropTest)

Example 45 with TruffleObject

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

the class JavaInteropTest method indexJavaArrayWithNumberTypes.

@Test
public void indexJavaArrayWithNumberTypes() throws Exception {
    int[] a = new int[] { 1, 2, 3 };
    TruffleObject truffleObject = JavaInterop.asTruffleObject(a);
    assertEquals(2, ForeignAccess.sendRead(Message.READ.createNode(), truffleObject, 1));
    assertEquals(2, ForeignAccess.sendRead(Message.READ.createNode(), truffleObject, 1.0));
    assertEquals(2, ForeignAccess.sendRead(Message.READ.createNode(), truffleObject, 1L));
    ForeignAccess.sendWrite(Message.WRITE.createNode(), truffleObject, 1, 42);
    ForeignAccess.sendWrite(Message.WRITE.createNode(), truffleObject, 1.0, 42);
    ForeignAccess.sendWrite(Message.WRITE.createNode(), truffleObject, 1L, 42);
    assertEquals(42, ForeignAccess.sendRead(Message.READ.createNode(), truffleObject, 1));
    assertEquals(42, ForeignAccess.sendRead(Message.READ.createNode(), truffleObject, 1.0));
    assertEquals(42, ForeignAccess.sendRead(Message.READ.createNode(), truffleObject, 1L));
}
Also used : 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