Documentation of support for polymorphic pragma c code

Fergus Henderson fjh at cs.mu.oz.au
Wed Jan 14 12:39:50 AEDT 1998


On 14-Jan-1998, Oliver Hutchison <ohutch at students.cs.mu.oz.au> wrote:
> 
> I notice that there does not seem to be any documentation about using
> pragma c_code for polymorphic preds, but when I had a go at it I discovered
> that the compiler does support this.  Perhaps there is some uncommitted
> documentation floating around?

What's to document?  It just works. 

> Now we have type layouts etc. this is a
> very useful feature and unless the interface for this feature is unstable
> it sould be documented. 

The interface is the same whether the predicate is monomorphic or polymorphic.

If you want to get access to the type_infos, then as the documentation
in the "Calling Mercury code from C" section says:

	... `type_info' arguments can be obtained using the Mercury
	`type_of' function in the Mercury standard library module `std_util'.

(Well, OK, I admit it --- there is an undocumented alternate way of obtaining
them.  However, using `type_of' works fine, and is arguably more elegant,
so I thought it better not to document the alternative.)

I suppose we could add a similar statement to the above documentation
in the "Calling C code from Mercury" section.  Perhaps something like
	
	Note that `pragma c_code' can be used for both polymorphic and
	ordinary (monomorphic) predicates.  When defining polymorphic
	predicates, you may sometimes need access to the `type_info'
	values which provides information about the particular types
	passed.  These can be obtained using the Mercury `type_of'
	function in the Mercury standard library module `std_util'.
	You can write a small wrapper predicate which calls `type_of'
	to obtain the type_info for its arguments and then passes the
	results to the predicate implemented using `pragma c_code'.

Would that help?

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