1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-30 23:28:12 +00:00

LibJS: Add bytecode generation for BinaryOp::InstanceOf

This commit is contained in:
Linus Groh 2021-06-07 21:18:19 +01:00
parent 5e996de8c6
commit 9c0d83d11d
4 changed files with 35 additions and 2 deletions

View file

@ -113,8 +113,11 @@ Optional<Bytecode::Register> BinaryExpression::generate_bytecode(Bytecode::Gener
case BinaryOp::In: case BinaryOp::In:
generator.emit<Bytecode::Op::In>(dst_reg, *lhs_reg, *rhs_reg); generator.emit<Bytecode::Op::In>(dst_reg, *lhs_reg, *rhs_reg);
return dst_reg; return dst_reg;
case BinaryOp::InstanceOf:
generator.emit<Bytecode::Op::InstanceOf>(dst_reg, *lhs_reg, *rhs_reg);
return dst_reg;
default: default:
TODO(); VERIFY_NOT_REACHED();
} }
} }

View file

@ -49,7 +49,8 @@
O(LeftShift) \ O(LeftShift) \
O(RightShift) \ O(RightShift) \
O(UnsignedRightShift) \ O(UnsignedRightShift) \
O(In) O(In) \
O(InstanceOf)
namespace JS::Bytecode { namespace JS::Bytecode {

View file

@ -163,6 +163,11 @@ void In::execute(Bytecode::Interpreter& interpreter) const
interpreter.reg(m_dst) = in(interpreter.global_object(), interpreter.reg(m_src1), interpreter.reg(m_src2)); interpreter.reg(m_dst) = in(interpreter.global_object(), interpreter.reg(m_src1), interpreter.reg(m_src2));
} }
void InstanceOf::execute(Bytecode::Interpreter& interpreter) const
{
interpreter.reg(m_dst) = instance_of(interpreter.global_object(), interpreter.reg(m_src1), interpreter.reg(m_src2));
}
void BitwiseNot::execute(Bytecode::Interpreter& interpreter) const void BitwiseNot::execute(Bytecode::Interpreter& interpreter) const
{ {
interpreter.reg(m_dst) = bitwise_not(interpreter.global_object(), interpreter.reg(m_src)); interpreter.reg(m_dst) = bitwise_not(interpreter.global_object(), interpreter.reg(m_src));
@ -405,6 +410,11 @@ String In::to_string() const
return String::formatted("In dst:{}, src1:{}, src2:{}", m_dst, m_src1, m_src2); return String::formatted("In dst:{}, src1:{}, src2:{}", m_dst, m_src1, m_src2);
} }
String InstanceOf::to_string() const
{
return String::formatted("In dst:{}, src1:{}, src2:{}", m_dst, m_src1, m_src2);
}
String BitwiseNot::to_string() const String BitwiseNot::to_string() const
{ {
return String::formatted("BitwiseNot dst:{}, src:{}", m_dst, m_src); return String::formatted("BitwiseNot dst:{}, src:{}", m_dst, m_src);

View file

@ -449,6 +449,25 @@ private:
Register m_src2; Register m_src2;
}; };
class InstanceOf final : public Instruction {
public:
InstanceOf(Register dst, Register src1, Register src2)
: Instruction(Type::InstanceOf)
, 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 BitwiseNot final : public Instruction { class BitwiseNot final : public Instruction {
public: public:
BitwiseNot(Register dst, Register src) BitwiseNot(Register dst, Register src)