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 2 - (view) (download) (as text)

1 : monnier 2 /* 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 :     /* High bit of descriptor for objects with */
29 :     /* a length operation is unboxed bit-0: */
30 :     #define HASLEN HEXLIT(0) /* 0xxx - objects with length */
31 :     #define NOLEN HEXLIT(8) /* 1xxx - objects without a length */
32 :    
33 :     /* mark/unmark an ML pointer to make it look like an unboxed object */
34 :     #define MARK_PTR(p) ((ml_val_t)((Addr_t)(p) ANDOP ~HEXLIT(1)))
35 :     #define UNMARK_PTR(p) ((ml_val_t)((Addr_t)(p) OROP HEXLIT(1)))
36 :    
37 :     #else /* BOXED1 */
38 :     /* Major tag: */
39 :     #define TAG_boxed HEXLIT(0) /* 00 - pointers */
40 :     #define TAG_desc HEXLIT(2) /* 10 - descriptors */
41 :     #define TAG_unboxed_b0 HEXLIT(1) /* 01, 11 - unboxed (bit 0 is 1) */
42 :     /* High bit of descriptor for objects with */
43 :     /* a length operation is unboxed bit-0: */
44 :     #define HASLEN HEXLIT(8) /* 1xxx - objects with length */
45 :     #define NOLEN HEXLIT(0) /* 0xxx - objects without length */
46 :    
47 :     /* mark/unmark an ML pointer to make it look like an unboxed object */
48 :     #define MARK_PTR(p) ((ml_val_t)((Addr_t)(p) OROP HEXLIT(1)))
49 :     #define UNMARK_PTR(p) ((ml_val_t)((Addr_t)(p) ANDOP ~HEXLIT(1)))
50 :    
51 :     #endif /* BOXED1 */
52 :    
53 :     /* Descriptors have four more tag bits (defined below). For objects that
54 :     * have a ML length operation, the high bit is the unboxed bit-0 value. */
55 :     #define DTAG_SHIFTW 2
56 :     #define DTAG_WID 4
57 :     #define DTAG_MASK (((1 << DTAG_WID)-1) << DTAG_SHIFTW)
58 :     #define TAG_SHIFTW (DTAG_SHIFTW+DTAG_WID)
59 :    
60 :     #define DTAG_record (HASLEN OROP HEXLIT(0)) /* records (len != 2) and vectors */
61 :     #define DTAG_vector DTAG_record
62 :     #define DTAG_array (HASLEN OROP HEXLIT(1)) /* arrays and refs */
63 :     #define DTAG_string (HASLEN OROP HEXLIT(2)) /* strings */
64 :     /* (HASLEN OROP HEXLIT(3)) unused */
65 :     #define DTAG_bytearray (HASLEN OROP HEXLIT(4)) /* bytearrays */
66 :     #define DTAG_realdarray (HASLEN OROP HEXLIT(5)) /* real array (double precision) */
67 :     /* (HASLEN OROP HEXLIT(6)) unused */
68 :     /* (HASLEN OROP HEXLIT(7)) unused */
69 :     #define DTAG_pair (NOLEN OROP HEXLIT(0)) /* pairs */
70 :     #define DTAG_reald (NOLEN OROP HEXLIT(1)) /* reals (double precision) */
71 :     /* (NOLEN OROP HEXLIT(2)) unused */
72 :     #define DTAG_variant (NOLEN OROP HEXLIT(3)) /* tagged variant record (see below) */
73 :     #define DTAG_special (NOLEN OROP HEXLIT(4)) /* special (susp, weak ptr, ...) */
74 :     #define DTAG_backptr (NOLEN OROP HEXLIT(5)) /* a back pointer (obsolete) */
75 :     #define DTAG_cont (NOLEN OROP HEXLIT(5)) /* a quasi-stack frame */
76 :     #define DTAG_extern (NOLEN OROP HEXLIT(6)) /* an external symbol reference (used in */
77 :     /* exported heap images) */
78 :     #define DTAG_forwarded (NOLEN OROP HEXLIT(7)) /* a forwarded object */
79 :    
80 :     /* Variant tags have a small length field, plus other bits */
81 :     #define VARIANT_LEN_BITS 4
82 :     #define VARIANT_OTHER_BITS (BITS_PER_WORD-(DTAG_SHIFTW+VARIANT_LEN_BITS))
83 :    
84 :     /* Build a descriptor from a descriptor tag and a length */
85 :     #ifndef _ASM_
86 :     #define MAKE_TAG(t) (((t) << DTAG_SHIFTW) OROP TAG_desc)
87 :     #define MAKE_DESC(l,t) ((ml_val_t)(((l) << TAG_SHIFTW) OROP MAKE_TAG(t)))
88 :     #else
89 :     #define MAKE_TAG(t) (((t)*4) + TAG_desc)
90 :     #define MAKE_DESC(l,t) (((l)*64) + MAKE_TAG(t))
91 :     #endif
92 :    
93 :     #define DESC_pair MAKE_DESC(2, DTAG_pair)
94 :     #define DESC_exn MAKE_DESC(3, DTAG_record)
95 :     #define DESC_ref MAKE_DESC(1, DTAG_array)
96 :     #define DESC_reald MAKE_DESC(2, DTAG_reald)
97 :    
98 :     #define DESC_forwarded MAKE_DESC(0, DTAG_forwarded)
99 :    
100 :     /* There are two kinds of special objects: suspensions and weak pointers
101 :     * The length field of these defines the state and kind of special object:
102 :     */
103 :     #define SPCL_evaled_susp 0 /* unevaluated suspension */
104 :     #define SPCL_unevaled_susp 1 /* evaluated suspension */
105 :     #define SPCL_weak 2 /* weak pointer */
106 :     #define SPCL_null_weak 3 /* nulled weak pointer */
107 :    
108 :     #define DESC_evaled_susp MAKE_DESC(SPECIAL_evaled_susp, DTAG_special)
109 :     #define DESC_unevaled_susp MAKE_DESC(SPCL_unevaled_susp, DTAG_special)
110 :     #define DESC_weak MAKE_DESC(SPCL_weak, DTAG_special)
111 :     #define DESC_null_weak MAKE_DESC(SPCL_null_weak, DTAG_special)
112 :    
113 :     /* tests on words:
114 :     * isBOXED(W) -- true if W is tagged as an boxed value
115 :     * isUNBOXED(W) -- true if W is tagged as an unboxed value
116 :     * isDESC(W) -- true if W is tagged as descriptor
117 :     */
118 :     #define isBOXED(W) (((Word_t)(W) ANDOP MAJOR_MASK) == TAG_boxed)
119 :     #define isUNBOXED(W) (((Word_t)(W) ANDOP HEXLIT(1)) == TAG_unboxed_b0)
120 :     #define isDESC(W) (((Word_t)(W) ANDOP MAJOR_MASK) == TAG_desc)
121 :    
122 :     /* extract descriptor fields */
123 :     #define GET_LEN(D) (((Word_t)(D)) >> TAG_SHIFTW)
124 :     #define GET_STR_LEN(D) ((((Word_t)(D))+(3<<TAG_SHIFTW)) >> (TAG_SHIFTW+2))
125 :     #define GET_REALDARR_LEN(D) (GET_LEN(D)*(REALD_SZB/WORD_SZB))
126 :     #define GET_TAG(D) ((((Word_t)(D)) ANDOP DTAG_MASK) >> DTAG_SHIFTW)
127 :     #define GET_VARIANT_LEN(D) (GET_LEN(D) ANDOP ((1 << VARIANT_LEN_BITS)-1))
128 :    
129 :     #endif /* !_TAGS_ */

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