about summary refs log tree commit diff stats
path: root/apps/mu.subx
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2019-11-18 17:36:59 -0800
committerKartik Agaram <vc@akkartik.com>2019-11-18 17:36:59 -0800
commit49ffb0308470b03249452120c4945ccbb642a71b (patch)
tree519248f97ce99a546e61b059a677478876e0cf86 /apps/mu.subx
parentdd6c5fff9edaf95c2c3393fc76ea276e4939a7c6 (diff)
downloadmu-49ffb0308470b03249452120c4945ccbb642a71b.tar.gz
5756
Diffstat (limited to 'apps/mu.subx')
-rw-r--r--apps/mu.subx42
1 files changed, 30 insertions, 12 deletions
diff --git a/apps/mu.subx b/apps/mu.subx
index 9f4daec1..1612e9ce 100644
--- a/apps/mu.subx
+++ b/apps/mu.subx
@@ -1056,7 +1056,7 @@ emit-subx-rm32:  # out : (address buffered-file), l : arg-location, stmt : (addr
     74/jump-if-equal $emit-subx-rm32:end/disp8
     #
     (get-stmt-operand-from-arg-location *(ebp+0x10) *(ebp+0xc))  # stmt, l => var/eax
-    (emit-subx-call-operand *(ebp+8) %eax)  # out, var
+    (emit-subx-var-as-rm32 *(ebp+8) %eax)  # out, var
 $emit-subx-rm32:end:
     # . restore registers
     58/pop-to-eax
@@ -1218,11 +1218,37 @@ emit-subx-call-operand:  # out : (address buffered-file), operand : (address var
     50/push-eax
     # eax = operand
     8b/-> *(ebp+0xc) 0/r32/eax
+    # if non-literal, emit appropriately
+    (emit-subx-var-as-rm32 *(ebp+8) %eax)
+    # else if (operand->type == literal) emit "__"
+    {
+      81 7/subop/compare *(eax+4) 0/imm32  # Var-type
+      75/jump-if-not-equal break/disp8
+$emit-subx-call-operand:literal:
+      (write-buffered *(ebp+8) Space)
+      (write-buffered *(ebp+8) *eax)
+    }
+$emit-subx-call-operand:end:
+    # . restore registers
+    58/pop-to-eax
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return
+
+emit-subx-var-as-rm32:  # out : (address buffered-file), operand : (address variable)
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    # . save registers
+    50/push-eax
+    # eax = operand
+    8b/-> *(ebp+0xc) 0/r32/eax
     # if (operand->register) emit "%__"
     {
       81 7/subop/compare *(eax+0x10) 0/imm32  # Var-register
       74/jump-if-equal break/disp8
-$emit-subx-call-operand:register:
+$emit-subx-var-as-rm32:register:
       (write-buffered *(ebp+8) " %")
       (write-buffered *(ebp+8) *(eax+0x10))  # Var-register
     }
@@ -1230,22 +1256,14 @@ $emit-subx-call-operand:register:
     {
       81 7/subop/compare *(eax+0xc) 0/imm32  # Var-stack-offset
       74/jump-if-equal break/disp8
-$emit-subx-call-operand:stack:
+$emit-subx-var-as-rm32:stack:
       (write-buffered *(ebp+8) Space)
       (write-buffered *(ebp+8) "*(ebp+")
       8b/-> *(ebp+0xc) 0/r32/eax
       (print-int32-buffered *(ebp+8) *(eax+0xc))  # Var-stack-offset
       (write-buffered *(ebp+8) ")")
     }
-    # else if (operand->type == literal) emit "__"
-    {
-      81 7/subop/compare *(eax+4) 0/imm32  # Var-type
-      75/jump-if-not-equal break/disp8
-$emit-subx-call-operand:literal:
-      (write-buffered *(ebp+8) Space)
-      (write-buffered *(ebp+8) *eax)
-    }
-$emit-subx-call-operand:end:
+$emit-subx-var-as-rm32:end:
     # . restore registers
     58/pop-to-eax
     # . epilogue