On 04/09/2013 01:38 PM, Étienne André wrote:As others suggested, you can tell your build system to generate an ad hoc file containing the compile-time information. Another approach is to use a preprocessor to inject such compile-time information into the source code "on the fly" during its compilation. This can be done with a dedicated Camlp4 syntax extension or a -ppx preprocessor (available in trunk only, with syntactic extension points being designed in the extension_points branch of the OCaml SVN).
I quite stupidly used the Unix.gettimeofday() function before realizing
that it is of course executed at runtime.
As an illustration of the -ppx approach, I've created a tiny preprocessor which uses the OCaml toplevel to evaluate expressions and inserts the result as constants in the compiled code.
The source code for this -ppx preprocessor can be found here:
http://caml.inria.fr/cgi-bin/viewvc.cgi/ocaml/branches/extension_points/experimental/frisch/eval.ml?&view=markup
and here is an example of what you can write with it:
http://caml.inria.fr/cgi-bin/viewvc.cgi/ocaml/branches/extension_points/experimental/frisch/test_eval.ml?&view=markup
(To play with it, you need to checkout the extension_points branch and after compiling it: cd experimental/frisch && make eval)
-- Alain
--
Caml-list mailing list. Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs