A compiler that converts Brainfuck code to WebAssembly (WASM), allowing you to run Brainfuck programs in the browser or on any platform that supports WASM.
This project is just a gimmick to learn more about Rust and WebAssembly
- Compile Brainfuck code to Webassembly
- Install using Cargo:
cargo install bf2wasm
- Compile a Brainfuck program to WASM:
bf2wasm input.bf output.wasm
- Run the compiled WASM program in a browser or any platform that supports WebAssembly, such as Node.js.
- Clone this repository to get started with the project code:
git clone https://github.com/AdamStrojek/bf2wasm.git
- Install the required dependencies using Cargo, Rust's package manager:
cargo build --release
- Run the compiler on your Brainfuck code using the provided CLI tool:
cargo run brainfuck_code.bf
Work in progress, keep in mind that all what is presented here may change at any time
Compiled WASM modules revolve around a few core concepts, what allows to provide coherent expiriance
- Import Object - you need to provide import object to module that will contain whole environment for execution
{
"env": {
"memory": WebAssembly.Memory, // Memory object that is used to store data
"putch": function(i32) -> void, // Function that prints a character at given index in memory
"getch": function() -> i32, // Function that reads a character from input and returns it's index in memory
}
}
- Ready to use script is attached to repository
runner.js
- Provide WASM module as parameter
- Run the script:
node runner.js brainfuck_code.wasm
- The output will be printed on console
- Ready to use script is attached to repository
web-runner.js
andindex.html
- Start any webserver:
python3 -m http.server 8080
- Open browser and navigate to http://localhost:8080/
- Provide WASM module as parameter in input field and click Start button
- TODO - need to provide import objects
[ ] Add support for getch
[ ] Import only required functions from environment
[ ] Automated tests based on provided examples
[ ] Zero memory before each execution (who should be responsible for that?)