From Esolang
Jump to navigation Jump to search

Drainfuck is a modified version of Brainfuck, named for how it is draining on CPU power. Drainfuck uses three tapes, each cell being two bytes, 65536 cells per tape. One tape is the code tape, and the other two are the data tapes. Along side this is a pointer function, setting the pointer to the cell number given in the data at the current cell. Official interpreter download link is in External resources


The standard Brainfuck functions:

+ Increment the cell.
- Decrement the cell.
> Move the pointer right.
< Move the pointer left.
. Output the character.
, Input a character.
[ Jump to associated ] if zero.
] Jump to associated [ if not zero.

With some new(ish) functions:

X Swap the data tape in use.
Y Reserved. Possibly a fork.
L Record onto the inactive data tape with this one.
E End the program with code stored in the current cell.
0 Set this cell's data to zero.
@ Point to cell number stored here.
& Jump to n in the code, where n is the number stored in the cache.
* Reserved.
/ Reserved.
\ Reserved.
$ Set the cache mode id to this cell's contents. 5 and up are ignored.
^ Set the cache to the data stored here.
V Set this data to the data stored in the cache.
# Store this cell number in the cache.
% Point to the cell number stored in the cache.
{ Marker. Does nothing on its own.
} Jump to associated { if not zero.
( Jump to associated ) if zero.
) Marker. Does nothing on its own.
| Reserved. Possible return command?
! Reserved. Possible interrupt-like command?
~ Reserved. Possible bit-wise inversion.
_ Reserved? Possible hi-byte removal?
= Reserved. ???
End of File halts execution of the code, and returns 0.


Wait for the user to enter a character without altering the contents of the current cell. (Unfortunately, this disrupts the cache's value so it shouldn't be used while the cache is holding something needed later. Stack-compatible.)


Jump to the start of the program. (This resets the current cell and the cache to 0. Stack-compatible.)


Swap two bytes. (Assuming the cell after the destination and the cache can be tampered with, and that the source is directly behind the destination, and that you are pointed at the source. Stack-compatible.)


The same using the inactive tape's current cell rather than the cell after the destination.


The same using the cache while in stack mode.


Copy source onto destination. (Uses cache yet again, and assuming the destination is one to the right of the source. Stack-compatible.)


Increment the left, copy to the right, and repeat.


After this you will get 01234567 incrementing as far as the data tape goes (infinite loop).


Take user input until a newline, then echo it all back in brainfuck. Rinse and repeat.


And do the same in drainfuck. EOF is assumed as two characters, 0 followed by E, thus the end of the parsed file is always a 'return 0'.



No examples yet :\

Information Storage


The tape is a class within the interpreter that contains a series of unsigned shorts. Each tape has an individual position, so two tapes might have a different position that is currently being pointed to. Thus after the X command, the pointer will be wherever it was left off before the previous X.

The Code Tape

The interpreter does not stream the code directly out of the source files. It copies all command characters to the data tape. EOF is parsed as 0 followed by an E. All other characters are printed to the screen while parsing the file. The code is loaded onto a tape for reasons of expandability. It is intended that the code and inactive tapes may at one point be swapped via a command.

The Data Tape

This is the tape that stores the cells involved in data procedures < > + - . , [ ] { } ( ) ^ V # @.

The Inactive Tape

This tape actually does something, despite its name. The data and inactive tapes switch places when X is called.


As of V1.2, there are multiple modes for the cache.

0 - Classic Mode

This is the original behavior of the cache.
One value is used, and remains after downloaded (V) from. V1.0

1 - Stack Mode

This mode treats the cache as a stack. Information is pushed on the top, and popped back off.
The V in classic mode can be replaced with V^ in stack mode.
A single read pops the value off the stack. This INCLUDES the & jump command and % follow command. V1.2

2 - Queue Mode

This mode treats the cache as a queue. Much like stack mode, but information is pushed on top and popped off of the bottom. Not implemented yet.

3 - RandList Mode

A random element in the list is used when getting. This does NOT remove the element from the cache. Not implemented yet.

4 - RandDeck Mode

This works the same as RandList, but the element is removed from the cache. Not implemented yet.

External resources