An optimizing brainfuck interpreter in js

Juhani Krekelä 9dddb09972 Bump the version since we changed ircbot.js and want to distribute the changes to our users 11 months ago
.gitignore 2cbc9be4e3 First commit 1 year ago
.npmignore ccc320522a Prepare for publishing to npm registry 1 year ago
README.md 5efd241ef9 Fix typo in the example program 1 year ago
UNLICENSE 2cbc9be4e3 First commit 1 year ago
api.md 316e839804 Document the API 1 year ago
architecture.md 2cde47e42b Document the architecture of Gir 1 year ago
brainfuck.md d74b6ab594 Support all the types of EOF 1 year ago
gir.html 21832b0bb5 Move Gir to use modules 1 year ago
gir.js 21832b0bb5 Move Gir to use modules 1 year ago
ir.md 00eb264cb4 Document writeInt, readInt, breakPoint 1 year ago
ircbot.js e5138ff737 Also replace DEL with its graphical equivalent 11 months ago
optimizations.md e75a0a085d Update documentation 1 year ago
package.json 9dddb09972 Bump the version since we changed ircbot.js and want to distribute the changes to our users 11 months ago

README.md

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?