Index: pkg/kernel/lib/transformations/closure/rewriter.dart |
diff --git a/pkg/kernel/lib/transformations/closure/rewriter.dart b/pkg/kernel/lib/transformations/closure/rewriter.dart |
index 1fb93800b6c7624afae8689596ffb21bb42b58c6..f161b43f41820a2ecb8781747329ee76e4020acc 100644 |
--- a/pkg/kernel/lib/transformations/closure/rewriter.dart |
+++ b/pkg/kernel/lib/transformations/closure/rewriter.dart |
@@ -23,20 +23,20 @@ abstract class AstRewriter { |
/// Inserts an allocation of a context and initializes [contextDeclaration] |
/// and [contextSize]. |
- void insertContextDeclaration(Class contextClass, Expression accessParent); |
+ void insertContextDeclaration(Expression accessParent); |
- /// Inserts an expression or statement that extends the context, where |
- /// [arguments] holds a pair of the new index and the initial value. |
- void insertExtendContext(Expression accessContext, Arguments arguments); |
+ /// Inserts an expression or statement that extends the context. |
+ void insertExtendContext(VectorSet extender); |
- void _createDeclaration(Class contextClass) { |
+ void _createDeclaration() { |
assert(contextDeclaration == null && contextSize == null); |
- contextSize = new IntLiteral(0); |
+ // [contextSize] is set to 1 initially, becauze the 0-th element of it works |
+ // as a link to the parent context. |
+ contextSize = new IntLiteral(1); |
contextDeclaration = new VariableDeclaration.forValue( |
- new ConstructorInvocation(contextClass.constructors.first, |
- new Arguments(<Expression>[contextSize])), |
- type: new InterfaceType(contextClass)); |
+ new VectorCreation(contextSize), |
+ type: new VectorType()); |
contextDeclaration.name = "#context"; |
} |
} |
@@ -72,20 +72,20 @@ class BlockRewriter extends AstRewriter { |
statement.parent = _currentBlock; |
} |
- void insertContextDeclaration(Class contextClass, Expression accessParent) { |
- _createDeclaration(contextClass); |
+ void insertContextDeclaration(Expression accessParent) { |
+ _createDeclaration(); |
_insertStatement(contextDeclaration); |
if (accessParent is! NullLiteral) { |
- _insertStatement(new ExpressionStatement(new PropertySet( |
+ // Index 0 of a context always points to the parent. |
+ _insertStatement(new ExpressionStatement(new VectorSet( |
new VariableGet(contextDeclaration), |
- new Name('parent'), |
+ new IntLiteral(0), |
accessParent))); |
} |
} |
- void insertExtendContext(Expression accessContext, Arguments arguments) { |
- _insertStatement(new ExpressionStatement( |
- new MethodInvocation(accessContext, new Name('[]='), arguments))); |
+ void insertExtendContext(VectorSet extender) { |
+ _insertStatement(new ExpressionStatement(extender)); |
} |
} |
@@ -104,8 +104,8 @@ class InitializerRewriter extends AstRewriter { |
} |
@override |
- void insertContextDeclaration(Class contextClass, Expression accessParent) { |
- _createDeclaration(contextClass); |
+ void insertContextDeclaration(Expression accessParent) { |
+ _createDeclaration(); |
FieldInitializer parent = initializingExpression.parent; |
Let binding = new Let(contextDeclaration, initializingExpression); |
initializingExpression.parent = binding; |
@@ -114,12 +114,9 @@ class InitializerRewriter extends AstRewriter { |
} |
@override |
- void insertExtendContext(Expression accessContext, Arguments arguments) { |
- Expression extendContext = |
- new MethodInvocation(accessContext, new Name('[]='), arguments); |
+ void insertExtendContext(VectorSet extender) { |
Let parent = initializingExpression.parent; |
- Let binding = new Let( |
- new VariableDeclaration(null, initializer: extendContext), |
+ Let binding = new Let(new VariableDeclaration(null, initializer: extender), |
initializingExpression); |
parent.body = binding; |
binding.parent = parent; |