1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 22:58:11 +00:00

LibJS/JIT: Compile the NewFunction bytecode instruction

This commit is contained in:
Andreas Kling 2023-10-21 15:49:04 +02:00
parent 9f61cda27e
commit 9c93d100d1
3 changed files with 33 additions and 0 deletions

View file

@ -1003,6 +1003,10 @@ public:
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
FunctionExpression const& function_node() const { return m_function_node; }
Optional<IdentifierTableIndex> const& lhs_name() const { return m_lhs_name; }
Optional<Register> const& home_object() const { return m_home_object; }
private:
FunctionExpression const& m_function_node;
Optional<IdentifierTableIndex> m_lhs_name;

View file

@ -446,6 +446,30 @@ void Compiler::compile_new_array(Bytecode::Op::NewArray const& op)
store_vm_register(Bytecode::Register::accumulator(), RET);
}
Value cxx_new_function(
VM& vm,
FunctionExpression const& function_node,
Optional<Bytecode::IdentifierTableIndex> const& lhs_name,
Optional<Bytecode::Register> const& home_object)
{
return Bytecode::new_function(vm, function_node, lhs_name, home_object);
}
void Compiler::compile_new_function(Bytecode::Op::NewFunction const& op)
{
m_assembler.mov(
Assembler::Operand::Register(ARG1),
Assembler::Operand::Imm64(bit_cast<u64>(&op.function_node())));
m_assembler.mov(
Assembler::Operand::Register(ARG2),
Assembler::Operand::Imm64(bit_cast<u64>(&op.lhs_name())));
m_assembler.mov(
Assembler::Operand::Register(ARG3),
Assembler::Operand::Imm64(bit_cast<u64>(&op.home_object())));
m_assembler.native_call((void*)cxx_new_function);
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));
@ -689,6 +713,9 @@ OwnPtr<NativeExecutable> Compiler::compile(Bytecode::Executable& bytecode_execut
case Bytecode::Instruction::Type::NewArray:
compiler.compile_new_array(static_cast<Bytecode::Op::NewArray const&>(op));
break;
case Bytecode::Instruction::Type::NewFunction:
compiler.compile_new_function(static_cast<Bytecode::Op::NewFunction const&>(op));
break;
case Bytecode::Instruction::Type::GetById:
compiler.compile_get_by_id(static_cast<Bytecode::Op::GetById const&>(op));
break;

View file

@ -63,6 +63,8 @@ private:
void compile_new_string(Bytecode::Op::NewString const&);
void compile_new_object(Bytecode::Op::NewObject const&);
void compile_new_array(Bytecode::Op::NewArray const&);
void compile_new_function(Bytecode::Op::NewFunction const&);
void compile_get_by_id(Bytecode::Op::GetById const&);
void compile_get_by_value(Bytecode::Op::GetByValue const&);
void compile_get_global(Bytecode::Op::GetGlobal const&);