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