aboutsummaryrefslogtreecommitdiff
path: root/bootstrap/test.cff
diff options
context:
space:
mode:
Diffstat (limited to 'bootstrap/test.cff')
-rw-r--r--bootstrap/test.cff41
1 files changed, 41 insertions, 0 deletions
diff --git a/bootstrap/test.cff b/bootstrap/test.cff
new file mode 100644
index 0000000..7749345
--- /dev/null
+++ b/bootstrap/test.cff
@@ -0,0 +1,41 @@
+
+defmacro MAX(x, y) [ ((x) < (y) ? (y) : (x)) ]
+
+defmacro fmt(fmt, ...args) [ printf(fmt, args) ]
+defmacro add {
+(x) [ (x) ],
+(x, y, ...rest) [ (x) + add(y, rest) ]
+}
+
+defmacro swap(x, y) [{
+ let $x = &(x);
+ let $y = &(y);
+ let $z = *($x);
+ *($x) = *($y);
+ *($y) = ($z);
+}]
+
+fn fact(x usize) usize {
+ fn f(acc usize, n usize) usize {
+ return n == 0 ? acc : f(acc * n, n - 1);
+ }
+ return f(1, x);
+}
+
+extern fn main (argc int, argv **u8) int {
+ extern fn printf(fmt *const u8, ...) int;
+ fmt("%d\n", add(1, 2, 3, 4));
+
+ let x = 0;
+ let y = 7;
+ 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;
+ }
+
+ return foo(-1);
+}