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