User:PkmnQ/Esimpl stuff

From Esolang
Jump to navigation Jump to search

This is User:PkmnQ's page for Esimpl stuff that others may find useful.

Conventions

  • Semideques are given bolded names.
  • Comments directly above a table separator work as "labels" in place of stanza numbers.
    • These labels are italicized.
  • [next] marks a goto command that varies depending on where you want to jump afterward.

Integers

The convention I'll use to represent an integer n is the sign of n (0 = positive, 1 = negative), followed by |n| 0's and a terminating 1. This means both 1 0 and 1 1 are valid representations of 0.

Adding/subtracting one integer from another

Running b pop-goto add does addition and b pop-goto sub does subtraction. Requires a third semideque X for temporary storage.

# add
b table
a pop-goto b-pos
a pop-goto b-neg
# sub
b table
a pop-goto b-neg
a pop-goto b-pos
# b-pos
a table
X push 0
b pop-goto same
X push 1
b pop-goto diff-b
# b-neg
a table
X push 0
b pop-goto diff-b
X push 1
b pop-goto same
# same
b table
a push 0
b pop-goto same
X pop-goto push-sign
# diff-b
b table
a pop-goto diff-a
X pop-goto push-sign
# diff-a
a table
b pop-goto diff-b
X pop-goto flip-sign
# flip-sign
X table
X push 1
b pop-goto same
X push 0
b pop-goto same
# push-sign
X table
a push 0
[next]
a push 1
[next]