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 part of dart2js.js_emitter; | 5 part of dart2js.js_emitter; |
| 6 | 6 |
| 7 | 7 |
| 8 class OldEmitter implements Emitter { | 8 class OldEmitter implements Emitter { |
| 9 final Compiler compiler; | 9 final Compiler compiler; |
| 10 final CodeEmitterTask task; | 10 final CodeEmitterTask task; |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 174 | 174 |
| 175 jsAst.Expression generateEmbeddedGlobalAccess(String global) { | 175 jsAst.Expression generateEmbeddedGlobalAccess(String global) { |
| 176 return js(generateEmbeddedGlobalAccessString(global)); | 176 return js(generateEmbeddedGlobalAccessString(global)); |
| 177 } | 177 } |
| 178 | 178 |
| 179 String generateEmbeddedGlobalAccessString(String global) { | 179 String generateEmbeddedGlobalAccessString(String global) { |
| 180 // TODO(floitsch): don't use 'init' as global embedder storage. | 180 // TODO(floitsch): don't use 'init' as global embedder storage. |
| 181 return '$initName.$global'; | 181 return '$initName.$global'; |
| 182 } | 182 } |
| 183 | 183 |
| 184 jsAst.PropertyAccess globalPropertyAccess(Element element) { | |
| 185 String name = namer.getNameX(element); | |
| 186 jsAst.PropertyAccess pa = new jsAst.PropertyAccess.field( | |
| 187 new jsAst.VariableUse(namer.globalObjectFor(element)), | |
| 188 name); | |
| 189 return pa; | |
| 190 } | |
| 191 | |
| 184 jsAst.FunctionDeclaration get generateAccessorFunction { | 192 jsAst.FunctionDeclaration get generateAccessorFunction { |
| 185 const RANGE1_SIZE = RANGE1_LAST - RANGE1_FIRST + 1; | 193 const RANGE1_SIZE = RANGE1_LAST - RANGE1_FIRST + 1; |
| 186 const RANGE2_SIZE = RANGE2_LAST - RANGE2_FIRST + 1; | 194 const RANGE2_SIZE = RANGE2_LAST - RANGE2_FIRST + 1; |
| 187 const RANGE1_ADJUST = - (FIRST_FIELD_CODE - RANGE1_FIRST); | 195 const RANGE1_ADJUST = - (FIRST_FIELD_CODE - RANGE1_FIRST); |
| 188 const RANGE2_ADJUST = - (FIRST_FIELD_CODE + RANGE1_SIZE - RANGE2_FIRST); | 196 const RANGE2_ADJUST = - (FIRST_FIELD_CODE + RANGE1_SIZE - RANGE2_FIRST); |
| 189 const RANGE3_ADJUST = | 197 const RANGE3_ADJUST = |
| 190 - (FIRST_FIELD_CODE + RANGE1_SIZE + RANGE2_SIZE - RANGE3_FIRST); | 198 - (FIRST_FIELD_CODE + RANGE1_SIZE + RANGE2_SIZE - RANGE3_FIRST); |
| 191 | 199 |
| 192 String receiverParamName = compiler.enableMinification ? "r" : "receiver"; | 200 String receiverParamName = compiler.enableMinification ? "r" : "receiver"; |
| 193 String valueParamName = compiler.enableMinification ? "v" : "value"; | 201 String valueParamName = compiler.enableMinification ? "v" : "value"; |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 639 }''', | 647 }''', |
| 640 [namer.isolatePropertiesName, namer.isolatePropertiesName, | 648 [namer.isolatePropertiesName, namer.isolatePropertiesName, |
| 641 needsDefineClass, finishClassesProperty, finishClassesProperty, | 649 needsDefineClass, finishClassesProperty, finishClassesProperty, |
| 642 task.outputContainsConstantList, | 650 task.outputContainsConstantList, |
| 643 makeConstListProperty, makeConstListProperty ]); | 651 makeConstListProperty, makeConstListProperty ]); |
| 644 } | 652 } |
| 645 | 653 |
| 646 jsAst.Fun get lazyInitializerFunction { | 654 jsAst.Fun get lazyInitializerFunction { |
| 647 String isolate = namer.currentIsolate; | 655 String isolate = namer.currentIsolate; |
| 648 jsAst.Expression cyclicThrow = | 656 jsAst.Expression cyclicThrow = |
| 649 namer.elementAccess(backend.getCyclicThrowHelper()); | 657 globalPropertyAccess(backend.getCyclicThrowHelper()); |
|
floitsch
2014/12/03 17:02:25
staticFunctionAccess
zarah
2014/12/05 08:22:51
Done.
| |
| 650 jsAst.Expression laziesAccess = | 658 jsAst.Expression laziesAccess = |
| 651 generateEmbeddedGlobalAccess(embeddedNames.LAZIES); | 659 generateEmbeddedGlobalAccess(embeddedNames.LAZIES); |
| 652 | 660 |
| 653 return js(''' | 661 return js(''' |
| 654 function (prototype, staticName, fieldName, getterName, lazyValue) { | 662 function (prototype, staticName, fieldName, getterName, lazyValue) { |
| 655 if (!#) # = Object.create(null); | 663 if (!#) # = Object.create(null); |
| 656 #[fieldName] = getterName; | 664 #[fieldName] = getterName; |
| 657 | 665 |
| 658 var sentinelUndefined = {}; | 666 var sentinelUndefined = {}; |
| 659 var sentinelInProgress = {}; | 667 var sentinelInProgress = {}; |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1036 } | 1044 } |
| 1037 | 1045 |
| 1038 /// Returns the code equivalent to: | 1046 /// Returns the code equivalent to: |
| 1039 /// `function(args) { $.startRootIsolate(X.main$closure(), args); }` | 1047 /// `function(args) { $.startRootIsolate(X.main$closure(), args); }` |
| 1040 jsAst.Expression buildIsolateSetupClosure(Element appMain, | 1048 jsAst.Expression buildIsolateSetupClosure(Element appMain, |
| 1041 Element isolateMain) { | 1049 Element isolateMain) { |
| 1042 jsAst.Expression mainAccess = namer.isolateStaticClosureAccess(appMain); | 1050 jsAst.Expression mainAccess = namer.isolateStaticClosureAccess(appMain); |
| 1043 // Since we pass the closurized version of the main method to | 1051 // Since we pass the closurized version of the main method to |
| 1044 // the isolate method, we must make sure that it exists. | 1052 // the isolate method, we must make sure that it exists. |
| 1045 return js('function(a){ #(#, a); }', | 1053 return js('function(a){ #(#, a); }', |
| 1046 [namer.elementAccess(isolateMain), mainAccess]); | 1054 [backend.emitter.globalPropertyAccess(isolateMain), mainAccess]); |
|
floitsch
2014/12/03 17:02:25
staticFunctionAccess
zarah
2014/12/05 08:22:51
Done.
| |
| 1047 } | 1055 } |
| 1048 | 1056 |
| 1049 /** | 1057 /** |
| 1050 * Emits code that sets the `isolateTag embedded global to a unique string. | 1058 * Emits code that sets the `isolateTag embedded global to a unique string. |
| 1051 */ | 1059 */ |
| 1052 jsAst.Expression generateIsolateAffinityTagInitialization() { | 1060 jsAst.Expression generateIsolateAffinityTagInitialization() { |
| 1053 jsAst.Expression getIsolateTagAccess = | 1061 jsAst.Expression getIsolateTagAccess = |
| 1054 generateEmbeddedGlobalAccess(embeddedNames.GET_ISOLATE_TAG); | 1062 generateEmbeddedGlobalAccess(embeddedNames.GET_ISOLATE_TAG); |
| 1055 jsAst.Expression isolateTagAccess = | 1063 jsAst.Expression isolateTagAccess = |
| 1056 generateEmbeddedGlobalAccess(embeddedNames.ISOLATE_TAG); | 1064 generateEmbeddedGlobalAccess(embeddedNames.ISOLATE_TAG); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1108 | 1116 |
| 1109 emitMain(CodeBuffer buffer) { | 1117 emitMain(CodeBuffer buffer) { |
| 1110 if (compiler.isMockCompilation) return; | 1118 if (compiler.isMockCompilation) return; |
| 1111 Element main = compiler.mainFunction; | 1119 Element main = compiler.mainFunction; |
| 1112 jsAst.Expression mainCallClosure = null; | 1120 jsAst.Expression mainCallClosure = null; |
| 1113 if (compiler.hasIsolateSupport) { | 1121 if (compiler.hasIsolateSupport) { |
| 1114 Element isolateMain = | 1122 Element isolateMain = |
| 1115 backend.isolateHelperLibrary.find(JavaScriptBackend.START_ROOT_ISOLATE); | 1123 backend.isolateHelperLibrary.find(JavaScriptBackend.START_ROOT_ISOLATE); |
| 1116 mainCallClosure = buildIsolateSetupClosure(main, isolateMain); | 1124 mainCallClosure = buildIsolateSetupClosure(main, isolateMain); |
| 1117 } else if (compiler.hasIncrementalSupport) { | 1125 } else if (compiler.hasIncrementalSupport) { |
| 1118 mainCallClosure = | 1126 mainCallClosure = js( |
| 1119 js('function() { return #(); }', namer.elementAccess(main)); | 1127 'function() { return #(); }', |
| 1128 backend.emitter.globalPropertyAccess(main)); | |
|
floitsch
2014/12/03 17:02:25
staticFunctionAccess
zarah
2014/12/05 08:22:51
Done.
| |
| 1120 } else { | 1129 } else { |
| 1121 mainCallClosure = namer.elementAccess(main); | 1130 mainCallClosure = backend.emitter.globalPropertyAccess(main); |
|
floitsch
2014/12/03 17:02:25
staticFunctionAccess
zarah
2014/12/05 08:22:51
Done.
| |
| 1122 } | 1131 } |
| 1123 | 1132 |
| 1124 if (backend.needToInitializeIsolateAffinityTag) { | 1133 if (backend.needToInitializeIsolateAffinityTag) { |
| 1125 buffer.write( | 1134 buffer.write( |
| 1126 jsAst.prettyPrint(generateIsolateAffinityTagInitialization(), | 1135 jsAst.prettyPrint(generateIsolateAffinityTagInitialization(), |
| 1127 compiler, monitor: compiler.dumpInfoTask)); | 1136 compiler, monitor: compiler.dumpInfoTask)); |
| 1128 buffer.write(N); | 1137 buffer.write(N); |
| 1129 } | 1138 } |
| 1130 if (backend.needToInitializeDispatchProperty) { | 1139 if (backend.needToInitializeDispatchProperty) { |
| 1131 assert(backend.needToInitializeIsolateAffinityTag); | 1140 assert(backend.needToInitializeIsolateAffinityTag); |
| (...skipping 936 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2068 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { | 2077 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { |
| 2069 if (element.isInstanceMember) { | 2078 if (element.isInstanceMember) { |
| 2070 cachedClassBuilders.remove(element.enclosingClass); | 2079 cachedClassBuilders.remove(element.enclosingClass); |
| 2071 | 2080 |
| 2072 nativeEmitter.cachedBuilders.remove(element.enclosingClass); | 2081 nativeEmitter.cachedBuilders.remove(element.enclosingClass); |
| 2073 | 2082 |
| 2074 } | 2083 } |
| 2075 } | 2084 } |
| 2076 } | 2085 } |
| 2077 } | 2086 } |
| OLD | NEW |