patch_seq_peek_int_value

Function patch_seq_peek_int_value 

Source
#[unsafe(no_mangle)]
pub unsafe extern "C" fn patch_seq_peek_int_value(stack: Stack) -> i64
Expand description

Helper for peeking at the top integer value without popping

Returns the integer value on top of the stack without modifying the stack. Used in conjunction with pop_stack for conditional branching.

Why separate peek and pop? In LLVM IR for conditionals, we need to:

  1. Extract the integer value to test it (peek_int_value)
  2. Branch based on that value (icmp + br)
  3. Free the stack node in both branches (pop_stack)

A combined pop_int_value would leak memory since we’d need the value before branching but couldn’t return the updated stack pointer through both branches. Separating these operations prevents memory leaks.

Stack effect: ( n – n ) returns n

§Safety

Stack must have an Int value on top