[][src]Struct xmachine::Machine

pub struct Machine {
    pub stack: Vec<Ref<Value>>,
    pub registers: BTreeMap<String, Ref<Value>>,
}

Fields

stack: Vec<Ref<Value>>

A dynamically allocated stack to push and pop values onto and off of

registers: BTreeMap<String, Ref<Value>>

The place to store named values (variables)

Methods

impl Machine[src]

pub fn new() -> Self[src]

Return a new instance of a Machine with empty stack and registers

pub fn get_arg(&mut self) -> Value[src]

#################################################### The following functions are meant to be used to interface and interact with the virtual machine #################################################### FOR FOREIGN FUNCTIONS This gets an argument from the call to this foreign function by popping a value off the stack, and removing the reference

pub fn return_value(&mut self, value: Value)[src]

FOR FOREIGN FUNCTIONS This pushes a return value onto the stack

pub fn duplicate(self) -> Self[src]

#################################################### The following functions represent instructions that are natively supported by the virtual machine. These are not meant to be used by foreign functions, but they CAN be used without worry. #################################################### This function duplicates the current machine. This is VERY IMPORTANT. It iterates through the stack and copies each item into a new machine.

This is ONLY used to create the context for functions. If we don't do this, the context Machine never goes out of scope, and never lets the Refs die. This causes a memory leak.

The addition of this method fixes the memory leak.

pub fn push(&mut self, value: Ref<Value>)[src]

Push an item onto the stack

pub fn pop(&mut self) -> Ref<Value>[src]

Pop an item off of the stack, and return it If the stack is empty, return an Error

pub fn copy(&mut self)[src]

  1. Pop off a REFERENCE value from the stack
  2. Push a copy the object and remove the reference

pub fn assign(&mut self)[src]

  1. Pop off a REFERENCE value from the stack
  2. Pop off a VALUE value from the stack
  3. Assign the value of VALUE to the memory location of REFERENCE

This can be used to assign to an indexed value from a list or table

pub fn index(&mut self)[src]

  1. Pop off the INDEX value from the stack
  2. Pop off a TABLE value from the stack
  3. Push the TABLE[INDEX] reference onto the stack

pub fn method_call(&mut self)[src]

  1. Pop off the INDEX value from the stack
  2. Pop off a TABLE value from the stack
  3. Push the TABLE onto the stack
  4. Call the value at TABLE[INDEX] as a function

pub fn call(&mut self)[src]

  1. Pop off function from the stack
  2. Call it with this Machine instance

pub fn while_loop(&mut self)[src]

  1. Pop off a CONDITION function from the stack
  2. Pop off a BODY function from the stack
  3. Call the CONDITION function with the context of this instance
  4. If the return value is true, run the BODY function with the context of this instance
  5. Goto step 3

pub fn if_then_else(&mut self)[src]

  1. Pop off a CONDITION function from the stack
  2. Pop off a THEN function from the stack
  3. Pop off an ELSE function from the stack
  4. Call the CONDITION function with the context of this instance
  5. If the return value is true, run the THEN function with the context of this instance
  6. If the return value is false, run the ELSE function with the context of this instance

pub fn store(&mut self)[src]

  1. Pop off a KEY value from the stack
  2. Pop off a VALUE value from the stack
  3. Assign the value of VALUE to the register named KEY

pub fn load(&mut self)[src]

  1. Pop off a KEY value from the stack
  2. Push the value in the register named KEY to the stack

Trait Implementations

impl PartialEq<Machine> for Machine[src]

impl PartialOrd<Machine> for Machine[src]

impl Display for Machine[src]

How to print Machine / convert Machine to string This is for debugging code and seeing the current instance of the machine

impl Clone for Machine[src]

impl Default for Machine[src]

Auto Trait Implementations

impl Unpin for Machine

impl !Send for Machine

impl !Sync for Machine

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryInto<U> 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> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]