From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id BAA20738; Sat, 22 Nov 2003 01:18:27 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id BAA22142 for ; Sat, 22 Nov 2003 01:18:26 +0100 (MET) Received: from mx2.mail.ru (mx2.mail.ru [194.67.23.22]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id hAM0IP119193 for ; Sat, 22 Nov 2003 01:18:25 +0100 (MET) Received: from [81.56.190.171] (port=33950 helo=localhost) by mx2.mail.ru with smtp id 1ANLTk-000Eg4-00 for caml-list@inria.fr; Sat, 22 Nov 2003 03:18:24 +0300 Date: Sat, 22 Nov 2003 01:20:54 +0100 From: Kim Nguyen To: caml-list@inria.fr Subject: Re: [Caml-list] Accuracy of Gc.stat () Message-Id: <20031122012054.0dbd44e2.nguyen@bk.ru> In-Reply-To: <1970C334-1AB9-11D8-ADB3-000393DBC266@epfl.ch> References: <1970C334-1AB9-11D8-ADB3-000393DBC266@epfl.ch> X-Mailer: Sylpheed version 0.9.6claws (GTK+ 1.2.10; i386-pc-linux-gnu) Mime-Version: 1.0 Content-Type: multipart/signed; protocol="application/pgp-signature"; micalg="pgp-sha1"; boundary="Signature=_Sat__22_Nov_2003_01_20_54_+0100_tqr2In9DANrTP=L3" X-Loop: caml-list@inria.fr X-Spam: no; 0.00; kim:99 caml-list:01 runtime:01 endline:01 endline:01 mlvalues:01 camlprim:01 val:01 camlprim:01 val:01 gcc:01 ocamlc:01 ocamlc:01 -use-runtime:01 ocamlopt:01 X-Attachments: type="application/pgp-signature" Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk --Signature=_Sat__22_Nov_2003_01_20_54_+0100_tqr2In9DANrTP=L3 Content-Type: text/plain; charset=ISO-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi, On Wed, 19 Nov 2003 18:52:10 +0100 Daniel B=FCnzli wrote: >=20 > 3) Is it possible to know at runtime whether we are running native code=20 > or interpreted bytecode ? >=20 There is actualy an (ugly) hack which seems to work, but it requires few li= nes of C codes : --- prog.ml -- (* An external declaration, first C function is used when compiled to bytec= ode,=20 second when compiled to native code. *) external is_bytecode : unit -> bool =3D "is_bytecode_bytecode" "is_bytecode= _native" (* And now you can use it... *) let _ =3D=20 if is_bytecode ()=20 then=20 print_endline "Bytecode !!!" else print_endline "Native code !!!" ----------- --- bytecode.c ----- #include CAMLprim value is_bytecode_bytecode(value unit){ return Val_true; } CAMLprim value is_bytecode_native(value unit){ return Val_false; } ------------- Et voil=E0 ! Linking native caml code with this C code isn't a big deal but, linking with bytecode make you somehow loose the portability of the later.=20 See the corresponding chapter in the Ocaml manual (Chapter 18). $ gcc -c bytecode.c $ ocamlc -make-runtime -o myruntime bytecode.o $ ocamlc -o prog -use-runtime ./myruntime prog.ml $ ocamlopt -o prog.opt bytecode.o prog.ml $ ./prog Bytecode !!! $ ./prog.opt Native code !!! I wonder if there is a cleaner way to do this. Maybe there could be a flag = like the Sys.interactive one. I'd like to know how "safe" is this code, the beh= avior=20 of the compiler is only described for function with more than 5 arguments i= n=20 the manual. Cheers. Kim Nguyen. --Signature=_Sat__22_Nov_2003_01_20_54_+0100_tqr2In9DANrTP=L3 Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.3 (GNU/Linux) iD8DBQE/vqvpGqhFkfuNlVkRAh9jAJ9WOz4otpTQ8M7r3H9bPyK5NO06dwCcCP/h 48AzSxCygfIutimTBZBjSx4= =leoR -----END PGP SIGNATURE----- --Signature=_Sat__22_Nov_2003_01_20_54_+0100_tqr2In9DANrTP=L3-- ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners