[m-dev.] foreign type syntax

Tyson Dowd trd at cs.mu.OZ.AU
Thu Oct 25 12:43:21 AEST 2001


We propose adding a foreign_type pragma, which allows you to define a
Mercury type as being equivalent to a foreign language type. 
It might be optimistic of me, but I think it might be worthwhile asking
for input on the syntax.

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
	- 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
	- 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 name of the type may be different for each backend
	- additional information is backend specific

This indicates we should probably try something more like:

:- pragma foreign_type(xmldoc, il("System.Xml", 
	class('System__Xml__XmlDocument'))).
:- pragma foreign_type(xmldoc, c(c_ptr(struct('xmlnode')))).


I would still consider this experimental, but it seems to be a better
approach than what we currently have.  The drawback is that we have to
invent little languages to represent the type systems of other
languages.  But the major alternative is to parse the other language's
type system ourselves.

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.

Any comments at this stage?

-- 
       Tyson Dowd           # 
                            #  Surreal humour isn't everyone's cup of fur.
     trd at cs.mu.oz.au        # 
http://www.cs.mu.oz.au/~trd #
--------------------------------------------------------------------------
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