https://github.com/akkartik/mu/blob/master/apps/factorial.mu
 1 # compute the factorial of 5, and return the result in the exit code
 2 #
 3 # To run:
 4 #   $ ./translate_mu apps/factorial.mu
 5 #   $ ./a.elf
 6 #   $ echo $?
 7 #   120
 8 #
 9 # You can also run the automated test suite:
10 #   $ ./a.elf test
11 #
12 # Compare apps/factorial4.subx
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-on-stack: (addr array addr array byte) -> exit-status/ebx: int {
35   var args/eax: (addr array addr array byte) <- copy args-on-stack
36   var tmp/ecx: int <- length args
37   $main-body: {
38     # if (len(args) <= 1) factorial(5)
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     }
pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Gen