mirror of
https://github.com/RGBCube/serenity
synced 2025-05-19 00:45:08 +00:00
LibJS: Add bytecode ops for <<, >> and >>>
This commit is contained in:
parent
6681415f58
commit
1e10965e61
4 changed files with 100 additions and 1 deletions
|
@ -99,6 +99,15 @@ Optional<Bytecode::Register> BinaryExpression::generate_bytecode(Bytecode::Gener
|
||||||
case BinaryOp::BitwiseXor:
|
case BinaryOp::BitwiseXor:
|
||||||
generator.emit<Bytecode::Op::BitwiseXor>(dst_reg, *lhs_reg, *rhs_reg);
|
generator.emit<Bytecode::Op::BitwiseXor>(dst_reg, *lhs_reg, *rhs_reg);
|
||||||
return dst_reg;
|
return dst_reg;
|
||||||
|
case BinaryOp::LeftShift:
|
||||||
|
generator.emit<Bytecode::Op::LeftShift>(dst_reg, *lhs_reg, *rhs_reg);
|
||||||
|
return dst_reg;
|
||||||
|
case BinaryOp::RightShift:
|
||||||
|
generator.emit<Bytecode::Op::RightShift>(dst_reg, *lhs_reg, *rhs_reg);
|
||||||
|
return dst_reg;
|
||||||
|
case BinaryOp::UnsignedRightShift:
|
||||||
|
generator.emit<Bytecode::Op::UnsignedRightShift>(dst_reg, *lhs_reg, *rhs_reg);
|
||||||
|
return dst_reg;
|
||||||
default:
|
default:
|
||||||
TODO();
|
TODO();
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,10 @@
|
||||||
O(Not) \
|
O(Not) \
|
||||||
O(UnaryPlus) \
|
O(UnaryPlus) \
|
||||||
O(UnaryMinus) \
|
O(UnaryMinus) \
|
||||||
O(Typeof)
|
O(Typeof) \
|
||||||
|
O(LeftShift) \
|
||||||
|
O(RightShift) \
|
||||||
|
O(UnsignedRightShift)
|
||||||
|
|
||||||
namespace JS::Bytecode {
|
namespace JS::Bytecode {
|
||||||
|
|
||||||
|
|
|
@ -142,6 +142,21 @@ 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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LeftShift::execute(Bytecode::Interpreter& interpreter) const
|
||||||
|
{
|
||||||
|
interpreter.reg(m_dst) = left_shift(interpreter.global_object(), interpreter.reg(m_src1), interpreter.reg(m_src2));
|
||||||
|
}
|
||||||
|
|
||||||
|
void RightShift::execute(Bytecode::Interpreter& interpreter) const
|
||||||
|
{
|
||||||
|
interpreter.reg(m_dst) = right_shift(interpreter.global_object(), interpreter.reg(m_src1), interpreter.reg(m_src2));
|
||||||
|
}
|
||||||
|
|
||||||
|
void UnsignedRightShift::execute(Bytecode::Interpreter& interpreter) const
|
||||||
|
{
|
||||||
|
interpreter.reg(m_dst) = unsigned_right_shift(interpreter.global_object(), interpreter.reg(m_src1), interpreter.reg(m_src2));
|
||||||
|
}
|
||||||
|
|
||||||
void Not::execute(Bytecode::Interpreter& interpreter) const
|
void Not::execute(Bytecode::Interpreter& interpreter) const
|
||||||
{
|
{
|
||||||
interpreter.reg(m_dst) = Value(!interpreter.reg(m_src).to_boolean());
|
interpreter.reg(m_dst) = Value(!interpreter.reg(m_src).to_boolean());
|
||||||
|
@ -354,6 +369,21 @@ String BitwiseXor::to_string() const
|
||||||
return String::formatted("BitwiseXor dst:{}, src1:{}, src2:{}", m_dst, m_src1, m_src2);
|
return String::formatted("BitwiseXor dst:{}, src1:{}, src2:{}", m_dst, m_src1, m_src2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String LeftShift::to_string() const
|
||||||
|
{
|
||||||
|
return String::formatted("LeftShift dst:{}, src1:{}, src2:{}", m_dst, m_src1, m_src2);
|
||||||
|
}
|
||||||
|
|
||||||
|
String RightShift::to_string() const
|
||||||
|
{
|
||||||
|
return String::formatted("RightShift dst:{}, src1:{}, src2:{}", m_dst, m_src1, m_src2);
|
||||||
|
}
|
||||||
|
|
||||||
|
String UnsignedRightShift::to_string() const
|
||||||
|
{
|
||||||
|
return String::formatted("UnsignedRightShift 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);
|
||||||
|
|
|
@ -355,6 +355,63 @@ private:
|
||||||
Register m_src2;
|
Register m_src2;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class LeftShift final : public Instruction {
|
||||||
|
public:
|
||||||
|
LeftShift(Register dst, Register src1, Register src2)
|
||||||
|
: Instruction(Type::LeftShift)
|
||||||
|
, 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 RightShift final : public Instruction {
|
||||||
|
public:
|
||||||
|
RightShift(Register dst, Register src1, Register src2)
|
||||||
|
: Instruction(Type::RightShift)
|
||||||
|
, 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 UnsignedRightShift final : public Instruction {
|
||||||
|
public:
|
||||||
|
UnsignedRightShift(Register dst, Register src1, Register src2)
|
||||||
|
: Instruction(Type::UnsignedRightShift)
|
||||||
|
, 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)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue