Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Kim Nguyen <nguyen@bk.ru>
To: Richard Jones <rich@annexia.org>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Accuracy of Gc.stat ()
Date: Sat, 22 Nov 2003 15:28:16 +0100	[thread overview]
Message-ID: <20031122152816.20e089ba.nguyen@bk.ru> (raw)
In-Reply-To: <20031122114908.GA11593@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 1723 bytes --]

Hello,

On Sat, 22 Nov 2003 11:49:08 +0000
Richard Jones <rich@annexia.org> wrote:


> > Neat trick. This _ought_ to work, but it doesn't for some reason:
> > 
> > 	let arg = (true, false) 
> > 	external is_bytecode : bool * bool -> bool = "%field0" "%field1" 
> >  
> > 	let () = 
> > 	  if is_bytecode arg then 
> > 	    print_endline "Bytecode!" 
> > 	  else 
> > 	    print_endline "Native!" 
> > 
> > Perhaps someone can explain why ...
> 
> OK, closer inspection of the manual[*] reveals why this doesn't work.
> Surely OCaml should flag the above code as a bug, because there are
> fewer than the magical 6 arguments?
> 
> Rich.

Well, my guess is that '%' primitives pre-defined in Ocaml are not compiled as
function. Some are just a way to bypass the typechecker (like %identity) and others
are directly translated to a sequence of bytecode/native instructions and inlined 
in the code. Thus when you use a "%primitive" in an external only the first declaration
 would by used, and so, the %field1 above would get ignored by the compiler. 
You can see it if you try to mix both kinds of primitive :

external is_bytecode : bool * bool -> bool = "field0_bytecode" "%field1" 

the compilation process fine but at link time, the linker complain about an undefiened
 symbol '$25field1'.
if you use :
external is_bytecode : bool * bool -> bool = "%field0" "field1_native"
then the "field1_native" is ignored %field0 is used in both cases.

Anyhow, I just meant to toy with the compiler and don't think using this 'feature' of
the compiler should be considered safe, as it is not specified in the documentation
(unless we have clearer explanation by an Ocaml guru :-). It could be a nice feature
though.

Regards,

Kim.

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

  parent reply	other threads:[~2003-11-22 14:25 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-11-19 17:52 Daniel Bünzli
2003-11-21 16:46 ` Damien Doligez
2003-11-22  0:20 ` Kim Nguyen
2003-11-22 11:43   ` Richard Jones
2003-11-22 11:49     ` Richard Jones
2003-11-22 14:20       ` Self-detection of native code execution (Was Re: [Caml-list] Accuracy of Gc.stat ()) Daniel Bünzli
2003-11-22 14:28         ` Richard Jones
2003-11-22 14:28       ` Kim Nguyen [this message]
2003-11-22 14:31         ` [Caml-list] Accuracy of Gc.stat () Richard Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20031122152816.20e089ba.nguyen@bk.ru \
    --to=nguyen@bk.ru \
    --cc=caml-list@inria.fr \
    --cc=rich@annexia.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox