MashedPotatoes
A register machine dressed in C++, Perl, Lisp, Python and BASIC, where a name changes every time it is written.
Mercerenies, 2017 · Turing complete: conjectured · ●●● hard · esolangs.org
Tested with 4 known programs · Test method
Run it
The idea
Mercerenies made MashedPotatoes in 2017 to look like other languages at a glance. Each construct is borrowed and used for something else. std::cout << x << std::endl; stores x in a register, goto rotates the registers, (format t " ... ") is a loop and case ... of reads input.
Read the story
The names change as the parser reads them. Label 0 is written 0.0f the first time, then ++i, <>, Object, and then 0.0f again. The statement that sends Trigger A has six forms used in turn, Trigger B has five, and comments alternate between :S(...) and :F(...). A name out of its turn is a syntax error. Even "Hello, world!" is a counter, 0 where it first appears and 1 the next time.
Whitespace means nothing, with one exception. synchronized (L) sets label L to the line number of its opening parenthesis, and a goto rotates one way for an even label and the other way for an odd one, so moving a line can change what a program does.
The machine
There are three registers ^A, ^C and ^E, three labels and three stacks.
| Statement | Does |
|---|---|
std::cout << x << std::endl; | Put x in ^A |
goto L; | Rotate the registers, A to C to E for an even L, back for an odd one |
synchronized (L) { ... } | L holds the line number of the ( |
(format L " ... ") | Loop while ^C is above 0, taking 1 from it after each pass |
proc L {x} { ... } | L prints x |
case L of { _ -> ... } | L reads input into ^A |
WHILE L op x ... WEND | L does arithmetic on ^E |
def L(x) ... end | L works stack x |
use strict qw/L/; and five more | Send Trigger A to L |
s/L//g and four more | Send Trigger B to L |
A binding lasts while its block runs. What a trigger does depends on the block. On a printer, A prints a character and B a number. On a stack, A pushes ^A and B pops into it. On a loop, A breaks and B goes to the next pass. In expressions --help is 0, STDERR, $[ and `uniq -c` read the registers in turn, (int) L reads a label and @{[ x ]} negates.
Example
This echo reads a line into ^A and prints it as a number.
This echo reads a line into ^A and prints it as a number. It uses label 0 four times, under its four names.
The factorial reads N and rotates the registers until ^C holds N and ^E holds 1. Its loop then multiplies ^E by ^C N times, inside a WHILE whose Trigger B multiplies.
The Fibonacci program keeps two numbers on stack 0 and needs its blocks on the right lines. Its first synchronized sits on an odd line and the two inside the loop on even lines. Given 10 it prints 89.
Patterns it teaches
- Camouflage: code that looks like a dozen other languages and means none of them.
Further
See also
Also in Camouflage
Write your own in Run Convert a program from MashedPotatoes
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: mashedpotatoes.
Command line
shib run mashedpotatoes program.txt --input '5
'The program is long; save it as program.txt first.
shib manual mashedpotatoesSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/mashedpotatoes.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org