A Rational Deconstruction of Landin’s SECD Machine

  • Olivier Danvy
Part of the Lecture Notes in Computer Science book series (LNCS, volume 3474)

Abstract

Landin’s SECD machine was the first abstract machine for the λ-calculus viewed as a programming language. Both theoretically as a model of computation and practically as an idealized implementation, it has set the tone for the subsequent development of abstract machines for functional programming languages. However, and even though variants of the SECD machine have been presented, derived, and invented, the precise rationale for its architecture and modus operandi has remained elusive. In this article, we deconstruct the SECD machine into a λ-interpreter, i.e., an evaluation function, and we reconstruct λ-interpreters into a variety of SECD-like machines. The deconstruction and reconstructions are transformational: they are based on equational reasoning and on a combination of simple program transformations—mainly closure conversion, transformation into continuation-passing style, and defunctionalization.

The evaluation function underlying the SECD machine provides a precise rationale for its architecture: it is an environment-based eval-apply evaluator with a callee-save strategy for the environment, a data stack of intermediate results, and a control delimiter. Each of the components of the SECD machine (stack, environment, control, and dump) is therefore rationalized and so are its transitions.

The deconstruction and reconstruction method also applies to other abstract machines and other evaluation functions.

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. 1.
    Ager, M.S., Biernacki, D., Danvy, O., Midtgaard, J.: A functional correspondence between evaluators and abstract machines. In: Miller, D. (ed.) Proceedings of the Fifth ACM-SIGPLAN International Conference on Principles and Practice of Declarative Programming (PPDP 2003), pp. 8–19. ACM Press, New York (2003)CrossRefGoogle Scholar
  2. 2.
    Ager, M.S., Danvy, O., Goldberg, M.: A symmetric approach to compilation and decompilation. In: Mogensen, T.Æ., Schmidt, D.A., Sudborough, I.H. (eds.) The Essence of Computation. LNCS, vol. 2566, pp. 296–331. Springer, Heidelberg (2002)CrossRefGoogle Scholar
  3. 3.
    Ager, M.S., Danvy, O., Midtgaard, J.: A functional correspondence between call-by-need evaluators and lazy abstract machines. Information Processing Letters 90(5), 223–232 (2004); Extended version available as the technical report BRICS-RS-04-3Google Scholar
  4. 4.
    Ager, M.S., Danvy, O., Midtgaard, J.: A functional correspondence between monadic evaluators and abstract machines for languages with computational effects. Theoretical Computer Science (2005); Accepted for publication. Extended version available as the technical report BRICS RS-04-28Google Scholar
  5. 5.
    Banerjee, A., Heintze, N., Riecke, J.G.: Design and correctness of program transformations based on control-flow analysis. In: Kobayashi, N., Pierce, B.C. (eds.) TACS 2001. LNCS, vol. 2215, pp. 420–447. Springer, Heidelberg (2001)CrossRefGoogle Scholar
  6. 6.
    Bell, J.M., Bellegarde, F., Hook, J.: Type-driven defunctionalization. In: Tofte, M. (ed.) Proceedings of the 1997 ACM SIGPLAN International Conference on Functional Programming, Amsterdam, The Netherlands, pp. 25–37. ACM Press, New York (1997)CrossRefGoogle Scholar
  7. 7.
    Biernacki, D., Danvy, O.: From interpreter to logic engine by defunctionalization. In: Bruynooghe, M. (ed.) LOPSTR 2003. LNCS, vol. 3018, pp. 143–159. Springer, Heidelberg (2004)Google Scholar
  8. 8.
    Boehm, H.-J. (ed.): Proceedings of the Twenty-First Annual ACM Symposium on Principles of Programming Languages, Portland, Oregon. ACM Press, New York (1994)Google Scholar
  9. 9.
    Danvy, O.: Back to direct style. Science of Computer Programming 22(3), 183–195 (1994)MATHCrossRefMathSciNetGoogle Scholar
  10. 10.
    Danvy, O.: Type-directed partial evaluation. In: Steele Jr., G.L. (ed.) Proceedings of the Twenty-Third Annual ACM Symposium on Principles of Programming Languages, St. Petersburg Beach, Florida, pp. 242–257. ACM Press, New York (1996)Google Scholar
  11. 11.
    Danvy, O.: A rational deconstruction of Landin’s SECD machine. Technical Report BRICS RS-03-33, DAIMI, Department of Computer Science, University of Aarhus, Aarhus, Denmark (October 2003)Google Scholar
  12. 12.
    Danvy, O., Filinski, A.: Abstracting control. In: Wand, M. (ed.) Proceedings of the 1990 ACM Conference on Lisp and Functional Programming, Nice, France, pp. 151–160. ACM Press, New York (1990)CrossRefGoogle Scholar
  13. 13.
    Danvy, O., Filinski, A.: Representing control, a study of the CPS transformation. Mathematical Structures in Computer Science 2(4), 361–391 (1992)MATHCrossRefMathSciNetGoogle Scholar
  14. 14.
    Danvy, O., Nielsen, L.R.: Defunctionalization at work. In: Søndergaard, H. (ed.) Proceedings of the Third International ACM SIGPLAN Conference on Principles and Practice of Declarative Programming (PPDP 2001), Firenze, Italy, pp. 162–174. ACM Press, New York (2001); Extended version available as the technical report BRICS RS-01-23Google Scholar
  15. 15.
    Danvy, O., Nielsen, L.R.: On one-pass CPS transformations. Technical Report BRICS RS-02-3, DAIMI, Department of Computer Science, University of Aarhus, Aarhus, Denmark (January 2002); Accepted for publication in the Journal of Functional ProgrammingGoogle Scholar
  16. 16.
    Diehl, S., Hartel, P., Sestoft, P.: Abstract machines for programming language implementation. Future Generation Computer Systems 16, 739–751 (2000)CrossRefGoogle Scholar
  17. 17.
    Felleisen, M.: The Calculi of λ-v-CS Conversion: A Syntactic Theory of Control and State in Imperative Higher-Order Programming Languages. PhD thesis, Department of Computer Science, Indiana University, Bloomington, Indiana (August 1987)Google Scholar
  18. 18.
    Felleisen, M.: The theory and practice of first-class prompts. In: Ferrante, J., Mager, P. (eds.) Proceedings of the Fifteenth Annual ACM Symposium on Principles of Programming Languages, San Diego, California, pp. 180–190. ACM Press, New York (1988)Google Scholar
  19. 19.
    Felleisen, M., Flatt, M.: Programming languages and lambda calculi. Unpublished lecture notes (1989–2003), http://www.ccs.neu.edu/home/matthias/3810-w02/readings.html
  20. 20.
    Filinski, A.: Representing monads. In: Boehm [8], pp. 446–457Google Scholar
  21. 21.
    Friedman, D.P., Wand, M., Haynes, C.T.: Essentials of Programming Languages, 2nd edn. MIT Press, Cambridge (2001)MATHGoogle Scholar
  22. 22.
    Gasbichler, M., Sperber, M.: Final shift for call/cc: direct implementation of shift and reset. In: Peyton Jones, S. (ed.) Proceedings of the 2002 ACM SIGPLAN International Conference on Functional Programming, Pittsburgh, Pennsylvania. SIGPLAN Notices, vol. 37(9), pp. 271–282. ACM Press, New York (2002)CrossRefGoogle Scholar
  23. 23.
    Hatcliff, J., Danvy, O.: A generic account of continuation-passing styles. In: Boehm [8], pp. 458–471Google Scholar
  24. 24.
    Hein, P.: Grooks. MIT Press, Cambridge (1966)Google Scholar
  25. 25.
    Kameyama, Y., Hasegawa, M.: A sound and complete axiomatization of delimited continuations. In: Shivers, O. (ed.) Proceedings of the 2003 ACM SIGPLAN International Conference on Functional Programming, Uppsala, Sweden, pp. 177–188. ACM Press, New York (2003)CrossRefGoogle Scholar
  26. 26.
    Krivine, J.-L.: Un interprète du λ-calcul. Brouillon (1985), Available online at, http://www.pps.jussieu.fr/~krivine
  27. 27.
    Landin, P.J.: The mechanical evaluation of expressions. The Computer Journal 6(4), 308–320 (1964)MATHGoogle Scholar
  28. 28.
    Landin, P.J.: The next 700 programming languages. Commun. ACM 9(3), 157–166 (1966)MATHCrossRefGoogle Scholar
  29. 29.
    Lawall, J.L., Danvy, O.: Continuation-based partial evaluation. In: Talcott, C.L. (ed.) Proceedings of the 1994 ACM Conference on Lisp and Functional Programming, Orlando, Florida. LISP Pointers, vol. VII(3), pp. 227–238. ACM Press, New York (1994)CrossRefGoogle Scholar
  30. 30.
    McCarthy, J., Abrahams, P.W., Edwards, D.J., Hart, T.P., Levin, M.I.: LISP 1.5 Programmer’s Manual. The MIT Press, Cambridge (1962)Google Scholar
  31. 31.
    Morris, L.: The next 700 formal language descriptions. Lisp and Symbolic Computation 6(3/4), 249–258 (1993)CrossRefGoogle Scholar
  32. 32.
    Nielsen, L.R.: A denotational investigation of defunctionalization. Technical Report BRICS RS-00-47, DAIMI, Department of Computer Science, University of Aarhus, Aarhus, Denmark (December 2000)Google Scholar
  33. 33.
    Peyton Jones, S.L.: Implementing lazy functional languages on stock hardware: The spineless tagless G-machine. Journal of Functional Programming 2(2), 127–202 (1992)MATHCrossRefGoogle Scholar
  34. 34.
    Plotkin, G.D.: Call-by-name, call-by-value and the λ-calculus. Theoretical Computer Science 1, 125–159 (1975)MATHCrossRefMathSciNetGoogle Scholar
  35. 35.
    Ramsdell, J.D.: The tail-recursive SECD machine. Journal of Automated Reasoning 23(1), 43–62 (1999)CrossRefMathSciNetGoogle Scholar
  36. 36.
    Reynolds, J.C.: The discoveries of continuations. Lisp and Symbolic Computation 6(3/4), 233–247 (1993)CrossRefGoogle Scholar
  37. 37.
    Reynolds, J.C.: Definitional interpreters for higher-order programming languages. Higher-Order and Symbolic Computation 11(4), 363–397 (1998); Reprinted from the proceedings of the 25th ACM National Conference (1972) (with a foreword)Google Scholar
  38. 38.
    Schmidt, D.A.: Denotational Semantics: A Methodology for Language Development. Allyn and Bacon, Inc., Boston (1986)Google Scholar
  39. 39.
    Shivers, O.: Control-Flow Analysis of Higher-Order Languages or Taming Lambda. PhD thesis, School of Computer Science, Carnegie Mellon University, Pittsburgh, Pennsylvania (May 1991), Technical Report CMU-CS-91-145Google Scholar
  40. 40.
    Steele Jr., G.L.: Lambda, the ultimate declarative. AI Memo 379, Artificial Intelligence Laboratory. Massachusetts Institute of Technology, Cambridge, Massachusetts (November 1976)Google Scholar
  41. 41.
    Steele Jr., G.L.: Rabbit: A compiler for Scheme. Master’s thesis, Artificial Intelligence Laboratory. Massachusetts Institute of Technology, Cambridge, Massachusetts (May 1978), Technical report AI-TR-474Google Scholar
  42. 42.
    Steele Jr., G.L., Sussman, G.J.: Lambda, the ultimate imperative. AI Memo 353, Artificial Intelligence Laboratory. Massachusetts Institute of Technology, Cambridge, Massachusetts (March 1976)Google Scholar
  43. 43.
    Steele Jr., G.L., Sussman, G.J.: The art of the interpreter or, the modularity complex (parts zero, one, and two). AI Memo 453, Artificial Intelligence Laboratory, Massachusetts Institute of Technology, Cambridge, Massachusetts (May 1978)Google Scholar
  44. 44.
    Stoy, J.E.: Denotational Semantics: The Scott-Strachey Approach to Programming Language Theory. MIT Press, Cambridge (1977)Google Scholar
  45. 45.
    Winskel, G.: The Formal Semantics of Programming Languages. Foundation of Computing Series. The MIT Press, Cambridge (1993)MATHGoogle Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2005

Authors and Affiliations

  • Olivier Danvy
    • 1
  1. 1.BRICS Department of Computer ScienceUniversity of Aarhus, IT-parkenAarhus NDenmark

Personalised recommendations