OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 part of dart2js.js_emitter; | 5 part of dart2js.js_emitter; |
6 | 6 |
7 /** | 7 /** |
8 * Generates the code for all used classes in the program. Static fields (even | 8 * Generates the code for all used classes in the program. Static fields (even |
9 * in classes) are ignored, since they can be treated as non-class elements. | 9 * in classes) are ignored, since they can be treated as non-class elements. |
10 * | 10 * |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 => r'$finishClasses'; | 128 => r'$finishClasses'; |
129 String get finishClassesName | 129 String get finishClassesName |
130 => '${namer.isolateName}.$finishClassesProperty'; | 130 => '${namer.isolateName}.$finishClassesProperty'; |
131 String get finishIsolateConstructorName | 131 String get finishIsolateConstructorName |
132 => '${namer.isolateName}.\$finishIsolateConstructor'; | 132 => '${namer.isolateName}.\$finishIsolateConstructor'; |
133 String get isolatePropertiesName | 133 String get isolatePropertiesName |
134 => '${namer.isolateName}.${namer.isolatePropertiesName}'; | 134 => '${namer.isolateName}.${namer.isolatePropertiesName}'; |
135 String get lazyInitializerName | 135 String get lazyInitializerName |
136 => '${namer.isolateName}.\$lazy'; | 136 => '${namer.isolateName}.\$lazy'; |
137 String get initName => 'init'; | 137 String get initName => 'init'; |
| 138 String get makeConstListProperty |
| 139 => namer.getMappedInstanceName('makeConstantList'); |
138 | 140 |
139 jsAst.FunctionDeclaration get generateAccessorFunction { | 141 jsAst.FunctionDeclaration get generateAccessorFunction { |
140 const RANGE1_SIZE = RANGE1_LAST - RANGE1_FIRST + 1; | 142 const RANGE1_SIZE = RANGE1_LAST - RANGE1_FIRST + 1; |
141 const RANGE2_SIZE = RANGE2_LAST - RANGE2_FIRST + 1; | 143 const RANGE2_SIZE = RANGE2_LAST - RANGE2_FIRST + 1; |
142 const RANGE1_ADJUST = - (FIRST_FIELD_CODE - RANGE1_FIRST); | 144 const RANGE1_ADJUST = - (FIRST_FIELD_CODE - RANGE1_FIRST); |
143 const RANGE2_ADJUST = - (FIRST_FIELD_CODE + RANGE1_SIZE - RANGE2_FIRST); | 145 const RANGE2_ADJUST = - (FIRST_FIELD_CODE + RANGE1_SIZE - RANGE2_FIRST); |
144 const RANGE3_ADJUST = | 146 const RANGE3_ADJUST = |
145 - (FIRST_FIELD_CODE + RANGE1_SIZE + RANGE2_SIZE - RANGE3_FIRST); | 147 - (FIRST_FIELD_CODE + RANGE1_SIZE + RANGE2_SIZE - RANGE3_FIRST); |
146 | 148 |
147 String receiverParamName = compiler.enableMinification ? "r" : "receiver"; | 149 String receiverParamName = compiler.enableMinification ? "r" : "receiver"; |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 function ForceEfficientMap() {} | 533 function ForceEfficientMap() {} |
532 ForceEfficientMap.prototype = this; | 534 ForceEfficientMap.prototype = this; |
533 new ForceEfficientMap(); | 535 new ForceEfficientMap(); |
534 } | 536 } |
535 Isolate.prototype = oldIsolate.prototype; | 537 Isolate.prototype = oldIsolate.prototype; |
536 Isolate.prototype.constructor = Isolate; | 538 Isolate.prototype.constructor = Isolate; |
537 Isolate.${namer.isolatePropertiesName} = isolateProperties; | 539 Isolate.${namer.isolatePropertiesName} = isolateProperties; |
538 if (#) | 540 if (#) |
539 Isolate.$finishClassesProperty = oldIsolate.$finishClassesProperty; | 541 Isolate.$finishClassesProperty = oldIsolate.$finishClassesProperty; |
540 if (#) | 542 if (#) |
541 Isolate.makeConstantList = oldIsolate.makeConstantList; | 543 Isolate.$makeConstListProperty = oldIsolate.$makeConstListProperty; |
542 return Isolate; | 544 return Isolate; |
543 }''', | 545 }''', |
544 [ needsDefineClass, hasMakeConstantList ]); | 546 [ needsDefineClass, hasMakeConstantList ]); |
545 } | 547 } |
546 | 548 |
547 jsAst.Fun get lazyInitializerFunction { | 549 jsAst.Fun get lazyInitializerFunction { |
548 String isolate = namer.currentIsolate; | 550 String isolate = namer.currentIsolate; |
549 jsAst.Expression cyclicThrow = | 551 jsAst.Expression cyclicThrow = |
550 namer.elementAccess(backend.getCyclicThrowHelper()); | 552 namer.elementAccess(backend.getCyclicThrowHelper()); |
551 | 553 |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
949 int r = namer.constantLongName(a).compareTo(namer.constantLongName(b)); | 951 int r = namer.constantLongName(a).compareTo(namer.constantLongName(b)); |
950 if (r != 0) return r; | 952 if (r != 0) return r; |
951 // Resolve collisions in the long name by using the constant name (i.e. JS | 953 // Resolve collisions in the long name by using the constant name (i.e. JS |
952 // name) which is unique. | 954 // name) which is unique. |
953 return namer.constantName(a).compareTo(namer.constantName(b)); | 955 return namer.constantName(a).compareTo(namer.constantName(b)); |
954 } | 956 } |
955 | 957 |
956 void emitMakeConstantListIfNotEmitted(CodeBuffer buffer) { | 958 void emitMakeConstantListIfNotEmitted(CodeBuffer buffer) { |
957 if (hasMakeConstantList) return; | 959 if (hasMakeConstantList) return; |
958 hasMakeConstantList = true; | 960 hasMakeConstantList = true; |
959 buffer | 961 jsAst.Statement value = new jsAst.ExpressionStatement(new jsAst.Assignment( |
960 ..write(namer.isolateName) | 962 new jsAst.PropertyAccess.field( |
961 ..write('''.makeConstantList = function(list) { | 963 new jsAst.VariableUse(namer.isolateName), |
962 list.immutable\$list = $initName; | 964 makeConstListProperty), |
963 list.fixed\$length = $initName; | 965 js('''function(list) { |
964 return list; | 966 list.immutable\$list = $initName; |
965 }; | 967 list.fixed\$length = $initName; |
966 '''); | 968 return list; |
| 969 }'''))); |
| 970 buffer.write(jsAst.prettyPrint(value, compiler)); |
967 } | 971 } |
968 | 972 |
969 /// Returns the code equivalent to: | 973 /// Returns the code equivalent to: |
970 /// `function(args) { $.startRootIsolate(X.main$closure(), args); }` | 974 /// `function(args) { $.startRootIsolate(X.main$closure(), args); }` |
971 String buildIsolateSetupClosure(CodeBuffer buffer, | 975 String buildIsolateSetupClosure(CodeBuffer buffer, |
972 Element appMain, | 976 Element appMain, |
973 Element isolateMain) { | 977 Element isolateMain) { |
974 jsAst.Expression mainAccess = namer.isolateStaticClosureAccess(appMain); | 978 jsAst.Expression mainAccess = namer.isolateStaticClosureAccess(appMain); |
975 // Since we pass the closurized version of the main method to | 979 // Since we pass the closurized version of the main method to |
976 // the isolate method, we must make sure that it exists. | 980 // the isolate method, we must make sure that it exists. |
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1739 String sourceMap = sourceMapBuilder.build(); | 1743 String sourceMap = sourceMapBuilder.build(); |
1740 compiler.outputProvider(name, 'js.map') | 1744 compiler.outputProvider(name, 'js.map') |
1741 ..add(sourceMap) | 1745 ..add(sourceMap) |
1742 ..close(); | 1746 ..close(); |
1743 } | 1747 } |
1744 | 1748 |
1745 void registerReadTypeVariable(TypeVariableElement element) { | 1749 void registerReadTypeVariable(TypeVariableElement element) { |
1746 readTypeVariables.add(element); | 1750 readTypeVariables.add(element); |
1747 } | 1751 } |
1748 } | 1752 } |
OLD | NEW |