From 762c6c17c9effd360a6e00a440964cb176cf96e7 Mon Sep 17 00:00:00 2001 From: lemon Date: Sat, 6 Aug 2022 05:42:19 +0200 Subject: macro body arg --- bootstrap/test.cff | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'bootstrap/test.cff') diff --git a/bootstrap/test.cff b/bootstrap/test.cff index 011d386..6c0f605 100644 --- a/bootstrap/test.cff +++ b/bootstrap/test.cff @@ -20,6 +20,18 @@ enum Color { static xs *void = {}, ok = 6; +defmacro each(i, x, arr, &body) [ + for let i = 0; i < sizeof(arr)/sizeof(arr[0]); ++i { + let x = arr[i]; + body + } +] +defmacro times(n,&body) [ + for let $i = 0; $i < (n); ++$i { + body + } +] + fn isort(xs *int, n usize) void { fn icmp(lhs *const void, rhs *const void, _ *void) int { let lhs = *as(*int)lhs, @@ -40,13 +52,14 @@ extern fn main (argc int, argv **u8) int { let p = &x; printf("v = { %g, %g }\n", x.x, p.y); - 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]); - } + let xs [10]int = { [4] = 1, 2, [1 - 1] = 3 }; + isort(xs, 10); + + each(i, x, xs) { + printf("%d\n", xs[i]); + } - printf("sizeof(is) = %zu\n", sizeof(is)); + printf("sizeof(is) = %zu\n", sizeof(xs)); printf("sizeof *void = %zu\n", sizeof *void); -- cgit v1.2.3