esolang

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

Expected: E

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

InstructionDoes
load v cPut v in cell c
copy a bCopy cell a to cell b
set_length n vMake the tape n cells long, every cell v
add a b subtract a bPut a + b, or b - a, in cell b
clamp a bPut the digits of a then those of b in cell b, so 6 and 9 give 69
print 1 c print 0 cPrint cell c as a character or as a number
get_character 1 cRead a character code into c; with 0, the digit typed
get_character_outputThe same, and print the character
compare a bRemember two cells for the next conditional jump
jump_equal n jump_greater n jump_less nJump to word n if the first cell is equal, greater or less
jump n haltJump 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.
Expected: 32

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.

Expected: 255

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.

Expected: cat

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.

Expected: 2

Patterns it teaches

Further

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 loadstring

Source

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