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 '../../constants/values.dart' show ConstantValue, FunctionConstantValue; | 7 import '../../constants/values.dart' show ConstantValue, FunctionConstantValue; |
8 import '../../dart2jslib.dart' show Compiler; | 8 import '../../dart2jslib.dart' show Compiler; |
9 import '../../elements/elements.dart' show ClassElement, FunctionElement; | 9 import '../../elements/elements.dart' show ClassElement, FunctionElement; |
10 import '../../js/js.dart' as js; | 10 import '../../js/js.dart' as js; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 final NativeEmitter nativeEmitter; | 81 final NativeEmitter nativeEmitter; |
82 | 82 |
83 JavaScriptBackend get backend => compiler.backend; | 83 JavaScriptBackend get backend => compiler.backend; |
84 | 84 |
85 /// For deferred loading we communicate the initializers via this global var. | 85 /// For deferred loading we communicate the initializers via this global var. |
86 static const String deferredInitializersGlobal = | 86 static const String deferredInitializersGlobal = |
87 r"$__dart_deferred_initializers__"; | 87 r"$__dart_deferred_initializers__"; |
88 | 88 |
89 static const String deferredExtension = "part.js"; | 89 static const String deferredExtension = "part.js"; |
90 | 90 |
91 static const String typeNameProperty = r"builtin$cls"; | |
92 | |
93 ModelEmitter(Compiler compiler, Namer namer, this.nativeEmitter) | 91 ModelEmitter(Compiler compiler, Namer namer, this.nativeEmitter) |
94 : this.compiler = compiler, | 92 : this.compiler = compiler, |
95 this.namer = namer { | 93 this.namer = namer { |
96 | 94 |
97 this.constantEmitter = new ConstantEmitter( | 95 this.constantEmitter = new ConstantEmitter( |
98 compiler, namer, this.generateConstantReference, | 96 compiler, namer, this.generateConstantReference, |
99 constantListGenerator); | 97 constantListGenerator); |
100 } | 98 } |
101 | 99 |
102 js.Expression constantListGenerator(js.Expression array) { | 100 js.Expression constantListGenerator(js.Expression array) { |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 } | 469 } |
472 | 470 |
473 static final String readMetadataTypeName = "readMetadataType"; | 471 static final String readMetadataTypeName = "readMetadataType"; |
474 | 472 |
475 js.Statement get readMetadataTypeFunction { | 473 js.Statement get readMetadataTypeFunction { |
476 // Types are non-evaluated and must be compiled at first use. | 474 // Types are non-evaluated and must be compiled at first use. |
477 // Compiled strings are guaranteed not to be strings, and it's thus safe | 475 // Compiled strings are guaranteed not to be strings, and it's thus safe |
478 // to use a type-test to determine if a type has already been compiled. | 476 // to use a type-test to determine if a type has already been compiled. |
479 return js.js.statement('''function $readMetadataTypeName(index) { | 477 return js.js.statement('''function $readMetadataTypeName(index) { |
480 var type = #typesAccess[index]; | 478 var type = #typesAccess[index]; |
481 if (typeof type == 'string') { | 479 if (typeof type == "string") { |
482 type = expressionCompile(type); | 480 type = expressionCompile(type); |
483 #typesAccess[index] = type; | 481 #typesAccess[index] = type; |
484 } | 482 } |
485 return type; | 483 return type; |
486 }''', {"typesAccess": generateEmbeddedGlobalAccess(TYPES)}); | 484 }''', {"typesAccess": generateEmbeddedGlobalAccess(TYPES)}); |
487 } | 485 } |
488 | 486 |
489 js.Template get templateForReadType { | 487 js.Template get templateForReadType { |
490 // TODO(floitsch): make sure that no local variable shadows the access to | 488 // TODO(floitsch): make sure that no local variable shadows the access to |
491 // the readMetadataType function. | 489 // the readMetadataType function. |
492 return js.js.expressionTemplateFor('$readMetadataTypeName(#)'); | 490 return js.js.expressionTemplateFor('$readMetadataTypeName(#)'); |
493 } | 491 } |
494 | 492 |
495 static final String readMetadataName = "readLazyMetadata"; | 493 static final String readMetadataName = "readLazyMetadata"; |
496 static final String lazyMetadataName = "lazy_$METADATA"; | 494 static final String lazyMetadataName = "lazy_$METADATA"; |
497 | 495 |
498 js.Statement get readMetadataFunction { | 496 js.Statement get readMetadataFunction { |
499 // Types are non-evaluated and must be compiled at first use. | 497 // Types are non-evaluated and must be compiled at first use. |
500 // Compiled strings are guaranteed not to be strings, and it's thus safe | 498 // Compiled strings are guaranteed not to be strings, and it's thus safe |
501 // to use a type-test to determine if a type has already been compiled. | 499 // to use a type-test to determine if a type has already been compiled. |
502 return js.js.statement('''function $readMetadataName(index) { | 500 return js.js.statement('''function $readMetadataName(index) { |
503 var lazyMetadata = #lazyMetadataAccess[index]; | 501 var lazyMetadata = #lazyMetadataAccess[index]; |
504 if (typeof lazyMetadata == 'string') { | 502 if (typeof lazyMetadata == "string") { |
505 #metadataAccess[index] = expressionCompile(lazyMetadata); | 503 #metadataAccess[index] = expressionCompile(lazyMetadata); |
506 #lazyMetadataAccess[index] = null; | 504 #lazyMetadataAccess[index] = null; |
507 } | 505 } |
508 return #metadataAccess[index]; | 506 return #metadataAccess[index]; |
509 }''', { | 507 }''', { |
510 "lazyMetadataAccess": generateEmbeddedGlobalAccess(lazyMetadataName), | 508 "lazyMetadataAccess": generateEmbeddedGlobalAccess(lazyMetadataName), |
511 "metadataAccess": generateEmbeddedGlobalAccess(METADATA) | 509 "metadataAccess": generateEmbeddedGlobalAccess(METADATA) |
512 }); | 510 }); |
513 } | 511 } |
514 | 512 |
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1011 // We assume that all constants are in the same holder. | 1009 // We assume that all constants are in the same holder. |
1012 var holder = holders[constants[0]]; | 1010 var holder = holders[constants[0]]; |
1013 for (var i = 1; i < constants.length; i += 2) { | 1011 for (var i = 1; i < constants.length; i += 2) { |
1014 var name = constants[i]; | 1012 var name = constants[i]; |
1015 var initializer = constants[i + 1]; | 1013 var initializer = constants[i + 1]; |
1016 setupConstant(name, holder, initializer); | 1014 setupConstant(name, holder, initializer); |
1017 } | 1015 } |
1018 } | 1016 } |
1019 | 1017 |
1020 function setupStatic(name, holder, descriptor, typesOffset) { | 1018 function setupStatic(name, holder, descriptor, typesOffset) { |
1021 if (typeof descriptor == 'string') { | 1019 if (typeof descriptor == "string") { |
1022 holder[name] = function() { | 1020 holder[name] = function() { |
1023 if (descriptor == null) { | 1021 if (descriptor == null) { |
1024 // Already compiled. This happens when we have calls to the static as | 1022 // Already compiled. This happens when we have calls to the static as |
1025 // arguments to the static: `foo(foo(499))`; | 1023 // arguments to the static: `foo(foo(499))`; |
1026 return holder[name].apply(this, arguments); | 1024 return holder[name].apply(this, arguments); |
1027 } | 1025 } |
1028 var method = compile(name, descriptor); | 1026 var method = compile(name, descriptor); |
1029 holder[name] = method; | 1027 holder[name] = method; |
1030 descriptor = null; // GC the descriptor. | 1028 descriptor = null; // GC the descriptor. |
1031 return method.apply(this, arguments); | 1029 return method.apply(this, arguments); |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1178 } else { | 1176 } else { |
1179 constructor = descriptor[2]; | 1177 constructor = descriptor[2]; |
1180 functionsIndex = 3; | 1178 functionsIndex = 3; |
1181 } | 1179 } |
1182 | 1180 |
1183 for (var i = functionsIndex; i < descriptor.length; i += 2) { | 1181 for (var i = functionsIndex; i < descriptor.length; i += 2) { |
1184 parseFunctionDescriptor(prototype, descriptor[i], descriptor[i + 1], | 1182 parseFunctionDescriptor(prototype, descriptor[i], descriptor[i + 1], |
1185 typesOffset); | 1183 typesOffset); |
1186 } | 1184 } |
1187 | 1185 |
1188 constructor.$typeNameProperty = name; // Needed for RTI. | 1186 if (typeof constructor.name != "string") { |
| 1187 // IE does not store the name, but allows to modify the property. |
| 1188 constructor.name = name; |
| 1189 } |
1189 constructor.prototype = prototype; | 1190 constructor.prototype = prototype; |
1190 prototype[#operatorIsPrefix + name] = constructor; | 1191 prototype[#operatorIsPrefix + name] = constructor; |
1191 prototype.constructor = constructor; | 1192 prototype.constructor = constructor; |
1192 return constructor; | 1193 return constructor; |
1193 } | 1194 } |
1194 | 1195 |
1195 function fillPrototypeWithMixedIn(mixinName, mixinHolderIndex, prototype) { | 1196 function fillPrototypeWithMixedIn(mixinName, mixinHolderIndex, prototype) { |
1196 var mixin = holders[mixinHolderIndex][mixinName].ensureResolved(); | 1197 var mixin = holders[mixinHolderIndex][mixinName].ensureResolved(); |
1197 var mixinPrototype = mixin.prototype; | 1198 var mixinPrototype = mixin.prototype; |
1198 | 1199 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1276 | 1277 |
1277 var end = Date.now(); | 1278 var end = Date.now(); |
1278 // print('Setup: ' + (end - start) + ' ms.'); | 1279 // print('Setup: ' + (end - start) + ' ms.'); |
1279 | 1280 |
1280 #invokeMain; // Start main. | 1281 #invokeMain; // Start main. |
1281 | 1282 |
1282 })(Date.now(), #code) | 1283 })(Date.now(), #code) |
1283 }"""; | 1284 }"""; |
1284 | 1285 |
1285 } | 1286 } |
OLD | NEW |