项目作者: NoraCodes

项目描述 :
Machine Learning Machine - a VM for machine learning
高级语言: Rust
项目地址: git://github.com/NoraCodes/mlem.git
创建时间: 2017-04-02T23:26:33Z
项目社区:https://github.com/NoraCodes/mlem

开源协议:

下载


MLeM

Crates.io version badge
Docs.rs version badge

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 u64s in big endian using byteorder.

Features

The serialize feature imports serde and derives Serialize and Deserialize on all
types. It is enabled by default.

Example

This example shows a simple program being executed by the MLeM managed execution routine.

  1. use mlem::{execute, Instruction, Address, Register, Outcome};
  2. let input = vec![2, 2, 2, 2];
  3. let expected = vec![4, 0];
  4. let program = vec![
  5. // Get all input values
  6. Instruction::Input(Address::RegAbs(Register::R0)),
  7. Instruction::Input(Address::RegAbs(Register::R1)),
  8. Instruction::Input(Address::RegAbs(Register::R2)),
  9. Instruction::Input(Address::RegAbs(Register::R3)),
  10. // Perform arithmetic
  11. Instruction::Add(Address::RegAbs(Register::R0), Address::RegAbs(Register::R1)),
  12. Instruction::Sub(Address::RegAbs(Register::R2), Address::RegAbs(Register::R3)),
  13. // Output computed values
  14. Instruction::Output(Address::RegAbs(Register::R0)),
  15. Instruction::Output(Address::RegAbs(Register::R2)),
  16. // Halt
  17. Instruction::Halt
  18. ];
  19. //!
  20. let (outcome, _, output) = execute(program, input);
  21. assert!(outcome == Outcome::Halt, "Program did not successfully halt! {:?}", outcome);
  22. assert!(output == expected, "Program did not produce {:?} as expected, but rather {:?}.", expected, output);