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

Unified Diff: src/fast-codegen.cc

Issue 340059: Add support for for loops to the toplevel code generator. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: src/fast-codegen.cc
===================================================================
--- src/fast-codegen.cc (revision 3198)
+++ src/fast-codegen.cc (working copy)
@@ -298,6 +298,7 @@
// Do not worry about optimizing for empty then or else bodies.
true_label_ = &then_part;
false_label_ = &else_part;
+ ASSERT(stmt->condition()->context() == Expression::kTest);
Visit(stmt->condition());
true_label_ = NULL;
false_label_ = NULL;
@@ -349,7 +350,33 @@
void FastCodeGenerator::VisitForStatement(ForStatement* stmt) {
- UNREACHABLE();
+ Label test, body, exit;
+ if (stmt->init() != NULL) Visit(stmt->init());
+
+ // Emit the test at the bottom of the loop (even if empty).
+ __ jmp(&test);
+ __ bind(&body);
+ Visit(stmt->body());
+ if (stmt->next() != NULL) Visit(stmt->next());
+
+ __ bind(&test);
+ if (stmt->cond() == NULL) {
+ // For an empty test jump to the top of the loop.
+ __ jmp(&body);
+ } else {
+ // We are not in an expression context because we have been compiling
+ // statements. Set up a test expression context for the condition.
+ ASSERT_EQ(NULL, true_label_);
+ ASSERT_EQ(NULL, false_label_);
+ true_label_ = &body;
+ false_label_ = &exit;
+ ASSERT(stmt->cond()->context() == Expression::kTest);
+ Visit(stmt->cond());
+ true_label_ = NULL;
+ false_label_ = NULL;
+ }
+
+ __ bind(&exit);
}
« src/compiler.cc ('K') | « src/compiler.cc ('k') | test/mjsunit/compiler/loops.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698