comparison graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/NoTypeSystemTest.java @ 20940:476374f3fe9a

Truffle-DSL: generate better polymorphic execute signatures
author Christian Humer <christian.humer@gmail.com>
date Tue, 14 Apr 2015 15:12:48 +0200
parents 18c0f02fa4d2
children
comparison
equal deleted inserted replaced
20939:f83fd99b2962 20940:476374f3fe9a
35 import com.oracle.truffle.api.frame.*; 35 import com.oracle.truffle.api.frame.*;
36 import com.oracle.truffle.api.nodes.*; 36 import com.oracle.truffle.api.nodes.*;
37 37
38 public class NoTypeSystemTest { 38 public class NoTypeSystemTest {
39 39
40 abstract static class DummyChild extends Node {
41 abstract Object execute();
42 }
43
40 abstract static class NoParameterTestNode extends Node { 44 abstract static class NoParameterTestNode extends Node {
41 abstract void execute(); 45 abstract void execute();
42 46
43 @Specialization 47 @Specialization
44 void s1() { 48 void s1() {
136 140
137 abstract String executeString(Object primitive) throws UnexpectedResultException; 141 abstract String executeString(Object primitive) throws UnexpectedResultException;
138 142
139 abstract int[] executeIntArray(Object primitive) throws UnexpectedResultException; 143 abstract int[] executeIntArray(Object primitive) throws UnexpectedResultException;
140 144
141 abstract void executeVoid(Object primitive) throws UnexpectedResultException; 145 abstract void executeVoid(Object primitive);
142 146
143 abstract void executeChar(Object primitive) throws UnexpectedResultException; 147 abstract void executeChar(Object primitive);
144 148
145 abstract int executeInt(int primitive) throws UnexpectedResultException; 149 abstract int executeInt(int primitive) throws UnexpectedResultException;
146 150
147 abstract double executeDouble(double primitive) throws UnexpectedResultException; 151 abstract double executeDouble(double primitive) throws UnexpectedResultException;
148 152
149 abstract String executeString(String primitive) throws UnexpectedResultException; 153 abstract String executeString(String primitive) throws UnexpectedResultException;
150 154
151 abstract int[] executeIntArray(int[] primitive) throws UnexpectedResultException; 155 abstract int[] executeIntArray(int[] primitive) throws UnexpectedResultException;
152 156
153 abstract void executeChar(char primitive) throws UnexpectedResultException; 157 abstract void executeChar(char primitive);
154 158
155 @Specialization 159 @Specialization
156 int s1(int primitive) { 160 int s1(int primitive) {
157 return primitive; 161 return primitive;
158 } 162 }
174 178
175 @Specialization 179 @Specialization
176 void s5(@SuppressWarnings("unused") char object) { 180 void s5(@SuppressWarnings("unused") char object) {
177 } 181 }
178 182
179 }
180
181 // make nodes replacable
182 private static <T extends Node> T createRoot(final T node) {
183 new RootNode() {
184 @Child T child = node;
185
186 @Override
187 public Object execute(VirtualFrame frame) {
188 return null;
189 }
190 }.adoptChildren();
191 return node;
192 } 183 }
193 184
194 @Test 185 @Test
195 public void testTypesNotInTypeSystem() throws UnexpectedResultException { 186 public void testTypesNotInTypeSystem() throws UnexpectedResultException {
196 int[] someArray = {1, 2, 3}; 187 int[] someArray = {1, 2, 3};
230 createTypesNotInTypeSystem().executeChar("a"); 221 createTypesNotInTypeSystem().executeChar("a");
231 222
232 } 223 }
233 224
234 private static TypesNotInTypeSystemTest createTypesNotInTypeSystem() { 225 private static TypesNotInTypeSystemTest createTypesNotInTypeSystem() {
235 return createRoot(TypesNotInTypeSystemTestNodeGen.create()); 226 return TestHelper.createRoot(TypesNotInTypeSystemTestNodeGen.create());
236 } 227 }
237 228
238 abstract static class ErrorImpossibleTypes1 extends Node { 229 abstract static class ErrorImpossibleTypes1 extends Node {
239 230
240 abstract int execute(int primitive); 231 abstract int execute(int primitive);
279 } 270 }
280 } 271 }
281 272
282 @ExpectError("Not enough child node declarations found. Please annotate the node class with addtional @NodeChild annotations or remove all execute methods that do not provide all evaluated values. " 273 @ExpectError("Not enough child node declarations found. Please annotate the node class with addtional @NodeChild annotations or remove all execute methods that do not provide all evaluated values. "
283 + "The following execute methods do not provide all evaluated values for the expected signature size 2: [execute(int)].") 274 + "The following execute methods do not provide all evaluated values for the expected signature size 2: [execute(int)].")
284 @NodeChild 275 @NodeChild(type = DummyChild.class)
285 abstract static class ErrorMissingNodeChild2 extends Node { 276 abstract static class ErrorMissingNodeChild2 extends Node {
286 277
287 abstract int execute(int arg0); 278 abstract int execute(int arg0);
288 279
289 @Specialization 280 @Specialization
306 } 297 }
307 298
308 } 299 }
309 300
310 @ExpectError("Unnecessary @NodeChild declaration. All evaluated child values are provided as parameters in execute methods.") 301 @ExpectError("Unnecessary @NodeChild declaration. All evaluated child values are provided as parameters in execute methods.")
311 @NodeChild 302 @NodeChild(type = DummyChild.class)
312 abstract static class ErrorAdditionalNodeChild1 extends Node { 303 abstract static class ErrorAdditionalNodeChild1 extends Node {
313 304
314 abstract int execute(int arg0); 305 abstract int execute(int arg0);
315 306
316 @Specialization 307 @Specialization
317 int s1(int arg0) { 308 int s1(int arg0) {
318 return arg0; 309 return arg0;
319 } 310 }
320 } 311 }
321 312
322 @NodeChild 313 @NodeChild(type = DummyChild.class)
323 @ExpectError("Not enough child node declarations found. Please annotate the node class with addtional @NodeChild annotations or remove all execute methods that do not provide all evaluated values. " 314 @ExpectError("Not enough child node declarations found. Please annotate the node class with addtional @NodeChild annotations or remove all execute methods that do not provide all evaluated values. "
324 + "The following execute methods do not provide all evaluated values for the expected signature size 2: [execute(int)].") 315 + "The following execute methods do not provide all evaluated values for the expected signature size 2: [execute(int)].")
325 abstract static class ErrorAdditionalNodeChild2 extends Node { 316 abstract static class ErrorAdditionalNodeChild2 extends Node {
326 317
327 abstract int execute(int arg0); 318 abstract int execute(int arg0);