Index: pkg/kernel/lib/transformations/closure/context.dart |
diff --git a/pkg/kernel/lib/transformations/closure/context.dart b/pkg/kernel/lib/transformations/closure/context.dart |
index 904ac560785ce95a3acfac424f2cb5aa8130259e..de5204f3c06c11f96949c030539b0bc9c8e70282 100644 |
--- a/pkg/kernel/lib/transformations/closure/context.dart |
+++ b/pkg/kernel/lib/transformations/closure/context.dart |
@@ -18,10 +18,12 @@ import '../../ast.dart' |
Throw, |
VariableDeclaration, |
VariableGet, |
- VariableSet; |
+ VariableSet, |
+ VectorGet, |
+ VectorSet, |
+ VectorCopy; |
-import '../../frontend/accessors.dart' |
- show Accessor, IndexAccessor, VariableAccessor; |
+import '../../frontend/accessors.dart' show Accessor, VariableAccessor; |
import 'converter.dart' show ClosureConverter; |
@@ -110,16 +112,15 @@ class LocalContext extends Context { |
final VariableDeclaration self; |
final IntLiteral size; |
final List<VariableDeclaration> variables = <VariableDeclaration>[]; |
- final Map<VariableDeclaration, Arguments> initializers = |
- <VariableDeclaration, Arguments>{}; |
+ final Map<VariableDeclaration, VectorSet> initializers = |
+ <VariableDeclaration, VectorSet>{}; |
LocalContext._internal(this.converter, this.parent, this.self, this.size); |
factory LocalContext(ClosureConverter converter, Context parent) { |
Class contextClass = converter.contextClass; |
assert(contextClass.constructors.length == 1); |
- converter.rewriter |
- .insertContextDeclaration(contextClass, parent.expression); |
+ converter.rewriter.insertContextDeclaration(parent.expression); |
return new LocalContext._internal(converter, parent, |
converter.rewriter.contextDeclaration, converter.rewriter.contextSize); |
@@ -130,36 +131,42 @@ class LocalContext extends Context { |
Accessor get accessor => new VariableAccessor(self); |
void extend(VariableDeclaration variable, Expression value) { |
- Arguments arguments = |
- new Arguments(<Expression>[new IntLiteral(variables.length), value]); |
- converter.rewriter.insertExtendContext(expression, arguments); |
+ // Increase index by 1, because the parent occupies item 0, and all other |
+ // variables are therefore shifted by 1. |
+ IntLiteral index = new IntLiteral(variables.length + 1); |
+ VectorSet initializer = new VectorSet(expression, index, value); |
+ index.parent = initializer; |
+ value.parent = initializer; |
+ |
+ converter.rewriter.insertExtendContext(initializer); |
++size.value; |
variables.add(variable); |
- initializers[variable] = arguments; |
+ initializers[variable] = initializer; |
} |
void update(VariableDeclaration variable, Expression value) { |
- Arguments arguments = initializers[variable]; |
- arguments.positional[1] = value; |
- value.parent = arguments; |
+ VectorSet initializer = initializers[variable]; |
+ initializer.value = value; |
+ value.parent = initializer; |
} |
Expression lookup(VariableDeclaration variable) { |
var index = variables.indexOf(variable); |
+ // Increase index by 1 in case of success, because the parent occupies |
+ // item 0, and all other variables are therefore shifted by 1. |
return index == -1 |
? parent.lookup(variable) |
- : new MethodInvocation(expression, new Name('[]'), |
- new Arguments(<Expression>[new IntLiteral(index)])); |
+ : new VectorGet(expression, new IntLiteral(index + 1)); |
} |
Expression assign(VariableDeclaration variable, Expression value, |
{bool voidContext: false}) { |
var index = variables.indexOf(variable); |
+ // Increase index by 1 in case of success, because the parent occupies |
+ // item 0, and all other variables are therefore shifted by 1. |
return index == -1 |
? parent.assign(variable, value, voidContext: voidContext) |
- : IndexAccessor |
- .make(expression, new IntLiteral(index), null, null) |
- .buildAssignment(value, voidContext: voidContext); |
+ : new VectorSet(expression, new IntLiteral(index + 1), value); |
} |
Context toNestedContext([Accessor accessor]) { |
@@ -180,10 +187,7 @@ class LocalContext extends Context { |
Expression clone() { |
self.isFinal = false; |
- return new VariableSet( |
- self, |
- new MethodInvocation( |
- new VariableGet(self), new Name("copy"), new Arguments.empty())); |
+ return new VariableSet(self, new VectorCopy(new VariableGet(self))); |
} |
} |
@@ -208,10 +212,12 @@ class NestedContext extends Context { |
for (var variables in variabless) { |
var index = variables.indexOf(variable); |
if (index != -1) { |
- return new MethodInvocation(context, new Name('[]'), |
- new Arguments(<Expression>[new IntLiteral(index)])); |
+ // Increase index by 1, because the parent occupies item 0, and all |
+ // other variables are therefore shifted by 1. |
+ return new VectorGet(context, new IntLiteral(index + 1)); |
} |
- context = new PropertyGet(context, new Name('parent')); |
+ // Item 0 of a context always points to its parent. |
+ context = new VectorGet(context, new IntLiteral(0)); |
} |
throw 'Unbound NestedContext.lookup($variable)'; |
} |
@@ -222,11 +228,12 @@ class NestedContext extends Context { |
for (List<VariableDeclaration> variables in variabless) { |
var index = variables.indexOf(variable); |
if (index != -1) { |
- return IndexAccessor |
- .make(context, new IntLiteral(index), null, null) |
- .buildAssignment(value, voidContext: voidContext); |
+ // Increase index by 1, because the parent occupies item 0, and all |
+ // other variables are therefore shifted by 1. |
+ return new VectorSet(context, new IntLiteral(index + 1), value); |
} |
- context = new PropertyGet(context, new Name('parent')); |
+ // Item 0 of a context always points to its parent. |
+ context = new VectorGet(context, new IntLiteral(0)); |
} |
throw 'Unbound NestedContext.lookup($variable)'; |
} |