Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/TestHelper.java @ 14765:365800f2a7aa
SnippetCounter: use own location for counter
author | Bernhard Urban <bernhard.urban@jku.at> |
---|---|
date | Wed, 26 Mar 2014 21:52:45 +0100 |
parents | 5f5e2711dc24 |
children | 64dcb92ee75a |
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, 2013, 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 |
11469
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
25 import static org.junit.Assert.*; |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
26 |
14042
2864cb92fa9a
TruffleDSL: retire NodeFactory#createNodeGeneric
Andreas Woess <andreas.woess@jku.at>
parents:
13528
diff
changeset
|
27 import java.lang.reflect.*; |
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
|
28 import java.util.*; |
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
|
29 |
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
|
30 import com.oracle.truffle.api.*; |
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
|
31 import com.oracle.truffle.api.dsl.*; |
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
|
32 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ArgumentNode; |
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
|
33 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ChildrenNode; |
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
|
34 import com.oracle.truffle.api.dsl.test.TypeSystemTest.TestArguments; |
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
|
35 import com.oracle.truffle.api.dsl.test.TypeSystemTest.TestRootNode; |
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
|
36 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode; |
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
|
37 |
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
|
38 /** |
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
|
39 * Utility class to provide some test helper functions. |
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
|
40 */ |
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
|
41 class TestHelper { |
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
|
42 |
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 private static ArgumentNode[] arguments(int count) { |
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
|
44 ArgumentNode[] nodes = new ArgumentNode[count]; |
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
|
45 for (int i = 0; i < nodes.length; i++) { |
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
|
46 nodes[i] = new ArgumentNode(i); |
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
|
47 } |
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 return nodes; |
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 } |
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
|
50 |
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
|
51 static <E extends ValueNode> E createNode(NodeFactory<E> factory, Object... constants) { |
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
|
52 ArgumentNode[] argumentNodes = arguments(factory.getExecutionSignature().size()); |
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
|
53 |
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
|
54 List<Object> argumentList = new ArrayList<>(); |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
12401
diff
changeset
|
55 if (ChildrenNode.class.isAssignableFrom(factory.getNodeClass())) { |
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
|
56 argumentList.add(argumentNodes); |
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
|
57 } else { |
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
|
58 argumentList.addAll(Arrays.asList(argumentNodes)); |
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
|
59 } |
11191
c7d9ff67beed
Truffle-DSL: Fixed argument order problem for test cases.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
60 argumentList.addAll(Arrays.asList(constants)); |
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
|
61 return factory.createNode(argumentList.toArray(new Object[argumentList.size()])); |
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
|
62 } |
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
|
63 |
12401
85dcc7f59c34
Truffle-DSL: fixed incorrect else guard connections for executeAndSpecialize.
Christian Humer <christian.humer@gmail.com>
parents:
11473
diff
changeset
|
64 static <E extends ValueNode> E createGenericNode(NodeFactory<E> factory, Object... constants) { |
14042
2864cb92fa9a
TruffleDSL: retire NodeFactory#createNodeGeneric
Andreas Woess <andreas.woess@jku.at>
parents:
13528
diff
changeset
|
65 Method createGenericMethod; |
2864cb92fa9a
TruffleDSL: retire NodeFactory#createNodeGeneric
Andreas Woess <andreas.woess@jku.at>
parents:
13528
diff
changeset
|
66 try { |
2864cb92fa9a
TruffleDSL: retire NodeFactory#createNodeGeneric
Andreas Woess <andreas.woess@jku.at>
parents:
13528
diff
changeset
|
67 createGenericMethod = factory.getClass().getMethod("createGeneric", factory.getNodeClass()); |
2864cb92fa9a
TruffleDSL: retire NodeFactory#createNodeGeneric
Andreas Woess <andreas.woess@jku.at>
parents:
13528
diff
changeset
|
68 } catch (NoSuchMethodException e) { |
2864cb92fa9a
TruffleDSL: retire NodeFactory#createNodeGeneric
Andreas Woess <andreas.woess@jku.at>
parents:
13528
diff
changeset
|
69 throw new RuntimeException(e); |
2864cb92fa9a
TruffleDSL: retire NodeFactory#createNodeGeneric
Andreas Woess <andreas.woess@jku.at>
parents:
13528
diff
changeset
|
70 } |
2864cb92fa9a
TruffleDSL: retire NodeFactory#createNodeGeneric
Andreas Woess <andreas.woess@jku.at>
parents:
13528
diff
changeset
|
71 try { |
2864cb92fa9a
TruffleDSL: retire NodeFactory#createNodeGeneric
Andreas Woess <andreas.woess@jku.at>
parents:
13528
diff
changeset
|
72 return factory.getNodeClass().cast(createGenericMethod.invoke(null, createNode(factory, constants))); |
2864cb92fa9a
TruffleDSL: retire NodeFactory#createNodeGeneric
Andreas Woess <andreas.woess@jku.at>
parents:
13528
diff
changeset
|
73 } catch (IllegalAccessException | InvocationTargetException e) { |
2864cb92fa9a
TruffleDSL: retire NodeFactory#createNodeGeneric
Andreas Woess <andreas.woess@jku.at>
parents:
13528
diff
changeset
|
74 throw new RuntimeException(e); |
2864cb92fa9a
TruffleDSL: retire NodeFactory#createNodeGeneric
Andreas Woess <andreas.woess@jku.at>
parents:
13528
diff
changeset
|
75 } |
12401
85dcc7f59c34
Truffle-DSL: fixed incorrect else guard connections for executeAndSpecialize.
Christian Humer <christian.humer@gmail.com>
parents:
11473
diff
changeset
|
76 } |
85dcc7f59c34
Truffle-DSL: fixed incorrect else guard connections for executeAndSpecialize.
Christian Humer <christian.humer@gmail.com>
parents:
11473
diff
changeset
|
77 |
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
|
78 static <E extends ValueNode> TestRootNode<E> createRoot(NodeFactory<E> factory, Object... constants) { |
14632
5f5e2711dc24
fix TruffleDSL tests
Andreas Woess <andreas.woess@jku.at>
parents:
14042
diff
changeset
|
79 TestRootNode<E> rootNode = new TestRootNode<>(createNode(factory, constants)); |
5f5e2711dc24
fix TruffleDSL tests
Andreas Woess <andreas.woess@jku.at>
parents:
14042
diff
changeset
|
80 rootNode.adoptChildren(); |
5f5e2711dc24
fix TruffleDSL tests
Andreas Woess <andreas.woess@jku.at>
parents:
14042
diff
changeset
|
81 return rootNode; |
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 } |
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
|
83 |
12401
85dcc7f59c34
Truffle-DSL: fixed incorrect else guard connections for executeAndSpecialize.
Christian Humer <christian.humer@gmail.com>
parents:
11473
diff
changeset
|
84 static <E extends ValueNode> TestRootNode<E> createGenericRoot(NodeFactory<E> factory, Object... constants) { |
14632
5f5e2711dc24
fix TruffleDSL tests
Andreas Woess <andreas.woess@jku.at>
parents:
14042
diff
changeset
|
85 TestRootNode<E> rootNode = new TestRootNode<>(createGenericNode(factory, constants)); |
5f5e2711dc24
fix TruffleDSL tests
Andreas Woess <andreas.woess@jku.at>
parents:
14042
diff
changeset
|
86 rootNode.adoptChildren(); |
5f5e2711dc24
fix TruffleDSL tests
Andreas Woess <andreas.woess@jku.at>
parents:
14042
diff
changeset
|
87 return rootNode; |
12401
85dcc7f59c34
Truffle-DSL: fixed incorrect else guard connections for executeAndSpecialize.
Christian Humer <christian.humer@gmail.com>
parents:
11473
diff
changeset
|
88 } |
85dcc7f59c34
Truffle-DSL: fixed incorrect else guard connections for executeAndSpecialize.
Christian Humer <christian.humer@gmail.com>
parents:
11473
diff
changeset
|
89 |
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
|
90 static CallTarget createCallTarget(ValueNode node) { |
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
|
91 return createCallTarget(new TestRootNode<>(node)); |
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
|
92 } |
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
|
93 |
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
|
94 static CallTarget createCallTarget(TestRootNode<? extends ValueNode> node) { |
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
|
95 return Truffle.getRuntime().createCallTarget(node); |
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
|
96 } |
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
|
97 |
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
|
98 static <E> Object executeWith(TestRootNode<? extends ValueNode> node, Object... values) { |
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
|
99 return createCallTarget(node).call(new TestArguments(values)); |
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
|
100 } |
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
|
101 |
11464
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
102 static Object array(Object... val) { |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
103 return val; |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
104 } |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
105 |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
106 static <E> List<List<E>> permutations(List<E> list) { |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
107 return permutations(new ArrayList<E>(), list, new ArrayList<List<E>>()); |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
108 } |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
109 |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
110 static Object[][] permutations(Object... list) { |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
111 List<List<Object>> permutations = permutations(Arrays.asList(list)); |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
112 |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
113 Object[][] a = new Object[permutations.size()][]; |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
114 int index = 0; |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
115 for (List<Object> p : permutations) { |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
116 a[index] = p.toArray(new Object[p.size()]); |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
117 index++; |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
118 } |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
119 |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
120 return a; |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
121 } |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
122 |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
123 static <E> List<List<E>> permutations(List<E> prefix, List<E> suffix, List<List<E>> output) { |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
124 if (suffix.size() == 1) { |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
125 ArrayList<E> newElement = new ArrayList<>(prefix); |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
126 newElement.addAll(suffix); |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
127 output.add(newElement); |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
128 return output; |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
129 } |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
130 |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
131 for (int i = 0; i < suffix.size(); i++) { |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
132 List<E> newPrefix = new ArrayList<>(prefix); |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
133 newPrefix.add(suffix.get(i)); |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
134 List<E> newSuffix = new ArrayList<>(suffix); |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
135 newSuffix.remove(i); |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
136 permutations(newPrefix, newSuffix, output); |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
137 } |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
138 |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
139 return output; |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
140 } |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
141 |
11469
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
142 /* Methods tests all test values in combinational order. */ |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
143 static void assertRuns(NodeFactory<? extends ValueNode> factory, Object result, Object... testValues) { |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
144 // test each run by its own. |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
145 for (int i = 0; i < testValues.length; i++) { |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
146 assertValue(createRoot(factory), result, testValues); |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
147 } |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
148 |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
149 // test all combinations of the test values |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
150 List<List<Object>> permuts = permutations(Arrays.asList(testValues)); |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
151 for (List<Object> list : permuts) { |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
152 TestRootNode<?> root = createRoot(factory); |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
153 for (Object object : list) { |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
154 assertValue(root, result, object); |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
155 } |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
156 } |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
157 } |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
158 |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
159 static void assertValue(TestRootNode<? extends ValueNode> root, Object result, Object testValues) { |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
160 if (testValues instanceof Object[]) { |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
161 assertEquals(result, executeWith(root, (Object[]) testValues)); |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
162 } else { |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
163 assertEquals(result, executeWith(root, testValues)); |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
164 } |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
165 } |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
166 |
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
|
167 } |