OLD | NEW |
1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dartino 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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
4 | 4 |
5 library fletchc.constructor_codegen; | 5 library dartino_compiler.constructor_codegen; |
6 | 6 |
7 import 'package:compiler/src/elements/elements.dart'; | 7 import 'package:compiler/src/elements/elements.dart'; |
8 import 'package:compiler/src/resolution/tree_elements.dart' show | 8 import 'package:compiler/src/resolution/tree_elements.dart' show |
9 TreeElements; | 9 TreeElements; |
10 import 'package:compiler/src/tree/tree.dart'; | 10 import 'package:compiler/src/tree/tree.dart'; |
11 import 'package:compiler/src/universe/call_structure.dart' show | 11 import 'package:compiler/src/universe/call_structure.dart' show |
12 CallStructure; | 12 CallStructure; |
13 import 'package:compiler/src/dart_types.dart'; | 13 import 'package:compiler/src/dart_types.dart'; |
14 | 14 |
15 import 'fletch_context.dart'; | 15 import 'dartino_context.dart'; |
16 | 16 |
17 import 'fletch_function_builder.dart' show | 17 import 'dartino_function_builder.dart' show |
18 FletchFunctionBuilder; | 18 DartinoFunctionBuilder; |
19 | 19 |
20 import 'fletch_class_builder.dart' show | 20 import 'dartino_class_builder.dart' show |
21 FletchClassBuilder; | 21 DartinoClassBuilder; |
22 | 22 |
23 import 'closure_environment.dart'; | 23 import 'closure_environment.dart'; |
24 | 24 |
25 import 'lazy_field_initializer_codegen.dart'; | 25 import 'lazy_field_initializer_codegen.dart'; |
26 | 26 |
27 import 'codegen_visitor.dart'; | 27 import 'codegen_visitor.dart'; |
28 | 28 |
29 import 'fletch_registry.dart' show | 29 import 'dartino_registry.dart' show |
30 FletchRegistry; | 30 DartinoRegistry; |
31 | 31 |
32 class ConstructorCodegen extends CodegenVisitor with FletchRegistryMixin { | 32 class ConstructorCodegen extends CodegenVisitor with DartinoRegistryMixin { |
33 final FletchRegistry registry; | 33 final DartinoRegistry registry; |
34 | 34 |
35 final FletchClassBuilder classBuilder; | 35 final DartinoClassBuilder classBuilder; |
36 | 36 |
37 final Map<FieldElement, LocalValue> fieldScope = <FieldElement, LocalValue>{}; | 37 final Map<FieldElement, LocalValue> fieldScope = <FieldElement, LocalValue>{}; |
38 | 38 |
39 final List<ConstructorElement> constructors = <ConstructorElement>[]; | 39 final List<ConstructorElement> constructors = <ConstructorElement>[]; |
40 | 40 |
41 ClosureEnvironment initializerClosureEnvironment; | 41 ClosureEnvironment initializerClosureEnvironment; |
42 | 42 |
43 ConstructorCodegen(FletchFunctionBuilder functionBuilder, | 43 ConstructorCodegen(DartinoFunctionBuilder functionBuilder, |
44 FletchContext context, | 44 DartinoContext context, |
45 TreeElements elements, | 45 TreeElements elements, |
46 this.registry, | 46 this.registry, |
47 ClosureEnvironment closureEnvironment, | 47 ClosureEnvironment closureEnvironment, |
48 ConstructorElement constructor, | 48 ConstructorElement constructor, |
49 this.classBuilder) | 49 this.classBuilder) |
50 : super(functionBuilder, context, elements, | 50 : super(functionBuilder, context, elements, |
51 closureEnvironment, constructor); | 51 closureEnvironment, constructor); |
52 | 52 |
53 ConstructorElement get constructor => element; | 53 ConstructorElement get constructor => element; |
54 | 54 |
(...skipping 18 matching lines...) Expand all Loading... |
73 int parameterCount = signature.parameterCount; | 73 int parameterCount = signature.parameterCount; |
74 | 74 |
75 // Visit constructor and evaluate initializers and super calls. The | 75 // Visit constructor and evaluate initializers and super calls. The |
76 // arguments to the constructor are located before the return address. | 76 // arguments to the constructor are located before the return address. |
77 inlineInitializers(constructor, -parameterCount - 1); | 77 inlineInitializers(constructor, -parameterCount - 1); |
78 | 78 |
79 handleAllocationAndBodyCall(); | 79 handleAllocationAndBodyCall(); |
80 } | 80 } |
81 | 81 |
82 LazyFieldInitializerCodegen lazyFieldInitializerCodegenFor( | 82 LazyFieldInitializerCodegen lazyFieldInitializerCodegenFor( |
83 FletchFunctionBuilder function, | 83 DartinoFunctionBuilder function, |
84 FieldElement field) { | 84 FieldElement field) { |
85 TreeElements elements = field.resolvedAst.elements; | 85 TreeElements elements = field.resolvedAst.elements; |
86 return new LazyFieldInitializerCodegen( | 86 return new LazyFieldInitializerCodegen( |
87 function, | 87 function, |
88 context, | 88 context, |
89 elements, | 89 elements, |
90 registry, | 90 registry, |
91 context.backend.createClosureEnvironment(field, elements), | 91 context.backend.createClosureEnvironment(field, elements), |
92 field); | 92 field); |
93 } | 93 } |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 // Boxed parameters are passed as boxed objects, not as the values | 340 // Boxed parameters are passed as boxed objects, not as the values |
341 // contained within like we do for ordinary invokes | 341 // contained within like we do for ordinary invokes |
342 scope[parameter].loadRaw(assembler); | 342 scope[parameter].loadRaw(assembler); |
343 }); | 343 }); |
344 | 344 |
345 assembler | 345 assembler |
346 ..invokeStatic(constructorId, 1 + signature.parameterCount) | 346 ..invokeStatic(constructorId, 1 + signature.parameterCount) |
347 ..pop(); | 347 ..pop(); |
348 } | 348 } |
349 | 349 |
350 void pushInitialFieldValues(FletchClassBuilder classBuilder) { | 350 void pushInitialFieldValues(DartinoClassBuilder classBuilder) { |
351 if (classBuilder.hasSuperClass) { | 351 if (classBuilder.hasSuperClass) { |
352 pushInitialFieldValues(classBuilder.superclass); | 352 pushInitialFieldValues(classBuilder.superclass); |
353 } | 353 } |
354 int fieldIndex = classBuilder.superclassFields; | 354 int fieldIndex = classBuilder.superclassFields; |
355 ClassElement classElement = classBuilder.element.implementation; | 355 ClassElement classElement = classBuilder.element.implementation; |
356 classElement.forEachInstanceField((_, FieldElement field) { | 356 classElement.forEachInstanceField((_, FieldElement field) { |
357 fieldScope[field] = new UnboxedLocalValue(fieldIndex++, field); | 357 fieldScope[field] = new UnboxedLocalValue(fieldIndex++, field); |
358 Expression initializer = field.initializer; | 358 Expression initializer = field.initializer; |
359 if (initializer == null) { | 359 if (initializer == null) { |
360 assembler.loadLiteralNull(); | 360 assembler.loadLiteralNull(); |
361 } else { | 361 } else { |
362 // Create a LazyFieldInitializerCodegen for compiling the initializer. | 362 // Create a LazyFieldInitializerCodegen for compiling the initializer. |
363 // Note that we reuse the functionBuilder, to inline it into the | 363 // Note that we reuse the functionBuilder, to inline it into the |
364 // constructor. | 364 // constructor. |
365 LazyFieldInitializerCodegen codegen = | 365 LazyFieldInitializerCodegen codegen = |
366 lazyFieldInitializerCodegenFor(functionBuilder, field); | 366 lazyFieldInitializerCodegenFor(functionBuilder, field); |
367 | 367 |
368 // We only want the value of the actual initializer, not the usual | 368 // We only want the value of the actual initializer, not the usual |
369 // 'body'. | 369 // 'body'. |
370 codegen.visitForValue(initializer); | 370 codegen.visitForValue(initializer); |
371 } | 371 } |
372 }); | 372 }); |
373 assert(fieldIndex <= classBuilder.fields); | 373 assert(fieldIndex <= classBuilder.fields); |
374 } | 374 } |
375 } | 375 } |
OLD | NEW |