about summary refs log tree commit diff stats
path: root/apps/mu.subx
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-09-29 09:14:09 -0700
committerKartik Agaram <vc@akkartik.com>2020-09-29 09:14:09 -0700
commitd2b9c7283aa497d4bae69c0f6e50484ab7d104ea (patch)
treebd3aa211f8f5c85a16abbdab2e7fc102cad635ec /apps/mu.subx
parent55847cde874538b4792e03c418707cc666529c92 (diff)
downloadmu-d2b9c7283aa497d4bae69c0f6e50484ab7d104ea.tar.gz
6901
Diffstat (limited to 'apps/mu.subx')
-rw-r--r--apps/mu.subx40
1 files changed, 32 insertions, 8 deletions
diff --git a/apps/mu.subx b/apps/mu.subx
index 30027164..ed6d0322 100644
--- a/apps/mu.subx
+++ b/apps/mu.subx
@@ -15180,11 +15180,8 @@ push-output-and-maybe-emit-spill:  # out: (addr buffered-file), stmt: (addr reg-
     # *Curr-local-stack-offset -= 4
     81 5/subop/subtract *Curr-local-stack-offset 4/imm32
     # emit spill
-    (emit-indent *(ebp+8) *Curr-block-depth)
-    (write-buffered *(ebp+8) "ff 6/subop/push %")
     (lookup *(ecx+0x18) *(ecx+0x1c))  # Var-register Var-register => eax
-    (write-buffered *(ebp+8) %eax)
-    (write-buffered *(ebp+8) Newline)
+    (emit-push-register *(ebp+8) %eax)
 $push-output-and-maybe-emit-spill:push:
     8b/-> *(ebp+0xc) 1/r32/ecx
     (lookup *(ecx+0x14) *(ecx+0x18))  # Regvardef-outputs Regvardef-outputs => eax
@@ -15449,11 +15446,8 @@ $emit-cleanup-code-until-depth:check-for-previous-spill:
           3d/compare-eax-and 0/imm32/false
           74/jump-if-= break/disp8
 $emit-cleanup-code-until-depth:reclaim-var-in-register:
-          (emit-indent *(ebp+8) *Curr-block-depth)
-          (write-buffered *(ebp+8) "8f 0/subop/pop %")
           (lookup *(ebx+0x18) *(ebx+0x1c))  # Var-register Var-register => eax
-          (write-buffered *(ebp+8) %eax)
-          (write-buffered *(ebp+8) Newline)
+          (emit-pop-register *(ebp+8) %eax)
         }
         eb/jump $emit-cleanup-code-until-depth:continue/disp8
       }
@@ -15488,6 +15482,36 @@ $emit-cleanup-code-until-depth:end:
     5d/pop-to-ebp
     c3/return
 
+emit-push-register:  # out: (addr buffered-file), reg: (addr array byte)
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    #
+    (emit-indent *(ebp+8) *Curr-block-depth)
+    (write-buffered *(ebp+8) "ff 6/subop/push %")
+    (write-buffered *(ebp+8) *(ebp+0xc))
+    (write-buffered *(ebp+8) Newline)
+$emit-push-register:end:
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return
+
+emit-pop-register:  # out: (addr buffered-file), reg: (addr array byte)
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    #
+    (emit-indent *(ebp+8) *Curr-block-depth)
+    (write-buffered *(ebp+8) "8f 0/subop/pop %")
+    (write-buffered *(ebp+8) *(ebp+0xc))
+    (write-buffered *(ebp+8) Newline)
+$emit-pop-register:end:
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return
+
 # emit clean-up code for 'vars' until a given label is encountered
 # doesn't actually modify 'vars' so we need traverse manually inside the stack
 emit-cleanup-code-until-target:  # out: (addr buffered-file), vars: (addr stack live-var), until-block-label: (addr array byte)