Mercurial > hg > truffle
annotate truffle/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/PolymorphicTest2.java @ 22157:dc83cc1f94f2
Using fully qualified imports
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Wed, 16 Sep 2015 11:33:22 +0200 |
parents | 9c8c0937da41 |
children | 14e6dfb1ef05 |
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 |
22157
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
25 import com.oracle.truffle.api.dsl.Specialization; |
10743
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
26 import com.oracle.truffle.api.dsl.test.BinaryNodeTest.BinaryNode; |
16756
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
27 import com.oracle.truffle.api.dsl.test.PolymorphicTest2Factory.Polymorphic1Factory; |
22157
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
28 import static com.oracle.truffle.api.dsl.test.TestHelper.executeWith; |
10743
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
29 import com.oracle.truffle.api.dsl.test.TypeSystemTest.TestRootNode; |
22157
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
30 import com.oracle.truffle.api.nodes.NodeCost; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
31 import static org.junit.Assert.assertEquals; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
32 import org.junit.Test; |
10743
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
33 |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
34 public class PolymorphicTest2 { |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
35 |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
36 @Test |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
37 public void testMultipleTypes() { |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
38 /* Tests the unexpected polymorphic case. */ |
16756
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
39 TestRootNode<Polymorphic1> node = TestHelper.createRoot(Polymorphic1Factory.getInstance()); |
10743
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
40 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
|
41 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
|
42 assertEquals("(boolean,int)", executeWith(node, false, 42)); |
14641
f0bb82ebe30c
Truffle-DSL: some fixes and optimizations to the generated code.
Christian Humer <christian.humer@gmail.com>
parents:
14564
diff
changeset
|
43 assertEquals(NodeCost.POLYMORPHIC, node.getNode().getCost()); |
10743
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
44 } |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
45 |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
46 @SuppressWarnings("unused") |
16756
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
47 abstract static class Polymorphic1 extends BinaryNode { |
10743
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
48 |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
16756
diff
changeset
|
49 @Specialization |
10743
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
50 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
|
51 return 42; |
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 |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
16756
diff
changeset
|
54 @Specialization |
10743
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
55 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
|
56 return 21; |
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 |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
16756
diff
changeset
|
59 @Specialization |
10743
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
60 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
|
61 return "(boolean,int)"; |
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 |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
64 } |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
65 |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
66 } |