pub struct ProgramBuilder { /* private fields */ }Expand description
A VDBE bytecode program under construction.
Provides methods to emit instructions, create/resolve labels for forward
jumps, and allocate registers. Once construction is complete, call
finish to validate and extract the final instruction
sequence.
Implementations§
Source§impl ProgramBuilder
impl ProgramBuilder
Sourcepub fn emit(&mut self, op: VdbeOp) -> usize
pub fn emit(&mut self, op: VdbeOp) -> usize
Emit a single instruction and return its address (index in ops).
Sourcepub fn emit_op(
&mut self,
opcode: Opcode,
p1: i32,
p2: i32,
p3: i32,
p4: P4,
p5: u16,
) -> usize
pub fn emit_op( &mut self, opcode: Opcode, p1: i32, p2: i32, p3: i32, p4: P4, p5: u16, ) -> usize
Emit a simple instruction from parts.
Sourcepub fn current_addr(&self) -> usize
pub fn current_addr(&self) -> usize
The current address (index of the next instruction to be emitted).
Sourcepub fn op_at(&self, addr: usize) -> Option<&VdbeOp>
pub fn op_at(&self, addr: usize) -> Option<&VdbeOp>
Get a reference to the instruction at addr.
Sourcepub fn op_at_mut(&mut self, addr: usize) -> Option<&mut VdbeOp>
pub fn op_at_mut(&mut self, addr: usize) -> Option<&mut VdbeOp>
Get a mutable reference to the instruction at addr.
Sourcepub fn emit_label(&mut self) -> Label
pub fn emit_label(&mut self) -> Label
Create a new label for forward-reference jumps.
Sourcepub fn emit_jump_to_label(
&mut self,
opcode: Opcode,
p1: i32,
p3: i32,
label: Label,
p4: P4,
p5: u16,
) -> usize
pub fn emit_jump_to_label( &mut self, opcode: Opcode, p1: i32, p3: i32, label: Label, p4: P4, p5: u16, ) -> usize
Emit a jump instruction whose p2 target is a label (forward reference).
The label’s address will be patched into p2 when resolve_label is called.
Sourcepub fn resolve_label(&mut self, label: Label)
pub fn resolve_label(&mut self, label: Label)
Resolve a label to the current address and patch all forward refs.
Sourcepub fn resolve_label_to(&mut self, label: Label, address: i32)
pub fn resolve_label_to(&mut self, label: Label, address: i32)
Resolve a label to an explicit address (used for some control patterns).
Sourcepub fn alloc_regs(&mut self, n: i32) -> i32
pub fn alloc_regs(&mut self, n: i32) -> i32
Allocate a contiguous block of persistent registers.
Sourcepub fn alloc_temp(&mut self) -> i32
pub fn alloc_temp(&mut self) -> i32
Allocate a temporary register (reusable).
Sourcepub fn register_count(&self) -> i32
pub fn register_count(&self) -> i32
Total registers allocated (high water mark).
Sourcepub fn apply_fuse_literal_result_row(&mut self) -> usize
pub fn apply_fuse_literal_result_row(&mut self) -> usize
Fuse Integer(lit, reg) + ResultRow(reg, 1) pairs into
FusedLiteralResultRow(lit, reg) + Noop.
Rewrites in-place so program counters, jump targets, and the label
tables remain valid without rewiring. The ResultRow is replaced by a
Noop rather than removed so no following instruction shifts.
Conservative preconditions per fusion site:
- The
Integer’s target register equals theResultRow’s start register. - The
ResultRowemits exactly one column (p2 == 1). - The
ResultRowis NOT a resolved jump target from any prior jump in this program (a mid-pair jump would otherwise skip the Integer write and runResultRowagainst an unrelated register value). - Neither instruction carries a non-
NoneP4 payload (Integer/ResultRow don’t use P4 in their canonical form). - Both instructions carry P5 == 0 and P3 == 0.
Returns the number of fusions performed.
Sourcepub fn finish(self) -> Result<VdbeProgram>
pub fn finish(self) -> Result<VdbeProgram>
Validate all labels are resolved and return the finished program.
Trait Implementations§
Source§impl Debug for ProgramBuilder
impl Debug for ProgramBuilder
Auto Trait Implementations§
impl Freeze for ProgramBuilder
impl RefUnwindSafe for ProgramBuilder
impl Send for ProgramBuilder
impl Sync for ProgramBuilder
impl Unpin for ProgramBuilder
impl UnsafeUnpin for ProgramBuilder
impl UnwindSafe for ProgramBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, _span: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more