[mercury-users] Calling Mercury from C

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Jul 11 14:56:23 AEST 2003


On 11-Jul-2003, Michael Day <mikeday at yeslogic.com> wrote:
> 
> > > Is there a way I can avoid this? I tried casting the closure directly to 
> > > the right kind of function pointer and calling that, but it crashed.
> > 
> > Why do you want to avoid it?
> 
> Many many many forwarding predicates.
> Tiresome to write, and annoying to
> update and keep synchronised with the C functions when the interface
> changes.
> 
> I take it that this is unavoidable though :)

Right.  Mercury closures are not the same as C function pointers.
Mercury closures can be constructed at run-time, and can contain
references to data (such as partially applied arguments) as well
as a code address.  Even the code address which is stored in the
closure is not the same as a C function pointer; the code that it
points to uses the Mercury calling convention, which may be different
than the C calling convention.

In general the representation of Mercury closures can vary depending on
the Mercury compiler options -- they are represented differently in
different grades.

-- 
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