[][src]Struct stack_vm::Builder

pub struct Builder<'a, T: 'a + Debug + PartialEq> {
    pub instruction_table: &'a InstructionTable<T>,
    pub instructions: Vec<usize>,
    pub labels: WriteOnceTable<usize>,
    pub data: Vec<T>,
}

The builder struct.

Contains:

  • an InstructionTable.
  • a list of instructions that have been pushed into this builder.
  • a Table of labels used for jumping.
  • a list of T to be stored in the builder's data section.

Fields

instruction_table: &'a InstructionTable<T>instructions: Vec<usize>labels: WriteOnceTable<usize>data: Vec<T>

Methods

impl<'a, T: Debug + PartialEq> Builder<'a, T>[src]

pub fn new(instruction_table: &'a InstructionTable<T>) -> Builder<T>[src]

Create a new Builder from an InstructionTable.

pub fn push(&mut self, name: &str, args: Vec<T>)[src]

Push an instruction into the code.

  • name should match that of an instruction in the InstructionTable.
  • args a vector of operands to be pushed into the builder's data section.

pub fn label(&mut self, name: &str)[src]

Insert a label at this point in the code.

Labels are used as targets for jumps. When you call this method a label is stored which points to the position of the next instruction.

pub fn len(&self) -> usize[src]

Return the length of the instructions vector.

i.e. the number of instructions pushed so far.

pub fn is_empty(&self) -> bool[src]

Return whether the Builder contains any instructions.

Trait Implementations

impl<'a, T: Debug + PartialEq> From<Builder<'a, T>> for Code<T>[src]

fn from(builder: Builder<T>) -> Code<T>[src]

Convert a Builder into Code.

This function consumes the builder and returns a Code.

impl<'a, T: 'a + Debug + PartialEq> Debug for Builder<'a, T>[src]

Auto Trait Implementations

impl<'a, T> Send for Builder<'a, T> where
    T: Send

impl<'a, T> Sync for Builder<'a, T> where
    T: Sync

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]