Basicfuck

Basicfuck is an esoteric programming language by User:Rdococ. Contrary to what its name might suggest, it is not a brainfuck derivative - rather, it is designed to be compiled into brainfuck fairly easily while hiding as many temporary variables from the program as possible.

Directives
Basicfuck programs have directives, which in this case dictate the size of the tape, and the maximum and minimum values on each cell of that tape. These settings affect the requirements of interpreting the resulting brainfuck program, rather than the compiler itself. Directives should be of the form, but   may be set to unbounded, and   may omit one or both ends of the cell value range to indicate an unbounded range. If  is unbounded in both directions, then   should be omitted.

may be one of the following words:

Below the main directive should be an  statement, followed by a comma-separated list of the variables to allocate to cells. Variables can either be of the form, which allocates one cell for   to point to, or  , which allocates   cells, the first of which   points to. As an example:


 * 1) basicfuck t=unbounded r=0~ o=nearest
 * 2) allocate a, b, x, y, arr->3, z

y += 23; arr->2 += y;

The above code would increment the fourth cell 23 times, and then increments the seventh (5 + 2) cell (  is 5,   is 7) by the value of the fourth cell. In this case,  refers to the eighth cell, as does.

Instructions
All instructions, excluding instructions that end with a closed bracket (for example, the while loop), must end with a semicolon, excluding the directives mentioned above.

Compilation
Compilation of code in basicfuck would take a few steps.


 * 1) Allocation is to be performed in the order of variable names in the   directive.
 * 2) All instances of incrementation/decrementation by the value of another cell, rather than a fixed constant, would be treated as code that allocates temporary variables to perform the inc/dec without the use of the aforementioned instances.
 * 3) While loops are to begin by firstly moving to the cell of the variable specified, and then returning to the aforementioned cell at the end of - but inside - the loop. As a result of this, the compiler can easily keep track the current cell pointer's position.

Assignment
Basicfuck does not have variable assignment, mainly because it can be replicated by subtracting a variable's value from itself.
 * 1) basicfuck t=unbounded r=0~ o=nearest
 * 2) allocate v

v += 21; // Say v was allocated, and at 21.

v -= v; // This sets v to 0. v += 3; // Then we can add 3.

Multiplication
This calculates the multiplication of two non-negative numbers. In brainfuck, this would require several temporary cells, but only one is required in basicfuck to avoid destroying the original arguments.
 * 1) basicfuck t=unbounded r=0~ o=nearest
 * 2) allocate x, y, y2, result

x += 8; // These are the numbers to multiply. y += 3;

y2 += y;

while (y2) { result += x;   y2 -= 1; }

Cat
This cat supports EOF=0, -1 (which wraps to 255), and no change.
 * 1) basicfuck t=unbounded r=0~255 o=wrap
 * 2) allocate char, eof255

read -> char; while (char) { write <- char; char -= char; // This line is to support EOF = no change. read -> char;

// These support EOF = -1 = 255. eof255 -= eof255; // First, we clear 'eof255'. eof255 += char; // Then we increment 'eof255' by the value of 'char'. eof255 += 1; // Finally, we add one so that a value of 255 wraps over to 0. if !(eof255) { char -= char; // If eof255 is zero, then we set char to 0 to effectively break out of the loop. } }