I think the (old) reason of the way Sys.word_size is implemented is that the same code can run both on 32 bits and 64 bits, when compiled to bytecode. But of course, I see no reason why such a primitive could not be added, with different compilation schemes for asm (it would be hard coded) and bytecode (it would continue to call the runtime function). Fabrice On 09/06/2011 12:11 AM, John Carr wrote: > 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;; > >