1 | /*************************************************************************** |
---|
2 | * |
---|
3 | * HEADER FILE: MP_Types.h |
---|
4 | * |
---|
5 | * Most of the typedefs needed by MP are here, including the definition |
---|
6 | * of node and annotation packets. |
---|
7 | * |
---|
8 | * Change Log: |
---|
9 | * May 30, 1995 SG - added defines for new types for MP 1.0 |
---|
10 | * December 12, 1995 SG - added ifdef for AIX per Hannes' instructions |
---|
11 | * December 20, 1995 SG - added enum for fp format |
---|
12 | * 4/23/96 sgray - added defines to support different arbitrary precision |
---|
13 | * integer formats. |
---|
14 | * Jan 6, 1997 OB - rearranged integer assignments for MP types |
---|
15 | * |
---|
16 | ***************************************************************************/ |
---|
17 | |
---|
18 | #ifndef _MP_Types_h |
---|
19 | #define _MP_Types_h |
---|
20 | |
---|
21 | #define MP_TRUE 0x01 |
---|
22 | #define MP_FALSE 0x00 |
---|
23 | |
---|
24 | #ifdef __hpux |
---|
25 | # define SELECT(maxfdp1, readfs, writefs, exceptfds, tvptr) \ |
---|
26 | select((int)maxfdp1, (int*)readfs, (int*)writefs, \ |
---|
27 | (int*)exceptfds, tvptr) |
---|
28 | #else /* not __hpux */ |
---|
29 | # define SELECT select |
---|
30 | #endif /* not __hpux */ |
---|
31 | |
---|
32 | |
---|
33 | /* to indicate the direction of traffic */ |
---|
34 | #define MP_SEND 0 |
---|
35 | #define MP_RECEIVE 1 |
---|
36 | |
---|
37 | /* For checking the status of a link*/ |
---|
38 | enum link_status_option {MP_UnknownStatus, MP_LinkReadyReading, |
---|
39 | MP_LinkReadyWriting, |
---|
40 | MP_LinkIsParent, MP_LinkIsChild}; |
---|
41 | typedef enum link_status_option MP_LinkStatus_t; |
---|
42 | |
---|
43 | /* To determine which byte ordering is native and which is actually used. */ |
---|
44 | /* The default is BigEndian. */ |
---|
45 | enum word_order {MP_BigEndian, MP_LittleEndian}; |
---|
46 | typedef enum word_order MP_WordOrder_t; |
---|
47 | |
---|
48 | /* To determine which floating format is native and which is actually used. */ |
---|
49 | /* The default is IEEE format. */ |
---|
50 | enum fp_format {MP_IEEE_fp, MP_Vax_fp}; |
---|
51 | typedef enum fp_format MP_FpFormat_t; |
---|
52 | |
---|
53 | |
---|
54 | |
---|
55 | /* |
---|
56 | * Important size used throughout |
---|
57 | */ |
---|
58 | #define MP_BytesPerMPUnit 4 |
---|
59 | |
---|
60 | /* New defines for MP 1.0 */ |
---|
61 | |
---|
62 | /* shift values for the node packet */ |
---|
63 | #define MP_NodeOpFieldShift 8 |
---|
64 | #define MP_NodeNumChildFieldShift 8 |
---|
65 | #define MP_NodeAnnotFieldShift 12 |
---|
66 | #define MP_NodeDictTagFieldShift 16 |
---|
67 | #define MP_NodeCommonValueFieldShift 24 |
---|
68 | |
---|
69 | /* used for the #children and #annots field in the node packet header |
---|
70 | to indicate that there are more than 14 children or annotations and |
---|
71 | that an extra field(s) (a long) must be retrieved from the stream */ |
---|
72 | #define MP_ExtraFieldIndicator 0xf |
---|
73 | |
---|
74 | /* used for the dictionary tag field to indicate that an extra four |
---|
75 | bytes must be read to get the dictionary tag - don't expect to |
---|
76 | actually have to use this for a long time */ |
---|
77 | #define MP_ExtraMPDictTagFieldIndicator 0x7f |
---|
78 | #define MP_ExtraUserDictTagFieldIndicator 0xff |
---|
79 | |
---|
80 | /* masks for the node packet fields */ |
---|
81 | #define MP_NodeTypeMask 0x000000ff |
---|
82 | #define MP_NodeNumChildMask 0x00000f00 |
---|
83 | #define MP_NodeNumAnnotMask 0x0000f000 |
---|
84 | #define MP_NodeDictTagMask 0x00ff0000 |
---|
85 | #define MP_NodeCommonValueMask 0xff000000 |
---|
86 | |
---|
87 | |
---|
88 | #define MP_ExtraAnnotField MP_ExtraFieldIndicator << MP_NodeAnnotFieldShift |
---|
89 | #define MP_ExtraChildField MP_ExtraFieldIndicator << MP_NodeOpFieldShift |
---|
90 | #define MP_ExtraDictTagField MP_ExtraFieldIndicator << MP_NodeDictTagFieldShift |
---|
91 | |
---|
92 | |
---|
93 | /* |
---|
94 | * The format of a node packet header is: |
---|
95 | * |
---|
96 | * | 3 2 1 0 | |
---|
97 | * +-----------+-----------|-------------+-----------+ |
---|
98 | * | common |dictionary | ^ | ^ | Node | |
---|
99 | * | value | tag | | | | | type | |
---|
100 | * | |- #children |
---|
101 | * |- #annots |
---|
102 | */ |
---|
103 | |
---|
104 | typedef unsigned char MP_NodeType_t; |
---|
105 | typedef unsigned char MP_CommonValue_t; |
---|
106 | typedef unsigned long MP_NodeHeader_t; |
---|
107 | typedef unsigned long MP_NumChild_t; |
---|
108 | typedef unsigned long MP_NumAnnot_t; |
---|
109 | typedef unsigned long MP_DictTag_t; /* common to annotation packet header */ |
---|
110 | |
---|
111 | /* macros for setting and getting the fields of a node header */ |
---|
112 | |
---|
113 | #define MP_SetNodeTypeField(hdr, type) \ |
---|
114 | (hdr = (hdr & ~MP_NodeTypeMask) | (long) type) |
---|
115 | |
---|
116 | #define MP_SetNodeNumChildField(hdr, nchild) \ |
---|
117 | (hdr = (hdr & ~MP_NodeNumChildMask) \ |
---|
118 | | ((long) nchild << MP_NodeNumChildFieldShift)) |
---|
119 | |
---|
120 | #define MP_SetNodeNumAnnotsField(hdr, nannots) \ |
---|
121 | (hdr = (hdr & ~MP_NodeNumAnnotMask) \ |
---|
122 | | ((long) nannots << MP_NodeAnnotFieldShift)) |
---|
123 | |
---|
124 | #define MP_SetNodeDictTagField(hdr, dtag) \ |
---|
125 | (hdr = (hdr & ~MP_NodeDictTagMask) \ |
---|
126 | | (dtag << MP_NodeDictTagFieldShift)) |
---|
127 | |
---|
128 | #define MP_SetNodeExtraChildField(hdr) \ |
---|
129 | (hdr |= (long) MP_ExtraChildField) |
---|
130 | |
---|
131 | #define MP_SetNodeExtraAnnotsField(hdr) \ |
---|
132 | (hdr |= (long) MP_ExtraAnnotField) |
---|
133 | |
---|
134 | #define MP_SetNodeCommonValueField(hdr, value) \ |
---|
135 | (hdr = (hdr & ~MP_NodeCommonValueMask) \ |
---|
136 | | ((long) value << MP_NodeCommonValueFieldShift)) |
---|
137 | |
---|
138 | #define MP_GetNodeFieldType(hdr) \ |
---|
139 | (hdr & MP_NodeTypeMask) |
---|
140 | |
---|
141 | #define MP_GetNodeNumAnnotsField(hdr) \ |
---|
142 | ((hdr & MP_NodeNumAnnotMask) >> MP_NodeAnnotFieldShift) |
---|
143 | |
---|
144 | #define MP_GetNodeNumChildField(hdr) \ |
---|
145 | ((hdr & MP_NodeNumChildMask) >> MP_NodeOpFieldShift) |
---|
146 | |
---|
147 | #define MP_GetNodeDictTagField(hdr) \ |
---|
148 | ((hdr & MP_NodeDictTagMask) >> MP_NodeDictTagFieldShift) |
---|
149 | |
---|
150 | #define MP_GetNodeCommonValueField(hdr) \ |
---|
151 | ((hdr & MP_NodeCommonValueMask) >> MP_NodeCommonValueFieldShift) |
---|
152 | |
---|
153 | /* see MP_Annotations.h for the defines for annotations */ |
---|
154 | |
---|
155 | /* Note: plain cc (old style?) doesn't like signed char!! */ |
---|
156 | typedef signed char MP_Sint8_t; |
---|
157 | typedef unsigned char MP_Uint8_t; |
---|
158 | typedef unsigned short MP_Uint16_t; /* aren't real MP types yet */ |
---|
159 | typedef signed short MP_Sint16_t; |
---|
160 | typedef long MP_Sint32_t; |
---|
161 | typedef unsigned long MP_Uint32_t; |
---|
162 | typedef float MP_Real32_t; |
---|
163 | typedef double MP_Real64_t; |
---|
164 | typedef unsigned char MP_Boolean_t; |
---|
165 | typedef unsigned char MP_Common_t; /* for common types rep as a char */ |
---|
166 | typedef void * MP_ApInt_t; |
---|
167 | typedef MP_ApInt_t * MP_ApInt_pt; |
---|
168 | typedef void * MP_ApReal_t; |
---|
169 | typedef MP_ApReal_t * MP_ApReal_pt; |
---|
170 | |
---|
171 | typedef struct MP_Link_t MP_Link_t; |
---|
172 | typedef MP_Link_t * MP_Link_pt; |
---|
173 | |
---|
174 | /* |
---|
175 | encodings for the Multi dictionaries |
---|
176 | */ |
---|
177 | #define MP_BasicDict 0 |
---|
178 | #define MP_NoSemanticsDict 128 |
---|
179 | #define MP_ReceiverDict 129 |
---|
180 | #define MP_UnavailSemanticsDict 130 |
---|
181 | #define MP_LocalDict 155 |
---|
182 | |
---|
183 | |
---|
184 | /* |
---|
185 | * encodings for the Multi types plus some useful macros |
---|
186 | */ |
---|
187 | #define MP_Sint8Type 65 |
---|
188 | #define MP_Uint8Type 67 |
---|
189 | #define MP_BooleanType 68 |
---|
190 | #define MP_CommonLatinIdentifierType 72 |
---|
191 | #define MP_CommonGreekIdentifierType 76 |
---|
192 | #define MP_CommonConstantType 80 |
---|
193 | #define MP_CommonMetaType 84 |
---|
194 | #define MP_CommonMetaOperatorType 88 |
---|
195 | |
---|
196 | #define MP_StringType 36 |
---|
197 | #define MP_ConstantType 40 |
---|
198 | #define MP_IdentifierType 44 |
---|
199 | #define MP_MetaType 48 |
---|
200 | #define MP_MetaOperatorType 52 |
---|
201 | |
---|
202 | #define MP_Sint32Type 17 |
---|
203 | #define MP_Uint32Type 19 |
---|
204 | #define MP_Real32Type 18 |
---|
205 | |
---|
206 | #define MP_ApIntType 9 |
---|
207 | #define MP_ApRealType 10 |
---|
208 | |
---|
209 | #define MP_Real64Type 6 |
---|
210 | |
---|
211 | #define MP_OperatorType 128 |
---|
212 | #define MP_CommonOperatorType 129 |
---|
213 | |
---|
214 | #define MP_RawType 134 |
---|
215 | |
---|
216 | /* MP_ANY_TYPE is used by the internal get node packet routine */ |
---|
217 | #define MP_ANY_TYPE 255 |
---|
218 | |
---|
219 | |
---|
220 | /* And here are some Handy Macros */ |
---|
221 | /* Basic types, i.e. those which appear as a leaf of a data tree |
---|
222 | have numerical values between 0 and 127 ,i.e. bit 8 is zero */ |
---|
223 | #define MP_IsBasicType(type) (!((type) & 128)) |
---|
224 | |
---|
225 | /* native 8-bit types have numeric values between 64 and 127 |
---|
226 | i.e. bit 8 is zero and bit 7 is one */ |
---|
227 | #define MP_Is8BitNumericType(type) (!((type) & 128) && ((type) & 64)) |
---|
228 | |
---|
229 | /* native String-based types have numeric values between 32 an 63, |
---|
230 | i.e. bit 8,7 are zero, bit 6 is one */ |
---|
231 | #define MP_IsStringBasedType(type) (!((type) & 192) && ((type) & 32)) |
---|
232 | |
---|
233 | /* native 32 bit types have numeric values beween 16 and 31, i.e. bits |
---|
234 | 8,7,6, are zero, bit 5 is one. Furthermore, integers have bit 1 set |
---|
235 | to 1 and Reals have bit 1 set to 0 */ |
---|
236 | #define MP_Is32BitNumericType(type) (!((type) & 224) && ((type) & 16)) |
---|
237 | |
---|
238 | |
---|
239 | /* Ap Numbers have bit 5-8 set to zero, bit 4 set to one */ |
---|
240 | #define MP_IsApNumberType(type) (!((type) & 240) && ((type) & 8)) |
---|
241 | |
---|
242 | /* Native 64-bit numbers have bit 4-8 set to zero, bit 3 set to one */ |
---|
243 | #define MP_Is64BitNumericType(type) (type == MP_Real64Type) |
---|
244 | |
---|
245 | /* Predicates for real and integers |
---|
246 | Integers are odd numbers, reals are even numbers, not divisble by 4*/ |
---|
247 | #define MP_IsRealType(type) (MP_IsBasicType(type) && \ |
---|
248 | !((type) & 1) && \ |
---|
249 | ((type) >> 1) & 1) |
---|
250 | #define MP_IsIntegerType(type)(MP_IsBasicType(type) && ((type) & 1)) |
---|
251 | |
---|
252 | #define MP_IsFixedIntegerType(type) \ |
---|
253 | (MP_IsIntegerType(type) && ! (type == MP_ApIntType)) |
---|
254 | |
---|
255 | #define MP_IsIdType(type) \ |
---|
256 | (type == MP_IdentifierType || \ |
---|
257 | type == MP_CommonLatinIdentifierType || \ |
---|
258 | type == MP_CommonGreekIdentifierType) |
---|
259 | |
---|
260 | #define MP_IsCommonType(type) ((type >= 72 && type <= 88) || type == 129) |
---|
261 | #endif /* _MP_Types_h */ |
---|