Skip to content

Commit

Permalink
Merge branch 'main' of github.com:mousetail/Fish
Browse files Browse the repository at this point in the history
  • Loading branch information
mousetail committed Mar 13, 2024
2 parents 925880f + 1380977 commit fda2d52
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
9 changes: 3 additions & 6 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ <h3>Literals</h3>
<p><code data-symbol="0123456789">0123456789</code> Push the number (0-9)</p>
</div>
<div>
<p><code data-symbol="abcdef">abcdef</code> Push the hexadecimal (10-15)</p>
<p><code data-symbol="abcdef">abcdef</code> Push the number in hexadecimal (10-15)</p>
</div>
</div>

Expand All @@ -165,10 +165,7 @@ <h3>Literals</h3>
<p><code data-symbol=")(">)(</code> Greater than, less than. Push 1 or 0 to the stack.</p>

<p><code data-symbol="'&quot;">'" </code> Enable or disable string parsing mode. In string parsing mode
all characters are
pushed
to the stack instead of executed.</p>

all characters are pushed to the stack instead of executed.</p>
<h3>Stack</h3>

<div class="two-columns">
Expand All @@ -178,7 +175,7 @@ <h3>Stack</h3>
</div>
<div>
<p><code data-symbol="~">~</code> Delete the top element of the stack</p>
<p><code data-symbol="@">@</code> Move the top elemnt of the stack back 2</p>
<p><code data-symbol="@">@</code> Move the top element of the stack back 2</p>
</div>
</div>

Expand Down
21 changes: 16 additions & 5 deletions src/scripts/interpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
},
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit fda2d52

Please sign in to comment.