Skip to content

Instantly share code, notes, and snippets.

@aarroyoc
Created August 27, 2014 10:45
Show Gist options
  • Save aarroyoc/12e24a1f0dd65e4cd65d to your computer and use it in GitHub Desktop.
Save aarroyoc/12e24a1f0dd65e4cd65d to your computer and use it in GitHub Desktop.
execute.rs
fn execute(&mut self, execbyte: u8) -> () {
if self.push {
self.push(execbyte);
self.push=false;
}else{
let op: Option<Instruction> = FromPrimitive::from_u8(execbyte);
match op{
None => {
println!("Unknown instruction, skipping...");
},
Some(bc) => {
match bc{
INTEGER => {
self.push=true;
},
ADD => {
let a=self.pop() as int;
let b=self.pop() as int;
let c=a+b;
self.push(c as u8);
},
SHOWINTEGER => {
println!("Integer value {}",self.pop() as int);
},
SHOWVERSION => {
println!("PerinVM v0.1.0");
},
EXITVM => {
println!("Exit VM");
},
STRING => {
println!("Unsupported instruction 'STRING' ");
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment