esolang

Revaver2pi

Every command undoes itself, so a program read from the bottom up undoes the program.

Zzo38, 2006 · Turing complete: unknown · ●●● hard · esolangs.org

Tested with 6 known programs · Test method

Run it

Expected: 0[4,2]!4

The idea

Zzo38 made Revaver2pi in 2006 as a variant of Revaver. A program is a function from states to states. The input is the starting state, written as an accumulator and some stacks, and the output is the state at the end. Every command is its own inverse, so the program read upside down computes the inverse function. The specification says that, leaving out the commands that print, the programs probably form a group.

Read the story

To keep every step undoable, a stack may never hold a number right above the same number, and under each stack lies a 0. So PP n pushes n, unless n is already on top; then it pops it. Doing it twice gets you back. A command that would break the rule does nothing.

The machine

CommandDoes
PP nPush n on the main stack, or pop it if n is on top
SWAMSwap the accumulator with the top of the main stack
SWMS nSwap the main stack with stack n
XOR n SUB nTop becomes top xor n, or n minus top
IODE IEDOAccumulator steps up if odd and down if even, or the other way
NEG CMS SUBSAccumulator becomes -acc, depth minus acc, or top minus acc
TTG nSwitch teleport group n off or on again
TEL n mGo on after the next TEL whose n has the same value

TEL searches forward and wraps round, so it finds itself last. A TEL whose group m is switched off does nothing, and searches pass over it. Expressions are numbers, # for the accumulator, and forms with ' like '#=0, which compares the accumulator with 0 and gives -1, 0 or 1. A state is written like 5[1,0,2][3=4,-1]!-4, which means accumulator 5, main stack 1 0 2, stack 3 holding 4 -1, and group -4 switched off.

Example

The countdown.

The countdown. On an even number it pushes it and every even number below it down to 2. TTG # switches off the group named by the start value, so the first TEL is skipped once and then jumped to.

The loop program leaves a positive number alone, adds 2 to an even negative number and takes 2 from an odd one. On 0 it would never stop.

Expected: -4

The program that reverses the main stack, using stack 0 as a spare.

Expected: 0[3,2,1]

!TEST, which the specification says gets program code from input, is not built.

Patterns it teaches

Further

Reversible computing

Stack-based

Write your own in Run Convert a program from Revaver2pi

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run revaver2pi -e '/ Program to reverse the order of the stack.
/ Please initialize the accumulator to 0.
TTG 0
CMS
TTG #
TEL # #
CMS
SUBS
PP #
SWMS 0
PP #
SUBS
SWMS 0
CMS
TEL # #
SWMS 0
CMS
TTG #
CMS
TTG 0' --input '0[1,2,3]'
shib manual revaver2pi

Source

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

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

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