mirror of
https://github.com/azur1s/bobbylisp.git
synced 2024-09-28 09:27:35 +00:00
refactor: fold brackets
This commit is contained in:
parent
93f8f57db8
commit
bb86934b53
|
@ -39,14 +39,10 @@ impl VM {
|
||||||
pub fn run(&mut self, instrs: Vec<Instr>, debug: bool) -> VMReturn {
|
pub fn run(&mut self, instrs: Vec<Instr>, debug: bool) -> VMReturn {
|
||||||
'tco: loop {
|
'tco: loop {
|
||||||
self.instr_pointer += 1;
|
self.instr_pointer += 1;
|
||||||
if self.instr_pointer - 1 == instrs.len() as isize {
|
if self.instr_pointer - 1 == instrs.len() as isize { return Ok(()); }
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
let instr = &instrs[self.instr_pointer as usize - 1];
|
let instr = &instrs[self.instr_pointer as usize - 1];
|
||||||
if debug {
|
if debug { println!("ptr: {} | stack: {:?} | curr: {}", self.instr_pointer - 1, &self.stack, &instr); }
|
||||||
println!("ptr: {} | stack: {:?} | curr: {}", self.instr_pointer - 1, &self.stack, &instr);
|
|
||||||
}
|
|
||||||
match instr {
|
match instr {
|
||||||
Store { address, value, .. } => {
|
Store { address, value, .. } => {
|
||||||
self.store(&address, &value)?;
|
self.store(&address, &value)?;
|
||||||
|
@ -97,14 +93,10 @@ impl VM {
|
||||||
},
|
},
|
||||||
PopJumpIfFalse { to, .. } => {
|
PopJumpIfFalse { to, .. } => {
|
||||||
let value = self.stack.pop().unwrap();
|
let value = self.stack.pop().unwrap();
|
||||||
if !value.as_bool() {
|
if !value.as_bool() { self.instr_pointer = *to as isize - 1; }
|
||||||
self.instr_pointer = *to as isize - 1;
|
|
||||||
}
|
|
||||||
continue 'tco;
|
continue 'tco;
|
||||||
},
|
},
|
||||||
Return { .. } => {
|
Return { .. } => return Ok(()),
|
||||||
return Ok(());
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue