diff options
author | Linus Groh <mail@linusgroh.de> | 2021-06-07 21:13:37 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-06-07 21:18:35 +0100 |
commit | 5e996de8c688ab4db56f3b54cc0d3486011115b3 (patch) | |
tree | 5736413284f37fc8ec7ca5bca4ec2815544fb213 /Userland | |
parent | 93eae063a1f28962e6d917a2b3caebcab2cc73c3 (diff) | |
download | serenity-5e996de8c688ab4db56f3b54cc0d3486011115b3.zip |
LibJS: Add bytecode generation for BinaryOp::In
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Bytecode/Instruction.h | 3 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Bytecode/Op.cpp | 21 | ||||
-rw-r--r-- | 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 ca96f4924c..cffcf1a7b5 100644 --- a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp +++ b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2021, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2021, Linus Groh <linusg@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -109,6 +110,9 @@ Optional<Bytecode::Register> BinaryExpression::generate_bytecode(Bytecode::Gener case BinaryOp::UnsignedRightShift: generator.emit<Bytecode::Op::UnsignedRightShift>(dst_reg, *lhs_reg, *rhs_reg); return dst_reg; + case BinaryOp::In: + generator.emit<Bytecode::Op::In>(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 8ec107e220..bb52b84cc9 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 2a71384d3a..f44086f3e9 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Op.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2021, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2021, Linus Groh <linusg@serenityos.org> * * 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 5d5da53eda..998e344d0e 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.h +++ b/Userland/Libraries/LibJS/Bytecode/Op.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2021, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2021, Linus Groh <linusg@serenityos.org> * * 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) |