comparison graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/ExecuteMethodTest.java @ 18776:c0fb70634640

Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
author Christian Humer <christian.humer@gmail.com>
date Mon, 05 Jan 2015 01:31:08 +0100
parents a069a87b9a02
children ae827362559d
comparison
equal deleted inserted replaced
18775:a069a87b9a02 18776:c0fb70634640
21 * questions. 21 * questions.
22 */ 22 */
23 package com.oracle.truffle.api.dsl.test; 23 package com.oracle.truffle.api.dsl.test;
24 24
25 import com.oracle.truffle.api.dsl.*; 25 import com.oracle.truffle.api.dsl.*;
26 import com.oracle.truffle.api.dsl.internal.*;
27 import com.oracle.truffle.api.frame.*;
26 import com.oracle.truffle.api.nodes.*; 28 import com.oracle.truffle.api.nodes.*;
27 29
28 public class ExecuteMethodTest { 30 public class ExecuteMethodTest {
29 31
30 private static final String NO_EXECUTE = "No accessible and overridable generic execute method found. Generic execute methods usually have the signature 'public abstract {Type} " 32 private static final String ERROR_NO_EXECUTE = "No accessible and overridable generic execute method found. Generic execute methods usually have the signature 'public abstract {Type} "
31 + "executeGeneric(VirtualFrame)' and must not throw any checked exceptions."; 33 + "execute(VirtualFrame)' and must not throw any checked exceptions.";
32 34
33 @TypeSystem({int.class, Object[].class}) 35 @TypeSystem({int.class})
34 static class ExecuteTypeSystem { 36 @DSLOptions(useNewLayout = true)
35 37 static class ExecuteMethodTypes {
36 } 38 }
37 39
38 @TypeSystemReference(ExecuteTypeSystem.class) 40 @TypeSystemReference(ExecuteMethodTypes.class)
39 abstract static class ValidChildNode extends Node { 41 abstract static class ChildNoFrame extends Node {
40 abstract Object execute(); 42 abstract Object execute();
41 } 43 }
42 44
43 @TypeSystemReference(ExecuteTypeSystem.class) 45 @TypeSystemReference(ExecuteMethodTypes.class)
44 @NodeChild(value = "a", type = ValidChildNode.class) 46 @NodeChild(value = "a", type = ChildNoFrame.class)
45 @ExpectError(NO_EXECUTE) 47 @ExpectError(ERROR_NO_EXECUTE)
46 abstract static class ExecuteThis1 extends Node { 48 abstract static class ExecuteThis1 extends Node {
47 49
48 @Specialization 50 @Specialization
49 int doInt(int a) { 51 int doInt(int a) {
50 return a; 52 return a;
51 } 53 }
52 } 54 }
53 55
54 @TypeSystemReference(ExecuteTypeSystem.class) 56 @TypeSystemReference(ExecuteMethodTypes.class)
55 @NodeChild(value = "a", type = ValidChildNode.class) 57 @NodeChild(value = "a", type = ChildNoFrame.class)
56 @ExpectError(NO_EXECUTE) 58 @ExpectError(ERROR_NO_EXECUTE)
57 abstract static class ExecuteThis2 extends Node { 59 abstract static class ExecuteThis2 extends Node {
58 60
59 abstract Object execute() throws UnexpectedResultException; 61 abstract Object execute() throws UnexpectedResultException;
60 62
61 @Specialization 63 @Specialization
62 int doInt(int a) { 64 int doInt(int a) {
63 return a; 65 return a;
64 } 66 }
65 } 67 }
66 68
67 @TypeSystemReference(ExecuteTypeSystem.class) 69 @TypeSystemReference(ExecuteMethodTypes.class)
68 @NodeChild(value = "a", type = ValidChildNode.class) 70 @NodeChild(value = "a", type = ChildNoFrame.class)
69 @ExpectError(NO_EXECUTE) 71 @ExpectError(ERROR_NO_EXECUTE)
70 abstract static class ExecuteThis3 extends Node { 72 abstract static class ExecuteThis3 extends Node {
71 73
72 abstract int execute() throws UnexpectedResultException; 74 abstract int execute() throws UnexpectedResultException;
73 75
74 @Specialization 76 @Specialization
75 int doInt(int a) { 77 int doInt(int a) {
76 return a; 78 return a;
77 } 79 }
78 } 80 }
79 81
80 @TypeSystemReference(ExecuteTypeSystem.class) 82 @TypeSystemReference(ExecuteMethodTypes.class)
81 @NodeChild(value = "a", type = ValidChildNode.class) 83 @NodeChild(value = "a", type = ChildNoFrame.class)
82 abstract static class ExecuteThis4 extends Node { 84 abstract static class ExecuteThis4 extends Node {
83 85
84 protected abstract Object execute(); 86 protected abstract Object execute();
85 87
86 @Specialization 88 @Specialization
87 int doInt(int a) { 89 int doInt(int a) {
88 return a; 90 return a;
89 } 91 }
90 } 92 }
91 93
92 @TypeSystemReference(ExecuteTypeSystem.class) 94 @TypeSystemReference(ExecuteMethodTypes.class)
93 @NodeChild(value = "a", type = ValidChildNode.class) 95 @NodeChild(value = "a", type = ChildNoFrame.class)
94 abstract static class ExecuteThis5 extends Node { 96 abstract static class ExecuteThis5 extends Node {
95 97
96 public abstract Object execute(); 98 public abstract Object execute();
97 99
98 @Specialization 100 @Specialization
99 int doInt(int a) { 101 int doInt(int a) {
100 return a; 102 return a;
101 } 103 }
102 } 104 }
103 105
104 @TypeSystemReference(ExecuteTypeSystem.class) 106 @TypeSystemReference(ExecuteMethodTypes.class)
105 @NodeChild(value = "a", type = ValidChildNode.class) 107 @NodeChild(value = "a", type = ChildNoFrame.class)
106 @ExpectError(NO_EXECUTE) 108 @ExpectError(ERROR_NO_EXECUTE)
107 abstract static class ExecuteThis6 extends Node { 109 abstract static class ExecuteThis6 extends Node {
108 110
109 @SuppressWarnings({"unused", "static-method"}) 111 @SuppressWarnings({"unused", "static-method"})
110 private Object execute() { 112 private Object execute() {
111 return 0; 113 return 0;
115 int doInt(int a) { 117 int doInt(int a) {
116 return a; 118 return a;
117 } 119 }
118 } 120 }
119 121
120 @TypeSystemReference(ExecuteTypeSystem.class) 122 @TypeSystemReference(ExecuteMethodTypes.class)
121 @NodeChild(value = "a", type = ValidChildNode.class) 123 @NodeChild(value = "a", type = ChildNoFrame.class)
122 @ExpectError(NO_EXECUTE) 124 @ExpectError(ERROR_NO_EXECUTE)
123 abstract static class ExecuteThis7 extends Node { 125 abstract static class ExecuteThis7 extends Node {
124 126
125 @SuppressWarnings("static-method") 127 @SuppressWarnings("static-method")
126 public final int executeInt() { 128 public final int executeInt() {
127 return 0; 129 return 0;
131 int doInt(int a) { 133 int doInt(int a) {
132 return a; 134 return a;
133 } 135 }
134 } 136 }
135 137
136 @TypeSystemReference(ExecuteTypeSystem.class) 138 @TypeSystemReference(ExecuteMethodTypes.class)
137 @NodeChild(value = "a", type = ValidChildNode.class) 139 @NodeChild(value = "a", type = ChildNoFrame.class)
138 @ExpectError("Multiple accessible and overridable generic execute methods found [executeInt(), executeObject()]. Remove all but one or mark all but one as final.") 140 @ExpectError("Multiple accessible and overridable generic execute methods found [executeInt(), executeObject()]. Remove all but one or mark all but one as final.")
139 abstract static class ExecuteThis8 extends Node { 141 abstract static class ExecuteThis8 extends Node {
140 142
141 abstract int executeInt(); 143 abstract int executeInt();
142 144
147 return a; 149 return a;
148 } 150 }
149 151
150 } 152 }
151 153
152 @TypeSystemReference(ExecuteTypeSystem.class) 154 @TypeSystemReference(ExecuteMethodTypes.class)
153 @NodeChild(value = "a", type = ValidChildNode.class) 155 @NodeChild(value = "a", type = ChildNoFrame.class)
154 abstract static class ExecuteThis9 extends Node { 156 abstract static class ExecuteThis9 extends Node {
155 157
156 abstract int executeInt(); 158 abstract int executeInt();
157 159
158 // disambiguate executeObject 160 // disambiguate executeObject
164 int doInt(int a) { 166 int doInt(int a) {
165 return a; 167 return a;
166 } 168 }
167 } 169 }
168 170
171 @TypeSystemReference(ExecuteMethodTypes.class)
172 @NodeChild(value = "a", type = ChildNoFrame.class)
173 abstract static class ExecuteThisVoid1 extends Node {
174
175 abstract void executeVoid();
176
177 @Specialization
178 int doInt(int a) {
179 return a;
180 }
181 }
182
183 @TypeSystemReference(ExecuteMethodTypes.class)
184 @NodeChild(value = "a", type = ChildNoFrame.class)
185 abstract static class ExecuteThisVoid2 extends Node {
186
187 // allow one execute void
188 abstract void executeVoid();
189
190 abstract Object executeObject();
191
192 @Specialization
193 int doInt(int a) {
194 return a;
195 }
196 }
197
198 @TypeSystemReference(ExecuteMethodTypes.class)
199 @NodeChild(value = "a", type = ChildNoFrame.class)
200 @ExpectError("Multiple accessible and overridable generic execute methods found [executeObject(), executeVoid1(), executeVoid2()]. Remove all but one or mark all but one as final.")
201 abstract static class ExecuteThisVoid3 extends Node {
202
203 // allow only one execute void
204 abstract void executeVoid1();
205
206 abstract void executeVoid2();
207
208 abstract Object executeObject();
209
210 @Specialization
211 int doInt(int a) {
212 return a;
213 }
214 }
215
216 @TypeSystemReference(ExecuteMethodTypes.class)
217 @NodeChild(value = "a", type = ChildNoFrame.class)
218 abstract static class ExecuteWithFrame1 extends Node {
219
220 // no frame in execute. no parameter in specializations
221 abstract Object executeNoFrame();
222
223 @Specialization
224 int doInt(int a) {
225 return a;
226 }
227 }
228
229 @TypeSystemReference(ExecuteMethodTypes.class)
230 @NodeChild(value = "a", type = ChildNoFrame.class)
231 abstract static class ExecuteWithFrame2 extends Node {
232
233 // frame in execute also usable in specialization
234 abstract Object executeWithFrame(VirtualFrame frame);
235
236 @Specialization
237 int doInt(@SuppressWarnings("unused") VirtualFrame frame, int a) {
238 return a;
239 }
240 }
241
242 @TypeSystemReference(ExecuteMethodTypes.class)
243 @NodeChild(value = "a", type = ChildNoFrame.class)
244 abstract static class ExecuteWithFrame3 extends Node {
245
246 abstract Object executeWithFrame(Frame frame);
247
248 @Specialization
249 int doInt(@SuppressWarnings("unused") Frame frame, int a) {
250 return a;
251 }
252 }
253
254 @TypeSystemReference(ExecuteMethodTypes.class)
255 @NodeChild(value = "a", type = ExecuteWithFrame4.class)
256 abstract static class ExecuteWithFrame4 extends Node {
257
258 abstract Object executeWithFrame(MaterializedFrame frame);
259
260 @Specialization
261 int doInt(@SuppressWarnings("unused") MaterializedFrame frame, int a) {
262 return a;
263 }
264 }
265
266 @TypeSystemReference(ExecuteMethodTypes.class)
267 @NodeChild(value = "a", type = ChildNoFrame.class)
268 abstract static class ExecuteWithFrameError1 extends Node {
269
270 abstract Object executeNoFrame();
271
272 @Specialization
273 @ExpectError("Method signature (VirtualFrame, int) does not match to the expected signature:%")
274 int doInt(@SuppressWarnings("unused") VirtualFrame frame, int a) {
275 return a;
276 }
277 }
278
279 @TypeSystemReference(ExecuteMethodTypes.class)
280 @NodeChild(value = "a", type = ChildNoFrame.class)
281 abstract static class ExecuteWithFrameError2 extends Node {
282
283 abstract Object executeFrame(MaterializedFrame frame);
284
285 @Specialization
286 @ExpectError("Method signature (VirtualFrame, int) does not match to the expected signature:%")
287 int doInt(@SuppressWarnings("unused") VirtualFrame frame, int a) {
288 return a;
289 }
290 }
291
292 @TypeSystemReference(ExecuteMethodTypes.class)
293 @NodeChild(value = "a", type = ChildNoFrame.class)
294 abstract static class ExecuteWithFrameError3 extends Node {
295
296 abstract Object executeFrame(VirtualFrame frame);
297
298 @Specialization
299 @ExpectError("Method signature (MaterializedFrame, int) does not match to the expected signature:%")
300 int doInt(@SuppressWarnings("unused") MaterializedFrame frame, int a) {
301 return a;
302 }
303 }
304
305 @TypeSystemReference(ExecuteMethodTypes.class)
306 @NodeChild(value = "a", type = ChildNoFrame.class)
307 @ExpectError("Invalid inconsistent frame types [MaterializedFrame, VirtualFrame] found for the declared execute methods.%")
308 abstract static class ExecuteWithFrameError4 extends Node {
309
310 abstract Object execute(VirtualFrame frame);
311
312 abstract int executeInt(MaterializedFrame frame) throws UnexpectedResultException;
313
314 @Specialization
315 int doInt(int a) {
316 return a;
317 }
318 }
319
320 @TypeSystemReference(ExecuteMethodTypes.class)
321 @NodeChild(value = "a", type = ChildNoFrame.class)
322 @ExpectError("Invalid inconsistent frame types [MaterializedFrame, void] found for the declared execute methods.%")
323 abstract static class ExecuteWithFrameError5 extends Node {
324
325 abstract Object execute();
326
327 abstract int executeInt(MaterializedFrame frame) throws UnexpectedResultException;
328
329 @Specialization
330 int doInt(int a) {
331 return a;
332 }
333 }
334
335 @TypeSystemReference(ExecuteMethodTypes.class)
336 abstract static class ChildVirtualFrame extends Node {
337 abstract Object execute(VirtualFrame frame);
338 }
339
340 @TypeSystemReference(ExecuteMethodTypes.class)
341 abstract static class ChildMaterializedFrame extends Node {
342 abstract Object execute(MaterializedFrame frame);
343 }
344
345 @TypeSystemReference(ExecuteMethodTypes.class)
346 abstract static class ChildFrame extends Node {
347 abstract Object execute(Frame frame);
348 }
349
350 @TypeSystemReference(ExecuteMethodTypes.class)
351 @NodeChild(value = "a", type = ChildNoFrame.class)
352 abstract static class ExecuteChildFrame1 extends Node {
353
354 abstract Object execute(VirtualFrame frame);
355
356 @Specialization
357 int doInt(int a) {
358 return a;
359 }
360 }
361
362 @TypeSystemReference(ExecuteMethodTypes.class)
363 @NodeChild(value = "a", type = ChildFrame.class)
364 abstract static class ExecuteChildFrame2 extends Node {
365
366 abstract Object execute(VirtualFrame frame);
367
368 @Specialization
369 int doInt(int a) {
370 return a;
371 }
372 }
373
374 @TypeSystemReference(ExecuteMethodTypes.class)
375 @NodeChild(value = "a", type = ChildFrame.class)
376 abstract static class ExecuteChildFrame3 extends Node {
377
378 abstract Object execute(MaterializedFrame frame);
379
380 @Specialization
381 int doInt(int a) {
382 return a;
383 }
384 }
385
386 @TypeSystemReference(ExecuteMethodTypes.class)
387 @NodeChild(value = "a", type = ChildFrame.class)
388 abstract static class ExecuteChildFrame4 extends Node {
389
390 abstract Object execute(Frame frame);
391
392 @Specialization
393 int doInt(int a) {
394 return a;
395 }
396 }
397
398 @ExpectError("No generic execute method found with 0 evaluated arguments for node type ChildVirtualFrame and frame types [com.oracle.truffle.api.frame.Frame].")
399 @TypeSystemReference(ExecuteMethodTypes.class)
400 @NodeChild(value = "a", type = ChildVirtualFrame.class)
401 abstract static class ExecuteChildFrameError1 extends Node {
402
403 abstract Object execute(Frame frame);
404
405 @Specialization
406 int doInt(int a) {
407 return a;
408 }
409 }
410
411 @ExpectError("No generic execute method found with 0 evaluated arguments for node type ChildFrame and frame types [].")
412 @TypeSystemReference(ExecuteMethodTypes.class)
413 @NodeChild(value = "a", type = ChildFrame.class)
414 abstract static class ExecuteChildFrameError2 extends Node {
415
416 abstract Object execute();
417
418 @Specialization
419 int doInt(int a) {
420 return a;
421 }
422 }
423
424 @ExpectError("No generic execute method found with 0 evaluated arguments for node type ChildVirtualFrame and frame types [].")
425 @TypeSystemReference(ExecuteMethodTypes.class)
426 @NodeChild(value = "a", type = ChildVirtualFrame.class)
427 abstract static class ExecuteChildFrameError3 extends Node {
428
429 abstract Object execute();
430
431 @Specialization
432 int doInt(int a) {
433 return a;
434 }
435 }
436
169 } 437 }