Struct stack_vm::Machine [] [src]

pub struct Machine<'a, T: 'a + Debug> {
    pub code: Code<T>,
    pub instruction_table: &'a InstructionTable<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 Code, used describe the source instructions and data to execute.
  • An instruction pointer, which points to the currently-executing instruciton.
  • A Table of constants, which you can use in your instructions if needed.
  • A Stack of Frame used to keep track of calls being executed.
  • A Stack of T which is used as the main operand stack.

Fields

Methods

impl<'a, T: 'a + Debug> Machine<'a, T>
[src]

[src]

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.

[src]

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

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

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

[src]

Set a local variable in the current call frame.

Places a value in the frame's local variable table.

[src]

Push an operand onto the operand stack.

[src]

Pop an operand off the operand stack.

[src]

Retrieve a reference to a T stored in the Code's data section.

[src]

Perform a jump to a named label.

This method performs the following actions: * Retrieve the instruction pointer for a given label from the Code. * Create a new frame with it's return address set to the current instruction pointer. * Push the new frame onto the call stack. * Set the machine's instruction pointer to the new location.

This method specifically does not transfer operands to call arguments.

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

The last call frame contains a return address at the end of the source code, so the machine will stop executing at the beginning of the next iteration.

If you call ret too many times then the machine will panic when it attempts to pop the last frame off the stack.