summary refs log tree commit diff stats
path: root/test/tc_commandlist.py
Commit message (Expand)AuthorAgeFilesLines
* added copyright info to config files and test caseshut2010-03-081-0/+15
* test/tc_commandlist: removed obsolete testhut2010-02-161-4/+6
* commandlist: bugfixhut2010-01-141-5/+6
* commandlist: aliases are now references rather than copieshut2010-01-131-2/+13
* commandlist: added alias(existing, *new)hut2010-01-131-0/+8
* commandlist: added clear()hut2010-01-131-0/+9
* commandlist: improvements and test casehut2010-01-131-0/+54
244591c3042df43'>6b343a82 ^
ad61776f ^
































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







                                        
                                                                     

                                        
                                                          



                               
                                                  
































                                                        
# parse a decimal int at the commandline
#
# To run:
#   $ ./translate_mu apps/parse-int.mu
#   $ ./a.elf 123
#   $ echo $?
#   123

fn main _args: (addr array addr array byte) -> exit-status/ebx: int {
$main-body: {
  # if no args, print a message and exit
  var args/esi: (addr array addr array byte) <- copy _args
  var n/ecx: int <- length args
  compare n, 1
  {
    break-if->
    print-string 0, "usage: parse-int <integer>\n"
    exit-status <- copy 1
    break $main-body
  }
  # otherwise parse the first arg as an integer
  var in/ecx: (addr addr array byte) <- index args, 1
  var out/eax: int <- parse-int *in
  exit-status <- copy out
}
}

fn parse-int _in: (addr array byte) -> result/eax: int {
  var in/esi: (addr array byte) <- copy _in
  var len/edx: int <- length in
  var i/ecx: int <- copy 0
  var out/edi: int <- copy 0
  {
    compare i, len
    break-if->=
    # out *= 10
    var ten/eax: int <- copy 0xa
    out <- multiply ten
    # c = in[i]
    var tmp/ebx: (addr byte) <- index in, i
    var c/eax: byte <- copy 0
    c <- copy-byte *tmp
    #
    var digit/eax: int <- to-decimal-digit c
    out <- add digit
    i <- increment
    loop
  }
  result <- copy out
}