[m-dev.] Re: conditional compilation
Paul Bone
pbone at csse.unimelb.edu.au
Tue Jan 5 18:30:21 AEDT 2010
On Tue, Jan 05, 2010 at 05:41:08PM +1100, Peter Wang wrote:
> 2009/3/25 Peter Wang <novalazy at gmail.com>:
> > Hi,
> >
> > Here is another idea: conditional sections, where a section is kept or
> > omitted depending on compile time flags and/or grades. If we borrow the
> > feature from trace goals, we might have something like this:
> >
> > :- implementation(not(flag("production"))).
> ...
> > 2. Modules which paper over platform differences or work with optional
> > dependencies would be easier to write, or become possible without an
> > explicitly preprocessing pass. Any number of situations, really.
>
> I didn't get any response to this last year. Today I came across
> another situation where it would really help.
>
> The problem is that I have a Mercury+C implementation of a network
> protocol. In Java grades I don't want that implementation, I want to
> call an external Java library instead. I can use "Java" foreign_procs
> to override the Mercury predicates, and foreign_types to override the
> Mercury types. However, 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.
>
> With conditional implementation sections I could cleanly separate the
> two completely different implementations, while providing the single
> module interface.
An extra benefit that we can get here is that the 'disabled' sections can be
error checked but not compiled. This can help us verify that these sections
are correct even when they aren't applicable to the current backend/platform.
This idea sounds reasonable, I can't imagine any drawbacks.
This would also give us the ability to write test code within the same module
as the real code without adding unnecessary code to the final program.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 489 bytes
Desc: Digital signature
URL: <http://lists.mercurylang.org/archives/developers/attachments/20100105/4d5301db/attachment.sig>
More information about the developers
mailing list