esolang

Codon

A program is messenger RNA. Each codon is an amino acid, and each amino acid is an opcode or a digit.

Dtp09, 2023 · Turing complete: unknown · ●●○ moderate · esolangs.org

Tested with 4 known programs · Test method

Run it

Expected: H

The idea

Dtp09 made Codon in 2023, on the idea of RNA with another syntax. A program is written in the four bases U, C, A and G and read three at a time. The standard genetic code turns each of the 64 codons into one of 20 amino acids or a stop. As in a ribosome, the work starts after the first AUG and ends at the first stop codon.

Read the story

The 20 amino acids are the 20 opcodes. Put in alphabetical order, from Alanine to Valine, they are also the digits 0 to 19 of base 20, so the numbers in a program are spelled in amino acids as well. Methionine, the start codon, is 12, and inside a number it does not end anything.

The machine

Two registers A and B, a comparison flag and a row of cells, all 0 at first. In the table x is any of the four bases.

DigitAmino acidCodonsDoes
0AlanineGCxSwap A and B
1ArginineCGx AGA AGGCopy A to B
2AsparagineAAU AACLoad the cell A points to into A
3Aspartic acidGAU GACStore A in the cell B points to
4CysteineUGU UGCFlip the flag
5GlutamineCAA CAGLoad the next 2 codons into A as a number
6Glutamic acidGAA GAGLoad the next 4 codons into A as a number
7GlycineGGxJump A codons from here if the flag is set
8HistidineCAU CACRead a character into A
9IsoleucineAUU AUC AUAPrint A as a character
10LeucineCUx UUA UUGA + B
11LysineAAA AAGA - B
12MethionineAUGEnd the program
13PhenylalanineUUU UUCA * B
14ProlineCCxA / B
15SerineUCx AGU AGCRound A
16ThreonineACxNegate A
17TryptophanUGGFlag is A > B
18TyrosineUAU UACFlag is A < B
19ValineGUxFlag is A == B

The arithmetic leaves its result in A. UAA, UAG and UGA are stop codons. Whitespace is ignored, # starts a comment, and the end of the input reads as 0.

Example

Glutamine reads the next two codons as base 20 digits.

Glutamine reads the next two codons as base 20 digits. Aspartic acid is 3 and Methionine 12, and 3 times 20 plus 12 is 72, the code of H.

The cat. It compares the character with 0, flips the flag, and jumps 2 codons over the AUG that would end it. At the bottom it loads 18, negates it and jumps back to the start.

Expected: cat

The Hello, World! loads each character with Glutamine and prints it with Isoleucine.

Expected: Hello, World!

Patterns it teaches

  • Camouflage: a program that is also a strand of RNA, read the way a cell reads it.
  • Encoding tricks: one alphabet of 20 amino acids for both the opcodes and the digits.

Further

Cell-based

Write your own in Run Convert a program from Codon

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run codon program.txt --input 'cat'

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

shib manual codon

Source

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

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

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