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

Unified Diff: src/interpreter/bytecode-generator.cc

Issue 1343363002: [Interpreter] Basic flow control. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Switch test-bytecode-generator/IfConditions to use new style bytecode array check. Created 5 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/interpreter/bytecode-array-iterator.h ('k') | src/interpreter/bytecodes.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/interpreter/bytecode-generator.cc
diff --git a/src/interpreter/bytecode-generator.cc b/src/interpreter/bytecode-generator.cc
index 55fd7c9945a55af00637f40d07e81620cf9c0631..7257fd413422de3b43b4b146e3aa319b1e7b4264 100644
--- a/src/interpreter/bytecode-generator.cc
+++ b/src/interpreter/bytecode-generator.cc
@@ -45,13 +45,6 @@ Handle<BytecodeArray> BytecodeGenerator::MakeBytecode(CompilationInfo* info) {
// Visit statements in the function body.
VisitStatements(info->literal()->body());
- // If the last bytecode wasn't a return, then return 'undefined' to avoid
- // falling off the end.
- if (!builder_.HasExplicitReturn()) {
- builder_.LoadUndefined();
- builder_.Return();
- }
-
set_scope(nullptr);
set_info(nullptr);
return builder_.ToBytecodeArray();
@@ -59,6 +52,7 @@ Handle<BytecodeArray> BytecodeGenerator::MakeBytecode(CompilationInfo* info) {
void BytecodeGenerator::VisitBlock(Block* node) {
+ builder().EnterBlock();
if (node->scope() == NULL) {
// Visit statements in the same scope, no declarations.
VisitStatements(node->statements());
@@ -71,6 +65,7 @@ void BytecodeGenerator::VisitBlock(Block* node) {
VisitStatements(node->statements());
}
}
+ builder().LeaveBlock();
}
@@ -114,11 +109,26 @@ void BytecodeGenerator::VisitExpressionStatement(ExpressionStatement* stmt) {
void BytecodeGenerator::VisitEmptyStatement(EmptyStatement* stmt) {
- UNIMPLEMENTED();
+ // TODO(oth): For control-flow it could be useful to signal empty paths here.
}
-void BytecodeGenerator::VisitIfStatement(IfStatement* stmt) { UNIMPLEMENTED(); }
+void BytecodeGenerator::VisitIfStatement(IfStatement* stmt) {
+ BytecodeLabel else_start, else_end;
+ // TODO(oth): Spot easy cases where there code would not need to
+ // emit the then block or the else block, e.g. condition is
+ // obviously true/1/false/0.
+ Visit(stmt->condition());
+ builder().CastAccumulatorToBoolean();
+ builder().JumpIfFalse(&else_start);
+
+ Visit(stmt->then_statement());
+ builder().Jump(&else_end);
+ builder().Bind(&else_start);
+
+ Visit(stmt->else_statement());
+ builder().Bind(&else_end);
+}
void BytecodeGenerator::VisitSloppyBlockFunctionStatement(
@@ -478,7 +488,17 @@ void BytecodeGenerator::VisitBinaryOperation(BinaryOperation* binop) {
void BytecodeGenerator::VisitCompareOperation(CompareOperation* expr) {
- UNIMPLEMENTED();
+ Token::Value op = expr->op();
+ Expression* left = expr->left();
+ Expression* right = expr->right();
+
+ TemporaryRegisterScope temporary_register_scope(&builder_);
+ Register temporary = temporary_register_scope.NewRegister();
+
+ Visit(left);
+ builder().StoreAccumulatorInRegister(temporary);
+ Visit(right);
+ builder().CompareOperation(op, temporary, language_mode());
}
« no previous file with comments | « src/interpreter/bytecode-array-iterator.h ('k') | src/interpreter/bytecodes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698