[mercury-users] Calling Mercury from C and handling io__state

Fergus Henderson fjh at cs.mu.OZ.AU
Mon Dec 17 21:37:14 AEDT 2001


On 17-Dec-2001, Roy Ward <rward at infoscience.otago.ac.nz> wrote:
> I'm trying to call a Mercury library from a C module
...
> :- pred mycall(string::in, string::out, io__state::di, io__state::uo) is 
> det.
> 
> The question is, how do deal with the io__state at the
> C end?

>From the Mercury language reference manual:

 | Calling Mercury code from C
 | ===========================
 ...
 |    A declaration of the form
 | 
 |      :- pragma export(PRED(MODE1, MODE2, ...), "C_NAME_1").
 | 
 | exports a procedure for use by C.
 ...
 | 
 |    The [C] interface to a Mercury procedure is determined as follows. 
 ...
 | Arguments of type `io__state'
 | or `store__store(_)' are not passed at all; that's because these types
 | represent mutable state, and in C modifications to mutable state are
 | done via side effects, rather than argument passing.

So for your example,

:- pred mycall(string::in, string::out, io__state::di, io__state::uo) is det.

if you export this using `pragma export',
the C interface will look like this:

	void mycall(MR_String, MR_String *);

The C code can then call this C function directly, and there's no
io__state arguments to pass.

Does that answer your question?

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list