enum Bytecode {
Nop,
Push(i64),
BinaryAdd,
Print,
}
use Bytecode::*;
static CODE: &'static [Bytecode] = &[
Push(9),
Push(5),
BinaryAdd,
Print,
];
fn main() {
let mut stack = Vec::new();
for element in CODE {
match *element {
Nop => {},
Push(x) => { stack.push(x) },
BinaryAdd => {
let v = stack.pop().unwrap();
*stack.last_mut().unwrap() += v;
},
Print => { println!("{}", stack.pop().unwrap()); },
}
}
}
Comments