Advertisement

LISP and Symbolic Computation

, Volume 10, Issue 2, pp 113–158 | Cite as

An Automatic Program Generator for Multi-Level Specialization

  • Robert Glück
  • Jesper Jørgensen
Article

Abstract

Program specialization can divide a computation into several computation stages. This paper investigates the theoretical limitations and practical problems of standard specialization tools, presents multi-level specialization, and demonstrates that, in combination with the cogen approach, it is far more practical than previously supposed. The program generator which we designed and implemented for a higher-order functional language converts programs into very compact multi-level generating extensions that guarantee fast successive specialization. Experimental results show a remarkable reduction of generation time and generator size compared to previous attempts of multi-level specialization by self-application. Our approach to multi-level specialization seems well-suited for applications where generation time and program size are critical.

programming languages program transformation partial evaluation generating extensions binding-time analysis functional languages Scheme 

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. 1.
    Andersen, L.O. Program analysis and specialization for the C programming language. Ph.D. Thesis, DIKU Report 94/19. Dept. of Computer Science, University of Copenhagen, 1994.Google Scholar
  2. 2.
    Andersen, P.H. and Holst, C.K. Termination analysis for offline partial evaluation of a higher order functional language. In Static Analysis, R. Cousot and D. Schmidt (Eds.). Springer-Verlag, Lecture Notes in Computer Science, vol. 1145, pp. 67–82, 1996.Google Scholar
  3. 3.
    Barklund, J., Boberg, K., Dell'Acqua, P., and Veanes, M. Meta-programming with theory systems, In Meta-Logics and Logic Programming, K. Apt and F. Turini (Eds.), Logic Programming, MIT Press, pp. 195–224, 1995.Google Scholar
  4. 4.
    Beckman, L., Haraldson, A., Oskarsson, Ö., and Sandewall, E. A partial evaluator and its use as a programming tool. Artificial Intelligence, 7:319–357, 1976.Google Scholar
  5. 5.
    Birkedal, L. and Welinder, M. Partial evaluation of Standard ML. DIKU Report 93/22. Dept. of Computer Science, University of Copenhagen, 1993.Google Scholar
  6. 6.
    Birkedal, L. and Welinder, M. Binding-time analysis for Standard ML. Lisp and Symbolic Computation, 8(3):191–208, 1995.Google Scholar
  7. 7.
    Birkedal, L. and Welinder, M. Hand-writing program generator generators. In Programming Language Implementation and Logic Programming, M. Hermenegildo and J. Penjam (Eds.). Springer-Verlag, Lecture Notes in Computer Science, vol. 844, pp. 198–214, 1994.Google Scholar
  8. 8.
    Bjørner, D., Ershov, A.P., and Jones, N.D. (Eds.). Partial Evaluation and Mixed Computation. North-Holland, 1988.Google Scholar
  9. 9.
    Bondorf, A. Self-Applicable Partial Evaluation. Ph.D. Thesis, Report 90/17. DIKU Dept. of Computer Science, University of Copenhagen, 1990.Google Scholar
  10. 10.
    Bondorf, A. Automatic autoprojection of higher order recursive equations. Science of Computer Programming, 17(1-3):3–34, 1991.Google Scholar
  11. 11.
    Bondorf, A. and Danvy, O. Automatic autoprojection of recursive equations with global variables and abstract data types. Science of Computer Programming, 16:151–195, 1991.Google Scholar
  12. 12.
    Bondorf, A. and Jørgensen, J. Efficient analyses for realistic off-line partial evaluation. Journal of Functional Programming, 3(3):315–346, 1993.Google Scholar
  13. 13.
    Bondorf, A. and Dussart, D. Improving cps-based partial evaluation: Writing cogen by hand. In ACM SIGPLAN Workshop on Partial Evaluation and Semantics-Based Program Manipulation, Technical Report 94/9. University of Melbourne, Australia, pp. 1–9, 1994.Google Scholar
  14. 14.
    Bulyonkov, M.A. Polyvariant mixed computation for analyzer programs. Acta Informatica, 21:473–484, 1984.Google Scholar
  15. 15.
    Cardone, F. and Coppo, M. Type inference with recursive types: Syntax and semantics. Information and Computation, 92:48–80, 1991.Google Scholar
  16. 16.
    Consel, C. A tour of Schism: a partial evaluation system for higher-order applicative languages. In Proceedings of the Symposium on Partial Evaluation and Semantics-Based Program Manipulation. ACM Press, pp. 145–154, 1993.Google Scholar
  17. 17.
    Consel, C. and Danvy, O. From interpreting to compiling binding times. In ESOP '90, N.D. Jones (Ed.). Springer-Verlag, Lecture Notes in Computer Science, vol. 432, pp. 88–105, 1990.Google Scholar
  18. 18.
    Danvy, O., Glück, R., and Thiemann, P. (Eds.). Partial Evaluation. Springer-Verlag, Lecture Notes in Computer Science, vol. 1110, 1996.Google Scholar
  19. 19.
    Davies, R. and Pfenning, F. A modal analysis of staged computation. In Symposium on Principles of Programming Languages. ACM Press, pp. 258-270, 1996.Google Scholar
  20. 20.
    Ershov, A.P. On the essence of compilation. In Formal Description of Programming Concepts, E.J. Neuhold (Ed.). North-Holland, pp. 391–420, 1978.Google Scholar
  21. 21.
    Futamura, Y. Partial evaluation of computation process—An approach to a compiler-compiler. Systems, Computers, Controls, 2(5):45–50, 1971.Google Scholar
  22. 22.
    Glenstrup, A. and Jones, N.D. BTA algorithms to ensure termination of off-line partial evaluation. In Perspectives of System Informatics, D. Bjørner, M. Broy, and I.V. Pottosin (Eds.). Springer-Verlag, Lecture Notes in Computer Science, vol. 1181, pp. 273–284, 1996.Google Scholar
  23. 23.
    Glück, R. Towards multiple self-application. In Proceedings of the Symposium on Partial Evaluation and Semantics-Based Program Manipulation. ACM Press, pp. 309–320, 1991.Google Scholar
  24. 24.
    Glück, R. On the generation of specializers. Journal of Functional Programming, 4(4):499–514, 1994.Google Scholar
  25. 25.
    Glück, R. and Jørgensen, J. Generating transformers for deforestation and supercompilation. In Static Analysis, B. Le Charlier (Ed.). Springer-Verlag, Lecture Notes in Computer Science, vol. 864, pp. 432–448, 1994.Google Scholar
  26. 26.
    Glück, R. and Jørgensen, J. Efficient multi-level generating extensions for program specialization. In Programming Languages, Implementations, Logics and Programs, M. Hermenegildo and S.D. Swierstra (Eds.). Springer-Verlag, Lecture Notes in Computer Science, vol. 982, pp. 259–278, 1995.Google Scholar
  27. 27.
    Glück, R. and Jørgensen, J. Fast binding-time analysis for multi-level specialization. In Perspectives of System Informatics, D. Bjørner, M. Broy, and I.V. Pottosin (Eds.). Springer-Verlag, Lecture Notes in Computer Science, vol. 1181, pp. 261–272, 1996.Google Scholar
  28. 28.
    Gomard, C.K. and Jones, N.D. A partial evaluator for the untyped lambda calculus. Journal of Functional Programming, 1(1):21–69, 1991.Google Scholar
  29. 29.
    Hatcliff, J. Mechanically verifying the correctness of an off-line partial evaluator. In Programming Languages, Implementations, Logics and Programs, M. Hermenegildo and S.D. Swierstra (Eds.). Springer-Verlag, Lecture Notes in Computer Science, vol. 982, pp. 279–298, 1995.Google Scholar
  30. 30.
    Henglein, F. Efficient type inference for higher-order binding-time analysis. In Functional Programming and Computer Architecture, J. Hughes (Ed.). Springer-Verlag, Lecture Notes in Computer Science, vol. 523, pp. 448–472, 1991.Google Scholar
  31. 31.
    Holst, C.K. Syntactic currying: Yet another approach to partial evaluation. Technical report. DIKU, Department of Computer Science, University of Copenhagen, 1989.Google Scholar
  32. 32.
    Holst, C.K. and Launchbury, J. Handwriting cogen to avoid problems with static typing. Working paper, 1992.Google Scholar
  33. 33.
    IEEE. Standard for the Scheme programming language. IEEE Std 1178-1990, Institute of Electrical and Electronics Engineers, 1991.Google Scholar
  34. 34.
    Jones, N.D. (Ed.). Semantics-Directed Compiler Generation Proceedings, Springer-Verlag, Lecture Notes in Computer Science, vol. 94, 1980.Google Scholar
  35. 35.
    Jones, N.D., Sestoft, P., and Søndergaard, H. An experiment in partial evaluation: the generation of a compiler generator. In Rewriting Techniques and Applications, J.-P. Jouannaud (Ed.). Springer-Verlag, Lecture Notes in Computer Science, vol. 202, pp. 124–140, 1985.Google Scholar
  36. 36.
    Jones, N.D., Sestoft, P., and Søndergaard, H. Mix: A self-applicable partial evaluator for experiments in compiler generation. Lisp and Symbolic Computation, 2(1):9–50, 1989.Google Scholar
  37. 37.
    Jones, N.D., Gomard, C.K., and Sestoft, P. Partial Evaluation and Automatic Program Generation. Prentice Hall International Series in Computer Science, Prentice-Hall, 1993.Google Scholar
  38. 38.
    Jørgensen, J. and Leuschel, M. Efficiently generating efficient generating extensions in Prolog. In [18], pp. 238–262, 1996.Google Scholar
  39. 39.
    Jørring, U. and Scherlis, W. Compilers and staging transformations. In Conference Record of the Thirteenth ACM Symposium on Principles of Programming Languages. ACM, pp. 86–95, 1986.Google Scholar
  40. 40.
    Lawall, J. and Danvy, O. Continuation-based partial evaluation. In ACM Conference on Lisp and Functional Programming, ACM Press. pp. 227-238, 1994.Google Scholar
  41. 41.
    Mogensen, T.Æ . Partially static structures in a self-applicable partial evaluator. In [8], pp. 325–347, 1988.Google Scholar
  42. 42.
    Nielson, F. and Nielson, H.R. Two-Level Functional Languages, Cambridge Tracts in Theoretical Computer Science. Cambridge University Press, Vol. 34, 1992.Google Scholar
  43. 43.
    Nielson, F. and Nielson, H.R. Multi-level lambda-calculus: An algebraic description. In [18], pp. 338–354, 1996.Google Scholar
  44. 44.
    Romanenko, S.A. A compiler generator produced by a self-applicable specializer can have a surprisingly natural and understandable structure. In [8], pp. 445–463, 1988.Google Scholar
  45. 45.
    Schmidt, David A. Denotational Semantics, a Methodology for Language Development. Allyn and Bacon, 1986.Google Scholar
  46. 46.
    Sørensen, M.H., Glück, R., and Jones, N.D. A positive supercompiler. Journal of Functional Programming, 1996 (to appear).Google Scholar
  47. 47.
    Taha, W. and Sheard, T. Multi-stage programming with explicit annotations. In ACM SIGPLAN Symposium on Partial Evaluation and Semantics-Based Program Manipiulation. ACP Press, 1997 (to appear).Google Scholar
  48. 48.
    Tennent, R.D. Principles of Programming Languages. Prentice Hall International Series in Computer Science. Prentice Hall, 1981.Google Scholar
  49. 49.
    Thiemann, P. Cogen in six lines. In International Conference on Functional Programming. ACM Press, 1996, pp. 180–189.Google Scholar
  50. 50.
    Thiemann, P. Towards partial evaluation of full Scheme. In Reflection'96, G. Kiczales (Ed.), pp. 105–116, 1996.Google Scholar
  51. 51.
    Turchin, V.F. Refal-5, Programming Guide and Reference Manual. New England Publishing Co., Holyoke, Massachusetts, 1989.Google Scholar
  52. 52.
    Wand, M. Specifying the correctness of binding-time analysis. Journal of Functional Programming, 3(3):365–387, 1993.Google Scholar

Copyright information

© Kluwer Academic Publishers 1997

Authors and Affiliations

  • Robert Glück
    • 1
  • Jesper Jørgensen
    • 2
  1. 1.DIKU, Department of Computer ScienceUniversity of CopenhagenCopenhagenDenmark
  2. 2.Department of Mathematics and PhysicsRoyal Veterinary and Agricultural UniversityFrederiksberg CDenmark

Personalised recommendations