An optimizing brainfuck interpreter in js
.gitignore | ||
.npmignore | ||
api.md | ||
architecture.md | ||
brainfuck.md | ||
gir.html | ||
gir.js | ||
ir.md | ||
ircbot.js | ||
optimizations.md | ||
package.json | ||
README.md | ||
UNLICENSE |
Gir is an optimizing brainfuck interpreter in Javascript.
Name
𒌋𒀜 gir (Sumerian) - n. kiln
License
Everything in the repo is under Unlicense / CC0.
Status
Gir can parse, prettyprint, and run programs in brainfuck. Gir supports following optimizations:
- Turn runs of +- or <> into one command
- Turn [-] or [+] into one command
- Add offsets to commands that modify tape, to reduce moving tape head
- Turn multiply loops into one command
Examples
ircbot.js
is an implementation of an IRC bot's brainfuck interpreter
function. Smaller examples for every function are available in api.md
const gir = require('bf-gir');
let compiled = gir.compile(',[+.,]');
let input = gir.encodeUTF8('Foobar');
let vm = gir.newVM(compiled, input);
let result = gir.runVM(vm, 1000);
if(result.complete) {
console.log(gir.decodeUTF8(result.state.output));
} else {
console.log('Bf program terminated abnormally');
}
Installing
Gir is available at npm registry under the name bf-gir.
TODO
gir.html
- Implement a UI
General
- Move stuff into subdirectories?