Threead
Three threads, one instruction pointer. Every column of the program runs three commands at once.
Turing complete: yes · ●●● hard
Tested with 5 known programs · Hello World on Try It Online: identical · Test method
Run it
The idea
Threead, by TehFlaminTaco on GitHub, is an assembly-like language read in groups of three lines. The first line of each group belongs to thread 1, the second to thread 2, the third to thread 3. One instruction pointer moves along all three, so each step runs the three characters stacked in one column.
Read the story
Each thread has its own tape and may only write its own cell, its buffer. Most commands read the neighbouring threads: + puts left plus right into the thread's own buffer. Reads see the cells as they were before the step, so the three commands in a column never get in each other's way.
The machine
| Code | Does |
|---|---|
0…9 | Buffer times 10 plus the digit |
"text" | Store a string |
+ - * / ^ | Left op right into the buffer; + joins strings, * repeats one |
= | 1 if left equals right |
l r _ | Copy the left or right buffer, set 0 |
s n c b | To string, to number, number to character, character to number |
H T | The first or last R characters of L |
> < i d | Move along the tape, insert a cell, delete one |
o R I B | Print the buffer, read a line, a number, a byte |
[ ] | Loop while this thread's buffer is not 0, moving all three threads |
@ | Stop |
Thread 1's left neighbour is thread 3, and its right is thread 2. Spaces do nothing. Two loop brackets in one column are an error. Numbers print as LuaJIT prints them, so 7 / 2 is 3.5. The reference is main.lua and functions.lua in github.com/TehFlaminTaco/Threead.
Example
In the second, thread 1 builds 12 and thread 3 builds 30 while thread 2 waits with spaces; then it adds…
In the second, thread 1 builds 12 and thread 3 builds 30 while thread 2 waits with spaces; then it adds its two neighbours and prints. The third counts down on thread 2. Thread 1 copies the count each round, thread 3 holds 1, and - puts the copy minus 1 back into thread 2's buffer.
Patterns it teaches
- Two-dimensional control flow: code in rows and columns, where the column is the time.
Further
- The reference interpreter, in Lua
See also
Also in Spatial (2D and up)
Write your own in Run Convert a program from Threead
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: threead.
Command line
shib run threead -e '7
/o
2'shib manual threeadSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/threead.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language