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

Side by Side Diff: pkg/compiler/lib/src/js_emitter/new_emitter/model_emitter.dart

Issue 869953002: dart2js: add type lookup in the new emitter. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed comments. Created 5 years, 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 GET_TYPE_FROM_NAME;
floitsch 2015/01/23 22:33:42 They are sorted by name.
zarah 2015/01/26 17:54:11 Done.
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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 // that covers the entire program. 129 // that covers the entire program.
129 130
130 List<js.Statement> statements = [ 131 List<js.Statement> statements = [
131 new js.ExpressionStatement( 132 new js.ExpressionStatement(
132 new js.VariableDeclarationList(holders.map((e) => 133 new js.VariableDeclarationList(holders.map((e) =>
133 new js.VariableInitialization( 134 new js.VariableInitialization(
134 new js.VariableDeclaration(e.name, allowRename: false), 135 new js.VariableDeclaration(e.name, allowRename: false),
135 new js.ObjectInitializer(const []))).toList())), 136 new js.ObjectInitializer(const []))).toList())),
136 js.js.statement('var holders = #', new js.ArrayInitializer( 137 js.js.statement('var holders = #', new js.ArrayInitializer(
137 holders.map((e) => new js.VariableUse(e.name)) 138 holders.map((e) => new js.VariableUse(e.name))
138 .toList(growable: false))) 139 .toList(growable: false))),
140 js.js.statement('var holdersMap = {}')
floitsch 2015/01/23 22:32:03 Object.create(null);
zarah 2015/01/26 17:54:11 Done.
139 ]; 141 ];
140 return new js.Block(statements); 142 return new js.Block(statements);
141 } 143 }
142 144
143 static js.Template get makeConstantListTemplate { 145 static js.Template get makeConstantListTemplate {
144 // TODO(floitsch): remove hard-coded name. 146 // TODO(floitsch): remove hard-coded name.
145 // TODO(floitsch): there is no harm in caching the template. 147 // TODO(floitsch): there is no harm in caching the template.
146 return js.js.uncachedExpressionTemplate('makeConstList(#)'); 148 return js.js.uncachedExpressionTemplate('makeConstList(#)');
147 } 149 }
148 150
149 js.Block emitEmbeddedGlobals(Map<String, List<Fragment>> loadMap) { 151 js.Block emitEmbeddedGlobals(Map<String, List<Fragment>> loadMap) {
150 List<js.Property> globals = <js.Property>[]; 152 List<js.Property> globals = <js.Property>[];
151 153
152 if (loadMap.isNotEmpty) { 154 if (loadMap.isNotEmpty) {
153 globals.addAll(emitLoadUrisAndHashes(loadMap)); 155 globals.addAll(emitLoadUrisAndHashes(loadMap));
154 globals.add(emitIsHunkLoadedFunction()); 156 globals.add(emitIsHunkLoadedFunction());
155 globals.add(emitInitializeLoadedHunk()); 157 globals.add(emitInitializeLoadedHunk());
156 } 158 }
157 159
160 globals.add(emitGetTypeFromName());
158 js.ObjectInitializer globalsObject = new js.ObjectInitializer(globals); 161 js.ObjectInitializer globalsObject = new js.ObjectInitializer(globals);
159 162
160 List<js.Statement> statements = 163 List<js.Statement> statements =
161 [new js.ExpressionStatement( 164 [new js.ExpressionStatement(
162 new js.VariableDeclarationList( 165 new js.VariableDeclarationList(
163 [new js.VariableInitialization( 166 [new js.VariableInitialization(
164 new js.VariableDeclaration("init", allowRename: false), 167 new js.VariableDeclaration("init", allowRename: false),
165 globalsObject)]))]; 168 globalsObject)]))];
166 return new js.Block(statements); 169 return new js.Block(statements);
167 } 170 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 js.js("function(hash) { return !!$deferredInitializersGlobal[hash]; }"); 212 js.js("function(hash) { return !!$deferredInitializersGlobal[hash]; }");
210 return new js.Property(js.string(IS_HUNK_LOADED), function); 213 return new js.Property(js.string(IS_HUNK_LOADED), function);
211 } 214 }
212 215
213 js.Property emitInitializeLoadedHunk() { 216 js.Property emitInitializeLoadedHunk() {
214 js.Expression function = 217 js.Expression function =
215 js.js("function(hash) { eval($deferredInitializersGlobal[hash]); }"); 218 js.js("function(hash) { eval($deferredInitializersGlobal[hash]); }");
216 return new js.Property(js.string(INITIALIZE_LOADED_HUNK), function); 219 return new js.Property(js.string(INITIALIZE_LOADED_HUNK), function);
217 } 220 }
218 221
222 js.Property emitGetTypeFromName() {
223 js.Expression function =
224 js.js( """function(name) {return holdersMap[name][name];}""");
floitsch 2015/01/23 22:39:21 must call ensureResolved!
zarah 2015/01/26 17:54:11 Done.
225 return new js.Property(js.string(GET_TYPE_FROM_NAME), function);
226 }
227
219 js.Expression emitDeferredFragment(DeferredFragment fragment, 228 js.Expression emitDeferredFragment(DeferredFragment fragment,
220 List<Holder> holders) { 229 List<Holder> holders) {
221 // TODO(floitsch): initialize eager classes. 230 // TODO(floitsch): initialize eager classes.
222 // TODO(floitsch): the hash must depend on the output. 231 // TODO(floitsch): the hash must depend on the output.
223 int hash = this.hashCode; 232 int hash = this.hashCode;
224 if (fragment.constants.isNotEmpty) { 233 if (fragment.constants.isNotEmpty) {
225 throw new UnimplementedError("constants in deferred units"); 234 throw new UnimplementedError("constants in deferred units");
226 } 235 }
227 js.ArrayInitializer content = 236 js.ArrayInitializer content =
228 new js.ArrayInitializer(fragment.libraries.map(emitLibrary) 237 new js.ArrayInitializer(fragment.libraries.map(emitLibrary)
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 function setupLibrary(library) { 417 function setupLibrary(library) {
409 var statics = library[0]; 418 var statics = library[0];
410 for (var i = 0; i < statics.length; i += 3) { 419 for (var i = 0; i < statics.length; i += 3) {
411 var holderIndex = statics[i + 1]; 420 var holderIndex = statics[i + 1];
412 setupStatic(statics[i], holders[holderIndex], statics[i + 2]); 421 setupStatic(statics[i], holders[holderIndex], statics[i + 2]);
413 } 422 }
414 423
415 var classes = library[1]; 424 var classes = library[1];
416 for (var i = 0; i < classes.length; i += 3) { 425 for (var i = 0; i < classes.length; i += 3) {
417 var holderIndex = classes[i + 1]; 426 var holderIndex = classes[i + 1];
427 holdersMap[classes[i]] = holders[holderIndex];
418 setupClass(classes[i], holders[holderIndex], classes[i + 2]); 428 setupClass(classes[i], holders[holderIndex], classes[i + 2]);
419 } 429 }
420 } 430 }
421 431
422 function setupLazyStatics(statics) { 432 function setupLazyStatics(statics) {
423 for (var i = 0; i < statics.length; i += 4) { 433 for (var i = 0; i < statics.length; i += 4) {
424 var name = statics[i]; 434 var name = statics[i];
425 var getterName = statics[i + 1]; 435 var getterName = statics[i + 1];
426 var holderIndex = statics[i + 2]; 436 var holderIndex = statics[i + 2];
427 var initializer = statics[i + 3]; 437 var initializer = statics[i + 3];
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 584
575 var end = Date.now(); 585 var end = Date.now();
576 print('Setup: ' + (end - start) + ' ms.'); 586 print('Setup: ' + (end - start) + ' ms.');
577 587
578 #main(); // Start main. 588 #main(); // Start main.
579 589
580 }(Date.now(), #code) 590 }(Date.now(), #code)
581 }"""; 591 }""";
582 592
583 } 593 }
OLDNEW
« no previous file with comments | « no previous file | pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698