This repository has been archived on 2025-02-21. You can view files and clone it, but cannot push or open issues or pull requests.
corten/src/instruction.rs
2020-02-06 16:37:23 -05:00

45 lines
No EOL
755 B
Rust

#[derive(Debug, PartialEq)]
pub enum Opcode {
HLT,
IGL
}
impl From<u8> for Opcode {
fn from(vm: u8) -> Self {
match vm {
0 => Opcode::HLT,
_ => Opcode::IGL
}
}
}
#[derive(Debug, PartialEq)]
pub struct Instruction {
opcode: Opcode
}
impl Instruction {
pub fn new(opcode: Opcode) -> Self {
Instruction {
opcode
}
}
}
#[cfg(test)]
mod instruction_tests {
use crate::instruction::*;
#[test]
fn test_crate_hlt() {
let opcode = Opcode::HLT;
assert_eq!(opcode, Opcode::HLT);
}
#[test]
fn test_create_instruction() {
let inst = Instruction::new(Opcode::HLT);
assert_eq!(inst.opcode, Opcode::HLT);
}
}