From 67b2d81a1304109de4b09e6683e95d4a0035a9ab Mon Sep 17 00:00:00 2001 From: "Maurits van Riezen (mousetail)" Date: Thu, 27 Jul 2023 09:28:54 +0200 Subject: [PATCH 1/2] fix the behavior of {, }, g, and % to better match the official version --- src/scripts/interpreter.ts | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/scripts/interpreter.ts b/src/scripts/interpreter.ts index 857400d..28b4253 100644 --- a/src/scripts/interpreter.ts +++ b/src/scripts/interpreter.ts @@ -124,7 +124,7 @@ const commands = { '*': wrap((a, b) => a * b), '-': wrap((a, b) => b - a), ',': wrap((a, b) => b / a), - '%': wrap((a, b) => b % a), + '%': wrap((a, b) => ((b % a) + a) % a), '=': (o: ProgramState) => { push(o, Number(pop(o) == pop(o))) }, @@ -158,12 +158,16 @@ const commands = { push(o, x); push(o, z); push(o, y); }, '{': (o: ProgramState) => { - let a = o.stacks[o.stacks.length - 1].contents.shift(); - push(o, a as number); + if (o.stacks[o.stacks.length -1].contents.length > 0) { + let a = o.stacks[o.stacks.length - 1].contents.shift(); + push(o, a as number); + } }, '}': (o: ProgramState) => { - let a = o.stacks[o.stacks.length - 1].contents.pop(); - o.stacks[o.stacks.length - 1].contents.unshift(a as number); + if (o.stacks[o.stacks.length -1].contents.length > 0) { + let a = o.stacks[o.stacks.length - 1].contents.pop(); + o.stacks[o.stacks.length - 1].contents.unshift(a as number); + } }, 'r': (o: ProgramState) => { o.stacks[o.stacks.length - 1].contents.reverse(); @@ -221,6 +225,13 @@ const commands = { }, 'g': (o: ProgramState) => { let [y, x] = [pop(o), pop(o)]; + if (x < 0) { + x = 0; + } + if (y < 0) { + y = 0; + } + if (y < o.program.length && x < o.program[y].length) { push( o, From 9b562ad13237eff8744fd6fce44c039b2832d3d3 Mon Sep 17 00:00:00 2001 From: "Maurits van Riezen (mousetail)" Date: Thu, 27 Jul 2023 09:30:21 +0200 Subject: [PATCH 2/2] fix typo --- src/index.html | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/index.html b/src/index.html index 72822df..77c0d15 100644 --- a/src/index.html +++ b/src/index.html @@ -151,7 +151,7 @@

Literals

0123456789 Push the number (0-9)

-

abcdef Push the hexadecimal (10-15)

+

abcdef Push the number in hexadecimal (10-15)

@@ -165,10 +165,7 @@

Literals

)( Greater than, less than. Push 1 or 0 to the stack.

'" Enable or disable string parsing mode. In string parsing mode - all characters are - pushed - to the stack instead of executed.

- + all characters are pushed to the stack instead of executed.

Stack

@@ -178,7 +175,7 @@

Stack

~ Delete the top element of the stack

-

@ Move the top elemnt of the stack back 2

+

@ Move the top element of the stack back 2