forked from compuphase/pawn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test2.p
471 lines (406 loc) · 11.4 KB
/
test2.p
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
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
#include <core>
#include <console>
#if defined STRINS_MAXLENGTH
#include <string>
#endif
#if defined ASSERT_LINENO
/* NOTE: make sure the function heading of ispacked stays at line 10, see
* test 3 in test.rexx (and ASSERT_LINENO below)
*/
bool: ispacked(string[]) /* line 10 */
return bool: (string[0] > charmax);
#endif
#if defined PARTIAL_ARRAY_SIZE
#include <float>
new Array[0.5]
#endif
#if defined COUNT_ARRAY_SIZE
new Array[][3] =
[
[ 123, 456, 789 ],
[ 987, 654, 321 ]
]
#endif
#if defined DECLARATION_POSITION
#include "menu.inc"
#endif
#if defined UNBALANCED_BRACES
native clam();
#endif
#if defined REFERENCE_ARG
func(&va)
{
printf("func1: %d\n",va);
printf("func2: %d\n",va);
va++;
}
#endif
#if defined DEF_ARRAY_ARG
DefArg(const cStruc[]='''')
return cStruc[0] /* just to avoid a warning */
#endif
#if defined DOUBLE_NATIVE_DECLARE
native printf(const format[], {Float,Fixed,_}:...)
#endif
#if defined CALL_BEFORE_DEF
Test()
return 0
#endif
#if defined RETURN_WITH_INCR
increment(a)
return ++a
#endif
#if defined CONST_WRITE_USAGE
const
{
PARAM_CELL=1,
PARAM_CELL_REF,
PARAM_STRING,
PARAM_ARRAY
};
native RegPublicFunction(ParameterCount, ...);
#endif
#if defined TAGOF_PARAM
test({Sentient,Foo,_}:param,paramTag = tagof param)
{
if (paramTag == tagof Sentient:)
printf("Passed a Sentient %d\n",_:param);
else if (paramTag == tagof Foo:)
printf("Passed a Foo %d\n",_:param);
else
printf("Passed something else %d\n",_:param);
}
#endif
#if defined COND_EXP_ARRAY
return_array(c)
{
new result[2]
result[0] = '0' + c
return result
}
#endif
#if defined NATIVE_RET_ARRAY
native netsocket[1](value);
#endif
#if defined STRINGIZE_OPER
#define log(%1) "logging: " ... #%1 ... "\n"
#endif
#if defined PACKED_OPCODE_LIMITS
printvalue(d, const s[])
printf "%d (should be %s)\n", d, s
#endif
#if defined MIX_PACK_FUNC
getpack(array[], idx)
return array[idx]
setpack(array[], idx, value)
array[idx] = value
#endif
#if defined CLOSING_BRACE_NO_PARMS
do_abc()
{
print "abc\n"
}
#endif
main()
{
#if defined ASSERT_LINENO
assert ispacked(''unpacked'');
#endif
#if defined CASCADED_ASSIGN
new a = 4, b = 5;
a ^= b ^= a ^= b;
printf(''a==%d, b==%d (should be a==5, b==4)\n'', a, b);
#endif
#if defined LINE_CAT
print(''hello''); \
print(''\n''); // a somewhat long line
#endif
#if defined REFERENCE_ARG
new test=40;
printf(''before: %d\n'',test);
func(test);
printf(''after: %d\n'',test);
#endif
#if defined UNTERMINATED_STRING
/* generated the error "missing terminating quote", but then stayed
* in the loop for parsing parameters, because printf() has a
* variable number of parameters and the closing ')' was not found
* (the closing ')' was assumed to be part of the literal string)
*/
printf(''Bye\n);
#endif
#if defined IMPLICIT_POSTFIX
new a, b = 4
a = 3
++b; ++a
printf(''%d %d\n'', a, b)
#endif
#if defined REDUNDANT_TEST
if (1==1)
print("Hello ")
print("world\n")
#endif
#if defined REDUNDANT_CODE
if (1==2)
print("NOT ")
print("Okay\n")
#endif
#if defined COND_EXPR_CONST
new str{} = "monkey"
new index
for (index = 0; str{index}; index += 1)
if ('e' == str{index})
break
new result = str{index} ? index : -1
printf("Result: %d\n", result)
#endif
#if defined DEF_ARRAY_ARG
new cRef = DefArg()
printf(''Result: %d\n'', cRef)
#endif
#if defined COND_OPER_ARRAY
new a = 1
new str[] = ''Second''
printf(''result = %s\n'', a ? ''First'' : str)
printf(''result = %s\n'', !a ? ''First'' : str)
#endif
#if defined POST_INCREMENT_REF
new pos = 0
printf(''Before: %d\n'', pos++ )
printf(''After: %d\n'', pos )
#endif
#if defined NEGATIVE_INDEX1
new array[10] = [ 1, 2, ... ]
new v = array[-1]
v = v + 1 // to avoid a compiler warning
#endif
#if defined NEGATIVE_INDEX2
new array[10] = [ 1, 2, ... ]
printf(''field %d = %d\n'',-1,array[-1])
#endif
#if defined NEGATIVE_INDEX3
new array[10] = [ 1, 2, ... ]
new i = -1
new v = array[i]
v = v + 1 // to avoid a compiler warning
#endif
#if defined NEGATIVE_INDEX4
new array[10] = [ 1, 2, ... ]
new i = -1
printf(''field %d = %d\n'',i,array[i])
#endif
#if defined DOUBLE_NATIVE_DECLARE
printf ''Hello world\n''
#endif
#if defined CALL_BEFORE_DEF
new x;
switch(x)
{
case 1: x = Test()
}
printf(''bug'')
#endif
#if defined SWITCH_SIDE_EFFECT
new a = 1
switch (a++)
{
case 0:
print ''zero''
case 1:
print ''one''
case 2:
print ''two''
}
print '' (should be one)\n''
printf ''exit = %d (should be 2)\n'', a
#endif
#if defined CHAINED_ARRAY_ASSIGN
new a[3]
a[0] = a[1] = a[2] = 5
printf ''%d %d %d\n'', a[0], a[1], a[2]
#endif
#if defined CONST_WRITE_USAGE
RegPublicFunction(2, PARAM_CELL, PARAM_CELL);
#endif
#if defined SYMBOL_TOO_LONG_FOR_OPTIMIZER
new desired_velocity_towards_A
printf ''%d\n'', desired_velocity_towards_A
#endif
#if defined TAGOF_PARAM
test(Sentient:2);
test(Foo:1);
test(0);
#endif
#if defined MACRO_PARM_INSTR
#define TEST ''%1test''
print TEST
#endif
#if defined MACRO_PARM_UNKNOWN
#define TEST %1+4
printf ''%d'', TEST
#endif
#if defined FLOORED_DIVISION
new n = 8, q = 3, n2 = 9
printf ''\t(%+d,%+d) q=%+d r=%+d\n'', n, q, n / q, n % q
printf ''\t(%+d,%+d) q=%+d r=%+d\n'', n, -q, n / -q, n % -q
printf ''\t(%+d,%+d) q=%+d r=%+d\n'', -n, q, -n / q, -n % q
printf ''\t(%+d,%+d) q=%+d r=%+d\n'', -n, -q, -n / -q, -n % -q
printf ''\t(%+d,%+d) q=%+d r=%+d\n'', n2, q, n2 / q, n2 % q
printf ''\t(%+d,%+d) q=%+d r=%+d\n'', n2, -q, n2 / -q, n2 % -q
printf ''\t(%+d,%+d) q=%+d r=%+d\n'', -n2, q, -n2 / q, -n2 % q
printf ''\t(%+d,%+d) q=%+d r=%+d\n'', -n2, -q, -n2 / -q, -n2 % -q
#endif
#if defined RETURN_WITH_INCR
new b
b = increment(1)
printf ''%d'', b
#endif
#if defined COND_EXP_ARRAY
new b=0
new other[]=''123''
printf ''result=%s\n'', b ? return_array(1) : other
b=1
printf ''result=%s\n'', b ? return_array(1) : other
#endif
#if defined PRINTF_PCT
new result = 15
printf ''queue: %d%%\n'', result
printf ''queue: %d\n''
#endif
#if defined PARTIAL_ARRAY_SIZE
Array[Float:0] = 0 /* only to avoid a "symbol not used" warning */
#endif
#if defined COUNT_ARRAY_SIZE
printf "size: %d x %d\n", sizeof Array, sizeof Array[]
Array[0][0] = 0 /* only to avoid a "symbol not used" warning */
#endif
#if defined DECLARATION_POSITION
printf ''hello...\n''
#endif
#if defined UNBALANCED_BRACES
new b=1, c=0
if (b)
{
} else if (c)
clam();
}
new e = clam();
#endif
#if defined NATIVE_RET_ARRAY
new addr[4]
addr = netsocket(25)
print addr
#endif
#if defined LIT_STRING_CAT
print ''Eenie '' ... ''Meenie\n''
print "Meinie " ... "Moe\n"
#endif
#if defined LIT_STRING_CAT_MIX
print ''Eenie '' ... \''Meenie\n''
print ''Meinie '' ... "Moe\n"
#endif
#if defined ENUM_ELLIPSIS
#define Rect[ .left, .top, .right, .bottom ]
new r[Rect] = [ -1, ... ]
printf ''%d, %d, %d, %d\n'', r.left, r.top, r.right, r.bottom
#endif
#if defined STRINGIZE_OPER
print log(test)
#endif
#if defined PACKED_OPCODE_LIMITS
printvalue 32767, "32767"
printvalue 32768, "32768"
printvalue -32767, "-32767"
printvalue -32768, "-32768"
printvalue -32769, "-32769"
#endif
#if defined CONST_REL_CHAINED_OP
printf ''Result = %d (should be 1)\n'', (0 < 1 <= 2)
#endif
#if defined MULTI_DIM_PARTIAL_COUNT
new const seethis[][2]{8} = [
["bye", "hello"],
["bye", "hello"],
["bye", "hello"],
["bye", "hello"],
["bye", "hello"]
]
print(seethis[0][1]);
#endif
#if defined SUB_CONST_EXPR
new a = 40;
new p = 70 - a
new q = a - 10
printf "p=%d, q=%d (should be p=30, q=30)\n", p, q;
assert p == 30 && q == 30
#endif
#if defined MIX_PACK_ASSIGN || defined MIX_PACK_FUNC
new unpacked[4] = [ 0, ... ]
new packed{4} = { 0, ... }
#endif
#if defined MIX_PACK_ASSIGN
packed[0] = unpacked[0]
unpacked[0] = packed[0]
#endif
#if defined MIX_PACK_FUNC
unpacked[0] = 0x11223344
setpack packed, 0, unpacked[0]
unpacked[1] = getpack(packed, 0)
printf "packed: %x %x %x %x\n", packed{0}, packed{1}, packed{2}, packed{3}
printf "unpacked: %x\n", unpacked[1]
#endif
#if defined CLOSING_BRACE_NO_PARMS
new a=1, b=2
if (a>b)
{
do_abc }
#endif
#if defined VARIABLE_3D_ARRAY
new StringArray[][]{} = [ ["short1","short2"] ,
["long message 1","long message 2"] ]
for(new a = 0; a < 2; a++)
for(new b = 0; b < 2; b++)
{
print StringArray[a][b];
print "\n";
}
#endif
#if defined INIT_ARRAY_TRAILING_COMMA
static const my_array[3][3] =
[
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
];
for (new i = 0; i < sizeof(my_array); ++i)
{
printf("\t");
for (new j = 0; j < sizeof(my_array[]); ++j)
printf(" %d", my_array[i][j]);
printf("\n");
}
#endif
#if defined STRINS_MAXLENGTH
new str{} = "test"
strins str, "1", 0
printf "%s\n", str
strins str, "2", 0
printf "%s\n", str
strins str, "3", 0
printf "%s\n", str
strins str, "4", 0
printf "%s\n", str
strins str, "5", 0
printf "%s\n", str
strins str, "6", 0
printf "%s\n", str
#endif
#if defined DUPLICATE_LABEL
goto test_label;
test_label:
print("test_label 1\n");
goto test_label;
test_label:
print("test_label 2\n");
#endif
}