Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/PolymorphicTest2.java @ 13556:44288fe54352
Ruby: fix some ?break? semantics.
author | Chris Seaton <chris.seaton@oracle.com> |
---|---|
date | Wed, 08 Jan 2014 17:42:10 +0000 |
parents | ff6eb563a2e2 |
children | 5d1308c78ddc |
rev | line source |
---|---|
10743
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1 /* |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
4 * |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
8 * |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
13 * accompanied this code). |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
14 * |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
18 * |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
21 * questions. |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
22 */ |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
23 package com.oracle.truffle.api.dsl.test; |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
24 |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
25 import static com.oracle.truffle.api.dsl.test.TestHelper.*; |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
26 import static org.junit.Assert.*; |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
27 |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
28 import org.junit.*; |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
29 |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
30 import com.oracle.truffle.api.dsl.*; |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
31 import com.oracle.truffle.api.dsl.test.BinaryNodeTest.BinaryNode; |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
32 import com.oracle.truffle.api.dsl.test.PolymorphicTest2Factory.Node1Factory; |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
33 import com.oracle.truffle.api.dsl.test.TypeSystemTest.TestRootNode; |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
34 import com.oracle.truffle.api.nodes.*; |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
35 import com.oracle.truffle.api.nodes.NodeInfo.Kind; |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
36 |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
37 public class PolymorphicTest2 { |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
38 |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
39 @Test |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
40 public void testMultipleTypes() { |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
41 /* Tests the unexpected polymorphic case. */ |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
42 TestRootNode<Node1> node = TestHelper.createRoot(Node1Factory.getInstance()); |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
43 assertEquals(21, executeWith(node, false, false)); |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
44 assertEquals(42, executeWith(node, 21, 21)); |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
45 assertEquals("(boolean,int)", executeWith(node, false, 42)); |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
46 assertEquals(Kind.POLYMORPHIC, node.getNode().getClass().getAnnotation(NodeInfo.class).kind()); |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
47 } |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
48 |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
49 @SuppressWarnings("unused") |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
50 @PolymorphicLimit(3) |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
51 abstract static class Node1 extends BinaryNode { |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
52 |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
53 @Specialization(order = 1) |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
54 int add(int left, int right) { |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
55 return 42; |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
56 } |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
57 |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
58 @Specialization(order = 2) |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
59 int add(boolean left, boolean right) { |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
60 return 21; |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
61 } |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
62 |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
63 @Specialization(order = 4) |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
64 String add(boolean left, int right) { |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
65 return "(boolean,int)"; |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
66 } |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
67 |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
68 } |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
69 |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
70 } |