diff options
| author | 2022-08-06 14:10:19 +0200 | |
|---|---|---|
| committer | 2022-08-06 14:10:29 +0200 | |
| commit | b8d9ad1f6636f46a832b0f949ce7525ae08f53bd (patch) | |
| tree | 037c7e0a86835b2e284df786e3ba2680b7677cc4 /bootstrap/test.cff | |
| parent | 1dd19e56fb81d1334bb21e4aa097f9593576feb7 (diff) | |
basic method calls & many bugfix
Diffstat (limited to 'bootstrap/test.cff')
| -rw-r--r-- | bootstrap/test.cff | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/bootstrap/test.cff b/bootstrap/test.cff index 011d386..7a6b7ce 100644 --- a/bootstrap/test.cff +++ b/bootstrap/test.cff @@ -1,12 +1,5 @@ import "libc.hff"; import "libc.hff"; - -struct Vec2f; -struct Vec2f { - x f32, - y f32, -} - union Val { x i64, lo i32, @@ -17,6 +10,13 @@ enum Color { Red, Green, Blue } +defmacro each(i, x, arr, ...body) [ + for let i = 0; i < sizeof(arr)/sizeof(arr[0]); ++i { + let x = arr[i]; + { body } + } +] + static xs *void = {}, ok = 6; @@ -33,18 +33,36 @@ fn isort(xs *int, n usize) void { x(); } +struct Vec2f; +struct Vec2f { + x f32, + y f32, + + fn mag(v Vec2f) f32 { + extern fn sqrtf(_ f32) f32; + return sqrtf((v.x * v.x) + (v.y * v.y)); + } + fn zero(v *Vec2f) void { + v.x = 0; + v.y = 0; + } +} + extern fn main (argc int, argv **u8) int { let colors [3]Color = { :Red, :Green, :Blue } ; let x = Vec2f { .y: 1, .x: 2.4 }; - let p = &x; + let p *const Vec2f = &x; printf("v = { %g, %g }\n", x.x, p.y); + printf("mag = %g\n", x->mag()); + x->zero(); + printf("mag = %g\n", (&x)->mag()); let is [10]int = { [4] = 1, 2, [1 - 1] = 3 }; isort(is, 10); - for let i = 0; i < 10; ++i { - printf("%d\n", is[i]); - } + each(i, x, is, + printf("%d\n", x); + ) printf("sizeof(is) = %zu\n", sizeof(is)); printf("sizeof *void = %zu\n", sizeof *void); |