Neucomp
A computer in the style of von Neumann. Numbered cells, an ALU, an If and a goto by line.
2023 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 5 known programs · Test method
Run it
The idea
Neucomp is short for a Neumann styled computer. A program is a list of lines, one instruction each, that work on memory cells numbered 0, 1, 2 and up. Most numbers in an instruction are cell numbers. Let 1 72 puts 72 in cell 1, but ALU 1 2 + 3 adds the contents of cells 1 and 2 and puts the sum in cell 3, and If 10 = 0 compares cell 10 with cell 0. So constants such as 0, 1 and 10 have to live in cells of their own first.
Read the story
Val reads through a cell. In Val 2 reads into the cell whose number is in cell 2, which is how the cat stores a whole line one character after another. Jumps go to a line number, counted without blank lines and comments.
The machine
| Instruction | Does |
|---|---|
Let a b | Set cell a to the number b |
ALU a b op d | Set cell d to cell a op cell b |
In a | Read one character into cell a |
Out a | Print cell a as a number |
Prt a | Print cell a as a character |
If a op b ... End | Run the lines up to End only if cell a op cell b holds |
Go a | Go to line a |
Halt | Stop |
Val a | In place of a number, the value in cell a |
# | A comment to the end of the line |
The specification shows + and - for the ALU and = and > for If. This implementation also takes *, / and %, and !=, <, <= and >=. With cells that hold any whole number, If and Go are enough to run a counter machine.
Example
Add 2 and 2.
Add 2 and 2.
The cat reads characters into cells 3, 4, 5 and on until it meets a line feed, then goes back and prints them.
The truth machine. On 1 it jumps back into its own If at line 8 and prints 1 forever.
Patterns it teaches
- Counter machines: cells that count up and down, a test and a goto.
Further
See also
Also in Turing tarpits
Write your own in Run Convert a program from Neucomp
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: neucomp.
Command line
shib run neucomp -e 'Let 1 2
Let 2 2
ALU 1 2 + 3
Out 3'shib manual neucompSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/neucomp.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org