LibJS: Add AbstractEquals bytecode instruction for == comparison :^)

This commit is contained in:
Andreas Kling 2021-06-06 13:36:34 +02:00
parent 4bdfe73895
commit 0cc9d47e1b
3 changed files with 32 additions and 0 deletions

View file

@ -55,6 +55,9 @@ Optional<Bytecode::Register> BinaryExpression::generate_bytecode(Bytecode::Gener
case BinaryOp::AbstractInequals: case BinaryOp::AbstractInequals:
generator.emit<Bytecode::Op::AbstractInequals>(dst_reg, *lhs_reg, *rhs_reg); generator.emit<Bytecode::Op::AbstractInequals>(dst_reg, *lhs_reg, *rhs_reg);
return dst_reg; return dst_reg;
case BinaryOp::AbstractEquals:
generator.emit<Bytecode::Op::AbstractEquals>(dst_reg, *lhs_reg, *rhs_reg);
return dst_reg;
default: default:
TODO(); TODO();
} }

View file

@ -38,6 +38,11 @@ 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))); interpreter.reg(m_dst) = Value(!abstract_eq(interpreter.global_object(), interpreter.reg(m_src1), interpreter.reg(m_src2)));
} }
void AbstractEquals::execute(Bytecode::Interpreter& interpreter) const
{
interpreter.reg(m_dst) = Value(abstract_eq(interpreter.global_object(), interpreter.reg(m_src1), interpreter.reg(m_src2)));
}
void NewString::execute(Bytecode::Interpreter& interpreter) const void NewString::execute(Bytecode::Interpreter& interpreter) const
{ {
interpreter.reg(m_dst) = js_string(interpreter.vm(), m_string); interpreter.reg(m_dst) = js_string(interpreter.vm(), m_string);
@ -164,6 +169,11 @@ String AbstractInequals::to_string() const
return String::formatted("AbstractInequals dst:{}, src1:{}, src2:{}", m_dst, m_src1, m_src2); return String::formatted("AbstractInequals dst:{}, src1:{}, src2:{}", m_dst, m_src1, m_src2);
} }
String AbstractEquals::to_string() const
{
return String::formatted("AbstractEquals dst:{}, src1:{}, src2:{}", m_dst, m_src1, m_src2);
}
String NewString::to_string() const String NewString::to_string() const
{ {
return String::formatted("NewString dst:{}, string:\"{}\"", m_dst, m_string); return String::formatted("NewString dst:{}, string:\"{}\"", m_dst, m_string);

View file

@ -108,6 +108,25 @@ private:
Register m_src2; Register m_src2;
}; };
class AbstractEquals final : public Instruction {
public:
AbstractEquals(Register dst, Register src1, Register src2)
: m_dst(dst)
, m_src1(src1)
, m_src2(src2)
{
}
virtual ~AbstractEquals() 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 { class NewString final : public Instruction {
public: public:
NewString(Register dst, String string) NewString(Register dst, String string)