summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-06-04 12:03:57 +0200
committerAndreas Kling <kling@serenityos.org>2021-06-07 18:11:59 +0200
commit91640d0727e6a4d9ff24417909e02d77547c89df (patch)
tree1be8bd721b9b89bb9c56468a25d9b07b68f7ff07 /Userland
parent6d66cdc668756b6f43fec99a033bca477462a968 (diff)
downloadserenity-91640d0727e6a4d9ff24417909e02d77547c89df.zip
LibJS: Add LessThan bytecode instruction :^)
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp3
-rw-r--r--Userland/Libraries/LibJS/Bytecode/Op.cpp10
-rw-r--r--Userland/Libraries/LibJS/Bytecode/Op.h19
3 files changed, 32 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp
index 5f349dd2ea..b6adc70c21 100644
--- a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp
+++ b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp
@@ -48,6 +48,9 @@ Optional<Bytecode::Register> BinaryExpression::generate_bytecode(Bytecode::Gener
case BinaryOp::Subtraction:
generator.emit<Bytecode::Op::Sub>(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;
default:
TODO();
}
diff --git a/Userland/Libraries/LibJS/Bytecode/Op.cpp b/Userland/Libraries/LibJS/Bytecode/Op.cpp
index 570bcff112..1d975150f7 100644
--- a/Userland/Libraries/LibJS/Bytecode/Op.cpp
+++ b/Userland/Libraries/LibJS/Bytecode/Op.cpp
@@ -26,6 +26,11 @@ void Sub::execute(Bytecode::Interpreter& interpreter) const
interpreter.reg(m_dst) = sub(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 NewString::execute(Bytecode::Interpreter& interpreter) const
{
interpreter.reg(m_dst) = js_string(interpreter.vm(), m_string);
@@ -56,6 +61,11 @@ String Sub::to_string() const
return String::formatted("Sub 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 NewString::to_string() const
{
return String::formatted("NewString dst:{}, string:\"{}\"", m_dst, m_string);
diff --git a/Userland/Libraries/LibJS/Bytecode/Op.h b/Userland/Libraries/LibJS/Bytecode/Op.h
index 93fc951483..14a6ef1f8f 100644
--- a/Userland/Libraries/LibJS/Bytecode/Op.h
+++ b/Userland/Libraries/LibJS/Bytecode/Op.h
@@ -69,6 +69,25 @@ private:
Register m_src2;
};
+class LessThan final : public Instruction {
+public:
+ LessThan(Register dst, Register src1, Register src2)
+ : m_dst(dst)
+ , m_src1(src1)
+ , m_src2(src2)
+ {
+ }
+
+ virtual ~LessThan() override { }
+ virtual void execute(Bytecode::Interpreter&) const override;
+ virtual String to_string() const override;
+
+private:
+ Register m_dst;
+ Register m_src1;
+ Register m_src2;
+};
+
class NewString final : public Instruction {
public:
NewString(Register dst, String string)