Index: pkg/kernel/lib/ast.dart |
diff --git a/pkg/kernel/lib/ast.dart b/pkg/kernel/lib/ast.dart |
index 9d6d5cdd073424bf9d2999e6e6673af3d96dd8bc..59f177579763c750acf30d8a23074991eb2eea8f 100644 |
--- a/pkg/kernel/lib/ast.dart |
+++ b/pkg/kernel/lib/ast.dart |
@@ -2750,6 +2750,119 @@ class CheckLibraryIsLoaded extends Expression { |
transformChildren(Transformer v) {} |
} |
+/// Expression of the form `MakeVector(N)` where `N` is an integer representing |
+/// the length of the vector. |
+/// |
+/// For detailed comment about Vectors see [VectorType]. |
+class VectorCreation extends Expression { |
+ int length; |
+ |
+ VectorCreation(this.length); |
+ |
+ accept(ExpressionVisitor v) => v.visitVectorCreation(this); |
+ accept1(ExpressionVisitor1 v, arg) => v.visitVectorCreation(this, arg); |
+ |
+ visitChildren(Visitor v) {} |
+ |
+ transformChildren(Transformer v) {} |
+ |
+ DartType getStaticType(TypeEnvironment types) { |
+ return const VectorType(); |
+ } |
+} |
+ |
+/// Expression of the form `v[i]` where `v` is a vector expression, and `i` is |
+/// an integer index. |
+class VectorGet extends Expression { |
+ Expression vectorExpression; |
+ int index; |
+ |
+ VectorGet(this.vectorExpression, this.index) { |
+ vectorExpression?.parent = this; |
+ } |
+ |
+ accept(ExpressionVisitor v) => v.visitVectorGet(this); |
+ accept1(ExpressionVisitor1 v, arg) => v.visitVectorGet(this, arg); |
+ |
+ visitChildren(Visitor v) { |
+ vectorExpression.accept(v); |
+ } |
+ |
+ transformChildren(Transformer v) { |
+ if (vectorExpression != null) { |
+ vectorExpression = vectorExpression.accept(v); |
+ vectorExpression?.parent = this; |
+ } |
+ } |
+ |
+ DartType getStaticType(TypeEnvironment types) { |
+ return const DynamicType(); |
+ } |
+} |
+ |
+/// Expression of the form `v[i] = x` where `v` is a vector expression, `i` is |
+/// an integer index, and `x` is an arbitrary expression. |
+class VectorSet extends Expression { |
+ Expression vectorExpression; |
+ int index; |
+ Expression value; |
+ |
+ VectorSet(this.vectorExpression, this.index, this.value) { |
+ vectorExpression?.parent = this; |
+ value?.parent = this; |
+ } |
+ |
+ accept(ExpressionVisitor v) => v.visitVectorSet(this); |
+ accept1(ExpressionVisitor1 v, arg) => v.visitVectorSet(this, arg); |
+ |
+ visitChildren(Visitor v) { |
+ vectorExpression.accept(v); |
+ value.accept(v); |
+ } |
+ |
+ transformChildren(Transformer v) { |
+ if (vectorExpression != null) { |
+ vectorExpression = vectorExpression.accept(v); |
+ vectorExpression?.parent = this; |
+ } |
+ if (value != null) { |
+ value = value.accept(v); |
+ value?.parent = this; |
+ } |
+ } |
+ |
+ DartType getStaticType(TypeEnvironment types) { |
+ return value.getStaticType(types); |
+ } |
+} |
+ |
+/// Expression of the form `CopyVector(v)` where `v` is a vector expression. |
+class VectorCopy extends Expression { |
+ Expression vectorExpression; |
+ |
+ VectorCopy(this.vectorExpression) { |
+ vectorExpression?.parent = this; |
+ } |
+ |
+ accept(ExpressionVisitor v) => v.visitVectorCopy(this); |
+ accept1(ExpressionVisitor1 v, arg) => v.visitVectorCopy(this, arg); |
+ |
+ visitChildren(Visitor v) { |
+ vectorExpression.accept(v); |
+ } |
+ |
+ transformChildren(Transformer v) { |
+ if (vectorExpression != null) { |
+ vectorExpression = vectorExpression.accept(v); |
+ vectorExpression?.parent = this; |
+ } |
+ } |
+ |
+ DartType getStaticType(TypeEnvironment types) { |
+ return const VectorType(); |
+ } |
+} |
+ |
// ------------------------------------------------------------------------ |
// STATEMENTS |
// ------------------------------------------------------------------------ |
@@ -3652,6 +3765,38 @@ class InterfaceType extends DartType { |
} |
} |
+/// [VectorType] represents Vectors, a special kind of data that is not |
+/// available for use by Dart programmers directly. It is used by Kernel |
+/// transformations as efficient index-based storage. |
+/// |
+/// (1) Vectors aren't user-visible. For example, they are not supposed to |
+/// be exposed to Dart programs through variables or be visible in stack |
+/// traces. |
+/// |
+/// (2) Vectors have fixed length at runtime. The length is known at compile |
+/// time, and [VectorCreation] AST node stores it in a field. |
+/// |
+/// (3) Indexes for accessing and assigning Vector items are known at |
+/// compile time. The corresponding [VectorGet] and [VectorSet] AST nodes |
+/// store the index in a field. |
+/// |
+/// (4) For efficiency considerations, bounds checks aren't performed for |
+/// Vectors. If necessary, a transformer or verifier can do this checks at |
+/// compile-time, after adding length field to [VectorType], to make sure |
+/// that previous transformations didn't introduce any access errors. |
+/// |
+/// (5) Access to Vectors is untyped. |
+/// |
+/// (6) Vectors can be used by various transformations of Kernel programs. |
+/// Currently they are used by Closure Conversion to represent closure |
+/// contexts. |
asgerf
2017/03/27 11:15:39
Great! Please use markdown syntax, though.
Dmitry Stefantsov
2017/03/27 12:17:24
Done.
|
+class VectorType extends DartType { |
+ const VectorType(); |
+ |
+ accept(DartTypeVisitor v) => v.visitVectorType(this); |
+ visitChildren(Visitor v) {} |
+} |
+ |
/// A possibly generic function type. |
class FunctionType extends DartType { |
final List<TypeParameter> typeParameters; |