esolang

Cthulhu

Deadfish torn into numbered functions. Each one keeps its own accumulator, and the only branch is a call by number.

2019 · Turing complete: yes · ●●○ moderate · esolangs.org

Tested with 4 known programs · Test method

Run it

Expected: 7

The idea

Cthulhu is heavily based on Deadfish i. A program is a list of functions, one per line, each named by a number and a letter from A to D. Every function has its own accumulator, and running a program means running 0A.

Read the story

There is no jump and no test. The one way to branch is ], which calls the function whose number is the accumulator. A call to a number that does not exist goes to the largest number below it with the same letter. So with only 0C and 1C defined, ]C picks 0C on 0 and 1C on anything above, and that is a test for zero. The specification builds a two register Minsky machine this way, which makes Cthulhu Turing complete.

The machine

CommandDoes
i dAdd 1 to this function's accumulator; take 1 away
oPrint the accumulator
*Read a number into the accumulator
[0ACall function 0A
]BCall the B function numbered by the accumulator
E1ACopy the accumulator into 1A's
e1ACopy 1A's accumulator into this one

A function returns to its caller after its last command, and the program halts when 0A returns. Accumulators start at 0 and keep their value between calls. The specification says E moves an accumulator; its Deadfish interpreter prints 289 only when the value stays behind, so E and e copy. Each number prints on its own line.

Example

The addition reads a and b.

The addition reads a and b. Function 1A counts a down, and while it is not 0 the call ]B lands on 1B, which adds 1 to b. At 0 it lands on 0B, which prints b.

The Deadfish interpreter takes its commands as numbers, 2 for i, 3 for d, 4 for s, 5 for o and 1 to end. Function 0A reads one and calls it with ]A. Squaring is a loop of loops over the B, C and D functions, and 264A and 7A bring 256 and -1 back to 0 as Deadfish does. The program is iissiso.

Expected: 289

Patterns it teaches

Further

Object-oriented paradigm

Write your own in Run Convert a program from Cthulhu

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run cthulhu -e '0A *iE1A*E1B[1A
1A d]B
1B i[1A
0B e1Bo' --input '3 4'
shib manual cthulhu

Source

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

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

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