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

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

Issue 1399773002: [Interpreter] Adds logical and, logical or and comma operators to interpreter (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Added a new bytecode to jump by casting the value to boolean. This reduces code size for logical op… Created 5 years, 2 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
Index: src/interpreter/bytecode-generator.cc
diff --git a/src/interpreter/bytecode-generator.cc b/src/interpreter/bytecode-generator.cc
index 2eb235df04c701bbbedcca3656b62b6eb6d33b88..f3db893557f2cb9e08697842203d251810984329 100644
--- a/src/interpreter/bytecode-generator.cc
+++ b/src/interpreter/bytecode-generator.cc
@@ -840,9 +840,13 @@ void BytecodeGenerator::VisitCountOperation(CountOperation* expr) {
void BytecodeGenerator::VisitBinaryOperation(BinaryOperation* binop) {
switch (binop->op()) {
case Token::COMMA:
+ VisitCommaExpression(binop);
+ break;
case Token::OR:
+ VisitLogicalOrExpression(binop);
+ break;
case Token::AND:
- UNIMPLEMENTED();
+ VisitLogicalAndExpression(binop);
break;
default:
VisitArithmeticExpression(binop);
@@ -940,6 +944,53 @@ void BytecodeGenerator::VisitArithmeticExpression(BinaryOperation* binop) {
}
+void BytecodeGenerator::VisitCommaExpression(BinaryOperation* binop) {
+ Expression* left = binop->left();
+ Expression* right = binop->right();
+
+ Visit(left);
+ Visit(right);
+}
+
+
+void BytecodeGenerator::VisitLogicalOrExpression(BinaryOperation* binop) {
+ Expression* left = binop->left();
+ Expression* right = binop->right();
+
+ // Short-circuit evaluation- If it is known that left is always true,
+ // no need to visit right
+ if (left->ToBooleanIsTrue()) {
+ Visit(left);
+ } else {
+ BytecodeLabel end_label;
+
+ Visit(left);
+ builder()->JumpIfToBooleanTrue(&end_label);
+ Visit(right);
+ builder()->Bind(&end_label);
+ }
+}
+
+
+void BytecodeGenerator::VisitLogicalAndExpression(BinaryOperation* binop) {
+ Expression* left = binop->left();
+ Expression* right = binop->right();
+
+ // Short-circuit evaluation- If it is known that left is always false,
+ // no need to visit right
+ if (left->ToBooleanIsFalse()) {
+ Visit(left);
+ } else {
+ BytecodeLabel end_label;
+
+ Visit(left);
+ builder()->JumpIfToBooleanFalse(&end_label);
+ Visit(right);
+ builder()->Bind(&end_label);
+ }
+}
+
+
LanguageMode BytecodeGenerator::language_mode() const {
return info()->language_mode();
}

Powered by Google App Engine
This is Rietveld 408576698