vxx2 / vlib / v3 / tests / test_all_lang_features.v
6847 lines · 5914 sloc · 145.39 KB · 6c4d26f1f98c5464b012a375667ab345e462f7e0
Raw
1module main
2
3import math
4import os
5import sync
6import strings
7import v3.bench
8import v.token
9
10// Cat represents cat data used by v3 tests.
11struct Cat {
12 name string
13 age int
14}
15
16// Dog represents dog data used by v3 tests.
17struct Dog {
18 name string
19 tricks int
20}
21
22// Animal aliases animal values used by v3 tests.
23type Animal = Cat | Dog
24
25// UserId104 aliases user id104 values used by v3 tests.
26type UserId104 = int
27
28// Holder represents holder data used by v3 tests.
29struct Holder {
30mut:
31 pet Animal
32}
33
34// describe_holder supports describe holder handling for v3 tests.
35fn describe_holder(h Holder) string {
36 if h.pet is Cat {
37 return h.pet.name
38 } else if h.pet is Dog {
39 return h.pet.name
40 }
41 return 'unknown'
42}
43
44// holder_detail supports holder detail handling for v3 tests.
45fn holder_detail(h Holder) int {
46 match h.pet {
47 Cat {
48 return h.pet.age
49 }
50 Dog {
51 return h.pet.tricks
52 }
53 }
54
55 return 0
56}
57
58// Point represents point data used by v3 tests.
59struct Point {
60mut:
61 x int
62 y int
63}
64
65// Node represents node data used by v3 tests.
66struct Node {
67mut:
68 value int
69 left int
70 right int
71}
72
73// Rectangle represents rectangle data used by v3 tests.
74struct Rectangle {
75mut:
76 width int
77 height int
78 origin Point
79}
80
81__global (
82 g_val int
83 g_count int
84 g_flag bool
85 g_point Point
86 g_vec Vec3
87 g_acc int
88 g_toggle bool
89)
90
91// ===================== HELPER FUNCTIONS =====================
92
93// fib supports fib handling for v3 tests.
94fn fib(n int) int {
95 if n < 2 {
96 return n
97 }
98 return fib(n - 1) + fib(n - 2)
99}
100
101// factorial supports factorial handling for v3 tests.
102fn factorial(n int) int {
103 if n <= 1 {
104 return 1
105 }
106 return n * factorial(n - 1)
107}
108
109// sum_recursive supports sum recursive handling for v3 tests.
110fn sum_recursive(n int) int {
111 if n <= 0 {
112 return 0
113 }
114 return n + sum_recursive(n - 1)
115}
116
117// Foo97 represents foo97 data used by v3 tests.
118struct Foo97 {
119 x int
120 y int
121 name string
122 val int
123}
124
125// new creates a Foo97 value for v3 tests.
126fn Foo97.new(x int, y int) Foo97 {
127 return Foo97{
128 x: x
129 y: y
130 }
131}
132
133// with_name supports with name handling for Foo97.
134fn Foo97.with_name(name string, val int) Foo97 {
135 return Foo97{
136 name: name
137 val: val
138 }
139}
140
141// multiply supports multiply handling for v3 tests.
142fn multiply(a int, b int) int {
143 return a * b
144}
145
146// apply_op supports apply op handling for v3 tests.
147fn apply_op(f fn (int, int) int, x int, y int) int {
148 return f(x, y)
149}
150
151// gcd supports gcd handling for v3 tests.
152fn gcd(a int, b int) int {
153 if b == 0 {
154 return a
155 }
156 return gcd(b, a % b)
157}
158
159// power supports power handling for v3 tests.
160fn power(base int, exp int) int {
161 if exp == 0 {
162 return 1
163 }
164 return base * power(base, exp - 1)
165}
166
167// add updates add state for v3 tests.
168fn add(a int, b int) int {
169 return a + b
170}
171
172// sub supports sub handling for v3 tests.
173fn sub(a int, b int) int {
174 return a - b
175}
176
177// mul supports mul handling for v3 tests.
178fn mul(a int, b int) int {
179 return a * b
180}
181
182// print_rec updates print rec state for v3 tests.
183fn print_rec(n int) {
184 if n == 0 {
185 return
186 }
187 print_rec(n / 10)
188 rem := n - (n / 10) * 10
189 C.putchar(rem + 48)
190}
191
192// print_int updates print int state for v3 tests.
193fn print_int(n int) {
194 if n == 0 {
195 C.putchar(48)
196 C.putchar(10)
197 return
198 }
199 mut v := n
200 if n < 0 {
201 C.putchar(45)
202 v = 0 - n
203 }
204 print_rec(v)
205 C.putchar(10)
206}
207
208// print_str updates print str state for v3 tests.
209fn print_str(s string) {
210 C.puts(s.str)
211}
212
213// repeat supports repeat handling for v3 tests.
214fn repeat(c u8, n int) int {
215 if c == `x` && n == 3 {
216 return 8
217 }
218 return 0
219}
220
221// next_in_value returns next in value data for v3 tests.
222fn next_in_value() int {
223 g_count = g_count + 1
224 return g_count
225}
226
227// maybe_review_value supports maybe review value handling for v3 tests.
228fn maybe_review_value(ok bool) ?int {
229 if ok {
230 return 42
231 }
232 return none
233}
234
235// optional_arg_int104 supports optional arg int104 handling for v3 tests.
236fn optional_arg_int104(x ?int) int {
237 return x or { -1 }
238}
239
240// optional_arg_point104 supports optional arg point104 handling for v3 tests.
241fn optional_arg_point104(p ?Point) int {
242 pt := p or { return -1 }
243 return pt.x + pt.y
244}
245
246// make_review_animal builds make review animal data for v3 tests.
247fn make_review_animal() Animal {
248 return Cat{
249 name: 'Milo'
250 age: 4
251 }
252}
253
254// next supports next handling for UserId104.
255fn (id UserId104) next() int {
256 return int(id) + 1
257}
258
259// sum_many supports sum many handling for v3 tests.
260fn sum_many(a int, b int, c int, d int, e int, f int, g int, h int) int {
261 return a + b + c + d + e + f + g + h
262}
263
264// mul_many supports mul many handling for v3 tests.
265fn mul_many(a int, b int, c int, d int, e int, f int, g int, h int) int {
266 return a * b * c * d * e * f * g * h
267}
268
269// max_of_eight supports max of eight handling for v3 tests.
270fn max_of_eight(a int, b int, c int, d int, e int, f int, g int, h int) int {
271 mut m := a
272 if b > m {
273 m = b
274 }
275 if c > m {
276 m = c
277 }
278 if d > m {
279 m = d
280 }
281 if e > m {
282 m = e
283 }
284 if f > m {
285 m = f
286 }
287 if g > m {
288 m = g
289 }
290 if h > m {
291 m = h
292 }
293 return m
294}
295
296// weighted_sum supports weighted sum handling for v3 tests.
297fn weighted_sum(a int, b int, c int, d int, e int, f int, g int, h int) int {
298 return a * 1 + b * 2 + c * 3 + d * 4 + e * 5 + f * 6 + g * 7 + h * 8
299}
300
301// Color represents color data used by v3 tests.
302struct Color {
303mut:
304 r int
305 g int
306 b int
307 a int
308}
309
310// Vec3 represents vec3 data used by v3 tests.
311struct Vec3 {
312mut:
313 x int
314 y int
315 z int
316}
317
318// Matrix2x2 represents matrix2x2 data used by v3 tests.
319struct Matrix2x2 {
320mut:
321 a int
322 b int
323 c int
324 d int
325}
326
327// LinkedNode represents linked node data used by v3 tests.
328struct LinkedNode {
329mut:
330 val int
331 next int
332}
333
334// Stats represents stats data used by v3 tests.
335struct Stats {
336mut:
337 min_v int
338 max_v int
339 sum int
340 count int
341}
342
343// make_point builds make point data for v3 tests.
344fn make_point(px int, py int) Point {
345 return Point{
346 x: px
347 y: py
348 }
349}
350
351// add_points updates add points state for v3 tests.
352fn add_points(a Point, b Point) Point {
353 return Point{
354 x: a.x + b.x
355 y: a.y + b.y
356 }
357}
358
359// abs_val supports abs val handling for v3 tests.
360fn abs_val(n int) int {
361 if n < 0 {
362 return 0 - n
363 }
364 return n
365}
366
367// min_val supports min val handling for v3 tests.
368fn min_val(a int, b int) int {
369 if a < b {
370 return a
371 }
372 return b
373}
374
375// max_val supports max val handling for v3 tests.
376fn max_val(a int, b int) int {
377 if a > b {
378 return a
379 }
380 return b
381}
382
383// clamp supports clamp handling for v3 tests.
384fn clamp(val int, lo int, hi int) int {
385 if val < lo {
386 return lo
387 }
388 if val > hi {
389 return hi
390 }
391 return val
392}
393
394// collatz_steps supports collatz steps handling for v3 tests.
395fn collatz_steps(start int) int {
396 mut v := start
397 mut steps := 0
398 for v != 1 {
399 if v % 2 == 0 {
400 v = v / 2
401 } else {
402 v = v * 3 + 1
403 }
404 steps++
405 }
406 return steps
407}
408
409// sum_digits supports sum digits handling for v3 tests.
410fn sum_digits(n int) int {
411 mut v := n
412 if v < 0 {
413 v = 0 - v
414 }
415 mut s := 0
416 for v > 0 {
417 s += v % 10
418 v = v / 10
419 }
420 return s
421}
422
423// count_bits supports count bits handling for v3 tests.
424fn count_bits(n int) int {
425 mut v := n
426 mut count := 0
427 for v != 0 {
428 count += v & 1
429 v = v >> 1
430 }
431 return count
432}
433
434// classify supports classify handling for v3 tests.
435fn classify(n int) int {
436 if n > 100 {
437 return 3
438 } else if n > 50 {
439 return 2
440 } else if n > 0 {
441 return 1
442 } else {
443 return 0
444 }
445}
446
447// point_quadrant supports point quadrant handling for v3 tests.
448fn point_quadrant(p Point) int {
449 if p.x > 0 && p.y > 0 {
450 return 1
451 } else if p.x < 0 && p.y > 0 {
452 return 2
453 } else if p.x < 0 && p.y < 0 {
454 return 3
455 } else if p.x > 0 && p.y < 0 {
456 return 4
457 } else {
458 return 0
459 }
460}
461
462// make_color builds make color data for v3 tests.
463fn make_color(r int, g int, b int, a int) Color {
464 return Color{
465 r: r
466 g: g
467 b: b
468 a: a
469 }
470}
471
472// color_brightness supports color brightness handling for v3 tests.
473fn color_brightness(c Color) int {
474 return (c.r + c.g + c.b) / 3
475}
476
477// scale_rect supports scale rect handling for v3 tests.
478fn scale_rect(mut r Rectangle, factor int) {
479 r.width = r.width * factor
480 r.height = r.height * factor
481}
482
483// modify_struct supports modify struct handling for v3 tests.
484fn modify_struct(mut p Point) {
485 p.x = 999
486 p.y = 888
487}
488
489// swap_point supports swap point handling for v3 tests.
490fn swap_point(mut p Point) {
491 tmp := p.x
492 p.x = p.y
493 p.y = tmp
494}
495
496// scale_point supports scale point handling for v3 tests.
497fn scale_point(mut p Point, factor int) {
498 p.x = p.x * factor
499 p.y = p.y * factor
500}
501
502// translate_point supports translate point handling for v3 tests.
503fn translate_point(mut p Point, dx int, dy int) {
504 p.x = p.x + dx
505 p.y = p.y + dy
506}
507
508// reset_point updates reset point state for v3 tests.
509fn reset_point(mut p Point) {
510 p.x = 0
511 p.y = 0
512}
513
514// vec3_dot supports vec3 dot handling for v3 tests.
515fn vec3_dot(a Vec3, b Vec3) int {
516 return a.x * b.x + a.y * b.y + a.z * b.z
517}
518
519// vec3_cross_z supports vec3 cross z handling for v3 tests.
520fn vec3_cross_z(a Vec3, b Vec3) int {
521 return a.x * b.y - a.y * b.x
522}
523
524// vec3_len_sq supports vec3 len sq handling for v3 tests.
525fn vec3_len_sq(v Vec3) int {
526 return v.x * v.x + v.y * v.y + v.z * v.z
527}
528
529// vec3_add supports vec3 add handling for v3 tests.
530fn vec3_add(a Vec3, b Vec3) Vec3 {
531 return Vec3{
532 x: a.x + b.x
533 y: a.y + b.y
534 z: a.z + b.z
535 }
536}
537
538// vec3_scale supports vec3 scale handling for v3 tests.
539fn vec3_scale(v Vec3, s int) Vec3 {
540 return Vec3{
541 x: v.x * s
542 y: v.y * s
543 z: v.z * s
544 }
545}
546
547// mat_det supports mat det handling for v3 tests.
548fn mat_det(m Matrix2x2) int {
549 return m.a * m.d - m.b * m.c
550}
551
552// mat_mul supports mat mul handling for v3 tests.
553fn mat_mul(m Matrix2x2, n Matrix2x2) Matrix2x2 {
554 return Matrix2x2{
555 a: m.a * n.a + m.b * n.c
556 b: m.a * n.b + m.b * n.d
557 c: m.c * n.a + m.d * n.c
558 d: m.c * n.b + m.d * n.d
559 }
560}
561
562// mat_trace supports mat trace handling for v3 tests.
563fn mat_trace(m Matrix2x2) int {
564 return m.a + m.d
565}
566
567// is_prime reports whether is prime applies in v3 tests.
568fn is_prime(n int) bool {
569 if n < 2 {
570 return false
571 }
572 mut i := 2
573 for i * i <= n {
574 if n % i == 0 {
575 return false
576 }
577 i++
578 }
579 return true
580}
581
582// isqrt supports isqrt handling for v3 tests.
583fn isqrt(n int) int {
584 if n <= 0 {
585 return 0
586 }
587 mut x := n
588 mut y := (x + 1) / 2
589 for y < x {
590 x = y
591 y = (x + n / x) / 2
592 }
593 return x
594}
595
596// reverse_int supports reverse int handling for v3 tests.
597fn reverse_int(n int) int {
598 mut v := n
599 mut neg := false
600 if v < 0 {
601 neg = true
602 v = 0 - v
603 }
604 mut result := 0
605 for v > 0 {
606 result = result * 10 + v % 10
607 v = v / 10
608 }
609 if neg {
610 return 0 - result
611 }
612 return result
613}
614
615// count_digits supports count digits handling for v3 tests.
616fn count_digits(n int) int {
617 if n == 0 {
618 return 1
619 }
620 mut v := n
621 if v < 0 {
622 v = 0 - v
623 }
624 mut count := 0
625 for v > 0 {
626 count++
627 v = v / 10
628 }
629 return count
630}
631
632// is_palindrome_num reports whether is palindrome num applies in v3 tests.
633fn is_palindrome_num(n int) bool {
634 if n < 0 {
635 return false
636 }
637 return n == reverse_int(n)
638}
639
640// update_stats supports update stats handling for v3 tests.
641fn update_stats(mut s Stats, val int) {
642 if s.count == 0 || val < s.min_v {
643 s.min_v = val
644 }
645 if s.count == 0 || val > s.max_v {
646 s.max_v = val
647 }
648 s.sum += val
649 s.count++
650}
651
652// binary_search_step supports binary search step handling for v3 tests.
653fn binary_search_step(target int, lo int, hi int, a0 int, a1 int, a2 int, a3 int, a4 int) int {
654 if lo > hi {
655 return 0 - 1
656 }
657 mid := (lo + hi) / 2
658 mut mid_val := 0
659 if mid == 0 {
660 mid_val = a0
661 } else if mid == 1 {
662 mid_val = a1
663 } else if mid == 2 {
664 mid_val = a2
665 } else if mid == 3 {
666 mid_val = a3
667 } else {
668 mid_val = a4
669 }
670
671 if mid_val == target {
672 return mid
673 } else if mid_val < target {
674 return binary_search_step(target, mid + 1, hi, a0, a1, a2, a3, a4)
675 }
676 return binary_search_step(target, lo, mid - 1, a0, a1, a2, a3, a4)
677}
678
679// ackermann supports ackermann handling for v3 tests.
680fn ackermann(m int, n int) int {
681 if m == 0 {
682 return n + 1
683 }
684 if n == 0 {
685 return ackermann(m - 1, 1)
686 }
687 return ackermann(m - 1, ackermann(m, n - 1))
688}
689
690// triangle_area_2x supports triangle area 2x handling for v3 tests.
691fn triangle_area_2x(x1 int, y1 int, x2 int, y2 int, x3 int, y3 int) int {
692 area := x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)
693 if area < 0 {
694 return 0 - area
695 }
696 return area
697}
698
699// rotate_point_90 supports rotate point 90 handling for v3 tests.
700fn rotate_point_90(p Point) Point {
701 return Point{
702 x: 0 - p.y
703 y: p.x
704 }
705}
706
707// manhattan_dist supports manhattan dist handling for v3 tests.
708fn manhattan_dist(a Point, b Point) int {
709 mut dx := a.x - b.x
710 mut dy := a.y - b.y
711 if dx < 0 {
712 dx = 0 - dx
713 }
714 if dy < 0 {
715 dy = 0 - dy
716 }
717 return dx + dy
718}
719
720// digital_root supports digital root handling for v3 tests.
721fn digital_root(n int) int {
722 mut v := n
723 if v < 0 {
724 v = 0 - v
725 }
726 for v >= 10 {
727 v = sum_digits(v)
728 }
729 return v
730}
731
732// lerp supports lerp handling for v3 tests.
733fn lerp(a int, b int, t_num int, t_den int) int {
734 return a + (b - a) * t_num / t_den
735}
736
737// sign supports sign handling for v3 tests.
738fn sign(n int) int {
739 if n > 0 {
740 return 1
741 } else if n < 0 {
742 return 0 - 1
743 }
744 return 0
745}
746
747// popcount_loop supports popcount loop handling for v3 tests.
748fn popcount_loop(n int) int {
749 mut v := n
750 mut c := 0
751 for v != 0 {
752 v = v & (v - 1)
753 c++
754 }
755 return c
756}
757
758// leading_zeros supports leading zeros handling for v3 tests.
759fn leading_zeros(n int) int {
760 if n == 0 {
761 return 32
762 }
763 mut v := n
764 mut count := 0
765 mut mask := 1 << 30
766 for mask > 0 {
767 if v & mask != 0 {
768 return count
769 }
770 count++
771 mask = mask >> 1
772 }
773 return count
774}
775
776// ===================== METHODS =====================
777
778// sum supports sum handling for Point.
779fn (p Point) sum() int {
780 return p.x + p.y
781}
782
783// product supports product handling for Point.
784fn (p Point) product() int {
785 return p.x * p.y
786}
787
788// double supports double handling for Point.
789fn (mut p Point) double() {
790 p.x = p.x * 2
791 p.y = p.y * 2
792}
793
794// area supports area handling for Rectangle.
795fn (r Rectangle) area() int {
796 return r.width * r.height
797}
798
799// perimeter supports perimeter handling for Rectangle.
800fn (r Rectangle) perimeter() int {
801 return 2 * (r.width + r.height)
802}
803
804// total supports total handling for Node.
805fn (n Node) total() int {
806 return n.value + n.left + n.right
807}
808
809// ===================== IF-EXPRESSION HELPERS =====================
810
811// int_abs supports int abs handling for v3 tests.
812fn int_abs(a int) int {
813 return if a < 0 { 0 - a } else { a }
814}
815
816// int_max2 supports int max2 handling for v3 tests.
817fn int_max2(a int, b int) int {
818 return if a > b { a } else { b }
819}
820
821// int_min2 supports int min2 handling for v3 tests.
822fn int_min2(a int, b int) int {
823 return if a < b { a } else { b }
824}
825
826// sign_expr supports sign expr handling for v3 tests.
827fn sign_expr(x int) int {
828 return if x < 0 {
829 0 - 1
830 } else {
831 if x > 0 {
832 1
833 } else {
834 0
835 }
836 }
837}
838
839// clamp_expr supports clamp expr handling for v3 tests.
840fn clamp_expr(x int, lo int, hi int) int {
841 return if x < lo {
842 lo
843 } else {
844 if x > hi {
845 hi
846 } else {
847 x
848 }
849 }
850}
851
852// ===================== DEFER HELPERS =====================
853
854// defer_return_test supports defer return test handling for v3 tests.
855fn defer_return_test() int {
856 defer {
857 g_acc += 100
858 }
859 return 42
860}
861
862// defer_order_test supports defer order test handling for v3 tests.
863fn defer_order_test() {
864 defer { g_acc += 1 }
865 defer { g_acc += 10 }
866 defer { g_acc += 100 }
867}
868
869// ===================== ENUMS =====================
870
871// nested_return supports nested return handling for v3 tests.
872fn nested_return(x int) int {
873 if x < 10 {
874 return 100
875 } else {
876 if x < 20 {
877 return 200
878 } else {
879 return 300
880 }
881 }
882}
883
884// operator_to_name converts operator to name data for v3 tests.
885fn operator_to_name(op string) string {
886 return match op {
887 '+' { '__plus' }
888 '-' { '__minus' }
889 '*' { '__mul' }
890 '/' { '__div' }
891 else { op }
892 }
893}
894
895// get_type_name returns get type name data for v3 tests.
896fn get_type_name(is_signed bool, size int) string {
897 return if is_signed {
898 match size {
899 8 { 'i8' }
900 16 { 'i16' }
901 32 { 'int' }
902 64 { 'i64' }
903 else { 'int' }
904 }
905 } else {
906 match size {
907 8 { 'u8' }
908 16 { 'u16' }
909 32 { 'u32' }
910 else { 'u64' }
911 }
912 }
913}
914
915// test_return_if_expr validates return if expr behavior in v3 tests.
916fn test_return_if_expr() {
917 assert get_type_name(true, 32) == 'int'
918 assert get_type_name(false, 64) == 'u64'
919 assert get_type_name(true, 8) == 'i8'
920 assert get_type_name(false, 16) == 'u16'
921 print_str('return if expr: ok')
922}
923
924// Direction lists direction values used by v3 tests.
925enum Direction {
926 up
927 down
928 left
929 right
930}
931
932// ===================== MULTI-RETURN FUNCTIONS =====================
933
934// two_vals supports two vals handling for v3 tests.
935fn two_vals() (int, string) {
936 return 42, 'hello'
937}
938
939// swap_ints supports swap ints handling for v3 tests.
940fn swap_ints(a int, b int) (int, int) {
941 return b, a
942}
943
944// three_ints supports three ints handling for v3 tests.
945fn three_ints(x int) (int, int, int) {
946 return x, x * 2, x * 3
947}
948
949// ===================== STRUCT OPERATORS =====================
950
951// operator + implements the + operator for Point.
952fn (a Point) + (b Point) Point {
953 return Point{
954 x: a.x + b.x
955 y: a.y + b.y
956 }
957}
958
959// operator == implements the == operator for Point.
960fn (a Point) == (b Point) bool {
961 return a.x == b.x && a.y == b.y
962}
963
964// operator < implements the < operator for Point.
965fn (a Point) < (b Point) bool {
966 return a.x + a.y < b.x + b.y
967}
968
969// ===================== RETURN MATCH / IF-EXPR-STRING =====================
970
971// classify_str supports classify str handling for v3 tests.
972fn classify_str(n int) string {
973 return match n {
974 0 { 'zero' }
975 1 { 'one' }
976 2 { 'two' }
977 else { 'other' }
978 }
979}
980
981// describe_sign supports describe sign handling for v3 tests.
982fn describe_sign(n int) string {
983 return if n > 0 {
984 'positive'
985 } else if n < 0 {
986 'negative'
987 } else {
988 'zero'
989 }
990}
991
992// return_assoc_point supports return assoc point handling for v3 tests.
993fn return_assoc_point(p Point, new_x int) Point {
994 return Point{
995 ...p
996 x: new_x
997 }
998}
999
1000// ===================== MAIN TEST FUNCTION =====================
1001
1002// try_get_value supports try get value handling for v3 tests.
1003fn try_get_value(ok bool) ?int {
1004 if ok {
1005 return 42
1006 }
1007 return none
1008}
1009
1010// CallInfo115 represents call info115 data used by v3 tests.
1011struct CallInfo115 {
1012 name string
1013 score int
1014}
1015
1016// maybe_call_info115 supports maybe call info115 handling for v3 tests.
1017fn maybe_call_info115(ok bool) ?CallInfo115 {
1018 if ok {
1019 return CallInfo115{
1020 name: 'resolved'
1021 score: 7
1022 }
1023 }
1024 return none
1025}
1026
1027// make_scores115 builds make scores115 data for v3 tests.
1028fn make_scores115() map[string]int {
1029 mut scores := map[string]int{}
1030 scores['alpha'] = 2
1031 scores['beta'] = 3
1032 scores['gamma'] = 4
1033 return scores
1034}
1035
1036// Defaults116 represents defaults116 data used by v3 tests.
1037struct Defaults116 {
1038 name string = 'v' + '3'
1039 count int = 42
1040}
1041
1042// MetaType117 aliases meta type117 values used by v3 tests.
1043type MetaType117 = MetaNamed117
1044 | MetaIface117
1045 | MetaArray117
1046 | MetaMap117
1047 | MetaFn117
1048 | MetaPointer117
1049
1050// CastLeak117 aliases cast leak117 values used by v3 tests.
1051type CastLeak117 = CastNamed117 | CastOther117
1052
1053// SumNameLeft117 aliases sum name left117 values used by v3 tests.
1054type SumNameLeft117 = SumNameLeftNamed117 | SumNameLeftOther117
1055
1056// SumNameRight117 aliases sum name right117 values used by v3 tests.
1057type SumNameRight117 = SumNameRightNamed117 | SumNameRightOther117
1058
1059// MetaNamed117 represents meta named117 data used by v3 tests.
1060struct MetaNamed117 {
1061 name string
1062}
1063
1064// MetaIface117 represents meta iface117 data used by v3 tests.
1065struct MetaIface117 {
1066 name string
1067}
1068
1069// MetaArray117 represents meta array117 data used by v3 tests.
1070struct MetaArray117 {
1071 elem MetaType117
1072}
1073
1074// MetaMap117 represents meta map117 data used by v3 tests.
1075struct MetaMap117 {
1076 key MetaType117
1077 val MetaType117
1078}
1079
1080// MetaFn117 represents meta fn117 data used by v3 tests.
1081struct MetaFn117 {
1082 params []MetaType117
1083 ret MetaType117
1084}
1085
1086// MetaPointer117 represents meta pointer117 data used by v3 tests.
1087struct MetaPointer117 {
1088 base MetaType117
1089}
1090
1091// Registry117 represents registry117 data used by v3 tests.
1092struct Registry117 {
1093 prefix string
1094mut:
1095 items map[string]MetaType117
1096}
1097
1098// Stack117 represents stack117 data used by v3 tests.
1099struct Stack117 {
1100mut:
1101 values []int
1102}
1103
1104// Instr117 represents instr117 data used by v3 tests.
1105struct Instr117 {
1106 op int
1107 operands []int
1108}
1109
1110// FieldBag117 represents field bag117 data used by v3 tests.
1111struct FieldBag117 {
1112 values []int
1113}
1114
1115// TypeStore117 represents type store117 data used by v3 tests.
1116struct TypeStore117 {
1117 types []FieldBag117
1118}
1119
1120// Symbol117 represents symbol117 data used by v3 tests.
1121struct Symbol117 {
1122 sect int
1123mut:
1124 value int
1125}
1126
1127// SymbolStore117 represents symbol store117 data used by v3 tests.
1128struct SymbolStore117 {
1129mut:
1130 symbols []Symbol117
1131}
1132
1133// ForField117 represents for field117 data used by v3 tests.
1134struct ForField117 {
1135 name string
1136 typ MetaType117
1137}
1138
1139// OptionalContext117 represents optional context117 data used by v3 tests.
1140struct OptionalContext117 {
1141 expr string
1142 variant string
1143 sum string
1144}
1145
1146// OptionalContextHolder117 represents optional context holder117 data used by v3 tests.
1147struct OptionalContextHolder117 {
1148 items []OptionalContext117
1149}
1150
1151// ConstHolder117 represents const holder117 data used by v3 tests.
1152struct ConstHolder117 {
1153 value int
1154}
1155
1156const zero_const_holder117 = ConstHolder117{}
1157
1158// CastNamed117 represents cast named117 data used by v3 tests.
1159struct CastNamed117 {
1160 name string
1161}
1162
1163// CastOther117 represents cast other117 data used by v3 tests.
1164struct CastOther117 {
1165 id int
1166}
1167
1168// SumNameLeftNamed117 represents sum name left named117 data used by v3 tests.
1169struct SumNameLeftNamed117 {
1170 value string
1171}
1172
1173// SumNameLeftOther117 represents sum name left other117 data used by v3 tests.
1174struct SumNameLeftOther117 {}
1175
1176// SumNameRightNamed117 represents sum name right named117 data used by v3 tests.
1177struct SumNameRightNamed117 {
1178 value string
1179}
1180
1181// SumNameRightOther117 represents sum name right other117 data used by v3 tests.
1182struct SumNameRightOther117 {}
1183
1184// Marker117 lists marker117 values used by v3 tests.
1185enum Marker117 {
1186 off
1187 on
1188}
1189
1190// ScalarAlias117 aliases scalar alias117 values used by v3 tests.
1191type ScalarAlias117 = int
1192
1193const fixed_len117 = 3
1194
1195// FixedHolder117 represents fixed holder117 data used by v3 tests.
1196struct FixedHolder117 {
1197 values [fixed_len117]int
1198}
1199
1200// FnHolder117 represents fn holder117 data used by v3 tests.
1201struct FnHolder117 {
1202 op fn (int, int) int
1203}
1204
1205// smartcast_name117 supports smartcast name117 handling for v3 tests.
1206fn smartcast_name117(t CastLeak117) string {
1207 if t is CastNamed117 {
1208 return t.name
1209 }
1210 return 'other'
1211}
1212
1213// smartcast_as_name117 converts smartcast as name117 data for v3 tests.
1214fn smartcast_as_name117(t CastLeak117) string {
1215 if t is CastNamed117 {
1216 named := t as CastNamed117
1217 return named.name
1218 }
1219 return 'other'
1220}
1221
1222// is_on reports whether is on applies in v3 tests.
1223fn (t Marker117) is_on() bool {
1224 return t == .on
1225}
1226
1227// qualify supports qualify handling for Registry117.
1228fn (r &Registry117) qualify(name string) string {
1229 if r.prefix.len == 0 {
1230 return name
1231 }
1232 return '${r.prefix}.${name}'
1233}
1234
1235// meta_name117 supports meta name117 handling for v3 tests.
1236fn meta_name117(t MetaType117) string {
1237 if t is MetaNamed117 {
1238 return t.name
1239 }
1240 if t is MetaArray117 {
1241 return '[]' + meta_name117(t.elem)
1242 }
1243 if t is MetaMap117 {
1244 return 'map[' + meta_name117(t.key) + ']' + meta_name117(t.val)
1245 }
1246 if t is MetaPointer117 {
1247 return '&' + meta_name117(t.base)
1248 }
1249 return 'unknown'
1250}
1251
1252// meta_array_elem117 supports meta array elem117 handling for v3 tests.
1253fn meta_array_elem117(t MetaType117) MetaType117 {
1254 if t is MetaArray117 {
1255 return t.elem
1256 }
1257 return MetaType117(MetaNamed117{
1258 name: 'none'
1259 })
1260}
1261
1262// meta_fn_signature117 supports meta fn signature117 handling for v3 tests.
1263fn meta_fn_signature117(t MetaType117) string {
1264 if t is MetaFn117 {
1265 mut parts := []string{}
1266 for param117 in t.params {
1267 parts << meta_name117(param117)
1268 }
1269 return 'fn(${parts.join(', ')}) ${meta_name117(t.ret)}'
1270 }
1271 return 'not-fn'
1272}
1273
1274// meta_iface_name117 supports meta iface name117 handling for v3 tests.
1275fn meta_iface_name117(t MetaType117) string {
1276 if t is MetaIface117 {
1277 return t.name
1278 }
1279 return 'not-interface'
1280}
1281
1282// meta_iface_passthrough117 supports meta iface passthrough117 handling for v3 tests.
1283fn meta_iface_passthrough117(v MetaIface117) string {
1284 return v.name
1285}
1286
1287// meta_iface_call117 supports meta iface call117 handling for v3 tests.
1288fn meta_iface_call117(t MetaType117) string {
1289 if t is MetaIface117 {
1290 return meta_iface_passthrough117(t)
1291 }
1292 return 'not-interface'
1293}
1294
1295// pointer_array_elem117 supports pointer array elem117 handling for v3 tests.
1296fn pointer_array_elem117(t MetaType117) string {
1297 mut arr := MetaArray117{
1298 elem: MetaType117(MetaNamed117{
1299 name: 'none'
1300 })
1301 }
1302 if t is MetaPointer117 {
1303 ptr := t
1304 base := ptr.base
1305 if base is MetaArray117 {
1306 arr = base
1307 }
1308 }
1309 return meta_name117(arr.elem)
1310}
1311
1312// short_variant117 supports short variant117 handling for v3 tests.
1313fn short_variant117(name string) string {
1314 mut short := name
1315 if name.contains('.') {
1316 short = name.all_after_last('.')
1317 }
1318 return short
1319}
1320
1321// optional_match_arith117 supports optional match arith117 handling for v3 tests.
1322fn optional_match_arith117(op string, left int, right int) ?int {
1323 match op {
1324 'div' {
1325 if right == 0 {
1326 return none
1327 }
1328 return left / right
1329 }
1330 'mod' {
1331 if right == 0 {
1332 return none
1333 }
1334 return left % right
1335 }
1336 else {
1337 return none
1338 }
1339 }
1340}
1341
1342// maybe_strings117 supports maybe strings117 handling for v3 tests.
1343fn maybe_strings117(ok bool) ?[]string {
1344 if ok {
1345 mut values := []string{}
1346 values << 'ssa'
1347 values << 'arm64'
1348 return values
1349 }
1350 return none
1351}
1352
1353// trim_last117 transforms trim last117 data for v3 tests.
1354fn trim_last117(mut values []int) {
1355 values.delete_last()
1356}
1357
1358// trim_stack117 transforms trim stack117 data for v3 tests.
1359fn trim_stack117(mut stack Stack117) {
1360 stack.values.delete_last()
1361}
1362
1363// scalar_alias_if117 converts scalar alias if117 data for v3 tests.
1364fn scalar_alias_if117(ok bool) ScalarAlias117 {
1365 return if ok { ScalarAlias117(11) } else { ScalarAlias117(12) }
1366}
1367
1368// fixed_holder_sum117 supports fixed holder sum117 handling for v3 tests.
1369fn fixed_holder_sum117(holder FixedHolder117) int {
1370 return holder.values[0] + holder.values[1] + holder.values[2]
1371}
1372
1373// add117 supports add117 handling for v3 tests.
1374fn add117(a int, b int) int {
1375 return a + b
1376}
1377
1378// fn_holder_call117 supports fn holder call117 handling for v3 tests.
1379fn fn_holder_call117(holder FnHolder117) int {
1380 return holder.op(4, 5)
1381}
1382
1383// operand_total117 supports operand total117 handling for Instr117.
1384fn (i &Instr117) operand_total117(extra int) int {
1385 return i.op + i.operands[0] + extra
1386}
1387
1388// indexed_struct_field117 supports indexed struct field117 handling for v3 tests.
1389fn indexed_struct_field117(store TypeStore117, idx int) int {
1390 bag := store.types[idx]
1391 if bag.values.len > 0 {
1392 return bag.values[0]
1393 }
1394 return -1
1395}
1396
1397// const_holder_value117 supports const holder value117 handling for v3 tests.
1398fn const_holder_value117() int {
1399 holder := unsafe { &zero_const_holder117 }
1400 return holder.value
1401}
1402
1403// adjust_symbol_values117 supports adjust symbol values117 handling for v3 tests.
1404fn adjust_symbol_values117(mut store SymbolStore117, base int) int {
1405 for i in 0 .. store.symbols.len {
1406 if store.symbols[i].sect == 2 {
1407 store.symbols[i].value += base
1408 }
1409 }
1410 return store.symbols[0].value + store.symbols[1].value
1411}
1412
1413// sum_string_for_in117 supports sum string for in117 handling for v3 tests.
1414fn sum_string_for_in117(values []string) int {
1415 mut total := 0
1416 for value117 in values {
1417 total += value117.len
1418 }
1419 return total
1420}
1421
1422// find_field_type117 resolves find field type117 information for v3 tests.
1423fn find_field_type117(fields []ForField117, wanted string) string {
1424 for field117 in fields {
1425 if field117.name == wanted {
1426 return meta_name117(field117.typ)
1427 }
1428 }
1429 return 'missing'
1430}
1431
1432// map_clone_pair117 supports map clone pair117 handling for v3 tests.
1433fn map_clone_pair117() int {
1434 original117 := make_scores115()
1435 mut cloned117 := make_scores115()
1436 cloned117 = original117.clone()
1437 cloned117['alpha'] = 7
1438 orig117 := original117['alpha'] or { -1 }
1439 copy117 := cloned117['alpha'] or { -1 }
1440 return orig117 * 10 + copy117
1441}
1442
1443// optional_context117 supports optional context117 handling for v3 tests.
1444fn optional_context117(holder OptionalContextHolder117, wanted string) ?OptionalContext117 {
1445 mut i := holder.items.len - 1
1446 for i >= 0 {
1447 if holder.items[i].expr == wanted {
1448 return holder.items[i]
1449 }
1450 i--
1451 }
1452 return none
1453}
1454
1455// optional_context_score117 supports optional context score117 handling for v3 tests.
1456fn optional_context_score117() int {
1457 holder117 := OptionalContextHolder117{
1458 items: [
1459 OptionalContext117{
1460 expr: 'node'
1461 variant: 'Ident'
1462 sum: 'Expr'
1463 },
1464 OptionalContext117{
1465 expr: 'other'
1466 variant: 'Other'
1467 sum: 'Expr'
1468 },
1469 ]
1470 }
1471 ctx117 := optional_context117(holder117, 'node') or { return 0 }
1472 if ctx117.expr == 'node' && ctx117.variant == 'Ident' && ctx117.sum == 'Expr'
1473 && !ctx117.variant.contains('.') {
1474 return 1
1475 }
1476 return 0
1477}
1478
1479// signed_narrow_load_score117 supports signed narrow load score117 handling for v3 tests.
1480fn signed_narrow_load_score117() int {
1481 mut values117 := []i8{}
1482 values117 << i8(-1)
1483 values117 << i8(7)
1484 if values117[0] < 0 && values117[1] > 0 {
1485 return 15
1486 }
1487 return 0
1488}
1489
1490// push_mut_stack_selector117 updates push mut stack selector117 state for v3 tests.
1491fn push_mut_stack_selector117(mut stack Stack117, value int) {
1492 stack.values << value
1493}
1494
1495// mut_selector_base_score117 supports mut selector base score117 handling for v3 tests.
1496fn mut_selector_base_score117() int {
1497 mut stack117 := Stack117{
1498 values: [3]
1499 }
1500 push_mut_stack_selector117(mut stack117, 8)
1501 return stack117.values[0] * 10 + stack117.values[1]
1502}
1503
1504// chained_if_expr_score117 supports chained if expr score117 handling for v3 tests.
1505fn chained_if_expr_score117(value int) int {
1506 typ117 := if value == 0 {
1507 MetaType117(MetaNamed117{
1508 name: 'zero'
1509 })
1510 } else if value == 7 {
1511 MetaType117(MetaArray117{
1512 elem: MetaType117(MetaNamed117{
1513 name: 'int'
1514 })
1515 })
1516 } else {
1517 MetaType117(MetaPointer117{
1518 base: MetaType117(MetaNamed117{
1519 name: 'fallback'
1520 })
1521 })
1522 }
1523 if meta_name117(typ117) == '[]int' {
1524 return 80
1525 }
1526 return 0
1527}
1528
1529// name returns name data for SumNameLeft117.
1530fn (t SumNameLeft117) name() string {
1531 if t is SumNameLeftNamed117 {
1532 return t.value
1533 }
1534 return 'left-other'
1535}
1536
1537// name returns name data for SumNameRight117.
1538fn (t SumNameRight117) name() string {
1539 if t is SumNameRightNamed117 {
1540 return t.value
1541 }
1542 return 'right-other'
1543}
1544
1545// sum_type_method_same_name_score117
1546// supports helper handling in v3 tests.
1547fn sum_type_method_same_name_score117() int {
1548 left117 := SumNameLeft117(SumNameLeftNamed117{
1549 value: 'left'
1550 })
1551 right117 := SumNameRight117(SumNameRightNamed117{
1552 value: 'right'
1553 })
1554 if left117.name() == 'left' && right117.name() == 'right' {
1555 return 33
1556 }
1557 return 0
1558}
1559
1560// array_pop_score117 supports array pop score117 handling for v3 tests.
1561fn array_pop_score117() int {
1562 mut values117 := [4, 6, 9]
1563 last117 := values117.pop()
1564 return last117 * 10 + values117.len
1565}
1566
1567// array_repeat_score117 supports array repeat score117 handling for v3 tests.
1568fn array_repeat_score117() int {
1569 base117 := []int{len: 2, init: 5}
1570 values117 := base117.repeat(3)
1571 if values117.len == 6 {
1572 return 6
1573 }
1574 return 0
1575}
1576
1577// discard_assignment_side_effect_score117
1578// supports helper handling in v3 tests.
1579fn discard_assignment_side_effect_score117() int {
1580 g_count = 0
1581 _ = next_in_value()
1582 return g_count
1583}
1584
1585// recursive_sum_method_score117 supports recursive sum method score117 handling for MetaType117.
1586fn (t MetaType117) recursive_sum_method_score117() int {
1587 if t is MetaPointer117 {
1588 if meta_name117(t.base) == 'core' {
1589 return 41
1590 }
1591 }
1592 return 0
1593}
1594
1595// large_sumtype_method_receiver_score117 supports large_sumtype_method_receiver_score117 handling.
1596fn large_sumtype_method_receiver_score117() int {
1597 typ117 := MetaType117(MetaPointer117{
1598 base: MetaType117(MetaNamed117{
1599 name: 'core'
1600 })
1601 })
1602 return typ117.recursive_sum_method_score117()
1603}
1604
1605// qualified_import_same_short_score117 supports qualified_import_same_short_score117 handling.
1606fn qualified_import_same_short_score117() int {
1607 mut score117 := repeat(`x`, 3)
1608 repeated117 := strings.repeat(`x`, 3)
1609 if repeated117.len == 3 && repeated117 == 'xxx' {
1610 score117 += 10
1611 }
1612 return score117
1613}
1614
1615// sum_nine116 supports sum nine116 handling for v3 tests.
1616fn sum_nine116(a int, b int, c int, d int, e int, f int, g int, h int, i int) int {
1617 return a + b + c + d + e + f + g + h + i
1618}
1619
1620// use_int116 supports use int116 handling for v3 tests.
1621fn use_int116(x int) int {
1622 return x
1623}
1624
1625// BuildArch118 lists build arch118 values used by v3 tests.
1626enum BuildArch118 {
1627 amd64
1628 arm64
1629}
1630
1631// callback_value118 supports callback value118 handling for v3 tests.
1632fn callback_value118(cb fn () int) int {
1633 return cb()
1634}
1635
1636// maybe_label118 supports maybe label118 handling for v3 tests.
1637fn maybe_label118(ok bool) !string {
1638 if ok {
1639 return 'ok'
1640 }
1641 return error('bad')
1642}
1643
1644// pass_error118 supports pass error118 handling for v3 tests.
1645fn pass_error118() !string {
1646 value := maybe_label118(false) or { return err }
1647 return value
1648}
1649
1650// array_callback_enum_score118 supports array callback enum score118 handling for v3 tests.
1651fn array_callback_enum_score118() int {
1652 mut args118 := []string{}
1653 args118 << 'beta'
1654 args118 << '-v2'
1655 args118 << 'alpha'
1656 filtered118 := args118.filter(it != '-v2')
1657 mut sorted118 := filtered118.clone()
1658 sorted118.sort()
1659 mut score118 := sorted118.len * 10
1660 if sorted118[0] == 'alpha' && sorted118[1] == 'beta' {
1661 score118 += 3
1662 }
1663 if BuildArch118.arm64.str() == 'arm64' {
1664 score118 += 5
1665 }
1666 score118 += callback_value118(fn () int {
1667 return 7
1668 })
1669 _ := pass_error118() or { 'fallback' }
1670 return score118
1671}
1672
1673// NestedIdent119 represents nested ident119 data used by v3 tests.
1674struct NestedIdent119 {
1675 name string
1676}
1677
1678// NestedInfixExpr119 represents nested infix expr119 data used by v3 tests.
1679struct NestedInfixExpr119 {
1680 op string
1681}
1682
1683// NestedMatchBranch119 represents nested match branch119 data used by v3 tests.
1684struct NestedMatchBranch119 {}
1685
1686// NestedIfBranch119 represents nested if branch119 data used by v3 tests.
1687struct NestedIfBranch119 {}
1688
1689// NestedExpr119 aliases nested expr119 values used by v3 tests.
1690type NestedExpr119 = NestedIdent119 | NestedInfixExpr119
1691
1692// NestedNode119 aliases nested node119 values used by v3 tests.
1693type NestedNode119 = NestedExpr119 | NestedMatchBranch119 | NestedIfBranch119
1694
1695// LoopHolder119 represents loop holder119 data used by v3 tests.
1696struct LoopHolder119 {
1697mut:
1698 current &NestedNode119 = unsafe { nil }
1699}
1700
1701// SumPointerNilHolder119 represents sum pointer nil holder119 data used by v3 tests.
1702struct SumPointerNilHolder119 {
1703 node &NestedNode119 = unsafe { nil }
1704}
1705
1706// SortItem119 represents sort item119 data used by v3 tests.
1707struct SortItem119 {
1708 rank int
1709 id int
1710}
1711
1712// OpVersion119 represents op version119 data used by v3 tests.
1713struct OpVersion119 {
1714 major int
1715}
1716
1717// InterfaceField119 defines the interface field119 contract used by v3 tests.
1718interface InterfaceField119 {
1719 value int
1720}
1721
1722// InterfaceFieldImpl119 represents interface field impl119 data used by v3 tests.
1723struct InterfaceFieldImpl119 {
1724 value int
1725}
1726
1727// NilLink119 represents nil link119 data used by v3 tests.
1728struct NilLink119 {
1729mut:
1730 next &NilLink119 = unsafe { nil }
1731}
1732
1733// IErrorDefault119 represents ierror default119 data used by v3 tests.
1734struct IErrorDefault119 {
1735 err IError = none
1736}
1737
1738// OptionalInterp119 represents optional interp119 data used by v3 tests.
1739struct OptionalInterp119 {
1740 stop ?string
1741}
1742
1743// MapMethodValue119 represents map method value119 data used by v3 tests.
1744struct MapMethodValue119 {
1745 kind int
1746}
1747
1748// StaticNewLocal119 represents static new local119 data used by v3 tests.
1749struct StaticNewLocal119 {
1750 value int
1751}
1752
1753// ZeroMapHolder119 represents zero map holder119 data used by v3 tests.
1754struct ZeroMapHolder119 {
1755mut:
1756 data map[string]int
1757}
1758
1759// FeatureFlags119 lists feature flags119 values used by v3 tests.
1760@[flag]
1761enum FeatureFlags119 {
1762 name
1763 version
1764}
1765
1766// RecursiveIf119 represents recursive if119 data used by v3 tests.
1767struct RecursiveIf119 {
1768 next &RecursiveExpr119 = unsafe { nil }
1769}
1770
1771// RecursiveHash119 represents recursive hash119 data used by v3 tests.
1772struct RecursiveHash119 {
1773 id int
1774}
1775
1776// HeapLocal119 represents heap local119 data used by v3 tests.
1777struct HeapLocal119 {
1778 value int
1779}
1780
1781// SsaSumPayload119 represents ssa sum payload119 data used by v3 tests.
1782struct SsaSumPayload119 {
1783 code int
1784}
1785
1786// FnFieldCall119 represents fn field call119 data used by v3 tests.
1787struct FnFieldCall119 {
1788 op fn (int, int) int
1789}
1790
1791// RecursiveExpr119 aliases recursive expr119 values used by v3 tests.
1792type RecursiveExpr119 = RecursiveIf119 | RecursiveHash119
1793
1794// RecursiveHashNode119 aliases recursive hash node119 values used by v3 tests.
1795type RecursiveHashNode119 = RecursiveIf119 | RecursiveHash119
1796
1797// SsaSum119 aliases ssa sum119 values used by v3 tests.
1798type SsaSum119 = RecursiveHash119 | SsaSumPayload119
1799
1800// C.atomic_fetch_add_u32 declares the C atomic_fetch_add_u32 symbol used by v3 tests.
1801fn C.atomic_fetch_add_u32(voidptr, u32) u32
1802
1803// C.atomic_load_u16 declares the C atomic_load_u16 symbol used by v3 tests.
1804fn C.atomic_load_u16(voidptr) u16
1805
1806// C.atomic_store_u16 declares the C atomic_store_u16 symbol used by v3 tests.
1807fn C.atomic_store_u16(voidptr, u16)
1808
1809// C.atomic_compare_exchange_strong_u16 declares a C symbol used by v3 tests.
1810fn C.atomic_compare_exchange_strong_u16(voidptr, voidptr, u16) bool
1811
1812// C.atomic_compare_exchange_weak_u32 declares a C symbol used by v3 tests.
1813fn C.atomic_compare_exchange_weak_u32(voidptr, voidptr, u32) bool
1814
1815// C.atomic_compare_exchange_weak_byte declares a C symbol used by v3 tests.
1816fn C.atomic_compare_exchange_weak_byte(voidptr, voidptr, u8) bool
1817
1818// C.atomic_compare_exchange_weak_u64 declares a C symbol used by v3 tests.
1819fn C.atomic_compare_exchange_weak_u64(voidptr, voidptr, u64) bool
1820
1821// C.atomic_load_ptr declares the C atomic_load_ptr symbol used by v3 tests.
1822fn C.atomic_load_ptr(voidptr) voidptr
1823
1824// C.atomic_store_ptr declares the C atomic_store_ptr symbol used by v3 tests.
1825fn C.atomic_store_ptr(voidptr, voidptr)
1826
1827// C._wymix declares the C _wymix symbol used by v3 tests.
1828fn C._wymix(u64, u64) u64
1829
1830// C.v_filelock_lock declares the C v_filelock_lock symbol used by v3 tests.
1831fn C.v_filelock_lock(i32, i32, i32, u64, u64) i32
1832
1833// C.v_filelock_unlock declares the C v_filelock_unlock symbol used by v3 tests.
1834fn C.v_filelock_unlock(i32, u64, u64) i32
1835
1836// C.v_prealloc_atomic_add_i32 declares the C v_prealloc_atomic_add_i32 symbol used by v3 tests.
1837fn C.v_prealloc_atomic_add_i32(voidptr, int) int
1838
1839// C.v_prealloc_atomic_load_i32 declares the C v_prealloc_atomic_load_i32 symbol used by v3 tests.
1840fn C.v_prealloc_atomic_load_i32(voidptr) int
1841
1842// C.v_prealloc_atomic_store_i32 declares the C v_prealloc_atomic_store_i32 symbol used by v3 tests.
1843fn C.v_prealloc_atomic_store_i32(voidptr, int) int
1844
1845// C.v_prealloc_atomic_cas_i32 declares the C v_prealloc_atomic_cas_i32 symbol used by v3 tests.
1846fn C.v_prealloc_atomic_cas_i32(voidptr, int, int) int
1847
1848// C.v_signal_with_handler_cast declares the C v_signal_with_handler_cast symbol used by v3 tests.
1849fn C.v_signal_with_handler_cast(i32, voidptr) voidptr
1850
1851// maybe_const119 supports maybe const119 handling for v3 tests.
1852fn maybe_const119(ok bool) ?string {
1853 if ok {
1854 return 'set'
1855 }
1856 return none
1857}
1858
1859const const_or119 = maybe_const119(false) or { 'fallback' }
1860
1861// return_if_branch119 supports return if branch119 handling for v3 tests.
1862fn return_if_branch119(flag bool) int {
1863 return if flag { return 12 } else { 7 }
1864}
1865
1866// match_smartcast_return119 supports match smartcast return119 handling for v3 tests.
1867fn match_smartcast_return119(expr NestedExpr119) string {
1868 ident119 := match expr {
1869 NestedIdent119 {
1870 expr as NestedIdent119
1871 }
1872 else {
1873 return 'not-ident'
1874 }
1875 }
1876
1877 return ident119.name
1878}
1879
1880// indexed_smartcast119 supports indexed smartcast119 handling for v3 tests.
1881fn indexed_smartcast119(items []NestedExpr119) string {
1882 first119 := items[0]
1883 if first119 is NestedIdent119 && first119.name == 'idx' {
1884 return first119.name
1885 }
1886 return 'none'
1887}
1888
1889// nested_type_membership119 supports nested type membership119 handling for v3 tests.
1890fn nested_type_membership119(node NestedNode119) int {
1891 if node !in [NestedMatchBranch119, NestedIfBranch119, NestedInfixExpr119] {
1892 return 1
1893 }
1894 return 0
1895}
1896
1897// sum_pointer_target119 supports sum pointer target119 handling for v3 tests.
1898fn sum_pointer_target119(node NestedNode119) int {
1899 mut holder119 := LoopHolder119{}
1900 match node {
1901 NestedIfBranch119 {
1902 holder119.current = unsafe { &node }
1903 }
1904 else {}
1905 }
1906
1907 if isnil(holder119.current) {
1908 return 0
1909 }
1910 return 6
1911}
1912
1913// compare_sort_item119 supports compare sort item119 handling for v3 tests.
1914fn compare_sort_item119(a &SortItem119, b &SortItem119) int {
1915 if a.rank < b.rank {
1916 return -1
1917 }
1918 if a.rank > b.rank {
1919 return 1
1920 }
1921 return 0
1922}
1923
1924// sort_with_compare119 updates sort with compare119 state for v3 tests.
1925fn sort_with_compare119() int {
1926 mut items119 := [
1927 SortItem119{
1928 rank: 3
1929 id: 1
1930 },
1931 SortItem119{
1932 rank: 1
1933 id: 2
1934 },
1935 SortItem119{
1936 rank: 2
1937 id: 3
1938 },
1939 ]
1940 items119.sort_with_compare(fn (a &SortItem119, b &SortItem119) int {
1941 if a.rank < b.rank {
1942 return -1
1943 }
1944 if a.rank > b.rank {
1945 return 1
1946 }
1947 return 0
1948 })
1949 sorted119 := items119.sorted_with_compare(compare_sort_item119)
1950 return items119[0].rank * 100 + items119[1].rank * 10 + items119[2].rank + sorted119[0].id
1951}
1952
1953// operator == implements the == operator for OpVersion119.
1954fn (a OpVersion119) == (b OpVersion119) bool {
1955 return a.major == b.major
1956}
1957
1958// operator < implements the < operator for OpVersion119.
1959fn (a OpVersion119) < (b OpVersion119) bool {
1960 return a.major < b.major
1961}
1962
1963// operator_compare119 supports operator compare119 handling for v3 tests.
1964fn operator_compare119() int {
1965 low119 := OpVersion119{
1966 major: 1
1967 }
1968 high119 := OpVersion119{
1969 major: 2
1970 }
1971 same119 := OpVersion119{
1972 major: 2
1973 }
1974 mut score119 := 0
1975 if high119 > low119 {
1976 score119 += 2
1977 }
1978 if high119 >= low119 {
1979 score119 += 3
1980 }
1981 if low119 <= high119 {
1982 score119 += 4
1983 }
1984 if high119 != low119 {
1985 score119 += 5
1986 }
1987 if high119 >= same119 {
1988 score119 += 6
1989 }
1990 if high119 <= same119 {
1991 score119 += 7
1992 }
1993 return score119
1994}
1995
1996// read_interface_field119 reads read interface field119 input for v3 tests.
1997fn read_interface_field119(item InterfaceField119) int {
1998 return item.value
1999}
2000
2001// read_interface_field_ptr119 reads read interface field ptr119 input for v3 tests.
2002fn read_interface_field_ptr119(item &InterfaceField119) int {
2003 return item.value
2004}
2005
2006// interface_field119 supports interface field119 handling for v3 tests.
2007fn interface_field119() int {
2008 item119 := InterfaceFieldImpl119{
2009 value: 19
2010 }
2011 return read_interface_field119(item119) + read_interface_field_ptr119(&item119)
2012}
2013
2014// math_generic119 supports math generic119 handling for v3 tests.
2015fn math_generic119() int {
2016 return math.abs(0 - 6) + math.min(8, 5)
2017}
2018
2019// module_const_method119 supports module const method119 handling for v3 tests.
2020fn module_const_method119() int {
2021 return token.scanner_matcher.find('fn')
2022}
2023
2024// qualified_static_new119 supports qualified static new119 handling for v3 tests.
2025fn qualified_static_new119() int {
2026 mut matcher119 := token.KeywordsMatcherTrie.new(2)
2027 matcher119.add_word('module', 71)
2028 return matcher119.find('module')
2029}
2030
2031// new creates a StaticNewLocal119 value for v3 tests.
2032fn StaticNewLocal119.new(value int) StaticNewLocal119 {
2033 return StaticNewLocal119{
2034 value: value + 2
2035 }
2036}
2037
2038// local_static_new119 supports local static new119 handling for v3 tests.
2039fn local_static_new119() int {
2040 item119 := StaticNewLocal119.new(73)
2041 return item119.value
2042}
2043
2044// module_function_new119 supports module function new119 handling for v3 tests.
2045fn module_function_new119() int {
2046 mut bench119 := bench.new()
2047 _ = bench119
2048 return 101
2049}
2050
2051// nil_newline_pointer_assignment119
2052// supports helper handling in v3 tests.
2053fn nil_newline_pointer_assignment119() int {
2054 mut item119 := NilLink119{}
2055 mut link119 := &item119.next
2056 unsafe {
2057 item119.next = nil
2058 *link119 = &item119
2059 }
2060 if isnil(item119.next) {
2061 return 0
2062 }
2063 return 21
2064}
2065
2066// ierror_none_field119 supports ierror none field119 handling for v3 tests.
2067fn ierror_none_field119() int {
2068 default119 := IErrorDefault119{}
2069 explicit119 := IErrorDefault119{
2070 err: none
2071 }
2072 _ = default119
2073 _ = explicit119
2074 return 29
2075}
2076
2077// sum_pointer_nil_default119 supports sum pointer nil default119 handling for v3 tests.
2078fn sum_pointer_nil_default119() int {
2079 holder119 := SumPointerNilHolder119{}
2080 if isnil(holder119.node) {
2081 return 31
2082 }
2083 return 0
2084}
2085
2086// optional_string_interp119 supports optional string interp119 handling for v3 tests.
2087fn optional_string_interp119() string {
2088 default119 := OptionalInterp119{}
2089 set119 := OptionalInterp119{
2090 stop: 'halt'
2091 }
2092 return '${default119.stop}|${set119.stop}'
2093}
2094
2095// optional_cast_field119 supports optional cast field119 handling for v3 tests.
2096fn optional_cast_field119(arg string) string {
2097 data119 := OptionalInterp119{
2098 stop: ?string(arg)
2099 }
2100 return '${data119.stop}'
2101}
2102
2103// optional_passthrough_field119 supports optional passthrough field119 handling for v3 tests.
2104fn optional_passthrough_field119(default_value ?string) string {
2105 data119 := OptionalInterp119{
2106 stop: default_value
2107 }
2108 return '${data119.stop}'
2109}
2110
2111// escape_default_string supports escape default string handling for v3 tests.
2112fn escape_default_string(value string) string {
2113 return value
2114}
2115
2116// flag_default_value supports flag default value handling for v3 tests.
2117fn flag_default_value(value string) string {
2118 return 'not-lowered:${value}'
2119}
2120
2121// flag_default_value_lowering119 supports flag default value lowering119 handling for v3 tests.
2122fn flag_default_value_lowering119() string {
2123 return flag_default_value('abc')
2124}
2125
2126// query_kind119 supports query kind119 handling for map[string]MapMethodValue119.
2127fn (m map[string]MapMethodValue119) query_kind119(name string) ?MapMethodValue119 {
2128 if name in m {
2129 return m[name]
2130 }
2131 return none
2132}
2133
2134// map_receiver_method119 supports map receiver method119 handling for v3 tests.
2135fn map_receiver_method119() int {
2136 mut kinds119 := map[string]MapMethodValue119{}
2137 kinds119['name'] = MapMethodValue119{
2138 kind: 41
2139 }
2140 got119 := kinds119.query_kind119('name') or { return 0 }
2141 return got119.kind
2142}
2143
2144// map_index_or_none119 supports map index or none119 handling for v3 tests.
2145fn map_index_or_none119(items map[string]MapMethodValue119, name string) ?MapMethodValue119 {
2146 return items[name] or { none }
2147}
2148
2149// map_index_bang119 supports map index bang119 handling for v3 tests.
2150fn map_index_bang119(items map[string]MapMethodValue119, name string) !MapMethodValue119 {
2151 return items[name]!
2152}
2153
2154// map_index_optional_return119 supports map index optional return119 handling for v3 tests.
2155fn map_index_optional_return119() int {
2156 mut kinds119 := map[string]MapMethodValue119{}
2157 kinds119['name'] = MapMethodValue119{
2158 kind: 41
2159 }
2160 got119 := map_index_or_none119(kinds119, 'name') or { return 0 }
2161 missing119 := map_index_or_none119(kinds119, 'missing') or {
2162 MapMethodValue119{
2163 kind: 7
2164 }
2165 }
2166 got_bang119 := map_index_bang119(kinds119, 'name') or { return 0 }
2167 missing_bang119 := map_index_bang119(kinds119, 'missing') or {
2168 MapMethodValue119{
2169 kind: 5
2170 }
2171 }
2172 return got119.kind + missing119.kind + got_bang119.kind + missing_bang119.kind
2173}
2174
2175// ReceiverMethodLive119 represents receiver method live119 data used by v3 tests.
2176struct ReceiverMethodLive119 {
2177 base int
2178}
2179
2180// hidden119 supports hidden119 handling for ReceiverMethodLive119.
2181fn (r ReceiverMethodLive119) hidden119(extra int) int {
2182 return r.base + extra
2183}
2184
2185// visible119 supports visible119 handling for ReceiverMethodLive119.
2186fn (r ReceiverMethodLive119) visible119(flag bool) int {
2187 if flag {
2188 return r.hidden119(64)
2189 }
2190 return r.hidden119(1)
2191}
2192
2193// receiver_method_liveness119 supports receiver method liveness119 handling for v3 tests.
2194fn receiver_method_liveness119() int {
2195 r := ReceiverMethodLive119{
2196 base: 53
2197 }
2198 return r.visible119(true)
2199}
2200
2201// zero_map_lookup119 supports zero map lookup119 handling for v3 tests.
2202fn zero_map_lookup119() int {
2203 holder119 := ZeroMapHolder119{}
2204 if 'missing' !in holder119.data {
2205 return 79
2206 }
2207 return 0
2208}
2209
2210// flag_enum_zero119 supports flag enum zero119 handling for v3 tests.
2211fn flag_enum_zero119() int {
2212 show119 := ~FeatureFlags119.zero() ^ .name
2213 if show119.has(.version) && !show119.has(.name) {
2214 return 43
2215 }
2216 return 0
2217}
2218
2219// sum_alias_pointer_cast119 converts sum alias pointer cast119 data for v3 tests.
2220fn sum_alias_pointer_cast119(expr RecursiveExpr119) int {
2221 alias119 := &RecursiveHashNode119(expr as RecursiveIf119)
2222 if isnil(alias119) {
2223 return 0
2224 }
2225 return 9
2226}
2227
2228// at_location119 supports at location119 handling for v3 tests.
2229fn at_location119() int {
2230 location119 := @LOCATION
2231 if location119.len > 0 {
2232 return 4
2233 }
2234 return 0
2235}
2236
2237// c_atomic_wymix119 supports c atomic wymix119 handling for v3 tests.
2238fn c_atomic_wymix119() int {
2239 mut counter119 := u32(4)
2240 old119 := C.atomic_fetch_add_u32(voidptr(&counter119), u32(3))
2241 mix119 := C._wymix(u64(11), u64(17))
2242 mut score119 := int(old119) + int(counter119)
2243 if mix119 != 0 {
2244 score119 += 2
2245 }
2246 return score119
2247}
2248
2249// c_atomic_channel_helpers119 supports c atomic channel helpers119 handling for v3 tests.
2250fn c_atomic_channel_helpers119() int {
2251 mut score119 := 0
2252 mut flag119 := u16(0)
2253 mut expected16_119 := u16(0)
2254 if C.atomic_compare_exchange_strong_u16(voidptr(&flag119), voidptr(&expected16_119), u16(3)) {
2255 score119 += int(C.atomic_load_u16(voidptr(&flag119)))
2256 }
2257 C.atomic_store_u16(voidptr(&flag119), u16(4))
2258 score119 += int(C.atomic_load_u16(voidptr(&flag119)))
2259 mut counter119 := u32(2)
2260 mut expected32_119 := u32(2)
2261 if C.atomic_compare_exchange_weak_u32(voidptr(&counter119), voidptr(&expected32_119), u32(5)) {
2262 score119 += int(counter119)
2263 }
2264 mut locked119 := u8(0)
2265 mut expected_byte119 := u8(0)
2266 if C.atomic_compare_exchange_weak_byte(voidptr(&locked119), voidptr(&expected_byte119), u8(8)) {
2267 score119 += int(locked119)
2268 }
2269 mut big119 := u64(10)
2270 mut expected64_119 := u64(10)
2271 if C.atomic_compare_exchange_weak_u64(voidptr(&big119), voidptr(&expected64_119), u64(12)) {
2272 score119 += int(big119)
2273 }
2274 value119 := 9
2275 mut slot119 := unsafe { nil }
2276 C.atomic_store_ptr(voidptr(&slot119), voidptr(&value119))
2277 if C.atomic_load_ptr(voidptr(&slot119)) == voidptr(&value119) {
2278 score119 += 6
2279 }
2280 return score119
2281}
2282
2283// c_filelock_helpers119 supports c filelock helpers119 handling for v3 tests.
2284fn c_filelock_helpers119() int {
2285 lock_result119 := C.v_filelock_lock(i32(-1), 1, 1, u64(0), u64(0))
2286 unlock_result119 := C.v_filelock_unlock(i32(-1), u64(0), u64(0))
2287 if lock_result119 != 0 && unlock_result119 != 0 {
2288 return 47
2289 }
2290 return 0
2291}
2292
2293// local_address_return119 supports local address return119 handling for v3 tests.
2294fn local_address_return119() &HeapLocal119 {
2295 item119 := HeapLocal119{
2296 value: 53
2297 }
2298 return &item119
2299}
2300
2301// heap_local_return119 supports heap local return119 handling for v3 tests.
2302fn heap_local_return119() int {
2303 item119 := local_address_return119()
2304 return item119.value
2305}
2306
2307// rune_array_string119 supports rune array string119 handling for v3 tests.
2308fn rune_array_string119() int {
2309 runes119 := [rune(`v`), rune(`3`)]
2310 if runes119.string() == 'v3' {
2311 return 61
2312 }
2313 return 0
2314}
2315
2316// prealloc_atomic_helpers119 supports prealloc atomic helpers119 handling for v3 tests.
2317fn prealloc_atomic_helpers119() int {
2318 mut value119 := 1
2319 C.v_prealloc_atomic_store_i32(voidptr(&value119), 2)
2320 mut score119 := value119
2321 score119 += C.v_prealloc_atomic_load_i32(voidptr(&value119))
2322 score119 += C.v_prealloc_atomic_add_i32(voidptr(&value119), 3)
2323 if C.v_prealloc_atomic_cas_i32(voidptr(&value119), 5, 7) != 0 {
2324 score119 += value119
2325 }
2326 return score119
2327}
2328
2329// signal_handler_cast119 supports signal handler cast119 handling for v3 tests.
2330fn signal_handler_cast119() int {
2331 prev119 := C.v_signal_with_handler_cast(0, unsafe { nil })
2332 if isnil(prev119) {
2333 return 67
2334 }
2335 return 67
2336}
2337
2338// printing_builtin_helpers119 supports printing builtin helpers119 handling for v3 tests.
2339fn printing_builtin_helpers119() int {
2340 print('')
2341 eprint('')
2342 eprintln('')
2343 return 89
2344}
2345
2346// string_last_part_helpers119 supports string last part helpers119 handling for v3 tests.
2347fn string_last_part_helpers119() int {
2348 path119 := 'vlib/v3/v3.v'
2349 if path119.all_before_last('/') == 'vlib/v3' && path119.all_after_last('/') == 'v3.v' {
2350 return 97
2351 }
2352 return 0
2353}
2354
2355// join_path_variadic119 supports join path variadic119 handling for v3 tests.
2356fn join_path_variadic119() int {
2357 sep119 := os.path_separator
2358 expected119 := 'vlib' + sep119 + 'v3' + sep119 + 'v3.v'
2359 path119 := os.join_path('vlib', 'v3', 'v3.v')
2360 if path119 == expected119 {
2361 return 107
2362 }
2363 return 0
2364}
2365
2366// ssa_sum_payload_store119 supports ssa sum payload store119 handling for v3 tests.
2367fn ssa_sum_payload_store119() int {
2368 payload119 := SsaSum119(SsaSumPayload119{
2369 code: 109
2370 })
2371 if payload119 is SsaSumPayload119 {
2372 return payload119.code
2373 }
2374 return 0
2375}
2376
2377// add_fn_field119 updates add fn field119 state for v3 tests.
2378fn add_fn_field119(a int, b int) int {
2379 return a + b
2380}
2381
2382// make_fn_field119 builds make fn field119 data for v3 tests.
2383fn make_fn_field119() FnFieldCall119 {
2384 return FnFieldCall119{
2385 op: add_fn_field119
2386 }
2387}
2388
2389// selector_fn_call_base119 supports selector fn call base119 handling for v3 tests.
2390fn selector_fn_call_base119() int {
2391 return make_fn_field119().op(50, 63)
2392}
2393
2394// channel_runtime119 supports channel runtime119 handling for v3 tests.
2395fn channel_runtime119() int {
2396 mutex119 := sync.new_mutex()
2397 _ = mutex119
2398 ch119 := chan bool{cap: 1}
2399 ch119 <- true
2400 got119 := <-ch119
2401 ch119.close()
2402 mut score119 := 0
2403 if got119 {
2404 score119 += 17
2405 }
2406 if ch119.closed {
2407 score119 += 19
2408 }
2409 waiters119 := [ch119]
2410 if waiters119[0] == ch119 {
2411 score119 += 23
2412 }
2413 return score119
2414}
2415
2416// ZeroDefaultStruct119 represents zero default struct119 data used by v3 tests.
2417struct ZeroDefaultStruct119 {
2418 name string
2419 count int
2420 enabled bool
2421}
2422
2423// zero_default_struct119 supports zero default struct119 handling for v3 tests.
2424fn zero_default_struct119() int {
2425 item119 := ZeroDefaultStruct119{}
2426 if item119.name == '' && item119.count == 0 && !item119.enabled {
2427 return 103
2428 }
2429 return 0
2430}
2431
2432// main runs the v3 tests entry point.
2433fn main() {
2434 print_str('=== v3 Test Suite ===')
2435
2436 // ==================== 1. STRUCT DECL & INIT (5 tests) ====================
2437 print_str('--- 1. Struct Declaration & Initialization ---')
2438
2439 // 1.1 Basic struct init
2440 p1 := Point{
2441 x: 10
2442 y: 20
2443 }
2444 print_int(p1.x) // 10
2445 print_int(p1.y) // 20
2446
2447 // 1.2 Default zero init
2448 p2 := Point{}
2449 print_int(p2.x) // 0
2450 print_int(p2.y) // 0
2451
2452 // 1.3 Mutable struct modification
2453 mut p3 := Point{
2454 x: 1
2455 y: 2
2456 }
2457 p3.x = 100
2458 p3.y = 200
2459 print_int(p3.x) // 100
2460 print_int(p3.y) // 200
2461
2462 // 1.4 Struct with computed values
2463 base := 7
2464 p4 := Point{
2465 x: base * 2
2466 y: base * 3
2467 }
2468 print_int(p4.x) // 14
2469 print_int(p4.y) // 21
2470
2471 // 1.5 Multiple struct instances
2472 p5a := Point{
2473 x: 1
2474 y: 2
2475 }
2476 p5b := Point{
2477 x: 3
2478 y: 4
2479 }
2480 print_int(p5a.x + p5b.x) // 4
2481 print_int(p5a.y + p5b.y) // 6
2482
2483 // ==================== 2. CALLS & SELECTOR ASSIGN (5 tests) ====================
2484 print_str('--- 2. Calls & Selector Assignment ---')
2485
2486 // 2.1 Basic function call with selector assign
2487 mut pt := Point{
2488 x: 10
2489 y: 20
2490 }
2491 pt.x = add(pt.x, 5)
2492 print_int(pt.x) // 15
2493
2494 // 2.2 Chained calls
2495 pt.y = add(add(pt.y, 10), 5)
2496 print_int(pt.y) // 35
2497
2498 // 2.3 Call result to selector with subtraction
2499 pt.x = sub(pt.x, 3)
2500 print_int(pt.x) // 12
2501
2502 // 2.4 Multiple selectors updated via calls
2503 mut pt2 := Point{
2504 x: 5
2505 y: 5
2506 }
2507 pt2.x = mul(pt2.x, 3)
2508 pt2.y = mul(pt2.y, 4)
2509 print_int(pt2.x) // 15
2510 print_int(pt2.y) // 20
2511
2512 // 2.5 Nested function calls with selectors
2513 mut pt3 := Point{
2514 x: 10
2515 y: 20
2516 }
2517 pt3.x = add(mul(pt3.x, 2), 5) // 10*2 + 5 = 25
2518 pt3.y = sub(mul(pt3.y, 3), 10) // 20*3 - 10 = 50
2519 print_int(pt3.x) // 25
2520 print_int(pt3.y) // 50
2521
2522 // ==================== 3. GLOBALS & COMPOUND ASSIGN (5 tests) ====================
2523 print_str('--- 3. Globals & Compound Assignment ---')
2524
2525 // 3.1 Basic global assignment and compound add
2526 g_val = 50
2527 g_val += 50
2528 print_int(g_val) // 100
2529
2530 // 3.2 Compound subtract
2531 g_val = 100
2532 g_val -= 30
2533 print_int(g_val) // 70
2534
2535 // 3.3 Compound multiply
2536 g_val = 5
2537 g_val *= 6
2538 print_int(g_val) // 30
2539
2540 // 3.4 Compound divide
2541 g_val = 100
2542 g_val /= 4
2543 print_int(g_val) // 25
2544
2545 // 3.5 Global struct
2546 g_point.x = 42
2547 g_point.y = 84
2548 g_point.x += 8
2549 print_int(g_point.x) // 50
2550 print_int(g_point.y) // 84
2551
2552 // ==================== 4. BOOL & LOGIC (5 tests) ====================
2553 print_str('--- 4. Bool & Logic ---')
2554
2555 // 4.1 Basic bool true
2556 flag1 := true
2557 if flag1 {
2558 print_int(1)
2559 } else {
2560 print_int(0)
2561 }
2562
2563 // 4.2 Basic bool false
2564 flag2 := false
2565 if flag2 {
2566 print_int(1)
2567 } else {
2568 print_int(0)
2569 }
2570
2571 // 4.3 Bool from comparison
2572 cmp_val := 10
2573 flag3 := cmp_val > 5
2574 if flag3 {
2575 print_int(1)
2576 } else {
2577 print_int(0)
2578 }
2579
2580 // 4.4 Logical AND
2581 a_bool := true
2582 b_bool := true
2583 if a_bool && b_bool {
2584 print_int(1)
2585 } else {
2586 print_int(0)
2587 }
2588
2589 // 4.5 Logical OR and NOT
2590 c_bool := false
2591 d_bool := true
2592 if c_bool || d_bool {
2593 print_int(1) // 1
2594 } else {
2595 print_int(0)
2596 }
2597 if !c_bool {
2598 print_int(1) // 1
2599 } else {
2600 print_int(0)
2601 }
2602
2603 // ==================== 5. LOOP WITH BREAK/CONTINUE (5 tests) ====================
2604 print_str('--- 5. Loop with Break/Continue ---')
2605
2606 // 5.1 Basic continue (skip 5)
2607 mut sum1 := 0
2608 mut i1 := 0
2609 for i1 < 10 {
2610 i1++
2611 if i1 == 5 {
2612 continue
2613 }
2614 if i1 > 7 {
2615 break
2616 }
2617 sum1 += i1
2618 }
2619 print_int(sum1) // 1+2+3+4+6+7 = 23
2620
2621 // 5.2 Multiple continues (skip even)
2622 mut sum2 := 0
2623 mut i2 := 0
2624 for i2 < 10 {
2625 i2++
2626 if i2 % 2 == 0 {
2627 continue
2628 }
2629 sum2 += i2
2630 }
2631 print_int(sum2) // 1+3+5+7+9 = 25
2632
2633 // 5.3 Early break
2634 mut sum3 := 0
2635 mut i3 := 0
2636 for i3 < 100 {
2637 i3++
2638 if i3 > 5 {
2639 break
2640 }
2641 sum3 += i3
2642 }
2643 print_int(sum3) // 1+2+3+4+5 = 15
2644
2645 // 5.4 Combined break and continue
2646 mut sum4 := 0
2647 mut i4 := 0
2648 for i4 < 20 {
2649 i4++
2650 if i4 % 3 == 0 {
2651 continue
2652 }
2653 if i4 > 10 {
2654 break
2655 }
2656 sum4 += i4
2657 }
2658 print_int(sum4) // 1+2+4+5+7+8+10 = 37
2659
2660 // 5.5 Simple condition loop
2661 mut sum5 := 0
2662 mut i5 := 0
2663 for i5 < 5 {
2664 sum5 += i5
2665 i5++
2666 }
2667 print_int(sum5) // 0+1+2+3+4 = 10
2668
2669 // ==================== 6. MATCH (5 tests) ====================
2670 print_str('--- 6. Match ---')
2671
2672 // 6.1 Match with else
2673 x1 := 10
2674 match x1 {
2675 1 { print_int(1) }
2676 2 { print_int(2) }
2677 else { print_int(777) }
2678 }
2679
2680 // 6.2 Match exact case
2681 x2 := 2
2682 match x2 {
2683 1 { print_int(100) }
2684 2 { print_int(200) }
2685 3 { print_int(300) }
2686 else { print_int(0) }
2687 }
2688
2689 // 6.3 Match first case
2690 x3 := 1
2691 match x3 {
2692 1 { print_int(111) }
2693 2 { print_int(222) }
2694 else { print_int(999) }
2695 }
2696
2697 // 6.4 Match with computation
2698 x4 := 5
2699 match x4 {
2700 1 { print_int(x4 * 10) }
2701 5 { print_int(x4 * 100) }
2702 else { print_int(0) }
2703 }
2704
2705 // 6.5 Match with more cases
2706 x5 := 4
2707 match x5 {
2708 1 { print_int(10) }
2709 2 { print_int(20) }
2710 3 { print_int(30) }
2711 4 { print_int(40) }
2712 5 { print_int(50) }
2713 else { print_int(0) }
2714 }
2715
2716 // ==================== 7. C-STYLE LOOP & FACTORIAL (5 tests) ====================
2717 print_str('--- 7. C-style Loop ---')
2718
2719 // 7.1 Basic factorial
2720 mut fact1 := 1
2721 for k := 1; k <= 5; k++ {
2722 fact1 = fact1 * k
2723 }
2724 print_int(fact1) // 120
2725
2726 // 7.2 Sum 1 to 10
2727 mut sum7 := 0
2728 for k := 1; k <= 10; k++ {
2729 sum7 += k
2730 }
2731 print_int(sum7) // 55
2732
2733 // 7.3 Powers of 2
2734 mut pow2 := 1
2735 for k := 0; k < 8; k++ {
2736 pow2 = pow2 * 2
2737 }
2738 print_int(pow2) // 256
2739
2740 // 7.4 Countdown
2741 mut countdown := 0
2742 for k := 10; k > 0; k-- {
2743 countdown += k
2744 }
2745 print_int(countdown) // 55
2746
2747 // 7.5 Step by 2
2748 mut sum_even := 0
2749 for k := 0; k <= 10; k += 2 {
2750 sum_even += k
2751 }
2752 print_int(sum_even) // 0+2+4+6+8+10 = 30
2753
2754 // ==================== 8. RECURSIVE FUNCTIONS (5 tests) ====================
2755 print_str('--- 8. Recursive Functions ---')
2756
2757 // 8.1 Fibonacci
2758 print_int(fib(10)) // 55
2759
2760 // 8.2 Factorial recursive
2761 print_int(factorial(6)) // 720
2762
2763 // 8.3 Sum recursive
2764 print_int(sum_recursive(10)) // 55
2765
2766 // 8.4 GCD
2767 print_int(gcd(48, 18)) // 6
2768
2769 // 8.5 Power
2770 print_int(power(2, 10)) // 1024
2771
2772 // ==================== 9. NESTED LOOPS (5 tests) ====================
2773 print_str('--- 9. Nested Loops ---')
2774
2775 // 9.1 Basic 3x3
2776 mut count1 := 0
2777 mut r1 := 0
2778 for r1 < 3 {
2779 mut c1 := 0
2780 for c1 < 3 {
2781 count1++
2782 c1++
2783 }
2784 r1++
2785 }
2786 print_int(count1) // 9
2787
2788 // 9.2 4x5 grid
2789 mut count2 := 0
2790 mut r2 := 0
2791 for r2 < 4 {
2792 mut c2 := 0
2793 for c2 < 5 {
2794 count2++
2795 c2++
2796 }
2797 r2++
2798 }
2799 print_int(count2) // 20
2800
2801 // 9.3 Sum of products
2802 mut sum9 := 0
2803 mut r3 := 1
2804 for r3 <= 3 {
2805 mut c3 := 1
2806 for c3 <= 3 {
2807 sum9 += r3 * c3
2808 c3++
2809 }
2810 r3++
2811 }
2812 print_int(sum9) // (1+2+3) + (2+4+6) + (3+6+9) = 36
2813
2814 // 9.4 2x3 with accumulator
2815 mut count4 := 0
2816 mut r4 := 0
2817 for r4 < 2 {
2818 mut c4 := 0
2819 for c4 < 3 {
2820 count4 += 1
2821 c4++
2822 }
2823 r4++
2824 }
2825 print_int(count4) // 6
2826
2827 // 9.5 Inner break
2828 mut count5 := 0
2829 mut r5 := 0
2830 for r5 < 5 {
2831 mut c5 := 0
2832 for c5 < 10 {
2833 if c5 >= 3 {
2834 break
2835 }
2836 count5++
2837 c5++
2838 }
2839 r5++
2840 }
2841 print_int(count5) // 5*3 = 15
2842
2843 // ==================== 10. INFINITE LOOP (5 tests) ====================
2844 print_str('--- 10. Infinite Loop ---')
2845
2846 // 10.1 Basic infinite with break
2847 mut iter1 := 0
2848 for {
2849 iter1++
2850 if iter1 == 5 {
2851 break
2852 }
2853 }
2854 print_int(iter1) // 5
2855
2856 // 10.2 Sum until threshold
2857 mut sum10 := 0
2858 mut n10 := 0
2859 for {
2860 n10++
2861 sum10 += n10
2862 if sum10 > 20 {
2863 break
2864 }
2865 }
2866 print_int(sum10) // 21 (1+2+3+4+5+6 = 21)
2867
2868 // 10.3 Find first power of 2 > 100
2869 mut pow := 1
2870 for {
2871 pow = pow * 2
2872 if pow > 100 {
2873 break
2874 }
2875 }
2876 print_int(pow) // 128
2877
2878 // 10.4 Countdown in infinite loop
2879 mut cd := 10
2880 for {
2881 cd--
2882 if cd == 0 {
2883 break
2884 }
2885 }
2886 print_int(cd) // 0
2887
2888 // 10.5 Simple counter
2889 mut x10 := 0
2890 for {
2891 x10++
2892 if x10 >= 10 {
2893 break
2894 }
2895 }
2896 print_int(x10) // 10
2897
2898 // ==================== 11. MANY ARGUMENTS (5 tests) ====================
2899 print_str('--- 11. Many Arguments ---')
2900
2901 // 11.1 Sum of 8 ones
2902 print_int(sum_many(1, 1, 1, 1, 1, 1, 1, 1)) // 8
2903
2904 // 11.2 Sum of sequence
2905 print_int(sum_many(1, 2, 3, 4, 5, 6, 7, 8)) // 36
2906
2907 // 11.3 Product of small numbers
2908 print_int(mul_many(1, 2, 1, 2, 1, 2, 1, 2)) // 16
2909
2910 // 11.4 Max of 8
2911 print_int(max_of_eight(3, 7, 2, 9, 1, 8, 4, 6)) // 9
2912
2913 // 11.5 Weighted sum
2914 print_int(weighted_sum(1, 1, 1, 1, 1, 1, 1, 1)) // 1+2+3+4+5+6+7+8 = 36
2915
2916 // ==================== 12. MODIFYING STRUCT (5 tests) ====================
2917 print_str('--- 12. Modifying Struct via Function ---')
2918
2919 // 12.1 Basic modify
2920 mut pm1 := Point{
2921 x: 10
2922 y: 20
2923 }
2924 modify_struct(mut pm1)
2925 print_int(pm1.x) // 999
2926 print_int(pm1.y) // 888
2927
2928 // 12.2 Swap
2929 mut pm2 := Point{
2930 x: 5
2931 y: 15
2932 }
2933 swap_point(mut pm2)
2934 print_int(pm2.x) // 15
2935 print_int(pm2.y) // 5
2936
2937 // 12.3 Scale
2938 mut pm3 := Point{
2939 x: 10
2940 y: 20
2941 }
2942 scale_point(mut pm3, 3)
2943 print_int(pm3.x) // 30
2944 print_int(pm3.y) // 60
2945
2946 // 12.4 Translate
2947 mut pm4 := Point{
2948 x: 5
2949 y: 10
2950 }
2951 translate_point(mut pm4, 100, 200)
2952 print_int(pm4.x) // 105
2953 print_int(pm4.y) // 210
2954
2955 // 12.5 Reset
2956 mut pm5 := Point{
2957 x: 999
2958 y: 888
2959 }
2960 reset_point(mut pm5)
2961 print_int(pm5.x) // 0
2962 print_int(pm5.y) // 0
2963
2964 // ==================== 13. ASSERT (5 tests) ====================
2965 print_str('--- 13. Assert ---')
2966
2967 // 13.1 Basic equality
2968 assert 1 == 1
2969 print_str('Assert 1 passed')
2970
2971 // 13.2 Computed equality
2972 assert 2 + 2 == 4
2973 print_str('Assert 2 passed')
2974
2975 // 13.3 Boolean assert
2976 assert true
2977 print_str('Assert 3 passed')
2978
2979 // 13.4 Comparison assert
2980 assert 10 > 5
2981 print_str('Assert 4 passed')
2982
2983 // 13.5 Complex expression
2984 assert (3 * 4) == (2 * 6)
2985 print_str('Assert 5 passed')
2986
2987 // ==================== 14. HEAP ALLOCATION (5 tests) ====================
2988 print_str('--- 14. Heap Allocation ---')
2989
2990 // 14.1 Basic heap Point
2991 hp1 := &Point{
2992 x: 10
2993 y: 20
2994 }
2995 print_int(hp1.x) // 10
2996 print_int(hp1.y) // 20
2997
2998 // 14.2 Heap with zero
2999 hp2 := &Point{
3000 x: 0
3001 y: 0
3002 }
3003 print_int(hp2.x) // 0
3004 print_int(hp2.y) // 0
3005
3006 // 14.3 Heap with computed values
3007 hp3 := &Point{
3008 x: 5 * 5
3009 y: 6 * 6
3010 }
3011 print_int(hp3.x) // 25
3012 print_int(hp3.y) // 36
3013
3014 // 14.4 Heap Rectangle
3015 hr := &Rectangle{
3016 width: 100
3017 height: 200
3018 origin: Point{
3019 x: 10
3020 y: 20
3021 }
3022 }
3023 print_int(hr.width) // 100
3024 print_int(hr.height) // 200
3025
3026 // 14.5 Heap Node
3027 hn := &Node{
3028 value: 42
3029 left: 1
3030 right: 2
3031 }
3032 print_int(hn.value) // 42
3033 print_int(hn.left) // 1
3034 print_int(hn.right) // 2
3035
3036 // ==================== 15. BITWISE OPERATIONS (5 tests) ====================
3037 print_str('--- 15. Bitwise Operations ---')
3038
3039 // 15.1 Basic AND
3040 print_int(0b1100 & 0b1010) // 8
3041
3042 // 15.2 Basic OR
3043 print_int(0b1100 | 0b1010) // 14
3044
3045 // 15.3 Basic XOR
3046 print_int(0b1100 ^ 0b1010) // 6
3047
3048 // 15.4 Mask extraction
3049 num := 0xABCD
3050 low_byte := num & 0xFF
3051 print_int(low_byte) // 0xCD = 205
3052
3053 // 15.5 Bit set/clear
3054 mut flags := 0
3055 flags = flags | 0b0001 // set bit 0
3056 flags = flags | 0b0100 // set bit 2
3057 print_int(flags) // 5
3058 flags = flags & 0b1110 // clear bit 0
3059 print_int(flags) // 4
3060
3061 // ==================== 16. SHIFT OPERATIONS (5 tests) ====================
3062 print_str('--- 16. Shift Operations ---')
3063
3064 // 16.1 Left shift basic
3065 print_int(1 << 4) // 16
3066
3067 // 16.2 Right shift basic
3068 print_int(32 >> 2) // 8
3069
3070 // 16.3 Multiple shifts
3071 print_int(255 >> 4) // 15
3072
3073 // 16.4 Shift for multiply
3074 val16 := 7
3075 print_int(val16 << 3) // 7 * 8 = 56
3076
3077 // 16.5 Shift for divide
3078 val17 := 96
3079 print_int(val17 >> 4) // 96 / 16 = 6
3080
3081 // ==================== 17. MODULO (5 tests) ====================
3082 print_str('--- 17. Modulo ---')
3083
3084 // 17.1 Basic modulo
3085 print_int(17 % 5) // 2
3086
3087 // 17.2 Modulo with larger divisor
3088 print_int(100 % 7) // 2
3089
3090 // 17.3 Even/odd check
3091 print_int(15 % 2) // 1 (odd)
3092 print_int(16 % 2) // 0 (even)
3093
3094 // 17.4 Clock arithmetic
3095 hour := 23
3096 new_hour := (hour + 5) % 24
3097 print_int(new_hour) // 4
3098
3099 // 17.5 Digit extraction
3100 num17 := 12345
3101 last_digit := num17 % 10
3102 print_int(last_digit) // 5
3103 second_digit := (num17 / 10) % 10
3104 print_int(second_digit) // 4
3105
3106 // ==================== 18. POINTER ARITHMETIC (5 tests) ====================
3107 print_str('--- 18. Pointer Arithmetic ---')
3108
3109 // 18.1 Heap struct access
3110 hp_arr1 := &Point{
3111 x: 10
3112 y: 20
3113 }
3114 print_int(hp_arr1.x) // 10
3115 print_int(hp_arr1.y) // 20
3116
3117 // 18.2 Multiple heap structs
3118 hp_arr2 := &Point{
3119 x: 100
3120 y: 200
3121 }
3122 hp_arr3 := &Point{
3123 x: 300
3124 y: 400
3125 }
3126 print_int(hp_arr2.x + hp_arr3.x) // 400
3127 print_int(hp_arr2.y + hp_arr3.y) // 600
3128
3129 // 18.3 Heap struct with computed values
3130 base18 := 5
3131 hp_arr4 := &Point{
3132 x: base18 * 10
3133 y: base18 * 20
3134 }
3135 print_int(hp_arr4.x) // 50
3136 print_int(hp_arr4.y) // 100
3137
3138 // 18.4 Multiple heap allocations in loop
3139 mut sum18 := 0
3140 mut i18 := 0
3141 for i18 < 3 {
3142 hp := &Point{
3143 x: i18 * 10
3144 y: i18 * 20
3145 }
3146 sum18 = sum18 + hp.x + hp.y
3147 i18++
3148 }
3149 print_int(sum18) // 0+0 + 10+20 + 20+40 = 90
3150
3151 // 18.5 Heap node tree structure
3152 node1 := &Node{
3153 value: 100
3154 left: 0
3155 right: 0
3156 }
3157 node2 := &Node{
3158 value: 200
3159 left: 0
3160 right: 0
3161 }
3162 print_int(node1.value + node2.value) // 300
3163
3164 // ==================== 19. NESTED STRUCT ACCESS (5 tests) ====================
3165 print_str('--- 19. Nested Struct Access ---')
3166
3167 // 19.1 Basic nested access
3168 rect := Rectangle{
3169 width: 100
3170 height: 200
3171 origin: Point{
3172 x: 10
3173 y: 20
3174 }
3175 }
3176 print_int(rect.width) // 100
3177 print_int(rect.height) // 200
3178
3179 // 19.2 Nested struct field via intermediate
3180 rect2 := Rectangle{
3181 width: 50
3182 height: 60
3183 origin: Point{
3184 x: 5
3185 y: 6
3186 }
3187 }
3188 print_int(rect2.width + rect2.height) // 110
3189
3190 // 19.3 Mutable nested struct modification
3191 mut rect3 := Rectangle{
3192 width: 10
3193 height: 20
3194 origin: Point{
3195 x: 1
3196 y: 2
3197 }
3198 }
3199 rect3.width = 100
3200 rect3.height = 200
3201 print_int(rect3.width) // 100
3202 print_int(rect3.height) // 200
3203
3204 // 19.4 Multiple rectangles
3205 rect4a := Rectangle{
3206 width: 10
3207 height: 20
3208 origin: Point{
3209 x: 0
3210 y: 0
3211 }
3212 }
3213 rect4b := Rectangle{
3214 width: 30
3215 height: 40
3216 origin: Point{
3217 x: 0
3218 y: 0
3219 }
3220 }
3221 print_int(rect4a.width + rect4b.width) // 40
3222 print_int(rect4a.height + rect4b.height) // 60
3223
3224 // 19.5 Rectangle area
3225 rect5 := Rectangle{
3226 width: 12
3227 height: 10
3228 origin: Point{
3229 x: 0
3230 y: 0
3231 }
3232 }
3233 area := rect5.width * rect5.height
3234 print_int(area) // 120
3235
3236 // ==================== 20. NEGATIVE NUMBERS (5 tests) ====================
3237 print_str('--- 20. Negative Numbers ---')
3238
3239 // 20.1 Unary minus
3240 n1 := 0 - 42
3241 print_int(n1) // -42
3242
3243 // 20.2 Negative addition
3244 n2 := 0 - 10
3245 n3 := n2 + 5
3246 print_int(n3) // -5
3247
3248 // 20.3 Negative subtraction
3249 n4 := 0 - 20
3250 n5 := n4 - 10
3251 print_int(n5) // -30
3252
3253 // 20.4 Negative multiplication
3254 n6 := 0 - 7
3255 n7 := n6 * 3
3256 print_int(n7) // -21
3257
3258 // 20.5 Double negative (positive)
3259 n8 := 0 - 50
3260 n9 := 0 - n8
3261 print_int(n9) // 50
3262
3263 // ==================== 21. ELSE-IF CHAINS (5 tests) ====================
3264 print_str('--- 21. Else-If Chains ---')
3265
3266 // 21.1 classify function (> 100)
3267 print_int(classify(200)) // 3
3268
3269 // 21.2 classify (> 50)
3270 print_int(classify(75)) // 2
3271
3272 // 21.3 classify (> 0)
3273 print_int(classify(25)) // 1
3274
3275 // 21.4 classify (<= 0)
3276 print_int(classify(0)) // 0
3277
3278 // 21.5 Multiple else-if inline
3279 val21 := 42
3280 mut r21 := 0
3281 if val21 > 100 {
3282 r21 = 5
3283 } else if val21 > 50 {
3284 r21 = 4
3285 } else if val21 > 40 {
3286 r21 = 3
3287 } else if val21 > 30 {
3288 r21 = 2
3289 } else {
3290 r21 = 1
3291 }
3292 print_int(r21) // 3
3293
3294 // ==================== 22. FUNCTION RETURNING STRUCT (5 tests) ====================
3295 print_str('--- 22. Function Returning Struct ---')
3296
3297 // 22.1 Basic make_point
3298 rp1 := make_point(10, 20)
3299 print_int(rp1.x) // 10
3300 print_int(rp1.y) // 20
3301
3302 // 22.2 make_point with computation
3303 rp2 := make_point(3 * 5, 4 * 6)
3304 print_int(rp2.x) // 15
3305 print_int(rp2.y) // 24
3306
3307 // 22.3 add_points
3308 rp3 := add_points(Point{ x: 10, y: 20 }, Point{
3309 x: 30
3310 y: 40
3311 })
3312 print_int(rp3.x) // 40
3313 print_int(rp3.y) // 60
3314
3315 // 22.4 Chained struct returns
3316 rp4 := add_points(make_point(1, 2), make_point(3, 4))
3317 print_int(rp4.x) // 4
3318 print_int(rp4.y) // 6
3319
3320 // 22.5 Return struct used in arithmetic
3321 rp5 := make_point(100, 200)
3322 print_int(rp5.x + rp5.y) // 300
3323
3324 // ==================== 23. EARLY RETURN (5 tests) ====================
3325 print_str('--- 23. Early Return ---')
3326
3327 // 23.1 abs positive
3328 print_int(abs_val(42)) // 42
3329
3330 // 23.2 abs negative
3331 print_int(abs_val(0 - 17)) // 17
3332
3333 // 23.3 abs zero
3334 print_int(abs_val(0)) // 0
3335
3336 // 23.4 min
3337 print_int(min_val(10, 20)) // 10
3338
3339 // 23.5 max
3340 print_int(max_val(10, 20)) // 20
3341
3342 // ==================== 24. CLAMP & MULTI-ARG FUNCTIONS (5 tests) ====================
3343 print_str('--- 24. Clamp & Multi-Arg Functions ---')
3344
3345 // 24.1 clamp below
3346 print_int(clamp(5, 10, 100)) // 10
3347
3348 // 24.2 clamp above
3349 print_int(clamp(200, 10, 100)) // 100
3350
3351 // 24.3 clamp in range
3352 print_int(clamp(50, 10, 100)) // 50
3353
3354 // 24.4 clamp at boundary
3355 print_int(clamp(10, 10, 100)) // 10
3356
3357 // 24.5 clamp at upper boundary
3358 print_int(clamp(100, 10, 100)) // 100
3359
3360 // ==================== 25. POSTFIX INC/DEC (5 tests) ====================
3361 print_str('--- 25. Postfix Inc/Dec ---')
3362
3363 // 25.1 Basic increment
3364 mut pi1 := 10
3365 pi1++
3366 print_int(pi1) // 11
3367
3368 // 25.2 Basic decrement
3369 mut pd1 := 10
3370 pd1--
3371 print_int(pd1) // 9
3372
3373 // 25.3 Multiple increments
3374 mut pi2 := 0
3375 pi2++
3376 pi2++
3377 pi2++
3378 pi2++
3379 pi2++
3380 print_int(pi2) // 5
3381
3382 // 25.4 Inc and dec combined
3383 mut pid := 100
3384 pid++
3385 pid++
3386 pid--
3387 print_int(pid) // 101
3388
3389 // 25.5 Postfix in loop
3390 mut pi3 := 0
3391 mut cnt25 := 0
3392 for pi3 < 10 {
3393 pi3++
3394 cnt25++
3395 }
3396 print_int(cnt25) // 10
3397
3398 // ==================== 26. COMPOUND BITWISE ASSIGNMENT (5 tests) ====================
3399 print_str('--- 26. Compound Bitwise Assignment ---')
3400
3401 // 26.1 OR assign
3402 mut bw1 := 0b0011
3403 bw1 |= 0b1100
3404 print_int(bw1) // 15
3405
3406 // 26.2 AND assign
3407 mut bw2 := 0b1111
3408 bw2 &= 0b1010
3409 print_int(bw2) // 10
3410
3411 // 26.3 XOR assign
3412 mut bw3 := 0b1100
3413 bw3 ^= 0b1010
3414 print_int(bw3) // 6
3415
3416 // 26.4 Shift left assign
3417 mut bw4 := 1
3418 bw4 <<= 4
3419 print_int(bw4) // 16
3420
3421 // 26.5 Shift right assign
3422 mut bw5 := 128
3423 bw5 >>= 3
3424 print_int(bw5) // 16
3425
3426 // ==================== 27. COMPLEX BOOLEAN (5 tests) ====================
3427 print_str('--- 27. Complex Boolean ---')
3428
3429 // 27.1 AND chain
3430 if 10 > 5 && 20 > 10 && 30 > 20 {
3431 print_int(1)
3432 } else {
3433 print_int(0)
3434 }
3435
3436 // 27.2 OR chain
3437 if false || false || true {
3438 print_int(1)
3439 } else {
3440 print_int(0)
3441 }
3442
3443 // 27.3 Mixed AND/OR
3444 if (true && false) || (true && true) {
3445 print_int(1)
3446 } else {
3447 print_int(0)
3448 }
3449
3450 // 27.4 NOT with AND
3451 if !false && !false {
3452 print_int(1)
3453 } else {
3454 print_int(0)
3455 }
3456
3457 // 27.5 Complex condition
3458 v27 := 42
3459 if v27 > 10 && v27 < 100 && v27 % 2 == 0 {
3460 print_int(1)
3461 } else {
3462 print_int(0)
3463 }
3464
3465 // ==================== 28. ITERATIVE ALGORITHMS (5 tests) ====================
3466 print_str('--- 28. Iterative Algorithms ---')
3467
3468 // 28.1 Collatz for 6 (6->3->10->5->16->8->4->2->1 = 8 steps)
3469 print_int(collatz_steps(6)) // 8
3470
3471 // 28.2 Collatz for 27 (111 steps)
3472 print_int(collatz_steps(27)) // 111
3473
3474 // 28.3 Collatz for 1 (0 steps)
3475 print_int(collatz_steps(1)) // 0
3476
3477 // 28.4 Sum digits
3478 print_int(sum_digits(12345)) // 15
3479
3480 // 28.5 Sum digits of large number
3481 print_int(sum_digits(99999)) // 45
3482
3483 // ==================== 29. BIT COUNTING (5 tests) ====================
3484 print_str('--- 29. Bit Counting ---')
3485
3486 // 29.1 count_bits of 0
3487 print_int(count_bits(0)) // 0
3488
3489 // 29.2 count_bits of 7 (111)
3490 print_int(count_bits(7)) // 3
3491
3492 // 29.3 count_bits of 255 (11111111)
3493 print_int(count_bits(255)) // 8
3494
3495 // 29.4 count_bits of 1024 (10000000000)
3496 print_int(count_bits(1024)) // 1
3497
3498 // 29.5 count_bits of 0b10101010
3499 print_int(count_bits(0b10101010)) // 4
3500
3501 // ==================== 30. GLOBAL COUNTER PATTERNS (5 tests) ====================
3502 print_str('--- 30. Global Counter Patterns ---')
3503
3504 // 30.1 Global counter in loop
3505 g_count = 0
3506 mut ig := 0
3507 for ig < 10 {
3508 g_count += ig
3509 ig++
3510 }
3511 print_int(g_count) // 45
3512
3513 // 30.2 Global flag
3514 g_flag = false
3515 if g_count > 40 {
3516 g_flag = true
3517 }
3518 if g_flag {
3519 print_int(1)
3520 } else {
3521 print_int(0)
3522 }
3523
3524 // 30.3 Global struct modification in loop
3525 g_point.x = 0
3526 g_point.y = 0
3527 mut ig2 := 1
3528 for ig2 <= 5 {
3529 g_point.x += ig2
3530 g_point.y += ig2 * ig2
3531 ig2++
3532 }
3533 print_int(g_point.x) // 15
3534 print_int(g_point.y) // 55
3535
3536 // 30.4 Global with compound multiply
3537 g_val = 1
3538 mut ig3 := 1
3539 for ig3 <= 5 {
3540 g_val *= ig3
3541 ig3++
3542 }
3543 print_int(g_val) // 120
3544
3545 // 30.5 Global reset and reuse
3546 g_val = 999
3547 g_val = 0
3548 g_val += 42
3549 print_int(g_val) // 42
3550
3551 // ==================== 31. NESTED STRUCT MUTATION (5 tests) ====================
3552 print_str('--- 31. Nested Struct Mutation ---')
3553
3554 // 31.1 Modify nested struct width/height
3555 mut rm1 := Rectangle{
3556 width: 10
3557 height: 20
3558 origin: Point{
3559 x: 1
3560 y: 2
3561 }
3562 }
3563 rm1.width = 50
3564 rm1.height = 60
3565 print_int(rm1.width) // 50
3566 print_int(rm1.height) // 60
3567
3568 // 31.2 Scale rectangle via function
3569 mut rm2 := Rectangle{
3570 width: 10
3571 height: 20
3572 origin: Point{
3573 x: 0
3574 y: 0
3575 }
3576 }
3577 scale_rect(mut rm2, 5)
3578 print_int(rm2.width) // 50
3579 print_int(rm2.height) // 100
3580
3581 // 31.3 Multiple rectangle modifications
3582 mut rm3 := Rectangle{
3583 width: 5
3584 height: 5
3585 origin: Point{
3586 x: 0
3587 y: 0
3588 }
3589 }
3590 rm3.width += 10
3591 rm3.height += 20
3592 print_int(rm3.width) // 15
3593 print_int(rm3.height) // 25
3594
3595 // 31.4 Rectangle area after modification
3596 mut rm4 := Rectangle{
3597 width: 3
3598 height: 4
3599 origin: Point{
3600 x: 0
3601 y: 0
3602 }
3603 }
3604 rm4.width *= 10
3605 rm4.height *= 10
3606 print_int(rm4.width * rm4.height) // 1200
3607
3608 // 31.5 Modify struct then pass to function
3609 mut rm5 := Point{
3610 x: 5
3611 y: 10
3612 }
3613 rm5.x *= 2
3614 rm5.y *= 3
3615 scale_point(mut rm5, 2)
3616 print_int(rm5.x) // 20
3617 print_int(rm5.y) // 60
3618
3619 // ==================== 32. QUADRANT & STRUCT PASSING (5 tests) ====================
3620 print_str('--- 32. Quadrant & Struct Passing ---')
3621
3622 // 32.1 Quadrant 1
3623 print_int(point_quadrant(Point{ x: 5, y: 5 })) // 1
3624
3625 // 32.2 Quadrant 2
3626 print_int(point_quadrant(Point{ x: 0 - 5, y: 5 })) // 2
3627
3628 // 32.3 Quadrant 3
3629 print_int(point_quadrant(Point{ x: 0 - 5, y: 0 - 5 })) // 3
3630
3631 // 32.4 Quadrant 4
3632 print_int(point_quadrant(Point{ x: 5, y: 0 - 5 })) // 4
3633
3634 // 32.5 Origin
3635 print_int(point_quadrant(Point{ x: 0, y: 0 })) // 0
3636
3637 // ==================== 33. 4-FIELD STRUCT (5 tests) ====================
3638 print_str('--- 33. 4-Field Struct ---')
3639
3640 // 33.1 Basic Color init
3641 c1 := Color{
3642 r: 255
3643 g: 128
3644 b: 64
3645 a: 255
3646 }
3647 print_int(c1.r) // 255
3648 print_int(c1.g) // 128
3649
3650 // 33.2 Color brightness
3651 c2 := Color{
3652 r: 90
3653 g: 120
3654 b: 90
3655 a: 255
3656 }
3657 print_int(color_brightness(c2)) // 100
3658
3659 // 33.3 make_color function return
3660 c3 := make_color(10, 20, 30, 40)
3661 print_int(c3.r + c3.g + c3.b + c3.a) // 100
3662
3663 // 33.4 Color with zero alpha
3664 c4 := Color{
3665 r: 100
3666 g: 200
3667 b: 50
3668 a: 0
3669 }
3670 print_int(c4.a) // 0
3671 print_int(c4.b) // 50
3672
3673 // 33.5 Mutable color
3674 mut c5 := Color{
3675 r: 0
3676 g: 0
3677 b: 0
3678 a: 0
3679 }
3680 c5.r = 255
3681 c5.g = 255
3682 c5.b = 255
3683 c5.a = 128
3684 print_int(c5.r + c5.g + c5.b) // 765
3685 print_int(c5.a) // 128
3686
3687 // ==================== 34. FIBONACCI ITERATIVE (5 tests) ====================
3688 print_str('--- 34. Fibonacci Iterative ---')
3689
3690 // 34.1 Fib(10) iteratively
3691 mut fa := 0
3692 mut fb := 1
3693 for fi := 0; fi < 10; fi++ {
3694 tmp := fa + fb
3695 fa = fb
3696 fb = tmp
3697 }
3698 print_int(fa) // 55
3699
3700 // 34.2 Fib(20) iteratively
3701 fa = 0
3702 fb = 1
3703 for fi := 0; fi < 20; fi++ {
3704 tmp := fa + fb
3705 fa = fb
3706 fb = tmp
3707 }
3708 print_int(fa) // 6765
3709
3710 // 34.3 Sum of first 10 fib numbers
3711 mut fsum := 0
3712 fa = 0
3713 fb = 1
3714 for fi := 0; fi < 10; fi++ {
3715 fsum += fa
3716 tmp := fa + fb
3717 fa = fb
3718 fb = tmp
3719 }
3720 print_int(fsum) // 88
3721
3722 // 34.4 Count fib numbers below 100
3723 mut fcnt := 0
3724 fa = 0
3725 fb = 1
3726 for fa < 100 {
3727 fcnt++
3728 tmp := fa + fb
3729 fa = fb
3730 fb = tmp
3731 }
3732 print_int(fcnt) // 12
3733
3734 // 34.5 Largest fib below 1000
3735 fa = 0
3736 fb = 1
3737 for fb < 1000 {
3738 tmp := fa + fb
3739 fa = fb
3740 fb = tmp
3741 }
3742 print_int(fa) // 987
3743
3744 // ==================== 35. NESTED LOOPS WITH FLOW CONTROL (5 tests) ====================
3745 print_str('--- 35. Nested Loops with Flow Control ---')
3746
3747 // 35.1 Nested with outer break
3748 mut sum35 := 0
3749 mut r35 := 0
3750 for r35 < 10 {
3751 mut c35 := 0
3752 for c35 < 10 {
3753 sum35++
3754 c35++
3755 }
3756 r35++
3757 if r35 >= 3 {
3758 break
3759 }
3760 }
3761 print_int(sum35) // 30
3762
3763 // 35.2 Nested with inner continue
3764 mut sum35b := 0
3765 for r35b := 0; r35b < 5; r35b++ {
3766 for c35b := 0; c35b < 5; c35b++ {
3767 if c35b % 2 == 0 {
3768 continue
3769 }
3770 sum35b++
3771 }
3772 }
3773 print_int(sum35b) // 10 (5 rows * 2 odd cols)
3774
3775 // 35.3 Triple nested
3776 mut sum35c := 0
3777 for i35 := 0; i35 < 3; i35++ {
3778 for j35 := 0; j35 < 3; j35++ {
3779 for k35 := 0; k35 < 3; k35++ {
3780 sum35c++
3781 }
3782 }
3783 }
3784 print_int(sum35c) // 27
3785
3786 // 35.4 Nested with accumulating product
3787 mut prod35 := 0
3788 for i35 := 1; i35 <= 3; i35++ {
3789 for j35 := 1; j35 <= 3; j35++ {
3790 prod35 += i35 * j35
3791 }
3792 }
3793 print_int(prod35) // 36
3794
3795 // 35.5 Skip diagonal
3796 mut sum35d := 0
3797 for i35 := 0; i35 < 4; i35++ {
3798 for j35 := 0; j35 < 4; j35++ {
3799 if i35 == j35 {
3800 continue
3801 }
3802 sum35d++
3803 }
3804 }
3805 print_int(sum35d) // 12
3806
3807 // ==================== 36. COMPLEX MATCH (5 tests) ====================
3808 print_str('--- 36. Complex Match ---')
3809
3810 // 36.1 Match with function call in body
3811 x36 := 3
3812 match x36 {
3813 1 { print_int(fib(5)) }
3814 2 { print_int(fib(6)) }
3815 3 { print_int(fib(7)) }
3816 else { print_int(0) }
3817 }
3818
3819 // 13
3820
3821 // 36.2 Match with computation in body
3822 x36b := 2
3823 match x36b {
3824 1 { print_int(10 * 10) }
3825 2 { print_int(20 * 20) }
3826 3 { print_int(30 * 30) }
3827 else { print_int(0) }
3828 }
3829
3830 // 400
3831
3832 // 36.3 Match on computed value
3833 x36c := 15 % 4
3834 match x36c {
3835 0 { print_int(100) }
3836 1 { print_int(200) }
3837 2 { print_int(300) }
3838 3 { print_int(400) }
3839 else { print_int(500) }
3840 }
3841
3842 // 400
3843
3844 // 36.4 Match in loop
3845 mut sum36 := 0
3846 for i36 := 0; i36 < 5; i36++ {
3847 match i36 {
3848 0 { sum36 += 1 }
3849 1 { sum36 += 10 }
3850 2 { sum36 += 100 }
3851 else { sum36 += 1000 }
3852 }
3853 }
3854 print_int(sum36) // 1 + 10 + 100 + 1000 + 1000 = 2111
3855
3856 // 36.5 Sequential matches
3857 mut r36 := 0
3858 x36d := 5
3859 match x36d {
3860 5 { r36 += 100 }
3861 else { r36 += 1 }
3862 }
3863
3864 match x36d {
3865 5 { r36 += 200 }
3866 else { r36 += 2 }
3867 }
3868
3869 print_int(r36) // 300
3870
3871 // ==================== 37. CHAINED FUNCTION CALLS (5 tests) ====================
3872 print_str('--- 37. Chained Function Calls ---')
3873
3874 // 37.1 add(add(add(1,2),3),4) = 10
3875 print_int(add(add(add(1, 2), 3), 4)) // 10
3876
3877 // 37.2 Nested mul and add
3878 print_int(add(mul(3, 4), mul(5, 6))) // 42
3879
3880 // 37.3 sub(mul(add(2,3),4),5) = 15
3881 print_int(sub(mul(add(2, 3), 4), 5)) // 15
3882
3883 // 37.4 min of max
3884 print_int(min_val(max_val(10, 20), max_val(5, 15))) // 15
3885
3886 // 37.5 max of min
3887 print_int(max_val(min_val(10, 20), min_val(25, 30))) // 25
3888
3889 // ==================== 38. MIXED ARITHMETIC (5 tests) ====================
3890 print_str('--- 38. Mixed Arithmetic ---')
3891
3892 // 38.1 Shift + add
3893 print_int((1 << 8) + 1) // 257
3894
3895 // 38.2 Bitwise + arithmetic
3896 print_int((0xFF & 0x0F) + 16) // 31
3897
3898 // 38.3 Modulo + multiply
3899 print_int((100 % 7) * 10) // 20
3900
3901 // 38.4 Shift + bitwise
3902 print_int((1 << 4) | (1 << 2)) // 20
3903
3904 // 38.5 Complex expression
3905 v38 := 100
3906 print_int((v38 * 2 + v38 / 2) - (v38 % 3)) // 249
3907
3908 // ==================== 39. LARGE COMPUTATIONS (5 tests) ====================
3909 print_str('--- 39. Large Computations ---')
3910
3911 // 39.1 Large factorial (10!)
3912 mut lf := 1
3913 for li := 1; li <= 10; li++ {
3914 lf *= li
3915 }
3916 print_int(lf) // 3628800
3917
3918 // 39.2 Power of 2^20
3919 mut lp := 1
3920 for li := 0; li < 20; li++ {
3921 lp *= 2
3922 }
3923 print_int(lp) // 1048576
3924
3925 // 39.3 Sum of squares 1..20
3926 mut lsq := 0
3927 for li := 1; li <= 20; li++ {
3928 lsq += li * li
3929 }
3930 print_int(lsq) // 2870
3931
3932 // 39.4 Triangular number T(100)
3933 mut tri := 0
3934 for li := 1; li <= 100; li++ {
3935 tri += li
3936 }
3937 print_int(tri) // 5050
3938
3939 // 39.5 Product of 1..8
3940 print_int(mul_many(1, 2, 3, 4, 5, 6, 7, 8)) // 40320
3941
3942 // ==================== 40. INTEGRATION TEST (5 tests) ====================
3943 print_str('--- 40. Integration Test ---')
3944
3945 // 40.1 Struct + loop + function
3946 mut ip := make_point(0, 0)
3947 for ii := 1; ii <= 5; ii++ {
3948 ip = add_points(ip, make_point(ii, ii * 2))
3949 }
3950 print_int(ip.x) // 15
3951 print_int(ip.y) // 30
3952
3953 // 40.2 Conditional + struct + global
3954 g_val = 0
3955 mut ip2 := Point{
3956 x: 1
3957 y: 1
3958 }
3959 for ii := 0; ii < 10; ii++ {
3960 if ii % 2 == 0 {
3961 ip2.x += ii
3962 g_val += 1
3963 } else {
3964 ip2.y += ii
3965 }
3966 }
3967 print_int(ip2.x) // 1 + 0 + 2 + 4 + 6 + 8 = 21
3968 print_int(ip2.y) // 1 + 1 + 3 + 5 + 7 + 9 = 26
3969 print_int(g_val) // 5
3970
3971 // 40.3 Nested function + assert
3972 assert abs_val(0 - 42) == 42
3973 assert min_val(10, 20) == 10
3974 assert max_val(10, 20) == 20
3975 print_str('Integration asserts passed')
3976
3977 // 40.4 Algorithm + match
3978 mut sum40 := 0
3979 for ii := 1; ii <= 10; ii++ {
3980 match classify(ii * 10) {
3981 1 { sum40 += 1 }
3982 2 { sum40 += 10 }
3983 3 { sum40 += 100 }
3984 else { sum40 += 0 }
3985 }
3986 }
3987 print_int(sum40) // 10: 1, 20: 1, 30: 1, 40: 1, 50: 1, 60: 10, 70: 10, 80: 10, 90: 10, 100: 10 = 5 + 50 = 55
3988 // Actually: 10->1, 20->1, 30->1, 40->1, 50->1, 60->2(>50), 70->2, 80->2, 90->2, 100->2(not >100)
3989 // so: 1*5 + 10*5 = 55
3990
3991 // 40.5 Heap struct in loop with accumulation
3992 mut hsum := 0
3993 for ii := 0; ii < 5; ii++ {
3994 hp := &Point{
3995 x: ii * 3
3996 y: ii * 7
3997 }
3998 hsum += hp.x + hp.y
3999 }
4000 print_int(hsum) // (0+0)+(3+7)+(6+14)+(9+21)+(12+28) = 0+10+20+30+40 = 100
4001
4002 // ==================== 41. VECTOR MATH (5 tests) ====================
4003 print_str('--- 41. Vector Math ---')
4004
4005 va := Vec3{
4006 x: 1
4007 y: 2
4008 z: 3
4009 }
4010 vb := Vec3{
4011 x: 4
4012 y: 5
4013 z: 6
4014 }
4015 print_int(vec3_dot(va, vb)) // 1*4+2*5+3*6 = 32
4016 print_int(vec3_len_sq(va)) // 1+4+9 = 14
4017 vsum := vec3_add(va, vb)
4018 print_int(vsum.x) // 5
4019 print_int(vsum.y) // 7
4020 print_int(vsum.z) // 9
4021
4022 // ==================== 42. VECTOR SCALE & CROSS (5 tests) ====================
4023 print_str('--- 42. Vector Scale & Cross ---')
4024
4025 vs := vec3_scale(va, 3)
4026 print_int(vs.x) // 3
4027 print_int(vs.y) // 6
4028 print_int(vs.z) // 9
4029 print_int(vec3_cross_z(va, vb)) // 1*5 - 2*4 = -3
4030 vc := vec3_add(vec3_scale(va, 2), vec3_scale(vb, 3))
4031 print_int(vc.x) // 2+12 = 14
4032
4033 // ==================== 43. MATRIX OPERATIONS (5 tests) ====================
4034 print_str('--- 43. Matrix Operations ---')
4035
4036 m1 := Matrix2x2{
4037 a: 1
4038 b: 2
4039 c: 3
4040 d: 4
4041 }
4042 m2 := Matrix2x2{
4043 a: 5
4044 b: 6
4045 c: 7
4046 d: 8
4047 }
4048 print_int(mat_det(m1)) // 1*4-2*3 = -2
4049 print_int(mat_trace(m1)) // 1+4 = 5
4050 m3 := mat_mul(m1, m2)
4051 print_int(m3.a) // 1*5+2*7 = 19
4052 print_int(m3.b) // 1*6+2*8 = 22
4053 print_int(m3.d) // 3*6+4*8 = 50
4054
4055 // ==================== 44. PRIME CHECKING (5 tests) ====================
4056 print_str('--- 44. Prime Checking ---')
4057
4058 mut prime_count := 0
4059 for ii := 2; ii <= 30; ii++ {
4060 if is_prime(ii) {
4061 prime_count++
4062 }
4063 }
4064 print_int(prime_count) // primes: 2,3,5,7,11,13,17,19,23,29 = 10
4065
4066 if is_prime(97) {
4067 print_int(1)
4068 } else {
4069 print_int(0)
4070 } // 1
4071 if is_prime(100) {
4072 print_int(1)
4073 } else {
4074 print_int(0)
4075 } // 0
4076 if is_prime(2) {
4077 print_int(1)
4078 } else {
4079 print_int(0)
4080 } // 1
4081 if is_prime(1) {
4082 print_int(1)
4083 } else {
4084 print_int(0)
4085 } // 0
4086
4087 // ==================== 45. INTEGER SQUARE ROOT (5 tests) ====================
4088 print_str('--- 45. Integer Square Root ---')
4089
4090 print_int(isqrt(0)) // 0
4091 print_int(isqrt(1)) // 1
4092 print_int(isqrt(4)) // 2
4093 print_int(isqrt(100)) // 10
4094 print_int(isqrt(99)) // 9
4095
4096 // ==================== 46. REVERSE & PALINDROME (5 tests) ====================
4097 print_str('--- 46. Reverse & Palindrome ---')
4098
4099 print_int(reverse_int(12345)) // 54321
4100 print_int(reverse_int(100)) // 1
4101 print_int(count_digits(12345)) // 5
4102 if is_palindrome_num(12321) {
4103 print_int(1)
4104 } else {
4105 print_int(0)
4106 } // 1
4107 if is_palindrome_num(12345) {
4108 print_int(1)
4109 } else {
4110 print_int(0)
4111 } // 0
4112
4113 // ==================== 47. STATS TRACKING (5 tests) ====================
4114 print_str('--- 47. Stats Tracking ---')
4115
4116 mut st_min := 0
4117 mut st_max := 0
4118 mut st_sum := 0
4119 mut st_cnt := 0
4120 // Inline stats tracking for values: 10, 3, 25, 7, 15
4121 // val=10
4122 st_min = 10
4123 st_max = 10
4124 st_sum = 10
4125 st_cnt = 1
4126 // val=3
4127 if 3 < st_min { st_min = 3 }
4128 if 3 > st_max { st_max = 3 }
4129 st_sum += 3
4130 st_cnt++
4131 // val=25
4132 if 25 < st_min { st_min = 25 }
4133 if 25 > st_max { st_max = 25 }
4134 st_sum += 25
4135 st_cnt++
4136 // val=7
4137 if 7 < st_min { st_min = 7 }
4138 if 7 > st_max { st_max = 7 }
4139 st_sum += 7
4140 st_cnt++
4141 // val=15
4142 if 15 < st_min { st_min = 15 }
4143 if 15 > st_max { st_max = 15 }
4144 st_sum += 15
4145 st_cnt++
4146 print_int(st_min) // 3
4147 print_int(st_max) // 25
4148 print_int(st_sum) // 60
4149 print_int(st_cnt) // 5
4150 print_int(st_sum / st_cnt) // 12
4151
4152 // ==================== 48. BINARY SEARCH (5 tests) ====================
4153 print_str('--- 48. Binary Search ---')
4154
4155 print_int(binary_search_step(30, 0, 4, 10, 20, 30, 40, 50)) // 2
4156 print_int(binary_search_step(10, 0, 4, 10, 20, 30, 40, 50)) // 0
4157 print_int(binary_search_step(50, 0, 4, 10, 20, 30, 40, 50)) // 4
4158 print_int(binary_search_step(35, 0, 4, 10, 20, 30, 40, 50)) // -1
4159 print_int(binary_search_step(40, 0, 4, 10, 20, 30, 40, 50)) // 3
4160
4161 // ==================== 49. ACKERMANN FUNCTION (5 tests) ====================
4162 print_str('--- 49. Ackermann Function ---')
4163
4164 print_int(ackermann(0, 0)) // 1
4165 print_int(ackermann(1, 1)) // 3
4166 print_int(ackermann(2, 2)) // 7
4167 print_int(ackermann(3, 2)) // 29
4168 print_int(ackermann(0, 5)) // 6
4169
4170 // ==================== 50. TRIANGLE & GEOMETRY (5 tests) ====================
4171 print_str('--- 50. Triangle & Geometry ---')
4172
4173 print_int(triangle_area_2x(0, 0, 4, 0, 0, 3)) // 12 (area=6, 2x=12)
4174 print_int(triangle_area_2x(0, 0, 10, 0, 0, 10)) // 100
4175 rp := rotate_point_90(Point{ x: 3, y: 4 })
4176 print_int(rp.x) // -4
4177 print_int(rp.y) // 3
4178 print_int(manhattan_dist(Point{ x: 1, y: 2 }, Point{
4179 x: 4
4180 y: 6
4181 })) // 3+4 = 7
4182
4183 // ==================== 51. DIGITAL ROOT (5 tests) ====================
4184 print_str('--- 51. Digital Root ---')
4185
4186 print_int(digital_root(0)) // 0
4187 print_int(digital_root(5)) // 5
4188 print_int(digital_root(39)) // 3+9=12, 1+2=3