From 4b23a7dfb4f68bfc8ff57dfaa1c674a594fcad0d Mon Sep 17 00:00:00 2001 From: Simon Wanner Date: Sun, 29 Oct 2023 02:59:50 +0100 Subject: [PATCH] LibJS/JIT: Compile the NewClass bytecode instruction --- Userland/Libraries/LibJS/Bytecode/Op.h | 3 +++ Userland/Libraries/LibJS/JIT/Compiler.cpp | 21 +++++++++++++++++++++ Userland/Libraries/LibJS/JIT/Compiler.h | 1 + 3 files changed, 25 insertions(+) diff --git a/Userland/Libraries/LibJS/Bytecode/Op.h b/Userland/Libraries/LibJS/Bytecode/Op.h index c9172bd4f6..7d98a9484f 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.h +++ b/Userland/Libraries/LibJS/Bytecode/Op.h @@ -1005,6 +1005,9 @@ public: ThrowCompletionOr execute_impl(Bytecode::Interpreter&) const; DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const; + ClassExpression const& class_expression() const { return m_class_expression; } + Optional const& lhs_name() const { return m_lhs_name; } + private: ClassExpression const& m_class_expression; Optional m_lhs_name; diff --git a/Userland/Libraries/LibJS/JIT/Compiler.cpp b/Userland/Libraries/LibJS/JIT/Compiler.cpp index c22c3eb43b..97bfd7999a 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.cpp +++ b/Userland/Libraries/LibJS/JIT/Compiler.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -708,6 +709,23 @@ void Compiler::compile_new_function(Bytecode::Op::NewFunction const& op) store_vm_register(Bytecode::Register::accumulator(), RET); } +static Value cxx_new_class(VM& vm, ClassExpression const& class_expression, Optional const& lhs_name) +{ + return TRY_OR_SET_EXCEPTION(Bytecode::new_class(vm, class_expression, lhs_name)); +} + +void Compiler::compile_new_class(Bytecode::Op::NewClass const& op) +{ + m_assembler.mov( + Assembler::Operand::Register(ARG1), + Assembler::Operand::Imm(bit_cast(&op.class_expression()))); + m_assembler.mov( + Assembler::Operand::Register(ARG2), + Assembler::Operand::Imm(bit_cast(&op.lhs_name()))); + native_call((void*)cxx_new_class); + store_vm_register(Bytecode::Register::accumulator(), RET); +} + static Value cxx_get_by_id(VM& vm, Value base, Bytecode::IdentifierTableIndex property, u32 cache_index) { return TRY_OR_SET_EXCEPTION(Bytecode::get_by_id(vm.bytecode_interpreter(), property, base, base, cache_index)); @@ -1251,6 +1269,9 @@ OwnPtr Compiler::compile(Bytecode::Executable& bytecode_execut case Bytecode::Instruction::Type::CreateVariable: compiler.compile_create_variable(static_cast(op)); break; + case Bytecode::Instruction::Type::NewClass: + compiler.compile_new_class(static_cast(op)); + break; # define DO_COMPILE_COMMON_BINARY_OP(TitleCaseName, snake_case_name) \ case Bytecode::Instruction::Type::TitleCaseName: \ diff --git a/Userland/Libraries/LibJS/JIT/Compiler.h b/Userland/Libraries/LibJS/JIT/Compiler.h index c23eff3d08..8c4b08b458 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.h +++ b/Userland/Libraries/LibJS/JIT/Compiler.h @@ -100,6 +100,7 @@ private: void compile_new_function(Bytecode::Op::NewFunction const&); void compile_new_regexp(Bytecode::Op::NewRegExp const&); void compile_new_bigint(Bytecode::Op::NewBigInt const&); + void compile_new_class(Bytecode::Op::NewClass const&); void compile_create_variable(Bytecode::Op::CreateVariable const&);