about summary refs log tree commit diff stats
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rwxr-xr-xapps/mubin69825 -> 69863 bytes
-rw-r--r--apps/mu.subx65
2 files changed, 38 insertions, 27 deletions
diff --git a/apps/mu b/apps/mu
index 0a6919bb..04cf1ee0 100755
--- a/apps/mu
+++ b/apps/mu
Binary files differdiff --git a/apps/mu.subx b/apps/mu.subx
index a67891ef..91f68a46 100644
--- a/apps/mu.subx
+++ b/apps/mu.subx
@@ -2268,6 +2268,34 @@ $stmt-has-outputs:end:
     c3/return
 
 lookup-var:  # name: (address slice), vars : (address stack (handle var)) -> result/eax: (handle var)
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    # var target/eax : (handle array byte) = slice-to-string(name)
+    (slice-to-string Heap *(ebp+8))  # => eax
+    #
+    (lookup-var-helper %eax *(ebp+0xc))  # => eax
+    # if (result == 0) abort
+    3d/compare-eax-and 0/imm32
+    74/jump-if-equal $lookup-var:abort/disp8
+$lookup-var:end:
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return
+
+$lookup-var:abort:
+    (write-buffered Stderr "unknown variable '")
+    (write-slice-buffered Stderr *(ebp+8))
+    (write-buffered Stderr "'\n")
+    (flush Stderr)
+    # . syscall(exit, 1)
+    bb/copy-to-ebx  1/imm32
+    b8/copy-to-eax  1/imm32/exit
+    cd/syscall  0x80/imm8
+    # never gets here
+
+lookup-var-helper:  # name: (address array byte), vars : (address stack (handle var)) -> result/eax: (handle var)
     # pseudocode:
     #   var curr : (address handle var) = &vars->data[vars->top - 4]
     #   var min = vars->data
@@ -2275,59 +2303,53 @@ lookup-var:  # name: (address slice), vars : (address stack (handle var)) -> res
     #     var v : (handle var) = *curr
     #     if v->name == name
     #       return v
-    #   abort
+    #   return 0
     #
     # . prologue
     55/push-ebp
     89/<- %ebp 4/r32/esp
     # . save registers
-    51/push-ecx
     52/push-edx
     53/push-ebx
     56/push-esi
-    # var target/ecx : (handle array byte) = slice-to-string(name)
-    8b/-> *(ebp+8) 1/r32/ecx
-    (slice-to-string Heap %ecx)  # => eax
-    89/<- %ecx 0/r32/eax
     # esi = vars
     8b/-> *(ebp+0xc) 6/r32/esi
     # ebx = vars->top
     8b/-> *esi 3/r32/ebx
     # if (vars->top > vars->length) abort
     3b/compare 0/r32/eax *(esi+4)
-    0f 8f/jump-if-greater $lookup-var:error1/disp32
+    0f 8f/jump-if-greater $lookup-var-helper:error1/disp32
     # var min/edx : (address handle var) = vars->data
     8d/copy-address *(esi+8) 2/r32/edx
     # var curr/ebx : (address handle var) = &vars->data[vars->top - 4]
     81 5/subop/subtract %ebx 4/imm32
     8d/copy-address *(esi+ebx+8) 3/r32/ebx
     {
-      # if (curr < min) abort
+      # if (curr < min) return 0
       39/compare %ebx 2/r32/edx
-      0f 82/jump-if-lesser-unsigned $lookup-var:error2/disp32
+      b8/copy-to-eax 0/imm32
+      0f 82/jump-if-lesser-unsigned break/disp32
       # var v/eax : (handle var) = *curr
       8b/-> *ebx 0/r32/eax
-      # if (v->name == name) break
-      (string-equal? *eax %ecx)  # Var-name Var-name
+      # if (v->name == name) return v
+      (string-equal? *eax *(ebp+8))  # Var-name
       3d/compare-eax-and 0/imm32
+      8b/-> *ebx 0/r32/eax
       75/jump-if-not-equal break/disp8
       8b/-> *(ebx+4) 3/r32/ebx  # List-next
       e9/jump loop/disp32
     }
-    # return *curr
-    8b/-> *ebx 0/r32/eax
-$lookup-var:end:
+$lookup-var-helper:end:
     # . restore registers
     5e/pop-to-esi
     5b/pop-to-ebx
     5a/pop-to-edx
-    59/pop-to-ecx
     # . epilogue
     89/<- %esp 5/r32/ebp
     5d/pop-to-ebp
     c3/return
 
-$lookup-var:error1:
+$lookup-var-helper:error1:
     (write-buffered Stderr "malformed stack when looking up '")
     (write-slice-buffered Stderr *(ebp+8))
     (write-buffered Stderr "'\n")
@@ -2338,17 +2360,6 @@ $lookup-var:error1:
     cd/syscall  0x80/imm8
     # never gets here
 
-$lookup-var:error2:
-    (write-buffered Stderr "unknown variable '")
-    (write-slice-buffered Stderr *(ebp+8))
-    (write-buffered Stderr "'\n")
-    (flush Stderr)
-    # . syscall(exit, 1)
-    bb/copy-to-ebx  1/imm32
-    b8/copy-to-eax  1/imm32/exit
-    cd/syscall  0x80/imm8
-    # never gets here
-
 test-parse-mu-stmt:
     # 'increment n'
     # . prologue