esolang

Moaiscript

A program is a column of moai heads. Only how many stand on each line matters.

Dtp09, 2021 · Turing complete: yes · ●●○ moderate · esolangs.org

Tested with 4 known programs · Test method

Run it

Expected: 🗿

The idea

Dtp09 made Moaiscript in 2021, after Chicken. The only characters it reads are the moai emoji 🗿 and the line break. Each line is one instruction, and the number of moai on it says which. Ten or more push a number, so the count is the value plus ten. Eiim wrote a second interpreter, MoaIDE.

The machine

A stack of numbers, a memory, a compare flag, and the input as a row of characters.

MoaiDoes
1Push the input character at the index on top, 0 past the end
2Print the top as a UTF-8 character, a moai for 0
3Write the second value to memory at the absolute value of the top
4Push the memory at the index on top
5 6 7Pop two, push the difference, the sum or the product
8Set the flag if the top two are equal, clear it if not
9If the flag is set, move by the top's number of lines
10 or morePush the count less 10

The specification does not say which instructions pop. Its Hello World and its two cats only work when nothing but the arithmetic pops, and when an empty stack reads as 0, so that is how this implementation runs. A jump counts from its own line, and leaving the program at either end stops it.

Example

An empty stack reads as 0, and printing 0 prints a moai.

An empty stack reads as 0, and printing 0 prints a moai.

Eleven lines print Hi. The counts are 17 20 7 12 6 2 13 21 7 6 2. That is push 7, push 10, multiply to 70, push 2, add to 72, print H. Printing does not pop, so the next lines add 33 to the 72 and print i.

Expected: Hi

The Hello World works the same way in 53 lines. Its first cat keeps the input index in memory cell 0 and the character in cell 1, and jumps 26 lines back while there is input. Eiim's cat uses only the stack.

Expected: moai

Patterns it teaches

  • Stack machines: ten instructions on one stack and a memory.
  • Encoding tricks: an instruction is a count, a number is the count less ten.
  • Camouflage: like Chicken, the whole program is one symbol repeated.

Further

Stack-based

Write your own in Run Convert a program from Moaiscript

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run moaiscript program.txt --input 'stack only'

The program is long; save it as program.txt first.

shib manual moaiscript

Source

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

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

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