Momema

From Esolang
Jump to navigation Jump to search

Momema is a boring imperative language with memory-mapped control flow created by User:Challenger5 in 2018. Its only real gimmick is to unify (or, more accurately, to lump) jump labels and (relative) jump statements. It was created due to a dissatisfaction with many similar languages that were in common use on PPCG, and to experiment with the creation of a very high quality interpreter (it supports a full interactive mode with a REPL, breakpoints, state debugging, etc.).

Language Overview

A Momema program has access to a doubly-infinite tape of unbounded integers, indexed by unbounded integers. A program consists of a list of assignment statements. An assignment statement consists of two expressions, and has the semantics of storing the result of the second expression in the tape cell given by the result of the first.

4   0

This assigns the value of the cell at index 4 to 0, which is useless since all cells are initialized to 0 anyway.

-8  0

The cells -8 and -9 are memory mapped for I/O. Reading and writing numbers from the cell -9 will output and input the corresponding Unicode character, respectively. -8 is the same, but works with numbers rather than character codes. -9 will return -1 on EOF; -8 will simply halt the program.

0   *-8
-8  *0

The * operator "dereferences" an integer, returning the value of the tape cell at that location. This program reads from cell -8 to read an integer from STDIN, and then writes to -8 to write it back out.

-8  + 5 5

The prefix + operator adds two numbers. This prints 10.

0   = 0
1   = -5

The = operator returns 0 if its argument is 0, and 1 otherwise.

j 0
j -1

The j command is both a label and a jump: it takes an argument and jumps forward (or backwards, if negative) past that many labels. It follows that an argument of 0 does nothing, and only serves as a label.

This program is an infinite loop.

j   0
r   *5
5   1
j   1
r   0

In fact, any string of lowercase characters acts like j, and only pays attention to jumps with their own label.

In this program, execution proceeds as follows: the initial j has an argument of 0, and does nothing. The first r gets the value at cell 5, returning 0, so it, too, does nothing. After this, we encounter an instruction that sets cell 5 to 1. The second j instruction has an argument of 1, but since there are no further j jumps in the program, it wraps around and starts searching from the beginning, causing a jump to the first j. This time, the argument to r is 1, so we jump forward to the second r, ending the program.

More information about the langauge, as well as an implementation, can be found on github.