Simplack
One stack of integers, nine instructions and a line number for every jump.
Saka, 2018 · Turing complete: unknown · ●○○ easy · esolangs.org
Tested with 5 known programs · Test method
Run it
The idea
Saka made Simplack in 2018 to be easy to learn. A program is one instruction a line. The stack holds only integers, but any item can be read or changed by its index, counted from the bottom, so the stack works more like a row of numbered cells. An argument written $2 means the item at index 2.
Read the story
Jumps go to line numbers, counted from 0. Every line counts, the comments too.
The machine
| Instruction | Does |
|---|---|
push n | Push a number |
pop i | Remove the item at index i |
increase i n set i n | Add n to the item at index i, or set it to n |
if i n goto l | Jump to line l if the item at index i is n |
goto l | Jump to line l |
output i a output i i | Print the item at index i as a character or as a number |
input a input i | Push the characters of an input line, or its number |
exit | Stop |
A line that starts with # is a comment. Running off the last line also stops the program.
Example
The truth machine.
The truth machine. On 0 it prints 0 and exits; on 1 it jumps to line 4 and prints 1 forever.
The square of the input adds the input to index 2 while index 1 counts up to it. The comment is line 0, so goto 4 lands on the first increase.
The cat pushes a 0 behind the input, then prints and removes the bottom item until the 0 comes up.
Patterns it teaches
- Stack machines: a stack read anywhere by index.
- Counter machines: unbounded integers, adding and a test for equality.
Further
- esolangs.org/wiki/Simplack
- Complack, its extension with named stacks, labels and subroutines.
See also
Stack-based
Write your own in Run Convert a program from Simplack
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: simplack.
Command line
shib run simplack -e 'input a
push 0
output 0 a
pop 0
if 0 0 goto 6
goto 2
exit' --input 'cat'shib manual simplackSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/simplack.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org