Next: , Previous: , Up: Top   [Contents][Index]


12 Foreign language interface

The Mercury foreign language interfaces allows pragma foreign_proc to specify multiple implementations (in different foreign programming languages) for a procedure.

If the compiler generates code for a procedure using a back-end for which there are multiple applicable foreign languages, it will choose the foreign language to use for each procedure according to a builtin ordering.

If the language specified in a foreign_proc is not available for a particular backend, it will be ignored.

If there are no suitable foreign_proc clauses for a particular procedure but there are Mercury clauses, they will be used instead.

C

This is the default foreign language on all backends which compile to C. Only available on backends that compile to C.

C#

Only available on backends that compile to IL or C#. This is the second preferred foreign language for IL code generation.

Erlang

This is the only foreign language for backends which compile to Erlang.

IL

IL is the intermediate language of the .NET Common Language Runtime (sometimes also known as CIL or MSIL). Only available on backends that compile to IL. This is the preferred foreign language for IL code generation.

Java

This is the only foreign language for backends which compile to Java.