diff --git a/src/main.rs b/src/main.rs index 06d9dee..ae49ac2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -80,10 +80,45 @@ fn parse(contents: String, opcodes: HashMap<&'static str, (i64, i32)>) -> Vec) { - for elem in instructions { - println!("{}", elem); +fn exec(instructions: Vec) -> i64 { + let mut stack: Vec = Vec::new(); + let ilen = instructions.len(); + let mut ip = 0; + while ip < ilen { + ip += 1; /* TMP */ + match instructions[ip] { + /* ENT */ 0 => (), + /* ADD */ 1 => (), + /* SUB */ 2 => (), + /* MUL */ 3 => (), + /* DIV */ 4 => (), + /* MOD */ 5 => (), + /* LT */ 6 => (), + /* EQ */ 7 => (), + /* GT */ 8 => (), + /* BR */ 9 => (), + /* BRT */ 10 => (), + /* BRF */ 11 => (), + /* CST */ 12 => (), + /* LD */ 13 => (), + /* GLD */ 14 => (), + /* ST */ 15 => (), + /* GST */ 16 => (), + /* PRN */ 17 => (), + /* POP */ 18 => (), + /* HLT */ 19 => break, + /* LEQ */ 20 => (), + /* GEQ */ 21 => (), + /* CAL */ 22 => (), + /* RET */ 23 => (), + /* IPR */ 24 => (), + /* FET */ 25 => (), + /* INC */ 26 => (), + /* DEC */ 27 => (), + /* IMP */ x => panic!("Unknown instruction {}!", x) + } } + return *stack.first().unwrap_or(&0); } fn main() { @@ -109,5 +144,5 @@ fn main() { let parsed = parse(contents, opcodes); - let execd = exec(parsed); + println!("{}", exec(parsed)); }