about summary refs log tree commit diff stats
path: root/doc/pydoc/ranger.commands.html
diff options
context:
space:
mode:
Diffstat (limited to 'doc/pydoc/ranger.commands.html')
0 files changed, 0 insertions, 0 deletions
r Kartik Agaram <vc@akkartik.com> 2020-08-21 21:32:48 -0700 6719 - error-checking for 'index' instructions' href='/akkartik/mu/commit/apps/factorial.mu?h=hlt&id=e8ffaf29cea786e1c1266273c65bdb5eb42b39ab'>e8ffaf29 ^
3a558d22 ^
8eec3eae ^
27b1e19e ^

8eec3eae ^
c48ce3c8 ^
8eec3eae ^

7c2ac5dc ^

fee1bbd8 ^
3a558d22 ^
c48ce3c8 ^
d5171ad7 ^
7c2ac5dc ^


fee1bbd8 ^
8eec3eae ^

ea62afb1 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56









                                                                    

                              




















                                                   

                                                                             
                                 
               

                                      
     
                

                                     

                      
                                        
                                                         
                                                        
                   


                
                                                                     

     
 
# compute the factorial of 5, and return the result in the exit code
#
# To run:
#   $ ./translate_mu apps/factorial.mu
#   $ ./a.elf
#   $ echo $?
#   120
#
# You can also run the automated test suite:
#   $ ./a.elf test
#
# Compare apps/factorial4.subx

fn factorial n: int -> result/eax: int {
  compare n 1
  {
    break-if->
    result <- copy 1
  }
  {
    break-if-<=
    var tmp/ecx: int <- copy n
    tmp <- decrement
    result <- factorial tmp
    result <- multiply n
  }
}

fn test-factorial {
  var result/eax: int <- factorial 5
  check-ints-equal result 0x78 "F - test-factorial"
}

fn main args-on-stack: (addr array addr array byte) -> exit-status/ebx: int {
  var args/eax: (addr array addr array byte) <- copy args-on-stack
  var tmp/ecx: int <- length args
  $main-body: {
    # if (len(args) <= 1) factorial(5)
    compare tmp, 1
    {
      break-if->
      var tmp/eax: int <- factorial 5
      exit-status <- copy tmp
      break $main-body
    }
    # if (args[1] == "test") run-tests()
    var tmp2/ecx: (addr addr array byte) <- index args, 1
    var tmp3/eax: boolean <- string-equal? *tmp2, "test"
    compare tmp3, 0
    {
      break-if-=
      run-tests
      exit-status <- copy 0  # TODO: get at Num-test-failures somehow
    }
  }
}