use of com.oracle.truffle.api.interop.TruffleObject in project graal by oracle.
the class TestMemberAccess method testIterate.
@Test
public void testIterate() throws InteropException {
List<Object> l = new ArrayList<>();
l.add("one");
l.add("two");
TruffleObject listObject = JavaInterop.asTruffleObject(l);
TruffleObject itFunction = (TruffleObject) ForeignAccess.sendRead(readNode, listObject, "iterator");
TruffleObject it = (TruffleObject) ForeignAccess.sendExecute(executeNode, itFunction);
TruffleObject hasNextFunction = (TruffleObject) ForeignAccess.sendRead(readNode, it, "hasNext");
List<Object> returned = new ArrayList<>();
while ((boolean) ForeignAccess.sendExecute(executeNode, hasNextFunction)) {
TruffleObject nextFunction = (TruffleObject) ForeignAccess.sendRead(readNode, it, "next");
Object element = ForeignAccess.sendExecute(executeNode, nextFunction);
returned.add(element);
}
assertEquals(l.size(), returned.size());
assertEquals(l.get(0), returned.get(0));
assertEquals(l.get(1), returned.get(1));
}
use of com.oracle.truffle.api.interop.TruffleObject in project graal by oracle.
the class TestMemberAccess method testOverloadedConstructor1.
@Test
public void testOverloadedConstructor1() throws InteropException {
TruffleObject testClass = JavaInterop.asTruffleObject(TestConstructor.class);
TruffleObject testObj;
testObj = (TruffleObject) ForeignAccess.sendNew(newNode, testClass);
assertEquals(void.class.getName(), ForeignAccess.sendRead(readNode, testObj, "ctor"));
testObj = (TruffleObject) ForeignAccess.sendNew(newNode, testClass, 42);
assertEquals(int.class.getName(), ForeignAccess.sendRead(readNode, testObj, "ctor"));
testObj = (TruffleObject) ForeignAccess.sendNew(newNode, testClass, 4.2f);
assertEquals(float.class.getName(), ForeignAccess.sendRead(readNode, testObj, "ctor"));
}
use of com.oracle.truffle.api.interop.TruffleObject in project graal by oracle.
the class TestMemberAccess method testObjectReadIndex.
@Test
public void testObjectReadIndex() throws InteropException {
TruffleObject arrayObject = JavaInterop.asTruffleObject(new TestClass());
try {
ForeignAccess.sendRead(readNode, arrayObject, 0);
fail();
} catch (UnsupportedMessageException e) {
}
}
use of com.oracle.truffle.api.interop.TruffleObject in project graal by oracle.
the class TestMemberAccess method testOverloadedConstructor2.
@Test
public void testOverloadedConstructor2() throws InteropException {
TruffleObject testClass = JavaInterop.asTruffleObject(TestConstructor.class);
TruffleObject testObj;
testObj = (TruffleObject) ForeignAccess.sendNew(newNode, testClass, (short) 42);
assertEquals(int.class.getName(), ForeignAccess.sendRead(readNode, testObj, "ctor"));
testObj = (TruffleObject) ForeignAccess.sendNew(newNode, testClass, 4.2f);
// TODO prioritize conversion from double to float over double to int
// assertEquals(float.class.getName(), ForeignAccess.sendRead(readNode, testObj, "ctor"));
}
use of com.oracle.truffle.api.interop.TruffleObject in project graal by oracle.
the class TestMemberAccess method testNewArray.
@Test
public void testNewArray() throws InteropException {
TruffleObject arrayClass = JavaInterop.asTruffleObject(Array.class);
TruffleObject newInstanceMethod = (TruffleObject) ForeignAccess.send(readNode, arrayClass, "newInstance");
TruffleObject stringArray = (TruffleObject) ForeignAccess.sendExecute(executeNode, newInstanceMethod, JavaInterop.asTruffleObject(String.class), 2);
assertTrue(JavaInteropTest.isArray(stringArray));
}
Aggregations