1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 23:07:34 +00:00

LibJS: Add bytecode generation for BinaryOp::In

This commit is contained in:
Linus Groh 2021-06-07 21:13:37 +01:00
parent 93eae063a1
commit 5e996de8c6
4 changed files with 42 additions and 6 deletions

View file

@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org> * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -109,6 +110,9 @@ Optional<Bytecode::Register> BinaryExpression::generate_bytecode(Bytecode::Gener
case BinaryOp::UnsignedRightShift: case BinaryOp::UnsignedRightShift:
generator.emit<Bytecode::Op::UnsignedRightShift>(dst_reg, *lhs_reg, *rhs_reg); generator.emit<Bytecode::Op::UnsignedRightShift>(dst_reg, *lhs_reg, *rhs_reg);
return dst_reg; return dst_reg;
case BinaryOp::In:
generator.emit<Bytecode::Op::In>(dst_reg, *lhs_reg, *rhs_reg);
return dst_reg;
default: default:
TODO(); TODO();
} }

View file

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

View file

@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org> * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -142,11 +143,6 @@ void BitwiseXor::execute(Bytecode::Interpreter& interpreter) const
interpreter.reg(m_dst) = bitwise_xor(interpreter.global_object(), interpreter.reg(m_src1), interpreter.reg(m_src2)); interpreter.reg(m_dst) = bitwise_xor(interpreter.global_object(), interpreter.reg(m_src1), interpreter.reg(m_src2));
} }
void BitwiseNot::execute(Bytecode::Interpreter& interpreter) const
{
interpreter.reg(m_dst) = bitwise_not(interpreter.global_object(), interpreter.reg(m_src));
}
void LeftShift::execute(Bytecode::Interpreter& interpreter) const void LeftShift::execute(Bytecode::Interpreter& interpreter) const
{ {
interpreter.reg(m_dst) = left_shift(interpreter.global_object(), interpreter.reg(m_src1), interpreter.reg(m_src2)); interpreter.reg(m_dst) = left_shift(interpreter.global_object(), interpreter.reg(m_src1), interpreter.reg(m_src2));
@ -162,6 +158,16 @@ 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)); interpreter.reg(m_dst) = unsigned_right_shift(interpreter.global_object(), interpreter.reg(m_src1), interpreter.reg(m_src2));
} }
void In::execute(Bytecode::Interpreter& interpreter) const
{
interpreter.reg(m_dst) = in(interpreter.global_object(), interpreter.reg(m_src1), interpreter.reg(m_src2));
}
void BitwiseNot::execute(Bytecode::Interpreter& interpreter) const
{
interpreter.reg(m_dst) = bitwise_not(interpreter.global_object(), interpreter.reg(m_src));
}
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());
@ -394,6 +400,11 @@ String UnsignedRightShift::to_string() const
return String::formatted("UnsignedRightShift dst:{}, src1:{}, src2:{}", m_dst, m_src1, m_src2); return String::formatted("UnsignedRightShift dst:{}, src1:{}, src2:{}", m_dst, m_src1, m_src2);
} }
String In::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

@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org> * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -429,6 +430,25 @@ private:
Register m_src2; Register m_src2;
}; };
class In final : public Instruction {
public:
In(Register dst, Register src1, Register src2)
: Instruction(Type::In)
, 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)