Struct Code

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

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)>

Implementations§

Source§

impl<T: Debug> Code<T>

Source

pub fn empty() -> Code<T>

Create an empty code.

Not useful for anything except tests and documentation.

Source

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

Retrieve a list of all symbols in the code.

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

Source

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

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

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

Retrieve the constant data compiled into the code.

Source

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

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.

Source

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

Returns the IP for a given label.

This function is used within the Machine to perform jumps.

Trait Implementations§

Source§

impl<T: Debug> Debug for Code<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.

Source§

impl<T: FromByteCode + Debug> FromByteCode for Code<T>

Source§

fn from_byte_code(buf: &mut dyn Read) -> Code<T>

Convert from MsgPack to your type. Read more
Source§

impl<T: ToByteCode + Debug> ToByteCode for Code<T>

Source§

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

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" ]
}

Auto Trait Implementations§

§

impl<T> Freeze for Code<T>

§

impl<T> RefUnwindSafe for Code<T>
where T: RefUnwindSafe,

§

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

§

impl<T> Sync for Code<T>
where T: Sync,

§

impl<T> Unpin for Code<T>
where T: Unpin,

§

impl<T> UnwindSafe for Code<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.