DominoScript
A program is a table of dominoes. The dots are the code, and the way the pieces lie is the control flow.
Galvandi, 2024 · Turing complete: yes · ●●● hard · esolangs.org
Tested with 5 known programs · Test method
Run it
The idea
Galvandi made DominoScript in 2024. A program is a grid of domino halves with 0 to 6 dots, written as digits, with — or | joining the two halves of a piece. The instruction pointer always crosses from one half of a domino to the other, then looks for the next domino ahead of it, to its left or to its right. Where it finds none, a call returns, or the program ends.
Read the story
Every domino is a two digit number in base 7, and that number is the opcode. 5—1 is 36, which prints a number, but the same piece entered from the other side reads 1—5, which is 12 and negates. Numbers and strings are dominoes too. After NUM the first half of the next domino says how many more dominoes belong to the number, so 12 is 1—0 1—5, the digits 0, 1 and 5.
The machine
| Opcodes | Instructions |
|---|---|
| 0 to 6 | POP NUM STR DUPE ROLL LEN CLR |
| 7 to 13 | ADD SUB MULT DIV MOD NEG CLAMP |
| 14 to 19 | NOT AND OR EQL GTR EQLSTR |
| 21 to 27 | BNOT BAND BOR BXOR LSL LSR ASR |
| 28 to 34 | NAVM BRANCH LABEL JUMP CALL IMPORT WAIT |
| 35 to 40 | NUMIN NUMOUT STRIN STROUT KEY KEYRES |
| 42 to 48 | GET SET LIT BASE EXT TIME NOOP |
Opcodes 20 and 41 are not used. BRANCH turns left when the value it pops is not 0 and right when it is. CALL goes to a cell address and comes back once the pointer has nowhere left to go. NAVM changes the order in which the pointer tries forward, left and right, and BASE allows dominoes with up to 15 dots on a half. The stack holds 512 integers of 32 bits.
This implementation leaves out GET and SET, which read and write the grid, IMPORT, TIME and the random, cycling and flip flop navigation modes. KEY never finds a key pressed.
Example
The first is the version of 5 6 + dup * .
The first is the version of 5 6 + dup * . in Forth. The second is STR, the characters h, i and ! at two dominoes each, the 0—0 that ends the string, and STROUT.
The factorial puts 12 on the stack and calls the function at address 42, the 0—3 in the third row. Its BRANCH at 4—1 turns up into POP and NUM 1 when the number is 0, and down into a call of itself otherwise.
The specification also has a Hello world drawn over nine rows. Its first character is 1—2 0—6, which is 206 in base 7 or 104, a small h, so it prints hello world.
Patterns it teaches
- Two-dimensional control flow: the pointer turns where the dominoes turn, and a dead end returns from a call.
- Stack machines: one stack of integers, used the way Forth uses it.
- Encoding tricks: opcodes, numbers and characters are all base 7 numbers in dots.
Further
See also
Self-modifying
Stack-based
Write your own in Run Convert a program from DominoScript
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: dominoscript.
Command line
shib run dominoscript -e '0—1 0—5 0—1 0—6 1—0 0—3 1—2 5—1'shib manual dominoscriptSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/dominoscript.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org