Loader

Loader is an esolang by SuperJedi224, in which recursive module loading is the principal mode of recursion and iteration.

A program consists of the main module (the one that will be directly called from the interpreter) and zero or more secondary modules. The file name for a module is the name of the module (which may not contain any spaces) with the extension .ldr.

Modules may be loaded on either a copy of the current memory space (load), or on the current memory space itself (loadip).

The memory space consists of zero or more variables (whose names consist exclusively of uppercase letters), each of which may store a 32-bit sigined integer, and a bidirectionally unbounded tape of 32-bit signed integers.

Unary Operators
- Unary Negation ~ Boolean NOT operator (yields 1 if the argument is 0, 0 otherwise) * Splat operator (for pointers; when used in an expression, yields the value on the tape pointed at by the argument)

Instructions
incr -> Increment that variable; when used in an expression, yield the variable's new value. All variables may be assumed to be preinitialized to 0. incr * -> Increment the value on the tape pointed at by this value; when used in an expression, yield the target's new value decr -> Decrement that variable; when used in an expression, yield the variable's new value decr * -> Decrement the value on the tape pointed at by this value; when used in an expression, yield the target's new value erase -> Zero all cells on the tape from the specified index through the next cell which is already zero. May not be used in expressions. exit -> Exit the program load -> Load and execute the specified module on a copy of the current memory. When used in an expression, yields the value that module call returned. loadip -> Load and execute the specified module on the current memory itself. When used in an expression, yields the value that module call returned. print  -> Printing the specified values to the output, in the specidfied order and on seperate lines. May not be used in expressions. printbool -> Print TRUE if the specified value is nonzero, and FALSE otherwise; followed by a newline. May not be used in expressions. printchar  -> Prints the specified values as ascii characters, in the specified order. Then, prints a newline. May not be used in expressions. printf " "  -> Prints the specified string with the specified values substituted for instances of %n (which are replaced with numeric values), %c (which are replaced with ascii characters), and/or %b (which are replaced with TRUE if the corresponding value is nonzero, and FALSE otherwise). printst -> Prints as characters the values on the tape starting at that index and continuing up to (but not including) the next 0. Then, prints a newline. May not be used in expressions. write " " -> Write to the tape the ascii codepoints of the characters in that string, starting at the specified index on the tape and continuing rightwards. May not be used in expressions. readline -> Reads the next line of input onto the tape (as the corresponding ascii codepoints), starting at the specified index on the tape. When used in expressions, yields the number of characters read. On EOF, does nothing and returns 0. set  = -> Set each variable in the (comma-seperated) list to the specified value, * may be substituted for any variable. When used in an expression, yield the specified value. throw " "  -> Throws an error. Substitutions work as with printf. warn " "  -> Throws a warning. Substitutions work as with printf. yield -> Exit the current module and return the specified value. "yield 0" is implicitly appended to every module. May not be used in expressions.

Special Expressions
@IN -> Yields a number taken from the input

Conditionals
Single-line conditionals may be formed by preceding that line of code with an expression, followed by a colon. That line will only be run if the expression evaluates to a nonzero value.

Comments
As in GridScript, single-line comments begin with double exclamation points. However, unlinke in GridScript, a comment can be appended to the end of a line and is not required to be put on its own line.

Interpreter
A java interpreter can be found here.

This interpreter takes the name of the main module from a command line argument or STDIN, and takes all program input from STDIN.

Count down from 100
(run from main.ldr)

~B:set A,B =100 print A decr A A:load main

Alternate Version in 2 modules
(main module, run from any .ldr file)

set A 100 load decrement

(decrement.ldr) print A decr A A:load decrement

Truth Machine
(run from main.ldr)

~B:set B =@IN ~B:print 0 ~B:exit print 1 load main

Alternate Version in 2 modules
(main module, run from any .ldr file)

set B =@IN B:load one print 0

(one.ldr)

print 1 load one

Hello, World!
printf "Hello, World!"

Cat Program
(Run from main.ldr)

erase 0 readline 0 *0:printst 0 *0:load main

99 Bottles of Beer
(Run from main.ldr)

~I:set I,BOTTLES =99 ~BOTTLES:printf "No more bottles of beer on the wall!" ~BOTTLES:printf "No more bottles of beer!" ~BOTTLES:printf "You go to the store and you buy some more," ~BOTTLES:printf "99 bottles of beer on the wall!" ~BOTTLES:exit set PLURAL =BOTTLES decr PLURAL PLURAL:printf "%n bottles of beer on the wall!" BOTTLES PLURAL:printf "%n bottles of beer!" BOTTLES ~PLURAL:printf "1 bottle of beer on the wall!" ~PLURAL:printf "1 bottle of beer!" printf "You take one down and you pass it around," decr BOTTLES decr PLURAL BOTTLES:PLURAL:printf "%n bottles of beer on the wall!" BOTTLES BOTTLES:~PLURAL:printf "1 bottle of beer on the wall!" ~BOTTLES:printf "No more bottles of beer on the wall!" printf "" load main