| 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; | 7 import '../../constants/values.dart' show ConstantValue; |
| 8 import '../../dart2jslib.dart' show Compiler; | 8 import '../../dart2jslib.dart' show Compiler; |
| 9 import '../../dart_types.dart' show DartType; | 9 import '../../dart_types.dart' show DartType; |
| 10 import '../../elements/elements.dart' show ClassElement; | 10 import '../../elements/elements.dart' show ClassElement; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 emitLazilyInitializedStatics(fragment.staticLazilyInitializedFields)); | 108 emitLazilyInitializedStatics(fragment.staticLazilyInitializedFields)); |
| 109 | 109 |
| 110 js.Expression code = new js.ArrayInitializer(elements); | 110 js.Expression code = new js.ArrayInitializer(elements); |
| 111 | 111 |
| 112 Map<String, dynamic> holes = | 112 Map<String, dynamic> holes = |
| 113 {'deferredInitializer': emitDeferredInitializerGlobal(program.loadMap), | 113 {'deferredInitializer': emitDeferredInitializerGlobal(program.loadMap), |
| 114 'holders': emitHolders(program.holders), | 114 'holders': emitHolders(program.holders), |
| 115 'tearOff': buildTearOffCode(backend), | 115 'tearOff': buildTearOffCode(backend), |
| 116 'parseFunctionDescriptor': | 116 'parseFunctionDescriptor': |
| 117 js.js.statement(parseFunctionDescriptorBoilerplate, | 117 js.js.statement(parseFunctionDescriptorBoilerplate, |
| 118 {'argCnt': js.string(namer.requiredParameterField), | 118 {'argumentCount': js.string(namer.requiredParameterField), |
| 119 'defArgValues': js.string(namer.defaultValuesField), | 119 'defaultArgumentValues': js.string(namer.defaultValuesField), |
| 120 'callName': js.string(namer.callNameField)}), | 120 'callName': js.string(namer.callNameField)}), |
| 121 | 121 |
| 122 'cyclicThrow': | 122 'cyclicThrow': |
| 123 backend.emitter.staticFunctionAccess(backend.getCyclicThrowHelper()), | 123 backend.emitter.staticFunctionAccess(backend.getCyclicThrowHelper()), |
| 124 'outputContainsConstantList': program.outputContainsConstantList, | 124 'outputContainsConstantList': program.outputContainsConstantList, |
| 125 'embeddedGlobals': emitEmbeddedGlobals(program), | 125 'embeddedGlobals': emitEmbeddedGlobals(program), |
| 126 'constants': emitConstants(fragment.constants), | 126 'constants': emitConstants(fragment.constants), |
| 127 'staticNonFinals': | 127 'staticNonFinals': |
| 128 emitStaticNonFinalFields(fragment.staticNonFinalFields), | 128 emitStaticNonFinalFields(fragment.staticNonFinalFields), |
| 129 'operatorIsPrefix': js.string(namer.operatorIsPrefix), | 129 'operatorIsPrefix': js.string(namer.operatorIsPrefix), |
| 130 'callName': js.string(namer.callNameField), | 130 'callName': js.string(namer.callNameField), |
| 131 'argumentCount': js.string(namer.requiredParameterField), |
| 132 'defaultArgumentValues': js.string(namer.defaultValuesField), |
| 131 'eagerClasses': emitEagerClassInitializations(fragment.libraries), | 133 'eagerClasses': emitEagerClassInitializations(fragment.libraries), |
| 132 'invokeMain': fragment.invokeMain, | 134 'invokeMain': fragment.invokeMain, |
| 133 'code': code}; | 135 'code': code}; |
| 134 | 136 |
| 135 holes.addAll(nativeHoles(program)); | 137 holes.addAll(nativeHoles(program)); |
| 136 | 138 |
| 137 return js.js.statement(boilerplate, holes); | 139 return js.js.statement(boilerplate, holes); |
| 138 } | 140 } |
| 139 | 141 |
| 140 Map<String, dynamic> nativeHoles(Program program) { | 142 Map<String, dynamic> nativeHoles(Program program) { |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 var stub = descriptor[pos + 2]; | 614 var stub = descriptor[pos + 2]; |
| 613 stub[#callName] = descriptor[pos + 1]; | 615 stub[#callName] = descriptor[pos + 1]; |
| 614 proto[descriptor[pos]] = stub; | 616 proto[descriptor[pos]] = stub; |
| 615 funs.push(stub); | 617 funs.push(stub); |
| 616 } | 618 } |
| 617 | 619 |
| 618 if (tearOffName) { | 620 if (tearOffName) { |
| 619 proto[tearOffName] = | 621 proto[tearOffName] = |
| 620 tearOff(funs, reflectionInfo, false, name, isIntercepted); | 622 tearOff(funs, reflectionInfo, false, name, isIntercepted); |
| 621 } | 623 } |
| 622 if (descriptor[pos] != null) { | 624 if (pos < descriptor.length) { |
| 623 f[#argCnt] = descriptor[pos]; | 625 f[#argumentCount] = descriptor[pos]; |
| 624 f[#defArgValues] = descriptor[pos + 1]; | 626 f[#defaultArgumentValues] = descriptor[pos + 1]; |
| 625 } | 627 } |
| 626 } else { | 628 } else { |
| 627 proto[name] = descriptor; | 629 proto[name] = descriptor; |
| 628 } | 630 } |
| 629 } | 631 } |
| 630 """; | 632 """; |
| 631 | 633 |
| 632 js.Expression _generateFunctionType(DartType memberType) { | 634 js.Expression _generateFunctionType(DartType memberType) { |
| 633 if (memberType.containsTypeVariables) { | 635 if (memberType.containsTypeVariables) { |
| 634 js.Expression thisAccess = js.js(r'this.$receiver'); | 636 js.Expression thisAccess = js.js(r'this.$receiver'); |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 824 }; | 826 }; |
| 825 } else { | 827 } else { |
| 826 // Parse the tear off information and generate compile handlers. | 828 // Parse the tear off information and generate compile handlers. |
| 827 // TODO(herhut): Share parser with instance methods. | 829 // TODO(herhut): Share parser with instance methods. |
| 828 function compileAllStubs() { | 830 function compileAllStubs() { |
| 829 var funs; | 831 var funs; |
| 830 var fun = compile(name, descriptor[0]); | 832 var fun = compile(name, descriptor[0]); |
| 831 fun[#callName] = descriptor[1]; | 833 fun[#callName] = descriptor[1]; |
| 832 holder[name] = fun; | 834 holder[name] = fun; |
| 833 funs = [fun]; | 835 funs = [fun]; |
| 834 for (var pos = 4; pos < descriptor.length; pos += 3) { | 836 // We iterate in blocks of 3 but have to stop before we reach the |
| 837 // (optional) two trailing items. To accomplish this, we only iterate |
| 838 // until we reach length - 2. |
| 839 for (var pos = 4; pos < descriptor.length - 2; pos += 3) { |
| 835 var stubName = descriptor[pos]; | 840 var stubName = descriptor[pos]; |
| 836 fun = compile(stubName, descriptor[pos + 2]); | 841 fun = compile(stubName, descriptor[pos + 2]); |
| 837 fun[#callName] = descriptor[pos + 1]; | 842 fun[#callName] = descriptor[pos + 1]; |
| 838 holder[stubName] = fun; | 843 holder[stubName] = fun; |
| 839 funs.push(fun); | 844 funs.push(fun); |
| 840 } | 845 } |
| 841 if (descriptor[2] != null) { // tear-off name. | 846 if (descriptor[2] != null) { // tear-off name. |
| 842 // functions, reflectionInfo, isStatic, name, isIntercepted. | 847 // functions, reflectionInfo, isStatic, name, isIntercepted. |
| 843 holder[descriptor[2]] = | 848 holder[descriptor[2]] = |
| 844 tearOff(funs, descriptor[3], true, name, false); | 849 tearOff(funs, descriptor[3], true, name, false); |
| 845 } | 850 } |
| 851 if (pos < descriptor.length) { |
| 852 fun[#argumentCount] = descriptor[pos]; |
| 853 fun[#defaultArgumentValues] = descriptor[pos + 1]; |
| 854 } |
| 846 } | 855 } |
| 847 | 856 |
| 848 function setupCompileAllAndDelegateStub(name) { | 857 function setupCompileAllAndDelegateStub(name) { |
| 849 holder[name] = function() { | 858 holder[name] = function() { |
| 850 compileAllStubs(); | 859 compileAllStubs(); |
| 851 return holder[name].apply(this, arguments); | 860 return holder[name].apply(this, arguments); |
| 852 }; | 861 }; |
| 853 } | 862 } |
| 854 | 863 |
| 855 setupCompileAllAndDelegateStub(name); | 864 setupCompileAllAndDelegateStub(name); |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1020 | 1029 |
| 1021 var end = Date.now(); | 1030 var end = Date.now(); |
| 1022 // print('Setup: ' + (end - start) + ' ms.'); | 1031 // print('Setup: ' + (end - start) + ' ms.'); |
| 1023 | 1032 |
| 1024 #invokeMain; // Start main. | 1033 #invokeMain; // Start main. |
| 1025 | 1034 |
| 1026 }(Date.now(), #code) | 1035 }(Date.now(), #code) |
| 1027 }"""; | 1036 }"""; |
| 1028 | 1037 |
| 1029 } | 1038 } |
| OLD | NEW |