Index: src/interpreter/bytecode-generator.cc |
diff --git a/src/interpreter/bytecode-generator.cc b/src/interpreter/bytecode-generator.cc |
index 2a330ca87059de709f9d3ab3c91039b6738ee064..b561b7fcb118ad983a0b2672ac40fd12cd355685 100644 |
--- a/src/interpreter/bytecode-generator.cc |
+++ b/src/interpreter/bytecode-generator.cc |
@@ -114,11 +114,25 @@ void BytecodeGenerator::VisitExpressionStatement(ExpressionStatement* stmt) { |
void BytecodeGenerator::VisitEmptyStatement(EmptyStatement* stmt) { |
- UNIMPLEMENTED(); |
+ // For control-flow it could be useful to signal empty paths here. |
} |
-void BytecodeGenerator::VisitIfStatement(IfStatement* stmt) { UNIMPLEMENTED(); } |
+void BytecodeGenerator::VisitIfStatement(IfStatement* stmt) { |
+ // TODO(oth): spot easy cases if (true/1/false/0)? |
+ BytecodeLabel else_start, else_end; |
+ Visit(stmt->condition()); |
+ // TODO(oth) This cast may need to be pushed down the evaluation stack |
+ // when logical connectives are implemented, e.g. &&, ||, etc. Optimization |
Michael Starzinger
2015/09/23 08:46:24
I am not sure what this TODO refers to exactly, bu
oth
2015/09/23 10:46:56
Sorry about the wording here.
Basically, the goal
|
+ // opportunities too in bytecode-array-builder.cc. |
+ 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::VisitContinueStatement(ContinueStatement* stmt) { |
@@ -452,7 +466,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()); |
} |