DE version is available. Content is displayed in original English for accuracy.
Advertisement
Advertisement
⚡ Community Insights
Discussion Sentiment
60% Positive
Analyzed from 599 words in the discussion.
Trending Topics
#stack#local#wasm#instructions#more#format#expression#seems#dup#java

Discussion (12 Comments)Read Original on HackerNews
The way I see it, the difference between register and stack vms is all about the instruction encoding. Register VMs have fatter instructions in exchange for needing fewer LOAD and STORE operations. Despite the name, register VMs also have a stack.
Out of curiosity what do you think about this - in spite of the name, stack machines also have yet another stack. Ok I don't like that wording, but locals are basically the stack frames people know of from their computer arch class I think.
It doesn't change the fact that Wasm operations have to have the execution stack as one or more of the operands. Seems like a stack machines to me too, though I don't know more details on why the specific design of Wasm would make optimizing compilers harder to write than JVM as the article suggests (I think?).
> In textual Wasm, for example, they are instead represented in a LISP-like notation – not any less or more efficient
The Text format, at least when it comes to instructions, it 1 to 1 with the binary format. The LISP-like syntax is mainly just syntax sugar[1].
So (in theory, as far as I understand it) you can just do `(local.get 2 local.get 0 local.get 1)` to mean `local.get 0 local.get 1 local.get 2`, and it works for (almost) any instruction.Unfortunately, in my limited testing, tools like `wat2wasm` and Binaryen's `wasm-as` don't seem to adhere to (my perhaps faulty understanding of) the spec, and demand all instructions in a folded block be folded and have the "correct" amount of arguments, which makes Binaryen do weird things like
when this is perfectly valid tl;dr: the LISP syntax is just syntax sugar. The textual format is as "stack-like" as the binary format.[1]: https://webassembly.github.io/spec/core/text/instructions.ht...
Very well articulated and concise critique by somebody who seems to have a great amount of knowledge and experience with the topics.
I've used it to translate SQLite (with a few extensions) and, that I know of, it's been used (to varying degrees of success) to translate the MARISA trie library (C++), libghostty (Zig), zlib, Perl, and QuickJS.
More on-topic, I use a mix of an unevaluated expression stack and a stack-to-locals approach to translate Wasm.
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