I found a simpler way to make Sys.word_size be a compile time constant.
See patch at end. Technically this is preprocessing, which I wanted to
avoid, but it's not preprocessing in my code.
> 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.
diff -rc /tmp/ocaml-3.12.1/stdlib/Makefile.shared ./stdlib/Makefile.shared
*** /tmp/ocaml-3.12.1/stdlib/Makefile.shared Fri May 21 07:28:21 2010
--- ./stdlib/Makefile.shared Mon Sep 5 17:39:14 2011
***************
*** 49,56 ****
stdlib.cmxa: $(OBJS:.cmo=.cmx)
$(CAMLOPT) -a -o stdlib.cmxa $(OBJS:.cmo=.cmx)
! sys.ml: sys.mlp ../VERSION
! sed -e "s|%%VERSION%%|`sed -e 1q ../VERSION`|" sys.mlp >sys.ml
clean::
rm -f sys.ml
--- 49,57 ----
stdlib.cmxa: $(OBJS:.cmo=.cmx)
$(CAMLOPT) -a -o stdlib.cmxa $(OBJS:.cmo=.cmx)
! sys.ml: sys.mlp ../VERSION ../config/m.h
! ws=`sed -n -e 's/^#define ARCH_SIXTYFOUR/64/p' -e 's/^#undef
ARCH_SIXTYFOUR/32/p' ../config/m.h`; \
! sed -e "s|%%VERSION%%|`sed -e 1q ../VERSION`|" -e
"s|%%WORD_SIZE%%|$$ws|" sys.mlp >sys.ml
clean::
rm -f sys.ml
diff -rc /tmp/ocaml-3.12.1/stdlib/sys.mlp ./stdlib/sys.mlp
*** /tmp/ocaml-3.12.1/stdlib/sys.mlp Mon Feb 26 09:21:57 2007
--- ./stdlib/sys.mlp Mon Sep 5 17:35:33 2011
***************
*** 23,29 ****
external get_argv: unit -> string * string array = "caml_sys_get_argv"
let (executable_name, argv) = get_argv()
! let (os_type, word_size) = get_config()
let max_array_length = (1 lsl (word_size - 10)) - 1;;
let max_string_length = word_size / 8 * max_array_length - 1;;
--- 23,30 ----
external get_argv: unit -> string * string array = "caml_sys_get_argv"
let (executable_name, argv) = get_argv()
! let (os_type, _) = get_config()
! let word_size = %%WORD_SIZE%%;;
let max_array_length = (1 lsl (word_size - 10)) - 1;;
let max_string_length = word_size / 8 * max_array_length - 1;;
--
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