https://github.com/akkartik/mu/blob/master/apps/factorial.mu
1
2
3
4
5
6 fn factorial n: int -> result/eax: int {
7 compare n 1
8 {
9 break-if->
10 result <- copy 1
11 }
12 {
13 break-if-<=
14 var tmp/ecx: int <- copy n
15 tmp <- decrement
16 result <- factorial tmp
17 result <- multiply n
18 }
19 }
20
21 fn test-factorial {
22 var result/eax: int <- factorial 5
23 check-ints-equal result 0x78 "F - test-factorial"
24 }
25
26 fn main args: (addr array kernel-string) -> exit-status/ebx: int {
27 var a/eax: (addr array kernel-string) <- copy args
28 var tmp/ecx: int <- length a
29 $main-body: {
30 compare tmp, 1
31
32 {
33 break-if-!=
34 var tmp/eax: int <- factorial 5
35 exit-status <- copy tmp
36 break $main-body
37 }
38
39 var tmp2/ecx: int <- copy 1
40 var tmp3/ecx: (addr kernel-string) <- index a, tmp2
41 var tmp4/eax: boolean <- kernel-string-equal? *tmp3, "test"
42 compare tmp4, 0
43 {
44 break-if-=
45 run-tests
46 exit-status <- copy 0
47 }
48 }
49 }