Struct Builder

Source
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>,
}
Expand description

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>

Implementations§

Source§

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

Source

pub fn new(instruction_table: &'a InstructionTable<T>) -> Builder<'_, T>

Create a new Builder from an InstructionTable.

Source

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

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

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

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.

Source

pub fn len(&self) -> usize

Return the length of the instructions vector.

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

Source

pub fn is_empty(&self) -> bool

Return whether the Builder contains any instructions.

Trait Implementations§

Source§

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

Source§

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

Formats the value using the given formatter. Read more
Source§

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

Source§

fn from(builder: Builder<'_, T>) -> Code<T>

Convert a Builder into Code.

This function consumes the builder and returns a Code.

Auto Trait Implementations§

§

impl<'a, T> Freeze for Builder<'a, T>

§

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

§

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

§

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

§

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

§

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

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.