mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 09:38:11 +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
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