esolang

MAWP

One stack that starts with a 1 on it, four letters for arithmetic and a digit at a time.

2020 · Turing complete: yes · ●●○ moderate · esolangs.org

Tested with 8 known programs · Test method

Run it

Expected: Hello, World!

The idea

MAWP was made in 2020. It works on one stack of whole numbers, and the stack starts as [1]. The letters M, A, W and P add, subtract, multiply and divide. A digit pushes only itself, so 72 is written 98W and 101 is 55W4W1M.

Read the story

The language grew in versions. 0.1 added a reverse, a stack length and loops that test before they run, and the specification shows it Turing complete by a translation from Volatile. 1.0 added the { } test and reading digits, and 1.1 two rotations. Version 2.0 changed several old commands and added strings, decimals and variables.

This implementation is version 1.1, which every program in the specification before 2.x is written for. The 2.x Hello World does not run.

The machine

CommandDoes
0 to 9Push the digit
M A W PAdd, absolute difference, multiply, floor divide the top two
% !Pop; duplicate
: ;Print and pop the top as a number; as a character
[ ]Loop while the top is not 0
( )Loop while the top is 0
< >Skip to > when the top is not 0
{ }Skip to } when the top is 0
?Skip the next command when the top is not 0
~ _Reverse the stack; push its length
/ \Move the top to the bottom; the bottom to the top
| @Push every input byte; the same with digits as numbers and others as 0
.End

None of the brackets and tests pop the value they look at.

Example

The truth machine takes the absolute difference of the 1 at the start and the input.
Expected: 0

The truth machine takes the absolute difference of the 1 at the start and the input. On 0 that is 1, so { lets it through to print 0 and end. On 1 it is 0, { skips the block and the loop prints 1 forever.

The second quine on the specification is 40 digits that spell the rest of the program in ASCII. The loop joins them in pairs, prints each pair as a number and rotates, and the last loop prints the same numbers as text.

Expected: 48923792915350878792773358929392915992930\%\[52WW\M!:\]\[;\]

Odd or even reads a number of any length, takes 2 away until 1 or 0 is left, and prints 0 for odd and 1 for even.

Expected: 1

Patterns it teaches

  • Stack machines: everything happens on one stack, rotated like a ring.
  • Quine: data that is the program's own ASCII codes, printed twice.

Further

Stack-based

Write your own in Run Convert a program from MAWP

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run mawp -e '@A{1A:.}1M[!:]' --input '0'
shib manual mawp

Source

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

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

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