Modulous

From Esolang
Jump to navigation Jump to search

Modulous is a 1D stack based esoteric programming language that is somewhat inspired by the assembly language. Made by Abyxlrz

Please read everything here

What?

a module is a command surrounded by square brackets []

the command pointer (module pointer) starts at the first module, it reads the commands and executes them (obviously).

Commands

Command/Module Effect Example
[JMP {F or B} {number of modules}] makes the pointer jump a number of modules (forwards if f and back if b) [JMP F 1]
[JMP {F or B} {number of modules} IF {second number}] makes the pointer jump a number of modules (forwards if f and back if b) if the top element of the stack is a specified number (second number) [JMP F 1 IF 0]
[JMP {F or B} {number of modules} IF NOT {second number}] makes the pointer jump a number of modules (forwards if f and back if b) if the top element of the stack is not the number you specified (second number) [JMP F 1 IF NOT 0]
[JMP {F or B} {number} IF LES {second number}] makes the pointer jump a number of modules (forwards if f and back if b) if the top element of the stack is less than the specified number (second number) [JMP F 1 IF LES 10]
[JMP {F or B} {number} IF MOR {second number}] makes the pointer jump a number of modules (forwards if f and back if b) if the top element of the stack is more than the specified number (second number) [JMP F 1 IF MOR 0]
[ADD {number}] adds a number to the top element of the stack [ADD 100]
[SUB {number}] subtracts a number from the top element of the stack [SUB 5]
[RST] resets the pointers position (puts the pointer at the start of the program) [RST]
[PSH {INT or STR} {number or string (string in quotes)}] pushes a number or string to the stack and if you add multiple numbers separated by spaces it will push all of them one by one [PSH INT 66] or [PSH STR "Hello!"]
[PSH {variable}] sets the specified variable to the top number of the stack [PSH VAR1]
[POP] pops the top number from the stack [POP]
[SWP] swaps the top two numbers in the stack [SWP]
[PRT {INT or STR}] prints the top number of the stack as a number or an ASCII character and pops it [PRT INT] or [PRT STR]
[PRT {variable} {INT or STR}] prints the specified variable as 1 ASCII character or number and the variable keeps its value [PRT VAR2 INT] or [PRT VAR2 STR]
[INP {INT or STR}] takes input from the user and pushes it on to the stack [INP INT] or [INP STR]
[END] ends the program [END]
[DUP] duplicates the top number of the stack [DUP]
[RND {number} {higher number}] randomly generates a number between the two numbers specified and pushes it to the stack [RND 0 100]
[{variable}+{number}] adds a number to the specified variable [VAR1+10]
[{variable}-{number}] subtracts a number from the specified variable [VAR1+1]

Other things

Other things (rules)
If there is nothing on the stack and you add a number then a 0 will be pushed to the stack and the number that you wanted to ADD will be added to the 0
If you subtract from 0 then the element will be popped
You can do multiple numbers separated by commas. example [MOV F 2 IF NOT 1,3]
If a string gets pushed to the stack it gets inverted first. example [PSH STR “hello”] -> h e l l o -> o l l e h then gets put onto the stack
VAR is a variable, there are 5, they are VAR followed by a number from 1 to 5 (example VAR1), they can store a single number each
Anything pushed to a variable stays on the stack
Anything outside of a module counts as a comment. example [Command]Comment[Command]
If the interpreter (or you) inspect a number on the stack / compare a number (with a command) then the number will not be popped
The program ends when you reach the end of the program
INT is for integer and STR is for string

Example programs

Hello World program

[PSH STR “Hello, World!”][PRT STR][JMP B 1 IF NOT 0]

Cat program

[INP STR][PRT STR][JMP B 1 IF NOT 0][JMP B 3]

Truth-machine

[INP INT][JMP F 3 IF 0][JMP F 4 IF 1][RST][PRT INT][END][DUP][PRT INT][JMP B 2]

Counter

[PSH INT 0][DUP][PRT INT][ADD 1][JMP B 3]

Number guessing game

[PSH STR “Guess a number from 0 to 100”][PRT STR][JMP B 1 IF NOT 0][RND 0 100][PSH VAR1][INP INT][JMP F 15 IF VAR1][JMP F 2 IF LES VAR1][JMP F 7 IF MOR VAR1][POP][JMP B 1 IF NOT 0][PUSH STR “Too low!”][PRT STR][JMP B 1 IF NOT 0][JMP B 9][POP][JMP B 1 IF NOT 0][PSH STR “Too high!"][PRT STR][JMP B 1 IF NOT 0][JMP B 15][POP][JMP B 1 IF NOT 0][PSH STR “Correct!”][PRT STR][JMP B 1 IF NOT 0][END]

99 bottles of beer

[VAR1+99][JMP F 2][POP][PSH INT VAR1][PRT INT][PSH STR “bottles of beer on the wall, ”][PSH INT 10][PRT STR][JMP B 1 IF NOT 0][PSH INT VAR1][PRT INT][PSH STR “bottles of beer “][PSH INT 10][PRT STR][JMP B 1 IF NOT 0][PSH STR “Take one down, pass it around, “][PSH INT 10][PRT STR][JMP B 1 IF NOT 0][VAR1-1][PSH INT VAR1][PRT INT][PSH STR “bottles of beer on the wall”][PSH INT 10,10][PRT STR][JMP B 1 IF NOT 0][PUSH INT VAR1][JMP B 22 IF NOT 1][PSH INT VAR1][PRT INT][PSH STR “bottle of beer on the wall, ”][PSH INT 10][PRT STR][JMP B 1 IF NOT 0][PSH INT VAR1][PRT INT][PSH STR “bottle of beer “][PSH INT 10][PRT STR][JMP B 1 IF NOT 0][PSH STR “Take one down, pass it around, “][PSH INT 10][PRT STR][JMP B 1 IF NOT 0][PSH STR “no bottles of beer on the wall”][PRT STR][JMP B 1 IF NOT 0][END]