Smilefuck
Two stacks of bits and a single bit to hold in your hand. Everything else has to be shuffled.
Sacchan, 2014 · Turing complete: unknown · ●●○ moderate · esolangs.org
Tested with 6 known programs · Test method
Run it
The idea
Sacchan made Smilefuck on 6 June 2014, after brainfuck. There is no tape and there are no bytes. The memory is two stacks of bits, l and r, and one working bit w. The input starts on l and the output is whatever is left on r when the program ends.
Read the story
With only four instructions, even moving a bit is work. ^_v_ takes the top of l and puts it on r. A loop of that reverses the input, and the specification builds a whole binary increment out of such moves.
The machine
| Char | Does |
|---|---|
! | Invert w |
_ | Swap the two stacks |
^ | Pop the top of l into w |
v | Push w onto l |
( ... ) | Repeat while l is not empty |
[ ... ] | Repeat while w is 1 |
Input and output are the characters 0 and 1. The last bit of the input is on top of l, and r is read from the bottom up. The two kinds of loop may nest but not cross.
Example
The reverse moves the bits one at a time, so the last one lands at the bottom of r.
The reverse moves the bits one at a time, so the last one lands at the bottom of r.
Bitwise invert. The first loop moves the bits over inverted, which reverses them, so it swaps back and reverses again.
The increment adds a 0 in front, flips the trailing 1s and the first 0, and drops the leading 0 again when it was not needed. Eleven becomes twelve, and seven becomes eight.
Patterns it teaches
- Turing tarpit: Sacchan believes it is Turing complete, because it can model Bitwise Cyclic Tag, but there is no proof yet.
- Stack machines: two stacks of bits and nothing else.
Further
See also
Also in Turing tarpits
Write your own in Run Convert a program from Smilefuck
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: smilefuck.
Command line
shib run smilefuck -e '_' --input '0010111'shib manual smilefuckSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/smilefuck.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org