about summary refs log tree commit diff stats
path: root/subx/055trace.subx
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2018-10-10 21:37:57 -0700
committerKartik Agaram <vc@akkartik.com>2018-10-10 21:37:57 -0700
commit7c39778633d5b89c84c18ff6fc509dde3b3facf5 (patch)
treee5dd2580e7d4f4cc028f7eca9cc7b0a6c7f9b03a /subx/055trace.subx
parenta0467aa2021d5b62b5d824b6119291bc73c4f16b (diff)
downloadmu-7c39778633d5b89c84c18ff6fc509dde3b3facf5.tar.gz
4681
Diffstat (limited to 'subx/055trace.subx')
-rw-r--r--subx/055trace.subx34
1 files changed, 33 insertions, 1 deletions
diff --git a/subx/055trace.subx b/subx/055trace.subx
index b29d0f36..b2bb72c0 100644
--- a/subx/055trace.subx
+++ b/subx/055trace.subx
@@ -115,6 +115,9 @@ trace:  # t : (address trace-stream), line : string
   8b/copy                         0/mod/indirect  0/rm32/EAX    .           .             .           2/r32/EDX   .               .                 # copy *EAX to EDX
   # ESI = line.length
   8b/copy                         0/mod/indirect  3/rm32/EBX    .           .             .           6/r32/ESI   .               .                 # copy *EBX to ESI
+  # if ESI == 0 return
+  81          7/subop/compare     3/mod/direct    6/rm32/ESI    .           .             .           .           .               0/imm32           # compare ESI
+  74/jump-if-equal  $trace:end/disp8
   # t.write += line.length
   01/add                          0/mod/indirect  0/rm32/EAX    .           .             .           6/r32/ESI   .               .                 # add ESI to *EAX
   # t.write++ (for the newline we'll append below)
@@ -142,7 +145,6 @@ $trace:loop:
   eb/jump  $trace:loop/disp8
 $trace:break:
   # finally, append a newline
-  # todo: don't append a newline if 'line' is empty
     # if EAX >= ECX return
   39/compare                      3/mod/direct    0/rm32/EAX    .           .             .           1/r32/ECX   .               .                 # compare EAX with ECX
   7d/jump-if-greater-or-equal  $trace:end/disp8
@@ -267,4 +269,34 @@ test-trace-appends:
   # done
   c3/return
 
+test-trace-empty-line:
+  # clear-trace-stream(Test-trace-stream)
+    # push args
+  68/push  Test-trace-stream/imm32
+    # call
+  e8/call  clear-trace-stream/disp32
+    # discard args
+  81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               4/imm32           # add to ESP
+  # trace(Test-trace-stream, "")
+    # push args
+  68/push  ""/imm32
+  68/push  Test-trace-stream/imm32
+    # call
+  e8/call  trace/disp32
+    # discard args
+  81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
+  # check-ints-equal(*Test-trace-stream.data, 0, msg)
+    # push args
+  68/push  "F - test-trace-empty-line"/imm32
+  68/push  0/imm32
+    # push *Test-trace-stream.data
+  b8/copy-to-EAX  Test-trace-stream/imm32
+  ff          6/subop/push        1/mod/*+disp8   0/rm32/EAX    .           .             .           .           0xc/disp8       .                 # push *(EAX+12)
+    # call
+  e8/call  check-ints-equal/disp32
+    # discard args
+  81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0xc/imm32         # add to ESP
+  # done
+  c3/return
+
 # vim:nowrap:textwidth=0