Target code generation from G-machine code

The G-machine is a stack machine for von-Neumann-like execution of lazy functional languages, using graph reduction. This paper describes how target code generation from G-machine code is performed in a compiler for Lazy ML. We briefly review the G-machine, and the compiler phases preceding the target code generation. Two different target code generation methods are described, as well as essential parts of the run-time system. The first target code generator is very simple, generating naive code by means of ‘macro expansion’. This code explicitly manipulates the stacks exactly as prescribed by the G-machine instructions. A simple peep-hole code improver can remove a fair amount of the most glaring inefficiencies of the naive code. The second target code generator is less naive, and takes a more systematic approach to avoid redundant operations in the resulting target code. This code generator can be neatly expressed as an attribute grammar over the G-machine code sequence.

[1]  Lennart Augustsson,et al.  Compiling Pattern Matching , 1985, FPCA.

[2]  William A. Wulf,et al.  The Design of an Optimizing Compiler , 1975 .

[3]  P. J. Landin The Mechanical Evaluation of Expressions , 1964, Comput. J..

[4]  R. J. M. Hughes,et al.  Super-combinators a new implementation method for applicative languages , 1982, LFP '82.

[5]  Peter Henderson,et al.  A lazy evaluator , 1976, POPL.

[6]  Pierre-Louis Curien,et al.  The Categorical Abstract Machine , 1987, Sci. Comput. Program..

[7]  Thomas Johnsson,et al.  Efficient compilation of lazy evaluation , 1984, SIGPLAN '84.

[8]  D. A. Turner The semantic elegance of applicative languages , 1981, FPCA '81.

[9]  D. A. Turner,et al.  A new implementation technique for applicative languages , 1979, Softw. Pract. Exp..

[10]  Simon L. Peyton Jones,et al.  The Implementation of Functional Programming Languages , 1987 .

[11]  Thomas Johnsson,et al.  Attribute grammars as a functional programming paradigm , 1987, FPCA.

[12]  John L. Hennessy,et al.  Register allocation by priority-based coloring , 1984, SIGPLAN '84.

[13]  Lennart Augustsson,et al.  A compiler for lazy ML , 1984, LFP '84.

[14]  Thomas Johnsson,et al.  Lambda Lifting: Treansforming Programs to Recursive Equations , 1985, FPCA.

[15]  Thomas Johnsson Efficient compilation of lazy evaluation , 1984, SIGP.

[16]  Daniel P. Friedman,et al.  CONS Should Not Evaluate its Arguments , 1976, ICALP.

[17]  Peter Henderson Functional Programming , 1980 .