Abstract
Standard ML is a major revision of earlier dialects of the functional language ML. We describe the first compiler written for Standard ML in Standard ML. The compiler incorporates a number of novel features and techniques, and is probably the largest system written to date in Standard ML.
Great attention was paid to modularity in the construction of the compiler, leading to a successful large-scale test of the modular capabilities of Standard ML. The front end is useful for purposes other than compilation, and the back end is easily retargetable (we have code generators for the VAX and MC68020). The module facilities of Standard ML were taken into account early in the design of the compiler, and they particularly influenced the environment management component of the front end. For example, the symbol table structure is designed for fast access to opened structures.
The front end of the compiler is a single phase that integrates parsing, environment management, and type checking. The middle end uses a sophisticated decision tree scheme to produce efficient pattern matching code for functions and case expressions. The abstract syntax produced by the front end is translated into a simple lambda-calculus-based intermediate representation that lends itself to easy case analysis and optimization in the code generator. Special care was taken in designing the runtime data structures for fast allocation and garbage collection.
We describe the overall organization of the compiler and present some of the data representations and algorithms used in its various phases. We conclude with some lessons learned about the ML language itself and about compilers for modern functional languages.
Supported by NSF Grant DCR-8603453 and by a Digital Equipment Corporation Faculty Incentive Grant.
Part of this author's work was done while an SERC Senior Visiting Fellow at the University of Edinburgh.
Chapter PDF
Similar content being viewed by others
Keywords
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.
References
P.J. Landin, “The next 700 programming languages,” Comm. ACM, vol. 9, no. 3, pp. 157–166, 1966.
Luca Cardelli, “Compiling a functional language,” 1984 Symp. on LISP and Functional Programming, pp. 208–217, ACM, 1984.
Robin Milner, “A proposal for Standard ML,” ACM Symposium on LISP and Functional Programming, pp. 184–197, ACM, 1984.
Robin Milner, “The Standard ML Core Language,” Polymorphism, vol. 2, no. 2, October 1985.
David MacQueen, “Modules for Standard ML,” Proc. 1984 ACM Conf. on LISP and Functional Programming, pp. 198–207, ACM, Austin, Texas, 1984.
David MacQueen, “Modules for Standard ML,” Polymorphism, vol. 2, no. 2, October 1985.
R. Burstall, D. MacQueen, and D. Sannella, “Hope: an Experimental Applicative Language,” Proceedings of the 1980 LISP Conference, pp. 136–143, Stanford, 1980.
David C. J. Matthews, “The Poly manual,” SIGPLAN Notices, September 1985.
David C. J. Matthews, An implementation of Standard ML in Poly, May 1986.
G. Cousineau, P. L. Curien, and M. Mauny, “The Categorical Abstract Machine,” in Functional Programming Languages and Computer Architecture, LNCS Vol 201, ed. J. P. Jouannaud, pp. 50–64, Springer-Verlag, 1985.
Robin Milner, “A Theory of Type Polymorphism in Programming,” J. CSS, vol. 17, pp. 348–375, 1978.
Luca Cardelli, “Basic polymorphic typechecking,” Polymorphism, vol. 2, no. 1, January 1985.
R. S. Boyer and J Moore, “The sharing of structure in theorem-proving programs,” in Machine Intelligence 7, ed. D. Michie, Edinburgh University Press, 1972.
Luis Damas, “Type Assignment in Programming Languages,” PhD Thesis, Department of Computer Science, University of Edinburgh, 1985.
Robert Harper, Robin Milner, and Mads Tofte, “A type discipline for program modules,” ECS-LFCS-87-28, Univ. of Edinburgh, 1987.
Marianne Baudinet and David MacQueen, Tree Pattern Matching for ML, 1986.
Guy L. Steele, “Rabbit: a compiler for Scheme,” AI-TR-474, MIT, 1978.
D. Kranz, R. Kelsey, J. Rees, P. Hudak, J. Philbin, and N. Adams, “ORBIT: An optimizing compiler for Scheme,” Proc. Sigplan '86 Symp. on Compiler Construction, vol. 21 (Sigplan Notices), no. 7, pp. 219–233, July 1986.
W. Wulf, R. K. Johnsson, C. B. Weinstock, C. B. Hobbs, and C. M. Geschke, Design of an Optimizing Compiler, Elsevier North-Holland, New York, 1975.
Luca Cardelli, “The functional abstract machine,” Polymorphism, vol. 1, no. 1, January 1983.
R. G. G. Cattell, “Formalization and automatic derivation of code generators,” Ph.D. Thesis, Carnegie-Mellon University, Pittsburgh, PA, April 1978.
A. V. Aho, M. Ganapathi, and S. W. K. Tjiang, Code generation using tree matching and dynamic programming, 1986.
D. A. Turner, “Miranda: a non-strict functional language with polymorphic types,” in Functional Programming Languages and Computer Architecture, LNCS Vol 201, ed. J. P. Jouannaud, pp. 1–16, Springer-Verlag, 1985.
Henry Lieberman and Carl Hewitt, “A real-time garbage collector based on the lifetimes of objects,” Communications of the ACM, vol. 23, no. 6, pp. 419–429, ACM, 1983.
A. W. Appel, “Garbage collection can be faster than stack allocation,” Information Processing Letters, vol. (to appear), 1987.
David A. Moon, “Garbage collection in a large LISP system,” ACM Symposium on LISP and Functional Programming, pp. 235–246, ACM, 1984.
David Ungar, “Generation scavenging: a non-disruptive high performance storage reclamation algorithm,” SIGPLAN Notices (Proc. ACM SIGSOFT/SIGPLAN Software Eng. Symp. on Practical Software Development Environments), vol. 19, no. 5, pp. 157–167, ACM, 1984.
Author information
Authors and Affiliations
Editor information
Rights and permissions
Copyright information
© 1987 Springer-Verlag Berlin Heidelberg
About this paper
Cite this paper
Appel, A.W., MacQueen, D.B. (1987). A standard ML compiler. In: Kahn, G. (eds) Functional Programming Languages and Computer Architecture. FPCA 1987. Lecture Notes in Computer Science, vol 274. Springer, Berlin, Heidelberg. https://doi.org/10.1007/3-540-18317-5_17
Download citation
DOI: https://doi.org/10.1007/3-540-18317-5_17
Published:
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-540-18317-4
Online ISBN: 978-3-540-47879-9
eBook Packages: Springer Book Archive