skip to main content
article
Free Access

No assembly required: compiling standard ML to C

Published:01 June 1992Publication History
Skip Abstract Section

Abstract

C has been used as a portable target language for implementing languages like Standard ML and Scheme. Previous efforts at compiling these languages to C have produced efficient code, but have compromised on portability and proper tail recursion. We show how to compile Standard ML to C wihout making such compromises. The compilation technique is based on converting Standard ML to a continuation-passing style λ-calculus intermediate language and then compiling this language to C. The code generated by this compiler achieves an execution speed that is about a factor of two slower than that generated by a native code compiler. The compiler generates highly portable code, yet still supports advanced features like garbage collection and first-class continuations. We analyze the performance and determine the aspects of the compilation method that lead to the observed slowdown. We also suggest changes to C compilers that would better support such compilation methods.

References

  1. 1 ACHARYA, A., AND KALP, D. Release notes for CParaOPS5 5.3 and ParaOPS5 4.4. Available with the CParaOPS5 release from School of Computer Science, Carnegie-Mellon Univ. Pittsburgh, Pa., May 1990.Google ScholarGoogle Scholar
  2. 2 AHO, A. V., SETHI, R., AND ULLMAN, J. D. Compilers: Pmnciples, Techniques and Tools. Addison-Wesley, Reading, Mass., 1986. Google ScholarGoogle Scholar
  3. 3 APPEL, A.W. A runtime system. Lisp Symbolic Comput. 3, 4 (Nov. 1990), 343-380. Google ScholarGoogle Scholar
  4. 4 APPEL, A.W. Compihng with Contmuatwns. Cambridge University Press, New York, 1992.Google ScholarGoogle Scholar
  5. 5 APPEL, A. W., AND JIM, T.Y. Continuation-passing, closure passing style. In Proceedings of the 16th Annual ACM Symposium on Prtnciples of Programming Languages (Austin, Tex., Jan. 11-13), ACM, New York, 1989, pp. 293-302. Google ScholarGoogle Scholar
  6. 6 APPEL, A. W., AND MACQUEEN, D.B. A standard ML compiler. In Functional Programming Languages and Computer Architecture, vol. 274, G. Kahn, Ed. Springer-Verlag, New York, 1987, pp. 301-324. Google ScholarGoogle Scholar
  7. 7 ATKINSON, R., DEMERS, A., HAUSER, C., JACOBI, C., KESSLER, P., AND WEISER, M. Experience creating a Portable Cedar. In Proceedings of the SIGPLAN 89 Conference on Programming Language Design and Implementation (Portland, Oreg., June 21-23). ACM, New York, 1989, pp. 322-329. Google ScholarGoogle Scholar
  8. 8 BARTLETT, J.F. SCHEME --~ C: A portable Scheme-to-C compiler. Tech. Rep., DEC Western Research Laboratory, Palo Alto, Calif., Jan. 1989.Google ScholarGoogle Scholar
  9. 9 COOPER, E. C., AND MORRISETT, J.G. Adding threads to Standard ML. Tech. Rep. CMU-CS- 90-186, School of Computer Science, Carnegie-Mellon Univ., Pittsburgh, Pa., Dec. 1990.Google ScholarGoogle Scholar
  10. 10 DUBA, B. F., HARPER, R., AND MACQUEEN, D. Typing first-class continuations in ML. In Proceedings of the 18th Annual ACM Symposium on Principles of Programming Languages (Orlando, Fla., Jan. 21-23), ACM, New York, 1991, pp. 163-173. Google ScholarGoogle Scholar
  11. 11 FELDMAN, S., GAY, D., MAIMONE, M. W., AND SCHYER, N. A Fortran-to-C converter. Comput. Sci. Tech. Rep. 149, AT & T Bell Laboratories, Murray Hill, N.J., May 1990.Google ScholarGoogle Scholar
  12. 12 GILLESPIE, D. The p2c translator. Available by anonymous ftp from csvax.cs.caltech.edu under the GNUcopyleft, 1989.Google ScholarGoogle Scholar
  13. 13 HIEB, R., DYBVIG, R. K., AND BRUGGEMAN, C. Representing control in the presence of first-class continuations. In Proceedings of the SIGPLAN 90 Conference on Programming Language Design and Implementation (White Plains, N.Y., June 20-22). ACM, New York, 1990, pp. 66-77. Google ScholarGoogle Scholar
  14. 14 HUELSBERGEN, L., AND LARUS, J. Dynamic program parallelization. In Proceedings of the 1992 ACM Conference on LISP and Functional Programming (San Franciezo, Calif,, June 22-24). ACM, New York, 1992, pp. 311-323. Google ScholarGoogle Scholar
  15. 15 KERNIGHAN, B. W., AND RITCHIE, D.M. The C Programming Language. 2nd Ed. Prentice-Hall, Englewood Cliffs, N.J., 1988. Google ScholarGoogle Scholar
  16. 16 KRANZ, D. ORBIT: An optimizing compiler for Scheme. Ph.D. thesis, Yale Univ., Dept. of Computer Science, New Haven, Conn., Feb. 1988. Google ScholarGoogle Scholar
  17. 17 KRANZ, D., KELSEY, R., REES, J., HUDAK, P., PHILBIN, J., AND ADAMS, N. ORBIT: An optimizing compiler for Scheme. In Proceedtngs of the SIGPLAN 86 Conference on Programming Language Design and Implementation (Palo Alto, Calif., June 25-27). ACM, New York, 1986, pp. 219-233. Google ScholarGoogle Scholar
  18. 18 MARTIN, M. Entwurfund Implementierung eines bersetzers von Modula-2 nach C. Master's thesis, Faklutt fur Informatik, Univ. of Karlsruhe, Germany, Feb. 1990.Google ScholarGoogle Scholar
  19. 19 MILNER, R., TOFTE, M., AND HARPER, R. The Definition of Standard ML. MIT Press, Cambridge, Mass., 1990. Google ScholarGoogle Scholar
  20. 20 MORRISETT, J. G., AND TOLMACH, A. A portable multiprocessor interface for Standard ML of New Jersey. Tech. Rep. CMU-CS-92-155, School of Computer Science, Carnegie-Mellon Univ., Pittsburgh, Pa., June 1992. Google ScholarGoogle Scholar
  21. 21 REES, J., AND CLINGER, W. Revised report on the algorithmic language Scheme. SIGPLAN Not. (ACM) 21, 12 (Dec. 1986), 37-79. Google ScholarGoogle Scholar
  22. 22 REPPY, J.H. Asynchronous signals in Standard ML. Tech. Rep. 90-1144, Dept. of Computer Science, Cornell Univ., Ithaca, N.Y., Aug. 1990. Google ScholarGoogle Scholar
  23. 23 SANTHANAM, V., AND ODNERT, D. Register allocation across procedure and module boundaries. In Proceedings of the SIGPLAN 90 Conference on Programming Language Design and Implementation (White Plains, N.Y., June 20-22), ACM, New York, 1990, pp. 28-39. Google ScholarGoogle Scholar
  24. 24 STALLMAN, R.M. Using and porting GNU CC. GNU CC is a widely available C compiler developed by the Free Software Foundation, Cambridge, Mass., Sept. 1989.Google ScholarGoogle Scholar
  25. 25 STEEL, G. L. JR. RABBIT: A compiler for Scheme (a study in compiler optimization). Master's thesis, Tech. Rep. AI-TR-474, AI Lab., MIT, Cambridge, Mass. May 1978. Google ScholarGoogle Scholar
  26. 26 TARDITI, D., ACHARYA, A., AND LEE, P. No assembly required: Compiling Standard ML to C. Tech. Rep. CMU-CS-90-187, School of Computer Science, Carnegie-Mellon Univ., Pittsburgh, Pa., Nov. 1990.Google ScholarGoogle Scholar

