about summary refs log tree commit diff stats
path: root/apps
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2019-11-26 18:07:55 -0800
committerKartik Agaram <vc@akkartik.com>2019-11-26 18:07:55 -0800
commitb697b343185fd60ddbf899bb2426a77cecf7306c (patch)
tree0d3914d428cb69ded10b51947ecbfbc8688b4c0c /apps
parentfee3e91d854264cacf249dc83d9a409ef66b8f4d (diff)
downloadmu-b697b343185fd60ddbf899bb2426a77cecf7306c.tar.gz
5763
Diffstat (limited to 'apps')
-rwxr-xr-xapps/mubin52835 -> 53140 bytes
-rw-r--r--apps/mu.subx76
2 files changed, 64 insertions, 12 deletions
diff --git a/apps/mu b/apps/mu
index c014f5ee..b8aad9cd 100755
--- a/apps/mu
+++ b/apps/mu
Binary files differdiff --git a/apps/mu.subx b/apps/mu.subx
index 42b31290..6385c020 100644
--- a/apps/mu.subx
+++ b/apps/mu.subx
@@ -1085,7 +1085,7 @@ _Primitive-add-lit-to-reg:
     _Primitive-add-lit-to-mem/imm32/next
 _Primitive-add-lit-to-mem:
     # add-to var1, lit => 81 0/subop/add var1/rm32 lit/imm32
-    "add"/imm32/name
+    "add-to"/imm32/name
     Int-var-and-literal/imm32/inouts
     0/imm32/outputs
     "81 0/subop/add"/imm32/subx-name
@@ -1107,7 +1107,7 @@ Int-var-on-stack:
 
 Int-var-and-second-int-var-in-some-register:
     Int-var-on-stack/imm32
-    Int-var-in-some-register/imm32/next
+    Single-int-var-in-some-register/imm32/next
 
 Int-var-and-literal:
     Int-var-on-stack/imm32
@@ -1505,9 +1505,8 @@ $mu-stmt-matches-primitive?:check-name:
       e9/jump $mu-stmt-matches-primitive?:end/disp32
     }
 $mu-stmt-matches-primitive?:check-inouts:
-    # curr = stmt->inouts
+    # for (curr/esi in stmt->inouts, curr2/edi in primitive->inouts)
     8b/-> *(ecx+8) 6/r32/esi  # Stmt1-inouts
-    # curr2 = primitive->inouts
     8b/-> *(edx+4) 7/r32/edi  # Primitive-inouts
     {
       # if (curr == 0) return (curr2 == 0)
@@ -1541,18 +1540,14 @@ $mu-stmt-matches-primitive?:check-inouts:
         e9/jump $mu-stmt-matches-primitive?:end/disp32
       }
       # curr=curr->next
-      8b/-> *(ecx+4) 1/r32/ecx  # Operand-next
+      8b/-> *(esi+4) 6/r32/esi  # Operand-next
       # curr2=curr2->next
-      8b/-> *(edx+4) 2/r32/edx  # Operand-next
+      8b/-> *(edi+4) 7/r32/edi  # Operand-next
+      eb/jump loop/disp8
     }
 $mu-stmt-matches-primitive?:check-outputs:
-    # ecx = stmt
-    8b/-> *(ebp+8) 1/r32/ecx
-    # edx = primitive
-    8b/-> *(ebp+0xc) 2/r32/edx
-    # curr = stmt->outputs
+    # for (curr/esi in stmt->outputs, curr2/edi in primitive->outputs)
     8b/-> *(ecx+0xc) 6/r32/esi  # Stmt1-outputs
-    # curr2 = primitive->outputs
     8b/-> *(edx+8) 7/r32/edi  # Primitive-outputs
     {
       # if (curr == 0) return (curr2 == 0)
@@ -1589,6 +1584,7 @@ $mu-stmt-matches-primitive?:check-outputs:
       8b/-> *(ecx+4) 1/r32/ecx  # Operand-next
       # curr2=curr2->next
       8b/-> *(edx+4) 2/r32/edx  # Operand-next
+      eb/jump loop/disp8
     }
 $mu-stmt-matches-primitive?:return-true:
     b8/copy-to-eax 1/imm32
@@ -2236,6 +2232,62 @@ test-add-literal-to-reg:
     5d/pop-to-ebp
     c3/return
 
+test-add-literal-to-mem:
+    #   add-to var1, 0x34
+    # =>
+    #   81 0/subop/add %eax 0x34/imm32
+    #
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    # setup
+    (clear-stream _test-output-stream)
+    (clear-stream _test-output-buffered-file->buffer)
+    # var-var1/ecx : var
+    68/push 0/imm32/no-register
+    68/push 8/imm32/stack-offset
+    68/push 1/imm32/block-depth
+    68/push 1/imm32/type-int
+    68/push "var1"/imm32
+    89/<- %ecx 4/r32/esp
+    # var-var2/edx : var literal
+    68/push 0/imm32/no-register
+    68/push 0/imm32/no-stack-offset
+    68/push 1/imm32/block-depth
+    68/push 0/imm32/type-literal
+    68/push "0x34"/imm32
+    89/<- %edx 4/r32/esp
+    # inouts/esi : (list var2)
+    68/push 0/imm32/next
+    52/push-edx/var-var2
+    89/<- %esi 4/r32/esp
+    # inouts = (list var1 inouts)
+    56/push-esi/next
+    51/push-ecx/var-var1
+    89/<- %esi 4/r32/esp
+    # stmt/esi : statement
+    68/push 0/imm32/next
+    68/push 0/imm32/outputs
+    56/push-esi/inouts
+    68/push "add-to"/imm32/operation
+    68/push 1/imm32
+    89/<- %esi 4/r32/esp
+    # convert
+    (emit-subx-statement _test-output-buffered-file %esi 0 Primitives 0)
+    (flush _test-output-buffered-file)
+#?     # dump _test-output-stream {{{
+#?     (write 2 "^")
+#?     (write-stream 2 _test-output-stream)
+#?     (write 2 "$\n")
+#?     (rewind-stream _test-output-stream)
+#?     # }}}
+    # check output
+    (check-next-stream-line-equal _test-output-stream "81 0/subop/add *(ebp+0x00000008) 0x34/imm32" "F - test-add-literal-to-mem")
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return
+
 test-emit-subx-statement-function-call:
     # Call a function on a variable on the stack.
     #   f foo