LibJS: Add bytecode ops for &, | and ^

This commit is contained in:
Luke 2021-06-07 19:16:04 +01:00 committed by Andreas Kling
parent 4be3374b24
commit ae763f1ade
Notes: sideshowbarker 2024-07-18 12:41:11 +09:00
4 changed files with 100 additions and 1 deletions

View file

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

View file

@ -34,7 +34,10 @@
O(JumpIfTrue) \
O(Call) \
O(EnterScope) \
O(Return)
O(Return) \
O(BitwiseAnd) \
O(BitwiseOr) \
O(BitwiseXor)
namespace JS::Bytecode {

View file

@ -112,6 +112,21 @@ 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 BitwiseAnd::execute(Bytecode::Interpreter& interpreter) const
{
interpreter.reg(m_dst) = Value(bitwise_and(interpreter.global_object(), interpreter.reg(m_src1), interpreter.reg(m_src2)));
}
void BitwiseOr::execute(Bytecode::Interpreter& interpreter) const
{
interpreter.reg(m_dst) = Value(bitwise_or(interpreter.global_object(), interpreter.reg(m_src1), interpreter.reg(m_src2)));
}
void BitwiseXor::execute(Bytecode::Interpreter& interpreter) const
{
interpreter.reg(m_dst) = Value(bitwise_xor(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);
@ -278,6 +293,21 @@ String AbstractEquals::to_string() const
return String::formatted("AbstractEquals dst:{}, src1:{}, src2:{}", m_dst, m_src1, m_src2);
}
String BitwiseAnd::to_string() const
{
return String::formatted("BitwiseAnd dst:{}, src1:{}, src2:{}", m_dst, m_src1, m_src2);
}
String BitwiseOr::to_string() const
{
return String::formatted("BitwiseOr dst:{}, src1:{}, src2:{}", m_dst, m_src1, m_src2);
}
String BitwiseXor::to_string() const
{
return String::formatted("BitwiseXor dst:{}, src1:{}, src2:{}", m_dst, m_src1, m_src2);
}
String NewString::to_string() const
{
return String::formatted("NewString dst:{}, string:\"{}\"", m_dst, m_string);

View file

@ -260,6 +260,63 @@ private:
Register m_src2;
};
class BitwiseAnd final : public Instruction {
public:
BitwiseAnd(Register dst, Register src1, Register src2)
: Instruction(Type::BitwiseAnd)
, 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 BitwiseOr final : public Instruction {
public:
BitwiseOr(Register dst, Register src1, Register src2)
: Instruction(Type::BitwiseOr)
, 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 BitwiseXor final : public Instruction {
public:
BitwiseXor(Register dst, Register src1, Register src2)
: Instruction(Type::BitwiseXor)
, 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 NewString final : public Instruction {
public:
NewString(Register dst, String string)