about summary refs log tree commit diff
path: root/transform.e
diff options
context:
space:
mode:
Diffstat (limited to 'transform.e')
-rw-r--r--transform.e34
1 files changed, 22 insertions, 12 deletions
diff --git a/transform.e b/transform.e
index 279ca72..0a5af3e 100644
--- a/transform.e
+++ b/transform.e
@@ -525,7 +525,7 @@ allocate-transformation-state s" transformation-state" variable
   ~ From linux.e.
   dup s" sys-exit" stringcmp 0 = { drop -1 exit } if
   dup s" sys-write" stringcmp 0 = { drop -2 exit } if
-  dup s" sys-read" stringcmp 0 = { drop -1 exit } if
+  dup s" sys-read" stringcmp 0 = { drop -2 exit } if
 
   ~ From output.e.
   dup s" emitstring" stringcmp 0 = { drop -1 exit } if
@@ -4479,15 +4479,20 @@ allocate-transformation-state s" transformation-state" variable
 ~ want to require that, so we keep all the formatting state in the output
 ~ metadata header.
 ~
-~ (length to write, base address --)
+~ (length to write, base address, file descriptor -- length written)
 : hex-sys-write-replacement
   ~   In intended operation, the code under transformation is a compilation
   ~ process, and it won't output anything that isn't executable binary.
   ~ However, while developing, it's common to have crashes, and it's nice to
   ~ get the crash dump as ASCII rather than hex.
-  dup is-in-label-loop-buffer not {
+  over is-in-label-loop-buffer not {
     sys-write exit
   } if
+  drop over 3unroll
+  ~   The result should be the length written. We just proactively declare
+  ~ that we'll write the full length we were asked to, threading that through
+  ~ as the result we'll eventually return.
+  ~ (result, length to write, base address)
 
   postprocess-metadata-entries
 
@@ -4498,9 +4503,10 @@ allocate-transformation-state s" transformation-state" variable
 
   transformation-state transformation-state-output-metadata @
   hex-output-metadata-first-entry
-  ~ (length to write, base address, initial metadata scan pointer)
+  ~ (result, length to write, base address, initial metadata scan pointer)
   { 2 pick 0 <= } {
-    ~ (length remaining, current output address, metadata scan pointer)
+    ~ (result, length remaining, current output address,
+    ~  metadata scan pointer)
 
     ~   Keep inspecting entries as long as the output address is greater than
     ~ or equal to the entry address. If we're looking at the entries that come
@@ -4508,8 +4514,8 @@ allocate-transformation-state s" transformation-state" variable
     ~ eventually catch up. Since the scan pointer is kept across iterations,
     ~ it's important we not go beyond that point.
     { dup @ dup
-      ~ (length remaining, current output address, metadata scan pointer,
-      ~  entry's first field, entry's first field)
+      ~ (result, length remaining, current output address,
+      ~  metadata scan pointer, entry's first field, entry's first field)
       {
         ~   This is an nop, but for clarity's sake it's best to not depend on
         ~ details of the structure layout that perhaps not everyone has
@@ -4521,15 +4527,17 @@ allocate-transformation-state s" transformation-state" variable
         hex-output-metadata-entry-data-start
 
         dup 3 pick
-        ~ (length remaining, current output address, metadata scan pointer,
-        ~  entry's data start, entry's data start, current output address)
+        ~ (result, length remaining, current output address,
+        ~  metadata scan pointer, entry's data start, entry's data start,
+        ~  current output address)
         >= swap drop
       } if
     } {
       dup @
       2 pick = {
         ~ We found a matching metadata entry.
-        ~ (length remaining, current output address, metadata scan pointer)
+        ~ (result, length remaining, current output address,
+        ~  metadata scan pointer)
 
         dup hex-output-metadata-entry-type @
         hex-output-metadata-entry-type-line-comment = {
@@ -4725,7 +4733,8 @@ allocate-transformation-state s" transformation-state" variable
       } if
       hex-output-metadata-next-entry
     } while
-    ~ (length remaining, current output address, metadata scan pointer)
+    ~ (result, length remaining, current output address,
+    ~  metadata scan pointer)
 
     2 pick {
       n-bytes-this-line@ 16 = {
@@ -4748,7 +4757,8 @@ allocate-transformation-state s" transformation-state" variable
       increment-bytes-this-line
       0 is-fresh-line!
     } if
-    ~ (length remaining, current output address, metadata scan pointer)
+    ~ (result, length remaining, current output address,
+    ~  metadata scan pointer)
 
     3unroll 1+ swap 1- swap 3roll
   } while drop ;