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.js_emitter.lazy_emitter.model_emitter; | 5 library dart2js.js_emitter.lazy_emitter.model_emitter; |
6 | 6 |
7 import '../../compiler.dart' show | 7 import '../../compiler.dart' show |
8 Compiler; | 8 Compiler; |
9 import '../../constants/values.dart' show | 9 import '../../constants/values.dart' show |
10 ConstantValue, | 10 ConstantValue, |
11 FunctionConstantValue; | 11 FunctionConstantValue; |
12 import '../../core_types.dart' show | 12 import '../../core_types.dart' show |
13 CoreClasses; | 13 CoreClasses; |
14 import '../../elements/elements.dart' show | 14 import '../../elements/elements.dart' show |
15 ClassElement, | 15 ClassElement, |
16 FunctionElement; | 16 FunctionElement; |
17 import '../../js/js.dart' as js; | 17 import '../../js/js.dart' as js; |
18 import '../../js_backend/js_backend.dart' show | 18 import '../../js_backend/js_backend.dart' show |
19 JavaScriptBackend, | 19 JavaScriptBackend, |
20 Namer, | 20 Namer, |
21 ConstantEmitter; | 21 ConstantEmitter; |
22 | 22 |
23 import '../js_emitter.dart' show NativeEmitter; | 23 import '../js_emitter.dart' show NativeEmitter; |
| 24 import '../constant_ordering.dart' show deepCompareConstants; |
24 | 25 |
25 import 'package:js_runtime/shared/embedded_names.dart' show | 26 import 'package:js_runtime/shared/embedded_names.dart' show |
26 CREATE_NEW_ISOLATE, | 27 CREATE_NEW_ISOLATE, |
27 DEFERRED_LIBRARY_URIS, | 28 DEFERRED_LIBRARY_URIS, |
28 DEFERRED_LIBRARY_HASHES, | 29 DEFERRED_LIBRARY_HASHES, |
29 GET_TYPE_FROM_NAME, | 30 GET_TYPE_FROM_NAME, |
30 INITIALIZE_LOADED_HUNK, | 31 INITIALIZE_LOADED_HUNK, |
31 INTERCEPTORS_BY_TAG, | 32 INTERCEPTORS_BY_TAG, |
32 IS_HUNK_INITIALIZED, | 33 IS_HUNK_INITIALIZED, |
33 IS_HUNK_LOADED, | 34 IS_HUNK_LOADED, |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 // Emit constant interceptors first. Constant interceptors for primitives | 102 // Emit constant interceptors first. Constant interceptors for primitives |
102 // might be used by code that builds other constants. See Issue 18173. | 103 // might be used by code that builds other constants. See Issue 18173. |
103 if (a.isInterceptor != b.isInterceptor) { | 104 if (a.isInterceptor != b.isInterceptor) { |
104 return a.isInterceptor ? -1 : 1; | 105 return a.isInterceptor ? -1 : 1; |
105 } | 106 } |
106 | 107 |
107 // Sorting by the long name clusters constants with the same constructor | 108 // Sorting by the long name clusters constants with the same constructor |
108 // which compresses a tiny bit better. | 109 // which compresses a tiny bit better. |
109 int r = namer.constantLongName(a).compareTo(namer.constantLongName(b)); | 110 int r = namer.constantLongName(a).compareTo(namer.constantLongName(b)); |
110 if (r != 0) return r; | 111 if (r != 0) return r; |
111 // Resolve collisions in the long name by using the constant name (i.e. JS | 112 |
112 // name) which is unique. | 113 // Resolve collisions in the long name by using a structural order. |
113 return namer.constantName(a).compareTo(namer.constantName(b)); | 114 return deepCompareConstants(a, b); |
114 } | 115 } |
115 | 116 |
116 js.Expression generateStaticClosureAccess(FunctionElement element) { | 117 js.Expression generateStaticClosureAccess(FunctionElement element) { |
117 return js.js('#.#()', | 118 return js.js('#.#()', |
118 [namer.globalObjectFor(element), namer.staticClosureName(element)]); | 119 [namer.globalObjectFor(element), namer.staticClosureName(element)]); |
119 } | 120 } |
120 | 121 |
121 js.Expression generateConstantReference(ConstantValue value) { | 122 js.Expression generateConstantReference(ConstantValue value) { |
122 if (value.isFunction) { | 123 if (value.isFunction) { |
123 FunctionConstantValue functionConstant = value; | 124 FunctionConstantValue functionConstant = value; |
(...skipping 1124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1248 | 1249 |
1249 var end = Date.now(); | 1250 var end = Date.now(); |
1250 // print('Setup: ' + (end - start) + ' ms.'); | 1251 // print('Setup: ' + (end - start) + ' ms.'); |
1251 | 1252 |
1252 #invokeMain; // Start main. | 1253 #invokeMain; // Start main. |
1253 | 1254 |
1254 })(Date.now(), #code) | 1255 })(Date.now(), #code) |
1255 }"""; | 1256 }"""; |
1256 | 1257 |
1257 } | 1258 } |
OLD | NEW |