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

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

Issue 9148021: Implement for-in. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Made test work. Created 8 years, 11 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
« no previous file with comments | « frog/leg/resolver.dart ('k') | frog/leg/typechecker.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 1272 matching lines...) Expand 10 before | Expand all | Expand 10 after
1283 1283
1284 visitBreakStatement(BreakStatement node) { 1284 visitBreakStatement(BreakStatement node) {
1285 compiler.unimplemented('SsaBuilder.visitBreakStatement', node: node); 1285 compiler.unimplemented('SsaBuilder.visitBreakStatement', node: node);
1286 } 1286 }
1287 1287
1288 visitContinueStatement(ContinueStatement node) { 1288 visitContinueStatement(ContinueStatement node) {
1289 compiler.unimplemented('SsaBuilder.visitContinueStatement', node: node); 1289 compiler.unimplemented('SsaBuilder.visitContinueStatement', node: node);
1290 } 1290 }
1291 1291
1292 visitForInStatement(ForInStatement node) { 1292 visitForInStatement(ForInStatement node) {
1293 compiler.unimplemented('SsaBuilder.visitForInStatement', node: node); 1293 // Generate a structure equivalent to:
1294 // Iterator<E> $iter = <iterable>.iterator()
1295 // while ($iter.hasNext()) {
1296 // E <declaredIdentifier> = $iter.next();
1297 // <body>
1298 // }
1299 SourceString iteratorName = const SourceString("iterator");
1300
1301 Element interceptor = interceptors.getStaticInterceptor(iteratorName, 0);
1302 assert(interceptor != null);
1303 HStatic target = new HStatic(interceptor);
1304 add(target);
1305 visit(node.expression);
1306 List<HInstruction> inputs = <HInstruction>[target, pop()];
1307 HInstruction iterator = new HInvokeInterceptor("iterator", false, inputs);
1308 add(iterator);
1309
1310 Map initializerDefinitions = startLoop();
1311 HBasicBlock conditionBlock = current;
1312
1313 // The condition.
1314 String jsHasNextName =
1315 compiler.namer.instanceName(new SourceString("hasNext"));
1316 push(new HInvokeDynamicMethod(jsHasNextName, [iterator]));
1317 HBasicBlock conditionExitBlock = close(new HLoopBranch(popBoolified()));
1318
1319 Map conditionDefinitions =
1320 new Map<Element, HInstruction>.from(definitions);
1321
1322 // The body.
1323 HBasicBlock bodyBlock = addNewBlock();
1324 conditionExitBlock.addSuccessor(bodyBlock);
1325 open(bodyBlock);
1326
1327 VariableDefinitions definition = node.declaredIdentifier;
1328 Identifier identifier = definition.definitions.nodes.head;
1329 Element variable = elements[identifier];
1330 String jsNextName =
1331 compiler.namer.instanceName(new SourceString("next"));
1332 push(new HInvokeDynamicMethod(jsNextName, [iterator]));
1333 definitions[variable] = pop();
1334
1335 visit(node.body);
1336 if (isAborted()) {
1337 compiler.unimplemented("SsaBuilder for loop with aborting body");
1338 }
1339 bodyBlock = close(new HGoto());
1340
1341 // Update.
1342 // We create an update block, even when we are in a while loop. There the
1343 // update block is the jump-target for continue statements. We could avoid
1344 // the creation if there is no continue, but for now we always create it.
1345 HBasicBlock updateBlock = addNewBlock();
1346 bodyBlock.addSuccessor(updateBlock);
1347 open(updateBlock);
1348 updateBlock = close(new HGoto());
1349 // The back-edge completing the cycle.
1350 updateBlock.addSuccessor(conditionBlock);
1351 conditionBlock.postProcessLoopHeader();
1352
1353 endLoop(conditionBlock, conditionExitBlock, false, conditionDefinitions);
1294 } 1354 }
1295 1355
1296 visitLabelledStatement(LabelledStatement node) { 1356 visitLabelledStatement(LabelledStatement node) {
1297 compiler.unimplemented('SsaBuilder.visitLabelledStatement', node: node); 1357 compiler.unimplemented('SsaBuilder.visitLabelledStatement', node: node);
1298 } 1358 }
1299 1359
1300 visitLiteralMap(LiteralMap node) { 1360 visitLiteralMap(LiteralMap node) {
1301 compiler.unimplemented('SsaBuilder.visitLiteralMap', node: node); 1361 compiler.unimplemented('SsaBuilder.visitLiteralMap', node: node);
1302 } 1362 }
1303 1363
(...skipping 18 matching lines...) Expand all
1322 } 1382 }
1323 1383
1324 visitCatchBlock(CatchBlock node) { 1384 visitCatchBlock(CatchBlock node) {
1325 compiler.unimplemented('SsaBuilder.visitCatchBlock', node: node); 1385 compiler.unimplemented('SsaBuilder.visitCatchBlock', node: node);
1326 } 1386 }
1327 1387
1328 visitTypedef(Typedef node) { 1388 visitTypedef(Typedef node) {
1329 compiler.unimplemented('SsaBuilder.visitTypedef', node: node); 1389 compiler.unimplemented('SsaBuilder.visitTypedef', node: node);
1330 } 1390 }
1331 } 1391 }
OLDNEW
« no previous file with comments | « frog/leg/resolver.dart ('k') | frog/leg/typechecker.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698