pub fn eval(&mut self, s: String) { let mut st = &mut vec![]; let mut b = &mut 0; let mut a = &mut self.a; let mut p = &mut self.p; let mut ip = &mut self.ip; let by = s.as_bytes(); while *ip < by.len() { let c = by[*ip]; match c as char { ']' => { if a[*p] != 0 { *ip = st.pop().unwrap(); } *b = *ip; } '[' => { if a[*p] == 0 { *ip = *b; } st.push(*ip); } '+' => a[*p] += 1, '-' => a[*p] -= 1, '>' => *p += 1, '<' => *p -= 1, '.' => self.b.push(a[*p]), ',' => {}, _ => unreachable!(), }; *ip += 1; } }
Enter