International Conference on Compiler Construction

CC 2002: Compiler Construction pp 197-212

Compiling Mercury to High-Level C Code

  • Fergus Henderson
  • Zoltan Somogyi
Conference paper

DOI: 10.1007/3-540-45937-5_15

Volume 2304 of the book series Lecture Notes in Computer Science (LNCS)
Cite this paper as:
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


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).


compilation techniquesprogramming language implementationlogic programmingMercuryCGNU C
Download to read the full conference paper text

Copyright information

© Springer-Verlag Berlin Heidelberg 2002

Authors and Affiliations

  • Fergus Henderson
    • 1
  • Zoltan Somogyi
    • 1
  1. 1.Department of Computer Science and Software EngineeringThe University of MelbourneVictoriaAustralia