Swapfuck

From Esolang
Jump to: navigation, search

Swapfuck is a derivative of brainfuck by User:Rdococ, which shares some similarities with boolfuck.

Differences from brainfuck

  • Input is loaded into the tape at the beginning of execution, as opposed to having an instruction to retrieve for an input character.
  • Cells are single bits - they can only hold two values, a 0 or a 1.
  • Rather than having an instruction to toggle the current cell value, the language offers a 'swap' instruction which is described with more detail below.
  • A register - named the 'SWAP register' - is used to store a pointer to the cell to be swapped.
  • An output queue is used to store the current number of output bits until it reaches a size of 8 bits, and then the contents of the queue are emptied and printed as a single character.

Instruction set

Instruction Description
@ If the SWAP register is currently empty, set it to point to the current cell. Otherwise, swap the values of the cell pointed to by the register, and the current cell, and then clear the register.
< Move the cell pointer to the left.
> Move the cell pointer to the right.
[ Jump past the matching ] if the current cell has a value of 0.
] Jump back to the matching [ if the current cell has a non-zero value.
. Adds the bit at the current cell to the output queue. When the output queue reaches a size of 8, it is emptied and the bits are printed as a single UTF-8/ASCII character code.

Computational class

Swapfuck allows you to swap any two cell values, but it doesn't allow you to create or modify cell values directly. This means that the amount of available non-zero cells is bounded by the contents of the initial tape, which holds the input. This is characteristic of a Linear bounded automaton, in which the size of the tape is bounded by the size of the input.

Speculation

The tape could be divided up into three repeating sections of N cells each. Each of the three sections represents N available values for three simulated registers. To check the value of a register, you would go to the start of the first, second or third section, and then scan for a non-zero value, skipping 2N values every N values.