Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/surma/bfwasm
A non-optimizing Brainf_ck to WebAssembly compiler
https://github.com/surma/bfwasm
Last synced: 16 days ago
JSON representation
A non-optimizing Brainf_ck to WebAssembly compiler
- Host: GitHub
- URL: https://github.com/surma/bfwasm
- Owner: surma
- License: apache-2.0
- Created: 2019-08-30T14:37:47.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2019-10-04T00:18:11.000Z (about 5 years ago)
- Last Synced: 2024-10-14T12:47:51.624Z (about 1 month ago)
- Language: JavaScript
- Homepage: https://npm.im/@surma/bfwasm
- Size: 77.1 KB
- Stars: 25
- Watchers: 3
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING
- License: LICENSE
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
# bfwasm
A non-optimizing [Brainf_ck][bf] to WebAssembly compiler. Yes, compiler. Not interpreter.
## Installation
```
npm install -g @surma/bfwasm
```## Usage (CLI)
```
Usage: bfwasm [options]Options:
-o, --output File to write compiled Wasm to
-r, --run Run compiled Wasm (implies --asyncify)
--mem-dump 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)
```js
import { compile } from "@surma/bfwasm";const wasmBuffer = compile(`
++++++++++[>++++++++++++++++++++++
>+++++++++++++++>++++++++++++++++>+
<<<<-]>++++++.>+++++++.>++++.
`);const decoder = new TextDecoder();
const importsObj = {
env: {
in() {
/* Called when bf programm needs input */
return 0;
},
out(v) {
/* Called when bf programm has output */
console.log(
decoder.decode(new Uint8Array([v]), {stream: true})
);
}
}
};
const {instance} = await WebAssembly.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.
- `useWasi` (default: `false`) use [WASI core] for I/O.---
License Apache-2.0
[bf]: http://www.muppetlabs.com/~breadbox/bf/
[wasi core]: https://github.com/CraneStation/wasmtime/blob/master/docs/WASI-api.md