From 5fd2167397923bacfc26ef63dc518d548ee24347 Mon Sep 17 00:00:00 2001 From: Haled Odat <8566042+HalidOdat@users.noreply.github.com> Date: Sat, 3 Aug 2024 13:01:01 +0200 Subject: [PATCH] Simplify assign stack cleanup --- .../src/bytecompiler/expression/assign.rs | 21 +++++++------------ core/engine/src/bytecompiler/register.rs | 2 +- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/core/engine/src/bytecompiler/expression/assign.rs b/core/engine/src/bytecompiler/expression/assign.rs index bfb9516c4e5..64f162c5558 100644 --- a/core/engine/src/bytecompiler/expression/assign.rs +++ b/core/engine/src/bytecompiler/expression/assign.rs @@ -280,21 +280,14 @@ impl ByteCompiler<'_> { } if let Some(early_exit) = early_exit { - if pop_count == 0 { - self.patch_jump(early_exit); - self.push_from_register(&lhs); - } else { - let exit = self.emit_opcode_with_operand(Opcode::Jump); - - self.patch_jump(early_exit); - self.push_from_register(&lhs); - - for _ in 0..pop_count { - self.emit_opcode(Opcode::Swap); - self.emit_opcode(Opcode::Pop); - } - self.patch_jump(exit); + let exit = self.emit_opcode_with_operand(Opcode::Jump); + + self.patch_jump(early_exit); + for _ in 0..pop_count { + self.emit_opcode(Opcode::Pop); } + self.push_from_register(&lhs); + self.patch_jump(exit); } self.register_allocator.dealloc(lhs); diff --git a/core/engine/src/bytecompiler/register.rs b/core/engine/src/bytecompiler/register.rs index 9a0684a9129..a7cc4156b02 100644 --- a/core/engine/src/bytecompiler/register.rs +++ b/core/engine/src/bytecompiler/register.rs @@ -37,7 +37,7 @@ impl Reg { impl Drop for Reg { fn drop(&mut self) { if !self.flags.is_persistent() { - unreachable!("forgot to deallocate a register!") + unreachable!("forgot to deallocate a register! Or a panic happend which caused Reg's drop to be called after the panic!") } } }