Chromium Code Reviews| 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; |
| 11 import '../io/source_information.dart'; | 11 import '../io/source_information.dart'; |
| 12 import '../elements/elements.dart'; | 12 import '../elements/elements.dart'; |
| 13 import 'cps_fragment.dart'; | |
|
Siggi Cherem (dart-lang)
2016/01/08 23:51:34
remove self import?
asgerf
2016/01/11 19:07:07
I must have been confused when I wrote that
| |
| 13 | 14 |
| 14 /// Builds a CPS fragment that can be plugged into another CPS term. | 15 /// Builds a CPS fragment that can be plugged into another CPS term. |
| 15 /// | 16 /// |
| 16 /// A CPS fragment contains a CPS term, possibly with a "hole" in it denoting | 17 /// A CPS fragment contains a CPS term, possibly with a "hole" in it denoting |
| 17 /// where to insert new IR nodes. We say a fragment is "open" if it has such | 18 /// where to insert new IR nodes. We say a fragment is "open" if it has such |
| 18 /// a hole. Otherwise, the fragment is "closed" and cannot be extended further. | 19 /// a hole. Otherwise, the fragment is "closed" and cannot be extended further. |
| 19 /// | 20 /// |
| 20 /// This class is designed for building non-trivial CPS terms in a readable and | 21 /// This class is designed for building non-trivial CPS terms in a readable and |
| 21 /// non-error prone manner. It is not designed to manipulate existing IR nodes, | 22 /// non-error prone manner. It is not designed to manipulate existing IR nodes, |
| 22 /// nor is it intended to shield the user from every complexity in the IR. | 23 /// nor is it intended to shield the user from every complexity in the IR. |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 | 183 |
| 183 /// Continue a loop started by [beginLoop]. | 184 /// Continue a loop started by [beginLoop]. |
| 184 /// | 185 /// |
| 185 /// This closes the fragment; no more nodes may be inserted. | 186 /// This closes the fragment; no more nodes may be inserted. |
| 186 void continueLoop(Continuation cont, [List<Primitive> updatedLoopVariables]) { | 187 void continueLoop(Continuation cont, [List<Primitive> updatedLoopVariables]) { |
| 187 put(new InvokeContinuation(cont, updatedLoopVariables, isRecursive: true)); | 188 put(new InvokeContinuation(cont, updatedLoopVariables, isRecursive: true)); |
| 188 } | 189 } |
| 189 | 190 |
| 190 /// Branch on [condition]. | 191 /// Branch on [condition]. |
| 191 /// | 192 /// |
| 193 /// Returns a new fragment for the 'then' branch, or the 'else' branch | |
| 194 /// if [negate] is true. | |
| 195 /// | |
| 196 /// The other branch becomes the new hole. | |
| 197 CpsFragment branch(Primitive condition, | |
| 198 {bool negate: false, | |
| 199 bool strict: false}) { | |
| 200 Continuation trueCont = new Continuation(<Parameter>[]); | |
| 201 Continuation falseCont = new Continuation(<Parameter>[]); | |
| 202 put(new LetCont.two(trueCont, falseCont, | |
| 203 new Branch(condition, trueCont, falseCont, strict: strict))); | |
| 204 if (negate) { | |
| 205 context = trueCont; | |
| 206 return new CpsFragment(sourceInformation, falseCont); | |
| 207 } else { | |
| 208 context = falseCont; | |
| 209 return new CpsFragment(sourceInformation, trueCont); | |
| 210 } | |
| 211 } | |
| 212 | |
| 213 /// Branch on [condition]. | |
| 214 /// | |
| 192 /// Returns a new fragment for the 'then' branch. | 215 /// Returns a new fragment for the 'then' branch. |
| 193 /// | 216 /// |
| 194 /// The 'else' branch becomes the new hole. | 217 /// The 'else' branch becomes the new hole. |
| 195 CpsFragment ifTruthy(Primitive condition) { | 218 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 | 219 |
| 204 /// Branch on [condition]. | 220 /// Branch on [condition]. |
| 205 /// | 221 /// |
| 206 /// Returns a new fragment for the 'else' branch. | 222 /// Returns a new fragment for the 'else' branch. |
| 207 /// | 223 /// |
| 208 /// The 'then' branch becomes the new hole. | 224 /// The 'then' branch becomes the new hole. |
| 209 CpsFragment ifFalsy(Primitive condition) { | 225 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 | 226 |
| 218 /// Create a new empty continuation and bind it here. | 227 /// Create a new empty continuation and bind it here. |
| 219 /// | 228 /// |
| 220 /// Convenient for making a join point where multiple branches | 229 /// Convenient for making a join point where multiple branches |
| 221 /// meet later. | 230 /// meet later. |
| 222 /// | 231 /// |
| 223 /// The LetCont body becomes the new hole. | 232 /// The LetCont body becomes the new hole. |
| 224 /// | 233 /// |
| 225 /// Example use: | 234 /// Example use: |
| 226 /// | 235 /// |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 357 while (prim.firstRef != null) { | 366 while (prim.firstRef != null) { |
| 358 Refinement refine = prim.firstRef.parent; | 367 Refinement refine = prim.firstRef.parent; |
| 359 destroyRefinementsOfDeadPrimitive(refine); | 368 destroyRefinementsOfDeadPrimitive(refine); |
| 360 LetPrim letPrim = refine.parent; | 369 LetPrim letPrim = refine.parent; |
| 361 InteriorNode parent = letPrim.parent; | 370 InteriorNode parent = letPrim.parent; |
| 362 parent.body = letPrim.body; | 371 parent.body = letPrim.body; |
| 363 letPrim.body.parent = parent; | 372 letPrim.body.parent = parent; |
| 364 prim.firstRef.unlink(); | 373 prim.firstRef.unlink(); |
| 365 } | 374 } |
| 366 } | 375 } |
| OLD | NEW |