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.
  • Output still uses an instruction to print a bit, but every eight output bits are treated as little-endian order UTF-8 character codes.
  • 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.

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.