aboutsummaryrefslogtreecommitdiff
path: root/bootstrap/test.cff
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2022-08-04 07:39:23 +0200
committerlemon <lsof@mailbox.org>2022-08-04 07:39:23 +0200
commitbb1d4b4a3e51a06fb0530dfc271a97a6cd88cc73 (patch)
treef300325814bc30e64f858ee313b8260a14d8df90 /bootstrap/test.cff
parent1625c50f0c0e4b1c7ba01a5df5713efaf6dce606 (diff)
stuff
Diffstat (limited to 'bootstrap/test.cff')
-rw-r--r--bootstrap/test.cff59
1 files changed, 47 insertions, 12 deletions
diff --git a/bootstrap/test.cff b/bootstrap/test.cff
index 7749345..61fcbf3 100644
--- a/bootstrap/test.cff
+++ b/bootstrap/test.cff
@@ -7,13 +7,23 @@ defmacro add {
(x, y, ...rest) [ (x) + add(y, rest) ]
}
-defmacro swap(x, y) [{
- let $x = &(x);
- let $y = &(y);
- let $z = *($x);
- *($x) = *($y);
- *($y) = ($z);
-}]
+defmacro swap(x, y) [
+ (do
+ let $x = &(x);
+ let $y = &(y);
+ let $z = *$x;
+ *$x = *$y;
+ *$y = $z;)
+]
+
+defmacro map {
+(f, x) [ f(x) ],
+(f, x, ...rest) [ f(x) map(f, rest) ]
+}
+
+defmacro printints_s(x) [ "%d " ## ]
+defmacro printints(...rest) [ printf(map(printints_s, rest) "\n", rest) ]
+
fn fact(x usize) usize {
fn f(acc usize, n usize) usize {
@@ -22,20 +32,45 @@ fn fact(x usize) usize {
return f(1, x);
}
-extern fn main (argc int, argv **u8) int {
+defmacro lambda(tys, body) [
+ (do
+ fn $lam tys body
+ &$lam;)
+]
+
+fn counter() int {
+ static xs int = 0;
+ extern static glob int;
+ glob;
+ return xs++;
+}
+
+extern static glob int = 42;
+
+extern fn main (argc int, argv **u8) void {
extern fn printf(fmt *const u8, ...) int;
fmt("%d\n", add(1, 2, 3, 4));
let x = 0;
let y = 7;
+ switch y {
+ case 0, 1 do
+ printf("wow\n");
+ case else
+ printf("p\n");
+ }
printf("x: %d; y: %d\n", x, y);
swap(x, y);
printf("x: %d; y: %d\n", x, y);
printf("fact(6) = %zu\n", fact(6));
- fn foo(n int) int {
- return n + 1;
- }
+ printints(1, 7, 8 + 9, x, x / (++y ^ 2));
+
+ let z = (do
+ printf("hi");
+ x + 1;);
+
+ let fo = lambda((x int) void, {});
- return foo(-1);
+ return (*fo)(0);
}