CompiledBytecode

Struct CompiledBytecode 

Source
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

Source

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.

Source

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_SIZE at every opcode boundary — checked by debug_assert! on each push.
  • i < consts.len() for every PushConst(i)add_const returns the index it just pushed, so the bytecode never emits a stale index.
  • pc < code.len() — the while header 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

Source§

fn clone(&self) -> CompiledBytecode

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CompiledBytecode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.