Sorry, Marvin!

From Esolang
Jump to navigation Jump to search
Sorry, Marvin!
Paradigm(s) imperative
Designed by User:Ttulka
Appeared in 2024
Dimensions one-dimensional
Computational class Turing complete
Major implementations Interpreter in JavaScript
Influenced by Minsky machine
File extension(s) .sm

Sorry, Marvin! is a failed attempt to design a programming language to simulate Minsky register machines in the simplest way possible.

While the instruction set of Minsky machines, consisting of only two instructions INC and JZDEC, is already minimal, the instructions themselves are relatively complex, as they require one and two arguments, respectively.

Additionally, the registers and instructions in a Minsky machine must be labeled, which requires the use of numbers or other similarly powerful enumeration methods.

Sorry, Marvin! simplifies this by using two instructions together with only two symbols ! and >. No other symbols are allowed.

For this language produces code that is terrible to read and write, an apology is also necessary:

Doctor Minsky, please forgive me
for ruining machines near divine!
Now, full of quirks, they hum in circles
— miserably failed to shine.

Memory model

Sorry, Marvin! operates on four registers that hold unbounded unsigned integers, all initially set to zero.

A program starts with the first register as the current default.

Instructions

Sorry, Marvin! features two compound instructions, MVINC and DECJZDEC, move and increment and decrement; jump if zero, decrement otherwise:

Instruction Code Meaning
MVINC ! Move to the next register and increment its value
DECJZDEC >×n Decrement; if n > 1 then if the current register is zero, jump n instructions forward, decrement otherwise

A program in Sorry, Marvin! is a cyclic, ordered list of instructions. When n of DECJZDEC exceeds the program length, the program counter wraps around to the beginning and jumps forward by the remainder of the division by n. Using this feature, backward jumps can be simulated via DECJZDEC.

The registers are also indexed in a cyclic list, meaning that performing MVINC with the (last) fourth register as the cursor will move back to the first register.

Examples

(Newlines are added arbitrarily.)

No-op

Moving to the next register and decrementing subsequently four times has no tangible effect:

!>!>!>!>

Infinite loop

Jumps are cyclic:

>>

Addition

Adds the value of the second register to the first register:

!>!>!>!>!>>>>>>>>>>>>!>!>!!>!>!>>>>>>>>>!>

Fibonacci sequence

!>!>!>!>!>>>>>>!!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>!>!>!>!>!>!>!>!
>>>>>>>>>>>>>!!>!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>!>!>!>!>!>!>>>>>>>>>!>
!!!>!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>!>>>>>>

Hello World

For computing "Hello World" the numbers in the registers must be interpreted as letters. It can achieved by defining a simple alphabet:

Letter Value
1
d 2
e 3
H 4
l 5
o 6
r 7
W 8

The following program sets the first register progressively to 4, 3, 5, 5, 6, 1, 8, 6, 7, 5, 2 which corresponds to "Hello World":

!>!>!>!!>!>!>!!>!>!>!!>!>!>!!>!>!>!>>>>>>>!>!>!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
!>!>!>!!>!>!>!!>!>!>!!>!>!>!>>>>>>>!>!>!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>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>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>!>

Simulating a Minsky machine

Simulating INC and JZDEC using MVINC and DECJZDEC is relatively straightforward.

INC

To increment a register n (where n=0..3), we first need to move to the preceding register. This can be accomplished by using the nondestructive subroutine !> repeated (4+n-1-c)%4 times, where c is the current register index:

Example: Increment the third register (n=2):

!>!>!

JZDEC

To counteract the initial decrement in DECJZDEC, an additional increment must be performed beforehand. Once again, the subroutine !> can be used to navigate between registers:

Example: Set the second register to 1 if the first register is not 0:

!>!>!>!>>!!>

External resources