Struct melon::VM
[−]
[src]
pub struct VM { pub mem: Vec<SmallUInt>, pub return_value: SmallUInt, // some fields omitted }
The state of the VM
Fields
mem: Vec<SmallUInt>
The memory allocated and used by the VM
return_value: SmallUInt
The return value of the VM
Methods
impl VM
[src]
pub fn exec<T: System>(
&mut self,
program: &Program,
system: &mut T
) -> Result<SmallUInt>
[src]
&mut self,
program: &Program,
system: &mut T
) -> Result<SmallUInt>
Executes the given program using the given system and returns the program's exit status
pub fn pc(&mut self) -> Address
[src]
Returns the current value of the program counter
pub fn sp(&mut self) -> Address
[src]
Returns the current value of the stack pointer
pub fn bp(&mut self) -> Address
[src]
Returns the current value of the base pointer
pub fn program(&mut self) -> Vec<Instruction>
[src]
Returns the full list of instructions for the current program
pub fn current_instruction(&mut self) -> Result<Instruction>
[src]
Returns the instruction at the current pc
pub fn halt(&mut self)
[src]
Stops execution and shuts down the VM
pub fn read_u8(&mut self, addr: Address) -> Result<SmallUInt>
[src]
Returns the u8 at the given address
pub fn write_u8(&mut self, addr: Address, value: SmallUInt) -> Result<()>
[src]
Writes the given u8 to the given address
pub fn read_u16(&mut self, addr: Address) -> Result<UInt>
[src]
Returns the u16 at the given address
pub fn write_u16(&mut self, addr: Address, value: UInt) -> Result<()>
[src]
Writes the given u16 to the given address
pub fn pop_u8(&mut self) -> Result<SmallUInt>
[src]
Helper method for popping a u8 value off the stack
pub fn pop_u16(&mut self) -> Result<UInt>
[src]
Helper method for popping a u16 value off the stack
pub fn pop_i8(&mut self) -> Result<SmallInt>
[src]
Helper method for popping a i8 value off the stack
pub fn pop_i16(&mut self) -> Result<Int>
[src]
Helper method for popping a i16 value off the stack
pub fn pop_u8_lr(&mut self) -> Result<(SmallUInt, SmallUInt)>
[src]
Returns two u8 values as (left-hand-side, right-hand-side)
pub fn pop_u16_lr(&mut self) -> Result<(UInt, UInt)>
[src]
Returns two u16 values as (left-hand-side, right-hand-side)
pub fn pop_i8_lr(&mut self) -> Result<(SmallInt, SmallInt)>
[src]
Returns two i8 values as (left-hand-side, right-hand-side)
pub fn pop_i16_lr(&mut self) -> Result<(Int, Int)>
[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 tio 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: SmallUInt) -> Result<()>
[src]
Pushes the given u8 onto the stack
pub fn push_const_u16(&mut self, value: UInt) -> Result<()>
[src]
Pushes the given u16 onto the stack
pub fn push_const_i8(&mut self, value: SmallInt) -> Result<()>
[src]
Pushes the given i8 onto the stack
pub fn push_const_i16(&mut self, value: Int) -> 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)
[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: UInt) -> 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 jnz(&mut self, forward: bool, addr: Address) -> Result<()>
[src]
Jumps if the value of the cmp register is not zero, in the given direction
pub fn jz(&mut self, forward: bool, addr: Address) -> Result<()>
[src]
Jumps if the value of the cmp register is zero, in the given direction
pub fn jn(&mut self, forward: bool, addr: Address) -> Result<()>
[src]
Jumps if the value of the cmp register is negative, in the given direction
pub fn jp(&mut self, forward: bool, addr: Address) -> Result<()>
[src]
Jumps if the value of the cmp register is positive, in the given direction