esolang

OCOO

One Character One Operation. Two operators, and what + does depends on where ; left the pointer.

Trap-representation · Turing complete: unknown · ●●○ moderate · esolangs.org

Tested with 3 known programs · Test method

Run it

Expected: H

The idea

Trap-representation designed OCOO. Its specification reads like the C standard, with storage blocks, implementation defined results and undefined behavior. There are eleven blocks in a ring. ; moves the block pointer one block on, and + does whatever the block under the pointer stands for. On OPERAND1 it counts up, on SWAP it swaps the two operands, on JUMP it jumps.

Read the story

Even input and output are left to the implementation. The examples assume that IMPL1 at 2 and IMPL2 at 1 read a character, and both at 1 write one. So every letter of Hello, World! is a row of + that counts OPERAND1 up to its code, then nine ;, a +, a ; and a + to write it.

The machine

Block+ does
OPERAND1Add 1, or take 1 when SIGN is 1
OPERAND2The same for OPERAND2
SWAPSwap OPERAND1 and OPERAND2
SIGNFlip SIGN between 0 and 1
ZEROSet OPERAND1 to 0
JUMPIf OPERAND2 is not 0, jump OPERAND1 operations forward, or back when SIGN is 1; then OPERAND1 is 0
STOREPut OPERAND1 in tape cell OPERAND2
LOADRead tape cell OPERAND2 into OPERAND1
NULLNothing
IMPL1 IMPL2Add 1; at 2 and 1 read a character into OPERAND1, at 1 and 1 write OPERAND1, then both are 0

; moves the pointer from one block to the next, and from IMPL2 back to OPERAND1. Every other character is a comment, but a + or ; inside a comment still runs. The echo program has two in its comment text, and they happen to change nothing it prints. Blocks hold 0 to 65535 and wrap.

Example

The first line of the Hello, World! is 72 plusses for H.

The first line of the Hello, World! is 72 plusses for H. Then nine ; reach IMPL1.

The echo program without its comments. It reads a character, writes it, then counts OPERAND1 up to 10 for a line feed.

Expected: A

Patterns it teaches

  • Turing tarpit: two characters, and the meaning sits in a pointer.

Further

Also in Turing tarpits

Write your own in Run Convert a program from OCOO

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run ocoo program.txt --input 'A'

The program is long; save it as program.txt first.

shib manual ocoo

Source

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

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

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