Skip to content

bloqade.lanes.bytecode.decode.StackMachineFrame

← Module overview

classStackMachineFramesource

bloqade.lanes.bytecode.decode.StackMachineFrame

Tracks IR construction state during bytecode decoding.

class StackMachineFrame(stack: list[ir.SSAValue] = list())

Mirrors kirin.lowering.Frame’s shape for the bytecode case: a single basic block wrapped in a Region, plus a virtual stack of SSA values.

Parameters

NameTypeDefaultDescription
stacklist[ir.SSAValue]list()

Attributes

NameTypeDefaultDescription
current_regionir.Regionfield(init=False)
current_blockir.Blockfield(init=False)
stacklist[ir.SSAValue]field(default_factory=list)

methodpushsource

bloqade.lanes.bytecode.decode.StackMachineFrame.push

def push(stmt: T) -> T

Append a statement to the current block and push its results onto the virtual stack.

Results are pushed in reverse declaration order — the first-declared result (highest on the stack per the dialect convention) ends up on top after pushing. For Swap this means out_top (declared first) sits above out_bot (declared second). For single-result statements there is only one result, so the reversed iteration is a no-op.

Parameters

NameTypeDescription
stmtT

Returns

T

source

methodpush_valuesource

bloqade.lanes.bytecode.decode.StackMachineFrame.push_value

def push_value(value: ir.SSAValue) -> None

Push an SSA value onto the virtual stack.

Parameters

NameTypeDescription
valueir.SSAValue
source

methodpop_valuesource

bloqade.lanes.bytecode.decode.StackMachineFrame.pop_value

def pop_value() -> ir.SSAValue

Pop the top of the virtual stack.

Returns

ir.SSAValue

Raises

TypeDescription
StackUnderflowErrorwhen the stack is empty.
source

methodpop_nsource

bloqade.lanes.bytecode.decode.StackMachineFrame.pop_n

def pop_n(n: int) -> list[ir.SSAValue]

Pop n values from the top of the stack.

Returns them in bottom-to-top order so the caller can pass them as a tuple matching the ‘top-of-stack = last argument’ convention.

Parameters

NameTypeDescription
nint

Returns

list[ir.SSAValue]

Raises

TypeDescription
StackUnderflowErrorwhen the stack has fewer than ``n`` values.
source

methodpeek_valuesource

bloqade.lanes.bytecode.decode.StackMachineFrame.peek_value

def peek_value() -> ir.SSAValue

Return the top-of-stack SSA value without popping.

Returns

ir.SSAValue

Raises

TypeDescription
StackUnderflowErrorwhen the stack is empty.
source

methodswap_valuessource

bloqade.lanes.bytecode.decode.StackMachineFrame.swap_values

def swap_values() -> None

Swap the top two values on the virtual stack in place.

Raises

TypeDescription
StackUnderflowErrorwhen the stack has fewer than 2 values.
source

methodsnapshotsource

bloqade.lanes.bytecode.decode.StackMachineFrame.snapshot

def snapshot() -> tuple[ir.SSAValue, ...]

Return a tuple snapshot of the stack — used for error reporting.

Returns

tuple[ir.SSAValue, ...]

source

methoddepthsource

bloqade.lanes.bytecode.decode.StackMachineFrame.depth

def depth() -> int

Returns

int

source