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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
|
-
|
!
-
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
!
|
!
-
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
!
|
!
-
|
|
|
|
|
|
|
|
|
|
!
-
|
|
|
|
|
!
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
!
|
|
|
!
-
|
!
-
|
|
|
!
-
|
|
|
!
-
|
|
|
!
-
|
|
|
!
-
|
|
|
|
|
!
-
|
|
|
|
|
!
-
|
|
|
!
-
|
|
|
!
-
|
|
|
!
-
|
|
|
!
-
|
|
|
!
-
|
|
|
!
-
|
|
|
!
-
|
|
|
!
-
|
|
|
!
-
|
|
|
!
-
|
|
|
!
-
|
|
!
-
|
!
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
!
-
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
!
|
!
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
!
|
|
|
|
|
|
|
|
!
-
|
|
|
|
!
-
|
|
|
|
|
|
|
|
|
|
!
| #include "hspvar_uint.h"
#define GetPtr(pdat) ((UINT *)pdat)
static UINT conv;
static short *aftertype;
static short vflag;
static PDAT *HspVarUInt_GetPtr(PVal *pval)
{
return (PDAT *)(((UINT *)(pval->pt)) + pval->offset);
}
static void *HspVarUInt_Cnv(const void *buffer, int flag)
{
switch(flag) {
case HSPVAR_FLAG_STR:
conv = (UINT)atoi((char *)buffer);
return &conv;
case HSPVAR_FLAG_INT:
conv = (UINT)(*(int *)buffer);
return &conv;
case HSPVAR_FLAG_DOUBLE:
conv = (UINT)(*(double *)buffer);
return &conv;
default:
throw HSPVAR_ERROR_TYPEMISS;
}
}
static int ref_ival; static double ref_dval; static char ref_str[11]; static UINT ref_uival;
static void *HspVarUInt_CnvCustom(const void *buffer, int flag)
{
switch(flag) {
case HSPVAR_FLAG_STR:
wsprintf(ref_str, "%u", *(UINT *)buffer);
return ref_str;
case HSPVAR_FLAG_INT:
ref_ival = (int)(*(UINT *)buffer);
return &ref_ival;
case HSPVAR_FLAG_DOUBLE:
ref_dval = (double)(*(UINT *)buffer);
return &ref_dval;
default:
throw HSPVAR_ERROR_TYPEMISS;
}
return (void *)buffer;
}
static int GetVarSize(PVal *pval)
{
int size;
size = pval->len[1];
if (pval->len[2]) size *= pval->len[2];
if (pval->len[3]) size *= pval->len[3];
if (pval->len[4]) size *= pval->len[4];
size *= sizeof(UINT);
return size;
}
static void HspVarUInt_Free(PVal *pval)
{
if (pval->mode == HSPVAR_MODE_MALLOC) { sbFree(pval->pt); }
pval->pt = NULL;
pval->mode = HSPVAR_MODE_NONE;
}
static void HspVarUInt_Alloc(PVal *pval, const PVal *pval2)
{
int size;
char *pt;
UINT *fv;
if (pval->len[1] < 1) pval->len[1] = 1; size = GetVarSize(pval);
pval->mode = HSPVAR_MODE_MALLOC;
pt = sbAlloc(size);
fv = (UINT *)pt;
for (int i = 0; i < (int)(size/sizeof(UINT)); i++) { fv[i] = 0; }
if (pval2 != NULL) {
memcpy(pt, pval->pt, pval->size);
sbFree(pval->pt);
}
pval->pt = pt;
pval->size = size;
return;
}
static int HspVarUInt_GetSize(const PDAT *pval)
{
return sizeof(UINT);
}
static void HspVarUInt_Set(PVal *pval, PDAT *pdat, const void *in)
{
*GetPtr(pdat) = *((UINT *)(in));
*aftertype = vflag;
return;
}
static void HspVarUInt_AddI(PDAT *pdat, const void *val)
{
*GetPtr(pdat) += *((UINT *)(val));
*aftertype = vflag;
return;
}
static void HspVarUInt_SubI(PDAT *pdat, const void *val)
{
*GetPtr(pdat) -= *((UINT *)(val));
*aftertype = vflag;
return;
}
static void HspVarUInt_MulI(PDAT *pdat, const void *val)
{
*GetPtr(pdat) *= *((UINT *)(val));
*aftertype = vflag;
return;
}
static void HspVarUInt_DivI(PDAT *pdat, const void *val)
{
UINT p = *((UINT *)(val));
if (p == 0) throw(HSPVAR_ERROR_DIVZERO);
*GetPtr(pdat) /= p;
*aftertype = vflag;
return;
}
static void HspVarUInt_ModI(PDAT *pdat, const void *val)
{
UINT p = *((UINT *)(val));
if (p == 0) throw(HSPVAR_ERROR_DIVZERO);
*GetPtr(pdat) %= p;
*aftertype = vflag;
return;
}
static void HspVarUInt_AndI(PDAT *pdat, const void *val)
{
*GetPtr(pdat) &= *((UINT *)(val));
*aftertype = vflag;
return;
}
static void HspVarUInt_OrI(PDAT *pdat, const void *val)
{
*GetPtr(pdat) |= *((UINT *)(val));
*aftertype = vflag;
return;
}
static void HspVarUInt_XorI(PDAT *pdat, const void *val)
{
*GetPtr(pdat) ^= *((UINT *)(val));
*aftertype = vflag;
return;
}
static void HspVarUInt_EqI(PDAT *pdat, const void *val)
{
*((UINT *)pdat) = ( *GetPtr(pdat) == *((UINT *)(val)) );
*aftertype = HSPVAR_FLAG_INT;
return;
}
static void HspVarUInt_NeI(PDAT *pdat, const void *val)
{
*((UINT *)pdat) = ( *GetPtr(pdat) != *((UINT *)(val)) );
*aftertype = HSPVAR_FLAG_INT;
return;
}
static void HspVarUInt_GtI( PDAT *pdat, const void *val)
{
*((UINT *)pdat) = ( *GetPtr(pdat) > *((UINT *)(val)) );
*aftertype = HSPVAR_FLAG_INT;
return;
}
static void HspVarUInt_LtI(PDAT *pdat, const void *val)
{
*((UINT *)pdat) = ( *GetPtr(pdat) < *((UINT *)(val)) );
*aftertype = HSPVAR_FLAG_INT;
return;
}
static void HspVarUInt_GtEqI(PDAT *pdat, const void *val)
{
*((UINT *)pdat) = ( *GetPtr(pdat) >= *((UINT *)(val)) );
*aftertype = HSPVAR_FLAG_INT;
return;
}
static void HspVarUInt_LtEqI(PDAT *pdat, const void *val)
{
*((UINT *)pdat) = ( *GetPtr(pdat) <= *((UINT *)(val)) );
*aftertype = HSPVAR_FLAG_INT;
return;
}
static void HspVarUInt_RrI(PDAT *pdat, const void *val)
{
*GetPtr(pdat) >>= *((UINT *)(val));
*aftertype = vflag;
return;
}
static void HspVarUInt_LrI(PDAT *pdat, const void *val)
{
*GetPtr(pdat) <<= *((UINT *)(val));
*aftertype = vflag;
return;
}
static void *GetBlockSize(PVal *pval, PDAT *pdat, int *size)
{
*size = pval->size - ( ((char *)pdat) - pval->pt );
return (pdat);
}
static void AllocBlock(PVal *pval, PDAT *pdat, int size)
{
return;
}
static void HspVarUInt_Init(HspVarProc *p)
{
vflag = p->flag;
aftertype = &p->aftertype;
p->Set = HspVarUInt_Set;
p->Cnv = HspVarUInt_Cnv;
p->GetPtr = HspVarUInt_GetPtr;
p->CnvCustom = HspVarUInt_CnvCustom;
p->GetSize = HspVarUInt_GetSize;
p->GetBlockSize = GetBlockSize;
p->AllocBlock = AllocBlock;
p->Alloc = HspVarUInt_Alloc;
p->Free = HspVarUInt_Free;
p->AddI = HspVarUInt_AddI;
p->SubI = HspVarUInt_SubI;
p->MulI = HspVarUInt_MulI;
p->DivI = HspVarUInt_DivI;
p->ModI = HspVarUInt_ModI;
p->AndI = HspVarUInt_AndI;
p->OrI = HspVarUInt_OrI;
p->XorI = HspVarUInt_XorI;
p->EqI = HspVarUInt_EqI;
p->NeI = HspVarUInt_NeI;
p->GtI = HspVarUInt_GtI;
p->LtI = HspVarUInt_LtI;
p->GtEqI = HspVarUInt_GtEqI;
p->LtEqI = HspVarUInt_LtEqI;
p->RrI = HspVarUInt_RrI;
p->LrI = HspVarUInt_LrI;
p->vartype_name = "uint"; p->version = 0x001; p->support = HSPVAR_SUPPORT_STORAGE | HSPVAR_SUPPORT_FLEXARRAY;
p->basesize = sizeof(UINT); return;
}
static int cmdfunc( int cmd )
{
PVal *pval;
int p1, p2, p3, p4;
code_next(); switch( cmd ) { case 0x00: code_getva(&pval);
p1 = code_getdi(1);
p2 = code_getdi(0);
p3 = code_getdi(0);
p4 = code_getdi(0);
exinfo->HspFunc_dim(pval, vflag, 0, p1, p2, p3, p4);
break;
default:
puterror( HSPERR_UNSUPPORTED_FUNCTION );
}
return RUNMODE_RUN;
}
static void *reffunc( int *type_res, int cmd )
{
void *ref_ptr;
int chk;
*type_res = vflag;
ref_ptr = &ref_uival;
if ( *type != TYPE_MARK ) puterror( HSPERR_INVALID_FUNCPARAM );
if ( *val != '(' ) puterror( HSPERR_INVALID_FUNCPARAM );
code_next();
switch(cmd) {
case 0x01: chk = code_getprm();
if (chk <= PARAM_END) puterror( HSPERR_INVALID_FUNCPARAM );
ref_uival = *(UINT*)HspVarUInt_Cnv((void*)mpval->pt, mpval->flag);
break;
default:
puterror( HSPERR_UNSUPPORTED_FUNCTION );
}
if ( *type != TYPE_MARK ) puterror( HSPERR_INVALID_FUNCPARAM );
if ( *val != ')' ) puterror( HSPERR_INVALID_FUNCPARAM );
code_next();
return ref_ptr;
}
static int termfunc( int option )
{
return 0;
}
EXPORT void WINAPI hsp3_uintinit( HSP3TYPEINFO *info )
{
hsp3sdk_init( info ); HSPVAR_COREFUNC func = HspVarUInt_Init;
registvar(-1, func);
sbInit(); info->cmdfunc = cmdfunc; info->reffunc = reffunc; info->termfunc = termfunc; return;
}
|