esolang

Spiral

The pointer rolls along tracks of code like a train, and at every cell it tries to turn.

Quintopia, 2003 · Turing complete: yes · ●●● hard · esolangs.org

Tested with 2 known programs · Test method

Run it

Expected: Hi

The idea

Quintopia devised Spiral in 2003, after Wierd and brainfuck. As in Wierd, the instruction pointer finds its own way. It moves only onto commands, so a program is drawn as tracks of characters on a blank field, and the pointer follows them. At every cell a right-turning pointer first tries to turn right, then to go straight on, then left, and only then back the way it came. So it keeps to the right at every junction, and a dead end sends it back.

Read the story

The memory is a deque and one register, called villanova. Every command works on the front of the deque. @ turns the deque over, so that the back becomes the front, and makes the pointer turn the other way.

The machine

CharDoes
0Start here
* #Add 1 to villanova; take 1 away
v ^Push villanova onto the deque; copy the front into villanova
XPop into villanova; a value other than 0 blocks the track
+ ~ $Add the front two; compare them; swap them
. ,Print the front as a character or as a number
: ;Read a character; read a line as a number
@Turn the deque over and switch the turning mode
=Nothing, a bridge where tracks cross
!Halt

Values are bytes. Any other character is a label. Labels come in pairs, and meeting one moves the pointer to its partner. A command runs when the pointer faces it, before it moves onto it.

The specification leaves some things open. Its Hello World only works if v leaves 0 in villanova, and its 99 bottles only if the pointer looks straight ahead after a jump before it turns. This implementation does both. The Rot13 example prints its first two characters and then goes wrong. It would need . to leave the printed byte in villanova, and the 99 bottles example needs the opposite.

Example

A straight track.

A straight track. Each ^v+ doubles the front of the deque and each ^*v+ doubles it and adds 1, the way the 99 bottles example builds its letters. 72 is H and 105 is i.

The Hello World draws its own letters. Each letter is a track of * that counts on from the letter before, up to its character code. A label in the corner jumps to the next letter, where an X pops the count back into villanova. Twelve . in the R print the characters at the end.

Expected: Hello World!

The 99 bottles of beer program prints every verse, with 1 bottle and No more. Its last verse says Go to the store and buy some more. and ends on 99 bottles again. It takes 473,761 steps of the pointer.

Further

Ideas it shows

Deque-based

Two-dimensional languages

Write your own in Run Convert a program from Spiral

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: spiral.

Command line

shib run spiral program.txt

The program is long; save it as program.txt first.

shib manual spiral

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/spiral.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org