# Emanator

Paradigm(s) Imperative User:Hakerh400 2023 Turing complete Implemented `.txt`

Emanator is an esolang invented by User:Hakerh400 in 2023.

## Overview

Source code consists of integers separated by dots.

Memory consist of a single tape, which can be represented as a function $f:\mathbb {N} \mapsto \mathbb {Z}$ . All cells are initially $0$ , except the cells at addresses $0,\dots ,n-1$ , which contain the source code, where $n$ is the length of the source code. Here, by source code we mean the list of integers parsed from the source code and not the literal source code string.

Memory contains the entire program state. There are no external registers such as instruction pointer or data pointer.

If we want to access cell at address $i$ , then there are two cases:

• If $i\geq 0$ , then we access cell $i$ directly.
• Otherwise, let $j$ be the value from cell $-i-1$ . The result of accessing $i$ is the result of accessing $j$ . If accesses form a loop, then we either read from input (if we want to read a value), or write to the output (if we want to write a value).

Perform the following algorithm until the program outputs number $0$ . Let `ip` be the value from cell $0$ . Let `dest` be the value from cell `ip` (keep in mind indirect addressing explained above). Let `op1` be the value from cell `ip + 1` and `op2` be the value from cell `ip + 2`. Write value `ip + 3` to cell $0$ and then write value `op1 - op2` to cell `dest`.

If anything in this explanation is unclear, see the implementation for details.

## Examples

### Cat program

```3.0.3.-4.-5.1.0.2.1
```

Explanation. The cell $0$ contains value $3$ . It represents the initial value of `ip` (instruction pointer).

Each "instruction" is 3 cells long. Our first instruction is `-4 -5 1`. In pseudocode it means `mem[-4] = mem[-5] - mem`. Of course, since memory contains only positive addresses, $-4$ and $-5$ represent indirect addressing, so we are effectively addressing $-(-4)-1=3$ and $-(-5)-1=4$ , respectively. However, since `mem = -4` and `mem = -5`, we have a cycle in both cases. We first evaluate operands, so `mem[-5]` resolves to the next character code from the input string. The second operand `mem` directly resolves to `0`. The result is `C - 0 = C`, where `C` is the next character code from the input (because the indirect addressing formed a cycle at `mem[-5]`). Finally, since `mem[-4]` also forms a cycle, we output the result `C` directly to the output stream.

Instruction pointer gets incremented by $3$ , so it becomes $6$ . The next "instruction" is `0 2 1`. It means `mem = mem - mem = 3 - 0 = 3`, so we write value $3$ to the instruction pointer, effectively jumping back to the first instruction. We perform these steps until we read integer $0$ (the end of input stream) and output it, which terminates the program.

## Computational class

This language is Turing-complete. We leave to the readers to figure out why.