Revision: 3250
Author: [email protected]
Date: Mon Nov  9 05:22:38 2009
Log: Fast-compiler: Added trivial implementations of while and do/while.

Review URL: http://codereview.chromium.org/372055

http://code.google.com/p/v8/source/detail?r=3250

Modified:
  /branches/bleeding_edge/src/compiler.cc
  /branches/bleeding_edge/src/fast-codegen.cc

=======================================
--- /branches/bleeding_edge/src/compiler.cc     Mon Nov  9 02:30:33 2009
+++ /branches/bleeding_edge/src/compiler.cc     Mon Nov  9 05:22:38 2009
@@ -708,12 +708,20 @@


  void CodeGenSelector::VisitDoWhileStatement(DoWhileStatement* stmt) {
-  BAILOUT("DoWhileStatement");
+  // We do not handle loops with breaks or continue statements in their
+  // body.  We will bailout when we hit those statements in the body.
+  ProcessExpression(stmt->cond(), Expression::kTest);
+  CHECK_BAILOUT;
+  Visit(stmt->body());
  }


  void CodeGenSelector::VisitWhileStatement(WhileStatement* stmt) {
-  BAILOUT("WhileStatement");
+  // We do not handle loops with breaks or continue statements in their
+  // body.  We will bailout when we hit those statements in the body.
+  ProcessExpression(stmt->cond(), Expression::kTest);
+  CHECK_BAILOUT;
+  Visit(stmt->body());
  }


=======================================
--- /branches/bleeding_edge/src/fast-codegen.cc Thu Nov  5 09:33:50 2009
+++ /branches/bleeding_edge/src/fast-codegen.cc Mon Nov  9 05:22:38 2009
@@ -304,12 +304,53 @@


  void FastCodeGenerator::VisitDoWhileStatement(DoWhileStatement* stmt) {
-  UNREACHABLE();
+  Comment cmnt(masm_, "[ DoWhileStatement");
+  increment_loop_depth();
+  Label body, exit;
+
+  // Emit the test at the bottom of the loop.
+  __ bind(&body);
+  Visit(stmt->body());
+
+  // 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());
+
+  __ bind(&exit);
+
+  decrement_loop_depth();
  }


  void FastCodeGenerator::VisitWhileStatement(WhileStatement* stmt) {
-  UNREACHABLE();
+  Comment cmnt(masm_, "[ WhileStatement");
+  increment_loop_depth();
+  Label test, body, exit;
+
+  // Emit the test at the bottom of the loop.
+  __ jmp(&test);
+
+  __ bind(&body);
+  Visit(stmt->body());
+
+  __ bind(&test);
+  // 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());
+
+  __ bind(&exit);
+
+  decrement_loop_depth();
  }



--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to