Struct mlem::Machine
[−]
[src]
pub struct Machine<'mach> { /* fields omitted */ }
Represents the state of a machine, including its registers, its memory, its I/O Read and Write, and its program.
The associated lifetime 'mach
represents the life of the machine; its I/O connections must live at
least that long.
Methods
impl<'mach> Machine<'mach>
[src]
fn new(
max_words: usize,
input: &'mach mut Read,
output: &'mach mut Write
) -> Self
max_words: usize,
input: &'mach mut Read,
output: &'mach mut Write
) -> Self
Create a new Machine connected to the given I/O ports.
fn load_program(&mut self, new: Vec<Instruction>)
Load a program into the machine This resets the instruction pointer.
fn get_memory(&self) -> &[Word]
Borrow out the machine's internal memory for examination. When it's borrowed out, the machine can't run.
fn load_memory(&mut self, new: Vec<Word>)
Replace the machine's memory with the given vector.
fn next_instr(&mut self) -> Outcome
Advance to the next instruction (i.e., increment IP). This can cause a Fault, if IP ends up off the end.
fn write_addr(&mut self, a: Address, v: Word) -> Outcome
Write the given word value to the given address. If it's a Literal, this will emit a Fault; otherwise it's a Continue.
fn read_addr(&self, a: Address) -> Word
Read a word from the given address.
fn execute_next(&mut self) -> Outcome
fn run(&mut self) -> Outcome
Execute instructions until a Halt or Fault occurs. BEWARE: This may run forever!
fn run_for(&mut self, cycles: u64) -> (Outcome, u64)
Execute at most the given number of instructions, also stopping on a Halt or Fault condition. Returns the Outcome of the last instruction and the number of instructions executed.