From 49895f1b1185bf399ba023768220cba0aa4b3750 Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Sat, 16 Dec 2023 14:02:11 +0100 Subject: [PATCH] define non-instruction bytes to just get eaten (for easier text printing), and add a special case for _ -> space --- README.md | 9 +++++---- src/main.rs | 6 ++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 0820bd0..286bb54 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ # Stupid Worm Languag -- program space is an arbitrary sized grid -- the worm starts where you place the worm head @ +- program space is an arbitrary sized grid of bytes +- the worm starts as just a 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) ++- pop 2 values, push sum/difference (uses the order they are popped, so `0-` negates the top of the stack) ><^v change direction 0..9 push number to stack /\ pop stack, reflect to the side if not zero @@ -15,5 +15,6 @@ = duplicate top of stack ! pop and write output as ascii char " pop and write output as number +_ push a space character +all other characters are pushed as-is ``` -* pop when stack is empty yields zero diff --git a/src/main.rs b/src/main.rs index bcf870b..259d4fc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -225,10 +225,8 @@ impl SandWormInterpreter { } } b' ' | 0 => dont_push_instruction = true, - other => { - self.worm_in.push(other); - dont_push_instruction = true; - } + b'_' => self.worm_in.push(b' '), + other => self.worm_in.push(other), } if !dont_push_instruction { self.worm_out.insert(0, instruction);