comparison graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/ImplicitCastTest.java @ 12391:7aa2a8c69ba3

TruffleDSL: improved code generation layout for implicit casts.
author Christian Humer <christian.humer@gmail.com>
date Thu, 03 Oct 2013 16:31:09 +0200
parents 2fb276f5e3e9
children 4e26955b6da2
comparison
equal deleted inserted replaced
12390:5151a7588384 12391:7aa2a8c69ba3
52 @NodeChild(value = "operand", type = ImplicitCast0Node.class) 52 @NodeChild(value = "operand", type = ImplicitCast0Node.class)
53 abstract static class ImplicitCast0Node extends ValueNode { 53 abstract static class ImplicitCast0Node extends ValueNode {
54 54
55 public abstract Object executeEvaluated(VirtualFrame frame, Object value2); 55 public abstract Object executeEvaluated(VirtualFrame frame, Object value2);
56 56
57 @Specialization(order = 1) 57 @Specialization
58 public String op1(String value) throws RuntimeException { 58 public String op1(String value) {
59 return value; 59 return value;
60 } 60 }
61 61
62 @Specialization(order = 2) 62 @Specialization
63 public boolean op1(boolean value) throws RuntimeException { 63 public boolean op1(boolean value) {
64 return value; 64 return value;
65 } 65 }
66 66
67 } 67 }
68 68
75 Assert.assertEquals("1", root.getNode().executeEvaluated(null, "1")); 75 Assert.assertEquals("1", root.getNode().executeEvaluated(null, "1"));
76 Assert.assertEquals(true, root.getNode().executeEvaluated(null, 1)); 76 Assert.assertEquals(true, root.getNode().executeEvaluated(null, 1));
77 Assert.assertEquals(true, root.getNode().executeEvaluated(null, true)); 77 Assert.assertEquals(true, root.getNode().executeEvaluated(null, true));
78 } 78 }
79 79
80 // @TypeSystemReference(ImplicitCast0Types.class)
81 // @NodeChild(value = "operand", type = ImplicitCast0Node.class)
82 // abstract static class ImplicitCast1Node extends ValueNode {
83 //
84 // @Specialization
85 // public String op0(String value) {
86 // return value;
87 // }
88 //
89 // @Specialization(order = 1, rewriteOn = RuntimeException.class)
90 // public boolean op1(@SuppressWarnings("unused") boolean value) throws RuntimeException {
91 // throw new RuntimeException();
92 // }
93 //
94 // @Specialization(order = 2)
95 // public boolean op2(boolean value) {
96 // return value;
97 // }
98 //
99 // }
100 //
101 // @Test
102 // public void testImplicitCast1() {
103 // ImplicitCast0Node node = ImplicitCast0NodeFactory.create(null);
104 // TestRootNode<ImplicitCast0Node> root = new TestRootNode<>(node);
105 // Assert.assertEquals("2", root.getNode().executeEvaluated(null, "2"));
106 // Assert.assertEquals(true, root.getNode().executeEvaluated(null, 1));
107 // Assert.assertEquals("1", root.getNode().executeEvaluated(null, "1"));
108 // Assert.assertEquals(true, root.getNode().executeEvaluated(null, 1));
109 // Assert.assertEquals(true, root.getNode().executeEvaluated(null, true));
110 // }
111
80 // TODO assert implicit casts only in one direction 112 // TODO assert implicit casts only in one direction
81 113
82 // test example that covers the most cases 114 // test example that covers the most cases
83 115
84 } 116 }