Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/trunk/src/runtime/include/tags.h
ViewVC logotype

Annotation of /sml/trunk/src/runtime/include/tags.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 249 - (view) (download) (as text)
Original Path: sml/branches/SMLNJ/src/runtime/include/tags.h

1 : monnier 249 /* tags.h
2 :     *
3 :     * COPYRIGHT (c) 1992 by AT&T Bell Laboratories.
4 :     *
5 :     * These are the macros for object tags and descriptors.
6 :     */
7 :    
8 :     #ifndef _TAGS_
9 :     #define _TAGS_
10 :    
11 :     #if defined(_ASM_) && defined(OPSYS_WIN32)
12 :     #define HEXLIT(x) CONCAT3(0,x,h)
13 :     #define OROP OR
14 :     #define ANDOP AND
15 :     #else
16 :     #define HEXLIT(y) CONCAT(0x,y)
17 :     #define OROP |
18 :     #define ANDOP &
19 :     #endif
20 :    
21 :     #define MAJOR_MASK HEXLIT(3) /* bits 0-1 are the major tag */
22 :    
23 :     #ifdef BOXED1
24 :     /* Major tag: */
25 :     #define TAG_boxed HEXLIT(1) /* 01 - pointers */
26 :     #define TAG_desc HEXLIT(3) /* 11 - descriptors */
27 :     #define TAG_unboxed_b0 HEXLIT(0) /* 00, 10 - unboxed (bit 0 is 0) */
28 :    
29 :     /* mark/unmark an ML pointer to make it look like an unboxed object */
30 :     #define MARK_PTR(p) ((ml_val_t)((Addr_t)(p) ANDOP ~HEXLIT(1)))
31 :     #define UNMARK_PTR(p) ((ml_val_t)((Addr_t)(p) OROP HEXLIT(1)))
32 :    
33 :     #else /* BOXED1 */
34 :     /* Major tag: */
35 :     #define TAG_boxed HEXLIT(0) /* 00 - pointers */
36 :     #define TAG_desc HEXLIT(2) /* 10 - descriptors */
37 :     #define TAG_unboxed_b0 HEXLIT(1) /* 01, 11 - unboxed (bit 0 is 1) */
38 :    
39 :     /* mark/unmark an ML pointer to make it look like an unboxed object */
40 :     #define MARK_PTR(p) ((ml_val_t)((Addr_t)(p) OROP HEXLIT(1)))
41 :     #define UNMARK_PTR(p) ((ml_val_t)((Addr_t)(p) ANDOP ~HEXLIT(1)))
42 :    
43 :     #endif /* BOXED1 */
44 :    
45 :     /* Descriptors have five more tag bits (defined below). */
46 :     #define DTAG_SHIFTW 2
47 :     #define DTAG_WID 5
48 :     #define DTAG_MASK (((1 << DTAG_WID)-1) << DTAG_SHIFTW)
49 :     #define TAG_SHIFTW (DTAG_SHIFTW+DTAG_WID)
50 :    
51 :     #define DTAG_record HEXLIT(0) /* records (including pairs) */
52 :     #define DTAG_vec_hdr HEXLIT(1) /* vector header; length is kind */
53 :     #define DTAG_vec_data DTAG_record /* polymorphic vector data */
54 :     #define DTAG_arr_hdr HEXLIT(2) /* array header; length is kind */
55 :     #define DTAG_arr_data HEXLIT(3) /* polymorphic array data */
56 :     #define DTAG_ref DTAG_arr_data /* reference cell */
57 :     #define DTAG_raw32 HEXLIT(4) /* 32-bit aligned non-pointer data */
58 :     #define DTAG_raw64 HEXLIT(5) /* 64-bit aligned non-pointer data */
59 :     #define DTAG_special HEXLIT(6) /* Special object; length is kind */
60 :     #define DTAG_extern HEXLIT(10) /* external symbol reference (used in */
61 :     /* exported heap images) */
62 :     #define DTAG_forward HEXLIT(1F) /* a forwarded object */
63 :    
64 :     /* Vector and array headers come in different kinds; the kind tag is stored
65 :     * in the length field of the descriptor. We need these codes for polymorphic
66 :     * equality and pretty-printing.
67 :     */
68 :     #define SEQ_poly HEXLIT(0)
69 :     #define SEQ_word8 HEXLIT(1)
70 :     #define SEQ_word16 HEXLIT(2)
71 :     #define SEQ_word31 HEXLIT(3)
72 :     #define SEQ_word32 HEXLIT(4)
73 :     #define SEQ_real32 HEXLIT(5)
74 :     #define SEQ_real64 HEXLIT(6)
75 :    
76 :     /* Build a descriptor from a descriptor tag and a length */
77 :     #ifndef _ASM_
78 :     #define MAKE_TAG(t) (((t) << DTAG_SHIFTW) OROP TAG_desc)
79 :     #define MAKE_DESC(l,t) ((ml_val_t)(((l) << TAG_SHIFTW) OROP MAKE_TAG(t)))
80 :     #else
81 :     #define MAKE_TAG(t) (((t)*4) + TAG_desc)
82 :     #define MAKE_DESC(l,t) (((l)*128) + MAKE_TAG(t))
83 :     #endif
84 :    
85 :     #define DESC_pair MAKE_DESC(2, DTAG_record)
86 :     #define DESC_exn MAKE_DESC(3, DTAG_record)
87 :     #define DESC_ref MAKE_DESC(1, DTAG_ref)
88 :     #define DESC_reald MAKE_DESC(2, DTAG_raw64)
89 :     #define DESC_polyvec MAKE_DESC(SEQ_poly, DTAG_vec_hdr)
90 :     #define DESC_polyarr MAKE_DESC(SEQ_poly, DTAG_arr_hdr)
91 :     #define DESC_word8arr MAKE_DESC(SEQ_word8, DTAG_arr_hdr)
92 :     #define DESC_string MAKE_DESC(SEQ_word8, DTAG_vec_hdr)
93 :     #define DESC_real64arr MAKE_DESC(SEQ_real64, DTAG_arr_hdr)
94 :    
95 :     #define DESC_forwarded MAKE_DESC(0, DTAG_forward)
96 :    
97 :     /* There are two kinds of special objects: suspensions and weak pointers
98 :     * The length field of these defines the state and kind of special object:
99 :     */
100 :     #define SPCL_evaled_susp 0 /* unevaluated suspension */
101 :     #define SPCL_unevaled_susp 1 /* evaluated suspension */
102 :     #define SPCL_weak 2 /* weak pointer */
103 :     #define SPCL_null_weak 3 /* nulled weak pointer */
104 :    
105 :     #define DESC_evaled_susp MAKE_DESC(SPECIAL_evaled_susp, DTAG_special)
106 :     #define DESC_unevaled_susp MAKE_DESC(SPCL_unevaled_susp, DTAG_special)
107 :     #define DESC_weak MAKE_DESC(SPCL_weak, DTAG_special)
108 :     #define DESC_null_weak MAKE_DESC(SPCL_null_weak, DTAG_special)
109 :    
110 :     /* tests on words:
111 :     * isBOXED(W) -- true if W is tagged as an boxed value
112 :     * isUNBOXED(W) -- true if W is tagged as an unboxed value
113 :     * isDESC(W) -- true if W is tagged as descriptor
114 :     */
115 :     #define isBOXED(W) (((Word_t)(W) & MAJOR_MASK) == TAG_boxed)
116 :     #define isUNBOXED(W) (((Word_t)(W) & 1) == TAG_unboxed_b0)
117 :     #define isDESC(W) (((Word_t)(W) & MAJOR_MASK) == TAG_desc)
118 :    
119 :     /* extract descriptor fields */
120 :     #define GET_LEN(D) (((Word_t)(D)) >> TAG_SHIFTW)
121 :     #define GET_TAG(D) ((((Word_t)(D)) ANDOP DTAG_MASK) >> DTAG_SHIFTW)
122 :    
123 :     #endif /* !_TAGS_ */

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0