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

Side by Side Diff: frog/leg/ssa/builder.dart

Issue 9378040: Allow self-referencing closures. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revert last update to CL. Created 8 years, 10 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 class Interceptors { 5 class Interceptors {
6 Compiler compiler; 6 Compiler compiler;
7 Interceptors(Compiler this.compiler); 7 Interceptors(Compiler this.compiler);
8 8
9 SourceString mapOperatorToMethodName(Operator op) { 9 SourceString mapOperatorToMethodName(Operator op) {
10 String name = op.source.stringValue; 10 String name = op.source.stringValue;
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 } 209 }
210 } 210 }
211 211
212 void startFunction(FunctionElement function, 212 void startFunction(FunctionElement function,
213 FunctionExpression node) { 213 FunctionExpression node) {
214 214
215 ClosureTranslator translator = 215 ClosureTranslator translator =
216 new ClosureTranslator(builder.compiler, builder.elements); 216 new ClosureTranslator(builder.compiler, builder.elements);
217 closureData = translator.translate(node); 217 closureData = translator.translate(node);
218 218
219 if (closureData.thisElement !== null && 219 if (closureData.thisElement !== null && !closureData.isClosure()) {
220 isAccessedDirectly(closureData.thisElement)) {
221 HInstruction thisInstruction = new HThis(); 220 HInstruction thisInstruction = new HThis();
221 builder.add(thisInstruction);
222 updateLocal(closureData.thisElement, thisInstruction); 222 updateLocal(closureData.thisElement, thisInstruction);
223 builder.add(thisInstruction);
224 } 223 }
225 224
226 FunctionParameters params = function.computeParameters(builder.compiler); 225 FunctionParameters params = function.computeParameters(builder.compiler);
227 params.forEachParameter((Element element) { 226 params.forEachParameter((Element element) {
228 HParameterValue parameter = new HParameterValue(element); 227 HParameterValue parameter = new HParameterValue(element);
229 builder.add(parameter); 228 builder.add(parameter);
230 // Note that for constructors [element] could be a field-element which we 229 // Note that for constructors [element] could be a field-element which we
231 // treat as if it was a local. 230 // treat as if it was a local.
232 directLocals[element] = parameter; 231 directLocals[element] = parameter;
233 }); 232 });
234 233
235 enterScope(node); 234 enterScope(node);
236 235
237 // If the freeVariableMapping is not empty, then this function was a 236 // If the freeVariableMapping is not empty, then this function was a
238 // nested closure that captures variables. Redirect the captured 237 // nested closure that captures variables. Redirect the captured
239 // variables to fields in the closure. 238 // variables to fields in the closure.
240 closureData.freeVariableMapping.forEach((Element from, Element to) { 239 closureData.freeVariableMapping.forEach((Element from, Element to) {
241 redirectElement(from, to); 240 redirectElement(from, to);
242 }); 241 });
242 // Inside closure redirect references to itself to [:this:].
243 if (closureData.isClosure()) {
244 HInstruction thisInstruction = new HThis();
245 builder.add(thisInstruction);
246 updateLocal(closureData.closureElement, thisInstruction);
ngeoffray 2012/02/13 10:13:38 Could you share some code with line 219? It looks
floitsch 2012/02/13 12:03:42 Refactored together.
247 }
243 } 248 }
244 249
245 /** 250 /**
246 * Returns true if the [For] loop declares a variable that is boxed. 251 * Returns true if the [For] loop declares a variable that is boxed.
247 */ 252 */
248 bool isForLoopDeclaringBoxedLoopVariable(Loop node) { 253 bool isForLoopDeclaringBoxedLoopVariable(Loop node) {
249 For forNode = node.asFor(); 254 For forNode = node.asFor();
250 if (forNode === null) return false; 255 if (forNode === null) return false;
251 if (forNode.initializer === null) return false; 256 if (forNode.initializer === null) return false;
252 VariableDefinitions definitions = 257 VariableDefinitions definitions =
(...skipping 1143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1396 1401
1397 visitClosureSend(Send node) { 1402 visitClosureSend(Send node) {
1398 Selector selector = elements.getSelector(node); 1403 Selector selector = elements.getSelector(node);
1399 assert(node.receiver === null); 1404 assert(node.receiver === null);
1400 Element element = elements[node]; 1405 Element element = elements[node];
1401 HInstruction closureTarget; 1406 HInstruction closureTarget;
1402 if (element === null) { 1407 if (element === null) {
1403 visit(node.selector); 1408 visit(node.selector);
1404 closureTarget = pop(); 1409 closureTarget = pop();
1405 } else { 1410 } else {
1406 assert(element.kind === ElementKind.VARIABLE || 1411 assert(Elements.isLocal(element));
1407 element.kind === ElementKind.PARAMETER);
1408 closureTarget = localsHandler.readLocal(element); 1412 closureTarget = localsHandler.readLocal(element);
1409 } 1413 }
1410 var inputs = <HInstruction>[]; 1414 var inputs = <HInstruction>[];
1411 inputs.add(closureTarget); 1415 inputs.add(closureTarget);
1412 addDynamicSendArgumentsToList(node, inputs); 1416 addDynamicSendArgumentsToList(node, inputs);
1413 push(new HInvokeClosure(selector, inputs)); 1417 push(new HInvokeClosure(selector, inputs));
1414 } 1418 }
1415 1419
1416 visitForeignSend(Send node) { 1420 visitForeignSend(Send node) {
1417 Identifier selector = node.selector; 1421 Identifier selector = node.selector;
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
1943 } 1947 }
1944 1948
1945 visitCatchBlock(CatchBlock node) { 1949 visitCatchBlock(CatchBlock node) {
1946 visit(node.block); 1950 visit(node.block);
1947 } 1951 }
1948 1952
1949 visitTypedef(Typedef node) { 1953 visitTypedef(Typedef node) {
1950 compiler.unimplemented('SsaBuilder.visitTypedef', node: node); 1954 compiler.unimplemented('SsaBuilder.visitTypedef', node: node);
1951 } 1955 }
1952 } 1956 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698