logoalt Hacker News

stevefan1999today at 7:45 AM2 repliesview on HN

I'm trying to implement a WASM to C compiler, and because of that not-quite-so-stack behavior, I can actually guarantee that it will always build an expression and I don't have to discard or reset stack value! Everything stays within that function, which is very neat, and I think it is one of the reason WAT, the textual format is so neat, that you can represent it with a S-Expression.


Replies

jedisct1today at 8:24 AM

Compiling WASM to C is a really good option: https://00f.net/2023/12/11/webassembly-compilation-to-c/

show 1 reply
bsdertoday at 8:43 AM

But how do you handle arguments or loop index variables? Your liveness is the entire function? You have to compile all the WASM chunks together in order to do any optimization? That seems ... problematic.

Edit: Yep. In article referenced from the original: http://troubles.md/posts/wasm-is-not-a-stack-machine/

Double edit: Some of this has already been fixed in WASM: https://github.com/WebAssembly/multi-value