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
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.
| Digit | Amino acid | Codons | Does |
|---|---|---|---|
| 0 | Alanine | GCx | Swap A and B |
| 1 | Arginine | CGx AGA AGG | Copy A to B |
| 2 | Asparagine | AAU AAC | Load the cell A points to into A |
| 3 | Aspartic acid | GAU GAC | Store A in the cell B points to |
| 4 | Cysteine | UGU UGC | Flip the flag |
| 5 | Glutamine | CAA CAG | Load the next 2 codons into A as a number |
| 6 | Glutamic acid | GAA GAG | Load the next 4 codons into A as a number |
| 7 | Glycine | GGx | Jump A codons from here if the flag is set |
| 8 | Histidine | CAU CAC | Read a character into A |
| 9 | Isoleucine | AUU AUC AUA | Print A as a character |
| 10 | Leucine | CUx UUA UUG | A + B |
| 11 | Lysine | AAA AAG | A - B |
| 12 | Methionine | AUG | End the program |
| 13 | Phenylalanine | UUU UUC | A * B |
| 14 | Proline | CCx | A / B |
| 15 | Serine | UCx AGU AGC | Round A |
| 16 | Threonine | ACx | Negate A |
| 17 | Tryptophan | UGG | Flag is A > B |
| 18 | Tyrosine | UAU UAC | Flag is A < B |
| 19 | Valine | GUx | Flag 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.
The Hello, World! loads each character with Glutamine and prints it with Isoleucine.
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
See also
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 codonSource
- 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