pub struct CompiledBytecode {
code: Vec<Op>,
consts: Vec<f64>,
}Expand description
A bytecode-compiled per_point / per_pixel block. Constructed by
CompiledBytecode::try_compile and replayed by
CompiledBytecode::run.
Cold variables (custom user vars + cold builtins) are addressed by
their slot index in the MilkContext::cold slab — resolved once
at compile time so Op::LoadCold(idx) / Op::StoreCold(idx) skip
the HashMap probe and String::from allocation the older
name-keyed path paid on every store.
Fields§
§code: Vec<Op>§consts: Vec<f64>Implementations§
Source§impl CompiledBytecode
impl CompiledBytecode
Sourcepub fn try_compile(
nodes: &[Node],
ctx: &mut MilkContext,
) -> Result<Self, CompileError>
pub fn try_compile( nodes: &[Node], ctx: &mut MilkContext, ) -> Result<Self, CompileError>
Translate a block of evalexpr Nodes into bytecode against the
supplied context. Cold-variable names referenced by the block
are interned into MilkContext::cold so the emitted opcodes
carry slab indices instead of string keys.
Returns Err(Unsupported) on the first operator / function the
compiler doesn’t lower — the caller can fall back to evaluating
the Vec<Node> through evalexpr directly.
Sourcepub fn run(&self, ctx: &mut MilkContext)
pub fn run(&self, ctx: &mut MilkContext)
Run the bytecode against ctx. Mutates the context in place
(hot vars, q-channels, custom vars).
§Safety footprint
The inner loop uses get_unchecked to elide bounds checks on
stack, consts, and code. The invariants the bytecode
compiler upholds are:
sp <= STACK_SIZEat every opcode boundary — checked bydebug_assert!on each push.i < consts.len()for everyPushConst(i)—add_constreturns the index it just pushed, so the bytecode never emits a stale index.pc < code.len()— thewhileheader guards each fetch.
On the bench-presets corpus this shaves a few percent off
per-sample VM time; on a tight inner loop with Op::Add /
Op::Mul, every bounds check elided counts.
Trait Implementations§
Source§impl Clone for CompiledBytecode
impl Clone for CompiledBytecode
Source§fn clone(&self) -> CompiledBytecode
fn clone(&self) -> CompiledBytecode
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more