Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pub fn vm_exec(p: &mut Process, isns: u64) -> Result<u64, (u64, &str)> {
- // FIXME Ugly nested matches can be made into a more functional thing.
- let mut execed = 0;
- while execed < isns {
- let top = p.call_stack.top();
- match top {
- Some(frame) => {
- let ti = frame.get_target_isn();
- match ti {
- Some(i) => {
- let ii = i.clone();
- match ii.execute(p) {
- Ok(segue) => {
- execed += 1;
- match segue {
- IsnSegue::Next => {
- let mut sf = p.call_stack.pop().unwrap();
- sf.next_isn += 1;
- p.call_stack.push(sf);
- },
- IsnSegue::RelJump(diff) => {
- let mut sf = p.call_stack.pop().unwrap();
- sf.next_isn += diff as u64;
- p.call_stack.push(sf)
- },
- IsnSegue::Return => {
- p.call_stack.pop();
- },
- IsnSegue::Detach => {
- let mut sf = p.call_stack.pop().unwrap();
- sf.next_isn += 1;
- p.call_stack.push(sf);
- return Ok(execed + 1);
- }
- }
- },
- Err(r) => return Err((execed + 1, r))
- }
- },
- None => {} // Don't push it back onto the stack and don't increment execed.
- }
- },
- None => return Err((execed, "process exited"))
- }
- }
- return Ok(execed);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement