You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A non-optimizing Brainf_ck to WebAssembly compiler. Yes, compiler. Not interpreter.
Installation
npm install -g @surma/bfwasm
Usage (CLI)
Usage: bfwasm [options]
Options:
-o, --output <file> File to write compiled Wasm to
-r, --run Run compiled Wasm (implies --asyncify)
--mem-dump <N> Dump the first N cells of memory after run
--hex-output Turn std out into hexadecimap
--asyncify Run Binaryen Asyncify pass
--wasi Use WASI for I/O
-h, --help output usage information
Usage (API)
import{compile}from"@surma/bfwasm";constwasmBuffer=compile(` ++++++++++[>++++++++++++++++++++++ >+++++++++++++++>++++++++++++++++>+ <<<<-]>++++++.>+++++++.>++++.`);constdecoder=newTextDecoder();constimportsObj={env: {in(){/* Called when bf programm needs input */return0;},out(v){/* Called when bf programm has output */console.log(decoder.decode(newUint8Array([v]),{stream: true}));}}};const{instance}=awaitWebAssembly.instantiate(wasmBuffer,importsObj);instance.exports._start();
compile(program, options) compiles program to a WebAssembly module exporting a "_start" function.
Options:
exportMemory (default: true) will export the memory as "memory".
autoRun (default: false) will declare "_start" as the module’s start function.