[−][src]Struct melon::VM
The state of the VM
Fields
mem: Vec<u8>
The memory allocated and used by the VM
return_value: u8
The return value of the VM
Methods
impl VM
[src]
pub fn exec<T: System>(
&mut self,
program: &Program,
system: &mut T
) -> Result<u8>
[src]
&mut self,
program: &Program,
system: &mut T
) -> Result<u8>
Executes the given program using the given system and returns the program's exit status
pub fn halt(&mut self)
[src]
Stops execution and shuts down the VM
pub fn read_u8(&mut self, addr: Address) -> Result<u8>
[src]
Returns the u8 at the given address
pub fn write_u8(&mut self, addr: Address, value: u8) -> Result<()>
[src]
Writes the given u8 to the given address
pub fn read_u16(&mut self, addr: Address) -> Result<u16>
[src]
Returns the u16 at the given address
pub fn write_u16(&mut self, addr: Address, value: u16) -> Result<()>
[src]
Writes the given u16 to the given address
pub fn pop_u8(&mut self) -> Result<u8>
[src]
Helper method for popping a u8 value off the stack
pub fn pop_u16(&mut self) -> Result<u16>
[src]
Helper method for popping a u16 value off the stack
pub fn pop_i8(&mut self) -> Result<i8>
[src]
Helper method for popping a i8 value off the stack
pub fn pop_i16(&mut self) -> Result<i16>
[src]
Helper method for popping a i16 value off the stack
pub fn pop_u8_lr(&mut self) -> Result<(u8, u8)>
[src]
Returns two u8 values as (left-hand-side, right-hand-side)
pub fn pop_u16_lr(&mut self) -> Result<(u16, u16)>
[src]
Returns two u16 values as (left-hand-side, right-hand-side)
pub fn pop_i8_lr(&mut self) -> Result<(i8, i8)>
[src]
Returns two i8 values as (left-hand-side, right-hand-side)
pub fn pop_i16_lr(&mut self) -> Result<(i16, i16)>
[src]
Returns two i16 values as (left-hand-side, right-hand-side)
pub fn add(&mut self, ty: IntegerType) -> Result<()>
[src]
Pops two values of the given type off the stack, adds them together and pushes the result back on the stack
pub fn sub(&mut self, ty: IntegerType) -> Result<()>
[src]
Pops two values of the given type off the stack, subtracts the second from the first and pushes the result back on the stack
pub fn mul(&mut self, ty: IntegerType) -> Result<()>
[src]
Pops two values of the given type off the stack, multiplies them and pushes the result back on the stack
pub fn div(&mut self, ty: IntegerType) -> Result<()>
[src]
Pops two values of the given type off the stack, divides the first through the second and pushes the result back on the stack
pub fn shr(&mut self, ty: IntegerType) -> Result<()>
[src]
Pops two values of the given type off the stack, uses the second one to shift the bits of the first one to the right and pushes the result back onto the stack
pub fn shl(&mut self, ty: IntegerType) -> Result<()>
[src]
Pops two values of the given type off the stack, uses the second one to shift the bits of the first one to the left and pushes the result back onto the stack
pub fn and(&mut self, ty: IntegerType) -> Result<()>
[src]
Pops two values of the given type off the stack, applies a bitwise and to both and pushes the result back onto the stack
pub fn or(&mut self, ty: IntegerType) -> Result<()>
[src]
Pops two values of the given type off the stack, applies a bitwise or to both and pushes the result back onto the stack
pub fn xor(&mut self, ty: IntegerType) -> Result<()>
[src]
Pops two values of the given type off the stack, applies a bitwise or to both and pushes the result back onto the stack
pub fn not(&mut self, ty: IntegerType) -> Result<()>
[src]
Applies a bitwise not operation to the top stack value
pub fn neg(&mut self, ty: IntegerType) -> Result<()>
[src]
Applies a negation on the top stack value
pub fn cmp(&mut self, ty: IntegerType) -> Result<()>
[src]
Compares the top two values of the stack by applying a subtraction on them and saving the result in the cmp register
pub fn inc(&mut self, ty: IntegerType) -> Result<()>
[src]
Increments the top stack value
pub fn dec(&mut self, ty: IntegerType) -> Result<()>
[src]
Decrements the top stack value
pub fn u8_promote(&mut self) -> Result<()>
[src]
Converts a u8 to a u16
pub fn u16_demote(&mut self) -> Result<()>
[src]
Converts a u16 to a u8
pub fn i8_promote(&mut self) -> Result<()>
[src]
Converts a i8 to a i16
pub fn i16_demote(&mut self) -> Result<()>
[src]
Converts a i16 to a i8
pub fn push_const_u8(&mut self, value: u8) -> Result<()>
[src]
Pushes the given u8 onto the stack
pub fn push_const_u16(&mut self, value: u16) -> Result<()>
[src]
Pushes the given u16 onto the stack
pub fn push_const_i8(&mut self, value: i8) -> Result<()>
[src]
Pushes the given i8 onto the stack
pub fn push_const_i16(&mut self, value: i16) -> Result<()>
[src]
Pushes the given i16 onto the stack
pub fn load_reg(&mut self, reg: Register) -> Result<()>
[src]
Loads the value from the given register and pushes it onto the stack
pub fn load(&mut self, ty: IntegerType, addr: Address) -> Result<()>
[src]
Loads the value from the given address and pushes it to the stack
pub fn load_indirect(&mut self, ty: IntegerType) -> Result<()>
[src]
Like load but takes the address off the stack before storing
pub fn store(&mut self, ty: IntegerType, addr: Address) -> Result<()>
[src]
Takes the top value off the stack and stores it at the given address
pub fn store_indirect(&mut self, ty: IntegerType) -> Result<()>
[src]
Like store but takes the address off the stack before storing
pub fn dup(&mut self, ty: IntegerType) -> Result<()>
[src]
Duplicates the top stack value and pushes it onto the stack
pub fn drop(&mut self, ty: IntegerType) -> Result<()>
[src]
Discards the top stack value
pub fn call(&mut self, addr: Address) -> Result<()>
[src]
Calls the function at the given address
pub fn ret(&mut self) -> Result<()>
[src]
Returns from a function call
pub fn alloc(&mut self, amount: u16) -> Result<()>
[src]
Allocates the given number of bytes in the heap
pub fn free(&mut self) -> Result<()>
[src]
Undos the last allocation and frees the memory
pub fn jmp(&mut self, forward: bool, addr: Address) -> Result<()>
[src]
Jumps unconditionally in the given direction
pub fn jneq(&mut self, forward: bool, addr: Address) -> Result<()>
[src]
Jumps in the given direction if the compared values are not equal
pub fn jeq(&mut self, forward: bool, addr: Address) -> Result<()>
[src]
Jumps in the given direction if the compared values are equal
pub fn jlt(&mut self, forward: bool, addr: Address) -> Result<()>
[src]
Jumps in the given direction if value a is less than value b
pub fn jlt_eq(&mut self, forward: bool, addr: Address) -> Result<()>
[src]
Jumps in the given direction if value a is less than or equal to value b
pub fn jgt(&mut self, forward: bool, addr: Address) -> Result<()>
[src]
Jumps in the given direction if value a is greater than value b
pub fn jgt_eq(&mut self, forward: bool, addr: Address) -> Result<()>
[src]
Jumps in the given direction if value a is greater than or equal to value b
Trait Implementations
impl Clone for VM
[src]
impl Debug for VM
[src]
impl Default for VM
[src]
impl<'de> Deserialize<'de> for VM
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
impl Serialize for VM
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,