esolang

Super Stack!

One stack of numbers, words for every command, and a stack you can turn like a wheel.

Orange, 2009 · Turing complete: yes · ●○○ easy · esolangs.org

Tested with 3 known programs · Hello World on Try It Online: identical · Test method

Run it

Expected: Hello, World!

The idea

Super Stack! was made in 2009 by the esolangs.org user Orange. A program is a list of keywords separated by whitespace: numbers to push, and words like add, dup and outputascii.

Read the story

The twist is that the stack is not quite a stack. cycle moves the top item to the bottom and rcycle brings the bottom one back up. With that, the stack becomes a ring you can walk around, and the specification shows how to turn any brainfuck program into Super Stack! that way.

The only control flow is if ... fi, which is really a while loop. It runs while the top value is not 0 and never pops it. Strings are pushed in reverse with a 0 under them, then printed with if outputascii fi, which stops when it reaches the 0.

The machine

One stack of integers. Words that are not keywords are ignored, so the specification writes comments as `words .

WordDoes
123Push a number
add sub mul div modPop two, push second op top (div and mod floored)
and or xor nand notLogic on 0 / not 0, pushing 1 or 0
randomPop n, push a number from 0 to n-1
output outputasciiPop and print as a number plus a space, or as a character
input inputasciiRead a line as a number, or push its characters with the first on top
pop swap dup revDrop, swap, duplicate, reverse the whole stack
cycle rcycleMove the top to the bottom, or the bottom to the top
if ... fiLoop while the top is not 0 (does not pop)
quit debugEnd the program, print the stack

Popping an empty stack gives 0, since the specification is silent. Dividing by zero or printing a code outside 0 to 255 stops the program. Reading past the end of input ends it, as in the Python reference. random uses a fixed seed, so runs repeat.

Example

The numbers push the text backwards, with a 0 at the bottom and H on top.

The numbers push the text backwards, with a 0 at the bottom and H on top. The loop prints the top character each time round. When only the 0 is left, the loop ends.

Patterns it teaches

Try this

  1. Print the numbers 1 to 10 with a loop.
  2. Read a line and print it back reversed.
  3. Hard: write the brainfuck program +++. with the specification's conversion table and run it.

Further

Stack-based

Write your own in Run Convert a program from Super Stack!

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: super-stack.

Command line

shib run super-stack -e '0 33 100 108 114 111 87 32 44 111 108 108 101 72
if outputascii fi'
shib manual super-stack

Source

Module
langs/stack/ports.js
Interpreter
langs/stack/super-stack.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org