Introduction Pattern matching is a very powerful and useful device in programming. In functional languages it emerged in SASL [Turn76] and Hope [BursS0], and has also found its way into SML [Miln84]. The pattern mathing described here is that of LML which is a lazy ([Frie76] and [Henri76]) variant of ML. The pattern matching in LML evolved independently of that in SML so they are not (yet) the same, although very similar. The compilation of pattern matching in SML has been addressed in [Card84]. The LML compiler project began as an attempt to produce efficient code for a typed functional language with lazy evaluation. Since we regard pattern matching as an important language feature it should also yield efficient code. Only pattern matching in case expressions is described here, since we regard this as the basic pattern matching facility in the language. All other types of pattern mathing used in LML can be easily translated into case expressions, see [Augu84] for details. The compilation (of pattern matching) proceeds in several steps: • transform all pattern matching to case expressions. • transform complex case expressions into expressions that are easy to generate code for. • generate G-code for the case expressions, and from that machine code for the target machine.
[1]
Luca Cardelli,et al.
Compiling a functional language
,
1984,
LFP '84.
[2]
Peter Henderson,et al.
A lazy evaluator
,
1976,
POPL.
[3]
Rod M. Burstall,et al.
HOPE: An experimental applicative language
,
1980,
LISP Conference.
[4]
Robin Milner,et al.
A Theory of Type Polymorphism in Programming
,
1978,
J. Comput. Syst. Sci..
[5]
Lennart Augustsson,et al.
A compiler for lazy ML
,
1984,
LFP '84.
[6]
Thomas Johnsson.
Efficient compilation of lazy evaluation
,
1984,
SIGP.
[7]
Daniel P. Friedman,et al.
CONS Should Not Evaluate its Arguments
,
1976,
ICALP.