mirror of
https://github.com/RGBCube/serenity
synced 2025-05-30 21:58:10 +00:00
LibJS: Support basic function calls in the bytecode world :^)
This patch adds the Call bytecode instruction which is emitted for the CallExpression AST node. It's pretty barebones and doesn't handle 'this' values properly, etc. But it can perform basic function calls! :^) Note that the called function will *not* execute as bytecode, but will simply fall back into the old codepath and use the AST interpreter.
This commit is contained in:
parent
1eafaf67fe
commit
dc63958478
4 changed files with 85 additions and 0 deletions
|
@ -156,4 +156,25 @@ Optional<Bytecode::Register> MemberExpression::generate_bytecode(Bytecode::Gener
|
|||
}
|
||||
}
|
||||
|
||||
Optional<Bytecode::Register> FunctionDeclaration::generate_bytecode(Bytecode::Generator&) const
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
Optional<Bytecode::Register> CallExpression::generate_bytecode(Bytecode::Generator& generator) const
|
||||
{
|
||||
auto callee_reg = m_callee->generate_bytecode(generator);
|
||||
|
||||
// FIXME: Load the correct 'this' value into 'this_reg'.
|
||||
auto this_reg = generator.allocate_register();
|
||||
generator.emit<Bytecode::Op::Load>(this_reg, js_undefined());
|
||||
|
||||
Vector<Bytecode::Register> argument_registers;
|
||||
for (auto& arg : m_arguments)
|
||||
argument_registers.append(*arg.value->generate_bytecode(generator));
|
||||
auto dst_reg = generator.allocate_register();
|
||||
generator.emit<Bytecode::Op::Call>(dst_reg, *callee_reg, this_reg, argument_registers);
|
||||
return dst_reg;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue