diff options
author | Kartik Agaram <vc@akkartik.com> | 2020-03-15 21:03:12 -0700 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2020-03-15 21:03:12 -0700 |
commit | c48ce3c8bfb6d1578f2530ed84b8e7b25d435b6d (patch) | |
tree | 9a7b23b95d9960853aad1be4e6e95b12f300ade8 /apps/factorial.mu | |
parent | f559236bdf9103c5f88d8dfc098f3afe3de64e4a (diff) | |
download | mu-c48ce3c8bfb6d1578f2530ed84b8e7b25d435b6d.tar.gz |
6153 - switch 'main' to use Mu strings
At the SubX level we have to put up with null-terminated kernel strings for commandline args. But so far we haven't done much with them. Rather than try to support them we'll just convert them transparently to standard length-prefixed strings. In the process I realized that it's not quite right to treat the combination of argc and argv as an array of kernel strings. Argc counts the number of elements, whereas the length of an array is usually denominated in bytes.
Diffstat (limited to 'apps/factorial.mu')
-rw-r--r-- | apps/factorial.mu | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/apps/factorial.mu b/apps/factorial.mu index 83b2bedf..55bee98e 100644 --- a/apps/factorial.mu +++ b/apps/factorial.mu @@ -31,21 +31,21 @@ fn test-factorial { check-ints-equal result 0x78 "F - test-factorial" } -fn main args: (addr array kernel-string) -> exit-status/ebx: int { - var a/eax: (addr array kernel-string) <- copy args +fn main args: (addr array string) -> exit-status/ebx: int { + var a/eax: (addr array string) <- copy args var tmp/ecx: int <- length a $main-body: { - compare tmp, 1 - # if (len(args) == 1) factorial(5) + # if (len(args) <= 4) factorial(5) + compare tmp, 4 { - break-if-!= + 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 kernel-string) <- index a, 1 - var tmp3/eax: boolean <- kernel-string-equal? *tmp2, "test" + var tmp2/ecx: (addr string) <- index a, 1 + var tmp3/eax: boolean <- string-equal? *tmp2, "test" compare tmp3, 0 { break-if-= |