[mercury-users] number of args for bag.init exported to C
pbone at csse.unimelb.edu.au
Wed Jun 8 11:43:50 AEST 2011
On Tue, Jun 07, 2011 at 04:38:49PM +0200, Guillaume Yziquel wrote:
> I'm exporting the bag.init function with the following pragma:
> :- pragma foreign_export("C", bag.init(out), "no_props").
> And the C function prototype that is exported is:
> void no_props(MR_Word, MR_Word *);
> What is the meaning of the first argument? There is no 'in' argument in
> the Mercury code, and yet it shows in the C function prototype. More
> importantly: what should I set it to?
> I tried investigation the C code, but the way Mercury generates code
> with kind of virtual registers doesn't lend itself to an immediate
> understanding of the C code for bag.init.
Most likly the first argument is used to pass a type info structure.
You're creating a bag that will have the type bag(T) where T is a variable.
When this code is compiled an implicit argument is added.
bag.init(TypeInfoForT, Bag) :- ...
The easiest way to work around this is to know the type of the bag that you're
creating and create a predicate that creates that type of bag. This way
Mercury will provide the first argument for you. For example, I can construct
a bag of ints.
% Note that I specify bag(int) as the type, this way the polymorphism
% transformation is not necessary.
:- pred bag_of_ints_init(bag(int)::out) is det.
:- pragma foreign_export("C", bag_of_ints_init(out), "no_props").
Hope this helps.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 490 bytes
Desc: Digital signature
More information about the users