mirror of
https://github.com/RGBCube/serenity
synced 2025-05-30 15:28:11 +00:00
LibJS: Compile ScriptFunctions into bytecode and run them that way :^)
If there's a current Bytecode::Interpreter in action, ScriptFunction will now compile itself into bytecode and execute in that context. This patch also adds the Return bytecode instruction so that we can actually return values from called functions. :^) Return values are propagated from callee to caller via the caller's $0 register. Bytecode::Interpreter now keeps a stack of register "windows". These are not very efficient, but it should be pretty straightforward to convert them to e.g a sliding register window architecture later on. This is pretty dang cool! :^)
This commit is contained in:
parent
b609fc6d51
commit
80b1604b0a
7 changed files with 150 additions and 49 deletions
|
@ -177,4 +177,14 @@ Optional<Bytecode::Register> CallExpression::generate_bytecode(Bytecode::Generat
|
|||
return dst_reg;
|
||||
}
|
||||
|
||||
Optional<Bytecode::Register> ReturnStatement::generate_bytecode(Bytecode::Generator& generator) const
|
||||
{
|
||||
Optional<Bytecode::Register> argument_reg;
|
||||
if (m_argument)
|
||||
argument_reg = m_argument->generate_bytecode(generator);
|
||||
|
||||
generator.emit<Bytecode::Op::Return>(argument_reg);
|
||||
return argument_reg;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue