|
| 1 | +// @warnings{no-unused} |
| 2 | +module test; |
| 3 | + |
| 4 | +import stdio local; |
| 5 | + |
| 6 | +type Foo struct { |
| 7 | + i32 x; |
| 8 | + i32 y; |
| 9 | +} |
| 10 | + |
| 11 | +fn void test_foo(Foo foo) {} |
| 12 | +fn void Foo.bar(Foo* foo) {} |
| 13 | +fn Foo Foo.create(i32 x, i32 y) { return (Foo){ x, y }; } |
| 14 | + |
| 15 | +fn i32 sum(i32 *p, u32 count) { |
| 16 | + i32 total = 0; |
| 17 | + for (i32 i = 0; i < count; i++) total += p[i]; |
| 18 | + return total; |
| 19 | +} |
| 20 | + |
| 21 | +public fn i32 main() { |
| 22 | + Foo[] foos = { |
| 23 | + { }, |
| 24 | + { 0, 1 }, |
| 25 | + (Foo){ 1, 2 }, |
| 26 | + (Foo){ .x = 2, .y = 3 }, |
| 27 | + [4] = { }, |
| 28 | + [5] = { 3, 4 }, |
| 29 | + [6] = (Foo){ 4, 5 }, |
| 30 | + [7] = (Foo){ .x = 5, .y = 6 }, |
| 31 | + } |
| 32 | + |
| 33 | + test_foo({}); |
| 34 | + test_foo({ 1, 2 }); |
| 35 | + test_foo({ .x = 1, .y = 2 }); |
| 36 | + test_foo((Foo){}); |
| 37 | + test_foo((Foo){ 1, 2 }); |
| 38 | + test_foo((Foo){ .x = 1, .y = 2 }); |
| 39 | + |
| 40 | + foos[0].bar(); |
| 41 | + (Foo){1, 2}.bar(); |
| 42 | + |
| 43 | + printf("%d\n", sum((i32[]){ 1 }, 1)); |
| 44 | + printf("%d\n", sum((i32[]){ 1, 2 }, 2)); |
| 45 | + printf("%d\n", sum((i32[]){ 1, 2, 3 }, 3)); |
| 46 | + printf("%d\n", sum((i32[1]){ 1 }, 1)); |
| 47 | + printf("%d\n", sum((i32[2]){ 1, 2 }, 2)); |
| 48 | + printf("%d\n", sum((i32[10]){ 1, 2, 3 }, 10)); |
| 49 | + |
| 50 | + // Enable these tests once arrays are implied for pointer arguments |
| 51 | + //printf("%d\n", sum({ 1 }, 1)); |
| 52 | + //printf("%d\n", sum({ 1, 2 }, 2)); |
| 53 | + //printf("%d\n", sum({ 1, 2, 3 }, 3)); |
| 54 | + |
| 55 | + return 0; |
| 56 | +} |
0 commit comments