caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Data representation of records
@ 2016-01-19  8:54 Ryohei Tokuda
  2016-01-19  9:07 ` Leo White
  0 siblings, 1 reply; 2+ messages in thread
From: Ryohei Tokuda @ 2016-01-19  8:54 UTC (permalink / raw)
  To: caml-list

Dear the compiler developers,

I am just curious about memory representation of records.
When I read dump of `clambda`, I felt the representation of records a
little bit strange.
In the following program, functions just create the variants and records.

a.ml

  type t = A of int | B of float
  type r1 = {x:int; y:float}

  let make_a x = A x
  let make_b x = B x
  let make_r1 x y = {x;y}

  type r2 = {a:int; b:int}

  let make_r2 a b = {a; b}

The result of `ocamlopt -dclambda -c a.ml` show the following.

(seq
  (let
    (make_a/1014
       (closure  (fun camlA__make_a_1014 1  x/1015 (makeblock 0 x/1015)) ))
    (setfield_imm 0 (global camlA!) make_a/1014))
  (let
    (make_b/1016
       (closure  (fun camlA__make_b_1016 1  x/1017 (makeblock 1 x/1017)) ))
    (setfield_imm 1 (global camlA!) make_b/1016))
  (let
    (make_r/1018
       (closure
         (fun camlA__make_r_1018 2  x/1019 y/1020 (makeblock 0 x/1019
y/1020)) ))
    (setfield_imm 3 (global camlA!) make_r/1018))
  (let
    (make_r/1024
       (closure
         (fun camlA__make_r_1024 2  a/1025 b/1026 (makeblock 0 a/1025
b/1026)) ))
    (setfield_imm 2 (global camlA!) make_r/1024))
  0a)

This dump of IL is likely to show:
- `makeblock` seems like `alloc`, which first argument is the label.
- `makeblock` creates  variants, and labels are different in A and B
(0 for A, and 1 for B).
- `makeblock` also creates records, and the label seems always 0.

I checked the above understanding by reading output assemblies,
I believe it is right comprehension.

My question is, why records need the labels.
In my comprehension, there is no chance that we check the label of records.

Thanks.

-- 
Ryohei Tokuda

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-01-19  9:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-19  8:54 [Caml-list] Data representation of records Ryohei Tokuda
2016-01-19  9:07 ` Leo White

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).