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.