Brainfuck Improved
BFM is a JS based language that makes brainfuck development easier
Additionally this CLI features a brainfuck runtime and a brainfuck2c compiler
strprint('Hello World!\n', 0) // write string to memory and print it
set(0, 10) // set register 0 (aka "counter") to 10
str('Count: 9\n', 1) // write string to memory from reg 1 to reg 9 (1 + 8)
whileFnc(0, () => { // loop until reg 0 is set to 0
print(1, 9) // print reg 1 to reg 9 as ascii string
mod(8, -1) // decrement ASCII value of the number in the string
mod(0, -1) // decrement "counter" by 1
})
/*
Prints:
Hello World!
Count: 9
Count: 8
Count: 7
Count: 6
Count: 5
Count: 4
Count: 3
Count: 2
Count: 1
Count: 0
*/
$ npm i -g bf-improved # install the CLI
$ bfm bfm example.bfm example.bf # compile BrainFuck Improved to Brainfuck
$ bfm bf example.bf # execute Brainfuck
$ bfm bftoc example.bf example.c # generate C code from BrainFuck
$ gcc example.c -o example # generate Executable
$ ./example # launch
Generates bf code to move from cur reg to new reg. Throws if arg is not a valid number
Example:
goto(1); goto(20);
=>>>>>>>>>>>>>>>>>>>>>
Modifies the value of a reg
Example:
mod(20, 2);
=>goto(20); bf('++');
Clears a registers value
Alias:
clear(reg);
=>goto(reg); bf('[-]');
Sets value of reg to val
Alias:
clear(reg); mod(reg, val);
Brainfuck native loop. Calls goto before and after code.
Example:
mod(0, 1); set(1, 2); while(0, () => { clear(1) })
=>+>++<[>[-]<]
Sets all registers from reg
to reg + str.length
to the ASCII values of str
Example:
str('H', 20);
=>goto(20); set(20, 72);
Prints char at reg (.
)
Optionally prints len
next cells too
Example:
print(0, 3);
=>.>.>.>.
Writes string into memory then prints it
Example:
strprint('Hello', 20)
=>str('Hello', 20); print(20, 25);
Prints the ASCII value of the number stored at reg using storeReg. Note: There must be at least 10 free cells after storeReg to avoid corruption for big numbers