diff --git a/README.md b/README.md index 5a14dec..0820bd0 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,16 @@ -# sandworm -program space is an arbitrary sized grid -the worm starts where you place the worm head @ -as it passes over commands, they get moved to the back of the worm (also depending on the worm length) -commands to change direction <>^v -values get pushed to stack (eaten) when passed over, worm body length increases -autosarkophagy/self-cannibalism is possible, cutting off the back of the worm (the lower part of the stack) and pushing the passed value to the stack (front of worm) -conditional: pop then side/forward if top of stack is zero +# Stupid Worm Languag +- program space is an arbitrary sized grid +- the worm starts where you place the worm head @ +- as it passes over commands, they get moved to the back of the worm +- values get pushed to stack (eaten) when passed over, worm body length increases +- the program gets rearranged every time the worm executes it ## commands ``` +- pop 2 values *, push sum/difference (uses the order they are popped, so `0 -` negates the top of the stack) ><^v change direction -0123456789ABCDEF push number to stack -/\ pop stack, reflect to the side if zero +0..9 push number to stack +/\ pop stack, reflect to the side if not zero ? reads one byte of input = duplicate top of stack ! pop and write output as ascii char diff --git a/src/main.rs b/src/main.rs index ae86212..41b3570 100644 --- a/src/main.rs +++ b/src/main.rs @@ -159,20 +159,19 @@ impl SandWormInterpreter { self.worm_in.push(instruction - 48); dont_push_instruction = true; } - // b'0'..=b'9' => self.grow(instruction - 48), b'+' => { let a = self.shrink(); self.worm_out.push(instruction); let b = self.shrink(); dont_push_instruction = true; - self.worm_in.push(a + b); + self.worm_in.push(a.wrapping_add(b)); } b'-' => { let a = self.shrink(); self.worm_out.push(instruction); dont_push_instruction = true; let b = self.shrink(); - self.worm_in.push(a + b); + self.worm_in.push(a.wrapping_sub(b)); } b'v' => self.direction = Direction::Down, b'^' => self.direction = Direction::Up,