Struct stack_vm::Code
[−]
[src]
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]
fn from_builder(builder: Builder<T>) -> Code<T>
[src]
Create a code object from a builder.
This function consumes the builder, making it unusable after it has been converted.
fn empty() -> Code<T>
[src]
Create an empty code.
Not useful for anything except tests and documentation.
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.
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 |
fn data(&self) -> &[T]
[src]
Retrieve the constant data compiled into the code.
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.
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: ToByteCode + Debug> ToByteCode for Code<T>
[src]
fn to_byte_code(&self, buf: &mut Write)
[src]
Create bytecode for this Code
.
Encodes into a Map of the following format:
json { "code" => [ 0, 1, 0, 0, 1, 1, 1, 0 ], "data" => [ 123, 456 ], "symbols" => [ 0, "push", 1, "add" ], "labels" => [ 0, "main" ] }
impl<T: FromByteCode + Debug> FromByteCode for Code<T>
[src]
fn from_byte_code(buf: &mut Read) -> Code<T>
[src]
Convert from MsgPack to your type. Read more