[m-dev.] foreign type syntax, the pain begins.

Tyson Dowd trd at cs.mu.OZ.AU
Thu Nov 1 16:49:47 AEDT 2001


So, now that Fergus beaten me into submission over the idea of having
foreign_types specified as foreign language strings, we can get back to
actually defining the syntax for foreign types.

The agreed scheme was to use uninterpreted strings to specify foreign
types, and each possible language the compiler might be required to
generated code for must be specified in a different pragma foreign_type
declaration.

So we are looking for something like:

:- pragma foreign_type(xmldoc, csharp, "System.Xml.XmlDocument")).

or

:- pragma foreign_type(xmldoc, csharp("System.Xml.XmlDocument")).

(I know that 'csharp' isn't the same as "C#" or "csharp" we use for
foreign_proc, but as mentioned in other recent email, we are supposed to 
move towards 'csharp' 'C#' or whatever, and it is my intention to accept
whatever language specifier atom is expected by foreign_proc, foreign_decl and
foreign_code).


Now the first thing to do is consider that the scheme doesn't actually
work as stated above for the example I am specifically interested in,
and that is .NET using C# syntax (it also doesn't work for MC++ for
different reasons).

The problem is that you need to specify the assembly that each type
belongs to, and pass that as a command line option to the C# compiler.
The information required to do this came from the foreign_type declaration.
Under the new system I guess we would normally expect to parse the
string to find this information.

Since the foreign language (C#) has absolutely no syntax for specifying this
information (it can only be given using a command line option) and
there therefore going, we are going to have to invent some Mercury
syntax for it so that we can pass the appropriate command line option
to the C# compiler when it compiles the C# code we generate.

I know, I know, those poor Mercury users are going to have to learn a
new piece of syntax to replace the C# command-line options they know and
love, and it will be a confusing, bewildering thing for them, but we
cannot easily avoid this pain.  Unless you would like to have the mmc
commandline options also accept C# options, or give up our lovely
automatic dependency generation system... ;-)

So I propose that we make foreign_type have the following syntax for C#:

:- pragma foreign_type(xmldoc,
	csharp("System.XML", "System.Xml.XmlDocument")).

Alternatives could be:

:- pragma foreign_type(xmldoc, csharp("System.XML"), "System.Xml.XmlDocument").

For IL we can actually specify this as part of the type name.  Which is
just great because now it means we can either define IL types to be
similar to C# types:

:- pragma foreign_type(xmldoc, 
	il("System.XML", "System.Xml.XmlDocument")).

or in a different manner to C#, but using IL syntax:

:- pragma foreign_type(xmldoc,
	il("[System.XML]System.Xml.XmlDocument")).

Either way is sure to confuse somebody of course.  If we choose the
second method we also have to parse the string to extract the
information.




For MC++ we might want to do much the same as C# because in MC++ you have to
include the appropriate assembly using a #using statement
	#using <System.XML.dll>
(we haven't done much work using MC++ as the foreign language, so I
don't think we have any code to handle this at the moment).

So the foreign_type might be (if we try to be similar to C#):

:- pragma foreign_type(xmldoc,
	mcplusplus("System.XML.dll", "System::Xml::XmlDocument")).

Or we could force the user to include an appropriate foreign_decl:

:- pragma foreign_decl("MC++", "#using <System.XML.dll>").
:- pragma foreign_type(xmldoc, mcplusplus("System::Xml::XmlDocument")).

Or we could follow the language syntax more closely:

:- pragma foreign_type(xmldoc,
	mcplusplus("<System.XML.dll>", "System::Xml::XmlDocument")).

Or even:

:- pragma foreign_type(xmldoc,
	mcplusplus("#using <System.XML.dll>", "System::Xml::XmlDocument")).

But those last two might be a bit much, probably better to allow seach
paths to be set using some separate mechanism (command line options set
from the build environment).


So, time for another popularity contest (we will have to keep going with
these until people get bored):

I like:

:- pragma foreign_type(xmldoc,
	csharp("System.XML.dll", "System.Xml.XmlDocument")).

:- pragma foreign_type(xmldoc, 
	il("System.XML", "System.Xml.XmlDocument")).

:- pragma foreign_type(xmldoc, 
	mcplusplus("System.XML.dll", "System::Xml::XmlDocument")).

but I could live with

:- pragma foreign_type(xmldoc,
	csharp("System.XML.dll"), "System.Xml.XmlDocument").

(and similar changes for the others)

or maybe other minor changes.

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