mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-05 23:59:49 +00:00
LibJS/Bytecode: Dedicated instructions for postfix increment/decrement
Instead of splitting the postfix variants into ToNumeric + Inc/Dec, we now have dedicated PostfixIncrement and PostfixDecrement instructions that handle both outputs in one go.
This commit is contained in:
parent
c4f49e343a
commit
9d9b737a58
Notes:
sideshowbarker
2024-07-17 03:00:02 +09:00
Author: https://github.com/awesomekling
Commit: 9d9b737a58
Pull-request: https://github.com/SerenityOS/serenity/pull/23269
4 changed files with 96 additions and 27 deletions
|
@ -2373,15 +2373,22 @@ Bytecode::CodeGenerationErrorOr<Optional<Bytecode::Operand>> UpdateExpression::g
|
|||
auto reference = TRY(generator.emit_load_from_reference(*m_argument));
|
||||
|
||||
Optional<Bytecode::Operand> previous_value_for_postfix;
|
||||
if (!m_prefixed) {
|
||||
previous_value_for_postfix = Bytecode::Operand(generator.allocate_register());
|
||||
generator.emit<Bytecode::Op::ToNumeric>(*previous_value_for_postfix, *reference.loaded_value);
|
||||
}
|
||||
|
||||
if (m_op == UpdateOp::Increment)
|
||||
generator.emit<Bytecode::Op::Increment>(*reference.loaded_value);
|
||||
else
|
||||
generator.emit<Bytecode::Op::Decrement>(*reference.loaded_value);
|
||||
if (m_op == UpdateOp::Increment) {
|
||||
if (m_prefixed) {
|
||||
generator.emit<Bytecode::Op::Increment>(*reference.loaded_value);
|
||||
} else {
|
||||
previous_value_for_postfix = Bytecode::Operand(generator.allocate_register());
|
||||
generator.emit<Bytecode::Op::PostfixIncrement>(*previous_value_for_postfix, *reference.loaded_value);
|
||||
}
|
||||
} else {
|
||||
if (m_prefixed) {
|
||||
generator.emit<Bytecode::Op::Decrement>(*reference.loaded_value);
|
||||
} else {
|
||||
previous_value_for_postfix = Bytecode::Operand(generator.allocate_register());
|
||||
generator.emit<Bytecode::Op::PostfixDecrement>(*previous_value_for_postfix, *reference.loaded_value);
|
||||
}
|
||||
}
|
||||
|
||||
if (is<Identifier>(*m_argument))
|
||||
(void)TRY(generator.emit_store_to_reference(static_cast<Identifier const&>(*m_argument), *reference.loaded_value));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue