Skip to main content

ChunkBuilder

Struct ChunkBuilder 

Source
pub struct ChunkBuilder { /* private fields */ }
Expand description

A DSL-style builder for constructing bytecode chunks.

Allows fluent construction of bytecode sequences without manually managing jump offsets.

Implementations§

Source§

impl ChunkBuilder

Source

pub fn new(name: &str) -> Self

Create a new builder for a chunk with the given name.

Source

pub fn push_nat(self, n: u64) -> Self

Emit a Push(n) instruction.

Source

pub fn push_bool(self, b: bool) -> Self

Emit a PushBool(b) instruction.

Source

pub fn push_str(self, s: &str) -> Self

Emit a PushStr(s) instruction.

Source

pub fn push_nil(self) -> Self

Emit PushNil.

Source

pub fn add(self) -> Self

Emit Add.

Source

pub fn sub(self) -> Self

Emit Sub.

Source

pub fn mul(self) -> Self

Emit Mul.

Source

pub fn div(self) -> Self

Emit Div.

Source

pub fn modulo(self) -> Self

Emit Mod.

Source

pub fn eq(self) -> Self

Emit Eq.

Source

pub fn lt(self) -> Self

Emit Lt.

Source

pub fn le(self) -> Self

Emit Le.

Source

pub fn not(self) -> Self

Emit Not.

Source

pub fn and(self) -> Self

Emit And.

Source

pub fn or(self) -> Self

Emit Or.

Source

pub fn dup(self) -> Self

Emit Dup.

Source

pub fn pop(self) -> Self

Emit Pop.

Source

pub fn swap(self) -> Self

Emit Swap.

Source

pub fn load(self, idx: u32) -> Self

Emit Load(idx).

Source

pub fn store(self, idx: u32) -> Self

Emit Store(idx).

Source

pub fn load_global(self, name: &str) -> Self

Emit LoadGlobal(name).

Source

pub fn jump(self, offset: i32) -> Self

Emit Jump(offset).

Source

pub fn jump_if(self, offset: i32) -> Self

Emit JumpIf(offset).

Source

pub fn jump_if_not(self, offset: i32) -> Self

Emit JumpIfNot(offset).

Source

pub fn call(self, pos: u32) -> Self

Emit Call(pos).

Source

pub fn ret(self) -> Self

Emit Return.

Source

pub fn make_closure(self, n: u32) -> Self

Emit MakeClosure(n).

Source

pub fn apply(self) -> Self

Emit Apply.

Source

pub fn halt(self) -> Self

Emit Halt.

Source

pub fn build(self) -> BytecodeChunk

Finalize and return the built chunk.

Source

pub fn current_ip(&self) -> usize

Current number of opcodes in the builder.

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> 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, 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.