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

Side by Side Diff: dart/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart

Issue 15096006: Handle constants that mix eager and deferred types. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 7 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
OLDNEW
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 js_backend; 5 part of js_backend;
6 6
7 /** 7 /**
8 * A function element that represents a closure call. The signature is copied 8 * A function element that represents a closure call. The signature is copied
9 * from the given element. 9 * from the given element.
10 */ 10 */
(...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 '";\\n")') 789 '";\\n")')
790 ]) 790 ])
791 ]), 791 ]),
792 792
793 js('str += "}\\n"'), 793 js('str += "}\\n"'),
794 794
795 js('var newIsolate = new Function(str)'), 795 js('var newIsolate = new Function(str)'),
796 js('newIsolate.prototype = isolatePrototype'), 796 js('newIsolate.prototype = isolatePrototype'),
797 js('isolatePrototype.constructor = newIsolate'), 797 js('isolatePrototype.constructor = newIsolate'),
798 js('newIsolate.${namer.isolatePropertiesName} = isolateProperties'), 798 js('newIsolate.${namer.isolatePropertiesName} = isolateProperties'),
799 // TODO(ahe): Only copy makeConstantList when it is used.
800 js('newIsolate.makeConstantList = oldIsolate.makeConstantList'),
799 ]..addAll(copyFinishClasses) 801 ]..addAll(copyFinishClasses)
800 ..addAll([ 802 ..addAll([
801 803
802 // return newIsolate; 804 // return newIsolate;
803 js.return_('newIsolate') 805 js.return_('newIsolate')
804 ])); 806 ]));
805 } 807 }
806 808
807 jsAst.Fun get lazyInitializerFunction { 809 jsAst.Fun get lazyInitializerFunction {
808 String isolate = namer.CURRENT_ISOLATE; 810 String isolate = namer.CURRENT_ISOLATE;
(...skipping 1337 matching lines...) Expand 10 before | Expand all | Expand 10 after
2146 2148
2147 String name = namer.constantName(constant); 2149 String name = namer.constantName(constant);
2148 // The name is null when the constant is already a JS constant. 2150 // The name is null when the constant is already a JS constant.
2149 // TODO(floitsch): every constant should be registered, so that we can 2151 // TODO(floitsch): every constant should be registered, so that we can
2150 // share the ones that take up too much space (like some strings). 2152 // share the ones that take up too much space (like some strings).
2151 if (name == null) continue; 2153 if (name == null) continue;
2152 if (!addedMakeConstantList && constant.isList()) { 2154 if (!addedMakeConstantList && constant.isList()) {
2153 addedMakeConstantList = true; 2155 addedMakeConstantList = true;
2154 emitMakeConstantList(eagerBuffer); 2156 emitMakeConstantList(eagerBuffer);
2155 } 2157 }
2156 CodeBuffer buffer = 2158 CodeBuffer buffer = bufferForConstant(constant, eagerBuffer);
2157 bufferForElement(constant.computeType(compiler).element, eagerBuffer);
2158 jsAst.Expression init = js('$isolateProperties.$name = #', 2159 jsAst.Expression init = js('$isolateProperties.$name = #',
2159 constantInitializerExpression(constant)); 2160 constantInitializerExpression(constant));
2160 buffer.write(jsAst.prettyPrint(init, compiler)); 2161 buffer.write(jsAst.prettyPrint(init, compiler));
2161 buffer.write('$N'); 2162 buffer.write('$N');
2162 } 2163 }
2163 } 2164 }
2164 2165
2165 void emitMakeConstantList(CodeBuffer buffer) { 2166 void emitMakeConstantList(CodeBuffer buffer) {
2166 buffer.write(namer.isolateName); 2167 buffer.write(namer.isolateName);
2167 buffer.write(r'''.makeConstantList = function(list) { 2168 buffer.write(r'''.makeConstantList = function(list) {
(...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after
3018 }); 3019 });
3019 return compiler.assembledCode; 3020 return compiler.assembledCode;
3020 } 3021 }
3021 3022
3022 CodeBuffer bufferForElement(Element element, CodeBuffer eagerBuffer) { 3023 CodeBuffer bufferForElement(Element element, CodeBuffer eagerBuffer) {
3023 if (!isDeferred(element)) return eagerBuffer; 3024 if (!isDeferred(element)) return eagerBuffer;
3024 emitDeferredPreambleWhenEmpty(deferredBuffer); 3025 emitDeferredPreambleWhenEmpty(deferredBuffer);
3025 return deferredBuffer; 3026 return deferredBuffer;
3026 } 3027 }
3027 3028
3029 bool firstDeferredConstant = true;
3030
3031 /**
3032 * Returns the appropriate buffer for [constant]. If constant is
3033 * itself an instance of a deferred type, or built from constants
3034 * that are instances of deferred types, attempting to use this
3035 * constant before the deferred type has been loaded has will not
ngeoffray 2013/05/14 10:08:49 remove second 'has'.
ahe 2013/05/15 08:22:56 Done.
3036 * work.
3037 */
3038 CodeBuffer bufferForConstant(Constant constant, CodeBuffer eagerBuffer) {
3039 var queue = new Queue()..add(constant);
3040 while (!queue.isEmpty) {
3041 constant = queue.removeFirst();
3042 if (isDeferred(constant.computeType(compiler).element)) {
3043 emitDeferredPreambleWhenEmpty(deferredBuffer);
3044 if (firstDeferredConstant) {
3045 deferredBuffer.write(
3046 '${namer.CURRENT_ISOLATE}$_=${_}old${namer.CURRENT_ISOLATE}$N');
3047 deferredBuffer.write(
3048 'old${namer.CURRENT_ISOLATE}$_=${_}${namer.CURRENT_ISOLATE}$N');
3049 }
3050 firstDeferredConstant = false;
3051 return deferredBuffer;
3052 }
3053 queue.addAll(constant.getDependencies());
3054 }
3055 return eagerBuffer;
3056 }
3057
3028 void emitDeferredCode(CodeBuffer buffer) { 3058 void emitDeferredCode(CodeBuffer buffer) {
3029 if (buffer.isEmpty) return; 3059 if (buffer.isEmpty) return;
3030 3060
3031 buffer.write(n); 3061 buffer.write(n);
3032 3062
3033 buffer.write( 3063 buffer.write(
3034 '${namer.CURRENT_ISOLATE}$_=${_}old${namer.CURRENT_ISOLATE}$N'); 3064 '${namer.CURRENT_ISOLATE}$_=${_}old${namer.CURRENT_ISOLATE}$N');
3035 3065
3036 String code = buffer.getText(); 3066 String code = buffer.getText();
3037 compiler.outputProvider('part', 'js') 3067 compiler.outputProvider('part', 'js')
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
3089 """; 3119 """;
3090 const String HOOKS_API_USAGE = """ 3120 const String HOOKS_API_USAGE = """
3091 // The code supports the following hooks: 3121 // The code supports the following hooks:
3092 // dartPrint(message) - if this function is defined it is called 3122 // dartPrint(message) - if this function is defined it is called
3093 // instead of the Dart [print] method. 3123 // instead of the Dart [print] method.
3094 // dartMainRunner(main) - if this function is defined, the Dart [main] 3124 // dartMainRunner(main) - if this function is defined, the Dart [main]
3095 // method will not be invoked directly. 3125 // method will not be invoked directly.
3096 // Instead, a closure that will invoke [main] is 3126 // Instead, a closure that will invoke [main] is
3097 // passed to [dartMainRunner]. 3127 // passed to [dartMainRunner].
3098 """; 3128 """;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698