Struct stack_vm::Machine
[−]
[src]
pub struct Machine<'a, T: 'a + Debug> { pub builder: Builder<'a, T>, pub ip: usize, pub constants: &'a Table<Item = T>, pub call_stack: Stack<Frame<T>>, pub operand_stack: Stack<T>, }
Machine contains all the information needed to run your program.
- A
Builder, used describe the source instructions and data to execute. - An instruction pointer, which points to the currently-executing instruciton.
- A
Tableof constants, which you can use in your instructions if needed. - A
StackofFrameused to keep track of calls being executed. - A
StackofTwhich is used as the main operand stack.
Fields
builder: Builder<'a, T>
ip: usize
constants: &'a Table<Item = T>
call_stack: Stack<Frame<T>>
operand_stack: Stack<T>
Methods
impl<'a, T: 'a + Debug> Machine<'a, T>[src]
fn new(
builder: Builder<'a, T>,
constants: &'a Table<Item = T>
) -> Machine<'a, T>[src]
builder: Builder<'a, T>,
constants: &'a Table<Item = T>
) -> Machine<'a, T>
Returns a new Machine ready to execute instructions.
The machine is initialised by passing in your Builder which contains
all the code and data of your program, and a Table of constants.
fn run(machine: Machine<'a, T>) -> Machine<'a, T>[src]
Run the machine.
Kick off the process of running the program.
Steps through the instructions in your program executing them one-by-one. Each instruction function is executed, much like a callback.
Stops when either the last instruction is executed or when the last frame is removed from the call stack.
fn get_local(&self, name: &str) -> Option<&T>[src]
Look up a local variable in the current call frame.
Note that the variable may not be set in the current frame but it's up to your instruction to figure out how to deal with this situation.
fn get_local_deep(&self, name: &str) -> Option<&T>[src]
Look for a local variable in all call frames.
The machine will look in each frame in the call stack starting at the top and moving down until it locates the local variable in question or runs out of stack frames.
fn set_local(&mut self, name: &str, value: T)[src]
Set a local variable in the current call frame.
Places a value in the frame's local variable table.
fn operand_push(&mut self, value: T)[src]
Push an operand onto the operand stack.
fn operand_pop(&mut self) -> T[src]
Pop an operand off the operand stack.
fn get_data(&self, idx: usize) -> &T[src]
Retrieve a reference to a T stored in the builder's data section.
fn jump(&mut self, label: &str)[src]
Perform a jump to a named label.
This method performs the following actions: * Retrieve the instruction pointer for a given label from the builder. * Create a new frame with it's return address set to the current instruction pointer. * Push the new frame onto the call stack.
This method specifically does not transfer operands to call arguments.
fn ret(&mut self)[src]
Performs a return.
This method pops the top frame off the call stack and moves the instruction pointer back to the frame's return address. It's up to you to push your return value onto the operand stack (if your language has such return semantics).