mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
LibJS: Add bytecode ops for &, | and ^
This commit is contained in:
parent
4be3374b24
commit
ae763f1ade
Notes:
sideshowbarker
2024-07-18 12:41:11 +09:00
Author: https://github.com/Lubrsi Commit: https://github.com/SerenityOS/serenity/commit/ae763f1ade0 Pull-request: https://github.com/SerenityOS/serenity/pull/7886
4 changed files with 100 additions and 1 deletions
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -34,7 +34,10 @@
|
|||
O(JumpIfTrue) \
|
||||
O(Call) \
|
||||
O(EnterScope) \
|
||||
O(Return)
|
||||
O(Return) \
|
||||
O(BitwiseAnd) \
|
||||
O(BitwiseOr) \
|
||||
O(BitwiseXor)
|
||||
|
||||
namespace JS::Bytecode {
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue