1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:37:34 +00:00

LibJS/JIT: Compile the TypeofLocal bytecode instruction

This commit is contained in:
Andreas Kling 2023-10-27 16:22:14 +02:00
parent a645b9c6c3
commit 17b2c7d965
3 changed files with 18 additions and 0 deletions

View file

@ -1447,6 +1447,8 @@ public:
ThrowCompletionOr<void> 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;
};

View file

@ -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<NativeExecutable> Compiler::compile(Bytecode::Executable& bytecode_execut
case Bytecode::Instruction::Type::SetLocal:
compiler.compile_set_local(static_cast<Bytecode::Op::SetLocal const&>(op));
break;
case Bytecode::Instruction::Type::TypeofLocal:
compiler.compile_typeof_local(static_cast<Bytecode::Op::TypeofLocal const&>(op));
break;
case Bytecode::Instruction::Type::Jump:
compiler.compile_jump(static_cast<Bytecode::Op::Jump const&>(op));
break;

View file

@ -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&);