Mercurial > hg > truffle
annotate truffle/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/PolymorphicTest.java @ 22548:6b76a24fffbd default tip
Use all variables: a, b, u,v and x, y
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Thu, 14 Jan 2016 14:20:57 +0100 |
parents | 5309cc9668e3 |
children |
rev | line source |
---|---|
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1 /* |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
4 * |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
8 * |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
13 * accompanied this code). |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
14 * |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
18 * |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
21 * questions. |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
22 */ |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
23 package com.oracle.truffle.api.dsl.test; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
24 |
22241
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
25 import static com.oracle.truffle.api.dsl.test.TestHelper.array; |
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
26 import static com.oracle.truffle.api.dsl.test.TestHelper.assertRuns; |
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
27 import static org.junit.Assert.assertEquals; |
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
28 |
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
29 import java.util.Arrays; |
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
30 import java.util.HashSet; |
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
31 import java.util.Set; |
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
32 |
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
33 import org.junit.Assert; |
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
34 import org.junit.Test; |
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
35 |
22157
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
36 import com.oracle.truffle.api.dsl.Fallback; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
37 import com.oracle.truffle.api.dsl.NodeChild; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
38 import com.oracle.truffle.api.dsl.Specialization; |
16756
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
39 import com.oracle.truffle.api.dsl.test.PolymorphicTestFactory.Polymorphic1Factory; |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
40 import com.oracle.truffle.api.dsl.test.PolymorphicTestFactory.Polymorphic2Factory; |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
41 import com.oracle.truffle.api.dsl.test.PolymorphicTestFactory.Polymorphic3Factory; |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
42 import com.oracle.truffle.api.dsl.test.TestHelper.ExecutionListener; |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
43 import com.oracle.truffle.api.dsl.test.TypeSystemTest.TestRootNode; |
11320
80de3bbfa8b9
Truffle-DSL: fixed inconsistent children for polymorphic -> generic rewrites. (GRAAL-425)
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
44 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode; |
22157
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
45 import com.oracle.truffle.api.nodes.Node; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
46 import com.oracle.truffle.api.nodes.NodeCost; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
47 import com.oracle.truffle.api.nodes.NodeUtil; |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
48 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
49 public class PolymorphicTest { |
22241
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
50 |
11544
e5b5a5cb0ac7
Truffle-DSL: polymorphic test asserts now on any child node's parent.
Christian Humer <christian.humer@gmail.com>
parents:
11320
diff
changeset
|
51 private static void assertParent(Node expectedParent, Node child) { |
e5b5a5cb0ac7
Truffle-DSL: polymorphic test asserts now on any child node's parent.
Christian Humer <christian.humer@gmail.com>
parents:
11320
diff
changeset
|
52 Node parent = child.getParent(); |
e5b5a5cb0ac7
Truffle-DSL: polymorphic test asserts now on any child node's parent.
Christian Humer <christian.humer@gmail.com>
parents:
11320
diff
changeset
|
53 while (parent != null && parent != expectedParent) { |
e5b5a5cb0ac7
Truffle-DSL: polymorphic test asserts now on any child node's parent.
Christian Humer <christian.humer@gmail.com>
parents:
11320
diff
changeset
|
54 parent = parent.getParent(); |
e5b5a5cb0ac7
Truffle-DSL: polymorphic test asserts now on any child node's parent.
Christian Humer <christian.humer@gmail.com>
parents:
11320
diff
changeset
|
55 } |
e5b5a5cb0ac7
Truffle-DSL: polymorphic test asserts now on any child node's parent.
Christian Humer <christian.humer@gmail.com>
parents:
11320
diff
changeset
|
56 |
e5b5a5cb0ac7
Truffle-DSL: polymorphic test asserts now on any child node's parent.
Christian Humer <christian.humer@gmail.com>
parents:
11320
diff
changeset
|
57 if (parent != expectedParent) { |
e5b5a5cb0ac7
Truffle-DSL: polymorphic test asserts now on any child node's parent.
Christian Humer <christian.humer@gmail.com>
parents:
11320
diff
changeset
|
58 assertEquals(expectedParent, parent); |
e5b5a5cb0ac7
Truffle-DSL: polymorphic test asserts now on any child node's parent.
Christian Humer <christian.humer@gmail.com>
parents:
11320
diff
changeset
|
59 } |
e5b5a5cb0ac7
Truffle-DSL: polymorphic test asserts now on any child node's parent.
Christian Humer <christian.humer@gmail.com>
parents:
11320
diff
changeset
|
60 } |
e5b5a5cb0ac7
Truffle-DSL: polymorphic test asserts now on any child node's parent.
Christian Humer <christian.humer@gmail.com>
parents:
11320
diff
changeset
|
61 |
16756
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
62 public static void assertNoDuplicates(Node node, Node... ignored) { |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
63 assertNoDuplicatesRec(new HashSet<>(Arrays.asList(ignored)), new HashSet<Class<?>>(), node); |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
64 } |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
65 |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
66 private static void assertNoDuplicatesRec(Set<Node> ignored, Set<Class<?>> seenClasses, Node current) { |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
67 if (!ignored.contains(current)) { |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
68 if (seenClasses.contains(current.getClass())) { |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
69 Assert.fail(String.format("Multiple occurences of the same class %s. %nTree: %s", current.getClass().getSimpleName(), NodeUtil.printCompactTreeToString(current.getRootNode()))); |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
70 } else { |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
71 seenClasses.add(current.getClass()); |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
72 } |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
73 } |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
74 |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
75 for (Node child : current.getChildren()) { |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
76 if (child != null) { |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
77 assertNoDuplicatesRec(ignored, seenClasses, child); |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
78 } |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
79 } |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
80 } |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
81 |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
82 @Test |
16756
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
83 public void testPolymorphic1() { |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
84 assertRuns(Polymorphic1Factory.getInstance(), // |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
85 array(42, 43, true, false, "a", "b"), // |
18163
c88ab4f1f04a
re-enabled Checkstyle with the release of 6.0 that supports Java 8; fixed existing Checkstyle warnings
Doug Simon <doug.simon@oracle.com>
parents:
16760
diff
changeset
|
86 array(42, 43, true, false, "a", "b"), // |
16756
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
87 new ExecutionListener() { |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
88 public void afterExecution(TestRootNode<? extends ValueNode> node, int index, Object value, Object expectedResult, Object actualResult, boolean last) { |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
89 Polymorphic1 polymorphic = ((Polymorphic1) node.getNode()); |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
90 assertParent(node.getNode(), polymorphic.getA()); |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
91 assertNoDuplicates(polymorphic, polymorphic.getA()); |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
92 if (index == 0) { |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
93 assertEquals(NodeCost.MONOMORPHIC, node.getNode().getCost()); |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
94 } |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
95 } |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
96 }); |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
97 } |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
98 |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
99 @NodeChild("a") |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
100 abstract static class Polymorphic1 extends ValueNode { |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
101 |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
102 public abstract ValueNode getA(); |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
103 |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
104 @Specialization |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
105 int add(int a) { |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
106 return a; |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
107 } |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
108 |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
109 @Specialization |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
110 boolean add(boolean a) { |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
111 return a; |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
112 } |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
113 |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
114 @Specialization |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
115 String add(String a) { |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
116 return a; |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
117 } |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
118 |
16760
9f38d222fa6c
Truffle-DSL: renamed @Generic to @Fallback.
Christian Humer <christian.humer@gmail.com>
parents:
16756
diff
changeset
|
119 @Fallback |
16756
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
120 String add(Object left) { |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
121 throw new AssertionError(left.toString()); |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
122 } |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
123 |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
124 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
125 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
126 @Test |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
127 public void testPolymorphic2() { |
16756
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
128 assertRuns(Polymorphic2Factory.getInstance(), // |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
129 array(0, 1, 1, "1", "2", 2, 3), // |
18163
c88ab4f1f04a
re-enabled Checkstyle with the release of 6.0 that supports Java 8; fixed existing Checkstyle warnings
Doug Simon <doug.simon@oracle.com>
parents:
16760
diff
changeset
|
130 array(0, 1, 1, "1", "2", 2, 3), // |
16756
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
131 new ExecutionListener() { |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
132 public void afterExecution(TestRootNode<? extends ValueNode> node, int index, Object value, Object expectedResult, Object actualResult, boolean last) { |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
133 Polymorphic2 polymorphic = ((Polymorphic2) node.getNode()); |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
134 assertParent(node.getNode(), polymorphic.getA()); |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
135 assertNoDuplicates(polymorphic, polymorphic.getA()); |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
136 if (index == 0) { |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
137 assertEquals(NodeCost.MONOMORPHIC, node.getNode().getCost()); |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
138 } |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
139 } |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
140 }); |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
141 } |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
142 |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
143 @NodeChild("a") |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
144 abstract static class Polymorphic2 extends ValueNode { |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
145 |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
146 public abstract ValueNode getA(); |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
147 |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
148 @Specialization |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
149 String s2(String a) { |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
150 return a; |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
151 } |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
152 |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
153 @Specialization(rewriteOn = RuntimeException.class) |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
154 int s0(int a) { |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
155 if (a == 1) { |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
156 throw new RuntimeException(); |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
157 } |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
158 return a; |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
159 } |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
160 |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
161 @Specialization |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
162 int s1(int a) { |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
163 return a; |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
164 } |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
165 |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
166 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
167 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
168 @Test |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
169 public void testPolymorphic3() { |
16756
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
170 assertRuns(Polymorphic3Factory.getInstance(), // |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
171 array("0", "1", 1, 1, 2, 2, 3, 3), // |
18163
c88ab4f1f04a
re-enabled Checkstyle with the release of 6.0 that supports Java 8; fixed existing Checkstyle warnings
Doug Simon <doug.simon@oracle.com>
parents:
16760
diff
changeset
|
172 array("0", "1", 1, 1, 2, 2, 3, 3), // |
16756
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
173 new ExecutionListener() { |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
174 public void afterExecution(TestRootNode<? extends ValueNode> node, int index, Object value, Object expectedResult, Object actualResult, boolean last) { |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
175 Polymorphic3 polymorphic = ((Polymorphic3) node.getNode()); |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
176 assertParent(node.getNode(), polymorphic.getA()); |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
177 assertNoDuplicates(polymorphic, polymorphic.getA()); |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
178 } |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
179 }); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
180 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
181 |
16756
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
182 @NodeChild("a") |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
183 abstract static class Polymorphic3 extends ValueNode { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
184 |
16756
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
185 public abstract ValueNode getA(); |
11320
80de3bbfa8b9
Truffle-DSL: fixed inconsistent children for polymorphic -> generic rewrites. (GRAAL-425)
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
186 |
16756
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
187 @Specialization |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
188 String s2(String a) { |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
189 return a; |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
190 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
191 |
16756
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
192 @Specialization(rewriteOn = RuntimeException.class) |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
193 int s0(int a) { |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
194 if (a == 1) { |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
195 throw new RuntimeException(); |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
196 } |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
197 return a; |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
198 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
199 |
16756
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
200 @Specialization(rewriteOn = RuntimeException.class) |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
201 int s1(int a) { |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
202 if (a == 1) { |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
203 throw new RuntimeException(); |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
204 } |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
205 return a; |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
206 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
207 |
16756
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
208 @Specialization |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
209 int s2(int a) { |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
210 return a; |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
211 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
212 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
213 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
214 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
215 } |