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/universe.dart' show Selector; | 9 import '../universe/universe.dart' show Selector; |
10 import '../types/types.dart' show TypeMask; | 10 import '../types/types.dart' show TypeMask; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
53 Expression root; | 53 Expression root; |
54 | 54 |
55 /// Node whose body is the hole in this CPS fragment. May be null. | 55 /// Node whose body is the hole in this CPS fragment. May be null. |
56 InteriorNode context; | 56 InteriorNode context; |
57 | 57 |
58 /// Source information to attach to every IR node created in the fragment. | 58 /// Source information to attach to every IR node created in the fragment. |
59 SourceInformation sourceInformation; | 59 SourceInformation sourceInformation; |
60 | 60 |
61 CpsFragment([this.sourceInformation, this.context]); | 61 CpsFragment([this.sourceInformation, this.context]); |
62 | 62 |
63 /// Asserts that the fragment is closed and returns the IR that was built. | 63 bool get isOpen => root == null || context != null; |
64 bool get isClosed => !isOpen; | |
65 bool get isEmpty => root == null; | |
66 | |
67 /// Asserts that the fragment is non-empty and closed and returns the IR that | |
68 /// was built. | |
64 Expression get result { | 69 Expression get result { |
65 assert(context == null); | 70 assert(!isEmpty); |
66 assert(root != null); | 71 assert(isClosed); |
67 return root; | 72 return root; |
68 } | 73 } |
69 | 74 |
70 /// Put the given expression into the fragment's hole. | 75 /// Put the given expression into the fragment's hole. |
71 /// | 76 /// |
72 /// Afterwards the fragment is closed and cannot be extended until a new | 77 /// Afterwards the fragment is closed and cannot be extended until a new |
73 /// [context] is set. | 78 /// [context] is set. |
74 void put(Expression node) { | 79 void put(Expression node) { |
75 assert(root == null || context != null); // We must put the node somewhere. | 80 assert(root == null || context != null); // We must put the node somewhere. |
76 if (root == null) { | 81 if (root == null) { |
(...skipping 15 matching lines...) Expand all Loading... | |
92 } | 97 } |
93 | 98 |
94 /// Bind a constant value. | 99 /// Bind a constant value. |
95 Primitive makeConstant(ConstantValue constant) { | 100 Primitive makeConstant(ConstantValue constant) { |
96 return letPrim(new Constant(constant)); | 101 return letPrim(new Constant(constant)); |
97 } | 102 } |
98 | 103 |
99 Primitive makeZero() => makeConstant(new IntConstantValue(0)); | 104 Primitive makeZero() => makeConstant(new IntConstantValue(0)); |
100 Primitive makeOne() => makeConstant(new IntConstantValue(1)); | 105 Primitive makeOne() => makeConstant(new IntConstantValue(1)); |
101 Primitive makeNull() => makeConstant(new NullConstantValue()); | 106 Primitive makeNull() => makeConstant(new NullConstantValue()); |
107 Primitive makeTrue() => makeConstant(new TrueConstantValue()); | |
108 Primitive makeFalse() => makeConstant(new FalseConstantValue()); | |
102 | 109 |
103 /// Invoke a built-in operator. | 110 /// Invoke a built-in operator. |
104 Primitive applyBuiltin(BuiltinOperator op, List<Primitive> args) { | 111 Primitive applyBuiltin(BuiltinOperator op, List<Primitive> args) { |
105 return letPrim(new ApplyBuiltinOperator(op, args)); | 112 return letPrim(new ApplyBuiltinOperator(op, args)); |
106 } | 113 } |
107 | 114 |
108 /// Inserts an invocation. binds its continuation, and returns the | 115 /// Inserts an invocation. binds its continuation, and returns the |
109 /// continuation parameter (i.e. the return value of the invocation). | 116 /// continuation parameter (i.e. the return value of the invocation). |
110 /// | 117 /// |
111 /// The continuation body becomes the new hole. | 118 /// The continuation body becomes the new hole. |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
256 /// in this fragment. | 263 /// in this fragment. |
257 /// | 264 /// |
258 /// [other] is reset to an empty fragment after this. | 265 /// [other] is reset to an empty fragment after this. |
259 void append(CpsFragment other) { | 266 void append(CpsFragment other) { |
260 if (other.root == null) return; | 267 if (other.root == null) return; |
261 put(other.root); | 268 put(other.root); |
262 context = other.context; | 269 context = other.context; |
263 other.context = null; | 270 other.context = null; |
264 other.root = null; | 271 other.root = null; |
265 } | 272 } |
273 | |
274 Primitive getMutable(MutableVariable variable) { | |
floitsch
2015/07/08 18:45:50
add dartdocs (here and for the other methods).
asgerf
2015/07/09 10:22:40
Done.
| |
275 return letPrim(new GetMutableVariable(variable)); | |
276 } | |
277 | |
278 void setMutable(MutableVariable variable, Primitive value) { | |
279 SetMutableVariable setter = new SetMutableVariable(variable, value); | |
280 put(setter); | |
281 context = setter; | |
282 } | |
283 | |
284 void letMutable(MutableVariable variable, Primitive initialValue) { | |
285 LetMutable let = new LetMutable(variable, initialValue); | |
286 put(let); | |
287 context = let; | |
288 } | |
266 } | 289 } |
OLD | NEW |