about summary refs log tree commit diff
path: root/boot/tests/transpile/functions.cskt
diff options
context:
space:
mode:
authorMel <mel@rnrd.eu>2026-05-06 18:48:56 +0200
committerMel <mel@rnrd.eu>2026-05-06 18:48:56 +0200
commitac696b22b3f03ae9670a9d1d154ce7ff848b5e55 (patch)
treee1f7ac3e1cd1f545d1ab0c1dc5c19130a9b23c5f /boot/tests/transpile/functions.cskt
parent3850a7b311bca7bae925aeea456a41036f116ebd (diff)
downloadcatskill-ac696b22b3f03ae9670a9d1d154ce7ff848b5e55.tar.zst
catskill-ac696b22b3f03ae9670a9d1d154ce7ff848b5e55.zip
Tests for new IR transpiler
Signed-off-by: Mel <mel@rnrd.eu>
Diffstat (limited to 'boot/tests/transpile/functions.cskt')
-rw-r--r--boot/tests/transpile/functions.cskt49
1 files changed, 49 insertions, 0 deletions
diff --git a/boot/tests/transpile/functions.cskt b/boot/tests/transpile/functions.cskt
new file mode 100644
index 0000000..889ffb3
--- /dev/null
+++ b/boot/tests/transpile/functions.cskt
@@ -0,0 +1,49 @@
+all function forwards land before any function body, so
+mutual recursion compiles without ordering games.
+`main` is renamed to `catskill_main` and wrapped by the
+runtime trailer to allow catskill programs to receive
+arguments using preferred types instead of the classic
+`argc` and `argv`.
+
+<<<
+
+is_even = fun (n int) bool {
+    if n == 0 {
+        return true
+    }
+    return is_odd(n - 1)
+}
+
+is_odd = fun (n int) bool {
+    if n == 0 {
+        return false
+    }
+    return is_even(n - 1)
+}
+
+main = fun () {
+    is_even(10)
+}
+
+>>>
+
+#include "core.c"
+bool is_even(integer n);
+bool is_odd(integer n);
+void catskill_main(void);
+bool is_even(integer n) {
+    if (n == 0) {
+        return true;
+    }
+    return is_odd(n - 1);
+}
+bool is_odd(integer n) {
+    if (n == 0) {
+        return false;
+    }
+    return is_even(n - 1);
+}
+void catskill_main(void) {
+    is_even(10);
+}
+#include "runtime.c"