From 5e996de8c688ab4db56f3b54cc0d3486011115b3 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Mon, 7 Jun 2021 21:13:37 +0100 Subject: [PATCH] LibJS: Add bytecode generation for BinaryOp::In --- .../Libraries/LibJS/Bytecode/ASTCodegen.cpp | 4 ++++ .../Libraries/LibJS/Bytecode/Instruction.h | 3 ++- Userland/Libraries/LibJS/Bytecode/Op.cpp | 21 ++++++++++++++----- Userland/Libraries/LibJS/Bytecode/Op.h | 20 ++++++++++++++++++ 4 files changed, 42 insertions(+), 6 deletions(-) diff --git a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp index ca96f4924cd..cffcf1a7b50 100644 --- a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp +++ b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2021, Andreas Kling + * Copyright (c) 2021, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ @@ -109,6 +110,9 @@ Optional BinaryExpression::generate_bytecode(Bytecode::Gener case BinaryOp::UnsignedRightShift: generator.emit(dst_reg, *lhs_reg, *rhs_reg); return dst_reg; + case BinaryOp::In: + generator.emit(dst_reg, *lhs_reg, *rhs_reg); + return dst_reg; default: TODO(); } diff --git a/Userland/Libraries/LibJS/Bytecode/Instruction.h b/Userland/Libraries/LibJS/Bytecode/Instruction.h index 8ec107e2206..bb52b84cc9b 100644 --- a/Userland/Libraries/LibJS/Bytecode/Instruction.h +++ b/Userland/Libraries/LibJS/Bytecode/Instruction.h @@ -48,7 +48,8 @@ O(Typeof) \ O(LeftShift) \ O(RightShift) \ - O(UnsignedRightShift) + O(UnsignedRightShift) \ + O(In) namespace JS::Bytecode { diff --git a/Userland/Libraries/LibJS/Bytecode/Op.cpp b/Userland/Libraries/LibJS/Bytecode/Op.cpp index 2a71384d3aa..f44086f3e97 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Op.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2021, Andreas Kling + * Copyright (c) 2021, Linus Groh * * 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)); } -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 { 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)); } +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 { 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); } +String In::to_string() const +{ + return String::formatted("In dst:{}, src1:{}, src2:{}", m_dst, m_src1, m_src2); +} + String BitwiseNot::to_string() const { return String::formatted("BitwiseNot dst:{}, src:{}", m_dst, m_src); diff --git a/Userland/Libraries/LibJS/Bytecode/Op.h b/Userland/Libraries/LibJS/Bytecode/Op.h index 5d5da53edac..998e344d0ef 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.h +++ b/Userland/Libraries/LibJS/Bytecode/Op.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2021, Andreas Kling + * Copyright (c) 2021, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ @@ -429,6 +430,25 @@ private: 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 { public: BitwiseNot(Register dst, Register src)