Loadstring

From Esolang
Jump to navigation Jump to search

Introduction

Loadstring is a turing complete esolang, what does loadstring mean? I don't know its just the name I chose because in lua that is a thing! This will give you an experience similar to the one of coding when punch cards were a thing. Bet you can't make anything useful with this, before you download the interpreter I have to warn you, coding in this language is mind-numbing and agonizing. Am I a masochist, am I a sadist, only you can answer by coding in this atrocity! Good luck...

Indexes

Indexes are used for jumps, every identifier or integer has an index, for example:

set_length 2 0
load 420 0
jump 3

The previous code will jump to the load instruction, since set_length has 2 parameters and itself, which makes the index of set_length 1. INDEX 1 = set_length INDEX 2 = 2 INDEX 3 = 0 So index 3 to 8 execute load and jump!

Documentation

Load

load <int value> <int cell>

Loads an integer into a cell.

Copy

copy <int cell1> <int cell2>

Copies the value in a cell to another cell.

SetLength

set_length <int length> <int value>

Sets the length of the tape and replaces every cell with the given value.

GetCharacter

get_character <bool getAscii> <int cell>

Gets input; if getAscii is 1 the ascii value of the input is placed into the cell, else the integer value of the input is placed instead. NOTE: THIS DOES NOT OUTPUT THE CHARACTER THAT YOU PUT IN, IF YOU WANT TO DO THAT YOU HAVE TO USE get_character_output

GetCharacterOutput

get_character_output <bool getAscii> <int cell>

Gets input; if getAscii is 1 the ascii value of the input is placed into the cell, else the integer value of the input is placed instead.

Compare

compare <int cell1> <int cell2>

Sets up compare flag, used when a jump instruction is executed.

JumpEqual

jump_equal <int index>

Jumps to an index (see indexes) if the cells in the compare flag are equal.

JumpGreater

jump_greater <int index>

Same as jump_equal but comparing if it is greater than.

JumpLess

jump_less <int index>

Same as jump_equal but comparing if it is less than.

Jump

jump <int index>

Jumps to an index (see indexes).

Add

add <int cell1> <int cell2>

Adds two cells and saves the value in the second given cell.

Subtract

subtract <int cell1> <int cell2>

Subtracts two cells and saves the value in the second given cell.

Clamp

clamp <int cell1> <int cell2>

Clamps two cells and saves the value in the second given cell e.g. 6 clamped to 9 is 69 (Concatenation).

Print

print <bool isAscii> <int cell>

If isAscii is 1, it prints the ascii value of whatever is in cell, else, it prints the value of the cell as a number.

Halt

halt

Halts execution.

How2Code

Output

load 69 0
print 1 0

This program loads 69 (Ascii for E) into cell 0, then it prints it as an ascii.

Output -> E

Math

load 1 0
load 1 1
add 0 1
print 0 1

This program loads 2 values 1 and 1 to cell 0 and cell 1, then adds them, and prints them as an integer.

Output -> 2

Jump

load 255 0
load 255 1
compare 0 1
jump_equal 12
halt
print 0 1

This program loads 2 values 255 and 255, then compares them setting up a flag, and finally jumps beyond the halt intruction if cell 1 is equal to cell 2.

Output -> 255

Input

get_character 1 0
print 1 0

This program replicates whatever character was put in, you could make a cat program by checking if the character was enter on not, putting in a loop if not!

Input <- h (NOT VISIBLE; SEE DOCUMENTATION)
Output -> h

Double Input

get_character 0 0
get_character 0 1
clamp 0 1
print 0 1

This program gets 2 single digit numbers then clamps them together making a double digit number and then outputs the number!

Input <- 32 (NOT VISIBLE; SEE DOCUMENTATION)
Output -> 32

Set Length

set_length 1 0
load 0 1

This program outputs an error since there is only 1 usable cell and the program is trying to load 0 to a non-existing cell

Output -> <python thingamajinga error thing> at line <whatever>...

Division

get_character 1 1
get_character 1 0
load 0 2
load 0 3
load 1 4
subtract 0 1
compare 1 2
jump_equal 28
add 4 3
jump 15
add 4 3
print 0 3

This final program gets 2 single digit inputs and then divides them, then it prints the result!

Input <- 84 (NOT VISIBLE; SEE DOCUMENTATION)
Output -> 2

8/4 = 2, 84 = 2

Examples

Hello World

set_length 1 0
load 72 0
print 1 0
load 101 0
print 1 0
load 108 0
print 1 0
load 108 0
print 1 0
load 111 0
print 1 0
load 32 0
print 1 0
load 87 0
print 1 0
load 111 0
print 1 0
load 114 0
print 1 0
load 108 0
print 1 0
load 100 0
print 1 0
load 13 0
print 1 0
load 10 0
print 1 0

Truth-machine

set_length 2 0
load 1 0
get_character 0 1
compare 0 1
print 0 1
jump_equal 12

Cat program

set_length 2 0
get_character_output 1 1
compare 0 1
jump_less 3

Interpreter

NOTE: YOU GOTTA HAVE PYTHON TO RUN IT, TO EXECUTE: EITHER DRAG THE FILE YOU WANT TO EXECUTE INTO THE PYC FILE, OR USE CMD AND TYPE interpreter.pyc yourfilename.loadstr I wish you luck, buddy! (in external resources!)

External resources

Download Link