about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--102kernel-string.subx10
-rw-r--r--apps/factorial.mu6
-rwxr-xr-xapps/mubin254216 -> 254249 bytes
-rw-r--r--mu-init.subx12
-rwxr-xr-xtest_apps57
5 files changed, 73 insertions, 12 deletions
diff --git a/102kernel-string.subx b/102kernel-string.subx
index ca92d813..13472cb0 100644
--- a/102kernel-string.subx
+++ b/102kernel-string.subx
@@ -4,7 +4,7 @@
 
 == code
 
-kernel-string-to-string:  # ad: (addr allocation-descriptor), in: (addr kernel-string) -> result/eax: (addr array byte)
+kernel-string-to-string:  # ad: (addr allocation-descriptor), in: (addr kernel-string), out: (addr handle array byte)
     # . prologue
     55/push-ebp
     89/<- %ebp 4/r32/esp
@@ -18,22 +18,24 @@ kernel-string-to-string:  # ad: (addr allocation-descriptor), in: (addr kernel-s
     (kernel-string-length *(ebp+0xc))
     89/<- %ecx 0/r32/eax
     # result = allocate-array(ad, len)
-    (allocate-array *(ebp+8) %ecx)  # => eax
+    (allocate-array *(ebp+8) %ecx *(ebp+0x10))
     # var c/edx: byte = 0
     ba/copy-to-edx 0/imm32
     # var src/esi: (addr byte) = in
     8b/-> *(ebp+0xc) 6/r32/esi
     # var dest/edi: (addr byte) = result->data
+    8b/-> *(ebp+0x10) 7/r32/edi
+    (lookup *edi *(edi+4))  # => eax
     8d/copy-address *(eax+4) 7/r32/edi
     {
 $kernel-string-to-string:loop:
       # c = *src
-      8a/byte-> *esi 2/r32/edx
+      8a/byte-> *esi 2/r32/dl
       # if (c == 0) break
       81 7/subop/compare %edx 0/imm32
       74/jump-if-= break/disp8
       # *dest = c
-      88/byte<- *edi 2/r32/edx
+      88/byte<- *edi 2/r32/dl
       # ++src
       46/increment-esi
       # ++dest
diff --git a/apps/factorial.mu b/apps/factorial.mu
index e498cae1..5a748f0d 100644
--- a/apps/factorial.mu
+++ b/apps/factorial.mu
@@ -31,8 +31,8 @@ fn test-factorial {
   check-ints-equal result 0x78 "F - test-factorial"
 }
 
-fn main args: (addr array string) -> exit-status/ebx: int {
-  var a/eax: (addr array string) <- copy args
+fn main args: (addr array (addr array byte)) -> exit-status/ebx: int {
+  var a/eax: (addr array (addr array byte)) <- copy args
   var tmp/ecx: int <- length a
   $main-body: {
     # if (len(args) <= 1) factorial(5)
@@ -44,7 +44,7 @@ fn main args: (addr array string) -> exit-status/ebx: int {
       break $main-body
     }
     # if (args[1] == "test") run-tests()
-    var tmp2/ecx: (addr string) <- index a, 1
+    var tmp2/ecx: (addr addr array byte) <- index a, 1
     var tmp3/eax: boolean <- string-equal? *tmp2, "test"
     compare tmp3, 0
     {
diff --git a/apps/mu b/apps/mu
index 33034270..9cb68c00 100755
--- a/apps/mu
+++ b/apps/mu
Binary files differdiff --git a/mu-init.subx b/mu-init.subx
index 74d90b7a..984e4ff7 100644
--- a/mu-init.subx
+++ b/mu-init.subx
@@ -27,13 +27,14 @@ $Entry:initialize-args:
     8b/-> *esi 2/r32/edx
     # argc is in words; convert it to bytes
     c1/shift 4/subop/left %edx 2/imm8
-    # var tmp/eax: handle
+    # var tmp/ebx: handle
     68/push 0/imm32
     68/push 0/imm32
-    89/<- %eax 4/r32/esp
+    89/<- %ebx 4/r32/esp
     # var args/edi: (addr array (addr array byte))
-    (allocate-array Heap %edx %eax)
-    8b/-> *(eax+4) 7/r32/edi
+    (allocate-array Heap %edx %ebx)
+    (lookup *ebx *(ebx+4))  # => eax
+    89/<- %edi 0/r32/eax
     # var curr/ecx: (addr kernel-string) = argv
     8d/copy-address *(esi+4) 1/r32/ecx
     # var max/edx: (addr kernel-string) = argv+4+argc
@@ -45,7 +46,8 @@ $Entry:initialize-args:
       39/compare %ecx 2/r32/edx
       73/jump-if-addr>= break/disp8
       # *dest = kernel-string-to-string(*curr)
-      (kernel-string-to-string Heap *ecx)  # => eax
+      (kernel-string-to-string Heap *ecx %ebx)
+      (lookup *ebx *(ebx+4))  # => eax
       89/<- *esi 0/r32/eax
       # curr += 4
       81 0/subop/add %ecx 4/imm32
diff --git a/test_apps b/test_apps
index e9532c66..b2d10472 100755
--- a/test_apps
+++ b/test_apps
@@ -338,4 +338,61 @@ echo mu
 ./translate_subx init.$OS [0-9]*.subx apps/mu.subx
 diff apps/mu a.elf
 
+# Mu programs
+
+echo ex1.mu
+./translate_mu apps/ex1.mu
+test $EMULATED  &&  {
+  ./bootstrap run a.elf  ||  ret=$?
+  test $ret -eq 42  # life, the universe and everything
+}
+test $NATIVE  &&  {
+  ./a.elf  ||  ret=$?
+  test $ret -eq 42  # life, the universe and everything
+}
+
+echo ex2.mu
+./translate_mu apps/ex2.mu
+test $EMULATED  &&  {
+  ./bootstrap run a.elf  ||  ret=$?
+  test $ret -eq 7
+}
+test $NATIVE  &&  {
+  ./a.elf  ||  ret=$?
+  test $ret -eq 7
+}
+
+echo ex2.2.mu
+./translate_mu apps/ex2.2.mu
+test $EMULATED  &&  {
+  ./bootstrap run a.elf  ||  ret=$?
+  test $ret -eq 4
+}
+test $NATIVE  &&  {
+  ./a.elf  ||  ret=$?
+  test $ret -eq 4
+}
+
+echo ex3.mu
+./translate_mu apps/ex3.mu
+test $EMULATED  &&  {
+  ./bootstrap run a.elf  ||  ret=$?
+  test $ret -eq 55
+}
+test $NATIVE  &&  {
+  ./a.elf  ||  ret=$?
+  test $ret -eq 55
+}
+
+echo ex3.2.mu
+./translate_mu apps/ex3.2.mu
+test $EMULATED  &&  {
+  ./bootstrap run a.elf  ||  ret=$?
+  test $ret -eq 55
+}
+test $NATIVE  &&  {
+  ./a.elf  ||  ret=$?
+  test $ret -eq 55
+}
+
 exit 0