summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp6
-rw-r--r--Userland/Libraries/LibJS/Bytecode/Instruction.h2
-rw-r--r--Userland/Libraries/LibJS/Bytecode/Op.cpp20
-rw-r--r--Userland/Libraries/LibJS/Bytecode/Op.h38
4 files changed, 66 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp
index d8d06feabf..b3e7f2da49 100644
--- a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp
+++ b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp
@@ -49,6 +49,12 @@ 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::Multiplication:
+ generator.emit<Bytecode::Op::Mul>(dst_reg, *lhs_reg, *rhs_reg);
+ return dst_reg;
+ case BinaryOp::Division:
+ generator.emit<Bytecode::Op::Div>(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;
diff --git a/Userland/Libraries/LibJS/Bytecode/Instruction.h b/Userland/Libraries/LibJS/Bytecode/Instruction.h
index 62d3d6ca30..3c2c04aa88 100644
--- a/Userland/Libraries/LibJS/Bytecode/Instruction.h
+++ b/Userland/Libraries/LibJS/Bytecode/Instruction.h
@@ -13,6 +13,8 @@
O(Load) \
O(Add) \
O(Sub) \
+ O(Mul) \
+ O(Div) \
O(LessThan) \
O(AbstractInequals) \
O(AbstractEquals) \
diff --git a/Userland/Libraries/LibJS/Bytecode/Op.cpp b/Userland/Libraries/LibJS/Bytecode/Op.cpp
index 51d0d63ece..e98aeac56e 100644
--- a/Userland/Libraries/LibJS/Bytecode/Op.cpp
+++ b/Userland/Libraries/LibJS/Bytecode/Op.cpp
@@ -62,6 +62,16 @@ void Sub::execute(Bytecode::Interpreter& interpreter) const
interpreter.reg(m_dst) = sub(interpreter.global_object(), interpreter.reg(m_src1), interpreter.reg(m_src2));
}
+void Mul::execute(Bytecode::Interpreter& interpreter) const
+{
+ interpreter.reg(m_dst) = mul(interpreter.global_object(), interpreter.reg(m_src1), interpreter.reg(m_src2));
+}
+
+void Div::execute(Bytecode::Interpreter& interpreter) const
+{
+ interpreter.reg(m_dst) = div(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));
@@ -193,6 +203,16 @@ String Sub::to_string() const
return String::formatted("Sub dst:{}, src1:{}, src2:{}", m_dst, m_src1, m_src2);
}
+String Mul::to_string() const
+{
+ return String::formatted("Mul dst:{}, src1:{}, src2:{}", m_dst, m_src1, m_src2);
+}
+
+String Div::to_string() const
+{
+ return String::formatted("Div 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);
diff --git a/Userland/Libraries/LibJS/Bytecode/Op.h b/Userland/Libraries/LibJS/Bytecode/Op.h
index 289f0bef73..d45779b783 100644
--- a/Userland/Libraries/LibJS/Bytecode/Op.h
+++ b/Userland/Libraries/LibJS/Bytecode/Op.h
@@ -70,6 +70,44 @@ private:
Register m_src2;
};
+class Mul final : public Instruction {
+public:
+ Mul(Register dst, Register src1, Register src2)
+ : Instruction(Type::Mul)
+ , 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 Div final : public Instruction {
+public:
+ Div(Register dst, Register src1, Register src2)
+ : Instruction(Type::Div)
+ , 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)