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. (Currently working on a compiler from FALSE to Esimpl, so stuff not relevant to that is unlikely to end up on this page.)

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]

Common Stack Operations

These operations will be named the same as they are on the Stack page. These will all only require one semideque X for temporary storage, with the restriction that it must be empty when these are called. (This will only show the simplest possible non-trivial stack, where each stack element corresponds to one semideque element, and the stack will only ever contain 0 and 1. These can be modified to support more complex stacks (e.g. ones that contain integers using the above convention). These may also cause undefined behavior if an element is pushed/pushbacked and immediately popped, but they can be easily modified to prevent these situations.)

DUP

Usage: a pop-goto dup

# dup
a table
X push 0
X pushback 0
X pop-goto repush-1
X push 1
X pushback 1
X pop-goto repush-1
# repush-1
X table
a push 0
X pop-goto repush-2
a push 1
X pop-goto repush-2
# repush-2
X table
a push 0
[next]
a push 1
[next]

SWAP

Usage: a pop-goto swap

# swap
a table
X pushback 0
a pop-goto swap-2
X pushback 1
a pop-goto swap-2
# swap-2
a table
X pushback 0
X pop-goto repush-1
X pushback 1
X pop-goto repush-1
# repush-1
X table
a push 0
X pop-goto repush-2
a push 1
X pop-goto repush-2
# repush-2
X table
a push 0
[next]
a push 1
[next]

OVER

Usage: a pop-goto over

# over
a table
X pushback 0
a pop-goto over-2
X pushback 1
a pop-goto over-2
# over-2
a table
X push 0
X pushback 0
X pop-goto repush-1
X push 1
X pushback 1
X pop-goto repush-1
# repush-1
X table
a push 0
X pop-goto repush-2
a push 1
X pop-goto repush-2
# repush-2
X table
a push 0
X pop-goto repush-3
a push 1
X pop-goto repush-3
# repush-3
X table
a push 0
[next]
a push 1
[next]

ROT

Usage: a pop-goto rot

# rot
a table
X push 0
a pop-goto rot-2
X push 1
a pop-goto rot-2
# rot-2
a table
X push 0
a pop-goto rot-3
X push 1
a pop-goto rot-3
# rot-3
a table
X pushback 0
X pop-goto spin
X pushback 1
X pop-goto spin
# spin
X table
X pushback 0
X pop-goto repush-1
X pushback 1
X pop-goto repush-1
# repush-1
X table
a push 0
X pop-goto repush-2
a push 1
X pop-goto repush-2
# repush-2
X table
a push 0
X pop-goto repush-3
a push 1
X pop-goto repush-3
# repush-3
X table
a push 0
[next]
a push 1
[next]

ROTCC

Usage: a pop-goto rotcc

# rotcc
a table
X push 0
a pop-goto rotcc-2
X push 1
a pop-goto rotcc-2
# rotcc-2
a table
X push 0
a pop-goto rotcc-3
X push 1
a pop-goto rotcc-3
# rotcc-3
a table
X pushback 0
X pop-goto repush-1
X pushback 1
X pop-goto repush-1
# repush-1
X table
a push 0
X pop-goto repush-2
a push 1
X pop-goto repush-2
# repush-2
X table
a push 0
X pop-goto repush-3
a push 1
X pop-goto repush-3
# repush-3
X table
a push 0
[next]
a push 1
[next]