Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/ChildrenNodesTest.java @ 20832:9794217565cd
replaced method substitutions for [Integer|Long].numberOf[Leading|Trailing]Zeros with InvocationPlugins
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Mon, 06 Apr 2015 00:08:22 +0200 |
parents | 8be5c68a779d |
children |
rev | line source |
---|---|
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
1 /* |
11903
df1d665ca846
Truffle; remove uses of Node() constructor in test code
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
7530
diff
changeset
|
2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
4 * |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
8 * |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
14 * |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
18 * |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
21 * questions. |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
22 */ |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
23 package com.oracle.truffle.api.test; |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
24 |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
25 import java.util.*; |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
26 |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
27 import org.junit.*; |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
28 |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
29 import com.oracle.truffle.api.*; |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
30 import com.oracle.truffle.api.frame.*; |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
31 import com.oracle.truffle.api.nodes.*; |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
32 |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
33 /** |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
34 * <h3>Creating an Array of Children Nodes</h3> |
14991
64dcb92ee75a
Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
14628
diff
changeset
|
35 * |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
36 * <p> |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7267
diff
changeset
|
37 * An array of children nodes can be used as a field in a parent node. The field has to be annotated |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7267
diff
changeset
|
38 * with {@link com.oracle.truffle.api.nodes.Node.Children} and must be declared private and final. |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7267
diff
changeset
|
39 * Before assigning the field in the parent node constructor, {@link Node#adoptChildren} must be |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7267
diff
changeset
|
40 * called in order to update the parent pointers in the child nodes. After filling the array with |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7267
diff
changeset
|
41 * its first values, it must never be changed. It is only possible to call {@link Node#replace} on a |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7267
diff
changeset
|
42 * child node. |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
43 * </p> |
14991
64dcb92ee75a
Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
14628
diff
changeset
|
44 * |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
45 * <p> |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7267
diff
changeset
|
46 * The next part of the Truffle API introduction is at |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7267
diff
changeset
|
47 * {@link com.oracle.truffle.api.test.FinalFieldTest}. |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
48 * </p> |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
49 */ |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
50 public class ChildrenNodesTest { |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
51 |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
52 @Test |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
53 public void test() { |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
54 TruffleRuntime runtime = Truffle.getRuntime(); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
55 TestChildNode firstChild = new TestChildNode(); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
56 TestChildNode secondChild = new TestChildNode(); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
57 TestRootNode rootNode = new TestRootNode(new TestChildNode[]{firstChild, secondChild}); |
14628
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
11903
diff
changeset
|
58 CallTarget target = runtime.createCallTarget(rootNode); |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
59 Assert.assertEquals(rootNode, firstChild.getParent()); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
60 Assert.assertEquals(rootNode, secondChild.getParent()); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
61 Iterator<Node> iterator = rootNode.getChildren().iterator(); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
62 Assert.assertEquals(firstChild, iterator.next()); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
63 Assert.assertEquals(secondChild, iterator.next()); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
64 Assert.assertFalse(iterator.hasNext()); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
65 Object result = target.call(); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
66 Assert.assertEquals(42, result); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
67 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
68 |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
69 class TestRootNode extends RootNode { |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
70 |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
71 @Children private final TestChildNode[] children; |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
72 |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
73 public TestRootNode(TestChildNode[] children) { |
11903
df1d665ca846
Truffle; remove uses of Node() constructor in test code
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
7530
diff
changeset
|
74 super(null); |
14628
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
11903
diff
changeset
|
75 this.children = children; |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
76 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
77 |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
78 @Override |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
79 public Object execute(VirtualFrame frame) { |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
80 int sum = 0; |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
81 for (int i = 0; i < children.length; ++i) { |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
82 sum += children[i].execute(); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
83 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
84 return sum; |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
85 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
86 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
87 |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
88 class TestChildNode extends Node { |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7267
diff
changeset
|
89 |
11903
df1d665ca846
Truffle; remove uses of Node() constructor in test code
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
7530
diff
changeset
|
90 public TestChildNode() { |
df1d665ca846
Truffle; remove uses of Node() constructor in test code
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
7530
diff
changeset
|
91 super(null); |
df1d665ca846
Truffle; remove uses of Node() constructor in test code
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
7530
diff
changeset
|
92 } |
df1d665ca846
Truffle; remove uses of Node() constructor in test code
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
7530
diff
changeset
|
93 |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
94 public int execute() { |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
95 return 21; |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
96 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
97 } |
16581
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
14991
diff
changeset
|
98 |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
14991
diff
changeset
|
99 @Test |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
14991
diff
changeset
|
100 public void testMultipleChildrenFields() { |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
14991
diff
changeset
|
101 TruffleRuntime runtime = Truffle.getRuntime(); |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
14991
diff
changeset
|
102 TestChildNode firstChild = new TestChildNode(); |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
14991
diff
changeset
|
103 TestChildNode secondChild = new TestChildNode(); |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
14991
diff
changeset
|
104 TestChildNode thirdChild = new TestChildNode(); |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
14991
diff
changeset
|
105 TestChildNode forthChild = new TestChildNode(); |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
14991
diff
changeset
|
106 TestRootNode rootNode = new TestRoot2Node(new TestChildNode[]{firstChild, secondChild}, new TestChildNode[]{thirdChild, forthChild}); |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
14991
diff
changeset
|
107 CallTarget target = runtime.createCallTarget(rootNode); |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
14991
diff
changeset
|
108 Assert.assertEquals(rootNode, firstChild.getParent()); |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
14991
diff
changeset
|
109 Assert.assertEquals(rootNode, secondChild.getParent()); |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
14991
diff
changeset
|
110 Assert.assertEquals(rootNode, thirdChild.getParent()); |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
14991
diff
changeset
|
111 Assert.assertEquals(rootNode, forthChild.getParent()); |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
14991
diff
changeset
|
112 Iterator<Node> iterator = rootNode.getChildren().iterator(); |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
14991
diff
changeset
|
113 Assert.assertEquals(firstChild, iterator.next()); |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
14991
diff
changeset
|
114 Assert.assertEquals(secondChild, iterator.next()); |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
14991
diff
changeset
|
115 Assert.assertEquals(thirdChild, iterator.next()); |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
14991
diff
changeset
|
116 Assert.assertEquals(forthChild, iterator.next()); |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
14991
diff
changeset
|
117 Assert.assertFalse(iterator.hasNext()); |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
14991
diff
changeset
|
118 Object result = target.call(); |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
14991
diff
changeset
|
119 Assert.assertEquals(2 * 42, result); |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
14991
diff
changeset
|
120 } |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
14991
diff
changeset
|
121 |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
14991
diff
changeset
|
122 class TestRoot2Node extends TestRootNode { |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
14991
diff
changeset
|
123 @Children private final TestChildNode[] children1; |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
14991
diff
changeset
|
124 @Children private final TestChildNode[] children2; |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
14991
diff
changeset
|
125 |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
14991
diff
changeset
|
126 public TestRoot2Node(TestChildNode[] children1, TestChildNode[] children2) { |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
14991
diff
changeset
|
127 super(new TestChildNode[0]); |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
14991
diff
changeset
|
128 this.children1 = children1; |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
14991
diff
changeset
|
129 this.children2 = children2; |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
14991
diff
changeset
|
130 } |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
14991
diff
changeset
|
131 |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
14991
diff
changeset
|
132 @Override |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
14991
diff
changeset
|
133 public Object execute(VirtualFrame frame) { |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
14991
diff
changeset
|
134 int sum = 0; |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
14991
diff
changeset
|
135 for (int i = 0; i < children1.length; ++i) { |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
14991
diff
changeset
|
136 sum += children1[i].execute(); |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
14991
diff
changeset
|
137 } |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
14991
diff
changeset
|
138 for (int i = 0; i < children2.length; ++i) { |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
14991
diff
changeset
|
139 sum += children2[i].execute(); |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
14991
diff
changeset
|
140 } |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
14991
diff
changeset
|
141 return sum; |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
14991
diff
changeset
|
142 } |
8be5c68a779d
Truffle: revert to previous iterator implementation, add test case
Andreas Woess <andreas.woess@jku.at>
parents:
14991
diff
changeset
|
143 } |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
144 } |