mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-27 14:58:46 +00:00
LibJS: Implement bytecode generation for UpdateExpression :^)
Added Increment and Decrement bytecode ops to support this. Postfix updates use a temporary register to preserve the original value. Note that this patch only implements Identifier updates. Member expression updates are a TODO.
This commit is contained in:
parent
5c98f979c6
commit
59eedd6de0
Notes:
sideshowbarker
2024-07-18 12:34:29 +09:00
Author: https://github.com/awesomekling
Commit: 59eedd6de0
5 changed files with 88 additions and 1 deletions
|
@ -638,4 +638,32 @@ void TemplateLiteral::generate_bytecode(Bytecode::Generator& generator) const
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateExpression::generate_bytecode(Bytecode::Generator& generator) const
|
||||
{
|
||||
if (is<Identifier>(*m_argument)) {
|
||||
auto& identifier = static_cast<Identifier const&>(*m_argument);
|
||||
generator.emit<Bytecode::Op::GetVariable>(identifier.string());
|
||||
|
||||
Optional<Bytecode::Register> previous_value_for_postfix_reg;
|
||||
if (!m_prefixed) {
|
||||
previous_value_for_postfix_reg = generator.allocate_register();
|
||||
generator.emit<Bytecode::Op::Store>(*previous_value_for_postfix_reg);
|
||||
}
|
||||
|
||||
if (m_op == UpdateOp::Increment)
|
||||
generator.emit<Bytecode::Op::Increment>();
|
||||
else
|
||||
generator.emit<Bytecode::Op::Decrement>();
|
||||
|
||||
generator.emit<Bytecode::Op::SetVariable>(identifier.string());
|
||||
|
||||
if (!m_prefixed)
|
||||
generator.emit<Bytecode::Op::Load>(*previous_value_for_postfix_reg);
|
||||
return;
|
||||
}
|
||||
|
||||
TODO();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue