WASM is not quite a stack machine
7 hours ago
- #programming languages
- #WebAssembly
- #stack machine
- Wasm is commonly described as a stack machine but differs from other stack-based languages.
- Traditional stack machines use operations like dup and swap to manipulate the stack, enabling value reuse and complex expressions.
- Wasm lacks these stack manipulation instructions, making it more akin to a register machine with compound expressions encoded in postfix notation.
- Wasm's design limits optimizations like common subexpression elimination without introducing variables.
- The postfix notation in binary Wasm is just an encoding choice, not an inherent stack machine feature.
- This distinction means experience with other stack-based VMs doesn't fully translate to Wasm.