Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Side by Side Diff: pkg/compiler/lib/src/cps_ir/cps_fragment.dart

Issue 1458703007: dart2js cps: Refactor CallExpressions into Primitives. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library cps_ir.cps_fragment; 5 library cps_ir.cps_fragment;
6 6
7 import 'cps_ir_nodes.dart'; 7 import 'cps_ir_nodes.dart';
8 import '../constants/values.dart'; 8 import '../constants/values.dart';
9 import '../universe/selector.dart' show Selector; 9 import '../universe/selector.dart' show Selector;
10 import '../types/types.dart' show TypeMask; 10 import '../types/types.dart' show TypeMask;
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 {bool receiverIsNotNull: false}) { 119 {bool receiverIsNotNull: false}) {
120 ApplyBuiltinMethod apply = 120 ApplyBuiltinMethod apply =
121 new ApplyBuiltinMethod(method, receiver, arguments, sourceInformation); 121 new ApplyBuiltinMethod(method, receiver, arguments, sourceInformation);
122 apply.receiverIsNotNull = receiverIsNotNull; 122 apply.receiverIsNotNull = receiverIsNotNull;
123 return letPrim(apply); 123 return letPrim(apply);
124 } 124 }
125 125
126 /// Inserts an invocation. binds its continuation, and returns the 126 /// Inserts an invocation. binds its continuation, and returns the
127 /// continuation parameter (i.e. the return value of the invocation). 127 /// continuation parameter (i.e. the return value of the invocation).
128 /// 128 ///
129 /// The continuation body becomes the new hole. 129 /// The continuation body becomes the new hole.
sra1 2015/11/19 21:41:45 The comment needs rewriting
asgerf 2015/11/20 16:23:53 Done.
130 Parameter invokeMethod(Primitive receiver, 130 Primitive invokeMethod(Primitive receiver,
131 Selector selector, 131 Selector selector,
132 TypeMask mask, 132 TypeMask mask,
133 List<Primitive> arguments) { 133 List<Primitive> arguments) {
134 Continuation cont = new Continuation(<Parameter>[new Parameter(null)]); 134 return letPrim(new InvokeMethod(receiver, selector, mask, arguments,
135 InvokeMethod invoke = 135 sourceInformation));
136 new InvokeMethod(receiver, selector, mask, arguments, cont,
137 sourceInformation);
138 put(new LetCont(cont, invoke));
139 context = cont;
140 return cont.parameters.single;
141 } 136 }
142 137
143 /// Inserts an invocation. binds its continuation, and returns the 138 /// Inserts an invocation. binds its continuation, and returns the
144 /// continuation parameter (i.e. the return value of the invocation). 139 /// continuation parameter (i.e. the return value of the invocation).
145 /// 140 ///
146 /// The continuation body becomes the new hole. 141 /// The continuation body becomes the new hole.
sra1 2015/11/19 21:41:45 rewrite comment
asgerf 2015/11/20 16:23:53 Done.
147 Parameter invokeStatic(FunctionElement target, List<Primitive> arguments) { 142 Primitive invokeStatic(FunctionElement target, List<Primitive> arguments) {
148 Continuation cont = new Continuation(<Parameter>[new Parameter(null)]); 143 return letPrim(new InvokeStatic(target, new Selector.fromElement(target),
149 InvokeStatic invoke = 144 arguments, sourceInformation));
150 new InvokeStatic(target, new Selector.fromElement(target), arguments,
151 cont, sourceInformation);
152 put(new LetCont(cont, invoke));
153 context = cont;
154 return cont.parameters.single;
155 } 145 }
156 146
157 /// Inserts an invocation to a static function that throws an error. 147 /// Inserts an invocation to a static function that throws an error.
158 /// 148 ///
159 /// This closes the fragment; no more nodes may be added. 149 /// This closes the fragment; no more nodes may be added.
160 void invokeStaticThrower(FunctionElement target, List<Primitive> arguments) { 150 void invokeStaticThrower(FunctionElement target, List<Primitive> arguments) {
161 invokeStatic(target, arguments); 151 invokeStatic(target, arguments);
162 put(new Unreachable()); 152 put(new Unreachable());
163 } 153 }
164 154
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 /// // Build the fail branch 236 /// // Build the fail branch
247 /// cps.insideContinuation(fail) 237 /// cps.insideContinuation(fail)
248 /// ..invokeStaticThrower(...); 238 /// ..invokeStaticThrower(...);
249 /// 239 ///
250 /// // Go to the happy branch 240 /// // Go to the happy branch
251 /// cps.invokeContinuation(cont..) 241 /// cps.invokeContinuation(cont..)
252 /// 242 ///
253 Continuation letCont([List<Parameter> parameters]) { 243 Continuation letCont([List<Parameter> parameters]) {
254 if (parameters == null) parameters = <Parameter>[]; 244 if (parameters == null) parameters = <Parameter>[];
255 Continuation cont = new Continuation(parameters); 245 Continuation cont = new Continuation(parameters);
246 bindContinuation(cont);
247 return cont;
248 }
249
250 /// Binds an existing continuation at this position.
251 ///
252 /// The LetCont body becomes the new hole.
253 void bindContinuation(Continuation cont) {
256 LetCont let = new LetCont(cont, null); 254 LetCont let = new LetCont(cont, null);
257 put(let); 255 put(let);
258 context = let; 256 context = let;
259 return cont; 257 }
258
259 /// Inlines [target] at the current position, substituting the provided
260 /// arguments.
261 ///
262 /// Returns a primitive containing the function's return value.
263 ///
264 /// The new hole is the the point after [target] has returned. The fragment
265 /// remains open, even if [target] never returns.
266 ///
267 /// The [target] function is destroyed and should not be reused.
268 Primitive inlineFunction(FunctionDefinition target,
269 List<Primitive> arguments,
270 Primitive thisArgument,
271 {Entity hint}) {
272 if (thisArgument != null) {
273 thisArgument.substituteFor(target.thisParameter);
274 }
275 for (int i = 0; i < arguments.length; ++i) {
276 arguments[i].substituteFor(target.parameters[i]);
277 }
278 Continuation returnCont = target.returnContinuation;
279 bindContinuation(returnCont);
280 put(target.body);
281 Parameter returnValue = returnCont.parameters.single;
282 returnValue.hint = hint;
283 context = returnCont;
284 return returnValue;
260 } 285 }
261 286
262 /// Returns a fragment whose context is the body of the given continuation. 287 /// Returns a fragment whose context is the body of the given continuation.
263 /// 288 ///
264 /// Does not change the state of this CPS fragment. 289 /// Does not change the state of this CPS fragment.
265 /// 290 ///
266 /// Useful for building the body of a continuation created using [letCont]. 291 /// Useful for building the body of a continuation created using [letCont].
267 CpsFragment insideContinuation(Continuation cont) { 292 CpsFragment insideContinuation(Continuation cont) {
268 return new CpsFragment(sourceInformation, cont); 293 return new CpsFragment(sourceInformation, cont);
269 } 294 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 } 340 }
316 } 341 }
317 342
318 /// Removes [node], unlinking all its references and replaces it with [newNode]. 343 /// Removes [node], unlinking all its references and replaces it with [newNode].
319 void destroyAndReplace(Expression node, Expression newNode) { 344 void destroyAndReplace(Expression node, Expression newNode) {
320 InteriorNode parent = node.parent; 345 InteriorNode parent = node.parent;
321 RemovalVisitor.remove(node); 346 RemovalVisitor.remove(node);
322 parent.body = newNode; 347 parent.body = newNode;
323 newNode.parent = parent; 348 newNode.parent = parent;
324 } 349 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698