Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 library kernel.interpreter; | 4 library kernel.interpreter; |
| 5 | 5 |
| 6 import '../ast.dart'; | 6 import '../ast.dart'; |
| 7 import '../ast.dart' as ast show Class; | 7 import '../ast.dart' as ast show Class; |
| 8 | 8 |
| 9 import '../log.dart'; | 9 import '../log.dart'; |
| 10 export '../log.dart'; | 10 export '../log.dart'; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 Statement statementBlock = mainMethod.function.body; | 32 Statement statementBlock = mainMethod.function.body; |
| 33 ExecConfiguration configuration = new ExecConfiguration( | 33 ExecConfiguration configuration = new ExecConfiguration( |
| 34 statementBlock, new Environment.empty(), const State.initial()); | 34 statementBlock, new Environment.empty(), const State.initial()); |
| 35 visitor.trampolinedExecution(configuration); | 35 visitor.trampolinedExecution(configuration); |
| 36 } | 36 } |
| 37 } | 37 } |
| 38 | 38 |
| 39 class Location { | 39 class Location { |
| 40 Value value; | 40 Value value; |
| 41 | 41 |
| 42 Location.empty(); | |
| 42 Location(this.value); | 43 Location(this.value); |
| 43 } | 44 } |
| 44 | 45 |
| 45 class Binding { | 46 class Binding { |
| 46 final VariableDeclaration variable; | 47 final VariableDeclaration variable; |
| 47 final Location location; | 48 final Location location; |
| 48 | 49 |
| 49 Binding(this.variable, this.location); | 50 Binding(this.variable, this.location); |
| 50 } | 51 } |
| 51 | 52 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 167 Configuration visitStaticInvocation( | 168 Configuration visitStaticInvocation( |
| 168 StaticInvocation node, EvalConfiguration config) { | 169 StaticInvocation node, EvalConfiguration config) { |
| 169 if ('print' == node.name.toString()) { | 170 if ('print' == node.name.toString()) { |
| 170 var cont = new PrintEK(config.continuation); | 171 var cont = new PrintEK(config.continuation); |
| 171 return new EvalConfiguration( | 172 return new EvalConfiguration( |
| 172 node.arguments.positional.first, config.environment, cont); | 173 node.arguments.positional.first, config.environment, cont); |
| 173 } else { | 174 } else { |
| 174 log.info('static-invocation-${node.target.name.toString()}\n'); | 175 log.info('static-invocation-${node.target.name.toString()}\n'); |
| 175 | 176 |
| 176 List<InterpreterExpression> args = | 177 List<InterpreterExpression> args = |
| 177 _createArgumentExpressionList(node.arguments, node.target.function); | 178 _getArgumentExpressions(node.arguments, node.target.function); |
| 178 ApplicationContinuation cont = | 179 ApplicationContinuation cont = |
| 179 new StaticInvocationA(node.target.function, config.continuation); | 180 new StaticInvocationA(node.target.function, config.continuation); |
| 180 return new EvalListConfiguration(args, config.environment, cont); | 181 return new EvalListConfiguration(args, config.environment, cont); |
| 181 } | 182 } |
| 182 } | 183 } |
| 183 | 184 |
| 184 Configuration visitMethodInvocation( | 185 Configuration visitMethodInvocation( |
| 185 MethodInvocation node, EvalConfiguration config) { | 186 MethodInvocation node, EvalConfiguration config) { |
| 186 // Currently supports only method invocation with <2 arguments and is used | 187 // Currently supports only method invocation with <2 arguments and is used |
| 187 // to evaluate implemented operators for int, double and String values. | 188 // to evaluate implemented operators for int, double and String values. |
| 188 var cont = new MethodInvocationEK( | 189 var cont = new MethodInvocationEK( |
| 189 node.arguments, node.name, config.environment, config.continuation); | 190 node.arguments, node.name, config.environment, config.continuation); |
| 190 | 191 |
| 191 return new EvalConfiguration(node.receiver, config.environment, cont); | 192 return new EvalConfiguration(node.receiver, config.environment, cont); |
| 192 } | 193 } |
| 193 | 194 |
| 194 Configuration visitConstructorInvocation( | 195 Configuration visitConstructorInvocation( |
| 195 ConstructorInvocation node, EvalConfiguration config) => | 196 ConstructorInvocation node, EvalConfiguration config) { |
| 196 defaultExpression(node, config); | 197 ApplicationContinuation cont = |
| 198 new ConstructorInvocationA(node.target, config.continuation); | |
| 199 var args = _getArgumentExpressions(node.arguments, node.target.function); | |
| 200 | |
| 201 return new EvalListConfiguration(args, config.environment, cont); | |
| 202 } | |
| 197 | 203 |
| 198 Configuration visitNot(Not node, EvalConfiguration config) { | 204 Configuration visitNot(Not node, EvalConfiguration config) { |
| 199 return new EvalConfiguration( | 205 return new EvalConfiguration( |
| 200 node.operand, config.environment, new NotEK(config.continuation)); | 206 node.operand, config.environment, new NotEK(config.continuation)); |
| 201 } | 207 } |
| 202 | 208 |
| 203 Configuration visitLogicalExpression( | 209 Configuration visitLogicalExpression( |
| 204 LogicalExpression node, EvalConfiguration config) { | 210 LogicalExpression node, EvalConfiguration config) { |
| 205 if ('||' == node.operator) { | 211 if ('||' == node.operator) { |
| 206 var cont = new OrEK(node.right, config.environment, config.continuation); | 212 var cont = new OrEK(node.right, config.environment, config.continuation); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 222 Configuration visitStringConcatenation( | 228 Configuration visitStringConcatenation( |
| 223 StringConcatenation node, EvalConfiguration config) { | 229 StringConcatenation node, EvalConfiguration config) { |
| 224 var cont = new StringConcatenationA(config.continuation); | 230 var cont = new StringConcatenationA(config.continuation); |
| 225 var expressions = node.expressions | 231 var expressions = node.expressions |
| 226 .map((Expression e) => new PositionalExpression(e)) | 232 .map((Expression e) => new PositionalExpression(e)) |
| 227 .toList(); | 233 .toList(); |
| 228 return new EvalListConfiguration(expressions, config.environment, cont); | 234 return new EvalListConfiguration(expressions, config.environment, cont); |
| 229 } | 235 } |
| 230 | 236 |
| 231 Configuration visitThisExpression( | 237 Configuration visitThisExpression( |
| 232 ThisExpression node, EvalConfiguration config) => | 238 ThisExpression node, EvalConfiguration config) { |
| 233 defaultExpression(node, config); | 239 return new ValuePassingConfiguration( |
| 240 config.continuation, config.environment.thisInstance); | |
| 241 } | |
| 234 | 242 |
| 235 // Evaluation of BasicLiterals. | 243 // Evaluation of BasicLiterals. |
| 236 Configuration visitStringLiteral( | 244 Configuration visitStringLiteral( |
| 237 StringLiteral node, EvalConfiguration config) { | 245 StringLiteral node, EvalConfiguration config) { |
| 238 return new ValuePassingConfiguration( | 246 return new ValuePassingConfiguration( |
| 239 config.continuation, new StringValue(node.value)); | 247 config.continuation, new StringValue(node.value)); |
| 240 } | 248 } |
| 241 | 249 |
| 242 Configuration visitIntLiteral(IntLiteral node, EvalConfiguration config) { | 250 Configuration visitIntLiteral(IntLiteral node, EvalConfiguration config) { |
| 243 return new ValuePassingConfiguration( | 251 return new ValuePassingConfiguration( |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 503 return new ForwardConfiguration(state.continuation, enclosingEnv); | 511 return new ForwardConfiguration(state.continuation, enclosingEnv); |
| 504 } | 512 } |
| 505 // Proceed with the execution statement when there are some remaining to | 513 // Proceed with the execution statement when there are some remaining to |
| 506 // be executed. | 514 // be executed. |
| 507 var cont = new BlockSK(statements.skip(1).toList(), enclosingEnv, state); | 515 var cont = new BlockSK(statements.skip(1).toList(), enclosingEnv, state); |
| 508 return new ExecConfiguration( | 516 return new ExecConfiguration( |
| 509 statements.first, env, state.withContinuation(cont)); | 517 statements.first, env, state.withContinuation(cont)); |
| 510 } | 518 } |
| 511 } | 519 } |
| 512 | 520 |
| 513 class NewSK extends StatementContinuation { | |
| 514 final ExpressionContinuation continuation; | |
| 515 final Location location; | |
| 516 | |
| 517 NewSK(this.continuation, this.location); | |
| 518 | |
| 519 Configuration call(Environment _) => | |
| 520 new ValuePassingConfiguration(continuation, location.value); | |
| 521 } | |
| 522 | |
| 523 class WhileConditionSK extends StatementContinuation { | 521 class WhileConditionSK extends StatementContinuation { |
| 524 final Expression condition; | 522 final Expression condition; |
| 525 final Statement body; | 523 final Statement body; |
| 526 final Environment enclosingEnv; | 524 final Environment enclosingEnv; |
| 527 final State state; | 525 final State state; |
| 528 | 526 |
| 529 WhileConditionSK(this.condition, this.body, this.enclosingEnv, this.state); | 527 WhileConditionSK(this.condition, this.body, this.enclosingEnv, this.state); |
| 530 | 528 |
| 531 Configuration call(Environment _) { | 529 Configuration call(Environment _) { |
| 532 // Evaluate the condition for the while loop execution. | 530 // Evaluate the condition for the while loop execution. |
| 533 var cont = new WhileConditionEK(condition, body, enclosingEnv, state); | 531 var cont = new WhileConditionEK(condition, body, enclosingEnv, state); |
| 534 return new EvalConfiguration(condition, enclosingEnv, cont); | 532 return new EvalConfiguration(condition, enclosingEnv, cont); |
| 535 } | 533 } |
| 536 } | 534 } |
| 537 | 535 |
| 536 /// Applies the expression continuation to the provided value. | |
| 537 class NewSK extends StatementContinuation { | |
| 538 final ExpressionContinuation continuation; | |
| 539 final Value value; | |
| 540 | |
| 541 NewSK(this.continuation, this.value); | |
| 542 | |
| 543 Configuration call(Environment _) => | |
| 544 new ValuePassingConfiguration(continuation, value.value); | |
| 545 } | |
| 546 | |
| 547 class ConstructorBodySK extends StatementContinuation { | |
| 548 final Statement body; | |
| 549 final Environment environment; | |
| 550 // todo: Add component for exception handler. | |
| 551 final StatementContinuation continuation; | |
| 552 | |
| 553 ConstructorBodySK(this.body, this.environment, this.continuation); | |
| 554 | |
| 555 Configuration call(Environment _) { | |
| 556 return new ExecConfiguration( | |
| 557 body, environment, new State(null, null, continuation)); | |
| 558 } | |
| 559 } | |
| 560 | |
| 538 // ------------------------------------------------------------------------ | 561 // ------------------------------------------------------------------------ |
| 539 // Application Continuations | 562 // Application Continuations |
| 540 // ------------------------------------------------------------------------ | 563 // ------------------------------------------------------------------------ |
| 541 | 564 |
| 542 /// Represents the continuation called after the evaluation of argument | 565 /// Represents the continuation called after the evaluation of argument |
| 543 /// expressions. | 566 /// expressions. |
| 544 /// | 567 /// |
| 545 /// There are various kinds of [ApplicationContinuation] and their names are | 568 /// There are various kinds of [ApplicationContinuation] and their names are |
| 546 /// suffixed with "A". | 569 /// suffixed with "A". |
| 547 abstract class ApplicationContinuation extends Continuation { | 570 abstract class ApplicationContinuation extends Continuation { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 618 Configuration call(List<InterpreterValue> argValues) { | 641 Configuration call(List<InterpreterValue> argValues) { |
| 619 Environment functionEnv = | 642 Environment functionEnv = |
| 620 ApplicationContinuation.createEnvironment(function, argValues); | 643 ApplicationContinuation.createEnvironment(function, argValues); |
| 621 State bodyState = new State( | 644 State bodyState = new State( |
| 622 null, continuation, new ExitSK(continuation, Value.nullInstance)); | 645 null, continuation, new ExitSK(continuation, Value.nullInstance)); |
| 623 | 646 |
| 624 return new ExecConfiguration(function.body, functionEnv, bodyState); | 647 return new ExecConfiguration(function.body, functionEnv, bodyState); |
| 625 } | 648 } |
| 626 } | 649 } |
| 627 | 650 |
| 651 /// Represents the application continuation for constructor invocation applied | |
| 652 /// on the list of evaluated arguments when a constructor is invoked with new. | |
| 653 /// | |
| 654 /// It creates the newly allocated object instance. | |
| 655 class ConstructorInvocationA extends ApplicationContinuation { | |
| 656 final Constructor constructor; | |
| 657 final ExpressionContinuation continuation; | |
| 658 | |
| 659 ConstructorInvocationA(this.constructor, this.continuation); | |
| 660 | |
| 661 Configuration call(List<InterpreterValue> argValues) { | |
| 662 Environment ctrEnv = ApplicationContinuation.createEnvironment( | |
| 663 constructor.function, argValues); | |
| 664 | |
| 665 var newObject = new ObjectValue(constructor.enclosingClass); | |
| 666 var cont = new InitializationEK( | |
| 667 constructor, ctrEnv, new NewSK(continuation, newObject)); | |
|
Dmitry Stefantsov
2017/07/25 11:45:07
From the specification I get it that the second ar
zhivkag
2017/07/25 13:17:02
Done.
| |
| 668 | |
| 669 return new ValuePassingConfiguration(cont, newObject); | |
| 670 } | |
| 671 } | |
| 672 | |
| 628 // ------------------------------------------------------------------------ | 673 // ------------------------------------------------------------------------ |
| 629 // Expression Continuations | 674 // Expression Continuations |
| 630 // ------------------------------------------------------------------------ | 675 // ------------------------------------------------------------------------ |
| 631 | 676 |
| 632 /// Represents an expression continuation. | 677 /// Represents an expression continuation. |
| 633 /// | 678 /// |
| 634 /// There are various kinds of [ExpressionContinuation]s and their names are | 679 /// There are various kinds of [ExpressionContinuation]s and their names are |
| 635 /// suffixed with "EK". | 680 /// suffixed with "EK". |
| 636 abstract class ExpressionContinuation extends Continuation { | 681 abstract class ExpressionContinuation extends Continuation { |
| 637 Configuration call(Value v); | 682 Configuration call(Value v); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 662 } | 707 } |
| 663 } | 708 } |
| 664 | 709 |
| 665 class PropertyGetEK extends ExpressionContinuation { | 710 class PropertyGetEK extends ExpressionContinuation { |
| 666 final Name name; | 711 final Name name; |
| 667 final ExpressionContinuation continuation; | 712 final ExpressionContinuation continuation; |
| 668 | 713 |
| 669 PropertyGetEK(this.name, this.continuation); | 714 PropertyGetEK(this.name, this.continuation); |
| 670 | 715 |
| 671 Configuration call(Value receiver) { | 716 Configuration call(Value receiver) { |
| 672 // TODO: CPS the invocation of the getter. | |
| 673 Value propertyValue = receiver.class_.lookupImplicitGetter(name)(receiver); | 717 Value propertyValue = receiver.class_.lookupImplicitGetter(name)(receiver); |
| 674 return new ValuePassingConfiguration(continuation, propertyValue); | 718 return new ValuePassingConfiguration(continuation, propertyValue); |
| 675 } | 719 } |
| 676 } | 720 } |
| 677 | 721 |
| 678 class PropertySetEK extends ExpressionContinuation { | 722 class PropertySetEK extends ExpressionContinuation { |
| 679 final Expression value; | 723 final Expression value; |
| 680 final Name setterName; | 724 final Name setterName; |
| 681 final Environment environment; | 725 final Environment environment; |
| 682 final ExpressionContinuation continuation; | 726 final ExpressionContinuation continuation; |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 884 return new ForwardConfiguration(state.continuation, environment); | 928 return new ForwardConfiguration(state.continuation, environment); |
| 885 } | 929 } |
| 886 } | 930 } |
| 887 | 931 |
| 888 /// Represents the continuation for the initializer expression in | 932 /// Represents the continuation for the initializer expression in |
| 889 /// [VariableDeclaration]. | 933 /// [VariableDeclaration]. |
| 890 class VariableInitializerEK extends ExpressionContinuation { | 934 class VariableInitializerEK extends ExpressionContinuation { |
| 891 final VariableDeclaration variable; | 935 final VariableDeclaration variable; |
| 892 final Environment environment; | 936 final Environment environment; |
| 893 final StatementContinuation continuation; | 937 final StatementContinuation continuation; |
| 894 | |
| 895 VariableInitializerEK(this.variable, this.environment, this.continuation); | 938 VariableInitializerEK(this.variable, this.environment, this.continuation); |
| 896 | 939 |
| 897 Configuration call(Value v) { | 940 Configuration call(Value v) { |
| 898 return new ForwardConfiguration( | 941 return new ForwardConfiguration( |
| 899 continuation, environment.extend(variable, v)); | 942 continuation, environment.extend(variable, v)); |
| 900 } | 943 } |
| 901 } | 944 } |
| 902 | 945 |
| 946 /// Expression continuation that further initializes the newly allocated object | |
| 947 /// instance with running the constructor. | |
| 948 class InitializationEK extends ExpressionContinuation { | |
| 949 final Constructor constructor; | |
| 950 final Environment environment; | |
| 951 // todo: Add components for exception handling support | |
| 952 final StatementContinuation continuation; | |
| 953 | |
| 954 InitializationEK(this.constructor, this.environment, this.continuation); | |
| 955 | |
| 956 Configuration call(Value value) { | |
| 957 if (constructor.enclosingClass.superclass.superclass != null) { | |
| 958 throw 'Support for super constructors in not implemented.'; | |
| 959 } | |
| 960 | |
| 961 if (constructor.initializers.isNotEmpty && | |
| 962 !(constructor.initializers.last is SuperInitializer)) { | |
| 963 throw 'Support for initializer is not implemented.'; | |
| 964 } | |
| 965 | |
| 966 // The statement body is captured by the next statement continuation and | |
| 967 // expressions for field initialization are evaluated. | |
| 968 var ctrEnv = environment.extendWithThis(value); | |
| 969 var bodyCont = | |
| 970 new ConstructorBodySK(constructor.function.body, ctrEnv, continuation); | |
| 971 // todo: Add support for initialization of fields with initializers. | |
| 972 return new ForwardConfiguration(bodyCont, ctrEnv); | |
|
Dmitry Stefantsov
2017/07/25 11:45:07
Shouldn't we initialize fields first?
zhivkag
2017/07/25 13:17:02
Indeed, we should initialize the fields first (hen
Dmitry Stefantsov
2017/07/25 13:21:09
No, another CL is fine.
As a side note, it would
zhivkag
2017/07/25 15:23:54
That's a good point, I have updated the TODOs in t
| |
| 973 } | |
| 974 } | |
| 975 | |
| 903 /// Executes statements. | 976 /// Executes statements. |
| 904 /// | 977 /// |
| 905 /// Execution of a statement completes in one of the following ways: | 978 /// Execution of a statement completes in one of the following ways: |
| 906 /// - It completes normally, in which case the execution proceeds to applying | 979 /// - It completes normally, in which case the execution proceeds to applying |
| 907 /// the next continuation. | 980 /// the next continuation. |
| 908 /// - It breaks with a label, in which case the corresponding continuation is | 981 /// - It breaks with a label, in which case the corresponding continuation is |
| 909 /// returned and applied. | 982 /// returned and applied. |
| 910 /// - It returns with or without value, in which case the return continuation is | 983 /// - It returns with or without value, in which case the return continuation is |
| 911 /// returned and applied accordingly. | 984 /// returned and applied accordingly. |
| 912 /// - It throws, in which case the handler is returned and applied accordingly. | 985 /// - It throws, in which case the handler is returned and applied accordingly. |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1088 if (f.isStatic) continue; | 1161 if (f.isStatic) continue; |
| 1089 assert(f.hasImplicitGetter); | 1162 assert(f.hasImplicitGetter); |
| 1090 | 1163 |
| 1091 int currentFieldIndex = implicitGetters.length; | 1164 int currentFieldIndex = implicitGetters.length; |
| 1092 // Shadowing an inherited getter with the same name. | 1165 // Shadowing an inherited getter with the same name. |
| 1093 implicitGetters[f.name] = | 1166 implicitGetters[f.name] = |
| 1094 (Value receiver) => receiver.fields[currentFieldIndex].value; | 1167 (Value receiver) => receiver.fields[currentFieldIndex].value; |
| 1095 if (f.hasImplicitSetter) { | 1168 if (f.hasImplicitSetter) { |
| 1096 // Shadowing an inherited setter with the same name. | 1169 // Shadowing an inherited setter with the same name. |
| 1097 implicitSetters[f.name] = (Value receiver, Value value) => | 1170 implicitSetters[f.name] = (Value receiver, Value value) => |
| 1098 receiver.fields[currentFieldIndex] = new Location(value); | 1171 receiver.fields[currentFieldIndex].value = value; |
| 1099 } | 1172 } |
| 1100 } | 1173 } |
| 1101 } | 1174 } |
| 1102 | 1175 |
| 1103 /// Populates instance methods, getters and setters for the current class and | 1176 /// Populates instance methods, getters and setters for the current class and |
| 1104 /// its super class recursively. | 1177 /// its super class recursively. |
| 1105 _populateInstanceMethods(ast.Class class_) { | 1178 _populateInstanceMethods(ast.Class class_) { |
| 1106 if (class_.superclass != null) { | 1179 if (class_.superclass != null) { |
| 1107 _populateInstanceMethods(class_.superclass); | 1180 _populateInstanceMethods(class_.superclass); |
| 1108 } | 1181 } |
| 1109 | 1182 |
| 1110 for (Procedure p in class_.members) { | 1183 for (Member m in class_.members) { |
| 1111 if (p.isStatic) continue; | 1184 if (m is Procedure) { |
| 1112 // Shadowing an inherited method, getter or setter with the same name. | 1185 // Shadowing an inherited method, getter or setter with the same name. |
| 1113 methods[p.name] = p; | 1186 methods[m.name] = m; |
| 1187 } | |
| 1114 } | 1188 } |
| 1115 } | 1189 } |
| 1116 } | 1190 } |
| 1117 | 1191 |
| 1118 abstract class Value { | 1192 abstract class Value { |
| 1119 Class get class_; | 1193 Class get class_; |
| 1120 List<Location> get fields; | 1194 List<Location> get fields; |
| 1121 Object get value; | 1195 Object get value; |
| 1122 | 1196 |
| 1123 static final NullValue nullInstance = const NullValue(); | 1197 static final NullValue nullInstance = const NullValue(); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1135 BoolValue equals(Value other) => | 1209 BoolValue equals(Value other) => |
| 1136 value == other?.value ? Value.trueInstance : Value.falseInstance; | 1210 value == other?.value ? Value.trueInstance : Value.falseInstance; |
| 1137 | 1211 |
| 1138 Value invokeMethod(Name name, [Value arg]) { | 1212 Value invokeMethod(Name name, [Value arg]) { |
| 1139 if (name.toString() == "==") return equals(arg); | 1213 if (name.toString() == "==") return equals(arg); |
| 1140 throw notImplemented(obj: name); | 1214 throw notImplemented(obj: name); |
| 1141 } | 1215 } |
| 1142 } | 1216 } |
| 1143 | 1217 |
| 1144 class ObjectValue extends Value { | 1218 class ObjectValue extends Value { |
| 1145 Class class_; | 1219 final Class class_; |
| 1146 List<Location> fields; | 1220 final List<Location> fields; |
| 1147 Object get value => this; | 1221 Object get value => this; |
| 1148 | 1222 |
| 1149 ObjectValue(this.class_, this.fields); | 1223 ObjectValue(ast.Class classDeclaration) |
| 1224 : class_ = new Class(classDeclaration.reference), | |
| 1225 fields = new List<Location>(classDeclaration.fields.length) { | |
| 1226 for (int i = 0; i < fields.length; i++) { | |
| 1227 // Create fresh locations for each field. | |
| 1228 fields[i] = new Location.empty(); | |
| 1229 } | |
| 1230 } | |
| 1150 } | 1231 } |
| 1151 | 1232 |
| 1152 abstract class LiteralValue extends Value { | 1233 abstract class LiteralValue extends Value { |
| 1153 Class get class_ => | 1234 Class get class_ => |
| 1154 notImplemented(m: "Loading class for literal is not implemented."); | 1235 notImplemented(m: "Loading class for literal is not implemented."); |
| 1155 List<Location> get fields => | 1236 List<Location> get fields => |
| 1156 notImplemented(m: "Literal value does not have fields"); | 1237 notImplemented(m: "Literal value does not have fields"); |
| 1157 | 1238 |
| 1158 const LiteralValue(); | 1239 const LiteralValue(); |
| 1159 } | 1240 } |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1245 const NullValue(); | 1326 const NullValue(); |
| 1246 } | 1327 } |
| 1247 | 1328 |
| 1248 notImplemented({String m, Object obj}) { | 1329 notImplemented({String m, Object obj}) { |
| 1249 throw new NotImplemented(m ?? 'Evaluation for $obj is not implemented'); | 1330 throw new NotImplemented(m ?? 'Evaluation for $obj is not implemented'); |
| 1250 } | 1331 } |
| 1251 | 1332 |
| 1252 // ------------------------------------------------------------------------ | 1333 // ------------------------------------------------------------------------ |
| 1253 // INTERNAL FUNCTIONS | 1334 // INTERNAL FUNCTIONS |
| 1254 // ------------------------------------------------------------------------ | 1335 // ------------------------------------------------------------------------ |
| 1336 | |
| 1255 /// Creates a list of all argument expressions to be evaluated for the | 1337 /// Creates a list of all argument expressions to be evaluated for the |
| 1256 /// invocation of the provided [FunctionNode] containing the actual arguments | 1338 /// invocation of the provided [FunctionNode] containing the actual arguments |
| 1257 /// and the optional argument initializers. | 1339 /// and the optional argument initializers. |
| 1258 List<InterpreterExpression> _createArgumentExpressionList( | 1340 List<InterpreterExpression> _getArgumentExpressions( |
| 1259 Arguments providedArgs, FunctionNode fun) { | 1341 Arguments providedArgs, FunctionNode fun) { |
| 1260 List<InterpreterExpression> args = <InterpreterExpression>[]; | 1342 List<InterpreterExpression> args = <InterpreterExpression>[]; |
| 1261 // Add positional arguments expressions. | 1343 // Add positional arguments expressions. |
| 1262 args.addAll(providedArgs.positional | 1344 args.addAll(providedArgs.positional |
| 1263 .map((Expression e) => new PositionalExpression(e))); | 1345 .map((Expression e) => new PositionalExpression(e))); |
| 1264 | 1346 |
| 1265 // Add optional positional argument initializers. | 1347 // Add optional positional argument initializers. |
| 1266 for (int i = providedArgs.positional.length; | 1348 for (int i = providedArgs.positional.length; |
| 1267 i < fun.positionalParameters.length; | 1349 i < fun.positionalParameters.length; |
| 1268 i++) { | 1350 i++) { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1280 var current = providedArgs.named[i]; | 1362 var current = providedArgs.named[i]; |
| 1281 args.add(new NamedExpression(current.name, current.value)); | 1363 args.add(new NamedExpression(current.name, current.value)); |
| 1282 namedFormals.remove(current.name); | 1364 namedFormals.remove(current.name); |
| 1283 } | 1365 } |
| 1284 | 1366 |
| 1285 // Add missing optional named initializers. | 1367 // Add missing optional named initializers. |
| 1286 args.addAll(namedFormals.values); | 1368 args.addAll(namedFormals.values); |
| 1287 | 1369 |
| 1288 return args; | 1370 return args; |
| 1289 } | 1371 } |
| OLD | NEW |