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