StackMachine

From Esolang
Jump to navigation Jump to search

This is an ordinary stack-based esolang that was created by a Discord bot(antigollark).


First answer

push: Pushes a value onto the stack.
pop: Pops a value from the stack and discards it.
dup: Duplicates the top value on the stack.
swap: Swaps the top two values on the stack.
rot: Rotates the top three values on the stack.
add: Adds the top two values on the stack and pushes the result.
sub: Subtracts the top two values on the stack and pushes the result.
mul: Multiplies the top two values on the stack and pushes the result.
div: Divides the top two values on the stack and pushes the result.
mod: Calculates the modulus of the top two values on the stack and pushes the result.
store: Stores a value in a variable.
load: Loads a value from a variable.

Second answer

prompt: "why it can't do loop"

jnz: Jumps to a label if the top value on the stack is not zero.
jmp: Jumps to a label unconditionally.

Third answer, details given

prompt: "give details about these 14 commands(the format, the errors, etc)" and this answer also adds trigonomic functions and sqrt.

push: Takes a value as an argument and pushes it onto the stack. If the value is not a valid number, an error is thrown.
pop: No arguments. If the stack is empty, an error is thrown.
dup: No arguments. If the stack is empty, an error is thrown.
swap: No arguments. If the stack has less than two values, an error is thrown.
rot: No arguments. If the stack has less than three values, an error is thrown.
add: No arguments. If the stack has less than two values, an error is thrown.
sub: No arguments. If the stack has less than two values, an error is thrown.
mul: No arguments. If the stack has less than two values, an error is thrown.
div: No arguments. If the stack has less than two values, an error is thrown.
mod: No arguments. If the stack has less than two values, an error is thrown.
sqrt: No arguments. If the stack is empty, an error is thrown.
sin: No arguments. If the stack is empty, an error is thrown.
cos: No arguments. If the stack is empty, an error is thrown.
tan: No arguments. If the stack is empty, an error is thrown.
jnz: Takes a label name as an argument. If the label does not exist, an error is thrown.
jmp: Takes a label name as an argument. If the label does not exist, an error is thrown.
All operations other than push can produce a value which is too large to be represented. In that case, an error is thrown.

About rot

The bot kept answering me this:

It takes the top three values and pushes them back onto the stack in the order: 1, 3, 2.

it said, if the stack is

[bottom] c b a [top]

after doing the command, the stack become

[bottom] b a c [top]