Chromium Code Reviews| 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 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 2077 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2088 for (ClassElement element in instantiatedClasses) { | 2088 for (ClassElement element in instantiatedClasses) { |
| 2089 for (ClassElement superclass = element.superclass; | 2089 for (ClassElement superclass = element.superclass; |
| 2090 superclass != null; | 2090 superclass != null; |
| 2091 superclass = superclass.superclass) { | 2091 superclass = superclass.superclass) { |
| 2092 if (neededClasses.contains(superclass)) break; | 2092 if (neededClasses.contains(superclass)) break; |
| 2093 neededClasses.add(superclass); | 2093 neededClasses.add(superclass); |
| 2094 } | 2094 } |
| 2095 } | 2095 } |
| 2096 } | 2096 } |
| 2097 | 2097 |
| 2098 void emitOneShotInterceptors(CodeBuffer buffer) { | |
|
kasperl
2013/01/24 07:19:14
How difficult would it be to build these one shot
ngeoffray
2013/01/24 08:39:15
As discussed, I agree it will be pretty neat to re
| |
| 2099 JavaScriptBackend backend = compiler.backend; | |
| 2100 for (Selector selector in backend.oneShotInterceptors) { | |
|
sra1
2013/01/23 21:21:30
These need to be sorted to have stable output.
It
ngeoffray
2013/01/24 08:39:15
Issue filed: https://code.google.com/p/dart/issues
| |
| 2101 Set<ClassElement> classes = backend.getInterceptedClassesOn(selector); | |
| 2102 String oneShotInterceptorName = namer.oneShotInterceptorName(selector); | |
| 2103 String getInterceptorName = | |
| 2104 namer.getInterceptorName(backend.getInterceptorMethod, classes); | |
| 2105 | |
| 2106 List<js.Parameter> parameters = <js.Parameter>[]; | |
| 2107 List<js.Expression> arguments = <js.Expression>[]; | |
| 2108 parameters.add(new js.Parameter('receiver')); | |
| 2109 arguments.add(new js.VariableUse('receiver')); | |
|
sra1
2013/01/23 21:21:30
also: js.use('receiver')
ngeoffray
2013/01/24 08:39:15
Done.
| |
| 2110 | |
| 2111 if (selector.isSetter()) { | |
| 2112 parameters.add(new js.Parameter('value')); | |
| 2113 arguments.add(new js.VariableUse('value')); | |
| 2114 } else { | |
| 2115 for (int i = 0; i < selector.argumentCount; i++) { | |
| 2116 String argName = 'a$i'; | |
| 2117 parameters.add(new js.Parameter(argName)); | |
| 2118 arguments.add(new js.VariableUse(argName)); | |
| 2119 } | |
| 2120 } | |
| 2121 | |
| 2122 String invocationName = backend.namer.invocationName(selector); | |
| 2123 js.Fun function = | |
| 2124 new js.Fun(parameters, | |
| 2125 new js.Block( | |
| 2126 <js.Statement>[ | |
| 2127 new js.Return( | |
|
sra1
2013/01/23 21:21:30
also: js.return_(x)
ngeoffray
2013/01/24 08:39:15
Done.
| |
| 2128 js.use(isolateProperties) | |
| 2129 .dot(getInterceptorName) | |
| 2130 .callWith([js.use('receiver')]) | |
| 2131 .dot(invocationName) | |
| 2132 .callWith(arguments))])); | |
| 2133 | |
| 2134 js.PropertyAccess property = | |
| 2135 js.fieldAccess(js.use(isolateProperties), oneShotInterceptorName); | |
| 2136 | |
| 2137 buffer.add(js.prettyPrint(js.assign(property, function), compiler)); | |
| 2138 buffer.add(N); | |
| 2139 } | |
| 2140 } | |
| 2141 | |
| 2098 String assembleProgram() { | 2142 String assembleProgram() { |
| 2099 measure(() { | 2143 measure(() { |
| 2100 computeNeededClasses(); | 2144 computeNeededClasses(); |
| 2101 | 2145 |
| 2102 mainBuffer.add(GENERATED_BY); | 2146 mainBuffer.add(GENERATED_BY); |
| 2103 if (!compiler.enableMinification) mainBuffer.add(HOOKS_API_USAGE); | 2147 if (!compiler.enableMinification) mainBuffer.add(HOOKS_API_USAGE); |
| 2104 mainBuffer.add('function ${namer.isolateName}()$_{}\n'); | 2148 mainBuffer.add('function ${namer.isolateName}()$_{}\n'); |
| 2105 mainBuffer.add('init()$N$n'); | 2149 mainBuffer.add('init()$N$n'); |
| 2106 // Shorten the code by using "$$" as temporary. | 2150 // Shorten the code by using "$$" as temporary. |
| 2107 classesCollector = r"$$"; | 2151 classesCollector = r"$$"; |
| 2108 mainBuffer.add('var $classesCollector$_=$_{}$N'); | 2152 mainBuffer.add('var $classesCollector$_=$_{}$N'); |
| 2109 // Shorten the code by using [namer.CURRENT_ISOLATE] as temporary. | 2153 // Shorten the code by using [namer.CURRENT_ISOLATE] as temporary. |
| 2110 isolateProperties = namer.CURRENT_ISOLATE; | 2154 isolateProperties = namer.CURRENT_ISOLATE; |
| 2111 mainBuffer.add( | 2155 mainBuffer.add( |
| 2112 'var $isolateProperties$_=$_$isolatePropertiesName$N'); | 2156 'var $isolateProperties$_=$_$isolatePropertiesName$N'); |
| 2113 emitClasses(mainBuffer); | 2157 emitClasses(mainBuffer); |
| 2114 mainBuffer.add(boundClosureBuffer); | 2158 mainBuffer.add(boundClosureBuffer); |
| 2115 // Clear the buffer, so that we can reuse it for the native classes. | 2159 // Clear the buffer, so that we can reuse it for the native classes. |
| 2116 boundClosureBuffer.clear(); | 2160 boundClosureBuffer.clear(); |
| 2117 emitStaticFunctions(mainBuffer); | 2161 emitStaticFunctions(mainBuffer); |
| 2118 emitStaticFunctionGetters(mainBuffer); | 2162 emitStaticFunctionGetters(mainBuffer); |
| 2119 // We need to finish the classes before we construct compile time | 2163 // We need to finish the classes before we construct compile time |
| 2120 // constants. | 2164 // constants. |
| 2121 emitFinishClassesInvocationIfNecessary(mainBuffer); | 2165 emitFinishClassesInvocationIfNecessary(mainBuffer); |
| 2122 emitRuntimeClassesAndTests(mainBuffer); | 2166 emitRuntimeClassesAndTests(mainBuffer); |
| 2123 emitCompileTimeConstants(mainBuffer); | 2167 emitCompileTimeConstants(mainBuffer); |
| 2124 // Static field initializations require the classes and compile-time | 2168 // Static field initializations require the classes and compile-time |
| 2125 // constants to be set up. | 2169 // constants to be set up. |
| 2126 emitStaticNonFinalFieldInitializations(mainBuffer); | 2170 emitStaticNonFinalFieldInitializations(mainBuffer); |
| 2171 emitOneShotInterceptors(mainBuffer); | |
| 2127 emitGetInterceptorMethods(mainBuffer); | 2172 emitGetInterceptorMethods(mainBuffer); |
| 2128 emitLazilyInitializedStaticFields(mainBuffer); | 2173 emitLazilyInitializedStaticFields(mainBuffer); |
| 2129 | 2174 |
| 2130 isolateProperties = isolatePropertiesName; | 2175 isolateProperties = isolatePropertiesName; |
| 2131 // The following code should not use the short-hand for the | 2176 // The following code should not use the short-hand for the |
| 2132 // initialStatics. | 2177 // initialStatics. |
| 2133 mainBuffer.add('var ${namer.CURRENT_ISOLATE}$_=${_}null$N'); | 2178 mainBuffer.add('var ${namer.CURRENT_ISOLATE}$_=${_}null$N'); |
| 2134 mainBuffer.add(boundClosureBuffer); | 2179 mainBuffer.add(boundClosureBuffer); |
| 2135 emitFinishClassesInvocationIfNecessary(mainBuffer); | 2180 emitFinishClassesInvocationIfNecessary(mainBuffer); |
| 2136 // After this assignment we will produce invalid JavaScript code if we use | 2181 // After this assignment we will produce invalid JavaScript code if we use |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2176 """; | 2221 """; |
| 2177 const String HOOKS_API_USAGE = """ | 2222 const String HOOKS_API_USAGE = """ |
| 2178 // The code supports the following hooks: | 2223 // The code supports the following hooks: |
| 2179 // dartPrint(message) - if this function is defined it is called | 2224 // dartPrint(message) - if this function is defined it is called |
| 2180 // instead of the Dart [print] method. | 2225 // instead of the Dart [print] method. |
| 2181 // dartMainRunner(main) - if this function is defined, the Dart [main] | 2226 // dartMainRunner(main) - if this function is defined, the Dart [main] |
| 2182 // method will not be invoked directly. | 2227 // method will not be invoked directly. |
| 2183 // Instead, a closure that will invoke [main] is | 2228 // Instead, a closure that will invoke [main] is |
| 2184 // passed to [dartMainRunner]. | 2229 // passed to [dartMainRunner]. |
| 2185 """; | 2230 """; |
| OLD | NEW |