esolang

Jungle

A tree of small machines. Each node has its own accumulator and stack, and only one runs at a time.

Madk, 2019 · Turing complete: with unbounded memory · ●●○ moderate · esolangs.org

Tested with 4 known programs · Test method

Run it

Expected: Hello world!

The idea

Madk made Jungle in May 2019. A program is a binary tree of nodes. The top level is the root, and left ( ... ) and right ( ... ) inside a node give it its two children. Every node is a small machine of its own, with a program counter, an accumulator, a stack of 256 numbers, and carry, overflow, divz, wrapped and error.

Read the story

Nodes read and change each other's accumulators and stacks, and hand control around the tree. The only jump inside a node is again, back to its first statement. Every other loop and branch is a trip to another node and back.

The machine

InstructionsDo
goto transferStart a node at its first statement; transfer also sets its accumulator
return return_withGo back to the node that came here, just after its goto
again exitRestart this node; end the program
push pop peek swap discardWork a node's stack
assign inc dec add sub mul div mod remArithmetic on the accumulator
shl shr sar and or xor not negate absBits
write_char write_int read_char read_intInput and output

A statement ends with ;, and its arguments come in any order. A node argument names a relative such as parent, sibling, leftmost or next in order; a condition such as if_zero or if_carry makes the jump optional. Values are 32-bit and wrap, setting carry, overflow, divz and wrapped on the way. The program ends at exit, or when the running node runs past its last statement.

Example

The cat stops after the line feed, where xor "\n" leaves 0.
Expected: Jungle

The cat stops after the line feed, where xor "\n" leaves 0. At the end of the input read_char gives 0, and the loop would go on writing it, so the input needs its line feed.

The Fibonacci keeps a counter in the left child and the last two numbers on the right child's stack. The left child counts down from 20 and calls its sibling 19 times; then it returns to the root, which writes the line feed and runs out of statements.

Expected: First 20 numbers of the Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181

Further

Also in Turing tarpits

Write your own in Run Convert a program from Jungle

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run jungle -e 'write_char "Hello world!";'
shib manual jungle

Source

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

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

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