logoalt Hacker News

Compiling Match Statements to Bytecode

20 pointsby ingvelast Wednesday at 8:53 PM4 commentsview on HN

Comments

i_don_t_knowtoday at 1:14 PM

Simon Peyton Jones's "The implementation of functional programming languages" has a chapter on the "Efficient compilation of pattern matching" (chapter 5 by Philip Wadler).

https://simon.peytonjones.org/assets/pdfs/slpj-book-1987-2up...

show 1 reply
discardable_dantoday at 6:31 PM

As someone who has implemented full match in several industrial languages: this isn’t really match; it doesn’t not handle unpacking. And that is by far the only interesting bit. This feature is more accurately called `cond` à la Scheme, and you can fully expand it away ahead of type checking. Looking at unpacking in the arms, even with Scheme’s truth-y values and `=>`, could be neat.

Optimizing well-known jumps is useful, as is branch reordering, but the tombstone flag is unnecessary; you can simply write down a list of all targeted / called blocks and perform dead block elimination more generally that way.

show 1 reply