esolang

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

Expected: Hello, World!

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

CommandDoes
@X:YMake a new stack X holding the characters of Y
$X:YPush X onto stack Y
!XPop stack X
"XPrint X
'XPrint stack X
?XRead one character onto X
#X=Y:ZJump to Z if the top of X is Y
!X=Y:ZJump to Z if the top of X is not Y
%X=Y:ZJump to Z if the tops of X and Y are equal
~X &X ^XSwap 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.

Expected: 0

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.

Expected: cat

A stack made from a word prints back as that word, and & turns it around.

Expected: kcats

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

Further

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 varstack

Source

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