Created
August 27, 2014 10:45
-
-
Save aarroyoc/12e24a1f0dd65e4cd65d to your computer and use it in GitHub Desktop.
execute.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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