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

LibJS: Perform function instantiation in bytecode

This replaces Bytecode::Op::EnterScope with a new NewFunction op that
instantiates a ScriptFunction from a given FunctionNode (AST).

This is then used to instantiate the local functions directly from
bytecode when entering a ScopeNode. :^)
This commit is contained in:
Andreas Kling 2021-06-10 00:49:23 +02:00
parent 941be2dcc2
commit b3e6a6c1cd
5 changed files with 16 additions and 21 deletions

View file

@ -22,7 +22,11 @@ void ASTNode::generate_bytecode(Bytecode::Generator&) const
void ScopeNode::generate_bytecode(Bytecode::Generator& generator) const
{
generator.emit<Bytecode::Op::EnterScope>(*this);
for (auto& function : functions()) {
generator.emit<Bytecode::Op::NewFunction>(function);
generator.emit<Bytecode::Op::SetVariable>(generator.intern_string(function.name()));
}
for (auto& child : children()) {
child.generate_bytecode(generator);
if (generator.is_current_block_terminated())