diff options
Diffstat (limited to 'bootstrap')
| -rw-r--r-- | bootstrap/test.cff | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/bootstrap/test.cff b/bootstrap/test.cff index 3a7599a..6b0e188 100644 --- a/bootstrap/test.cff +++ b/bootstrap/test.cff @@ -82,6 +82,17 @@ enum union Number { flo f32, } +defmacro match(ty, x, &body) [ + (do + let $res ty = {}; + #'match do { + defmacro yield(X) [ $res = (X); break #'match ] + switch (x) body + } while #f; + $res; + ) +] + extern fn main (argc int, argv **u8) int { let colors [3]Color = { :Red, :Green, :Blue } ; @@ -95,6 +106,13 @@ extern fn main (argc int, argv **u8) int { let x = Number:none; let x = Number:int{}; + printf("match: %d\n", match(int, x) { + case none; yield(42); + case int i; yield(i - 7); + case flo f; yield(f * 0.5f); + }); + + let is []int = { [4] = 1, 2, [1 - 1] = 3 }; isort(is, is.#len); each(i, x, is) { @@ -102,6 +120,8 @@ extern fn main (argc int, argv **u8) int { } let slice [#]int = is[3::5]; + static test *const u8 = "hi"; + printf("sl %d\n", slice[0]); slice = slice[1::4]; printf("sl %d\n", slice[0]); |