Filth
A byte stack machine that gives you NOR and nothing else for logic, plus a second stack that holds commands.
Brandon Zimmerman, 2010 · Turing complete: unknown · ●●● hard · esolangs.org
Tested with 2 known programs · Test method
Run it
The idea
Brandon Zimmerman (Dev squid on the wiki) designed Filth in 2010. The name is a recursive acronym: "Filth is a Lame Turing Hack". The specification says it hates you, and it means the logic. There is no add, no and, no or. There is only NOR, so every calculation must be built out of it.
Read the story
The odd part is the command stack. /C pushes the command C onto it without running it. \D pops the top D commands and runs them. -C applies a stack operation such as dup or swap to the command stack. So stored commands can be copied and reordered like data, while the program itself stays a read-only line of code.
Jumps use labels: *lp marks a place and ^lp pops a byte and jumps there if it is not zero.
The machine
A data stack of bytes, a command stack, labels and a read-only program.
| Command | Does |
|---|---|
XX | Push the byte with hex value XX |
+ $ @ | Dup, drop, rot |
:D | Swap the top two groups of D bytes |
;D | Pop a flag; if true, :D |
~ | NOR of the top two bytes |
! | Push 1 if the top two are equal, else 0 |
? | Push 1 if the second is less than the top, else 0 |
/C \D -C | Push a command; run the top D commands; apply C to the command stack |
*AAA ^AAA | Define a label; pop and jump to it if not 0 |
. , | Print a byte; read a byte |
# q | Stop; print q# |
\|…\| | Comment |
The specification does not say what happens on an empty stack or at the end of input. In this implementation both give 0, and \D runs the popped commands oldest first.
Example
The bytes of Hello, world! are pushed backwards, so H ends up on top and a zero sits at the bottom.
The bytes of Hello, world! are pushed backwards, so H ends up on top and a zero sits at the bottom. The loop prints the top, duplicates the next byte and jumps back while that byte is not zero. This is a small reordering of the Hello World. The version duplicates before printing, so it also prints the final zero byte.
Patterns it teaches
- Stack machines: two of them, one for bytes and one for commands.
- Hostile design: only NOR, to make arithmetic a chore.
- Code as data: commands on the command stack can be duplicated and swapped.
- Quine:
qprintsq#, soq#is a built-in quine.
Try this
- Use the
00!FE~to turn any byte into 0 or 1, and print the result plus 30 (the digit). - Push two commands with
/, swap them with-:1, and run them with\2. - Hard: build AND from NOR and test it on all four pairs of 0 and 1.
Further
See also
Stack-based
Write your own in Run Convert a program from Filth
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: filth.
Command line
shib run filth -e 'q#'shib manual filthSource
- Module
langs/stack/ports.js- Interpreter
langs/stack/filth.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org