Jolverine

From Esolang
Jump to: navigation, search

Jolverine is an esoteric programming language designed by Chris Pressey between September 10 and 11, 2012. It was devised as a conscious attempt to expand the genre of turning tarpit by adding the feature of modifying the instruction wheel during execution. It is not dissimilar to Wunnel, and was influenced slightly by Half-Broken Car in Heavy Traffic.

Etymology[edit]

The name is a portmanteau of "jolly wolverine" (where "jolly" is a euphemism for "drunk",) which is an attempt to capture, in a noun phrase, the language's vicious, erratic nature.

Program Structure[edit]

A Jolverine program consists of a two-dimensional grid of symbols. An instruction pointer (IP) traverses the grid, starting in the upper-left corner (x=0, y=0) travelling right (dx=1, dy=0). dx and dy have only three possible values, -1, 0, and 1, like values on the tape (see below.)

Execution[edit]

On each tick, if the symbol under the IP is a *, the current instruction on the instruction wheel is executed. The instruction wheel is then advanced to the next instruction, regardless of what the symbol is under the IP. (All symbols that are not * have the same meaning, that is to say, no meaning besides taking up space.) The IP is then advanced to the next position in the playfield, and the next tick begins. Execution halts when the IP travels beyond the extent of the playfield (i.e. when it can be proved that, in its direction of travel, it will never again hit a *.)

Storage[edit]

There is an unbounded tape, with a single head which can be moved left and right. Each cell on the tape may contain one of the three values -1, 0, or 1. Addition is defined on these values as follows:

  • x + 0 = 0 + x = x
  • 1 + -1 = -1 + 1 = 0
  • 1 + 1 = -1
  • -1 + -1 = 1

In other words, it is addition per usual, but it "wraps around" if the value ever exceeds the range -1..1. As usual, to increment such a value means to add 1 to it.

Initially, all tape cells contain 0.

Instruction Wheel[edit]

The instruction wheel contains seven instructions. Initially, the wheel looks like this:

left <--
right
rot
adddx
adddy
input
output

The arrow indicates the current instruction on the wheel. Each time the wheel is advanced, the arrow moves down one row, wrapping around back to the top once it advances past the bottom of the wheel.

Each time an instruction is executed from the wheel, it is removed from the wheel and re-inserted at a different position. The first time this happens, it is re-inserted at the top of the wheel; the second time, it is re-inserted at the bottom; the third time, at the top again; the fourth time, at the bottom again; and so forth.

So, for example, if the program starts with the wheel as it is above, and the IP passes over a space character, the wheel then looks like:

left
right <--
rot
adddx
adddy
input
output

If the IP then passes over a star, right is executed, removed from the wheel, and re-inserted at the top of the wheel -- and the wheel advances, so now it looks like:

right
left
rot <--
adddx
adddy
input
output

If the IP then passes over another star, rot is executed, removed from the wheel, and re-inserted at the bottom:

right
left
adddx
adddy <--
input
output
rot

And so forth.

Instructions[edit]

  • left: moves the tape head left one tape cell.
  • right: moves the tape head right one tape cell.
  • rot: increments the current tape cell.
  • adddx: adds the contents of the current tape cell to the IP's dx.
  • adddy: adds the contents of the current tape cell to the IP's dy.
  • input: inputs a single bit (I/O is bitwise, and implementation-defined.)
  • output: if the current tape cell is 0, output a 0; if the current tape cell is 1, output a 1; otherwise RESERVED for future expansion.

Notes[edit]

It is entirely possible for * to execute adddx or adddy with the result of both dx and dy being zero. In this case, execution does not halt, but the same * will be executed again, and again, until dx or dy changes.

Example programs[edit]

This program inputs a single bit, outputs the opposite bit, and halts. (Hyphens and slashes are entirely for aesthetics -- all non-* symbols have the same meaning.)

--*-*
     \
      \
       \           *
        \         /
         \       /
          \     /
           *   /
            \ /
             *-*---*

Here is a Truth-machine. The actual 1-printing loop part is rather simple; the trickiest part was finding a way to set up the wheel in a stable state for the loop. (Although the fact that the simple loop fits together so well may be considered an accident.)

.*.....*......*......*......*......*.....*...*...*......*.....*..*......*....
                                                                  .      
                                                                   .
                                                                    .
                                                                     .
                                                                      * 
                                                                       .
                                                                        .
                                                                         .
                                                                          .
                                                                           .
                                                                            .
                                                                             * 
                                                                              .
                                                                               .
                                                                                .
                                                                                 .
                                                                                  .
                                                                                   .
                                                                                    * 
                                                                                     .
                                                                                      .
                                                                                       .
                                                                                        .
                                                                                         .
                                                                                          .
                                                                                           .
                                                                                            .
                                                                                             .
                                                                                              .
                                                                                               .
                                                                                                * 
                                                                                               . .
                                                                                              .   .
                                                                                             .     .
                                                                                            *       * 
                                                                                             .       .
                                                                                              .       .
                                                                                               *       * 
                                                                                                .       .
                                                                                                 .       .
                                                                                                  *       * 
                                                                                                   .     .
                                                                                                    .   .
                                                                                                     . .
                                                                                                      *

Programming Techniques[edit]

  • You can always add seven non-stars between a star and the next star to be executed without changing the semantics of the second star. (The wheel just does a full rotation, ending up where it was originally.)
  • If you execute the instruction at the top of the wheel, and it is an odd-numbered execution step (e.g. the first instruction executed in the program, or the third, etc.), the position of that instruction on the wheel will not change (it will be removed, but then re-inserted exactly where it was.) The same goes for executing the instruction at the bottom of the wheel on an even-numbered execution step.

Computational Class[edit]

Jolverine is Turing complete, as one may construct a reduction from ternary Reversible Brainfuck.

External resources[edit]