[m-dev.] Re: conditional compilation

Julien Fischer juliensf at csse.unimelb.edu.au
Thu Jan 7 13:10:10 AEDT 2010

On Thu, 7 Jan 2010, Peter Wang wrote:

> On 2010-01-07, Julien Fischer <juliensf at csse.unimelb.edu.au> wrote:
>> How about this: add a pragma that that marks certain procedures as being
>> conditional on something, e.g.
>>     :- pragma conditional_proc(foo/2, [<conditions>]).
>>     :- pred foo(io::di, io::uo) is det.
> It wouldn't allow alternative clauses based on the condition.

I was attempting to deal with the problem that caused this thread
to be reopened:

     I'd also have to override any internal
     predicates used in the Mercury+C implementation even if they aren't
     used in the Java grade, because those predicates access fields in the
     Mercury types which are overridden.

The intention in the above is that <condtions> would say only look at
this procedure in C grades.  It doesn't, as you have noted, allow
for the selection of alternative clauses based on arbitrary conditions. 
Out of curiosity, were you envisaging conditions other than backend,
grade or command-line flags?


On a related note, it may be worth extending the implementation-defined
literal mechanism to allow arbitrary ground terms to be specified on
the command line.  This would allow for the selection of alternative
implementations based on command-line flags, e.g.

   :- type arch
 	---> 	x86
 	;	x86_64
 	;	powerpc.

   do_arch_specific_stuff(!IO) :-
 	Arch = $flag("ARCH"),
 		Arch = x86,
 		<x86 specific stuff>
 		Arch = x86_64,
 		<x86_64 specific stuff>
 		Arch = powerpc,

    $ mmc --cmdline-const="ARCH=x86"

Invoking the compiler with the above would cause all occurrences of
$flag("ARCH") to be replaced by "x86".  After simplification, only
the x86 specific branch in the above should remain.  (It would be
better to allow the definitions to be read from a file as well.)

I have often wanted something like this in G12, where we end up
generating modules containing system-specific information using
shell scripts or autoconf, which is quite error prone.  (You can
do that above using foreign langugage interface of course, but that
may well end up depriving mmc of possible optimization opportunities.)

I realise this doesn't help with at least some of Peter's problems, but
it seemed worth bringing up in the context of the discussion about
conditional compilation.

mercury-developers mailing list
Post messages to:       mercury-developers at csse.unimelb.edu.au
Administrative Queries: owner-mercury-developers at csse.unimelb.edu.au
Subscriptions:          mercury-developers-request at csse.unimelb.edu.au

More information about the developers mailing list