About Mercury/ back-ends

The Mercury implementation compiles to a wide variety of target languages on a wide variety of platforms. Several of these back-ends are quite mature, other have been released but are still immature, while others are under development.

Mature

Low level C.

Our original back-end. This one compiles Mercury source to low-level C code. It works by converting Mercury source into code for an abstract machine, and then converting the abstract machine instructions into C code with macros for the abstract machine registers and instructions. We use C's conditional compilation (#ifdef) to define these macros as either standard ANSI/ISO C code, or as GNU C code that makes uses of GNU C extensions such as global register variables, computed gotos, and inline assembler.

For more information on the low-level C back-end, see the papers section of the web site, in particular the papers titled "The execution algorithm of Mercury: an efficient purely declarative logic programming language", "Code generation for Mercury", and "Compiling logic programs to C using GNU C as a portable assembler".

High level C.

This back-end compiles Mercury code to fairly high-level C code, more like the kind that a C programmer might write.

For more information on the high-level C back-end see the papers section of the web site, in particular the paper titled "Compiling Mercury to high-level C code".

“Several of these back-ends are quite mature, other have been released but are still immature, while others are under development.”

Beta-release quality

Java.

This back-end compiles Mercury to Java.

The compiler support is complete, it includes good support for interfacing with Java (see the language reference manual for details), and the standard library is fairly reasonable. There is support for Mercury-level debugging, but there is not yet support for Mercury-level profiling.

For a guide to installing and using the Java grade, refer to README.Java and the User's Guide. You will need Mercury release 10.04 or later.

C#.

This back-end compiles Mercury to C#.

The compiler support is complete, it includes good support for interfacing with C# (see the language reference manual for details), and the standard library is fairly reasonable. There is support for Mercury-level debugging, but there is not yet support for Mercury-level profiling.

For a guide to installing and using the C# grade, refer to README.CSharp and the User's Guide. You will need Mercury release 11.01 or later.

Erlang.

This back-end compiles Mercury to Erlang.

The compiler support is in good shape, it includes good support for interfacing with Erlang (see the language reference manual for details), and the standard library is fairly reasonable. There is support for Mercury-level debugging, but there is not yet support for Mercury-level profiling.

For a guide to installing and using the Erlang grade, refer to README.Erlang and the User's Guide. You will need Mercury release 10.04 or later.

Dormant, not currently under development

Mercury byte-code.

We have our own bytecode format, a back-end which generates it, and an interpreter which runs it. This is designed to interoperate with our low-level C back-end. The main aim here is to get better turn-around time for debugging.

This one still needs quite a bit of work to integrate it with the rest of the Mercury implementation. Read the source.

Native code

We formerly had a back-end that compiled to assembler, using the GCC back-end. It had not been maintained for many years, so has been removed.

Microsoft's .NET

This back-end generates IL, the Intermediate Language used by Microsoft's .NET Common Language Runtime.

Click here for more