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 []

I'll refer the command pointer as the module pointer.

Commands

Command/Module Effect Example
[JMP {F or B} {number of modules}] makes the module 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 module pointer jump the {number of modules} (forwards if f and back if b) if the top element of the stack is the {second number} [JMP F 1 IF 0]
[JMP {F or B} {number of modules} NIF {second number}] makes the module pointer jump the {number of modules} (forwards if f and back if b) if the top element of the stack is not the {second number} [JMP F 1 NIF 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 module pointers position (puts the pointer at the start of the program) [RST]
[PSH {INT or STR} {number or string (string in quotes)}] pushes the {number or string} to the stack [PSH INT 66] or [PSH STR "Hello!"]
[PSH {variable}] sets the {variable} to the top number of the stack [PSH VAR1]
[POP] pops the top element from the stack [POP]
[SWP] swaps the top two elements 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 {variable} as 1 ASCII character or number and the {variable} keeps its value [PRT VAR2 INT] or [PRT VAR2 STR]
[INP {INT ir 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}] randomly generates a number between the zero and the {number} and pushes it to the stack [RND 100]
[{variable}+{number}] adds the {number} to the {variable} [VAR1+10]
[{variable}-{number}] subtracts the {number} from the {variable} [VAR1+1]

Other things

Other things (rules)
Negative numbers are allowed.
If there is nothing on the stack and you add a number then you'll get an error.
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 pushed onto the stack one by one.
there are only four variables (VAR1, VAR2, VAR3 and VAR4) they can store a single number each.
Anything pushed to a variable stays on the stack.
If the interpreter inspects 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 NIF 0]

Cat program

[INP STR][PRT STR][JMP B 1 NIF 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]

Interpreters

A Python interpreter by User:Bangyen.