diff options
author | Gunnar Beutner <gbeutner@serenityos.org> | 2021-06-07 19:57:38 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-06-07 20:09:23 +0200 |
commit | 4be3374b24d3ea02b6fd2b7f0859f3b2a150dda8 (patch) | |
tree | ad9e67e207a66cb528a0dfacf961b90d93a0574d /Userland | |
parent | 73b8acf432f64e0488c60645e3cdc6bac6201f24 (diff) | |
download | serenity-4be3374b24d3ea02b6fd2b7f0859f3b2a150dda8.zip |
LibJS: Add bytecode ops for >, >= and <=
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp | 9 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Bytecode/Instruction.h | 3 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Bytecode/Op.cpp | 30 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Bytecode/Op.h | 57 |
4 files changed, 99 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp index 090dcb9114..7e21322583 100644 --- a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp +++ b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp @@ -61,9 +61,18 @@ Optional<Bytecode::Register> BinaryExpression::generate_bytecode(Bytecode::Gener case BinaryOp::Exponentiation: generator.emit<Bytecode::Op::Exp>(dst_reg, *lhs_reg, *rhs_reg); return dst_reg; + case BinaryOp::GreaterThan: + generator.emit<Bytecode::Op::GreaterThan>(dst_reg, *lhs_reg, *rhs_reg); + return dst_reg; + case BinaryOp::GreaterThanEquals: + generator.emit<Bytecode::Op::GreaterThanEquals>(dst_reg, *lhs_reg, *rhs_reg); + return dst_reg; case BinaryOp::LessThan: generator.emit<Bytecode::Op::LessThan>(dst_reg, *lhs_reg, *rhs_reg); return dst_reg; + case BinaryOp::LessThanEquals: + generator.emit<Bytecode::Op::LessThanEquals>(dst_reg, *lhs_reg, *rhs_reg); + return dst_reg; case BinaryOp::AbstractInequals: generator.emit<Bytecode::Op::AbstractInequals>(dst_reg, *lhs_reg, *rhs_reg); return dst_reg; diff --git a/Userland/Libraries/LibJS/Bytecode/Instruction.h b/Userland/Libraries/LibJS/Bytecode/Instruction.h index dc523ebf93..f38d6d03e6 100644 --- a/Userland/Libraries/LibJS/Bytecode/Instruction.h +++ b/Userland/Libraries/LibJS/Bytecode/Instruction.h @@ -17,7 +17,10 @@ O(Div) \ O(Mod) \ O(Exp) \ + O(GreaterThan) \ + O(GreaterThanEquals) \ O(LessThan) \ + O(LessThanEquals) \ O(AbstractInequals) \ O(AbstractEquals) \ O(NewString) \ diff --git a/Userland/Libraries/LibJS/Bytecode/Op.cpp b/Userland/Libraries/LibJS/Bytecode/Op.cpp index 512ab3f081..9ca9dac5b5 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Op.cpp @@ -82,11 +82,26 @@ void Exp::execute(Bytecode::Interpreter& interpreter) const interpreter.reg(m_dst) = exp(interpreter.global_object(), interpreter.reg(m_src1), interpreter.reg(m_src2)); } +void GreaterThan::execute(Bytecode::Interpreter& interpreter) const +{ + interpreter.reg(m_dst) = greater_than(interpreter.global_object(), interpreter.reg(m_src1), interpreter.reg(m_src2)); +} + +void GreaterThanEquals::execute(Bytecode::Interpreter& interpreter) const +{ + interpreter.reg(m_dst) = greater_than_equals(interpreter.global_object(), interpreter.reg(m_src1), interpreter.reg(m_src2)); +} + void LessThan::execute(Bytecode::Interpreter& interpreter) const { interpreter.reg(m_dst) = less_than(interpreter.global_object(), interpreter.reg(m_src1), interpreter.reg(m_src2)); } +void LessThanEquals::execute(Bytecode::Interpreter& interpreter) const +{ + interpreter.reg(m_dst) = less_than_equals(interpreter.global_object(), interpreter.reg(m_src1), interpreter.reg(m_src2)); +} + void AbstractInequals::execute(Bytecode::Interpreter& interpreter) const { interpreter.reg(m_dst) = Value(!abstract_eq(interpreter.global_object(), interpreter.reg(m_src1), interpreter.reg(m_src2))); @@ -233,11 +248,26 @@ String Exp::to_string() const return String::formatted("Exp dst:{}, src1:{}, src2:{}", m_dst, m_src1, m_src2); } +String GreaterThan::to_string() const +{ + return String::formatted("GreaterThan dst:{}, src1:{}, src2:{}", m_dst, m_src1, m_src2); +} + +String GreaterThanEquals::to_string() const +{ + return String::formatted("GreaterThanEquals dst:{}, src1:{}, src2:{}", m_dst, m_src1, m_src2); +} + String LessThan::to_string() const { return String::formatted("LessThan dst:{}, src1:{}, src2:{}", m_dst, m_src1, m_src2); } +String LessThanEquals::to_string() const +{ + return String::formatted("LessThanEquals dst:{}, src1:{}, src2:{}", m_dst, m_src1, m_src2); +} + String AbstractInequals::to_string() const { return String::formatted("AbstractInequals dst:{}, src1:{}, src2:{}", m_dst, m_src1, m_src2); diff --git a/Userland/Libraries/LibJS/Bytecode/Op.h b/Userland/Libraries/LibJS/Bytecode/Op.h index b718c8b85f..127e3085bf 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.h +++ b/Userland/Libraries/LibJS/Bytecode/Op.h @@ -146,6 +146,44 @@ private: Register m_src2; }; +class GreaterThan final : public Instruction { +public: + GreaterThan(Register dst, Register src1, Register src2) + : Instruction(Type::GreaterThan) + , m_dst(dst) + , m_src1(src1) + , m_src2(src2) + { + } + + void execute(Bytecode::Interpreter&) const; + String to_string() const; + +private: + Register m_dst; + Register m_src1; + Register m_src2; +}; + +class GreaterThanEquals final : public Instruction { +public: + GreaterThanEquals(Register dst, Register src1, Register src2) + : Instruction(Type::GreaterThanEquals) + , m_dst(dst) + , m_src1(src1) + , m_src2(src2) + { + } + + void execute(Bytecode::Interpreter&) const; + String to_string() const; + +private: + Register m_dst; + Register m_src1; + Register m_src2; +}; + class LessThan final : public Instruction { public: LessThan(Register dst, Register src1, Register src2) @@ -165,6 +203,25 @@ private: Register m_src2; }; +class LessThanEquals final : public Instruction { +public: + LessThanEquals(Register dst, Register src1, Register src2) + : Instruction(Type::LessThanEquals) + , m_dst(dst) + , m_src1(src1) + , m_src2(src2) + { + } + + void execute(Bytecode::Interpreter&) const; + String to_string() const; + +private: + Register m_dst; + Register m_src1; + Register m_src2; +}; + class AbstractInequals final : public Instruction { public: AbstractInequals(Register dst, Register src1, Register src2) |