2018-05-21 20:55:48 +00:00
|
|
|
Gir is an optimizing brainfuck interpreter in Javascript.
|
|
|
|
|
|
|
|
Name
|
|
|
|
----
|
|
|
|
𒌋𒀜 gir (Sumerian) - n. kiln
|
|
|
|
|
|
|
|
License
|
|
|
|
-------
|
|
|
|
Everything in the repo is under Unlicense / CC0.
|
2018-05-21 20:58:06 +00:00
|
|
|
|
|
|
|
Status
|
|
|
|
------
|
2018-05-24 08:20:33 +00:00
|
|
|
Gir can parse, prettyprint, and run programs in brainfuck.
|
2018-05-21 21:18:05 +00:00
|
|
|
Gir supports following optimizations:
|
|
|
|
|
2018-05-22 11:22:21 +00:00
|
|
|
* Turn runs of +- or <> into one command
|
2018-05-22 11:26:40 +00:00
|
|
|
* Turn [-] or [+] into one command
|
2018-05-22 12:08:23 +00:00
|
|
|
* Add offsets to commands that modify tape, to reduce moving tape head
|
2018-05-25 20:21:29 +00:00
|
|
|
* Turn multiply loops into one command
|
2018-05-23 21:17:30 +00:00
|
|
|
|
2018-05-27 20:54:59 +00:00
|
|
|
Examples
|
|
|
|
--------
|
|
|
|
`ircbot.js` is an implementation of an IRC bot's brainfuck interpreter
|
2018-05-29 17:15:09 +00:00
|
|
|
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);
|
|
|
|
|
2018-05-29 17:17:42 +00:00
|
|
|
if(result.complete) {
|
2018-05-29 17:15:09 +00:00
|
|
|
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.
|
2018-05-27 20:54:59 +00:00
|
|
|
|
2018-05-23 21:17:30 +00:00
|
|
|
TODO
|
|
|
|
----
|
2018-05-23 21:19:47 +00:00
|
|
|
### gir.html
|
|
|
|
* Implement a UI
|
|
|
|
|
|
|
|
### General
|
2018-05-29 17:01:34 +00:00
|
|
|
* Move stuff into subdirectories?
|