diff --git a/src/index.html b/src/index.html
index 4018222..c0fedb6 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
diff --git a/src/scripts/interpreter.ts b/src/scripts/interpreter.ts
index 6a095ec..bc730f2 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,