about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--apps/mu.subx51
1 files changed, 31 insertions, 20 deletions
diff --git a/apps/mu.subx b/apps/mu.subx
index 6fac67b2..7f760486 100644
--- a/apps/mu.subx
+++ b/apps/mu.subx
@@ -5362,6 +5362,7 @@ add-operation-and-inputs-to-stmt:  # stmt: (addr stmt), line: (addr stream byte)
     51/push-ecx
     52/push-edx
     53/push-ebx
+    56/push-esi
     57/push-edi
     # edi = stmt
     8b/-> *(ebp+8) 7/r32/edi
@@ -5371,6 +5372,10 @@ add-operation-and-inputs-to-stmt:  # stmt: (addr stmt), line: (addr stream byte)
     89/<- %ecx 4/r32/esp
     # var is-deref?/edx: boolean = false
     ba/copy-to-edx 0/imm32/false
+    # var v/esi: (handle var)
+    68/push 0/imm32
+    68/push 0/imm32
+    89/<- %esi 4/r32/esp
 $add-operation-and-inputs-to-stmt:read-operation:
     (next-mu-token *(ebp+0xc) %ecx)
     8d/copy-address *(edi+4) 0/r32/eax  # Stmt1-operation or Regvardef-operationStmt1-operation or Regvardef-operation
@@ -5418,18 +5423,19 @@ $add-operation-and-inputs-to-stmt:inout-is-deref:
         ff 0/subop/increment *ecx
         ba/copy-to-edx 1/imm32/true
       }
-      # HERE
-      (lookup-var-or-literal %ecx *(ebp+0x10))  # => eax
+      (lookup-var-or-literal %ecx *(ebp+0x10) %esi)
 $add-operation-and-inputs-to-stmt:save-var:
+      # HERE
       (append-stmt-var Heap %eax *(edi+8) %edx)  # Stmt1-inouts or Regvardef-inouts => eax
       89/<- *(edi+8) 0/r32/eax  # Stmt1-inouts or Regvardef-inouts
       e9/jump loop/disp32
     }
 $add-operation-and-inputs-to-stmt:end:
     # . reclaim locals
-    81 0/subop/add %esp 8/imm32
+    81 0/subop/add %esp 0x10/imm32
     # . restore registers
     5f/pop-to-edi
+    5e/pop-to-esi
     5b/pop-to-ebx
     5a/pop-to-edx
     59/pop-to-ecx
@@ -5536,7 +5542,6 @@ lookup-var-or-literal:  # name: (addr slice), vars: (addr stack (handle var)), o
     }
     # otherwise return lookup-var(name, vars)
     {
-      # HERE
       (lookup-var %esi *(ebp+0xc))  # => eax
     }
 $lookup-var-or-literal:end:
@@ -5558,18 +5563,22 @@ $lookup-var-or-literal:abort:
     cd/syscall  0x80/imm8
     # never gets here
 
-# TODO
 # return first 'name' from the top (back) of 'vars' and abort if not found
 lookup-var:  # name: (addr slice), vars: (addr stack (handle var)), out: (addr handle var)
     # . prologue
     55/push-ebp
     89/<- %ebp 4/r32/esp
+    # . save registers
+    50/push-eax
     #
-    (lookup-var-helper *(ebp+8) *(ebp+0xc))  # => eax
-    # if (result == 0) abort
-    3d/compare-eax-and 0/imm32
+    (lookup-var-helper *(ebp+8) *(ebp+0xc) *(ebp+0x10))
+    # if (*out == 0) abort
+    8b/-> *(ebp+0x10) 0/r32/eax
+    81 7/subop/compare *eax 0/imm32
     74/jump-if-= $lookup-var:abort/disp8
 $lookup-var:end:
+    # . restore registers
+    58/pop-to-eax
     # . epilogue
     89/<- %esp 5/r32/ebp
     5d/pop-to-ebp
@@ -5586,25 +5595,28 @@ $lookup-var:abort:
     cd/syscall  0x80/imm8
     # never gets here
 
-# TODO
 # return first 'name' from the top (back) of 'vars', and 0/null if not found
 lookup-var-helper:  # name: (addr slice), vars: (addr stack (handle var)), out: (addr handle var)
     # pseudocode:
-    #   var curr: (addr handle var) = &vars->data[vars->top - 4]
+    #   var curr: (addr handle var) = &vars->data[vars->top - 8]
     #   var min = vars->data
     #   while curr >= min
     #     var v: (handle var) = *curr
     #     if v->name == name
-    #       return v
+    #       return
+    #     curr -= 8
     #   return 0
     #
     # . prologue
     55/push-ebp
     89/<- %ebp 4/r32/esp
     # . save registers
+    50/push-eax
     52/push-edx
     53/push-ebx
     56/push-esi
+    # clear out
+    (zero-out *(ebp+0x10) *Handle-size)
     # esi = vars
     8b/-> *(ebp+0xc) 6/r32/esi
     # ebx = vars->top
@@ -5614,23 +5626,21 @@ lookup-var-helper:  # name: (addr slice), vars: (addr stack (handle var)), out:
     0f 8f/jump-if-> $lookup-var-helper:error1/disp32
     # var min/edx: (addr handle var) = vars->data
     8d/copy-address *(esi+8) 2/r32/edx
-    # var curr/ebx: (addr handle var) = &vars->data[vars->top - 4]
-    81 5/subop/subtract %ebx 4/imm32
-    8d/copy-address *(esi+ebx+8) 3/r32/ebx
+    # var curr/ebx: (addr handle var) = &vars->data[vars->top - 8]
+    8d/copy-address *(esi+ebx) 3/r32/ebx
     {
       # if (curr < min) return 0
       39/compare %ebx 2/r32/edx
       b8/copy-to-eax 0/imm32
       0f 82/jump-if-addr< break/disp32
-      # var v/eax: (handle var) = *curr
-      8b/-> *ebx 0/r32/eax
-      # if (v->name == name) return v
+      # var v/eax: (addr var) = lookup(*curr)
+      (lookup *ebx *(ebx+4))  # => eax
+      # if (v->name == name) return
       (slice-equal? *(ebp+8) *eax)  # Var-name
       3d/compare-eax-and 0/imm32/false
-      8b/-> *ebx 0/r32/eax
       75/jump-if-!= break/disp8
-      # curr -= 4
-      81 5/subop/subtract %ebx 4/imm32
+      # curr -= 8
+      81 5/subop/subtract %ebx 8/imm32
       e9/jump loop/disp32
     }
 $lookup-var-helper:end:
@@ -5638,6 +5648,7 @@ $lookup-var-helper:end:
     5e/pop-to-esi
     5b/pop-to-ebx
     5a/pop-to-edx
+    58/pop-to-eax
     # . epilogue
     89/<- %esp 5/r32/ebp
     5d/pop-to-ebp