about summary refs log tree commit diff
path: root/boot/tests/transpile/functions.cskt
blob: 889ffb37a1b4ed8c5a4211ffd53e2a49c448aa6e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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"