mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 09:30:24 +00:00
LibJS: Add Sub bytecode instruction (subtract values)
This commit is contained in:
parent
23a4448862
commit
2b9fbd10ed
Notes:
sideshowbarker
2024-07-18 12:42:41 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/2b9fbd10ed7
3 changed files with 35 additions and 3 deletions
|
@ -2264,12 +2264,15 @@ Optional<Bytecode::Register> BinaryExpression::generate_bytecode(Bytecode::Gener
|
|||
VERIFY(lhs_reg.has_value());
|
||||
VERIFY(rhs_reg.has_value());
|
||||
|
||||
auto dst_reg = generator.allocate_register();
|
||||
|
||||
switch (m_op) {
|
||||
case BinaryOp::Addition: {
|
||||
auto dst_reg = generator.allocate_register();
|
||||
case BinaryOp::Addition:
|
||||
generator.emit<Bytecode::Op::Add>(dst_reg, *lhs_reg, *rhs_reg);
|
||||
return dst_reg;
|
||||
}
|
||||
case BinaryOp::Subtraction:
|
||||
generator.emit<Bytecode::Op::Sub>(dst_reg, *lhs_reg, *rhs_reg);
|
||||
return dst_reg;
|
||||
default:
|
||||
TODO();
|
||||
}
|
||||
|
|
|
@ -21,6 +21,11 @@ void Add::execute(Bytecode::Interpreter& interpreter) const
|
|||
interpreter.reg(m_dst) = add(interpreter.global_object(), interpreter.reg(m_src1), interpreter.reg(m_src2));
|
||||
}
|
||||
|
||||
void Sub::execute(Bytecode::Interpreter& interpreter) const
|
||||
{
|
||||
interpreter.reg(m_dst) = sub(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);
|
||||
|
@ -46,6 +51,11 @@ String Add::to_string() const
|
|||
return String::formatted("Add dst:{}, src1:{}, src2:{}", m_dst, m_src1, m_src2);
|
||||
}
|
||||
|
||||
String Sub::to_string() const
|
||||
{
|
||||
return String::formatted("Sub dst:{}, src1:{}, src2:{}", m_dst, m_src1, m_src2);
|
||||
}
|
||||
|
||||
String NewString::to_string() const
|
||||
{
|
||||
return String::formatted("NewString dst:{}, string:\"{}\"", m_dst, m_string);
|
||||
|
|
|
@ -50,6 +50,25 @@ private:
|
|||
Register m_src2;
|
||||
};
|
||||
|
||||
class Sub final : public Instruction {
|
||||
public:
|
||||
Sub(Register dst, Register src1, Register src2)
|
||||
: m_dst(dst)
|
||||
, m_src1(src1)
|
||||
, m_src2(src2)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~Sub() 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)
|
||||
|
|
Loading…
Reference in a new issue