Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/ImplicitCastTest.java @ 16756:5148aab962af
Truffle-DSL: updated tests for the new generation layout.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Mon, 11 Aug 2014 15:53:05 +0200 |
parents | 5f5e2711dc24 |
children | 3912400fc33a |
comparison
equal
deleted
inserted
replaced
16755:bd28da642eea | 16756:5148aab962af |
---|---|
32 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode; | 32 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode; |
33 import com.oracle.truffle.api.frame.*; | 33 import com.oracle.truffle.api.frame.*; |
34 | 34 |
35 public class ImplicitCastTest { | 35 public class ImplicitCastTest { |
36 | 36 |
37 @TypeSystem({int.class, boolean.class, String.class}) | 37 @TypeSystem({int.class, String.class, boolean.class}) |
38 static class ImplicitCast0Types { | 38 static class ImplicitCast0Types { |
39 | 39 |
40 @ImplicitCast | 40 @ImplicitCast |
41 boolean castInt(int intvalue) { | 41 boolean castInt(int intvalue) { |
42 return intvalue == 1 ? true : false; | 42 return intvalue == 1 ? true : false; |
53 @NodeChild(value = "operand", type = ImplicitCast0Node.class) | 53 @NodeChild(value = "operand", type = ImplicitCast0Node.class) |
54 abstract static class ImplicitCast0Node extends ValueNode { | 54 abstract static class ImplicitCast0Node extends ValueNode { |
55 | 55 |
56 public abstract Object executeEvaluated(VirtualFrame frame, Object value2); | 56 public abstract Object executeEvaluated(VirtualFrame frame, Object value2); |
57 | 57 |
58 @Specialization(order = 1) | 58 @Specialization |
59 public String op1(String value) { | 59 public String op1(String value) { |
60 return value; | 60 return value; |
61 } | 61 } |
62 | 62 |
63 @Specialization(order = 2) | 63 @Specialization |
64 public boolean op1(boolean value) { | 64 public boolean op1(boolean value) { |
65 return value; | 65 return value; |
66 } | 66 } |
67 | 67 |
68 } | 68 } |
79 Assert.assertEquals(true, root.getNode().executeEvaluated(null, true)); | 79 Assert.assertEquals(true, root.getNode().executeEvaluated(null, true)); |
80 } | 80 } |
81 | 81 |
82 @TypeSystemReference(ImplicitCast0Types.class) | 82 @TypeSystemReference(ImplicitCast0Types.class) |
83 @NodeChild(value = "operand", type = ImplicitCast1Node.class) | 83 @NodeChild(value = "operand", type = ImplicitCast1Node.class) |
84 // TODO temporary workaround | |
85 abstract static class ImplicitCast1Node extends ValueNode { | 84 abstract static class ImplicitCast1Node extends ValueNode { |
86 | 85 |
87 public abstract Object executeEvaluated(VirtualFrame frame, Object operand); | 86 public abstract Object executeEvaluated(VirtualFrame frame, Object operand); |
88 | 87 |
89 @Specialization(order = 0) | 88 @Specialization |
90 public String op0(String value) { | 89 public String op0(String value) { |
91 return value; | 90 return value; |
92 } | 91 } |
93 | 92 |
94 @Specialization(order = 1, rewriteOn = RuntimeException.class) | 93 @Specialization(rewriteOn = RuntimeException.class) |
95 public boolean op1(@SuppressWarnings("unused") boolean value) throws RuntimeException { | 94 public boolean op1(@SuppressWarnings("unused") boolean value) throws RuntimeException { |
96 throw new RuntimeException(); | 95 throw new RuntimeException(); |
97 } | 96 } |
98 | 97 |
99 @Specialization(order = 2) | 98 @Specialization(contains = "op1") |
100 public boolean op2(boolean value) { | 99 public boolean op2(boolean value) { |
101 return value; | 100 return value; |
102 } | 101 } |
103 | 102 |
104 } | 103 } |
118 @TypeSystemReference(ImplicitCast0Types.class) | 117 @TypeSystemReference(ImplicitCast0Types.class) |
119 @NodeChildren({@NodeChild(value = "operand0", type = ImplicitCast2Node.class), @NodeChild(value = "operand1", type = ImplicitCast2Node.class, executeWith = "operand0")}) | 118 @NodeChildren({@NodeChild(value = "operand0", type = ImplicitCast2Node.class), @NodeChild(value = "operand1", type = ImplicitCast2Node.class, executeWith = "operand0")}) |
120 // TODO temporary workaround | 119 // TODO temporary workaround |
121 abstract static class ImplicitCast2Node extends ValueNode { | 120 abstract static class ImplicitCast2Node extends ValueNode { |
122 | 121 |
123 @Specialization(order = 0) | 122 @Specialization |
124 public String op0(String v0, String v1) { | 123 public String op0(String v0, String v1) { |
125 return v0 + v1; | 124 return v0 + v1; |
126 } | 125 } |
127 | 126 |
128 @SuppressWarnings("unused") | 127 @SuppressWarnings("unused") |
129 @Specialization(order = 1, rewriteOn = RuntimeException.class) | 128 @Specialization(rewriteOn = RuntimeException.class) |
130 public boolean op1(boolean v0, boolean v1) throws RuntimeException { | 129 public boolean op1(boolean v0, boolean v1) throws RuntimeException { |
131 throw new RuntimeException(); | 130 throw new RuntimeException(); |
132 } | 131 } |
133 | 132 |
134 @Specialization(order = 2) | 133 @Specialization(contains = "op1") |
135 public boolean op2(boolean v0, boolean v1) { | 134 public boolean op2(boolean v0, boolean v1) { |
136 return v0 && v1; | 135 return v0 && v1; |
137 } | 136 } |
138 | 137 |
139 public abstract Object executeEvaluated(VirtualFrame frame, Object v1); | 138 public abstract Object executeEvaluated(VirtualFrame frame, Object v1); |
154 Assert.assertEquals("42", root.getNode().executeEvaluated(null, "4", "2")); | 153 Assert.assertEquals("42", root.getNode().executeEvaluated(null, "4", "2")); |
155 Assert.assertEquals(true, root.getNode().executeEvaluated(null, 1, 1)); | 154 Assert.assertEquals(true, root.getNode().executeEvaluated(null, 1, 1)); |
156 Assert.assertEquals(true, root.getNode().executeEvaluated(null, true, true)); | 155 Assert.assertEquals(true, root.getNode().executeEvaluated(null, true, true)); |
157 } | 156 } |
158 | 157 |
158 @TypeSystem({String.class, boolean.class}) | |
159 static class ImplicitCastError1 { | |
160 | |
161 @ImplicitCast | |
162 @ExpectError("Target type and source type of an @ImplicitCast must not be the same type.") | |
163 String castInvalid(@SuppressWarnings("unused") String value) { | |
164 throw new AssertionError(); | |
165 } | |
166 | |
167 } | |
168 | |
159 } | 169 } |