annotate graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/TestHelper.java @ 19289:62c43fcf5be2

Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
author Christian Humer <christian.humer@gmail.com>
date Tue, 03 Feb 2015 15:07:07 +0100
parents c5db657d93c1
children 476374f3fe9a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
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
27 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
28
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 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
30 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
31 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
32 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
33 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
34 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
35
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 * 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
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 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
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 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
42 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
43 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
44 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
45 }
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 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
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
16967
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16756
diff changeset
49 static <E extends ValueNode> E createNode(NodeFactory<E> factory, boolean prefixConstants, Object... 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
50 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
51
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 List<Object> argumentList = new ArrayList<>();
16967
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16756
diff changeset
53 if (prefixConstants) {
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16756
diff changeset
54 argumentList.addAll(Arrays.asList(constants));
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16756
diff changeset
55 }
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 12401
diff changeset
56 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
57 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
58 } 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
59 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
60 }
16967
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16756
diff changeset
61 if (!prefixConstants) {
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16756
diff changeset
62 argumentList.addAll(Arrays.asList(constants));
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16756
diff changeset
63 }
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
64 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
65 }
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
66
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
67 static <E extends ValueNode> TestRootNode<E> createRoot(NodeFactory<E> factory, Object... constants) {
16967
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16756
diff changeset
68 TestRootNode<E> rootNode = new TestRootNode<>(createNode(factory, false, constants));
14632
5f5e2711dc24 fix TruffleDSL tests
Andreas Woess <andreas.woess@jku.at>
parents: 14042
diff changeset
69 rootNode.adoptChildren();
5f5e2711dc24 fix TruffleDSL tests
Andreas Woess <andreas.woess@jku.at>
parents: 14042
diff changeset
70 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
71 }
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
72
16967
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16756
diff changeset
73 static <E extends ValueNode> TestRootNode<E> createRootPrefix(NodeFactory<E> factory, boolean prefixConstants, Object... constants) {
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16756
diff changeset
74 TestRootNode<E> rootNode = new TestRootNode<>(createNode(factory, prefixConstants, constants));
14632
5f5e2711dc24 fix TruffleDSL tests
Andreas Woess <andreas.woess@jku.at>
parents: 14042
diff changeset
75 rootNode.adoptChildren();
5f5e2711dc24 fix TruffleDSL tests
Andreas Woess <andreas.woess@jku.at>
parents: 14042
diff changeset
76 return rootNode;
12401
85dcc7f59c34 Truffle-DSL: fixed incorrect else guard connections for executeAndSpecialize.
Christian Humer <christian.humer@gmail.com>
parents: 11473
diff changeset
77 }
85dcc7f59c34 Truffle-DSL: fixed incorrect else guard connections for executeAndSpecialize.
Christian Humer <christian.humer@gmail.com>
parents: 11473
diff changeset
78
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
79 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
80 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
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
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 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
84 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
85 }
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
86
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 16967
diff changeset
87 static RootCallTarget createCallTarget(NodeFactory<? extends ValueNode> factory, Object... constants) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 16967
diff changeset
88 return Truffle.getRuntime().createCallTarget(createRoot(factory, constants));
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 16967
diff changeset
89 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 16967
diff changeset
90
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 16967
diff changeset
91 static boolean assertionsEnabled() {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 16967
diff changeset
92 boolean assertOn = false;
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 16967
diff changeset
93 // *assigns* true if assertions are on.
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 16967
diff changeset
94 assert (assertOn = true) == true;
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 16967
diff changeset
95 return assertOn;
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 16967
diff changeset
96 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 16967
diff changeset
97
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 16967
diff changeset
98 @SuppressWarnings("unchecked")
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 16967
diff changeset
99 static <T extends ValueNode> T getNode(CallTarget target) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 16967
diff changeset
100 return ((TestRootNode<T>) ((RootCallTarget) target).getRootNode()).getNode();
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 16967
diff changeset
101 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 16967
diff changeset
102
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
103 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
104 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
105 }
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
106
16756
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
107 static Object[] array(Object... val) {
11464
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
108 return val;
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
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
111 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
112 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
113 }
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
114
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
115 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
116 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
117
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
118 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
119 int index = 0;
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
120 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
121 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
122 index++;
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
123 }
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
124
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
125 return a;
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
126 }
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
127
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
128 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
129 if (suffix.size() == 1) {
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
130 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
131 newElement.addAll(suffix);
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
132 output.add(newElement);
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
133 return output;
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
134 }
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
135
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
136 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
137 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
138 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
139 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
140 newSuffix.remove(i);
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
141 permutations(newPrefix, newSuffix, output);
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
142 }
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
143
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
144 return output;
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
145 }
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
146
16756
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
147 static void assertRuns(NodeFactory<? extends ValueNode> factory, Object[] testValues, Object[] result) {
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
148 assertRuns(factory, testValues, result, null);
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
149 }
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
150
11469
88316d1c4644 Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents: 11464
diff changeset
151 /* Methods tests all test values in combinational order. */
16756
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
152 static void assertRuns(NodeFactory<? extends ValueNode> factory, Object[] testValues, Object[] result, ExecutionListener listener) {
11469
88316d1c4644 Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents: 11464
diff changeset
153 // test each run by its own.
88316d1c4644 Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents: 11464
diff changeset
154 for (int i = 0; i < testValues.length; i++) {
16756
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
155 assertValue(createRoot(factory), 0, testValues[i], result[i], listener, true);
11469
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 // test all combinations of the test values
16756
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
159 List<Object> testValuesList = Arrays.asList(testValues);
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
160 List<List<Object>> permuts = permutations(testValuesList);
11469
88316d1c4644 Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents: 11464
diff changeset
161 for (List<Object> list : permuts) {
88316d1c4644 Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents: 11464
diff changeset
162 TestRootNode<?> root = createRoot(factory);
16756
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
163 int index = 0;
11469
88316d1c4644 Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents: 11464
diff changeset
164 for (Object object : list) {
16756
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
165 assertValue(root, index, object, result[testValuesList.indexOf(object)], listener, index == list.size() - 1);
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
166 index++;
11469
88316d1c4644 Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents: 11464
diff changeset
167 }
88316d1c4644 Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents: 11464
diff changeset
168 }
88316d1c4644 Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents: 11464
diff changeset
169 }
88316d1c4644 Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents: 11464
diff changeset
170
16756
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
171 static void assertValue(TestRootNode<? extends ValueNode> root, int index, Object value, Object result, ExecutionListener listener, boolean last) {
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
172 Object actualResult = null;
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
173 if (result instanceof Class && Throwable.class.isAssignableFrom((Class<?>) result)) {
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
174 try {
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
175 if (value instanceof Object[]) {
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
176 actualResult = executeWith(root, (Object[]) value);
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
177 } else {
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
178 actualResult = executeWith(root, value);
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
179 }
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
180 fail(String.format("Exception %s expected but not occured.", result.getClass()));
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
181 } catch (Throwable e) {
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
182 actualResult = e;
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
183 if (!e.getClass().isAssignableFrom(((Class<?>) result))) {
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
184 e.printStackTrace();
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
185 fail(String.format("Incompatible exception class thrown. Expected %s but was %s.", result.toString(), e.getClass()));
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
186 }
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
187 }
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
188 } else if (value instanceof Object[]) {
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
189 actualResult = executeWith(root, (Object[]) value);
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
190 assertEquals(result, actualResult);
11469
88316d1c4644 Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents: 11464
diff changeset
191 } else {
16756
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
192 actualResult = executeWith(root, value);
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
193 assertEquals(result, actualResult);
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
194 }
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
195 if (listener != null) {
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
196 listener.afterExecution(root, index, value, result, actualResult, last);
11469
88316d1c4644 Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents: 11464
diff changeset
197 }
88316d1c4644 Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents: 11464
diff changeset
198 }
88316d1c4644 Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents: 11464
diff changeset
199
16756
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
200 public static final class LogListener implements ExecutionListener {
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
201
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
202 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: 14991
diff changeset
203 System.out.printf("Run %3d Node:%-20s Parameters: %10s Expected: %10s Result %10s%n", index, node.getNode().getClass().getSimpleName(), value, expectedResult, actualResult);
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
204 }
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
205
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
206 }
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
207
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
208 interface ExecutionListener {
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
209
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
210 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: 14991
diff changeset
211
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
212 }
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
213
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
214 }