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.
- 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 Scholar
- 2 AHO, A. V., SETHI, R., AND ULLMAN, J. D. Compilers: Pmnciples, Techniques and Tools. Addison-Wesley, Reading, Mass., 1986. Google Scholar
- 3 APPEL, A.W. A runtime system. Lisp Symbolic Comput. 3, 4 (Nov. 1990), 343-380. Google Scholar
- 4 APPEL, A.W. Compihng with Contmuatwns. Cambridge University Press, New York, 1992.Google Scholar
- 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 Scholar
- 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 Scholar
- 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 Scholar
- 8 BARTLETT, J.F. SCHEME --~ C: A portable Scheme-to-C compiler. Tech. Rep., DEC Western Research Laboratory, Palo Alto, Calif., Jan. 1989.Google Scholar
- 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 Scholar
- 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 Scholar
- 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 Scholar
- 12 GILLESPIE, D. The p2c translator. Available by anonymous ftp from csvax.cs.caltech.edu under the GNUcopyleft, 1989.Google Scholar
- 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 Scholar
- 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 Scholar
- 15 KERNIGHAN, B. W., AND RITCHIE, D.M. The C Programming Language. 2nd Ed. Prentice-Hall, Englewood Cliffs, N.J., 1988. Google Scholar
- 16 KRANZ, D. ORBIT: An optimizing compiler for Scheme. Ph.D. thesis, Yale Univ., Dept. of Computer Science, New Haven, Conn., Feb. 1988. Google Scholar
- 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 Scholar
- 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 Scholar
- 19 MILNER, R., TOFTE, M., AND HARPER, R. The Definition of Standard ML. MIT Press, Cambridge, Mass., 1990. Google Scholar
- 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 Scholar
- 21 REES, J., AND CLINGER, W. Revised report on the algorithmic language Scheme. SIGPLAN Not. (ACM) 21, 12 (Dec. 1986), 37-79. Google Scholar
- 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 Scholar
- 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 Scholar
- 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 Scholar
- 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 Scholar
- 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 Scholar
Index Terms
No assembly required: compiling standard ML to C
Recommendations
A New Backend for Standard ML of New Jersey
IFL '20: Proceedings of the 32nd Symposium on Implementation and Application of Functional LanguagesThis paper describes the design and implementation of a new backend for the Standard ML of New Jersey (SML/NJ) system that is based on the LLVM compiler infrastructure. We first describe the history and design of the current backend, which is based on ...
Revised Report on the Algorithmic Language Scheme
The report gives a defining description of the programming language Scheme. Scheme is a statically scoped and properly tail-recursive dialect of the Lisp programming language invented by Guy Lewis Steele, Jr. and Gerald Jay Sussman. It was designed to have ...
Continuations from generalized stack inspection
Proceedings of the tenth ACM SIGPLAN international conference on Functional programmingImplementing first-class continuations can pose a challenge if the target machine makes no provisions for accessing and re-installing the run-time stack. In this paper, we present a novel translation that overcomes this problem. In the first half of the ...








Comments