Hacker News new | ask | show | jobs
by thesz 2361 days ago
One of Elbrus supercomputers was a stack machine that translated stack operations into out-of-order register operations, quite successfully. There was also a variant of Ada called El-76.

(see more about Pentkovsky for more interesting stories)

This means that you do not need to sacrifice speed for compactness.

Also, zero-operand ISA (stack machines are zero-operands) have what can be called normalizing property: if you have stack layout for inputs and outputs you have only one optimal way to achieve it. E.g., "( b a -- x) swap -" sequence won't be different in any place where you have to compute b-a (in the register's three operand typical RISC case there are 32^3 combinations). This means that if you can use something like [1] Sequitur algorithm to make code more compact than six bit per opcode.

[1] https://en.wikipedia.org/wiki/Sequitur_algorithm

This is, actually, what Forth programmers often do manually. And in untyped language, which will not complain about stack layout violations after refactoring.

But this does not mean that you cannot use, say, dependent types for Forth programs for better programming safety. And this does not mean that you can't benefit from single (or double) stacks or their alternatives. For example, Applicative class from Haskell's Prelude is good in expressing concatenative programs, just like ones in Forth, I think.