eval: added run loop stub

This commit is contained in:
2017-05-26 16:21:47 -04:00
parent 3ea766724c
commit 8272f2939a

View File

@@ -80,11 +80,46 @@ fn parse(contents: String, opcodes: HashMap<&'static str, (i64, i32)>) -> Vec<i6
return code
}
fn exec(instructions: Vec<i64>) {
for elem in instructions {
println!("{}", elem);
fn exec(instructions: Vec<i64>) -> i64 {
let mut stack: Vec<i64> = 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() {
let opcodes = build_opcodes();
@@ -109,5 +144,5 @@ fn main() {
let parsed = parse(contents, opcodes);
let execd = exec(parsed);
println!("{}", exec(parsed));
}