From 40064d872ffe1e6306f1494747cce4c9cac4d725 Mon Sep 17 00:00:00 2001 From: Simon Wanner Date: Sun, 29 Oct 2023 17:25:49 +0100 Subject: [PATCH] LibJS/JIT: Compile the Append instruction --- Userland/Libraries/LibJS/Bytecode/Op.h | 3 +++ Userland/Libraries/LibJS/JIT/Compiler.cpp | 17 +++++++++++++++++ Userland/Libraries/LibJS/JIT/Compiler.h | 3 ++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibJS/Bytecode/Op.h b/Userland/Libraries/LibJS/Bytecode/Op.h index 26cb84c1e4..e97cc4a5c0 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.h +++ b/Userland/Libraries/LibJS/Bytecode/Op.h @@ -318,6 +318,9 @@ public: ThrowCompletionOr execute_impl(Bytecode::Interpreter&) const; DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const; + Register lhs() const { return m_lhs; } + bool is_spread() const { return m_is_spread; } + private: Register m_lhs; bool m_is_spread = false; diff --git a/Userland/Libraries/LibJS/JIT/Compiler.cpp b/Userland/Libraries/LibJS/JIT/Compiler.cpp index d76a8b17e3..24bbab4380 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.cpp +++ b/Userland/Libraries/LibJS/JIT/Compiler.cpp @@ -1319,6 +1319,23 @@ void Compiler::compile_iterator_to_array(Bytecode::Op::IteratorToArray const&) check_exception(); } +static Value cxx_append(VM& vm, Value lhs, Value rhs, bool is_spread) +{ + TRY_OR_SET_EXCEPTION(Bytecode::append(vm, lhs, rhs, is_spread)); + return {}; +} + +void Compiler::compile_append(Bytecode::Op::Append const& op) +{ + load_vm_register(ARG1, op.lhs()); + load_vm_register(ARG2, Bytecode::Register::accumulator()); + m_assembler.mov( + Assembler::Operand::Register(ARG3), + Assembler::Operand::Imm(static_cast(op.is_spread()))); + native_call((void*)cxx_append); + check_exception(); +} + void Compiler::jump_to_exit() { m_assembler.jump(m_exit_label); diff --git a/Userland/Libraries/LibJS/JIT/Compiler.h b/Userland/Libraries/LibJS/JIT/Compiler.h index 1464ba2795..84191e552c 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.h +++ b/Userland/Libraries/LibJS/JIT/Compiler.h @@ -113,7 +113,8 @@ private: O(ThrowIfNullish, throw_if_nullish) \ O(IteratorResultValue, iterator_result_value) \ O(IteratorClose, iterator_close) \ - O(IteratorToArray, iterator_to_array) + O(IteratorToArray, iterator_to_array) \ + O(Append, append) # define DECLARE_COMPILE_OP(OpTitleCase, op_snake_case) \ void compile_##op_snake_case(Bytecode::Op::OpTitleCase const&);