Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2283)

Unified Diff: pkg/kernel/lib/transformations/closure/context.dart

Issue 2767773004: Add Vector type to Kernel (Closed)
Patch Set: Reformat comment with Markdown, throw exception in type propagation Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/kernel/lib/text/ast_to_text.dart ('k') | pkg/kernel/lib/transformations/closure/converter.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 358ff730b4e65b4f9c974c1627ca77e8b6bd97ea..6425bb680eae54647dafc85d07e89989cb3d4580 100644
--- a/pkg/kernel/lib/transformations/closure/context.dart
+++ b/pkg/kernel/lib/transformations/closure/context.dart
@@ -6,23 +6,21 @@ library kernel.transformations.closure.context;
import '../../ast.dart'
show
- Arguments,
Class,
Expression,
- IntLiteral,
- MethodInvocation,
- Name,
NullLiteral,
- PropertyGet,
StringLiteral,
Throw,
TreeNode,
VariableDeclaration,
VariableGet,
- VariableSet;
+ VariableSet,
+ VectorCreation,
+ VectorGet,
+ VectorSet,
+ VectorCopy;
-import '../../frontend/accessors.dart'
- show Accessor, IndexAccessor, VariableAccessor;
+import '../../frontend/accessors.dart' show Accessor, VariableAccessor;
import 'converter.dart' show ClosureConverter;
@@ -109,21 +107,24 @@ class LocalContext extends Context {
final ClosureConverter converter;
final Context parent;
final VariableDeclaration self;
- final IntLiteral size;
+ final VectorCreation vectorCreation;
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);
+ LocalContext._internal(
+ this.converter, this.parent, this.self, this.vectorCreation);
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);
+ return new LocalContext._internal(
+ converter,
+ parent,
+ converter.rewriter.contextDeclaration,
+ converter.rewriter.vectorCreation);
}
Expression get expression => accessor.buildSimpleRead();
@@ -131,36 +132,42 @@ class LocalContext extends Context {
Accessor get accessor => new VariableAccessor(self, null, TreeNode.noOffset);
void extend(VariableDeclaration variable, Expression value) {
- Arguments arguments =
- new Arguments(<Expression>[new IntLiteral(variables.length), value]);
- converter.rewriter.insertExtendContext(expression, arguments);
- ++size.value;
+ // Increase index by 1, because the parent occupies item 0, and all other
+ // variables are therefore shifted by 1.
+ VectorSet initializer =
+ new VectorSet(expression, variables.length + 1, value);
+ value.parent = initializer;
+
+ converter.rewriter.insertExtendContext(initializer);
+
+ ++vectorCreation.length;
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, 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, index + 1, value);
}
Context toNestedContext([Accessor accessor]) {
@@ -181,10 +188,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)));
}
}
@@ -209,10 +213,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, index + 1);
}
- context = new PropertyGet(context, new Name('parent'));
+ // Item 0 of a context always points to its parent.
+ context = new VectorGet(context, 0);
}
throw 'Unbound NestedContext.lookup($variable)';
}
@@ -223,11 +229,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, index + 1, value);
}
- context = new PropertyGet(context, new Name('parent'));
+ // Item 0 of a context always points to its parent.
+ context = new VectorGet(context, 0);
}
throw 'Unbound NestedContext.lookup($variable)';
}
« no previous file with comments | « pkg/kernel/lib/text/ast_to_text.dart ('k') | pkg/kernel/lib/transformations/closure/converter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698