Index Terms

  1. No assembly required: compiling standard ML to C

          Recommendations

          Reviews

          Martin Joseph Jourdan

          The authors show how ML, a higher-order functional language, can be implemented both quickly and efficiently on most commercial computers by compiling it to C, used as a portable intermediate language. The authors' compiler, sml2c, is based on the well-known SML/NJ compiler; the code generator has been replaced and the runtime system slightly modified. SML/NJ uses a continuation-passing, closure-passing style (CPS) lambda-calculus as an intermediate representation. The authors show on two examples that CPS is remarkably close to C. Translating it to C requires some care, however, to make the generated code both completely portable and reasonably efficient. The authors discuss several relevant issues (dispatch loop, runtime system, and garbage collection) and present a number of optimization techniques (register caching, function integration, and overflow checking). Various benchmarks on various machines show that sml2c-generated C code is about half as fast as SML/NJ-generated native code. The paper is well written and clear. It intends to convey the experience acquired with sml2c to scientists and developers involved in similar projects, and it certainly fulfills its purpose. I have two regrets, however. First, lack of space forced the authors to use some specialized phrases, such as proper tail recursion, without explaining them, making the paper somewhat difficult for non-ML experts (but they provide references to good literature). Second, because of long publication delays, the references are a little outdated: recent publications exhibit even better performance [1,2]. In spite of this, the paper still deserves to be recommended.

          Access critical reviews of Computing literature here

          Become a reviewer for Computing Reviews.

          Comments

          Login options

          Check if you have access through your login credentials or your institution to get full access on this article.

          Sign in

          Full Access

          PDF Format

          View or Download as a PDF file.

          PDF

          eReader

          View online with eReader.

          eReader
          About Cookies On This Site

          We use cookies to ensure that we give you the best experience on our website.

          Learn more

          Got it!