-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTypes.hxx
319 lines (292 loc) · 8.2 KB
/
Types.hxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
// Copyright Kabuki Starship™ <kabukistarship.com>.
#include "Types.hpp"
#if SEAM == SCRIPT2_COUT
#include "_Debug.hxx"
#else
#include "_Release.hxx"
#endif
namespace _ {
DTB ATypePack(DTB pod, DTB vt) {
return pod | vt << ATypeVTBit0;
}
DTB ATypePack(DTB pod, DTB vt, DTB sw) {
return pod | vt << ATypeVTBit0 | sw << ATypeSWBit0;
}
DTB ATypePack(DTB pod, DTB vt, DTB sw, DTB mt) {
return pod | vt << ATypeVTBit0 | sw << ATypeSWBit0 | mt << ATypeMTBit0;
}
DTB ATypePack(DTB pod, DTB vt, DTB sw, DTB mt, DTB mod) {
return pod | vt << ATypeVTBit0 | sw << ATypeSWBit0 | mt << ATypeMTBit0 |
mod << ATypeMODBit0;
}
BOL ATypeIsCH(DTB type) {
// CHA: 3 0b0011
// CHB: 7 0b0111
// CHC: 11 0b1011
//return (type & 3) && (type != 15);
return type == _CHA || type == _CHB || type == _CHC;
}
BOL ATypeVTBits(DTB type) {
//| b15:b14 | b13:b9 | b8:b7 | b6:b5 | b4:b0 |
//|:-------:|:------:|:-----:|:-----:|:-----:|
//| MOD | MT | SW | VT | POD |
const DTB mask = 3,
VT = (type >> ATypeVTBit0) & mask,
MT = (type >> ATypeMTBit0) & mask;
return (VT != _ARY || MT != 0) ? -1 : VT;
}
// Retrusn the size of an ASCII POD Type 0-31 in bytes.
ISA ATypeSizeOfPOD(DTB type) {
if (type <= 0) return 0;
if (type <= _CHA) return 1;
if (type <= _CHB) return 2;
if (type <= _CHC) return 4;
if (type <= _TMD) return 8;
if (type <= _TME) return 16;
#if USING_CT5
if (type <= _CT5) return 16;
#endif
#if USING_CT4
if (type <= _CT4) return 8;
#endif
#if USING_CT3
if (type <= _CT3) return 4;
#endif
#if USING_CT2
if (type <= _CT2) return 2;
#endif
if (type <= 31) return 1;
return 0;
}
ISW ATypeBytes(const void* value, DTB type) {
return TATypeSizeOf<ISW>(value, type);
}
ISW ATypeBytes(const void* value_base, ISA bytes, DTB type) {
return ATypeBytes(TPtr<>(value_base, bytes), type);
}
void* ATypeValueEnd(void* value, DTB type) {
return TPtr<void>(value, ATypeBytes(value, type));
}
// Returns an array of the customizable POD type sizes.
//const ISA* ATypeCustomSize() {
// return nullptr;
//}
// Returns an array of the user-defined type alignment masks.
//const ISA* ATypeCustomAlignMask() {
// return nullptr;
//}
// Returns the custom time alignment mask for the given type.
//ISA ATypeCustomAlignMask(DTA type) {
// return 0;
//}
TypeValue::TypeValue() : type_(_NIL), word_(0), word_2_(0) {}
TypeValue::TypeValue(void* item) : type_(_PTR), word_(IUW(item)), word_2_(0) {}
TypeValue::TypeValue(const void* item)
: type_(_CNS_PTR), word_(IUW(item)), word_2_(0) {}
#if USING_UTF8 == YES_0
TypeValue::TypeValue(CHA item) : type_(_CHA), word_(IUW(item)), word_2_(0) {}
TypeValue::TypeValue(const CHA* item)
: type_(_STA), word_(IUW(item)), word_2_(0) {}
#endif
#if USING_UTF16 == YES_0
TypeValue::TypeValue(CHB item) : type_(_CHB), word_(IUW(item)), word_2_(0) {}
TypeValue::TypeValue(const CHB* item)
: type_(_STB), word_(IUW(item)), word_2_(0) {}
#endif
#if USING_UTF32 == YES_0
TypeValue::TypeValue(CHC item) : type_(_CHC), word_(IUW(item)), word_2_(0) {}
TypeValue::TypeValue(const CHC* item)
: type_(_STC), word_(IUW(item)), word_2_(0) {}
#endif
TypeValue::TypeValue(ISA item) : type_(_ISA), word_(IUW(item)), word_2_(0) {}
TypeValue::TypeValue(IUA item) : type_(_IUA), word_(IUW(item)), word_2_(0) {}
TypeValue::TypeValue(ISB item) : type_(_ISB), word_(IUW(item)), word_2_(0) {}
TypeValue::TypeValue(IUB item) : type_(_IUB), word_(IUW(item)), word_2_(0) {}
#if CPU_SIZE == CPU_2_BYTE
AValue::AValue(ISC item) : type_(_ISC) {
// @todo I don't know if this is going to be needed. In my mind the compiler
// will push the word_ onto the program stack because of the *reintpret_cast.
// This might however get optimized into just storing item. Dissassemble me!
*TPtr<ISC>(&word_) = item;
}
#else
TypeValue::TypeValue(ISC item) : type_(_ISC), word_(IUW(item)), word_2_(0) {}
#endif
#if CPU_SIZE == CPU_2_BYTE
AValue::AValue(IUC item) : type_(_IUC) {
*TPtr<IUC>(&word_) = item;
}
#else
TypeValue::TypeValue(IUC item) : type_(_IUC), word_(IUW(item)), word_2_(0) {}
#endif
#if CPU_SIZE == CPU_8_BYTE
TypeValue::TypeValue(ISD item) : type_(_ISD), word_(IUW(item)), word_2_(0) {}
#else
AValue::AValue(ISD item) : type_(_ISD) { *TPtr<ISD>(&word_) = item; }
#endif
#if CPU_SIZE == CPU_8_BYTE
TypeValue::TypeValue(IUD item) : type_(_IUD), word_(IUW(item)), word_2_(0) {}
#else
AValue::AValue(IUD item) : type_(_IUD) {
*TPtr<IUD>(&word_) = item;
}
#endif
#if USING_FPC == YES_0
#if CPU_SIZE == CPU_8_BYTE
TypeValue::TypeValue(FPC item)
: type_(_FPC), word_(ToUnsigned(item)), word_2_(0) {}
#else
AValue::AValue(FPC item) : type_(_FPC) { *TPtr<FPC>(&word_) = item; }
#endif
#endif
#if USING_FPD == YES_0
#if CPU_SIZE == CPU_8_BYTE
TypeValue::TypeValue(FPD item)
: type_(_FPD), word_(ToUnsigned(item)), word_2_(0) {}
#else
AValue::AValue(FPD item) : type_(_FPD) { *TPtr<FPD>(&word_) = item; }
#endif
#endif
TypeValue::TypeValue(const void* item, DTW type) : type_(type), word_2_(0) {
DTW pod_type = type & ATypePODMask;
if (type != pod_type) {
word_ = IUW(item);
} else if (pod_type <= 7) {
word_ = TGet<IUA>(item);
} else if (pod_type <= 15) {
word_ = TGet<IUB>(item);
} else if (pod_type <= 15) {
word_ = TGet<IUC>(item);
} else {
#if CPU_SIZE != CPU_2_BYTE
IUD* destination = TPtr<IUD>(WordPTR());
const IUD* source = TPtr<const IUD>(item);
*destination = *source;
if (pod_type >= _ISE) {
++destination;
++source;
*destination = *source;
}
#else
word_ = IUW(item);
#endif
}
}
DTW TypeValue::Type() { return type_; }
DTW TypeValue::UnicodeFormat() { return ATypeTextFormat(type_); }
void* TypeValue::WordPTR() { return &word_; }
void* TypeValue::ToPTR() { return TPtr<void>(word_); }
CHA* TypeValue::ToSTA() { return TPtr<CHA>(word_); }
CHB* TypeValue::ToSTB() { return TPtr<CHB>(word_); }
CHC* TypeValue::ToSTC() { return TPtr<CHC>(word_); }
IUA TypeValue::ToIUA() { return IUA(word_); }
IUB TypeValue::ToIUB() { return IUB(word_); }
IUN TypeValue::ToIUN() { return IUN(word_); }
IUC TypeValue::ToIUC() {
#if CPU_SIZE == CPU_2_BYTE
// @todo Inspect dissassembly to check if we even need the #if #else here.
// I have a feeling the compiler will optmize away memory copies I think
// I'm avoiding.
return *TPtr<IUC>(&word_);
#else
return IUC(word_);
#endif
}
IUD TypeValue::ToUID() {
#if CPU_SIZE == CPU_8_BYTE
return word_;
#else
// @todo Inspect dissassembly to check if we even need the #if #else here.
// I have a feeling the compiler will optmize away memory copies I think
// I'm avoiding.
return *TPtr<IUD>(&word_);
#endif
}
IUW TypeValue::Word() { return word_; }
IUW TypeValue::Word2() { return word_2_; }
void TypeValue::SetWord(IUW value) { word_ = value; }
void TypeValue::SetWord2(IUW value) { word_2_ = value; }
void TypeValue::SetNIL() { type_ = word_ = _NIL; }
void TypeValue::SetNIL(IUW value) {
type_ = _NIL;
word_ = value;
}
#if USING_UTF8 == YES_0
void TypeValue::Set(CHA item) {
type_ = _CHA;
word_ = IUW(item);
}
void TypeValue::Set(const CHA* item) {
type_ = CATypeMap(_STA, _CNS_PTR);
word_ = IUW(item);
}
#endif
#if USING_UTF16 == YES_0
void TypeValue::Set(CHB item) {
type_ = _CHB;
word_ = IUW(item);
}
void TypeValue::Set(const CHB* item) {
type_ = _STB;
word_ = IUW(item);
}
#endif
#if USING_UTF32 == YES_0
void TypeValue::Set(CHC item) {
type_ = _CHC;
word_ = IUW(item);
}
void TypeValue::Set(const CHC* item) {
type_ = _STC;
word_ = IUW(item);
}
#endif
void TypeValue::Set(ISA item) {
type_ = _ISA;
word_ = IUW(item);
}
void TypeValue::Set(IUA item) {
type_ = _IUA;
word_ = IUW(item);
}
void TypeValue::Set(ISB item) {
type_ = _ISB;
word_ = IUW(item);
}
void TypeValue::Set(IUB item) {
type_ = _IUB;
word_ = IUW(item);
}
void TypeValue::Set(BOL item) {
type_ = _BOL;
word_ = IUW(item);
}
void TypeValue::Set(ISC item) {
type_ = _ISC;
word_ = IUW(item);
}
void TypeValue::Set(IUC item) {
type_ = _IUC;
word_ = IUW(item);
}
void TypeValue::Set(ISD item) {
type_ = _ISD;
word_ = IUW(item);
}
void TypeValue::Set(IUD item) {
type_ = _IUD;
word_ = IUW(item);
}
#if USING_FPC == YES_0
void TypeValue::Set(FPC item) {
type_ = _FPC;
word_ = IUW(item);
}
#endif
#if USING_FPD == YES_0
void TypeValue::Set(FPD item) {
type_ = _FPD;
word_ = IUW(item);
}
#endif
} //< namespace _