April 28, 2026

Stack smackdown: no “dup” in sight

WASM is not quite a stack machine

Wasm isn’t the stack machine you think — devs feud over missing “dup”

TLDR: An engineer says WebAssembly isn’t a classic stack machine because it lacks stack-manipulation tricks, igniting debate. Devs split between wanting a “dup” instruction for tighter code and saying “just use locals” like Java; others nitpick the text format—stakes matter for compilers and how fast, compact Wasm code can be.

A spicy new post claims WebAssembly (Wasm) isn’t really a classic “stack machine,” and the comment section immediately split into teams. Team Feature says this “not-quite-stack” vibe is actually great: stevefan1999, building a Wasm-to-C tool, gushes that expressions stay tidy inside each function, and the S‑expression text format (WAT) keeps things neat. Team Fix-It fires back: kg calls the missing “dup” instruction—used in other stack machines to quickly copy a value—“quite annoying” and wishes it made the spec. Translation for non-nerds: one side loves the orderliness, the other wants a tiny shortcut button that could make code smaller.

Then Team Shrug strolls in: ufo says even Java’s virtual machine has stack-copy tricks but most real code just uses local variables anyway. So, why panic? Meanwhile, Hendrikto hypes the author’s broader series as a must-read, while asibahi nitpicks that WAT’s LISP-y text is 1:1 with the binary format—cue the “actually…” crowd. The memes? “Team Dup vs Team Local,” “WebAssembly: stack-curious,” and a chorus of “Wikipedia betrayed me.” Drama level: medium-hot. The real takeaway: whether Wasm is “stacky” enough turns out to be more than semantics—it affects how compact, fast, and clean your code (and compilers) can be. And the community is absolutely here for the bickering.

Key Points

  • The author argues the common classification of Wasm as a stack machine is misleading based on hands-on instruction writing.
  • Register machines encode indices explicitly and store intermediates in registers; stack machines use implicit ordering on a value stack.
  • Real stack languages rely on stack-manipulation instructions like dup and swap to enable value reuse and control evaluation order.
  • An example (computing x*x*x) shows how stack machines use dup/swap, contrasting with register-machine temporaries.
  • The article proposes that stack machines decouple operations from indices, trading higher instruction counts for reduced index encoding, akin to entropy-encoded compression.

Hottest takes

“lack of a dup opcode … quite annoying” — kg
“Everything stays within that function, which is very neat” — stevefan1999
“reuse happens via local variables” — ufo
Made with <3 by @siedrix and @shesho from CDMX. Powered by Forge&Hive.