[m-dev.] export declarations

Fergus Henderson fjh at cs.mu.oz.au
Fri Nov 21 14:04:26 AEDT 1997


Peter Schachte, you wrote:
> As I was reviewing the C interface section of the Mercury manual, I was
> struck by the fact that export declarations don't anywhere mention that they
> are exporting a predicate or function for invocation using C's calling
> conventions.  I think the pragma should really be 
> 
> 	:- pragma c_export(Pred(Mode1, Mode2, ...), "C_Name_1").
> 
> and similarly for functions.  Alternatively, it could be something like:
> 
> 	:- pragma export(Pred(Mode1, Mode2, ...), c("C_Name_1")).

I was thinking of an extra argument, i.e.

 	:- pragma export(Pred(Mode1, Mode2, ...), 'C', "C_Name_1").
 	:- pragma export(Pred(Mode1, Mode2, ...), 'Prolog', "Prolog_Name_1").
 	:- pragma export(Pred(Mode1, Mode2, ...), 'Ada', "Ada_Name_1").
 	:- pragma export(Pred(Mode1, Mode2, ...), 'Java', "Java_Name_1").

perhaps with the lower-case names allowed as an alternative:

 	:- pragma export(Pred(Mode1, Mode2, ...), c, "C_Name_1").
 	:- pragma export(Pred(Mode1, Mode2, ...), prolog, "Prolog_Name_1").
 	:- pragma export(Pred(Mode1, Mode2, ...), ada, "Ada_Name_1").
 	:- pragma export(Pred(Mode1, Mode2, ...), java, "Java_Name_1").

Another feature which may be useful: the Ada `pragma export' (which
was a major source of inspiration for the Mercury `pragma export')
allows you to specify the assembler-level link name instead of the
external language name.  This may be useful if interfacing to an
routine that uses say C calling convention but does not use C
naming conventions (e.g. the link name doesn't start with an
underscore).  It would be easy enough to implement that if compiling
to GNU C, since gcc lets you specify the assembler-level name
using e.g. `void my_func(void) asm("asm-name");'.

P.S.
I have a copy of the Ada reference manual at
<http://www.cs.mu.oz.au/~fjh/ada/rm95html-1.0/rm9x-toc.html>
and the rationale is at
<http://www.cs.mu.oz.au/~fjh/ada/rat95html-1.04/rat9x-contents.html>.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3         |     -- the last words of T. S. Garp.



More information about the developers mailing list