Skip to content

Commit

Permalink
Simplify assign stack cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat committed Aug 3, 2024
1 parent 772b766 commit 5fd2167
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
21 changes: 7 additions & 14 deletions core/engine/src/bytecompiler/expression/assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion core/engine/src/bytecompiler/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
}
}
}
Expand Down

0 comments on commit 5fd2167

Please sign in to comment.