esolang

Hanoi Love

Four stacks, one byte of register, eight symbols. Loops happen by pushing the program counter onto a stack.

Jeffry Johnston, 2001 · Turing complete: yes · ●●○ moderate · esolangs.org

Tested with 2 known programs · Test method

Run it

Expected: Hanoi!

The idea

Jeffry Johnston made Hanoi Love in April 2001. The name comes from the Towers of Hanoi puzzle, where you move discs between pegs. In Hanoi Love you move bytes between stacks, one at a time, through a single register.

Read the story

Stacks A, B and C hold bytes. Stack A has a trick: when it is empty it pops a 1, so it doubles as a supply of ones. That is how you count: pop a 1 from A, add it to a byte from B, push it back.

The fourth stack, D, holds code locations instead of bytes. Pushing onto D saves "where am I", and popping from D jumps back there. That is the only way to loop. The specification shows a table that turns any brainfuck program into Hanoi Love, which settles Turing completeness.

The machine

Stacks A, B, C (bytes), stack D (locations), an 8-bit register starting at 0. A "current stack" starts at A.

CharDoes
.Select the next stack: A, B, C, D, then A again
'Push the register (on D: push the current location minus one)
,Pop into the register (on D: pop a location and jump there)
;Pop and add to the register (on D: pop and forget)
` | Pop and subtract from the register (on D: pop and forget)
"The next command uses input or output instead of the stack
:If the register is 0, skip forward to the matching !
!Ends a skip; reached normally, it halts

Empty A pops 1, empty B and C pop 0. All other characters are comments. In this implementation end of input reads as 255, which is -1 as a byte.

Example

This is the cat program from the specification.

This is the cat program from the specification. ...' moves to D and saves the loop start. .,' moves to A, pops a 1 (A is empty) and pushes it back. "; adds an input byte, so the register is the byte plus 1. At end of input that is 255 + 1, which wraps to 0, and : skips to !. Otherwise ` takes the 1 away again, "' prints the byte, and ..., jumps back through D.

Patterns it teaches

Try this

  1. Print the letter A (65) by popping ones from A and adding them up.
  2. Change the cat so it prints every byte twice.
  3. Hard: translate the brainfuck program ,+. by hand with the specification's table and run it.

Further

Stack-based

Write your own in Run Convert a program from Hanoi Love

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: hanoi-love.

Command line

shib run hanoi-love -e '...'\''.,'\''";:`"'\''...,!' --input 'Hanoi!'
shib manual hanoi-love

Source

Module
langs/stack/ports.js
Interpreter
langs/stack/hanoi-love.js

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

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