esolang

MagiStack

Unefunge without arrows. To loop, it skips backwards until it finds a marker.

Katrina Scialdone, 2015 · Turing complete: unknown · ●●○ moderate · esolangs.org

Tested with 8 known programs · Test method

Run it

Expected: Hello, world!

The idea

Katrina Scialdone made MagiStack in 2015, after Unefunge, the one-dimensional cousin of Befunge. Most commands are Befunge's, such as the digits, arithmetic, : \ $, . and ,. But a line has no arrows to turn around with. Instead # skips forward to the next #, | or ], and @ skips back to the last @, | or [. A loop is a | at its start and ?1=#@ at its end, and = decides whether the # gets skipped.

Read the story

The language stopped at version 1.2, which added string mode, ~ to turn the whole stack over and ; to bring its bottom to the top.

The machine

CommandDoes
0...9Push the digit
+ - * / %Pop a, then b; push b+a, b-a, b*a, b/a, b%a
backtickPush 1 if b > a
!Push 1 if a is 0
: \ $Duplicate, swap, drop
. ,Print a number, print a character
=Pop two; skip the next character if they differ
# @Skip forward to # | ], back to @ | [
> <Skip to the last |, to the first |
?Push the stack size
^ &Read a number; read a line as character codes
"..." {Push characters; push the digits of a number as characters
~ ;Turn the stack over; move its bottom to the top
_End

The specification's table says @ stops at ], but its 99 bottles of beer for version 1.0 only ends if @ stops at [ instead; with ] it runs away. An empty stack gives 0, as in Unefunge.

Example

Version 1.2 pushes the whole text, turns the stack over so the H is on top, and prints until the stack is…

Version 1.2 pushes the whole text, turns the stack over so the H is on top, and prints until the stack is empty. ?0= skips the # while something is left, so @ jumps back to the |.

Version 1.1 had no strings, so its Hello World pushes the codes as pairs of digits and joins each pair with \91+*+. The codes it holds are the capitals.

Expected: HELLO, WORLD!

The factorial counts down to 1 in one loop, leaving 5 4 3 2 1 on the stack, then multiplies until one number is left.

Expected: 120
Expected: cat

Both versions of 99 bottles of beer in the specification sing all 99 verses, version 1.0 in capitals.

Patterns it teaches

  • Stack machines: with the whole stack turned over to read it from the bottom.

Further

Stack-based

Write your own in Run Convert a program from MagiStack

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: magistack.

Command line

shib run magistack -e '&~|,?0=#@' --input 'cat'
shib manual magistack

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/magistack.js

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

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