use of com.oracle.truffle.api.CallTarget in project graal by oracle.
the class StackTraceTest method testFirstFrameIsCurrentFrame.
@Test
public void testFirstFrameIsCurrentFrame() {
CallTarget callTarget = createCallTarget(new ReturnStackTraceNode());
StackTrace stack = (StackTrace) callTarget.call();
Assert.assertEquals(1, stack.frames.size());
assertFrameEquals(stack.currentFrame, stack.frames.get(0));
}
use of com.oracle.truffle.api.CallTarget in project graal by oracle.
the class AccessorTest method testAccessorInstrumentationHandlerNotInitialized.
/**
* Test that {@link CallTarget}s can be called even when the instrumentation framework is not
* initialized (e.g., when not using the {@link PolyglotEngine}).
*/
@Test
public void testAccessorInstrumentationHandlerNotInitialized() throws IllegalAccessException {
Object savedAccessor = instrumenthandler.get(null);
instrumenthandler.set(null, null);
try {
CallTarget testCallTarget = Truffle.getRuntime().createCallTarget(RootNode.createConstantNode(42));
assertEquals(42, testCallTarget.call(new Object[0]));
} finally {
instrumenthandler.set(null, savedAccessor);
}
}
use of com.oracle.truffle.api.CallTarget in project graal by oracle.
the class ChildrenNodesTest method test.
@Test
public void test() {
TruffleRuntime runtime = Truffle.getRuntime();
TestChildNode firstChild = new TestChildNode();
TestChildNode secondChild = new TestChildNode();
TestRootNode rootNode = new TestRootNode(new TestChildNode[] { firstChild, secondChild });
CallTarget target = runtime.createCallTarget(rootNode);
Assert.assertEquals(rootNode, firstChild.getParent());
Assert.assertEquals(rootNode, secondChild.getParent());
Iterator<Node> iterator = rootNode.getChildren().iterator();
Assert.assertEquals(firstChild, iterator.next());
Assert.assertEquals(secondChild, iterator.next());
Assert.assertFalse(iterator.hasNext());
Object result = target.call();
Assert.assertEquals(42, result);
}
use of com.oracle.truffle.api.CallTarget in project graal by oracle.
the class FinalFieldTest method test.
@Test
public void test() {
TruffleRuntime runtime = Truffle.getRuntime();
TestRootNode rootNode = new TestRootNode(new TestChildNode[] { new TestChildNode(20), new TestChildNode(22) });
CallTarget target = runtime.createCallTarget(rootNode);
Object result = target.call();
Assert.assertEquals(42, result);
}
use of com.oracle.truffle.api.CallTarget in project graal by oracle.
the class InterfaceChildFieldTest method testChildren.
@Test
public void testChildren() {
TruffleRuntime runtime = Truffle.getRuntime();
TestChildInterface[] children = new TestChildInterface[5];
for (int i = 0; i < children.length; i++) {
children[i] = new TestLeafNode();
}
TestChildrenNode parent = new TestChildrenNode(children);
TestRootNode rootNode = new TestRootNode(parent);
CallTarget target = runtime.createCallTarget(rootNode);
Iterator<Node> iterator = parent.getChildren().iterator();
for (int i = 0; i < children.length; i++) {
Assert.assertEquals(children[i], iterator.next());
}
Assert.assertFalse(iterator.hasNext());
Object result = target.call();
Assert.assertEquals(105, result);
Assert.assertEquals(2 + children.length, NodeUtil.countNodes(rootNode));
Assert.assertEquals(2 + children.length, NodeUtil.countNodes(NodeUtil.cloneNode(rootNode)));
}
Aggregations