This repository has been archived by the owner on Nov 22, 2023. It is now read-only.
forked from gek169/seabass
-
Notifications
You must be signed in to change notification settings - Fork 1
/
featuretest.cbas
722 lines (654 loc) · 15.1 KB
/
featuretest.cbas
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
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
codegen int have_failed = 0;
class myclass
int a
int* b
int c
float d
byte e
sbyte f
end
class myclass2
int a
int* b
int c
float d
byte e
sbyte f
end
class cascader
int which
end
method codegen cascader.ctor:
this.which = 0;
end
codegen int[10] cask;
fn codegen resetCask:
u64 i
for(i = 0, i < 10, i++)
cask[i] = 0;
end
end
method codegen cascader.dtor:
//if we are 0, just set it...
if(this.which == 0)
cask[0] = 12;
return
end
//verify that cask[this.which-1] is 12...
if(cask[this.which-1] != 12)
char[50] buf
__builtin_puts("Cascade Destruction test failed...");
__builtin_itoa(buf,this.which);
__builtin_puts("On:");
__builtin_puts(buf);
have_failed = 1;
else
cask[this.which] = 12;
end
end
codegen int setme = 0;
codegen int releaseme = 0;
method codegen myclass.ctor:
this.a = 12;
this.b = 0;
this.f = 115;
this.c = 0
end
method codegen myclass.dtor:
if(this.b != 0 && this.c == 0)
this.b[0] = -91;
elif(this.b != 0 && this.c)
this.b[0] = this.c;
end
end
method codegen myclass2.ctor:
this.a = 12;
this.b = 0;
this.f = 115;
this.c = 0;
setme++;
end
method codegen myclass2.dtor:
if(this.b != 0 && this.c == 0)
this.b[0] = -91;
elif(this.b != 0 && this.c)
this.b[0] = this.c;
end
releaseme++;
end
fn codegen testmath:
int a = 7
int b = 23
int c = a + b
if(c != a + b)
__builtin_puts("Failed integer addition test 1");
have_failed = 1
end
double q = 23
double q2 = 23
double q3 = q + q2
if(q3 != q + q2)
__builtin_puts("Failed double math test 1");
have_failed = 1
end
a = -23;
b = 23;
if(a + b != 0)
__builtin_puts("Failed addition test 2- should be zero");
have_failed = 1
end
byte* p = __builtin_malloc(512);
if(p == 0)
__builtin_puts("Failed malloc");
have_failed = 1
end
__builtin_free(p);
a = 27 % 3;
if(a != 0)
__builtin_puts("Failed modulo 1");
have_failed = 1
end
a = 27 % 2;
if(a != 1)
__builtin_puts("Failed modulo 2");
have_failed = 1
end
a = 1 ^ 1;
if(a != 0)
__builtin_puts("Failed Xor 1");
have_failed = 1;
end
a = 1 ^ 0;
if(a != 1)
__builtin_puts("Failed Xor 2");
have_failed = 1;
end
a = 0 ^ 1;
if(a != 1)
__builtin_puts("Failed Xor 3");
have_failed = 1;
end
a = 9 * -7;
if(a != -63)
__builtin_puts("Failed Multiplication 1");
have_failed = 1;
end
if(1)
u64[1] a
u64*[1] b
u64[1] c
u64[1] d
c[0] = -497;
b[0] = c; //make b[0] point to c[0].
__builtin_memcpy((byte*)a,(byte*)b,8); //memcpy to a
d[0] = (u64)b[0]; //convert b[0] to a u64...
if(d[0] != a[0])
__builtin_puts("Failed pointer-to-u64 conversion test 1...");
have_failed = 1;
end
if(b[0][0] != -497)
__builtin_puts("Failed pointer test 1");
have_failed = 1;
end
end
//test sign conversion...
if(1)
sbyte a = -100;
i64 b = a;
u64 c = a;
if(b != c || b != -100)
__builtin_puts("Failed sign extension test 1");
have_failed = 1;
end
end
if(1)
short a = -100;
i64 b = a;
u64 c = a;
if(b != c || b != -100)
__builtin_puts("Failed sign extension test 2");
have_failed = 1;
end
end
if(1)
i32 a = -100;
i64 b = a;
u64 c = a;
if(b != c || b != -100)
__builtin_puts("Failed sign extension test 3");
have_failed = 1;
end
end
if(1)
sbyte a = -100;
i32 b = a;
u32 c = a;
if(b != c || b != -100)
__builtin_puts("Failed sign extension test 4");
have_failed = 1;
end
end
if(1)
sbyte a = -100;
i16 b = a;
u16 c = a;
if(b != c || b != -100)
__builtin_puts("Failed sign extension test 5");
have_failed = 1;
end
end
//test non-conversions...
if(1)
byte a = 255;
u64 b = a;
if(b != 255)
__builtin_puts("Failed sign (non) extension test 1");
have_failed = 1;
end
end
//test non-conversions...
if(1)
ushort a = 65535;
u64 b = a;
if(b != 65535)
__builtin_puts("Failed sign (non) extension test 2");
have_failed = 1;
end
//also check shifting....
if(b != ((255)<<8) | 255)
__builtin_puts("Failed bit shift test 1");
have_failed = 1;
end
//also check shifting....
if(b != (((255)<<14) | (255<<6) )>>6 )
__builtin_puts("Failed bit shift test 2");
have_failed = 1;
end
end
//test non-conversions...
if(1)
u32 a = 1<<31;
u64 b = a;
if(b != (1<<31) || b == 0 || b & (1<<30) || b != a)
__builtin_puts("Failed sign (non) extension test 3");
have_failed = 1;
end
end
end
fn codegen test_loops:
for(0,0,0)
__builtin_puts("Failed for(0,0,0)");
have_failed = 1
end
for(1,1,1)
goto after_for_111
end
__builtin_puts("Failed for(1,1,1)");
have_failed = 1;
:after_for_111
i64 i
i64 j = 0
i64 k
//if(1)
k = 0
for(i = 0, i < 20; i++)
k++;
if(i == 3)
j--;
break
end
j++;
end
if(i != 3 || j != (3-1) || k != 4)
__builtin_puts("Failed Loop Test 1");
char[50] buf
__builtin_utoa(buf, i);
__builtin_puts(buf);
__builtin_utoa(buf, j);
__builtin_puts(buf);
have_failed = 1
end
//end
i = 12;
j = -13;
while(i > 0)
i = i - 1;
j--;
end
if(i != 0 || j != -25)
__builtin_puts("Failed Loop Test 2");
char[50] buf
__builtin_itoa(buf, i);
__builtin_puts(buf);
__builtin_itoa(buf, j);
__builtin_puts(buf);
have_failed = 1
end
i = 12;
j = -13;
while(1)
i = i - 1;
j--;
if(i == 0)
if(1)
if(1)
if(1)
if(1)
break
end
end
end
end
end
end
if(i != 0 || j != -25)
__builtin_puts("Failed Loop Test 2");
char[50] buf
__builtin_itoa(buf, i);
__builtin_puts(buf);
__builtin_itoa(buf, j);
__builtin_puts(buf);
have_failed = 1
end
i = 23;
j = 0;
while(1)
i++
while(1)
j++;
if(i == j)
break
end
end
if(i == 40)
break
end
end
if(i != j || i != 40)
__builtin_puts("Failed Loop Test 3");
char[50] buf
__builtin_itoa(buf, i);
__builtin_puts(buf);
__builtin_itoa(buf, j);
__builtin_puts(buf);
have_failed = 1
end
i = 23;
j = 0;
while(1)
i++
while(1)
j++;
if(i == j)
goto out1
end
end
:out1
if(i == 40)
jump out2
end
end
:out2
for(k = 0, k < i, k++)
;
end
if(i != j || i != 40 || i != k)
__builtin_puts("Failed Loop Test 3");
char[50] buf
__builtin_itoa(buf, i);
__builtin_puts(buf);
__builtin_itoa(buf, j);
__builtin_puts(buf);
have_failed = 1
end
while(1)
while(1)
break
end
break
end
end
fn codegen test_switch:
i64 i = 0
i64 j = 0
i64 k = 0
switch(1+2+3) l0 l1 l2 l3 l4 l5 l6 l7 l8 l9 l10;
:l0 i = 1 goto l_last
:l1 i = 1 goto l_last
:l2 i = 1 goto l_last
:l3 i = 1 goto l_last
:l4 i = 1 goto l_last
:l5 i = 1 goto l_last
:l6 goto l_last
:l7 i = 1 goto l_last
:l8 i = 1 goto l_last
:l9 i = 1 goto l_last
:l10 i = 1 goto l_last
:l11 i = 1 goto l_last
:l12 i = 1 goto l_last
:l13 i = 1 goto l_last
:l14 i = 1 goto l_last
:l_last
if(i != 0)
have_failed = 1;
__builtin_puts("Failed switch test")
end
return
end
fn codegen test_writefile_readfile:
__builtin_open_ofile("test.out");
__builtin_emit("1234567890",11);
__builtin_close_ofile();
u64[1] len
len[0] = 0
char* p = __builtin_read_file("test.out",len);
if(len[0] != 11 || p == 0)
__builtin_puts("Failed File I/O test - Could not read file.");
have_failed = 1;
end
if(p strneq "1234567890")
__builtin_puts("Failed File I/O test - File contents failure.");
have_failed = 1;
end
__builtin_free(p);
end
procedure codegen test_arrays_pointers:
u64[512] arr;
arr[0] = 12;
arr[57] = 13;
arr[58] = ~0;
arr[56] = ~0;
if((arr+57)[0] != 13)
__builtin_puts("Failed Pointer Arithmetic Test 1");
have_failed = 1;
end
if((arr + 100) - (100-57) != arr + 57 )
__builtin_puts("Failed Pointer Arithmetic Test 2");
have_failed = 1;
end
if((u64)(arr+12) - (u64)(arr+10) != 16)
__builtin_puts("Failed Pointer Arithmetic Test 3");
have_failed = 1;
end
if((arr+12) - 10 != arr + 2)
__builtin_puts("Failed Pointer Arithmetic Test 4");
have_failed = 1;
end
end
procedure codegen test_ctor_dtor:
int[1] ff;
int[1] gg;
ff[0] = 0;
gg[0] = 0;
if(1)
myclass qq
if(qq.a != 12 || qq.f != 115)
__builtin_puts("Failed Constructor Test 1");
have_failed = 1;
end
qq.b = ff;
end
if(ff[0] != -91)
__builtin_puts("Failed Destructor Test 1");
have_failed = 1;
end
ff[0] =0;
while(1)
myclass qq
while(1)
break
end
break
end
while(1)
myclass qq
while(1)
myclass rr
rr.b = ff;
qq.b = gg;
qq.c = 23;
break
end
if(ff[0] != -91)
__builtin_puts("Failed destructor test 2");
have_failed = 1;
end
break
end
if(gg[0] != 23)
__builtin_puts("Failed destructor test 3");
have_failed = 1;
end
resetCask();
//verify cascade destruction....
if(1)
cascader a;a.which = 3;
if(1)
cascader b;b.which = 2;
if(1)
cascader c;c.which = 1;
if(1)
cascader d;d.which = 0;
end
end
end
end
//2....
resetCask();
//verify cascade destruction....
while(1)
cascader a;a.which = 3;
while(1)
cascader b;b.which = 2;
while(1)
cascader c;c.which = 1;
while(1)
cascader d;d.which = 0;
goto beyond
end
end
end
end
:beyond
resetCask();
//verify cascade destruction....
while(1)
cascader a;a.which = 3;
while(1)
cascader b;b.which = 2;
while(1)
cascader c;c.which = 1;
while(1)
cascader d;d.which = 0;
break
end
break
end
goto beyond2
end
end
:beyond2
resetCask();
//verify cascade destruction....
while(1)
cascader a;a.which = 3;
while(1)
cascader b;b.which = 2;
while(1)
cascader c;c.which = 1;
while(1)
cascader d;d.which = 0;
break
end
break
end
break
end
break
end
//verify cascade destruction....
resetCask()
while(1)
cascader a;a.which = 3;
while(1)
cascader b;b.which = 2;
while(1)
cascader c;c.which = 1;
while(1)
cascader d;d.which = 0;
return
end
break
end
break
end
break
end
//unreachable...
__builtin_puts("You should never see this text. Failed deeply nested destructor cascade.");
have_failed = 1;
end
proc codegen test_tail_calls2->i64;
proc codegen test_tail_calls3->i64;
proc codegen test_tail_calls4(int a, int b)->i64;
proc codegen test_tail_calls5(int a, int b)->i64;
proc codegen test_tail_calls1->i64:
myclass2 a
tail test_tail_calls2
end
proc codegen test_tail_calls2->i64:
myclass2 a
tail test_tail_calls3
end
proc codegen test_tail_calls3->i64:
myclass2 a
return -473
end
proc codegen test_tail_calls4(int a, int b)->i64:
if(a <= 0)
return b;
end
a--;
b++;
tail test_tail_calls4
end
function codegen test_tail_calls5(int a, int b)->i64:
while(a < 200)
a++
if(a == 189) break end
end
tail test_tail_calls4
end
proc codegen test_tail_calls:
i64 qq = test_tail_calls1();
if(qq != -473)
__builtin_puts("Failed Tail Call Test 1");
have_failed = 1;
end
if(setme != 3 || releaseme != 3)
__builtin_puts("Failed Tail Call Test 1 (CTOR DTOR)");
have_failed = 1;
end
qq = test_tail_calls4(200,0);
if(qq != 200)
__builtin_puts("Failed Tail Call Test 2");
have_failed = 1;
end
qq = test_tail_calls4(200,100);
if(qq != 300)
__builtin_puts("Failed Tail Call Test 3");
have_failed = 1;
end
qq = test_tail_calls5(100, 100);
if(qq != 289)
__builtin_puts("Failed Tail Call Test 4");
have_failed = 1;
end
qq = test_tail_calls5(189, 500);
if(qq != 700)
__builtin_puts("Failed Tail Call Test 5");
have_failed = 1;
end
end
fn codegen codegen_main:
__builtin_puts("TESTING BASIC ARITHMETIC");
testmath();
__builtin_puts("TESTING ARRAYS AND POINTERS");
test_arrays_pointers();
__builtin_puts("TESTING LOOPS");
test_loops();
__builtin_puts("TESTING SWITCH");
test_switch;
__builtin_puts("TESTING FILES");
test_writefile_readfile();
__builtin_puts("TESTING CTOR_DTOR");
test_ctor_dtor();
__builtin_puts("TESTING TAIL CALLS");
test_tail_calls();
if(!have_failed)
__builtin_puts("Success!!!!");
else
__builtin_puts("------------FAILED--------------------");
__builtin_exit(1);
end
end