eval: added run loop stub
This commit is contained in:
43
src/main.rs
43
src/main.rs
@@ -80,10 +80,45 @@ fn parse(contents: String, opcodes: HashMap<&'static str, (i64, i32)>) -> Vec<i6
|
|||||||
return code
|
return code
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exec(instructions: Vec<i64>) {
|
fn exec(instructions: Vec<i64>) -> i64 {
|
||||||
for elem in instructions {
|
let mut stack: Vec<i64> = Vec::new();
|
||||||
println!("{}", elem);
|
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() {
|
fn main() {
|
||||||
@@ -109,5 +144,5 @@ fn main() {
|
|||||||
|
|
||||||
let parsed = parse(contents, opcodes);
|
let parsed = parse(contents, opcodes);
|
||||||
|
|
||||||
let execd = exec(parsed);
|
println!("{}", exec(parsed));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user