about summary refs log tree commit diff stats
path: root/apps/mu.subx
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-05-21 15:36:31 -0700
committerKartik Agaram <vc@akkartik.com>2020-05-21 15:36:31 -0700
commitc1804838791ef62e377cfc6bb036aca21ae8e85f (patch)
tree4b62603d23917d92db8a7a94e490b71527a0ea5d /apps/mu.subx
parentc4acf442b37f7c1009838f9d29830c1e52dd962b (diff)
downloadmu-c1804838791ef62e377cfc6bb036aca21ae8e85f.tar.gz
mu.subx: 9 failing tests remaining
Diffstat (limited to 'apps/mu.subx')
-rw-r--r--apps/mu.subx69
1 files changed, 40 insertions, 29 deletions
diff --git a/apps/mu.subx b/apps/mu.subx
index 9e3efe52..106a06f7 100644
--- a/apps/mu.subx
+++ b/apps/mu.subx
@@ -2591,7 +2591,7 @@ test-convert-index-into-array-with-literal:
     5d/pop-to-ebp
     c3/return
 
-_failing-test-convert-index-into-array-on-stack:
+test-convert-index-into-array-on-stack:
     # . prologue
     55/push-ebp
     89/<- %ebp 4/r32/esp
@@ -2646,7 +2646,7 @@ _failing-test-convert-index-into-array-on-stack:
     5d/pop-to-ebp
     c3/return
 
-_failing-test-convert-index-into-array-on-stack-with-literal:
+test-convert-index-into-array-on-stack-with-literal:
     # . prologue
     55/push-ebp
     89/<- %ebp 4/r32/esp
@@ -8517,9 +8517,10 @@ translate-mu-index-stmt:  # out: (addr buffered-file), stmt: (addr stmt)
     51/push-ecx
     # ecx = stmt
     8b/-> *(ebp+0xc) 1/r32/ecx
-    # var base/ecx: (handle var) = stmt->inouts[0]
+    # var base/ecx: (addr var) = stmt->inouts[0]
     (lookup *(ecx+0xc) *(ecx+0x10))  # Stmt1-inouts Stmt1-inouts => eax
     (lookup *eax *(eax+4))  # Stmt-var-value Stmt-var-value => eax
