From 17b2c7d965241e59fe37046da52e50a6a0c2490d Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 27 Oct 2023 16:22:14 +0200 Subject: [PATCH] LibJS/JIT: Compile the TypeofLocal bytecode instruction --- Userland/Libraries/LibJS/Bytecode/Op.h | 2 ++ Userland/Libraries/LibJS/JIT/Compiler.cpp | 15 +++++++++++++++ Userland/Libraries/LibJS/JIT/Compiler.h | 1 + 3 files changed, 18 insertions(+) diff --git a/Userland/Libraries/LibJS/Bytecode/Op.h b/Userland/Libraries/LibJS/Bytecode/Op.h index 5334432e06..0c6b6ca4a0 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.h +++ b/Userland/Libraries/LibJS/Bytecode/Op.h @@ -1447,6 +1447,8 @@ public: ThrowCompletionOr execute_impl(Bytecode::Interpreter&) const; DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const; + size_t index() const { return m_index; } + private: size_t m_index; }; diff --git a/Userland/Libraries/LibJS/JIT/Compiler.cpp b/Userland/Libraries/LibJS/JIT/Compiler.cpp index 67091d8fd6..8d5e6cfd55 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.cpp +++ b/Userland/Libraries/LibJS/JIT/Compiler.cpp @@ -100,6 +100,18 @@ void Compiler::compile_set_local(Bytecode::Op::SetLocal const& op) store_vm_local(op.index(), GPR0); } +static Value cxx_typeof_local(VM& vm, Value value) +{ + return PrimitiveString::create(vm, value.typeof()); +} + +void Compiler::compile_typeof_local(Bytecode::Op::TypeofLocal const& op) +{ + load_vm_local(ARG1, op.index()); + m_assembler.native_call((void*)cxx_typeof_local); + store_vm_register(Bytecode::Register::accumulator(), GPR0); +} + void Compiler::compile_jump(Bytecode::Op::Jump const& op) { m_assembler.jump(label_for(op.true_target()->block())); @@ -937,6 +949,9 @@ OwnPtr Compiler::compile(Bytecode::Executable& bytecode_execut case Bytecode::Instruction::Type::SetLocal: compiler.compile_set_local(static_cast(op)); break; + case Bytecode::Instruction::Type::TypeofLocal: + compiler.compile_typeof_local(static_cast(op)); + break; case Bytecode::Instruction::Type::Jump: compiler.compile_jump(static_cast(op)); break; diff --git a/Userland/Libraries/LibJS/JIT/Compiler.h b/Userland/Libraries/LibJS/JIT/Compiler.h index c9ea8c742e..bba8980ee8 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.h +++ b/Userland/Libraries/LibJS/JIT/Compiler.h @@ -42,6 +42,7 @@ private: void compile_store(Bytecode::Op::Store const&); void compile_get_local(Bytecode::Op::GetLocal const&); void compile_set_local(Bytecode::Op::SetLocal const&); + void compile_typeof_local(Bytecode::Op::TypeofLocal const&); void compile_jump(Bytecode::Op::Jump const&); void compile_jump_conditional(Bytecode::Op::JumpConditional const&); void compile_increment(Bytecode::Op::Increment const&);