Website Summary Files Commits Branches @commit @diff @stats
path: root / JSImpl / src
diff options
context:
space:
mode:
Commit09e59ae226f2fcb469b944c815b1e1bf46d4c569 (patch)
Author
 ValeriHristov <valeri.dhristov@gmail.com>
2018-11-25 17:49:14 +0200
Committer
 Martin Dobrev <martindobrev0@gmail.com>
2018-11-25 17:49:14 +0200
Filesd8273d7a27cab059957720e06dc19c2c0fd728d1 /JSImpl/src
IPL-09e59ae226f2fcb469b944c815b1e1bf46d4c569.tar
IPL-09e59ae226f2fcb469b944c815b1e1bf46d4c569.tar.gz
IPL-09e59ae226f2fcb469b944c815b1e1bf46d4c569.zip
Parent2425ccff65421e82dc406125c52b7bf804dcc918 (diff)
Implement comparison operators (#71)
* Implement comparison operators. * Remove debug code. * Undo test code.
2 files changed, 47 insertions, 5 deletions
-rw-r--r--JSImpl/src/ASTInterpreter.cpp9
-rw-r--r--JSImpl/src/ByteCodeGenerator.cpp43
diff --git a/JSImpl/src/ASTInterpreter.cpp b/JSImpl/src/ASTInterpreter.cpp
index f7d1dc2..25f5c02 100644
--- a/JSImpl/src/ASTInterpreter.cpp
+++ b/JSImpl/src/ASTInterpreter.cpp
@@ -185,6 +185,15 @@ void ASTInterpreter::Visit(BinaryExpression* e) {
case TokenType::Less:
m_Evaluation.push_back(left < right);
break;
+ case TokenType::LessEqual:
+ m_Evaluation.push_back(left <= right);
+ break;
+ case TokenType::Greater:
+ m_Evaluation.push_back(left > right);
+ break;
+ case TokenType::GreaterEqual:
+ m_Evaluation.push_back(left >= right);
+ break;
case TokenType::Comma:
m_Evaluation.push_back(right);
break;
diff --git a/JSImpl/src/ByteCodeGenerator.cpp b/JSImpl/src/ByteCodeGenerator.cpp
index dc846f2..fd85326 100644
--- a/JSImpl/src/ByteCodeGenerator.cpp
+++ b/JSImpl/src/ByteCodeGenerator.cpp
@@ -53,7 +53,11 @@ private:
SAVE,
RESTORE,
LESS,
+ LESSEQ,
+ GREATER,
+ GREATEREQ,
EQ,
+ NEQ,
LEQ,
GETG,
SETG,
@@ -282,11 +286,20 @@ void ByteCodeGenerator::Visit(BinaryExpression* e)
case TokenType::Less:
PushInstruction(Instruction::Type::LESS, o, l, r);
return;
+ case TokenType::LessEqual:
+ PushInstruction(Instruction::Type::LESSEQ, o, l, r);
+ return;
+ case TokenType::Greater:
+ PushInstruction(Instruction::Type::GREATER, o, l, r);
+ return;
+ case TokenType::GreaterEqual:
+ PushInstruction(Instruction::Type::GREATEREQ, o, l, r);
+ break;
case TokenType::EqualEqual:
PushInstruction(Instruction::Type::EQ, o, l, r);
return;
case TokenType::BangEqual:
- NOT_IMPLEMENTED;
+ PushInstruction(Instruction::Type::NEQ,o,l,r);
break;
case TokenType::Equal:
@@ -378,8 +391,8 @@ void ByteCodeGenerator::Visit(UnaryExpression* e)
PushInstruction(Instruction::Type::SUB, reg, reg, one);
}
return;
- default:
- NOT_IMPLEMENTED;
+ default:
+ NOT_IMPLEMENTED;
break;
}
}
@@ -427,8 +440,8 @@ void ByteCodeGenerator::Visit(UnaryExpression* e)
case TokenType::Bang:
NOT_IMPLEMENTED;
return;
- default:
- NOT_IMPLEMENTED;
+ default:
+ NOT_IMPLEMENTED;
break;
}
}
@@ -532,11 +545,31 @@ IPLString ByteCodeGenerator::GetCode()
+ " r" + std::to_string(ResolveRegisterName(i.Args[1]))
+ " r" + std::to_string(ResolveRegisterName(i.Args[2])) + '\n';
break;
+ case ByteCodeGenerator::Instruction::LESSEQ:
+ result += "lesseq r" + std::to_string(ResolveRegisterName(i.Args[0]))
+ + " r" + std::to_string(ResolveRegisterName(i.Args[1]))
+ + " r" + std::to_string(ResolveRegisterName(i.Args[2])) + '\n';
+ break;
+ case ByteCodeGenerator::Instruction::GREATER:
+ result += "greater r" + std::to_string(ResolveRegisterName(i.Args[0]))
+ + " r" + std::to_string(ResolveRegisterName(i.Args[1]))
+ + " r" + std::to_string(ResolveRegisterName(i.Args[2])) + '\n';
+ break;
+ case ByteCodeGenerator::Instruction::GREATEREQ:
+ result += "greatereq r" + std::to_string(ResolveRegisterName(i.Args[0]))
+ + " r" + std::to_string(ResolveRegisterName(i.Args[1]))
+ + " r" + std::to_string(ResolveRegisterName(i.Args[2])) + '\n';
+ break;
case ByteCodeGenerator::Instruction::EQ:
result += "eq r" + std::to_string(ResolveRegisterName(i.Args[0]))
+ " r" + std::to_string(ResolveRegisterName(i.Args[1]))
+ " r" + std::to_string(ResolveRegisterName(i.Args[2])) + '\n';
break;
+ case ByteCodeGenerator::Instruction::NEQ:
+ result += "neq r" + std::to_string(ResolveRegisterName(i.Args[0]))
+ + " r" + std::to_string(ResolveRegisterName(i.Args[1]))
+ + " r" + std::to_string(ResolveRegisterName(i.Args[2])) + '\n';
+ break;
case ByteCodeGenerator::Instruction::LEQ:
result += "leq r" + std::to_string(ResolveRegisterName(i.Args[0]))
+ " r" + std::to_string(ResolveRegisterName(i.Args[1]))