OLD | NEW |
1 library dart2js.unsugar_cps; | 1 library dart2js.unsugar_cps; |
2 | 2 |
3 import '../../cps_ir/cps_ir_nodes.dart'; | 3 import '../../cps_ir/cps_ir_nodes.dart'; |
4 | 4 |
5 import '../../cps_ir/optimizers.dart' show ParentVisitor; | 5 import '../../cps_ir/optimizers.dart' show ParentVisitor; |
6 import '../../constants/expressions.dart'; | 6 import '../../constants/expressions.dart'; |
7 import '../../constants/values.dart'; | 7 import '../../constants/values.dart'; |
8 import '../../elements/elements.dart'; | 8 import '../../elements/elements.dart'; |
9 import '../../js_backend/codegen/glue.dart'; | 9 import '../../js_backend/codegen/glue.dart'; |
10 import '../../dart2jslib.dart' show Selector, World; | 10 import '../../dart2jslib.dart' show Selector, World; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 // Set all parent pointers. | 75 // Set all parent pointers. |
76 _parentVisitor.visit(function); | 76 _parentVisitor.visit(function); |
77 | 77 |
78 if (inInterceptedMethod) { | 78 if (inInterceptedMethod) { |
79 explicitReceiverParameter.substituteFor(thisParameter); | 79 explicitReceiverParameter.substituteFor(thisParameter); |
80 } | 80 } |
81 | 81 |
82 visit(function); | 82 visit(function); |
83 } | 83 } |
84 | 84 |
85 @override | |
86 visit(Node node) { | |
87 Node result = node.accept(this); | |
88 return result != null ? result : node; | |
89 } | |
90 | |
91 Constant get trueConstant { | 85 Constant get trueConstant { |
92 return new Constant(new TrueConstantValue()); | 86 return new Constant(new TrueConstantValue()); |
93 } | 87 } |
94 | 88 |
95 Constant get falseConstant { | 89 Constant get falseConstant { |
96 return new Constant(new FalseConstantValue()); | 90 return new Constant(new FalseConstantValue()); |
97 } | 91 } |
98 | 92 |
99 Constant get nullConstant { | 93 Constant get nullConstant { |
100 return new Constant(new NullConstantValue()); | 94 return new Constant(new NullConstantValue()); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 new InvokeStatic(function, selector, arguments, continuation, null); | 163 new InvokeStatic(function, selector, arguments, continuation, null); |
170 _parentVisitor.processInvokeStatic(invoke); | 164 _parentVisitor.processInvokeStatic(invoke); |
171 | 165 |
172 LetCont letCont = new LetCont(continuation, invoke); | 166 LetCont letCont = new LetCont(continuation, invoke); |
173 _parentVisitor.processLetCont(letCont); | 167 _parentVisitor.processLetCont(letCont); |
174 | 168 |
175 parent.body = letCont; | 169 parent.body = letCont; |
176 letCont.parent = parent; | 170 letCont.parent = parent; |
177 } | 171 } |
178 | 172 |
179 processLetHandler(LetHandler node) { | 173 @override |
| 174 Expression traverseLetHandler(LetHandler node) { |
| 175 assert(node.handler.parameters.length == 2); |
| 176 Parameter previousExceptionParameter = _exceptionParameter; |
| 177 |
180 // BEFORE: Handlers have two parameters, exception and stack trace. | 178 // BEFORE: Handlers have two parameters, exception and stack trace. |
181 // AFTER: Handlers have a single parameter, which is unwrapped to get | 179 // AFTER: Handlers have a single parameter, which is unwrapped to get |
182 // the exception and stack trace. | 180 // the exception and stack trace. |
183 _exceptionParameter = node.handler.parameters.first; | 181 _exceptionParameter = node.handler.parameters.first; |
184 Parameter stackTraceParameter = node.handler.parameters.last; | 182 Parameter stackTraceParameter = node.handler.parameters.last; |
185 Expression body = node.handler.body; | 183 Expression body = node.handler.body; |
186 if (_exceptionParameter.hasAtLeastOneUse || | 184 if (_exceptionParameter.hasAtLeastOneUse || |
187 stackTraceParameter.hasAtLeastOneUse) { | 185 stackTraceParameter.hasAtLeastOneUse) { |
188 Parameter exceptionValue = new Parameter(null); | 186 Parameter exceptionValue = new Parameter(null); |
189 exceptionValue.substituteFor(_exceptionParameter); | 187 exceptionValue.substituteFor(_exceptionParameter); |
190 insertStaticCall(_glue.getExceptionUnwrapper(), [_exceptionParameter], | 188 insertStaticCall(_glue.getExceptionUnwrapper(), [_exceptionParameter], |
191 exceptionValue, body); | 189 exceptionValue, body); |
192 | 190 |
193 if (stackTraceParameter.hasAtLeastOneUse) { | 191 if (stackTraceParameter.hasAtLeastOneUse) { |
194 Parameter stackTraceValue = new Parameter(null); | 192 Parameter stackTraceValue = new Parameter(null); |
195 stackTraceValue.substituteFor(stackTraceParameter); | 193 stackTraceValue.substituteFor(stackTraceParameter); |
196 insertStaticCall(_glue.getTraceFromException(), [_exceptionParameter], | 194 insertStaticCall(_glue.getTraceFromException(), [_exceptionParameter], |
197 stackTraceValue, body); | 195 stackTraceValue, body); |
198 } | 196 } |
199 } | 197 } |
200 | 198 |
201 assert(stackTraceParameter.hasNoUses); | 199 assert(stackTraceParameter.hasNoUses); |
202 node.handler.parameters.removeLast(); | 200 node.handler.parameters.removeLast(); |
203 } | |
204 | 201 |
205 @override | |
206 visitLetHandler(LetHandler node) { | |
207 assert(node.handler.parameters.length == 2); | |
208 Parameter previousExceptionParameter = _exceptionParameter; | |
209 _exceptionParameter = node.handler.parameters.first; | |
210 processLetHandler(node); | |
211 visit(node.handler); | 202 visit(node.handler); |
212 _exceptionParameter = previousExceptionParameter; | 203 _exceptionParameter = previousExceptionParameter; |
213 | 204 |
214 visit(node.body); | 205 return node.body; |
215 } | 206 } |
216 | 207 |
217 processThrow(Throw node) { | 208 processThrow(Throw node) { |
218 // The subexpression of throw is wrapped in the JavaScript output. | 209 // The subexpression of throw is wrapped in the JavaScript output. |
219 Parameter value = new Parameter(null); | 210 Parameter value = new Parameter(null); |
220 insertStaticCall(_glue.getWrapExceptionHelper(), [node.value.definition], | 211 insertStaticCall(_glue.getWrapExceptionHelper(), [node.value.definition], |
221 value, node); | 212 value, node); |
222 node.value.unlink(); | 213 node.value.unlink(); |
223 node.value = new Reference<Primitive>(value); | 214 node.value = new Reference<Primitive>(value); |
224 } | 215 } |
(...skipping 12 matching lines...) Expand all Loading... |
237 /// Returns an interceptor for the given value, capable of responding to | 228 /// Returns an interceptor for the given value, capable of responding to |
238 /// [selector]. | 229 /// [selector]. |
239 /// | 230 /// |
240 /// A single getInterceptor call will be created per primitive, bound | 231 /// A single getInterceptor call will be created per primitive, bound |
241 /// immediately after the primitive is bound. | 232 /// immediately after the primitive is bound. |
242 /// | 233 /// |
243 /// The type propagation pass will later narrow the set of interceptors | 234 /// The type propagation pass will later narrow the set of interceptors |
244 /// based on the input type, and the let sinking pass will propagate the | 235 /// based on the input type, and the let sinking pass will propagate the |
245 /// getInterceptor call closer to its use when this is profitable. | 236 /// getInterceptor call closer to its use when this is profitable. |
246 Interceptor getInterceptorFor(Primitive prim, Selector selector) { | 237 Interceptor getInterceptorFor(Primitive prim, Selector selector) { |
| 238 assert(prim is! Interceptor); |
247 Interceptor interceptor = interceptors[prim]; | 239 Interceptor interceptor = interceptors[prim]; |
248 if (interceptor == null) { | 240 if (interceptor == null) { |
249 interceptor = new Interceptor(prim); | 241 interceptor = new Interceptor(prim); |
250 interceptors[prim] = interceptor; | 242 interceptors[prim] = interceptor; |
251 InteriorNode parent = prim.parent; | 243 InteriorNode parent = prim.parent; |
252 insertLetPrim(interceptor, parent.body); | 244 insertLetPrim(interceptor, parent.body); |
253 if (prim.hint != null) { | 245 if (prim.hint != null) { |
254 interceptor.hint = new InterceptorEntity(prim.hint); | 246 interceptor.hint = new InterceptorEntity(prim.hint); |
255 } | 247 } |
256 } | 248 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 condition.value.unlink(); | 302 condition.value.unlink(); |
311 node.trueContinuation.unlink(); | 303 node.trueContinuation.unlink(); |
312 node.falseContinuation.unlink(); | 304 node.falseContinuation.unlink(); |
313 parent.body = newNode; | 305 parent.body = newNode; |
314 } | 306 } |
315 | 307 |
316 processInterceptor(Interceptor node) { | 308 processInterceptor(Interceptor node) { |
317 _glue.registerSpecializedGetInterceptor(node.interceptedClasses); | 309 _glue.registerSpecializedGetInterceptor(node.interceptedClasses); |
318 } | 310 } |
319 } | 311 } |
OLD | NEW |