VarStack
Every variable is a stack of single characters, and every line ends with a jump.
ChuckEsoteric08 · Turing complete: yes · ●○○ easy · esolangs.org
Tested with 4 known programs · Test method
Run it
The idea
ChuckEsoteric08 made VarStack. A program is a list of lines of the form label;command;label. A line runs its one command and then jumps to the line named by its second label. There is no program counter that falls through to the next line, so even a straight run of commands needs a label on each line.
Read the story
Data lives in stacks with names, and each stack holds single characters. Conditions are jumps that compare the top of a stack with a character or with the top of another stack. Reaching for a label, a stack or an element that is not there halts the program, and that is how every program ends.
The machine
| Command | Does |
|---|---|
@X:Y | Make a new stack X holding the characters of Y |
$X:Y | Push X onto stack Y |
!X | Pop stack X |
"X | Print X |
'X | Print stack X |
?X | Read one character onto X |
#X=Y:Z | Jump to Z if the top of X is Y |
!X=Y:Z | Jump to Z if the top of X is not Y |
%X=Y:Z | Jump to Z if the tops of X and Y are equal |
~X &X ^X | Swap the top two; reverse; move the top to the bottom |
The specification leaves a few things open. This implementation pushes the characters of Y in order, so the last one ends on top, and 'X prints from the bottom up. ?X at the end of the input halts.
Example
Hello World jumps to halt, a label no line has, so the program stops after one line.
Hello World jumps to halt, a label no line has, so the program stops after one line.
The truth-machine starts stack X with a 0, reads a character on top of it and compares.
The cat reads a character, prints the stack and pops it again. It never jumps out, and stops only when there is nothing left to read.
A stack made from a word prints back as that word, and & turns it around.
The specification also has a Bitwise Cyclic Tag interpreter in 22 lines. It reads the program and the data character by character, each ended by @, and uses & to reach both ends of the data. It has no output command, so it only shows that it halts, which it does once the data is empty.
Patterns it teaches
- Stack machines: as many stacks as there are names.
- Tag systems: the Bitwise Cyclic Tag interpreter.
Further
See also
Stack-based
Write your own in Run Convert a program from VarStack
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: varstack.
Command line
shib run varstack -e 'hello;"Hello, World!;halt'shib manual varstackSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/varstack.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org