use of com.oracle.truffle.api.TruffleRuntime in project graal by oracle.
the class ReplaceTest method test.
@Test
public void test() {
TruffleRuntime runtime = Truffle.getRuntime();
UnresolvedNode leftChild = new UnresolvedNode("20");
UnresolvedNode rightChild = new UnresolvedNode("22");
TestRootNode rootNode = new TestRootNode(new ValueNode[] { leftChild, rightChild });
CallTarget target = runtime.createCallTarget(rootNode);
assertEquals(rootNode, leftChild.getParent());
assertEquals(rootNode, rightChild.getParent());
Iterator<Node> iterator = rootNode.getChildren().iterator();
Assert.assertEquals(leftChild, iterator.next());
Assert.assertEquals(rightChild, iterator.next());
Assert.assertFalse(iterator.hasNext());
Object result = target.call();
assertEquals(42, result);
assertEquals(42, target.call());
iterator = rootNode.getChildren().iterator();
Assert.assertEquals(ResolvedNode.class, iterator.next().getClass());
Assert.assertEquals(ResolvedNode.class, iterator.next().getClass());
Assert.assertFalse(iterator.hasNext());
iterator = rootNode.getChildren().iterator();
Assert.assertEquals(rootNode, iterator.next().getParent());
Assert.assertEquals(rootNode, iterator.next().getParent());
Assert.assertFalse(iterator.hasNext());
}
use of com.oracle.truffle.api.TruffleRuntime 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.TruffleRuntime 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.TruffleRuntime in project graal by oracle.
the class FrameTest method framesCanBeMaterialized.
@Test
public void framesCanBeMaterialized() {
final TruffleRuntime runtime = Truffle.getRuntime();
class FrameRootNode extends RootNode {
FrameRootNode() {
super(null);
}
@Override
public Object execute(VirtualFrame frame) {
FrameInstance frameInstance = runtime.getCurrentFrame();
Frame readWrite = frameInstance.getFrame(FrameInstance.FrameAccess.READ_WRITE);
Frame materialized = frameInstance.getFrame(FrameInstance.FrameAccess.MATERIALIZE);
assertTrue("Really materialized: " + materialized, materialized instanceof MaterializedFrame);
assertEquals("It's my frame", frame, readWrite);
return this;
}
}
FrameRootNode frn = new FrameRootNode();
Object ret = Truffle.getRuntime().createCallTarget(frn).call();
assertEquals("Returns itself", frn, ret);
}
use of com.oracle.truffle.api.TruffleRuntime 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