| OLD | NEW |
| 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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 | 182 |
| 183 /// Continue a loop started by [beginLoop]. | 183 /// Continue a loop started by [beginLoop]. |
| 184 /// | 184 /// |
| 185 /// This closes the fragment; no more nodes may be inserted. | 185 /// This closes the fragment; no more nodes may be inserted. |
| 186 void continueLoop(Continuation cont, [List<Primitive> updatedLoopVariables]) { | 186 void continueLoop(Continuation cont, [List<Primitive> updatedLoopVariables]) { |
| 187 put(new InvokeContinuation(cont, updatedLoopVariables, isRecursive: true)); | 187 put(new InvokeContinuation(cont, updatedLoopVariables, isRecursive: true)); |
| 188 } | 188 } |
| 189 | 189 |
| 190 /// Branch on [condition]. | 190 /// Branch on [condition]. |
| 191 /// | 191 /// |
| 192 /// Returns a new fragment for the 'then' branch, or the 'else' branch |
| 193 /// if [negate] is true. |
| 194 /// |
| 195 /// The other branch becomes the new hole. |
| 196 CpsFragment branch(Primitive condition, |
| 197 {bool negate: false, |
| 198 bool strict: false}) { |
| 199 Continuation trueCont = new Continuation(<Parameter>[]); |
| 200 Continuation falseCont = new Continuation(<Parameter>[]); |
| 201 put(new LetCont.two(trueCont, falseCont, |
| 202 new Branch(condition, trueCont, falseCont, strict: strict))); |
| 203 if (negate) { |
| 204 context = trueCont; |
| 205 return new CpsFragment(sourceInformation, falseCont); |
| 206 } else { |
| 207 context = falseCont; |
| 208 return new CpsFragment(sourceInformation, trueCont); |
| 209 } |
| 210 } |
| 211 |
| 212 /// Branch on [condition]. |
| 213 /// |
| 192 /// Returns a new fragment for the 'then' branch. | 214 /// Returns a new fragment for the 'then' branch. |
| 193 /// | 215 /// |
| 194 /// The 'else' branch becomes the new hole. | 216 /// The 'else' branch becomes the new hole. |
| 195 CpsFragment ifTruthy(Primitive condition) { | 217 CpsFragment ifTruthy(Primitive condition) => branch(condition); |
| 196 Continuation trueCont = new Continuation(<Parameter>[]); | |
| 197 Continuation falseCont = new Continuation(<Parameter>[]); | |
| 198 put(new LetCont.two(trueCont, falseCont, | |
| 199 new Branch.loose(condition, trueCont, falseCont))); | |
| 200 context = falseCont; | |
| 201 return new CpsFragment(sourceInformation, trueCont); | |
| 202 } | |
| 203 | 218 |
| 204 /// Branch on [condition]. | 219 /// Branch on [condition]. |
| 205 /// | 220 /// |
| 206 /// Returns a new fragment for the 'else' branch. | 221 /// Returns a new fragment for the 'else' branch. |
| 207 /// | 222 /// |
| 208 /// The 'then' branch becomes the new hole. | 223 /// The 'then' branch becomes the new hole. |
| 209 CpsFragment ifFalsy(Primitive condition) { | 224 CpsFragment ifFalsy(Primitive condition) => branch(condition, negate: true); |
| 210 Continuation trueCont = new Continuation(<Parameter>[]); | |
| 211 Continuation falseCont = new Continuation(<Parameter>[]); | |
| 212 put(new LetCont.two(trueCont, falseCont, | |
| 213 new Branch.loose(condition, trueCont, falseCont))); | |
| 214 context = trueCont; | |
| 215 return new CpsFragment(sourceInformation, falseCont); | |
| 216 } | |
| 217 | 225 |
| 218 /// Create a new empty continuation and bind it here. | 226 /// Create a new empty continuation and bind it here. |
| 219 /// | 227 /// |
| 220 /// Convenient for making a join point where multiple branches | 228 /// Convenient for making a join point where multiple branches |
| 221 /// meet later. | 229 /// meet later. |
| 222 /// | 230 /// |
| 223 /// The LetCont body becomes the new hole. | 231 /// The LetCont body becomes the new hole. |
| 224 /// | 232 /// |
| 225 /// Example use: | 233 /// Example use: |
| 226 /// | 234 /// |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 while (prim.firstRef != null) { | 365 while (prim.firstRef != null) { |
| 358 Refinement refine = prim.firstRef.parent; | 366 Refinement refine = prim.firstRef.parent; |
| 359 destroyRefinementsOfDeadPrimitive(refine); | 367 destroyRefinementsOfDeadPrimitive(refine); |
| 360 LetPrim letPrim = refine.parent; | 368 LetPrim letPrim = refine.parent; |
| 361 InteriorNode parent = letPrim.parent; | 369 InteriorNode parent = letPrim.parent; |
| 362 parent.body = letPrim.body; | 370 parent.body = letPrim.body; |
| 363 letPrim.body.parent = parent; | 371 letPrim.body.parent = parent; |
| 364 prim.firstRef.unlink(); | 372 prim.firstRef.unlink(); |
| 365 } | 373 } |
| 366 } | 374 } |
| OLD | NEW |