Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/ChildrenNodesTest.java @ 14628:a08b8694f556
Truffle: Node API changes
deprecate adoptChild, no longer needed in constructor
add Node#insert for inserting new nodes into the tree (previously adoptChild)
add Node#adoptChildren() helper method that adopts all (direct and indirect) children of a node, automatically called in TruffleRuntime#createCallTarget
author | Andreas Woess <andreas.woess@jku.at> |
---|---|
date | Wed, 19 Mar 2014 23:11:46 +0100 |
parents | df1d665ca846 |
children | 64dcb92ee75a |
comparison
equal
deleted
inserted
replaced
14627:46c020971d9c | 14628:a08b8694f556 |
---|---|
53 public void test() { | 53 public void test() { |
54 TruffleRuntime runtime = Truffle.getRuntime(); | 54 TruffleRuntime runtime = Truffle.getRuntime(); |
55 TestChildNode firstChild = new TestChildNode(); | 55 TestChildNode firstChild = new TestChildNode(); |
56 TestChildNode secondChild = new TestChildNode(); | 56 TestChildNode secondChild = new TestChildNode(); |
57 TestRootNode rootNode = new TestRootNode(new TestChildNode[]{firstChild, secondChild}); | 57 TestRootNode rootNode = new TestRootNode(new TestChildNode[]{firstChild, secondChild}); |
58 CallTarget target = runtime.createCallTarget(rootNode); | |
58 Assert.assertEquals(rootNode, firstChild.getParent()); | 59 Assert.assertEquals(rootNode, firstChild.getParent()); |
59 Assert.assertEquals(rootNode, secondChild.getParent()); | 60 Assert.assertEquals(rootNode, secondChild.getParent()); |
60 Iterator<Node> iterator = rootNode.getChildren().iterator(); | 61 Iterator<Node> iterator = rootNode.getChildren().iterator(); |
61 Assert.assertEquals(firstChild, iterator.next()); | 62 Assert.assertEquals(firstChild, iterator.next()); |
62 Assert.assertEquals(secondChild, iterator.next()); | 63 Assert.assertEquals(secondChild, iterator.next()); |
63 Assert.assertFalse(iterator.hasNext()); | 64 Assert.assertFalse(iterator.hasNext()); |
64 CallTarget target = runtime.createCallTarget(rootNode); | |
65 Object result = target.call(); | 65 Object result = target.call(); |
66 Assert.assertEquals(42, result); | 66 Assert.assertEquals(42, result); |
67 } | 67 } |
68 | 68 |
69 class TestRootNode extends RootNode { | 69 class TestRootNode extends RootNode { |
70 | 70 |
71 @Children private final TestChildNode[] children; | 71 @Children private final TestChildNode[] children; |
72 | 72 |
73 public TestRootNode(TestChildNode[] children) { | 73 public TestRootNode(TestChildNode[] children) { |
74 super(null); | 74 super(null); |
75 this.children = adoptChildren(children); | 75 this.children = children; |
76 } | 76 } |
77 | 77 |
78 @Override | 78 @Override |
79 public Object execute(VirtualFrame frame) { | 79 public Object execute(VirtualFrame frame) { |
80 int sum = 0; | 80 int sum = 0; |