picobrain
Perhaps the smallest Javascript brainfuck interpreter
picobrain
is a 250-byte Javascript brainfuck interpreter.
Usage
The library exports a generator function which yields on output.
var bf = ; // Yields "!"
You can also provide your own tape.
// Here, we specify that we want the interpreter to use a new `Uint8Array` as// the tape. This will set the tape size to 20 and cause cell values to wrap on// overflow/underflow.// If no tape is provided, the interpreter will just use a new empty unbounded// number array.var tape = 20;;
For the input command to work (,
), you must provide a function which is to be
invoked on input:
{ return windowprompt;} ;
Why
Why not?
This library is also an open codegolf challenge. Please feel free to submit pull requests if you're able to make the code even shorter, or fork the project and make your own API!
Install, Build & Test
To install the package, use the standard NPM install command:
npm install picobrain
The package is hand-written, minified Javascript; therefore, no build process is required, and you can directly edit and execute the source!
An NPM script has been created for simplicity when running tests, which can be run from the command line as shown below:
npm test
picobrain uses the Tape library for testing.
Content Delivery Network (CDN)
The picobrain library can be imported via unpkg as shown below:
Be aware that picobrain is a CommonJS module and therefore uses
module.exports
; before importing the script, you will need to define module
or use a CommonJS-compatible module loader.
License
Please see the LICENSE
file for license information.