Loadstring
Fifteen instructions on a tape, and a jump that counts words.
Turing complete: yes · ●○○ easy · esolangs.org
Tested with 8 known programs · Test method
Run it
The idea
Loadstring is meant to feel like coding on punch cards. Its specification warns that writing it is mind-numbing and agonizing. The instructions are plain. They load a number, add two cells, print one. The pain is in the jumps. A jump does not go to a line or a label. It goes to a word, counted from 0 over every instruction name and every number in the program. Add one parameter anywhere and every jump after it is wrong.
The machine
| Instruction | Does |
|---|---|
load v c | Put v in cell c |
copy a b | Copy cell a to cell b |
set_length n v | Make the tape n cells long, every cell v |
add a b subtract a b | Put a + b, or b - a, in cell b |
clamp a b | Put the digits of a then those of b in cell b, so 6 and 9 give 69 |
print 1 c print 0 c | Print cell c as a character or as a number |
get_character 1 c | Read a character code into c; with 0, the digit typed |
get_character_output | The same, and print the character |
compare a b | Remember two cells for the next conditional jump |
jump_equal n jump_greater n jump_less n | Jump to word n if the first cell is equal, greater or less |
jump n halt | Jump to word n; stop |
Cells hold integers of any size. The specification does not say how long the tape is before set_length, so in this implementation it grows as needed. The end of input reads as 0.
Example
The jump example.
The jump example. jump_equal 12 skips the halt, because print is word 12. Before it come three words for each load, three for compare, two for the jump and one for halt.
The cat reads into cell 1 and jumps back to word 3, the get_character_output, while 0 is less than the character it read. At the end of input it reads 0 and stops.
The division example reads its two digits with get_character 1, as character codes, and so never reaches 0. Read with get_character 0 it divides 8 by 4.
Patterns it teaches
- Hostile design: jumps by word index, so every edit moves them.
Further
See also
Cell-based
Write your own in Run Convert a program from Loadstring
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: loadstring.
Command line
shib run loadstring -e 'load 69 0
print 1 0'shib manual loadstringSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/loadstring.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org