about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-02-18 01:32:53 -0800
committerKartik Agaram <vc@akkartik.com>2020-02-18 01:34:49 -0800
commit8eec3eae35d3961a65b1ced4313ca00a0e32e55e (patch)
treec575995e9987ffea96d7cd9a6fcf69424a11ca9c
parenta5469a3a7ed6900fe7c8cea6a7558e821d262c56 (diff)
downloadmu-8eec3eae35d3961a65b1ced4313ca00a0e32e55e.tar.gz
6024 - finally, commandline parsing in Mu
-rw-r--r--apps/factorial.mu26
1 files changed, 22 insertions, 4 deletions
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 {