pub trait MachineInstruction: Sized + Clone {
fn execute<R: MachineRegister, O: OutputReceiver<R>>(
&self,
register: &mut R,
output_receiver: &mut O
) -> i64;
fn from_parsed_machine_instruction(
parsed: &ParsedMachineInstruction
) -> Result<Self, ParseError>;
fn from_str(instruction: &str) -> Result<Self, ParseError> { ... }
}
Expand description
A machine instruction.
Required Methods
sourcefn execute<R: MachineRegister, O: OutputReceiver<R>>(
&self,
register: &mut R,
output_receiver: &mut O
) -> i64
fn execute<R: MachineRegister, O: OutputReceiver<R>>(
&self,
register: &mut R,
output_receiver: &mut O
) -> i64
Executes this instruction. Returns an offset indicating the next instruction. For example,
an offset of 1 means “go to the next instruction”, an offset of -1 means “go to the previous
instruction”, an offset of 3 means “skip two instructions” and an offset of 0 means “repeat
the current instruction”. If this offset causes the program counter to point to a
non-existing instruction (i.e. either the counter becomes negative, or greater than the
number of instructions), this will cause the program to halt. If you want to abort the
program, you can just return i64::MIN
. This will always cause the program counter to
become negative, and will thus halt the program.
sourcefn from_parsed_machine_instruction(
parsed: &ParsedMachineInstruction
) -> Result<Self, ParseError>
fn from_parsed_machine_instruction(
parsed: &ParsedMachineInstruction
) -> Result<Self, ParseError>
Implement this method to be able to use the provided from_str
method to parse
instructions.
Provided Methods
sourcefn from_str(instruction: &str) -> Result<Self, ParseError>
fn from_str(instruction: &str) -> Result<Self, ParseError>
Parses an instruction using ParsedMachineInstruction
and
from_parsed_machine_instruction
.