Complack
Simplack with more of everything. As many stacks as you name, labels, four conditional jumps and subroutines.
Olivato, 2020 · Turing complete: yes · ●○○ easy · esolangs.org
Tested with 6 known programs · Test method
Run it
The idea
Olivato built Complack on Simplack, a small stack language by Saka, and the name is short for Complex Stack. A program is one instruction a line, and every instruction works on the selected stack. use potato selects a stack called potato, and makes it the first time. Items are found by index, counted from the bottom, and an argument written $2 means the item at index 2.
The machine
| Instruction | Does |
|---|---|
use n | Select stack n |
push n pop i | Push a number; remove the item at index i |
inc i n dec i n set i n | Add to, subtract from or set the item at index i |
label l goto l | Mark a line; jump to it |
if i n goto l | Jump if the item at index i is n; nif bif sif jump if it is not, if it is bigger, if it is smaller |
sub n ... end gosub n | A subroutine and its call |
output i c prints c | Print one item or the whole stack as characters, or with i as numbers |
input c input i | Push the characters of a line, or its number |
exit | Stop |
A line that starts with # is a comment. A jump may also name a line number, counted from 0 without the comments, which the specification discourages.
Example
The square of the input adds the input to index 2 while index 1 counts up to it.
The square of the input adds the input to index 2 while index 1 counts up to it.
The subroutines push 0, 10 and 20 three times. Then the second one twice removes the bottom item and prints the new bottom.
The Fibonacci program keeps five numbers on a stack called fib, the last one 10 for the line break, and counts down on a second stack.
Patterns it teaches
- Stack machines: the stacks are named and read anywhere by index.
- Counter machines: unbounded integers and conditional jumps are enough.
Further
See also
Stack-based
Write your own in Run Convert a program from Complack
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: complack.
Command line
shib run complack -e '# Echo what user input
input c
prints c' --input 'hello'shib manual complackSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/complack.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org