esolang

Emanator

One subtraction, and no registers at all. Input and output are where an address points back at itself.

Hakerh400, 2023 · Turing complete: yes · ●●● hard · esolangs.org

Tested with 3 known programs · Test method

Run it

Expected: meow

The idea

Hakerh400 made Emanator in 2023. The whole state of a run is one tape of whole numbers. The program is written into cells 0, 1, 2 and on, and every other cell is 0. Cell 0 is the instruction pointer. There is no data pointer and no I/O command.

Read the story

An address below 0 is indirect. Address i stands for the address held in cell -i-1, followed again if that is below 0. When such a chain comes back to an address it has already passed, it reaches the outside world. Reading there takes the next input character, and writing there prints one.

The specification counts it Turing complete, as any mov program translates into it more or less directly.

The machine

Every step does the same thing.

StepDoes
ipRead cell 0
destRead cell ip
op1Read the cell named by cell ip+1
op2Read the cell named by cell ip+2
jumpWrite ip+3 to cell 0
writeWrite op1 minus op2 to dest

The run ends when it prints 0. The end of the input reads as 0, so a cat ends by itself.

Example

A cat program.

A cat program. Cell 3 holds -4, which names cell 3 again, so writing there prints. Cell 4 holds -5 in the same way, so reading there takes input. The second instruction sets cell 0 back to 3.

A program that prints Hi. Each instruction names itself as its destination, and the last one prints cell 0 minus cell 0, which stops the run.

Expected: Hi

The second program prints the Kolakoski sequence as the digits 1 and 2 and never stops. It keeps a queue in the cells past its 26 numbers, and two of its own numbers are the front and the back of that queue. In this implementation it gives 1221121221221121122121121221121121221221 and on, and its first 33,333 digits match the sequence.

1.27.26.22.1.1.27.-2.26.22.1.1.24.-14.25.-7.6.6.24.26.24.26.0.4.-1.49

Patterns it teaches

Further

Also in Turing tarpits

Write your own in Run Convert a program from Emanator

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run emanator -e '3.0.3.-4.-5.1.0.2.1' --input 'Emanator'
shib manual emanator

Source

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

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

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