From 6db056110bc9bab90092b29908085a9befd5956e Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Sat, 14 Mar 2020 01:25:34 -0700 Subject: 6144 --- html/apps/factorial.mu.html | 106 +++++++++++++++++++++++--------------------- 1 file changed, 56 insertions(+), 50 deletions(-) (limited to 'html/apps/factorial.mu.html') diff --git a/html/apps/factorial.mu.html b/html/apps/factorial.mu.html index 2b8d1f0c..bb402fdd 100644 --- a/html/apps/factorial.mu.html +++ b/html/apps/factorial.mu.html @@ -56,56 +56,62 @@ if ('onhashchange' in window) { https://github.com/akkartik/mu/blob/master/apps/factorial.mu
- 1 # usage:
- 2 #   ./translate_mu apps/factorial.mu
- 3 #   ./a.elf test  # to run tests
- 4 #   ./a.elf       # to run factorial(5)
- 5 #
- 6 # Compare apps/factorial4.subx
- 7 
- 8 fn factorial n: int -> result/eax: int {
- 9   compare n 1
-10   {
-11     break-if->
-12     result <- copy 1
-13   }
-14   {
-15     break-if-<=
-16     var tmp/ecx: int <- copy n
-17     tmp <- decrement
-18     result <- factorial tmp
-19     result <- multiply n
-20   }
-21 }
-22 
-23 fn test-factorial {
-24   var result/eax: int <- factorial 5
-25   check-ints-equal result 0x78 "F - test-factorial"
-26 }
-27 
-28 fn main args: (addr array kernel-string) -> exit-status/ebx: int {
-29   var a/eax: (addr array kernel-string) <- copy args
-30   var tmp/ecx: int <- length a
-31   $main-body: {
-32     compare tmp, 1
-33     # if (len(args) == 1) factorial(5)
-34     {
-35       break-if-!=
-36       var tmp/eax: int <- factorial 5
-37       exit-status <- copy tmp
-38       break $main-body
-39     }
-40     # if (args[1] == "test") run-tests()
-41     var tmp2/ecx: (addr kernel-string) <- index a, 1
-42     var tmp3/eax: boolean <- kernel-string-equal? *tmp2, "test"
-43     compare tmp3, 0
-44     {
-45       break-if-=
-46       run-tests
-47       exit-status <- copy 0  # TODO: get at Num-test-failures somehow
-48     }
-49   }
-50 }
+ 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: (addr array kernel-string) -> exit-status/ebx: int {
+35   var a/eax: (addr array kernel-string) <- copy args
+36   var tmp/ecx: int <- length a
+37   $main-body: {
+38     compare tmp, 1
+39     # if (len(args) == 1) factorial(5)
+40     {
+41       break-if-!=
+42       var tmp/eax: int <- factorial 5
+43       exit-status <- copy tmp
+44       break $main-body
+45     }
+46     # if (args[1] == "test") run-tests()
+47     var tmp2/ecx: (addr kernel-string) <- index a, 1
+48     var tmp3/eax: boolean <- kernel-string-equal? *tmp2, "test"
+49     compare tmp3, 0
+50     {
+51       break-if-=
+52       run-tests
+53       exit-status <- copy 0  # TODO: get at Num-test-failures somehow
+54     }
+55   }
+56 }
 
-- cgit 1.4.1-2-gfad0