Abstract
Many logic programming implementations compile to C, but they compile to very low-level C, and thus discard many of the advantages of compiling to a high-level language. We describe an alternative approach to compiling logic programs to C, based on continuation passing, that we have used in a new back-end for the Mercury compiler. The new approach compiles to much higher-level C code, which means the compiler back-end and run-time system can be considerably simpler. We present a formal schema for the transformation, and give benchmark results which show that this approach delivers performance that is more than competitive with the fastest previous implementation, with greater simplicity and better portability and interoperability.
The approach we describe can also be used for compiling to other target languages, such as IL (the Microsoft .NET intermediate language).
Chapter PDF
Similar content being viewed by others
References
H. Boehm and M. Weiser. Garbage collection in an uncooperative environment. Software Practice and Experience, 18:807–820, 1988.
T. M. Breuel. Lexical closures for C++. In Proceedings of the 1988 USENIX C++ Conference, pages 293–304, Denver, Colorado, 1988.
F. Bueno, D. Cabeza, M. Carro, M. Hermenegildo, P. López-GarcÃa, and G. Puebla. The Ciao Prolog system. reference manual. Technical Report CLIP3/97.1, School of Computer Science, Technical University of Madrid (UPM), August 1997. Available from http://www.clip.dia...upm.es/.
L. Byrd. Understanding the control of Prolog programs. Technical Report 151, University of Edinburgh, 1980.
M. Carlsson. On implementing Prolog in functional programming. New Generation Computing, 2(4):347–359, 1984.
P. Codognet and D. Diaz. wamcc: Compiling Prolog to C. In Proceedings of the Twelfth International Conference on Logic Programming, pages 317–331, Kanagawa, Japan, June 1995.
T. Conway, F. Henderson, and Z. Somogyi. Code generation for Mercury. In Proceedings of the Twelfth International Conference on Logic Programming, pages 242–256, Portland, Oregon, December 1995.
T. Dowd, F. Henderson, and P. Ross. Compiling Mercury to the.NET Common Language Runtime. In Proceedings of the First International Workshop on Multi-Language Infrastructure and Interoperability, pages 70–85, Firenze, Italy, September 2001.
B. Hausman. Turbo Erlang: approaching the speed of C. In E. Tick, editor, Implementations of logic programming systems, pages 119–135. Kluwer, 1994.
F. Henderson, Z. Somogyi, and T. Conway. Compiling logic programs to C using GNU C as a portable assembler. In Proceedings of the ILPS’ 95 Postconference Workshop on Sequential Implementation Technologies for Logic Programming Languages, Portland, Oregon, December 1995.
F. Henderson, Z. Somogyi, and T. Conway. Determinism analysis in the Mercury compiler. In Proceedings of the Australian Computer Science Conference, pages 337–346, Melbourne, Australia, January 1996.
J. F. Nilsson. On the compilation of a domain-based Prolog. In Proceedings of the Ninth IFIP Congress, pages 293–298, Paris, France, 1983.
J. O'Bagy and R. E. Griswold. A recursive interpreter for the Icon programming language. In Proceedings of the 1987 SIGPLAN Symposium on Interpreters and Interpretive Techniques, pages 138–149, St. Paul, Minnesota, 1987.
Z. Somogyi, F. Henderson, and T. Conway. The execution algorithm of Mercury, an efficient purely declarative logic programming language. Journal of Logic Programming, 29(1–3):17–64, October–December 1996.
P. Tarau, K. D. Bosschere, and B. Demoen. Partial translation: towards a portable and efficient Prolog implementation technology. Journal of Logic Programming, 29(1–3):65–83, October–December 1996.
A. Taylor. LIPS on a MIPS: results from a Prolog compiler for a RISC. In Proceedings of the Seventh International Conference on Logic Programming, pages 174–185, Jerusalem, Israel, June 1990.
P. Van Roy and A. Despain. High-performance logic programming with the Aquarius Prolog compiler. IEEE Computer, 25(1):54–68, January 1992.
J. Weiner and S. Ramakrishnan. A piggy-back compiler for Prolog. In Proceedings of the SIGPLAN’ 88 Conference on Programming Language Design and Implementation, pages 288–296, Atlanta, Georgia, June 1988.
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2002 Springer-Verlag Berlin Heidelberg
About this paper
Cite this paper
Henderson, F., Somogyi, Z. (2002). Compiling Mercury to High-Level C Code. In: Horspool, R.N. (eds) Compiler Construction. CC 2002. Lecture Notes in Computer Science, vol 2304. Springer, Berlin, Heidelberg. https://doi.org/10.1007/3-540-45937-5_15
Download citation
DOI: https://doi.org/10.1007/3-540-45937-5_15
Published:
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-540-43369-9
Online ISBN: 978-3-540-45937-8
eBook Packages: Springer Book Archive