1 /**************************************************************************/
2 /*                                                                        */
3 /*                                 OCaml                                  */
4 /*                                                                        */
5 /*              Damien Doligez, projet Para, INRIA Rocquencourt           */
6 /*                                                                        */
7 /*   Copyright 1996 Institut National de Recherche en Informatique et     */
8 /*     en Automatique.                                                    */
9 /*                                                                        */
10 /*   All rights reserved.  This file is distributed under the terms of    */
11 /*   the GNU Lesser General Public License version 2.1, with the          */
12 /*   special exception on linking described in the file LICENSE.          */
13 /*                                                                        */
14 /**************************************************************************/
15 
16 #ifndef CAML_GC_H
17 #define CAML_GC_H
18 
19 
20 #include "mlvalues.h"
21 
22 #define Caml_white (0 << 8)
23 #define Caml_gray  (1 << 8)
24 #define Caml_blue  (2 << 8)
25 #define Caml_black (3 << 8)
26 
27 #define Color_hd(hd) ((color_t) ((hd) & Caml_black))
28 #define Color_hp(hp) (Color_hd (Hd_hp (hp)))
29 #define Color_val(val) (Color_hd (Hd_val (val)))
30 
31 #define Is_white_hd(hd) (Color_hd (hd) == Caml_white)
32 #define Is_gray_hd(hd) (Color_hd (hd) == Caml_gray)
33 #define Is_blue_hd(hd) (Color_hd (hd) == Caml_blue)
34 #define Is_black_hd(hd) (Color_hd (hd) == Caml_black)
35 
36 #define Whitehd_hd(hd) (((hd)  & ~Caml_black)/*| Caml_white*/)
37 #define Grayhd_hd(hd)  (((hd)  & ~Caml_black)  | Caml_gray)
38 #define Blackhd_hd(hd) (((hd)/*& ~Caml_black*/)| Caml_black)
39 #define Bluehd_hd(hd)  (((hd)  & ~Caml_black)  | Caml_blue)
40 
41 /* This depends on the layout of the header.  See [mlvalues.h]. */
42 #define Make_header(wosize, tag, color)                                       \
43       (/*Assert ((wosize) <= Max_wosize),*/                                   \
44        ((header_t) (((header_t) (wosize) << 10)                               \
45                     + (color)                                                 \
46                     + (tag_t) (tag)))                                         \
47       )
48 
49 #ifdef WITH_PROFINFO
50 #define Make_header_with_profinfo(wosize, tag, color, profinfo)               \
51       (Make_header(wosize, tag, color)                                        \
52         | ((((intnat) profinfo) & PROFINFO_MASK) << PROFINFO_SHIFT)           \
53       )
54 #else
55 #define Make_header_with_profinfo(wosize, tag, color, profinfo) \
56   Make_header(wosize, tag, color)
57 #endif
58 
59 #ifdef WITH_SPACETIME
60 struct ext_table;
61 extern uintnat caml_spacetime_my_profinfo(struct ext_table**, uintnat);
62 #define Make_header_allocated_here(wosize, tag, color)                        \
63       (Make_header_with_profinfo(wosize, tag, color,                          \
64         caml_spacetime_my_profinfo(NULL, wosize))                             \
65       )
66 #else
67 #define Make_header_allocated_here Make_header
68 #endif
69 
70 #define Is_white_val(val) (Color_val(val) == Caml_white)
71 #define Is_gray_val(val) (Color_val(val) == Caml_gray)
72 #define Is_blue_val(val) (Color_val(val) == Caml_blue)
73 #define Is_black_val(val) (Color_val(val) == Caml_black)
74 
75 /* For extern.c */
76 #define Colornum_hd(hd) ((color_t) (((hd) >> 8) & 3))
77 #define Coloredhd_hd(hd,colnum) (((hd) & ~Caml_black) | ((colnum) << 8))
78 
79 #endif /* CAML_GC_H */
80