comparison truffle/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/ExecuteMethodTest.java @ 21951:9c8c0937da41

Moving all sources into truffle subdirectory
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Wed, 17 Jun 2015 10:58:08 +0200
parents graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/ExecuteMethodTest.java@476374f3fe9a
children dc83cc1f94f2
comparison
equal deleted inserted replaced
21950:2a5011c7e641 21951:9c8c0937da41
1 /*
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package com.oracle.truffle.api.dsl.test;
24
25 import com.oracle.truffle.api.dsl.*;
26 import com.oracle.truffle.api.dsl.internal.*;
27 import com.oracle.truffle.api.frame.*;
28 import com.oracle.truffle.api.nodes.*;
29
30 public class ExecuteMethodTest {
31
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} "
33 + "execute(VirtualFrame)' and must not throw any checked exceptions.";
34
35 @TypeSystem({int.class})
36 @DSLOptions(useNewLayout = true)
37 static class ExecuteMethodTypes {
38 }
39
40 @TypeSystemReference(ExecuteMethodTypes.class)
41 abstract static class ChildNoFrame extends Node {
42 abstract Object execute();
43 }
44
45 @TypeSystemReference(ExecuteMethodTypes.class)
46 @NodeChild(value = "a", type = ChildNoFrame.class)
47 @ExpectError(ERROR_NO_EXECUTE)
48 abstract static class ExecuteThis1 extends Node {
49
50 @Specialization
51 int doInt(int a) {
52 return a;
53 }
54 }
55
56 @TypeSystemReference(ExecuteMethodTypes.class)
57 @NodeChild(value = "a", type = ChildNoFrame.class)
58 @ExpectError(ERROR_NO_EXECUTE)
59 abstract static class ExecuteThis2 extends Node {
60
61 abstract Object execute() throws UnexpectedResultException;
62
63 @Specialization
64 int doInt(int a) {
65 return a;
66 }
67 }
68
69 @TypeSystemReference(ExecuteMethodTypes.class)
70 @NodeChild(value = "a", type = ChildNoFrame.class)
71 @ExpectError(ERROR_NO_EXECUTE)
72 abstract static class ExecuteThis3 extends Node {
73
74 abstract int execute() throws UnexpectedResultException;
75
76 @Specialization
77 int doInt(int a) {
78 return a;
79 }
80 }
81
82 @TypeSystemReference(ExecuteMethodTypes.class)
83 @NodeChild(value = "a", type = ChildNoFrame.class)
84 abstract static class ExecuteThis4 extends Node {
85
86 protected abstract Object execute();
87
88 @Specialization
89 int doInt(int a) {
90 return a;
91 }
92 }
93
94 @TypeSystemReference(ExecuteMethodTypes.class)
95 @NodeChild(value = "a", type = ChildNoFrame.class)
96 abstract static class ExecuteThis5 extends Node {
97
98 public abstract Object execute();
99
100 @Specialization
101 int doInt(int a) {
102 return a;
103 }
104 }
105
106 @TypeSystemReference(ExecuteMethodTypes.class)
107 @NodeChild(value = "a", type = ChildNoFrame.class)
108 @ExpectError(ERROR_NO_EXECUTE)
109 abstract static class ExecuteThis6 extends Node {
110
111 @SuppressWarnings({"unused", "static-method"})
112 private Object execute() {
113 return 0;
114 }
115
116 @Specialization
117 int doInt(int a) {
118 return a;
119 }
120 }
121
122 @TypeSystemReference(ExecuteMethodTypes.class)
123 @NodeChild(value = "a", type = ChildNoFrame.class)
124 @ExpectError(ERROR_NO_EXECUTE)
125 abstract static class ExecuteThis7 extends Node {
126
127 @SuppressWarnings("static-method")
128 public final int executeInt() {
129 return 0;
130 }
131
132 @Specialization
133 int doInt(int a) {
134 return a;
135 }
136 }
137
138 @TypeSystemReference(ExecuteMethodTypes.class)
139 @NodeChild(value = "a", type = ChildNoFrame.class)
140 abstract static class ExecuteThis8 extends Node {
141
142 abstract int executeInt();
143
144 abstract Object executeObject();
145
146 @Specialization
147 int doInt(int a) {
148 return a;
149 }
150
151 }
152
153 @TypeSystemReference(ExecuteMethodTypes.class)
154 @NodeChild(value = "a", type = ChildNoFrame.class)
155 abstract static class ExecuteThis9 extends Node {
156
157 abstract int executeInt();
158
159 // disambiguate executeObject
160 final Object executeObject() {
161 return executeInt();
162 }
163
164 @Specialization
165 int doInt(int a) {
166 return a;
167 }
168 }
169
170 @TypeSystemReference(ExecuteMethodTypes.class)
171 @NodeChild(value = "a", type = ChildNoFrame.class)
172 abstract static class ExecuteThisVoid1 extends Node {
173
174 abstract void executeVoid();
175
176 @Specialization
177 void doInt(@SuppressWarnings("unused") int a) {
178 }
179 }
180
181 @TypeSystemReference(ExecuteMethodTypes.class)
182 @NodeChild(value = "a", type = ChildNoFrame.class)
183 abstract static class ExecuteThisVoid2 extends Node {
184
185 // allow one execute void
186 abstract void executeVoid();
187
188 abstract Object executeObject();
189
190 @Specialization
191 int doInt(int a) {
192 return a;
193 }
194 }
195
196 @TypeSystemReference(ExecuteMethodTypes.class)
197 @NodeChild(value = "a", type = ChildNoFrame.class)
198 abstract static class ExecuteThisVoid3 extends Node {
199
200 // allow only one execute void
201 abstract void executeVoid1();
202
203 abstract void executeVoid2();
204
205 abstract Object executeObject();
206
207 @Specialization
208 int doInt(int a) {
209 return a;
210 }
211 }
212
213 @TypeSystemReference(ExecuteMethodTypes.class)
214 @NodeChild(value = "a", type = ChildNoFrame.class)
215 abstract static class ExecuteWithFrame1 extends Node {
216
217 // no frame in execute. no parameter in specializations
218 abstract Object executeNoFrame();
219
220 @Specialization
221 int doInt(int a) {
222 return a;
223 }
224 }
225
226 @TypeSystemReference(ExecuteMethodTypes.class)
227 @NodeChild(value = "a", type = ChildNoFrame.class)
228 abstract static class ExecuteWithFrame2 extends Node {
229
230 // frame in execute also usable in specialization
231 abstract Object executeWithFrame(VirtualFrame frame);
232
233 @Specialization
234 int doInt(@SuppressWarnings("unused") VirtualFrame frame, int a) {
235 return a;
236 }
237 }
238
239 @TypeSystemReference(ExecuteMethodTypes.class)
240 @NodeChild(value = "a", type = ChildNoFrame.class)
241 abstract static class ExecuteWithFrame3 extends Node {
242
243 abstract Object executeWithFrame(Frame frame);
244
245 @Specialization
246 int doInt(@SuppressWarnings("unused") Frame frame, int a) {
247 return a;
248 }
249 }
250
251 @TypeSystemReference(ExecuteMethodTypes.class)
252 @NodeChild(value = "a", type = ExecuteWithFrame4.class)
253 abstract static class ExecuteWithFrame4 extends Node {
254
255 abstract Object executeWithFrame(MaterializedFrame frame);
256
257 @Specialization
258 int doInt(@SuppressWarnings("unused") MaterializedFrame frame, int a) {
259 return a;
260 }
261 }
262
263 @TypeSystemReference(ExecuteMethodTypes.class)
264 @NodeChild(value = "a", type = ChildNoFrame.class)
265 abstract static class ExecuteWithFrameError1 extends Node {
266
267 abstract Object executeNoFrame();
268
269 @Specialization
270 @ExpectError("Method signature (VirtualFrame, int) does not match to the expected signature:%")
271 int doInt(@SuppressWarnings("unused") VirtualFrame frame, int a) {
272 return a;
273 }
274 }
275
276 @TypeSystemReference(ExecuteMethodTypes.class)
277 @NodeChild(value = "a", type = ChildNoFrame.class)
278 abstract static class ExecuteWithFrameError2 extends Node {
279
280 abstract Object executeFrame(MaterializedFrame frame);
281
282 @Specialization
283 @ExpectError("Method signature (VirtualFrame, int) does not match to the expected signature:%")
284 int doInt(@SuppressWarnings("unused") VirtualFrame frame, int a) {
285 return a;
286 }
287 }
288
289 @TypeSystemReference(ExecuteMethodTypes.class)
290 @NodeChild(value = "a", type = ChildNoFrame.class)
291 abstract static class ExecuteWithFrameError3 extends Node {
292
293 abstract Object executeFrame(VirtualFrame frame);
294
295 @Specialization
296 @ExpectError("Method signature (MaterializedFrame, int) does not match to the expected signature:%")
297 int doInt(@SuppressWarnings("unused") MaterializedFrame frame, int a) {
298 return a;
299 }
300 }
301
302 @TypeSystemReference(ExecuteMethodTypes.class)
303 @NodeChild(value = "a", type = ChildNoFrame.class)
304 @ExpectError("Invalid inconsistent frame types [MaterializedFrame, VirtualFrame] found for the declared execute methods.%")
305 abstract static class ExecuteWithFrameError4 extends Node {
306
307 abstract Object execute(VirtualFrame frame);
308
309 abstract int executeInt(MaterializedFrame frame) throws UnexpectedResultException;
310
311 @Specialization
312 int doInt(int a) {
313 return a;
314 }
315 }
316
317 @TypeSystemReference(ExecuteMethodTypes.class)
318 @NodeChild(value = "a", type = ChildNoFrame.class)
319 abstract static class ExecuteWithFrameError5 extends Node {
320
321 abstract Object execute();
322
323 abstract int executeInt(MaterializedFrame frame) throws UnexpectedResultException;
324
325 @Specialization
326 int doInt(int a) {
327 return a;
328 }
329 }
330
331 @TypeSystemReference(ExecuteMethodTypes.class)
332 abstract static class ChildVirtualFrame extends Node {
333 abstract Object execute(VirtualFrame frame);
334 }
335
336 @TypeSystemReference(ExecuteMethodTypes.class)
337 abstract static class ChildMaterializedFrame extends Node {
338 abstract Object execute(MaterializedFrame frame);
339 }
340
341 @TypeSystemReference(ExecuteMethodTypes.class)
342 abstract static class ChildFrame extends Node {
343 abstract Object execute(Frame frame);
344 }
345
346 @TypeSystemReference(ExecuteMethodTypes.class)
347 @NodeChild(value = "a", type = ChildNoFrame.class)
348 abstract static class ExecuteChildFrame1 extends Node {
349
350 abstract Object execute(VirtualFrame frame);
351
352 @Specialization
353 int doInt(int a) {
354 return a;
355 }
356 }
357
358 @TypeSystemReference(ExecuteMethodTypes.class)
359 @NodeChild(value = "a", type = ChildFrame.class)
360 abstract static class ExecuteChildFrame2 extends Node {
361
362 abstract Object execute(VirtualFrame frame);
363
364 @Specialization
365 int doInt(int a) {
366 return a;
367 }
368 }
369
370 @TypeSystemReference(ExecuteMethodTypes.class)
371 @NodeChild(value = "a", type = ChildFrame.class)
372 abstract static class ExecuteChildFrame3 extends Node {
373
374 abstract Object execute(MaterializedFrame frame);
375
376 @Specialization
377 int doInt(int a) {
378 return a;
379 }
380 }
381
382 @TypeSystemReference(ExecuteMethodTypes.class)
383 @NodeChild(value = "a", type = ChildFrame.class)
384 abstract static class ExecuteChildFrame4 extends Node {
385
386 abstract Object execute(Frame frame);
387
388 @Specialization
389 int doInt(int a) {
390 return a;
391 }
392 }
393
394 @ExpectError("No generic execute method found with 0 evaluated arguments for node type ChildVirtualFrame and frame types [com.oracle.truffle.api.frame.Frame].")
395 @TypeSystemReference(ExecuteMethodTypes.class)
396 @NodeChild(value = "a", type = ChildVirtualFrame.class)
397 abstract static class ExecuteChildFrameError1 extends Node {
398
399 abstract Object execute(Frame frame);
400
401 @Specialization
402 int doInt(int a) {
403 return a;
404 }
405 }
406
407 @ExpectError("No generic execute method found with 0 evaluated arguments for node type ChildFrame and frame types [].")
408 @TypeSystemReference(ExecuteMethodTypes.class)
409 @NodeChild(value = "a", type = ChildFrame.class)
410 abstract static class ExecuteChildFrameError2 extends Node {
411
412 abstract Object execute();
413
414 @Specialization
415 int doInt(int a) {
416 return a;
417 }
418 }
419
420 @ExpectError("No generic execute method found with 0 evaluated arguments for node type ChildVirtualFrame and frame types [].")
421 @TypeSystemReference(ExecuteMethodTypes.class)
422 @NodeChild(value = "a", type = ChildVirtualFrame.class)
423 abstract static class ExecuteChildFrameError3 extends Node {
424
425 abstract Object execute();
426
427 @Specialization
428 int doInt(int a) {
429 return a;
430 }
431 }
432
433 }