1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 22:15:07 +00:00

LibJS/Bytecode: Add codegen for ImportCall

Also moved most of the AST ImportCall::execute() into a helper so we can
share the code.
This commit is contained in:
Andreas Kling 2023-06-24 15:22:16 +02:00
parent eb9298b54e
commit 8a5e71256d
8 changed files with 160 additions and 89 deletions

View file

@ -2725,4 +2725,22 @@ Bytecode::CodeGenerationErrorOr<void> OptionalChain::generate_bytecode(Bytecode:
return generate_optional_chain(generator, *this, current_value_register, current_base_register);
}
Bytecode::CodeGenerationErrorOr<void> ImportCall::generate_bytecode(Bytecode::Generator& generator) const
{
TRY(m_specifier->generate_bytecode(generator));
auto specifier_reg = generator.allocate_register();
generator.emit<Bytecode::Op::Store>(specifier_reg);
if (m_options) {
TRY(m_options->generate_bytecode(generator));
} else {
generator.emit<Bytecode::Op::LoadImmediate>(js_undefined());
}
auto options_reg = generator.allocate_register();
generator.emit<Bytecode::Op::Store>(options_reg);
generator.emit<Bytecode::Op::ImportCall>(specifier_reg, options_reg);
return {};
}
}