Next: , Previous: Declaring Mercury exports to other modules, Up: Foreign language interface   [Contents]


14.9 Adding foreign definitions

Definitions of foreign language entities (such as functions or global variables) may be included using a declaration of the form

:- pragma foreign_code("Lang", Code).

This declaration will have effects equivalent to including the specified Code in an automatically generated source file of the specified programming language, in a place appropriate for definitions, and linking that source file with the Mercury program (after having compiled it with a compiler for the specified programming language, if appropriate).

Entities declared in ‘pragma foreign_code’ declarations are visible in ‘pragma foreign_proc’ declarations that specify the same foreign language and occur in the same Mercury module.

The Melbourne Mercury implementation additionally supports the form

:- pragma foreign_code("Lang", include_file("Path")).

This has the same effect as the standard form except that the contents of the file referenced by Path are included in place of the string literal in the last argument, without further interpretation. Path may be an absolute path to a file, or a path to a file relative to the directory that contains the source file of the module containing the declaration. The interpretation of the path is platform-dependent. If the filesystem uses a different character set or encoding from the Mercury source file (which must be UTF-8), the file may not be found.

mmc --make’ and ‘mmake’ treat included files as dependencies of the module.