Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 | 4 |
| 5 library dart2js.new_js_emitter.model_emitter; | 5 library dart2js.new_js_emitter.model_emitter; |
| 6 | 6 |
| 7 import '../../dart2jslib.dart' show Compiler; | 7 import '../../dart2jslib.dart' show Compiler; |
| 8 import '../../js/js.dart' as js; | 8 import '../../js/js.dart' as js; |
| 9 import '../../js_backend/js_backend.dart' show | 9 import '../../js_backend/js_backend.dart' show |
| 10 JavaScriptBackend, | 10 JavaScriptBackend, |
| 11 Namer, | 11 Namer, |
| 12 ConstantEmitter; | 12 ConstantEmitter; |
| 13 | 13 |
| 14 import 'package:_internal/compiler/js_lib/shared/embedded_names.dart' show | 14 import 'package:_internal/compiler/js_lib/shared/embedded_names.dart' show |
| 15 DEFERRED_LIBRARY_URIS, | 15 DEFERRED_LIBRARY_URIS, |
| 16 DEFERRED_LIBRARY_HASHES, | 16 DEFERRED_LIBRARY_HASHES, |
| 17 INITIALIZE_LOADED_HUNK, | 17 INITIALIZE_LOADED_HUNK, |
| 18 IS_HUNK_INITIALIZED, | 18 IS_HUNK_INITIALIZED, |
| 19 IS_HUNK_LOADED; | 19 IS_HUNK_LOADED, |
| 20 TYPE_TO_INTERCEPTOR_MAP; | |
| 20 | 21 |
| 21 import '../js_emitter.dart' show NativeGenerator; | 22 import '../js_emitter.dart' show NativeGenerator; |
| 22 import '../model.dart'; | 23 import '../model.dart'; |
| 23 | 24 |
| 24 class ModelEmitter { | 25 class ModelEmitter { |
| 25 final Compiler compiler; | 26 final Compiler compiler; |
| 26 final Namer namer; | 27 final Namer namer; |
| 27 final ConstantEmitter constantEmitter; | 28 final ConstantEmitter constantEmitter; |
| 28 | 29 |
| 29 JavaScriptBackend get backend => compiler.backend; | 30 JavaScriptBackend get backend => compiler.backend; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 | 101 |
| 101 js.Expression code = new js.ArrayInitializer(elements); | 102 js.Expression code = new js.ArrayInitializer(elements); |
| 102 | 103 |
| 103 return js.js.statement( | 104 return js.js.statement( |
| 104 boilerplate, | 105 boilerplate, |
| 105 {'deferredInitializer': emitDeferredInitializerGlobal(program.loadMap), | 106 {'deferredInitializer': emitDeferredInitializerGlobal(program.loadMap), |
| 106 'holders': emitHolders(fragment.holders), | 107 'holders': emitHolders(fragment.holders), |
| 107 'cyclicThrow': | 108 'cyclicThrow': |
| 108 backend.emitter.staticFunctionAccess(backend.getCyclicThrowHelper()), | 109 backend.emitter.staticFunctionAccess(backend.getCyclicThrowHelper()), |
| 109 'outputContainsConstantList': program.outputContainsConstantList, | 110 'outputContainsConstantList': program.outputContainsConstantList, |
| 110 'embeddedGlobals': emitEmbeddedGlobals(program.loadMap), | 111 'embeddedGlobals': emitEmbeddedGlobals(program), |
| 111 'constants': emitConstants(fragment.constants), | 112 'constants': emitConstants(fragment.constants), |
| 112 'staticNonFinals': emitStaticNonFinalFields(fragment.staticNonFinalFiel ds), | 113 'staticNonFinals': emitStaticNonFinalFields(fragment.staticNonFinalFiel ds), |
|
floitsch
2015/01/27 13:13:06
I have a fix for this in a separate CL.
| |
| 113 'nativeBoilerplate': nativeBoilerplate, | 114 'nativeBoilerplate': nativeBoilerplate, |
| 114 'eagerClasses': emitEagerClassInitializations(fragment.libraries), | 115 'eagerClasses': emitEagerClassInitializations(fragment.libraries), |
| 115 'main': fragment.main, | 116 'main': fragment.main, |
| 116 'code': code}); | 117 'code': code}); |
| 117 } | 118 } |
| 118 | 119 |
| 119 js.Block emitHolders(List<Holder> holders) { | 120 js.Block emitHolders(List<Holder> holders) { |
| 120 // The top-level variables for holders must *not* be renamed by the | 121 // The top-level variables for holders must *not* be renamed by the |
| 121 // JavaScript pretty printer because a lot of code already uses the | 122 // JavaScript pretty printer because a lot of code already uses the |
| 122 // non-renamed names. The generated code looks like this: | 123 // non-renamed names. The generated code looks like this: |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 139 ]; | 140 ]; |
| 140 return new js.Block(statements); | 141 return new js.Block(statements); |
| 141 } | 142 } |
| 142 | 143 |
| 143 static js.Template get makeConstantListTemplate { | 144 static js.Template get makeConstantListTemplate { |
| 144 // TODO(floitsch): remove hard-coded name. | 145 // TODO(floitsch): remove hard-coded name. |
| 145 // TODO(floitsch): there is no harm in caching the template. | 146 // TODO(floitsch): there is no harm in caching the template. |
| 146 return js.js.uncachedExpressionTemplate('makeConstList(#)'); | 147 return js.js.uncachedExpressionTemplate('makeConstList(#)'); |
| 147 } | 148 } |
| 148 | 149 |
| 149 js.Block emitEmbeddedGlobals(Map<String, List<Fragment>> loadMap) { | 150 js.Block emitEmbeddedGlobals(Program program) { |
| 150 List<js.Property> globals = <js.Property>[]; | 151 List<js.Property> globals = <js.Property>[]; |
| 151 | 152 |
| 152 if (loadMap.isNotEmpty) { | 153 if (program.loadMap.isNotEmpty) { |
| 153 globals.addAll(emitLoadUrisAndHashes(loadMap)); | 154 globals.addAll(emitLoadUrisAndHashes(program.loadMap)); |
| 154 globals.add(emitIsHunkLoadedFunction()); | 155 globals.add(emitIsHunkLoadedFunction()); |
| 155 globals.add(emitInitializeLoadedHunk()); | 156 globals.add(emitInitializeLoadedHunk()); |
| 156 } | 157 } |
| 157 | 158 |
| 159 if (program.typeToInterceptorMap != null) { | |
| 160 globals.add(new js.Property(js.string(TYPE_TO_INTERCEPTOR_MAP), | |
| 161 program.typeToInterceptorMap)); | |
| 162 } | |
| 163 | |
| 158 js.ObjectInitializer globalsObject = new js.ObjectInitializer(globals); | 164 js.ObjectInitializer globalsObject = new js.ObjectInitializer(globals); |
| 159 | 165 |
| 160 List<js.Statement> statements = | 166 List<js.Statement> statements = |
| 161 [new js.ExpressionStatement( | 167 [new js.ExpressionStatement( |
| 162 new js.VariableDeclarationList( | 168 new js.VariableDeclarationList( |
| 163 [new js.VariableInitialization( | 169 [new js.VariableInitialization( |
| 164 new js.VariableDeclaration("init", allowRename: false), | 170 new js.VariableDeclaration("init", allowRename: false), |
| 165 globalsObject)]))]; | 171 globalsObject)]))]; |
| 166 return new js.Block(statements); | 172 return new js.Block(statements); |
| 167 } | 173 } |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 541 // hidden class. The actual values of the fields don't matter, since we | 547 // hidden class. The actual values of the fields don't matter, since we |
| 542 // only check if they exist. | 548 // only check if they exist. |
| 543 list.immutable\$list = Array; | 549 list.immutable\$list = Array; |
| 544 list.fixed\$length = Array; | 550 list.fixed\$length = Array; |
| 545 return list; | 551 return list; |
| 546 } | 552 } |
| 547 } | 553 } |
| 548 | 554 |
| 549 setupProgram(); | 555 setupProgram(); |
| 550 | 556 |
| 557 // Initialize constants. | |
| 558 #constants; | |
| 559 | |
| 551 // Initialize globals. | 560 // Initialize globals. |
| 552 #embeddedGlobals; | 561 #embeddedGlobals; |
| 553 | 562 |
| 554 // Initialize constants. | |
| 555 #constants; | |
| 556 | |
| 557 // Initialize static non-final fields. | 563 // Initialize static non-final fields. |
| 558 #staticNonFinals; | 564 #staticNonFinals; |
| 559 | 565 |
| 560 // Add native boilerplate code. | 566 // Add native boilerplate code. |
| 561 #nativeBoilerplate; | 567 #nativeBoilerplate; |
| 562 | 568 |
| 563 // Initialize eager classes. | 569 // Initialize eager classes. |
| 564 #eagerClasses; | 570 #eagerClasses; |
| 565 | 571 |
| 566 var end = Date.now(); | 572 var end = Date.now(); |
| 567 print('Setup: ' + (end - start) + ' ms.'); | 573 print('Setup: ' + (end - start) + ' ms.'); |
| 568 | 574 |
| 569 #main(); // Start main. | 575 #main(); // Start main. |
| 570 | 576 |
| 571 }(Date.now(), #code) | 577 }(Date.now(), #code) |
| 572 }"""; | 578 }"""; |
| 573 | 579 |
| 574 } | 580 } |
| OLD | NEW |