+    89/<- %ecx 0/r32/eax
     # if (var->register) do one thing
     {
       81 7/subop/compare *(ecx+0x18) 0/imm32  # Var-register
@@ -8586,7 +8587,7 @@ $translate-mu-index-stmt-with-array-in-register:emit-base:
     (lookup *(ebx+0x18) *(ebx+0x1c))  # Var-register Var-register => eax
     (write-buffered *(ebp+8) %eax)
     (write-buffered *(ebp+8) " + ")
-    # var index/edx: (handle var) = inouts[1]
+    # var index/edx: (addr var) = inouts[1]
     (lookup *(ecx+0xc) *(ecx+0x10))  # Stmt1-inouts Stmt1-inouts => eax
     (lookup *(eax+8) *(eax+0xc))  # Stmt-var-next Stmt-var-next => eax
     (lookup *eax *(eax+4))  # Stmt-var-value Stmt-var-value => eax
@@ -8598,7 +8599,7 @@ $translate-mu-index-stmt-with-array-in-register:emit-base:
 $translate-mu-index-stmt-with-array-in-register:emit-register-index:
       # if index is an int
       (lookup *(edx+8) *(edx+0xc))  # Var-type Var-type => eax
-      (is-simple-mu-type? %eax 1)  # => eax
+      (is-simple-mu-type? %eax 1)  # int => eax
       3d/compare-eax-and 0/imm32/false
       {
         0f 84/jump-if-= break/disp32
@@ -8626,7 +8627,7 @@ $translate-mu-index-stmt-with-array-in-register:emit-int-register-index:
       3d/compare-eax-and 0/imm32/false
       {
         0f 84/jump-if-= break/disp32
-        # print index->register " + 4) "
+        # print index->register
 $translate-mu-index-stmt-with-array-in-register:emit-offset-register-index:
         (lookup *(edx+0x18) *(edx+0x1c))  # Var-register Var-register => eax
         (write-buffered *(ebp+8) %eax)
@@ -8692,29 +8693,34 @@ translate-mu-index-stmt-with-array-on-stack:  # out: (addr buffered-file), stmt:
     #
     (emit-indent *(ebp+8) *Curr-block-depth)
     (write-buffered *(ebp+8) "8d/copy-address *(ebp + ")
-    # var curr/eax = stmt->inouts
+    # var curr/edx: (addr stmt-var) = lookup(stmt->inouts)
     8b/-> *(ebp+0xc) 0/r32/eax
-    # var base/ecx: (handle var) = stmt->inouts[0]
-    8b/-> *(eax+8) 0/r32/eax  # Stmt1-inouts
-    8b/-> *eax 1/r32/ecx  # Stmt-var-value
-    # curr = curr->next
-    8b/-> *(eax+4) 0/r32/eax  # Stmt-var-next
-    # var index/edx: (handle var) = stmt->inouts[1]
-    8b/-> *eax 2/r32/edx  # Stmt-var-value
+    (lookup *(eax+0xc) *(eax+0x10))  # Stmt1-inouts Stmt1-inouts => eax
+    89/<- %edx 0/r32/eax
+    # var base/ecx: (addr var) = lookup(curr->value)
+    (lookup *eax *(eax+4))  # Stmt-var-value Stmt-var-value => eax
+    89/<- %ecx 0/r32/eax
+    # var curr2/eax: (addr stmt-var) = lookup(curr->next)
+    (lookup *(edx+8) *(edx+0xc))  # Stmt-var-next Stmt-var-next => eax
+    # var index/edx: (handle var) = curr2->value
+    (lookup *eax *(eax+4))  # Stmt-var-value Stmt-var-value => eax
+    89/<- %edx 0/r32/eax
     # if index->register
-    81 7/subop/compare *(edx+0x10) 0/imm32  # Var-register
+    81 7/subop/compare *(edx+0x18) 0/imm32  # Var-register
     {
       0f 84/jump-if-= break/disp32
 $translate-mu-index-stmt-with-array-on-stack:emit-register-index:
       # if index is an int
-      (is-simple-mu-type? *(edx+4) 1)  # Var-type, int => eax
+      (lookup *(edx+8) *(edx+0xc))  # Var-type Var-type => eax
+      (is-simple-mu-type? %eax 1)  # int => eax
       3d/compare-eax-and 0/imm32/false
       {
         0f 84/jump-if-= break/disp32
 $translate-mu-index-stmt-with-array-on-stack:emit-int-register-index:
         # print index->register "<<" log2(size-of(element-type(base))) " + " base->offset+4
         # . inouts[1]->register "<<"
-        (write-buffered *(ebp+8) *(edx+0x10))  # Var-register
+        (lookup *(edx+0x18) *(edx+0x1c))  # Var-register Var-register => eax
+        (write-buffered *(ebp+8) %eax)
         (write-buffered *(ebp+8) "<<")
         # . log2(size-of(element(base)))
         # TODO: ensure size is a power of 2
@@ -8725,8 +8731,8 @@ $translate-mu-index-stmt-with-array-on-stack:emit-int-register-index:
         #
         (write-buffered *(ebp+8) " + ")
         #
-        8b/-> *(ecx+0xc) 0/r32/eax  # Var-offset
-        05/add-to-eax 4/imm32
+        8b/-> *(ecx+0x14) 0/r32/eax  # Var-offset
+        05/add-to-eax 4/imm32  # for array length
         (print-int32-buffered *(ebp+8) %eax)
         e9/jump $translate-mu-index-stmt-with-array-on-stack:emit-register-index-done/disp32
       }
@@ -8735,33 +8741,37 @@ $translate-mu-index-stmt-with-array-on-stack:emit-int-register-index:
       81 7/subop/compare *eax 0/imm32/false  # Tree-is-atom
       0f 85/jump-if-!= $translate-mu-index-stmt-with-array:error2/disp32
       # if index has type (offset ...)
-      (is-simple-mu-type? *(eax+4) 7)  # Tree-left, offset => eax
+      (lookup *(eax+4) *(eax+8))  # Tree-left Tree-left => eax
+      (is-simple-mu-type? %eax 7)  # => eax
       3d/compare-eax-and 0/imm32/false
       {
         0f 84/jump-if-= break/disp32
         # print index->register
 $translate-mu-index-stmt-with-array-on-stack:emit-offset-register-index:
-        (write-buffered *(ebp+8) *(edx+0x10))  # Var-register
+        (lookup *(edx+0x18) *(edx+0x1c))  # Var-register Var-register => eax
+        (write-buffered *(ebp+8) %eax)
       }
 $translate-mu-index-stmt-with-array-on-stack:emit-register-index-done:
       (write-buffered *(ebp+8) ") ")
       e9/jump $translate-mu-index-stmt-with-array-on-stack:emit-output/disp32
     }
     # otherwise if index is a literal
-    (is-simple-mu-type? *(edx+4) 0)  # Var-type => eax
+    (lookup *(edx+8) *(edx+0xc))  # Var-type Var-type => eax
+    (is-simple-mu-type? %eax 0)  # => eax
     3d/compare-eax-and 0/imm32/false
     {
       0f 84/jump-if-= break/disp32
 $translate-mu-index-stmt-with-array-on-stack:emit-literal-index:
       # var idx-value/edx: int = parse-hex-int(index->name)
-      (parse-hex-int *edx)  # Var-name => eax
-      89/<- %ebx 0/r32/eax
+      (lookup *edx *(edx+4))  # Var-name Var-name => eax
+      (parse-hex-int %eax)  # Var-name => eax
+      89/<- %edx 0/r32/eax
       # offset = idx-value * size-of(element-type(base->type))
       (array-element-type-id %ecx)  # => eax
       (size-of-type-id %eax)  # => eax
-      f7 4/subop/multiply-into-eax %ebx  # clobbers edx
+      f7 4/subop/multiply-into-eax %edx  # clobbers edx
       # offset += base->offset
-      03/add *(ecx+0xc) 0/r32/eax  # Var-offset
+      03/add *(ecx+0x14) 0/r32/eax  # Var-offset
       # offset += 4 for array size
       05/add-to-eax 4/imm32
       # TODO: check edx for overflow
@@ -8775,9 +8785,10 @@ $translate-mu-index-stmt-with-array-on-stack:emit-literal-index:
 $translate-mu-index-stmt-with-array-on-stack:emit-output:
     # outputs[0] "/r32"
     8b/-> *(ebp+0xc) 0/r32/eax
-    8b/-> *(eax+0xc) 0/r32/eax  # Stmt1-outputs
-    8b/-> *eax 0/r32/eax  # Stmt-var-value
-    (get Registers *(eax+0x10) 0xc "Registers")  # Var-register => eax
+    (lookup *(eax+0x14) *(eax+0x18))  # Stmt1-outputs Stmt1-outputs => eax
+    (lookup *eax *(eax+4))  # Stmt-var-value Stmt-var-value => eax
+    (lookup *(eax+0x18) *(eax+0x1c))  # Var-register Var-register => eax
+    (get Registers %eax 0xc "Registers")  # => eax: (addr int)
     (print-int32-buffered *(ebp+8) *eax)
     (write-buffered *(ebp+8) "/r32\n")
 $translate-mu-index-stmt-with-array-on-stack:end: