From 1445698a3ca66e84568cd78db4f365ba30855e72 Mon Sep 17 00:00:00 2001 From: ShaharNaveh <50263213+ShaharNaveh@users.noreply.github.com> Date: Thu, 25 Dec 2025 12:27:42 +0100 Subject: [PATCH 1/6] Remove `JumpIfTrueOrPop` & `JumpIfFalseOrPop` opcdes --- crates/codegen/src/compile.rs | 16 ++++++++++++---- crates/compiler-core/src/bytecode.rs | 21 --------------------- crates/vm/src/frame.rs | 23 ----------------------- 3 files changed, 12 insertions(+), 48 deletions(-) diff --git a/crates/codegen/src/compile.rs b/crates/codegen/src/compile.rs index 4f7174c8bad..fa788eddf9c 100644 --- a/crates/codegen/src/compile.rs +++ b/crates/codegen/src/compile.rs @@ -4030,7 +4030,9 @@ impl Compiler { if let Some(ref guard) = m.guard { // Compile guard and jump to end if false self.compile_expression(guard)?; - emit!(self, Instruction::JumpIfFalseOrPop { target: end }); + emit!(self, Instruction::CopyItem { index: 1_u32 }); + emit!(self, Instruction::PopJumpIfFalse { target: end }); + emit!(self, Instruction::Pop); } self.compile_statements(&m.body)?; } @@ -4101,12 +4103,14 @@ impl Compiler { // if comparison result is false, we break with this value; if true, try the next one. if let Some((break_block, _)) = end_blocks { + emit!(self, Instruction::CopyItem { index: 1_u32 }); emit!( self, - Instruction::JumpIfFalseOrPop { + Instruction::PopJumpIfFalse { target: break_block, } ); + emit!(self, Instruction::Pop); } } @@ -4457,14 +4461,16 @@ impl Compiler { let after_block = self.new_block(); let (last_value, values) = values.split_last().unwrap(); + for value in values { self.compile_expression(value)?; + emit!(self, Instruction::CopyItem { index: 1_u32 }); match op { BoolOp::And => { emit!( self, - Instruction::JumpIfFalseOrPop { + Instruction::PopJumpIfFalse { target: after_block, } ); @@ -4472,12 +4478,14 @@ impl Compiler { BoolOp::Or => { emit!( self, - Instruction::JumpIfTrueOrPop { + Instruction::PopJumpIfTrue { target: after_block, } ); } } + + emit!(self, Instruction::Pop); } // If all values did not qualify, take the value of the last value: diff --git a/crates/compiler-core/src/bytecode.rs b/crates/compiler-core/src/bytecode.rs index 11d2a7b5f1b..279429cf359 100644 --- a/crates/compiler-core/src/bytecode.rs +++ b/crates/compiler-core/src/bytecode.rs @@ -736,20 +736,10 @@ pub enum Instruction { }, /// Performs `is` comparison, or `is not` if `invert` is 1. IsOp(Arg), - /// Peek at the top of the stack, and jump if this value is false. - /// Otherwise, pop top of stack. - JumpIfFalseOrPop { - target: Arg