Virage
A program is a drawing of a graph. Each vertex does what the angles of its edges say.
TuxCrafting, 2019 · Turing complete: yes · ●●● hard · esolangs.org
Tested with 3 known programs · Test method
Run it
The idea
TuxCrafting made Virage in 2019. Virage is French for turn. The source is a picture of vertices and the edges between them, drawn with *, |, -, / and \. There are no command letters. What a vertex does depends on the edges that leave it, seen from the edge the run came in by. A vertex that turns right pushes a 1, one that turns left pushes a 0, and a fork to the left and the right is an if.
Read the story
The memory is two stacks of bits. Input and output go 8 bits at a time, the lowest bit on top. The specification shows Virage is Turing complete by drawing a building block for each command of F2, which are + > < [ ], and stacking the blocks.
The machine
The text is cut into blocks of 3 by 3 characters. A block with * in its middle is a vertex, and each of its eight border characters that is not a space is half of an edge toward that neighbour. Every half needs its partner, except one edge that leaves the drawing. The run starts there.
| Edges besides the way in | Does |
|---|---|
| none | Halt |
| straight | Go on |
| right, left | Push 1 or 0 and turn that way |
| bottom-right, bottom-left | Drop or duplicate the top bit, and turn that way |
| top-right, top-left | Move a bit to or from the second stack, and turn that way |
| straight and right | Read a byte; at the end of the input turn right |
| straight and left | Pop 8 bits and print them as a byte |
| right and left | Pop a bit, turn right on 1 and left on 0 |
| bottom-right and top-left | Go bottom-right, or top-left if the main stack is empty |
| top-right and bottom-left | Go top-right, or bottom-left if the second stack is empty |
| straight, left and right | A crossing, go on |
| left and top-right | A join, go top-right |
| right and top-left | A join, go top-left |
Any other set of edges is an error, and so is popping an empty stack. This implementation runs as the Python interpreter on the specification does.
Example
The cat.
The cat. The run comes in at the | on the top line and goes round a loop. One vertex on it, with a straight and a right edge, reads a byte, and the next, with a straight and a left edge, prints it. At the end of the input the reader turns right into a vertex with no other edge, and the run halts.
The truth machine comes in at the - on the left. Its drawing starts with an empty line, which puts the vertices on the middle line of each row of blocks. It reads a byte, and an if pops the lowest bit. On 0 it turns up, puts a 0 back on the seven bits that are left and prints them, which is the 0 it read. On 1 it turns down into a loop that pushes the eight bits of a 1 and prints them, for ever.
Patterns it teaches
- Two-dimensional control flow: the turns are the instructions, so every command also steers.
- Stack machines: two stacks of bits are all the memory there is.
Further
See also
Two-dimensional languages
Stack-based
Write your own in Run Convert a program from Virage
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: virage.
Command line
shib run virage program.txt --input '0'The program is long; save it as program.txt first.
shib manual virageSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/virage.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org