Skip to content

Commit

Permalink
Don't output noops
Browse files Browse the repository at this point in the history
  • Loading branch information
Quaqqer committed Jan 17, 2024
1 parent c1ed372 commit 7cf78ea
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions crates/saft-bytecode/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,20 @@ impl Compiler {
#[allow(unused)]
fn exit_scope(&mut self, chunk: &mut Chunk, span: impl Borrow<Span>) {
let env = self.scopes.pop().unwrap();
chunk.emit(Op::PopN(self.stack_i - env.stack_base), span);

let to_pop = self.stack_i - env.stack_base;
if 0 < to_pop {
chunk.emit(Op::PopN(to_pop), span);
}
}

fn exit_scope_trailing(&mut self, chunk: &mut Chunk, span: impl Borrow<Span>) {
let env = self.scopes.pop().unwrap();
let decls = self.stack_i - env.stack_base;
chunk.emit(Op::TrailPop(decls), span)

if 0 < decls {
chunk.emit(Op::TrailPop(decls), span)
}
}

fn binary(
Expand Down

0 comments on commit 7cf78ea

Please sign in to comment.