esolang

cpy

Three arrows. One moves a byte, one copies it and one jumps; writing to cell 0 prints and moving out of cell 1 reads.

ZippyMagician, 2021 · Turing complete: yes · ●●○ moderate · esolangs.org

Tested with 3 known programs · Test method

Run it

Expected: I

The idea

ZippyMagician made cpy in 2021; the name comes from memcpy. Every instruction is two cell numbers with an operator between them, one instruction a line. A move cannot just move. It adds 1 or takes 1 away on the way, depending on which address is the larger. The specification proves cpy Turing complete by translating Minsky machines into it.

The machine

InstructionDoes
X -> YMove cell X into cell Y, adding 1 if X is at most Y and taking 1 away if X is larger
X <-> YCopy cell X into cell Y
X <- YJump to line X if cell Y is above 0

Cells hold bytes. Writing to cell 0 prints the byte. Cell 1 holds the next byte of input, and a move out of it brings in the byte after, or 0 at the end. Lines count from 0, and the run ends past the last line.

Example

1->3 moves the input byte up two cells, so it gains 1 on the way.

1->3 moves the input byte up two cells, so it gains 1 on the way. H comes out as I.

The cat moves each byte to a higher cell and then to a lower one, so it gains 1 and loses it again. It prints the byte and loops while it was not 0. At the end of the input it prints that 0 byte too. The cat below checks the byte before it prints. Cell 6 is set to 1 on the first line and serves for the jumps that always happen.

Expected: cat

Patterns it teaches

  • Turing tarpit: three instructions, and a move that always changes what it moves.
  • Counter machines: the proof turns a Minsky increment into one line of cpy and a decrement or jump into four.

Further

Cell-based

Write your own in Run Convert a program from cpy

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run cpy -e '1->3
3->2
2<->0
0<-2' --input 'cat'
shib manual cpy

Source

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

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

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