[][src]Struct stack_vm::Code

pub struct Code<T> {
    pub symbols: Vec<(usize, String)>,
    pub code: Vec<usize>,
    pub data: Vec<T>,
    pub labels: Vec<(usize, String)>,
}

A structure containing runnable or dumpable code.

See the module-level docs for more details.

Fields

symbols: Vec<(usize, String)>code: Vec<usize>data: Vec<T>labels: Vec<(usize, String)>

Methods

impl<T: Debug> Code<T>[src]

pub fn empty() -> Code<T>[src]

Create an empty code.

Not useful for anything except tests and documentation.

pub fn symbols(&self) -> &[(usize, String)][src]

Retrieve a list of all symbols in the code.

This is a list of tuples containing op codes and instruction names.

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

Retrieve a list of instructions in the code.

This is the executable source program of the code. It is a simple format based around the following:

| Op Code | No of args | Args ...         |
| 0x01    | 0x03       | 0x01, 0x02, 0x03 |

pub fn data(&self) -> &[T][src]

Retrieve the constant data compiled into the code.

pub fn labels(&self) -> &[(usize, String)][src]

Retrieve a list of labels used in the program.

Returns a list of tuples containing the IP of the label and the name of the label.

pub fn get_label_ip(&self, name: &str) -> Option<usize>[src]

Returns the IP for a given label.

This function is used within the Machine to perform jumps.

Trait Implementations

impl<T: FromByteCode + Debug> FromByteCode for Code<T>[src]

impl<T: ToByteCode + Debug> ToByteCode for Code<T>[src]

fn to_byte_code(&self, buf: &mut dyn Write)[src]

Create bytecode for this Code.

Encodes into a Map of the following format:

{
    "code" => [ 0, 1, 0, 0, 1, 1, 1, 0 ],
    "data" => [ 123, 456 ],
    "symbols" => [ 0, "push", 1, "add" ],
    "labels" => [ 0, "main" ]
}

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<T: Debug> Debug for Code<T>[src]

Auto Trait Implementations

impl<T> Send for Code<T> where
    T: Send

impl<T> Sync for Code<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]