From 8eec3eae35d3961a65b1ced4313ca00a0e32e55e Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Tue, 18 Feb 2020 01:32:53 -0800 Subject: 6024 - finally, commandline parsing in Mu --- apps/factorial.mu | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'apps') diff --git a/apps/factorial.mu b/apps/factorial.mu index c9e241aa..164a7d45 100644 --- a/apps/factorial.mu +++ b/apps/factorial.mu @@ -1,8 +1,26 @@ +# usage is finicky for now: +# ./translate_mu apps/factorial.mu +# ./a.elf test # any args? run tests +# ./a.elf # no args? run factorial(5) fn main args: (addr array kernel-string) -> exit-status/ebx: int { -#? run-tests -#? result <- copy 0 - var tmp/eax: int <- factorial 5 - exit-status <- copy tmp + var a/eax: (addr array kernel-string) <- copy args + var tmp/ecx: int <- length a + $main-body: { + compare tmp, 1 + # if (len(args) != 1) run-tests() + { + break-if-= + run-tests + exit-status <- copy 0 + break $main-body + } + # if (len(args) == 1) factorial(5) + { + break-if-!= + var tmp/eax: int <- factorial 5 + exit-status <- copy tmp + } + } } fn factorial n: int -> result/eax: int { -- cgit 1.4.1-2-gfad0 le class='tabs'> about summary refs log tree commit diff stats
path: root/tangle.mu
blob: 91f12deade5635bfc0bab86308fda0fbea63bdec (plain) (blame)
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