comparison graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/InsertBeforeTest.java @ 19283:08aa0372dad4

Truffle-DSL: implement new guard expression syntax.
author Christian Humer <christian.humer@gmail.com>
date Fri, 23 Jan 2015 02:55:23 +0100
parents c88ab4f1f04a
children
comparison
equal deleted inserted replaced
19282:ae81dd154fb6 19283:08aa0372dad4
28 public class InsertBeforeTest { 28 public class InsertBeforeTest {
29 29
30 @NodeChild("a") 30 @NodeChild("a")
31 static class InsertBefore1Base extends ValueNode { 31 static class InsertBefore1Base extends ValueNode {
32 32
33 boolean g1(int a) { 33 @Specialization(guards = "a == 1")
34 return a == 1;
35 }
36
37 boolean g2(int a) {
38 return a == 2;
39 }
40
41 @Specialization(guards = "g1")
42 int f1(int a) { 34 int f1(int a) {
43 return a; 35 return a;
44 } 36 }
45 37
46 @Specialization(guards = "g2") 38 @Specialization(guards = "a == 2")
47 int f3(int a) { 39 int f3(int a) {
48 return a; 40 return a;
49 } 41 }
50 42
51 } 43 }
61 } 53 }
62 54
63 @NodeChild("a") 55 @NodeChild("a")
64 static class InsertBefore1T2 extends InsertBefore1Base { 56 static class InsertBefore1T2 extends InsertBefore1Base {
65 57
66 boolean g0(int a) { 58 @Specialization(guards = "a == 0", insertBefore = "f1")
67 return a == 0;
68 }
69
70 @Specialization(guards = "g0", insertBefore = "f1")
71 int f0(int a) { 59 int f0(int a) {
72 return a; 60 return a;
73 } 61 }
74 62
75 } 63 }
76 64
77 @NodeChild("a") 65 @NodeChild("a")
78 static class InsertBefore1T3 extends InsertBefore1Base { 66 static class InsertBefore1T3 extends InsertBefore1Base {
79 67
80 boolean g0(int a) { 68 @Specialization(guards = "a == 0", insertBefore = "f3")
81 return a == 0;
82 }
83
84 @Specialization(guards = "g0", insertBefore = "f3")
85 int f0(int a) { 69 int f0(int a) {
86 return a; 70 return a;
87 } 71 }
88 72
89 } 73 }
90 74
91 @NodeChild("a") 75 @NodeChild("a")
92 @ExpectError({"Method f3(int) at annotation @Specialization is erroneous: Specialization is not reachable. It is shadowed by f0(int).", 76 @ExpectError({"Method f3(int) at annotation @Specialization is erroneous: Specialization is not reachable. It is shadowed by f0(int).",
93 "Method f1(int) at annotation @Specialization is erroneous: Specialization is not reachable. It is shadowed by f0(int)."}) 77 "Method f1(int) at annotation @Specialization is erroneous: Specialization is not reachable. It is shadowed by f0(int)."})
94 static class InsertBefore1T4 extends InsertBefore1Base { 78 static class InsertBefore1T4 extends InsertBefore1Base {
95
96 boolean g0(int a) {
97 return a == 0;
98 }
99 79
100 @Specialization(insertBefore = "f1") 80 @Specialization(insertBefore = "f1")
101 int f0(int a) { 81 int f0(int a) {
102 return a; 82 return a;
103 } 83 }
124 104
125 boolean g0(int a) { 105 boolean g0(int a) {
126 return a == 0; 106 return a == 0;
127 } 107 }
128 108
129 @Specialization(insertBefore = "f1", guards = "g0") 109 @Specialization(insertBefore = "f1", guards = "a == 0")
130 int f0(int a) { 110 int f0(int a) {
131 return a; 111 return a;
132 } 112 }
133 113
134 } 114 }
135 115
136 @NodeChild("a") 116 @NodeChild("a")
137 static class InsertBefore1T6part2 extends InsertBefore1T6part1 { 117 static class InsertBefore1T6part2 extends InsertBefore1T6part1 {
138 118
139 boolean g(int a) { 119 @Specialization(insertBefore = "f0", guards = "a == 3")
140 return a == 0;
141 }
142
143 @Specialization(insertBefore = "f0", guards = "g")
144 int f(int a) { 120 int f(int a) {
145 return a; 121 return a;
146 } 122 }
147 123
148 } 124 }