From d08e43f70d7482543c9bb2ba548bcd31e7eba978 Mon Sep 17 00:00:00 2001 From: lemon Date: Fri, 26 Aug 2022 07:42:27 +0200 Subject: gensym fix, offset fix, str statics --- bootstrap/test.cff | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'bootstrap/test.cff') 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]); -- cgit v1.2.3