Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/TestHelper.java @ 15006:e60ea0bf468d
remove StampFactory.dependency/extension/condition
author | Lukas Stadler <lukas.stadler@oracle.com> |
---|---|
date | Mon, 07 Apr 2014 11:32:08 +0200 |
parents | 64dcb92ee75a |
children | 5148aab962af |
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.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
|
35 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
|
36 |
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 * 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
|
39 */ |
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 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
|
41 |
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 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
|
43 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
|
44 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
|
45 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
|
46 } |
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 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
|
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 |
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 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
|
51 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
|
52 |
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 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
|
54 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
|
55 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
|
56 } 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
|
57 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
|
58 } |
11191
c7d9ff67beed
Truffle-DSL: Fixed argument order problem for test cases.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
59 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
|
60 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
|
61 } |
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 |
12401
85dcc7f59c34
Truffle-DSL: fixed incorrect else guard connections for executeAndSpecialize.
Christian Humer <christian.humer@gmail.com>
parents:
11473
diff
changeset
|
63 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
|
64 Method createGenericMethod; |
2864cb92fa9a
TruffleDSL: retire NodeFactory#createNodeGeneric
Andreas Woess <andreas.woess@jku.at>
parents:
13528
diff
changeset
|
65 try { |
2864cb92fa9a
TruffleDSL: retire NodeFactory#createNodeGeneric
Andreas Woess <andreas.woess@jku.at>
parents:
13528
diff
changeset
|
66 createGenericMethod = factory.getClass().getMethod("createGeneric", factory.getNodeClass()); |
2864cb92fa9a
TruffleDSL: retire NodeFactory#createNodeGeneric
Andreas Woess <andreas.woess@jku.at>
parents:
13528
diff
changeset
|
67 } catch (NoSuchMethodException e) { |
2864cb92fa9a
TruffleDSL: retire NodeFactory#createNodeGeneric
Andreas Woess <andreas.woess@jku.at>
parents:
13528
diff
changeset
|
68 throw new RuntimeException(e); |
2864cb92fa9a
TruffleDSL: retire NodeFactory#createNodeGeneric
Andreas Woess <andreas.woess@jku.at>
parents:
13528
diff
changeset
|
69 } |
2864cb92fa9a
TruffleDSL: retire NodeFactory#createNodeGeneric
Andreas Woess <andreas.woess@jku.at>
parents:
13528
diff
changeset
|
70 try { |
2864cb92fa9a
TruffleDSL: retire NodeFactory#createNodeGeneric
Andreas Woess <andreas.woess@jku.at>
parents:
13528
diff
changeset
|
71 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
|
72 } catch (IllegalAccessException | InvocationTargetException e) { |
2864cb92fa9a
TruffleDSL: retire NodeFactory#createNodeGeneric
Andreas Woess <andreas.woess@jku.at>
parents:
13528
diff
changeset
|
73 throw new RuntimeException(e); |
2864cb92fa9a
TruffleDSL: retire NodeFactory#createNodeGeneric
Andreas Woess <andreas.woess@jku.at>
parents:
13528
diff
changeset
|
74 } |
12401
85dcc7f59c34
Truffle-DSL: fixed incorrect else guard connections for executeAndSpecialize.
Christian Humer <christian.humer@gmail.com>
parents:
11473
diff
changeset
|
75 } |
85dcc7f59c34
Truffle-DSL: fixed incorrect else guard connections for executeAndSpecialize.
Christian Humer <christian.humer@gmail.com>
parents:
11473
diff
changeset
|
76 |
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
|
77 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
|
78 TestRootNode<E> rootNode = new TestRootNode<>(createNode(factory, constants)); |
5f5e2711dc24
fix TruffleDSL tests
Andreas Woess <andreas.woess@jku.at>
parents:
14042
diff
changeset
|
79 rootNode.adoptChildren(); |
5f5e2711dc24
fix TruffleDSL tests
Andreas Woess <andreas.woess@jku.at>
parents:
14042
diff
changeset
|
80 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
|
81 } |
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 |
12401
85dcc7f59c34
Truffle-DSL: fixed incorrect else guard connections for executeAndSpecialize.
Christian Humer <christian.humer@gmail.com>
parents:
11473
diff
changeset
|
83 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
|
84 TestRootNode<E> rootNode = new TestRootNode<>(createGenericNode(factory, constants)); |
5f5e2711dc24
fix TruffleDSL tests
Andreas Woess <andreas.woess@jku.at>
parents:
14042
diff
changeset
|
85 rootNode.adoptChildren(); |
5f5e2711dc24
fix TruffleDSL tests
Andreas Woess <andreas.woess@jku.at>
parents:
14042
diff
changeset
|
86 return rootNode; |
12401
85dcc7f59c34
Truffle-DSL: fixed incorrect else guard connections for executeAndSpecialize.
Christian Humer <christian.humer@gmail.com>
parents:
11473
diff
changeset
|
87 } |
85dcc7f59c34
Truffle-DSL: fixed incorrect else guard connections for executeAndSpecialize.
Christian Humer <christian.humer@gmail.com>
parents:
11473
diff
changeset
|
88 |
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
|
89 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
|
90 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
|
91 } |
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 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
|
94 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
|
95 } |
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 static <E> Object executeWith(TestRootNode<? extends ValueNode> node, Object... values) { |
14991
64dcb92ee75a
Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
14632
diff
changeset
|
98 return createCallTarget(node).call(values); |
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
|
99 } |
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 |
11464
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
101 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
|
102 return val; |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
103 } |
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 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
|
106 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
|
107 } |
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 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
|
110 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
|
111 |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
112 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
|
113 int index = 0; |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
114 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
|
115 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
|
116 index++; |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
117 } |
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 return a; |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
120 } |
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 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
|
123 if (suffix.size() == 1) { |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
124 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
|
125 newElement.addAll(suffix); |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
126 output.add(newElement); |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
127 return output; |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
128 } |
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 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
|
131 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
|
132 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
|
133 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
|
134 newSuffix.remove(i); |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
135 permutations(newPrefix, newSuffix, output); |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
136 } |
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 return output; |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
139 } |
e55e24cc3e7b
Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents:
11191
diff
changeset
|
140 |
11469
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
141 /* 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
|
142 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
|
143 // test each run by its own. |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
144 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
|
145 assertValue(createRoot(factory), result, testValues); |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
146 } |
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 // test all combinations of the test values |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
149 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
|
150 for (List<Object> list : permuts) { |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
151 TestRootNode<?> root = createRoot(factory); |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
152 for (Object object : list) { |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
153 assertValue(root, result, object); |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
154 } |
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 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
|
159 if (testValues instanceof Object[]) { |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
160 assertEquals(result, executeWith(root, (Object[]) testValues)); |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
161 } else { |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
162 assertEquals(result, executeWith(root, testValues)); |
88316d1c4644
Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents:
11464
diff
changeset
|
163 } |
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 |
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 } |