DStack
Two stacks and a register, programmed in the six letters of its own name, read two at a time with every pair overlapping the next.
-Dark-Phantom-, 2015 · Turing complete: yes · ●●● hard · esolangs.org
Tested with 5 known programs · Hello World on Try It Online: identical · Test method
Run it
The idea
-Dark-Phantom- made DStack in November 2015. The only letters allowed are d s t a c k, in either case, plus the digits. The cursor reads the pair of characters under it, runs it, and then moves on by one character, not two. So 0kckt is the four instructions 0k, kc, ck and kt, and every character usually belongs to two of them.
Read the story
Writing DStack means choosing letters so that the pairs in between are harmless. A digit followed by a letter does nothing, and a capital second letter swaps the roles of the two stacks, which gives some room to manoeuvre.
Text lives outside the code, in numbered string literals between @ lines. Printing commands take the number of the string from the register.
The machine
Two stacks, each starting with a 0, and a register. Most pairs compute from the tops of the stacks into the register.
| Pair | Does |
|---|---|
x0 | Register = register × 10 + digit |
ds dS dt da dc dk | Add, multiply, subtract, power, divide, remainder |
st sc sk sa | Equal, greater, at least, between |
td ts tS ta | Not, or, and, xor |
tc tk tK sd | Peek, min, max, zero |
dd ss tt cc kk | Push the register |
cd cs ca | Move a top to the other stack, pop, swap the tops |
ck cK | Print the register as a character, as a number |
kc kC | Read a character, a number |
ks kt | Push the cursor's next position; jump there if the register is not 0 |
ka kA | Restart, or halt, if the register is not 0 |
ad as at ac ak | Print string register, with # and $ filled in, or push it |
The program ends when the cursor reaches its last character.
Example
The truth machine reads as 04, 4K, KK, KC, CK, KT.
The truth machine reads as 04, 4K, KK, KC, CK, KT. 04 puts 4 in the register and KK pushes it on the second stack. KC reads a number, CK prints it, and KT jumps back to position 4, the CK, as long as the number is not 0. The other two are the factorial and Collatz sequence.
Patterns it teaches
- Stack machines: two stacks, with a register between them.
- Encoding tricks: overlapping pairs make every letter do double duty.
- Quine: the specification has one, which prints its code from a string literal holding the same code.
- Turing completeness: every brainfuck command has a DStack translation.
See also
Stack-based
Write your own in Run Convert a program from DStack
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: dstack.
Command line
shib run dstack -e '0kckt' --input 'ab'shib manual dstackSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/dstack.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org