caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jianzhou Zhao <jianzhou@seas.upenn.edu>
To: Sylvain Le Gall <sylvain@le-gall.net>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Re: OCaml/C variant representation
Date: Sun, 28 Feb 2010 10:16:12 -0500	[thread overview]
Message-ID: <9dfe358d1002280716t4b756138m476455f1e86e44be@mail.gmail.com> (raw)
In-Reply-To: <slrnhoaln2.ckm.sylvain@gallu.homelinux.org>

On Wed, Feb 24, 2010 at 11:42 AM, Sylvain Le Gall <sylvain@le-gall.net> wrote:
> Hello,
>
> On 24-02-2010, Jean Yang <jeanyang@csail.mit.edu> wrote:
>> Hello,
>>
>>   I'm having some trouble with variant representation in the OCaml/C
>> interface.
>>
>>   According to the reference I found (
>> http://caml.inria.fr/pub/docs/manual-ocaml/manual032.html), it seems like if
>> we have value v = variant VConstr(val), where val is some integer value,
>> should have Field(val, 0) == hash_variant("VConstr") and Int_val(Field(v, 0)
>>== val.  I don't seem to be understanding this correctly, since I am getting
>> Int_val(Field(v, 0)) == val.
>>
>>   I have the following datatype declaration in my OCaml:
>> type newty = VConstr of int | ...
>> In the C implementation of OCaml function foo : newty -> int, I have
>> something like this;
>>   CAMLprim value foo (value v) {  ... }
>> In the body of this function I am looking at the fields of val.  Am I doing
>> something wrong here?
>>
>
> Please have a look at:
> http://caml.inria.fr/mantis/view.php?id=4803
>
> This section is misleading. You should use hash_variant for `VConstr.
>
> In your case VConstr of int will be Block with size = 1 and tag = 0;
> first non-constant constructor and first field contains Value_int(...)

If I am creating an OCaml variant (string option) from C, say using 'alloc',
does it matter which tag I am using for 'some'? Can it be only tag 0?
I was looking at LLVM OCamling bindings, sometimes the 'some' is
also of 'tag 1', which confused me.

If my variant is A | B | C of int | D of int, does C have to start from tag 0?
and D must be 1? Similarly, does A have to be assigned into Val_int(0),
and B is from 1?

Thanks.

Zjz

>
> Regards
> Sylvain Le Gall
>
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>


  reply	other threads:[~2010-02-28 15:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-24 15:26 Jean Yang
2010-02-24 16:42 ` Sylvain Le Gall
2010-02-28 15:16   ` Jianzhou Zhao [this message]
2010-02-28 16:22     ` Sylvain Le Gall
2010-02-24 23:07 ` [Caml-list] " 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=9dfe358d1002280716t4b756138m476455f1e86e44be@mail.gmail.com \
    --to=jianzhou@seas.upenn.edu \
    --cc=caml-list@inria.fr \
    --cc=sylvain@le-gall.net \
    /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;
as well as URLs for NNTP newsgroup(s).