skip the loop if current is 0
This commit is contained in:
parent
b69f495a3d
commit
e34bb583a1
22
src/lib.rs
22
src/lib.rs
|
@ -131,6 +131,28 @@ pub fn eval_mem<'a>(bf_str: &&str, mem: &'a mut [u8], pointer: &mut usize) -> Re
|
|||
continue
|
||||
}
|
||||
if char == '[' {
|
||||
|
||||
// if current is 0
|
||||
if mem[*pointer] == 0 {
|
||||
// skip the loop completely
|
||||
let mut p = pos.clone();
|
||||
loop {
|
||||
if p == progsize {
|
||||
return Err(
|
||||
BrainFuckError::new(format!("Unmatched '[' ({})", pos), mem)
|
||||
);
|
||||
}
|
||||
|
||||
if chars[p] == ']' {
|
||||
pos = p + 1;
|
||||
break;
|
||||
}
|
||||
|
||||
p += 1;
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
loop_stack.push(pos);
|
||||
continue
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue