Index: pkg/compiler/lib/src/cps_ir/cps_fragment.dart |
diff --git a/pkg/compiler/lib/src/cps_ir/cps_fragment.dart b/pkg/compiler/lib/src/cps_ir/cps_fragment.dart |
index 1b92edc489bef36a9aacd5851442f493a5dd5873..6eda70742528e37e653693eee459ff277fda8980 100644 |
--- a/pkg/compiler/lib/src/cps_ir/cps_fragment.dart |
+++ b/pkg/compiler/lib/src/cps_ir/cps_fragment.dart |
@@ -60,10 +60,15 @@ class CpsFragment { |
CpsFragment([this.sourceInformation, this.context]); |
- /// Asserts that the fragment is closed and returns the IR that was built. |
+ bool get isOpen => root == null || context != null; |
+ bool get isClosed => !isOpen; |
+ bool get isEmpty => root == null; |
+ |
+ /// Asserts that the fragment is non-empty and closed and returns the IR that |
+ /// was built. |
Expression get result { |
- assert(context == null); |
- assert(root != null); |
+ assert(!isEmpty); |
+ assert(isClosed); |
return root; |
} |
@@ -99,6 +104,8 @@ class CpsFragment { |
Primitive makeZero() => makeConstant(new IntConstantValue(0)); |
Primitive makeOne() => makeConstant(new IntConstantValue(1)); |
Primitive makeNull() => makeConstant(new NullConstantValue()); |
+ Primitive makeTrue() => makeConstant(new TrueConstantValue()); |
+ Primitive makeFalse() => makeConstant(new FalseConstantValue()); |
/// Invoke a built-in operator. |
Primitive applyBuiltin(BuiltinOperator op, List<Primitive> args) { |
@@ -263,4 +270,23 @@ class CpsFragment { |
other.context = null; |
other.root = null; |
} |
+ |
+ /// Reads the value of the given mutable variable. |
+ Primitive getMutable(MutableVariable variable) { |
+ return letPrim(new GetMutableVariable(variable)); |
+ } |
+ |
+ /// Sets the value of the given mutable variable. |
+ void setMutable(MutableVariable variable, Primitive value) { |
+ SetMutableVariable setter = new SetMutableVariable(variable, value); |
+ put(setter); |
+ context = setter; |
+ } |
+ |
+ /// Declare a new mutable variable. |
+ void letMutable(MutableVariable variable, Primitive initialValue) { |
+ LetMutable let = new LetMutable(variable, initialValue); |
+ put(let); |
+ context = let; |
+ } |
} |