[email protected] wrote:
> I suppose you don't want to use any kind of preprocessor, do you ?
I'd rather not preprocess (or compile alternate files). Both the
netnumber and core implementations use a preprocessor.
Preprocessor-based solutions have two problems. One is the extra
compilation step. Another is bitrot in the unused case.
I think it was Plan 9 where the documentation said don't use the
C preprocessor, our compiler does the right thing with if (false).
In ocaml what I'd like to say is
module Int : sig
type t
val add : t -> t -> t
...
end;
module Intfast : Int = struct type t = int ... end
module Int = if sixtyfour then Int end else Int32
with the understanding that the expression sixtyfour is evaluated
at compile time.
Here is some similar code using 3.12 syntax:
module type M = sig type t val add : t -> t -> t val of_int : int -> t
end;;
module Int : M = struct type t = int let add = (+) let of_int x = x
end;;
module M = (val (if Sys.word_size = 64 then (module Int : M) else
(module Int32 : M)) : M);;
let f x = M.add (M.of_int x) (M.of_int 1)
If the test (Sys.word_size = 64) is replaced by (true) this does what
I want. The compiler looks through the packing and unpacking and
sees the module Int. The body of function f compiles to a machine add
instruction.
Ocamlopt does not evaluate (Sys.word_size = 64) at compile time
because Sys.word_size is initialized at runtime. See sys.ml line 26
and run objinfo on sys.cmx.
INRIA developers, is it easy to add an intrinsic so we can write
extern word_size : int = "%caml_word_size"
in sys.ml? If sys.cmx has a constant definition, ocamlopt should do
constant folding on conditional expressions testing Sys.word_size.
If I want to do conditional compilation, can ocamlbuild be taught
"compile file a.ml as module X on 32 bit systems and module b.ml as
module X on 64 bit systems"?
--John Carr ([email protected])
--
Caml-list mailing list. Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs