Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Caml-list] Conditional compilation wrt OCaml version?

50 views
Skip to first unread message

David Rajchenbach-Teller

unread,
Jan 26, 2009, 4:25:06 PM1/26/09
to OCaml
Dear list,

Working on Batteries, we're faced with a few places where we'd like to
perform conditional compilation depending on the version of OCaml being
used. We could probably do this with Camlp4, cpp, Autoconf hackery, etc.
-- but first, we need to decide on which of these options we'll adopt.

Any suggestion?

Thanks in advance,
David

--
David Teller-Rajchenbach
Security of Distributed Systems
http://www.univ-orleans.fr/lifo/Members/David.Teller
La Recherche publique est liquidée. Les chercheurs sont en colère.
Latest News of French Research: System being liquidated. Researchers angry.

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Sylvain Le Gall

unread,
Jan 26, 2009, 4:40:56 PM1/26/09
to caml...@inria.fr
On 26-01-2009, David Rajchenbach-Teller <David....@ens-lyon.org> wrote:
> Dear list,
>
> Working on Batteries, we're faced with a few places where we'd like to
> perform conditional compilation depending on the version of OCaml being
> used. We could probably do this with Camlp4, cpp, Autoconf hackery, etc.
> -- but first, we need to decide on which of these options we'll adopt.
>
> Any suggestion?
>

There is optcomp:
https://forge.ocamlcore.org/projects/optcomp/
http://darcs.ocamlcore.org/repos/optcomp/optcomp/README

The example in README should talk to you directly.

Regards,
Sylvain Le Gall

Mikkel Fahnøe Jørgensen

unread,
Jan 26, 2009, 5:58:40 PM1/26/09
to David Rajchenbach-Teller, OCaml
> Working on Batteries, we're faced with a few places where we'd like to
> perform conditional compilation depending on the version of OCaml being
> used. We could probably do this with Camlp4, cpp, Autoconf hackery, etc.
> -- but first, we need to decide on which of these options we'll adopt.
>
> Any suggestion?

If you are interested in using ocamlbuild you can have a look at
ocamlbuild-ctools:

http://dvide.com/labs/ocamlbuild-ctools/

I added extensions to ocamlbuild using a syntax like

normalfile.o
[mytag,myothertag,~notthistag]
conditionalfile.o
..

this is done in a .cprog file that lists all files to include, but
that same could be done with other similar files e.g. .mllib

Also, I added multi-variant builds so the same build can handle
multiple build targets based on tags - for example debug and release
builds. Multivariant builds work by adding tags in the filename:
myfile.variant_release,mingw.o


Most of this could be integrated into ocamlbuild, but ocamlbuild is
not very actively maintained as I understand.

Mikkel

Jan Kybic

unread,
Jan 29, 2009, 3:44:18 AM1/29/09
to caml...@inria.fr
>> Working on Batteries, we're faced with a few places where we'd like to
>> perform conditional compilation depending on the version of OCaml being
>> used. We could probably do this with Camlp4, cpp, Autoconf hackery, etc.
>> -- but first, we need to decide on which of these options we'll adopt.
>>
>

Good morning. I have looked at ocamlopt and it looks very useful.
Are there any plans to include macro expansion in ocamlopt?
I mean something like merging the functionality of ocamlopt and
pa_macro but without the restrictions that pa_macro places on
where the macro can be used.

Besides conditional compilation - to try different variants of the
code or to have debugging messages which can be switched off without
any performance penalty - I would also like to use it for short pieces
of compile-time generated code (for speed up). Currently, I use a
Python-based templating system em.py
(http://www.alcyone.com/pyos/empy/) for this purpose. This works but
combining the way Python and Ocaml syntax is sometimes not very
intuitive.

It appears that a modern and universal tool for compile-time code
generation is MetaOcaml. However, is there a way in MetaOcaml to
generate the code just once and not every time the program is run? I
mean, can the code fragments be cached - saved into a file (a shared library?)
and later retrieved?

Thanks,

Jan

--
-------------------------------------------------------------------------
Jan Kybic <ky...@fel.cvut.cz> tel. +420 2 2435 5721
http://cmp.felk.cvut.cz/~kybic ICQ 200569450

David Rajchenbach-Teller

unread,
Jan 29, 2009, 4:21:38 AM1/29/09
to Sylvain Le Gall, caml...@inria.fr
Exactly what I needed.

Thanks,
David

On Mon, 2009-01-26 at 21:40 +0000, Sylvain Le Gall wrote:

> There is optcomp:
> https://forge.ocamlcore.org/projects/optcomp/
> http://darcs.ocamlcore.org/repos/optcomp/optcomp/README
>
> The example in README should talk to you directly.

--

David Teller-Rajchenbach
Security of Distributed Systems
http://www.univ-orleans.fr/lifo/Members/David.Teller
La Recherche publique est liquidée. Les chercheurs sont en colère.
Latest News of French Research: System being liquidated. Researchers angry.

_______________________________________________

Jérémie Dimino

unread,
Jan 29, 2009, 8:00:27 AM1/29/09
to Jan Kybic, caml...@inria.fr

Jan Kybic <ky...@fel.cvut.cz> writes:

> Good morning. I have looked at ocamlopt and it looks very useful.
> Are there any plans to include macro expansion in ocamlopt?

Right now there is no plan for that. My only intention when i started
optcomp was conditional compilation, and i made choices making it
incompatible with macro expansion.

By the way, it would be easy to transform it into a macro expansion
system.

> I mean something like merging the functionality of ocamlopt and
> pa_macro but without the restrictions that pa_macro places on
> where the macro can be used.

Yes, these restrictions could be bypassed because it modify directly the
stream of tokens.

The disadvantage of dealing with macros is for expressions needing to be
evaluated at compile time. For example in that case, assuming the
variable "x" is not defined:

,----
| #let y = x
|
| #if y
| ...
| #endif
`----

the error would be raised at the "#if y" line. Whereas it is raised at
the "#let y = x" line with optcomp. That is mostly why i decided not to
design it as a macro expansion system.

Jérémie

0 new messages