Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/ImplicitCastTest.java @ 20979:65d8d305f9c0
Minor linear scan tweaks
author | Tom Rodriguez <tom.rodriguez@oracle.com> |
---|---|
date | Tue, 14 Apr 2015 11:37:18 -0700 |
parents | 93016f2f3f16 |
children |
rev | line source |
---|---|
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1 /* |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
4 * |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
8 * |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
13 * accompanied this code). |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
14 * |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
18 * |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
21 * questions. |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
22 */ |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
23 package com.oracle.truffle.api.dsl.test; |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
24 |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
25 import org.junit.*; |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
26 |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
27 import com.oracle.truffle.api.dsl.*; |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
28 import com.oracle.truffle.api.dsl.test.ImplicitCastTestFactory.ImplicitCast0NodeFactory; |
12392
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
29 import com.oracle.truffle.api.dsl.test.ImplicitCastTestFactory.ImplicitCast1NodeFactory; |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
30 import com.oracle.truffle.api.dsl.test.ImplicitCastTestFactory.ImplicitCast2NodeFactory; |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
31 import com.oracle.truffle.api.dsl.test.TypeSystemTest.TestRootNode; |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
32 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode; |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
33 import com.oracle.truffle.api.frame.*; |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
34 |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
35 public class ImplicitCastTest { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
36 |
16756
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14632
diff
changeset
|
37 @TypeSystem({int.class, String.class, boolean.class}) |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
38 static class ImplicitCast0Types { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
39 |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
40 @ImplicitCast |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
16756
diff
changeset
|
41 static boolean castInt(int intvalue) { |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
42 return intvalue == 1 ? true : false; |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
43 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
44 |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
45 @ImplicitCast |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
16756
diff
changeset
|
46 static boolean castString(String strvalue) { |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
47 return strvalue.equals("1"); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
48 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
49 |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
50 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
51 |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
52 @TypeSystemReference(ImplicitCast0Types.class) |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
53 @NodeChild(value = "operand", type = ImplicitCast0Node.class) |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
54 abstract static class ImplicitCast0Node extends ValueNode { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
55 |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
56 public abstract Object executeEvaluated(VirtualFrame frame, Object value2); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
57 |
16756
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14632
diff
changeset
|
58 @Specialization |
12391
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11545
diff
changeset
|
59 public String op1(String value) { |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
60 return value; |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
61 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
62 |
16756
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14632
diff
changeset
|
63 @Specialization |
12391
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11545
diff
changeset
|
64 public boolean op1(boolean value) { |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
65 return value; |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
66 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
67 |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
68 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
69 |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
70 @Test |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
71 public void testImplicitCast0() { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
72 ImplicitCast0Node node = ImplicitCast0NodeFactory.create(null); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
73 TestRootNode<ImplicitCast0Node> root = new TestRootNode<>(node); |
14632
5f5e2711dc24
fix TruffleDSL tests
Andreas Woess <andreas.woess@jku.at>
parents:
13528
diff
changeset
|
74 root.adoptChildren(); |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
75 Assert.assertEquals("2", root.getNode().executeEvaluated(null, "2")); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
76 Assert.assertEquals(true, root.getNode().executeEvaluated(null, 1)); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
77 Assert.assertEquals("1", root.getNode().executeEvaluated(null, "1")); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
78 Assert.assertEquals(true, root.getNode().executeEvaluated(null, 1)); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
79 Assert.assertEquals(true, root.getNode().executeEvaluated(null, true)); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
80 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
81 |
12392
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
82 @TypeSystemReference(ImplicitCast0Types.class) |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
83 @NodeChild(value = "operand", type = ImplicitCast1Node.class) |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
84 abstract static class ImplicitCast1Node extends ValueNode { |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
85 |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
86 public abstract Object executeEvaluated(VirtualFrame frame, Object operand); |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
87 |
16756
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14632
diff
changeset
|
88 @Specialization |
12392
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
89 public String op0(String value) { |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
90 return value; |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
91 } |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
92 |
16756
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14632
diff
changeset
|
93 @Specialization(rewriteOn = RuntimeException.class) |
12392
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
94 public boolean op1(@SuppressWarnings("unused") boolean value) throws RuntimeException { |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
95 throw new RuntimeException(); |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
96 } |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
97 |
16756
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14632
diff
changeset
|
98 @Specialization(contains = "op1") |
12392
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
99 public boolean op2(boolean value) { |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
100 return value; |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
101 } |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
102 |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
103 } |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
104 |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
105 @Test |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
106 public void testImplicitCast1() { |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
107 ImplicitCast1Node node = ImplicitCast1NodeFactory.create(null); |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
108 TestRootNode<ImplicitCast1Node> root = new TestRootNode<>(node); |
14632
5f5e2711dc24
fix TruffleDSL tests
Andreas Woess <andreas.woess@jku.at>
parents:
13528
diff
changeset
|
109 root.adoptChildren(); |
12392
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
110 Assert.assertEquals("2", root.getNode().executeEvaluated(null, "2")); |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
111 Assert.assertEquals(true, root.getNode().executeEvaluated(null, 1)); |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
112 Assert.assertEquals("1", root.getNode().executeEvaluated(null, "1")); |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
113 Assert.assertEquals(true, root.getNode().executeEvaluated(null, 1)); |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
114 Assert.assertEquals(true, root.getNode().executeEvaluated(null, true)); |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
115 } |
12391
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11545
diff
changeset
|
116 |
12392
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
117 @TypeSystemReference(ImplicitCast0Types.class) |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
118 @NodeChildren({@NodeChild(value = "operand0", type = ImplicitCast2Node.class), @NodeChild(value = "operand1", type = ImplicitCast2Node.class, executeWith = "operand0")}) |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
119 // TODO temporary workaround |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
120 abstract static class ImplicitCast2Node extends ValueNode { |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
121 |
16756
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14632
diff
changeset
|
122 @Specialization |
12392
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
123 public String op0(String v0, String v1) { |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
124 return v0 + v1; |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
125 } |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
126 |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
127 @SuppressWarnings("unused") |
16756
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14632
diff
changeset
|
128 @Specialization(rewriteOn = RuntimeException.class) |
12392
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
129 public boolean op1(boolean v0, boolean v1) throws RuntimeException { |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
130 throw new RuntimeException(); |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
131 } |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
132 |
16756
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14632
diff
changeset
|
133 @Specialization(contains = "op1") |
12392
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
134 public boolean op2(boolean v0, boolean v1) { |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
135 return v0 && v1; |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
136 } |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
137 |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
138 public abstract Object executeEvaluated(VirtualFrame frame, Object v1); |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
139 |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
140 public abstract Object executeEvaluated(VirtualFrame frame, Object v1, Object v2); |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
141 |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
142 public abstract Object executeEvaluated(VirtualFrame frame, boolean v1, boolean v2); |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
143 |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
144 } |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
145 |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
146 @Test |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
147 public void testImplicitCast2() { |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
148 ImplicitCast2Node node = ImplicitCast2NodeFactory.create(null, null); |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
149 TestRootNode<ImplicitCast2Node> root = new TestRootNode<>(node); |
14632
5f5e2711dc24
fix TruffleDSL tests
Andreas Woess <andreas.woess@jku.at>
parents:
13528
diff
changeset
|
150 root.adoptChildren(); |
12393
7cce548b0b60
Truffle-DSL: fixed minor issue in implicit cast tests.
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
151 Assert.assertEquals("42", root.getNode().executeEvaluated(null, "4", "2")); |
7cce548b0b60
Truffle-DSL: fixed minor issue in implicit cast tests.
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
152 Assert.assertEquals(true, root.getNode().executeEvaluated(null, 1, 1)); |
7cce548b0b60
Truffle-DSL: fixed minor issue in implicit cast tests.
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
153 Assert.assertEquals("42", root.getNode().executeEvaluated(null, "4", "2")); |
7cce548b0b60
Truffle-DSL: fixed minor issue in implicit cast tests.
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
154 Assert.assertEquals(true, root.getNode().executeEvaluated(null, 1, 1)); |
7cce548b0b60
Truffle-DSL: fixed minor issue in implicit cast tests.
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
155 Assert.assertEquals(true, root.getNode().executeEvaluated(null, true, true)); |
12392
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
156 } |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
157 |
16756
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14632
diff
changeset
|
158 @TypeSystem({String.class, boolean.class}) |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14632
diff
changeset
|
159 static class ImplicitCastError1 { |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14632
diff
changeset
|
160 |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14632
diff
changeset
|
161 @ImplicitCast |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14632
diff
changeset
|
162 @ExpectError("Target type and source type of an @ImplicitCast must not be the same type.") |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
16756
diff
changeset
|
163 static String castInvalid(@SuppressWarnings("unused") String value) { |
16756
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14632
diff
changeset
|
164 throw new AssertionError(); |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14632
diff
changeset
|
165 } |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14632
diff
changeset
|
166 |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14632
diff
changeset
|
167 } |
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14632
diff
changeset
|
168 |
18785
93016f2f3f16
Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
169 @TypeSystem({String.class, boolean.class}) |
93016f2f3f16
Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
170 static class ImplicitCastError2 { |
93016f2f3f16
Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
171 |
93016f2f3f16
Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
172 @ImplicitCast |
93016f2f3f16
Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
173 @ExpectError("Target type and source type of an @ImplicitCast must not be the same type.") |
93016f2f3f16
Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
174 static String castInvalid(@SuppressWarnings("unused") String value) { |
93016f2f3f16
Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
175 throw new AssertionError(); |
93016f2f3f16
Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
176 } |
93016f2f3f16
Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
177 |
93016f2f3f16
Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
178 } |
93016f2f3f16
Truffle-DSL: optimize generated code for nodes with a single specialization. (GRAAL-602 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
179 |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
180 } |