[m-dev.] foreign type syntax

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Oct 25 22:13:57 AEST 2001


On 25-Oct-2001, Tyson Dowd <trd at cs.mu.OZ.AU> wrote:
> We propose adding a foreign_type pragma, which allows you to define a
> Mercury type as being equivalent to a foreign language type. 

What happens if the foreign language type doesn't fit in a single word?
Will the Mercury compiler automatically box/unbox it, like it does for `float'?

> Currently the syntax is:
> 
> :- pragma foreign_type(xmldoc, 'System__Xml__XmlDocument', il("System.Xml")).
> 
> This defines a new Mercury type "xmldoc", which is defined to be the
> same as the type System.Xml.XmlDocument in the IL backend, which can be
> found in the assembly System.Xml.
> 
> This syntax is a bit broken, but it helps us establish what has to be
> covered by an improved syntax:
> 
> We must specify 
> 	- the name of the Mercury type
> 	- the name of the foreign type
> 	- the backend(s) to which this mapping applies

Why do you say "backends" rather than "languages" here?

> 	- we may need to specify additional information about the
> 	  foreign type (assembly name/library name)
> 
> Other requirements are
> 
> 	- the name of the foreign type might be structured
> 	  	- it may have a namespace component
> 		- it may include type constructors such as * or
> 		  class/struct/enum

Why does the Mercury compiler need to know about this structure?

In other words, why can't the name of the foreign type just be treated
as an uninterpreted string by the Mercury compiler?

> 	- the name may need to be translated into other "backends" for
> 	  foreign language interfacing (e.g. into MC++, IL and C#, or
> 	  into C as well as gcc's syntax tree).

The user can do that if necessary, by giving addition `pragma foreign_type'
declarations for the same Mercury type but different foreign languages.

> Finally, I'm still not sure about what to do about namespace nested
> names.  System__Xml__XmlDocument is a bit long, but the idea is that
> it just uses Mercury's nested module naming system, so when we switch to
> "." we can just use "." instead.  So I guess it will be nicer in future.

I think it would be nicer to just use whatever syntax the foreign language
uses.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  | "... it seems to me that 15 years of
The University of Melbourne         | email is plenty for one lifetime."
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- Prof. Donald E. Knuth
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list