annotate graal/com.oracle.truffle.api.codegen.test/src/com/oracle/truffle/api/codegen/test/TypeSystemTest.java @ 10594:72e6b178de16

Truffle-DSL: added a few missing types to the dsl tests.
author Christian Humer <christian.humer@gmail.com>
date Mon, 01 Jul 2013 20:29:08 +0200
parents e162d9e32830
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8249
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1 /*
8596
6ef9fc7375c7 Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
8249
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
4 *
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
8 *
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
13 * accompanied this code).
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
14 *
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
18 *
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
21 * questions.
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
22 */
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
23 package com.oracle.truffle.api.codegen.test;
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
24
8596
6ef9fc7375c7 Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
25 import com.oracle.truffle.api.*;
8249
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
26 import com.oracle.truffle.api.codegen.*;
10594
72e6b178de16 Truffle-DSL: added a few missing types to the dsl tests.
Christian Humer <christian.humer@gmail.com>
parents: 9330
diff changeset
27 import com.oracle.truffle.api.codegen.test.NodeContainerTest.Str;
8249
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
28 import com.oracle.truffle.api.frame.*;
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
29 import com.oracle.truffle.api.nodes.*;
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
30
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
31 public class TypeSystemTest {
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
32
10594
72e6b178de16 Truffle-DSL: added a few missing types to the dsl tests.
Christian Humer <christian.humer@gmail.com>
parents: 9330
diff changeset
33 @TypeSystem({int.class, boolean.class, String.class, Str.class, CallTarget.class, Object[].class})
8249
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
34 static class SimpleTypes {
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
35 }
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
36
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
37 @TypeSystemReference(SimpleTypes.class)
9223
5f7f0d3e3638 Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents: 8596
diff changeset
38 public abstract static class ValueNode extends Node {
8249
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
39
9223
5f7f0d3e3638 Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents: 8596
diff changeset
40 public int executeInt(VirtualFrame frame) throws UnexpectedResultException {
8596
6ef9fc7375c7 Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
41 return SimpleTypesGen.SIMPLETYPES.expectInteger(execute(frame));
8249
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
42 }
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
43
9223
5f7f0d3e3638 Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents: 8596
diff changeset
44 public Str executeStr(VirtualFrame frame) throws UnexpectedResultException {
8596
6ef9fc7375c7 Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
45 return SimpleTypesGen.SIMPLETYPES.expectStr(execute(frame));
8249
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
46 }
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
47
10594
72e6b178de16 Truffle-DSL: added a few missing types to the dsl tests.
Christian Humer <christian.humer@gmail.com>
parents: 9330
diff changeset
48 public String executeString(VirtualFrame frame) throws UnexpectedResultException {
72e6b178de16 Truffle-DSL: added a few missing types to the dsl tests.
Christian Humer <christian.humer@gmail.com>
parents: 9330
diff changeset
49 return SimpleTypesGen.SIMPLETYPES.expectString(execute(frame));
72e6b178de16 Truffle-DSL: added a few missing types to the dsl tests.
Christian Humer <christian.humer@gmail.com>
parents: 9330
diff changeset
50 }
72e6b178de16 Truffle-DSL: added a few missing types to the dsl tests.
Christian Humer <christian.humer@gmail.com>
parents: 9330
diff changeset
51
72e6b178de16 Truffle-DSL: added a few missing types to the dsl tests.
Christian Humer <christian.humer@gmail.com>
parents: 9330
diff changeset
52 public boolean executeBoolean(VirtualFrame frame) throws UnexpectedResultException {
72e6b178de16 Truffle-DSL: added a few missing types to the dsl tests.
Christian Humer <christian.humer@gmail.com>
parents: 9330
diff changeset
53 return SimpleTypesGen.SIMPLETYPES.expectBoolean(execute(frame));
72e6b178de16 Truffle-DSL: added a few missing types to the dsl tests.
Christian Humer <christian.humer@gmail.com>
parents: 9330
diff changeset
54 }
72e6b178de16 Truffle-DSL: added a few missing types to the dsl tests.
Christian Humer <christian.humer@gmail.com>
parents: 9330
diff changeset
55
9223
5f7f0d3e3638 Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents: 8596
diff changeset
56 public Object[] executeIntArray(VirtualFrame frame) throws UnexpectedResultException {
5f7f0d3e3638 Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents: 8596
diff changeset
57 return SimpleTypesGen.SIMPLETYPES.expectObjectArray(execute(frame));
5f7f0d3e3638 Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents: 8596
diff changeset
58 }
5f7f0d3e3638 Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents: 8596
diff changeset
59
5f7f0d3e3638 Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents: 8596
diff changeset
60 public abstract Object execute(VirtualFrame frame);
5f7f0d3e3638 Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents: 8596
diff changeset
61
5f7f0d3e3638 Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents: 8596
diff changeset
62 @Override
5f7f0d3e3638 Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents: 8596
diff changeset
63 public ValueNode copy() {
5f7f0d3e3638 Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents: 8596
diff changeset
64 return (ValueNode) super.copy();
5f7f0d3e3638 Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents: 8596
diff changeset
65 }
8249
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
66 }
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
67
9223
5f7f0d3e3638 Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents: 8596
diff changeset
68 @NodeChild(value = "children", type = ValueNode[].class)
5f7f0d3e3638 Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents: 8596
diff changeset
69 public abstract static class ChildrenNode extends ValueNode {
8596
6ef9fc7375c7 Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
70
6ef9fc7375c7 Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
71 }
8249
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
72
8596
6ef9fc7375c7 Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
73 @TypeSystemReference(SimpleTypes.class)
9223
5f7f0d3e3638 Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents: 8596
diff changeset
74 public static class TestRootNode<E extends ValueNode> extends RootNode {
8596
6ef9fc7375c7 Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
75
6ef9fc7375c7 Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
76 @Child private E node;
6ef9fc7375c7 Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
77
6ef9fc7375c7 Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
78 public TestRootNode(E node) {
8249
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
79 this.node = adoptChild(node);
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
80 }
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
81
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
82 @Override
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
83 public Object execute(VirtualFrame frame) {
8596
6ef9fc7375c7 Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
84 return node.execute(frame);
6ef9fc7375c7 Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
85 }
6ef9fc7375c7 Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
86
6ef9fc7375c7 Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
87 public E getNode() {
6ef9fc7375c7 Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
88 return node;
8249
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
89 }
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
90 }
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
91
9223
5f7f0d3e3638 Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents: 8596
diff changeset
92 public static class TestArguments extends Arguments {
8596
6ef9fc7375c7 Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
93
6ef9fc7375c7 Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
94 private final Object[] values;
6ef9fc7375c7 Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
95
6ef9fc7375c7 Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
96 public TestArguments(Object... values) {
6ef9fc7375c7 Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
97 this.values = values;
6ef9fc7375c7 Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
98 }
6ef9fc7375c7 Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
99
6ef9fc7375c7 Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
100 public Object[] getValues() {
6ef9fc7375c7 Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
101 return values;
6ef9fc7375c7 Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
102 }
6ef9fc7375c7 Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
103
6ef9fc7375c7 Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
104 public Object get(int index) {
6ef9fc7375c7 Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
105 return values[index];
6ef9fc7375c7 Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
106 }
6ef9fc7375c7 Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
107
6ef9fc7375c7 Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
108 }
6ef9fc7375c7 Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
109
9223
5f7f0d3e3638 Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents: 8596
diff changeset
110 public static class ArgumentNode extends ValueNode {
8596
6ef9fc7375c7 Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
111
9287
8e3a1635cc9e Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents: 9223
diff changeset
112 private int invocationCount;
8596
6ef9fc7375c7 Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
113 final int index;
6ef9fc7375c7 Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
114
6ef9fc7375c7 Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
115 public ArgumentNode(int index) {
6ef9fc7375c7 Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
116 this.index = index;
6ef9fc7375c7 Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
117 }
6ef9fc7375c7 Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
118
9287
8e3a1635cc9e Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents: 9223
diff changeset
119 public int getInvocationCount() {
8e3a1635cc9e Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents: 9223
diff changeset
120 return invocationCount;
8e3a1635cc9e Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents: 9223
diff changeset
121 }
8e3a1635cc9e Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents: 9223
diff changeset
122
8596
6ef9fc7375c7 Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
123 @Override
9223
5f7f0d3e3638 Updated codegen tests to new codegen API.
Christian Humer <christian.humer@gmail.com>
parents: 8596
diff changeset
124 public Object execute(VirtualFrame frame) {
9287
8e3a1635cc9e Implemented @NodeChild(executeWith={...}).
Christian Humer <christian.humer@gmail.com>
parents: 9223
diff changeset
125 invocationCount++;
9330
e162d9e32830 Added a clazz parameter to Frame.getArguments in order to allow unsafe access to the arguments object (i.e., avoiding the null check and the type cast).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9287
diff changeset
126 return frame.getArguments(TestArguments.class).get(index);
8596
6ef9fc7375c7 Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
127 }
6ef9fc7375c7 Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
128
6ef9fc7375c7 Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
129 }
6ef9fc7375c7 Updated codegen tests for guards and builtins.
Christian Humer <christian.humer@gmail.com>
parents: 8592
diff changeset
130
8249
aad7e9f4f71c A few additions to codegen tests.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
131 }