From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p85FGVP3010695 for ; Mon, 5 Sep 2011 17:16:38 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ao8BANzmZE4SCRkOmWdsb2JhbABDmRePARQBAQEBAQYNCwcUJoFGAQEEASdXCwtGVxkbh1ivO4h/hmoEpFc X-IronPort-AV: E=Sophos;i="4.68,333,1312149600"; d="scan'208";a="107784048" Received: from dmz-mailsec-scanner-3.mit.edu ([18.9.25.14]) by mail4-smtp-sop.national.inria.fr with ESMTP; 05 Sep 2011 17:16:37 +0200 X-AuditID: 1209190e-b7c60ae000000a26-d1-4e64e74ece05 Received: from mailhub-auth-3.mit.edu ( [18.9.21.43]) by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP id 46.1B.02598.E47E46E4; Mon, 5 Sep 2011 11:14:22 -0400 (EDT) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id p85FGZCu005566 for ; Mon, 5 Sep 2011 11:16:35 -0400 Received: from localhost (CONTENTS-VNDER-PRESSVRE.MIT.EDU [18.9.64.11]) (authenticated bits=0) (User authenticated as jfc@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id p85FGX80005823 for ; Mon, 5 Sep 2011 11:16:34 -0400 (EDT) Message-Id: <201109051516.p85FGX80005823@outgoing.mit.edu> To: caml-list@inria.fr In-reply-to: <20110905072553.GA32471@ccellier.rd.securactive.lan> References: <201109041522.p84FM5DA001371@outgoing.mit.edu> <20110905072553.GA32471@ccellier.rd.securactive.lan> Comments: In-reply-to rixed@happyleptic.org message dated "Mon, 05 Sep 2011 09:25:53 +0200." X-Mailer: MH-E 8.2; nmh 1.3; GNU Emacs 23.1.1 Date: Mon, 05 Sep 2011 11:16:33 -0400 From: John Carr X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrAIsWRmVeSWpSXmKPExsUixCmqrev3PMXPYPY7BYtPOzawODB6THpx iCWAMYrLJiU1J7MstUjfLoEr49idmIL9/BUflmxmbWBs4Oli5OSQEDCR2D5tHxOELSZx4d56 NhBbSGAfo8TDHpcuRi4g+wSjxNeP/ewQzgwmiYWPJrCCVPEKWEnM3HySBcQWAeqeNf8KmC0s YCtx6Ms8oEkcHJwCjhJTl2dCDM2X+Hj/FTuIzSyQIPG4EaJcQkBX4uOimWBxFgFViUXTn4Md xCYgK/GovYtxAiPfAkaGVYyyKblVurmJmTnFqcm6xcmJeXmpRbrGermZJXqpKaWbGMGBIcm3 g/HrQaVDjAIcjEo8vB3Lk/2EWBPLiitzDzFKcjApifJmPknxE+JLyk+pzEgszogvKs1JLT7E KMHBrCTCe+YsUI43JbGyKrUoHyYlzcGiJM67eoeDn5BAemJJanZqakFqEUxWhoNDSYLXChgB QoJFqempFWmZOSUIaSYOTpDhPEDDFUFqeIsLEnOLM9Mh8qcYdTna9y88zijEkpeflyolzssJ UiQAUpRRmgc3BxbRrxjFgd4S5jUAqeIBJgO4Sa+AljABLXG1SgJZUpKIkJJqYKzjPm5y5EZn m4PYPNvtpZpaLz95uIcyZWn/sj1SIZie7SqZWJI8RVzR+cKztX4lvp8frbD6uErBWnrOu39P J9X4ywSddNopfKaE72puh/L5qT3qV39OVJz578ORX2pP/5mnL9hcqOTT9bk4deWW3pfduV69 Yhs73IX6fPhlnP55nVj8bFLIdSWW4oxEQy3mouJEALTrGTnDAgAA Subject: Re: [Caml-list] Conditionally boxed 32 bit integers? rixed@happyleptic.org 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 (jfc@mit.edu)