mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:37:35 +00:00
LibJS: Add bytecode instructions for modulo and exponentiation
This commit is contained in:
parent
6af9d87258
commit
55f0791b13
4 changed files with 66 additions and 0 deletions
|
@ -55,6 +55,12 @@ Optional<Bytecode::Register> BinaryExpression::generate_bytecode(Bytecode::Gener
|
||||||
case BinaryOp::Division:
|
case BinaryOp::Division:
|
||||||
generator.emit<Bytecode::Op::Div>(dst_reg, *lhs_reg, *rhs_reg);
|
generator.emit<Bytecode::Op::Div>(dst_reg, *lhs_reg, *rhs_reg);
|
||||||
return dst_reg;
|
return dst_reg;
|
||||||
|
case BinaryOp::Modulo:
|
||||||
|
generator.emit<Bytecode::Op::Mod>(dst_reg, *lhs_reg, *rhs_reg);
|
||||||
|
return dst_reg;
|
||||||
|
case BinaryOp::Exponentiation:
|
||||||
|
generator.emit<Bytecode::Op::Exp>(dst_reg, *lhs_reg, *rhs_reg);
|
||||||
|
return dst_reg;
|
||||||
case BinaryOp::LessThan:
|
case BinaryOp::LessThan:
|
||||||
generator.emit<Bytecode::Op::LessThan>(dst_reg, *lhs_reg, *rhs_reg);
|
generator.emit<Bytecode::Op::LessThan>(dst_reg, *lhs_reg, *rhs_reg);
|
||||||
return dst_reg;
|
return dst_reg;
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
O(Sub) \
|
O(Sub) \
|
||||||
O(Mul) \
|
O(Mul) \
|
||||||
O(Div) \
|
O(Div) \
|
||||||
|
O(Mod) \
|
||||||
|
O(Exp) \
|
||||||
O(LessThan) \
|
O(LessThan) \
|
||||||
O(AbstractInequals) \
|
O(AbstractInequals) \
|
||||||
O(AbstractEquals) \
|
O(AbstractEquals) \
|
||||||
|
|
|
@ -72,6 +72,16 @@ void Div::execute(Bytecode::Interpreter& interpreter) const
|
||||||
interpreter.reg(m_dst) = div(interpreter.global_object(), interpreter.reg(m_src1), interpreter.reg(m_src2));
|
interpreter.reg(m_dst) = div(interpreter.global_object(), interpreter.reg(m_src1), interpreter.reg(m_src2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Mod::execute(Bytecode::Interpreter& interpreter) const
|
||||||
|
{
|
||||||
|
interpreter.reg(m_dst) = mod(interpreter.global_object(), interpreter.reg(m_src1), interpreter.reg(m_src2));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Exp::execute(Bytecode::Interpreter& interpreter) const
|
||||||
|
{
|
||||||
|
interpreter.reg(m_dst) = exp(interpreter.global_object(), interpreter.reg(m_src1), interpreter.reg(m_src2));
|
||||||
|
}
|
||||||
|
|
||||||
void LessThan::execute(Bytecode::Interpreter& interpreter) const
|
void LessThan::execute(Bytecode::Interpreter& interpreter) const
|
||||||
{
|
{
|
||||||
interpreter.reg(m_dst) = less_than(interpreter.global_object(), interpreter.reg(m_src1), interpreter.reg(m_src2));
|
interpreter.reg(m_dst) = less_than(interpreter.global_object(), interpreter.reg(m_src1), interpreter.reg(m_src2));
|
||||||
|
@ -213,6 +223,16 @@ String Div::to_string() const
|
||||||
return String::formatted("Div dst:{}, src1:{}, src2:{}", m_dst, m_src1, m_src2);
|
return String::formatted("Div dst:{}, src1:{}, src2:{}", m_dst, m_src1, m_src2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String Mod::to_string() const
|
||||||
|
{
|
||||||
|
return String::formatted("Mod dst:{}, src1:{}, src2:{}", m_dst, m_src1, m_src2);
|
||||||
|
}
|
||||||
|
|
||||||
|
String Exp::to_string() const
|
||||||
|
{
|
||||||
|
return String::formatted("Exp dst:{}, src1:{}, src2:{}", m_dst, m_src1, m_src2);
|
||||||
|
}
|
||||||
|
|
||||||
String LessThan::to_string() const
|
String LessThan::to_string() const
|
||||||
{
|
{
|
||||||
return String::formatted("LessThan dst:{}, src1:{}, src2:{}", m_dst, m_src1, m_src2);
|
return String::formatted("LessThan dst:{}, src1:{}, src2:{}", m_dst, m_src1, m_src2);
|
||||||
|
|
|
@ -108,6 +108,44 @@ private:
|
||||||
Register m_src2;
|
Register m_src2;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Mod final : public Instruction {
|
||||||
|
public:
|
||||||
|
Mod(Register dst, Register src1, Register src2)
|
||||||
|
: Instruction(Type::Mod)
|
||||||
|
, 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 Exp final : public Instruction {
|
||||||
|
public:
|
||||||
|
Exp(Register dst, Register src1, Register src2)
|
||||||
|
: Instruction(Type::Exp)
|
||||||
|
, 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 {
|
class LessThan final : public Instruction {
|
||||||
public:
|
public:
|
||||||
LessThan(Register dst, Register src1, Register src2)
|
LessThan(Register dst, Register src1, Register src2)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue