Crate mlem [−] [src]
MLeM
The Machine Learning Machine is a 64-bit virtual Harvard-arch machine for evolutionary algorithms to program against.
The machine has eight GPRs (R0
through R7
), a hardware stack with SP and BP,
and hardware I/O with Input and Output.
These I/O instructions write out whole u64
s in big endian using byteorder
.
Example
use mlem::{execute, Instruction, Address, Register, Outcome}; let input = vec![2, 2, 2, 2]; let expected = vec![4, 0]; let program = vec![ // Get all input values Instruction::Input(Address::RegAbs(Register::R0)), Instruction::Input(Address::RegAbs(Register::R1)), Instruction::Input(Address::RegAbs(Register::R2)), Instruction::Input(Address::RegAbs(Register::R3)), // Perform arithmetic Instruction::Add(Address::RegAbs(Register::R0), Address::RegAbs(Register::R1)), Instruction::Sub(Address::RegAbs(Register::R2), Address::RegAbs(Register::R3)), // Output computed values Instruction::Output(Address::RegAbs(Register::R0)), Instruction::Output(Address::RegAbs(Register::R2)), // Halt Instruction::Halt ]; // The last value here is the maximum number of instructions to let the program run for. let (outcome, cycles, output) = execute(program, input, Some(10)); assert!(outcome == Outcome::Halt, "Program did not successfully halt! {:?}", outcome); assert!(output == expected, "Program did not produce {:?} as expected, but rather {:?}, in {} cycles.", expected, output, cycles);
Structs
Machine |
Represents the state of a machine, including its registers, its memory, its I/O Read and Write, and its program. |
Enums
Address |
Represents a place a value can come from: a register, a memory address, a pointer to memory stored in a register, or a literal value. |
Instruction |
Possible instructions for the machine to execute. For each instruction, the first operand is a, second is b, et cetera |
Outcome |
Represents the outcome of a program run; a halt (graceful termination) or a fault (hardware error), or a state of continuation, in which the computer can keep running. |
Register |
Specifies a register in the machine. |
Functions
execute |
Given a Program (that is, a Vec of Instructions), this function will manage creating a Machine and hooking up its Input and Output for you. It returns a tuple of the final outcome of the program, the number of instructions executed, and a Vector of the output. |
Type Definitions
JumpLocation |
A JumpLocation is a place on the instruction tape, which is a vector, so it should be indexable. |
Program |
Represents a program; a list of instructions, to be executed in order. |
Word |
Represents a machine word - an atomic int, a pointer, etc. Words are u64s; signed math has to do conversion. |