A Brainfuck to WebAssembly compiler and playground
1–10 of 20 posts
Re: A Brainfuck to WebAssembly compiler and playground
#2Re: A Brainfuck to WebAssembly compiler and playground
#3Re: A Brainfuck to WebAssembly compiler and playground
#4My first attempt was to put Jon Ripley's Lost Kingdom [1] to the input and it obviously didn't work (or took too much time, I don't know). At the very least there is an asm.js version that does work out of the box [2]. [1] http://jonripley.com/i-fiction/games/LostKingdomBF.html [2] https://github.com/rdebath/LostKingdom
Re: A Brainfuck to WebAssembly compiler and playground
#5I'm excited to hear about how you intend to solve input instructions. I've been struggling with that myself since I want to make it asynchronous, which might require some nasty tricks.
Re: A Brainfuck to WebAssembly compiler and playground
#6My first attempt was to put Jon Ripley's Lost Kingdom [1] to the input and it obviously didn't work (or took too much time, I don't know). At the very least there is an asm.js version that does work out of the box [2]. [1] http://jonripley.com/i-fiction/games/LostKingdomBF.html [2] https://github.com/rdebath/LostKingdom
Looks like the default Lost Kingdom BF interpreter uses 8-bit cells, whereas the bf2wasm compiler uses 32-bit cells. This matters in Brainfuck; choosing the "wrong" one of the idioms [-] and [+] for zeroing a cell gets worse as cells get bigger. Maybe if you tweaked the bf2wasm compiler to use 8-bit cells?
Re: A Brainfuck to WebAssembly compiler and playground
#7Earlier quoted context omitted.
Looks like the default Lost Kingdom BF interpreter uses 8-bit cells, whereas the bf2wasm compiler uses 32-bit cells. This matters in Brainfuck; choosing the "wrong" one of the idioms [-] and [+] for zeroing a cell gets worse as cells get bigger. Maybe if you tweaked the bf2wasm compiler to use 8-bit cells?
Moreover, the Lost Kingdom interpreter will expand the memory arbitrarily as it encounters > instructions, whereas the bf2wasm interpreter has a fixed limit of 16384 4-byte cells according to its documentation.
[1] https://esolangs.org/wiki/Brainfuck_bitwidth_conversions
Re: A Brainfuck to WebAssembly compiler and playground
#8My first attempt was to put Jon Ripley's Lost Kingdom [1] to the input and it obviously didn't work (or took too much time, I don't know). At the very least there is an asm.js version that does work out of the box [2]. [1] http://jonripley.com/i-fiction/games/LostKingdomBF.html [2] https://github.com/rdebath/LostKingdom
Looks like the default Lost Kingdom BF interpreter uses 8-bit cells, whereas the bf2wasm compiler uses 32-bit cells. This matters in Brainfuck; choosing the "wrong" one of the idioms [-] and [+] for zeroing a cell gets worse as cells get bigger. Maybe if you tweaked the bf2wasm compiler to use 8-bit cells?
Translating these idioms to "*data = 0" was one of the first peephole optimizations I implemented when writing my own optimizing brainfuck interpreter.
Re: A Brainfuck to WebAssembly compiler and playground
#9Honest question: why (is it beyond I was bored, so I did it because I could)?
Re: A Brainfuck to WebAssembly compiler and playground
#10I love it! I've been working on a brainfuck to asm.js compiler myself and it's a great learning experience, even if asm.js will be going away in favor of wasm (though I believe Chrome compiles asm.js into wasm). I'm excited to hear about how you intend to solve input instructions. I've been struggling with that myself since I want to make it asynchronous, which might require some nasty tricks.
I realized after coding that first version that most brainfuck programs run indefinitely. Apart from Hello World, I didn't find lots of program I could run synchronously. Making it asynchronous sounds like a tough job.