fix instruction pushing not being FIFO

This commit is contained in:
Crispy 2023-12-14 13:17:01 +01:00
parent 142cb9cc09
commit de9af67e50

View file

@ -157,18 +157,17 @@ impl SandWormInterpreter {
match instruction { match instruction {
b'0'..=b'9' => { b'0'..=b'9' => {
self.worm_in.push(instruction - 48); self.worm_in.push(instruction - 48);
dont_push_instruction = true;
} }
b'+' => { b'+' => {
let a = self.shrink(); let a = self.shrink();
self.worm_out.push(instruction); self.worm_out.insert(0, instruction);
let b = self.shrink(); let b = self.shrink();
dont_push_instruction = true; dont_push_instruction = true;
self.worm_in.push(a.wrapping_add(b)); self.worm_in.push(a.wrapping_add(b));
} }
b'-' => { b'-' => {
let a = self.shrink(); let a = self.shrink();
self.worm_out.push(instruction); self.worm_out.insert(0, instruction);
dont_push_instruction = true; dont_push_instruction = true;
let b = self.shrink(); let b = self.shrink();
self.worm_in.push(a.wrapping_sub(b)); self.worm_in.push(a.wrapping_sub(b));
@ -219,14 +218,14 @@ impl SandWormInterpreter {
} }
} }
} }
b' ' | 0 => (), b' ' | 0 => dont_push_instruction = true,
other => { other => {
self.worm_in.push(other); self.worm_in.push(other);
dont_push_instruction = true; dont_push_instruction = true;
} }
} }
if !dont_push_instruction { if !dont_push_instruction {
self.worm_out.push(instruction); self.worm_out.insert(0, instruction);
} }
self.move_to(front); self.move_to(front);
} }