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.e28
1 files changed, 27 insertions, 1 deletions
diff --git a/transform.e b/transform.e
index eb8e8bf..3086968 100644
--- a/transform.e
+++ b/transform.e
@@ -2720,7 +2720,8 @@ allocate-transformation-state s" transformation-state" variable
 : hex-output-metadata-label-loop-buffer-start ;
 : hex-output-metadata-label-loop-buffer-length 8 + ;
 : hex-output-metadata-latest-output-point 2 8 * + ;
-: hex-output-metadata-first-entry 3 8 * + ;
+: hex-output-metadata-is-fresh-line 3 8 * + ;
+: hex-output-metadata-first-entry 4 8 * + ;
 : hex-output-metadata-entry-data-start ;
 : hex-output-metadata-entry-data-length 8 + ;
 : hex-output-metadata-entry-type 2 8 * + ;
@@ -2742,6 +2743,7 @@ allocate-transformation-state s" transformation-state" variable
   dup hex-output-metadata-label-loop-buffer-start 0 swap !
   dup hex-output-metadata-label-loop-buffer-length 0 swap !
   dup hex-output-metadata-latest-output-point 0 swap !
+  dup hex-output-metadata-is-fresh-line 1 swap !
   dup hex-output-metadata-first-entry 0 swap ! ;
 
 ~ (pointer -- boolean)
@@ -2937,11 +2939,28 @@ allocate-transformation-state s" transformation-state" variable
 
   s" swap" find entry-to-execution-token , ;
 
+: is-fresh-line@
+  transformation-state transformation-state-output-metadata @
+  hex-output-metadata-is-fresh-line @ ;
+
+: is-fresh-line!
+  transformation-state transformation-state-output-metadata @
+  hex-output-metadata-is-fresh-line ! ;
+
+: fresh-line is-fresh-line@ not { newline } if ;
+
 ~   This "replacement" is a little different from an alternate: When the code
 ~ under transformation attempts to compile its own version of sys-write, it
 ~ gets a stub that calls this word instead. It's swapped out by
 ~ hex-colon-alternate, whereas the regular alternates are swapped out by
 ~ hex-transform-one.
+~
+~   In the programs we're actually running the transform on, there's only ever
+~ a single call to sys-write which is the whole binary in one go, but we don't
+~ want to require that, so we keep all the formatting state in the output
+~ metadata. In particular, hex-output-metadata-entry-is-fresh-line is kept
+~ there.
+~
 ~ (length to write, base address --)
 : hex-sys-write-replacement
   { over } {
@@ -2956,12 +2975,15 @@ allocate-transformation-state s" transformation-state" variable
 
         dup hex-output-metadata-entry-type @
         hex-output-metadata-entry-type-line-comment = {
+          fresh-line
           dup hex-output-metadata-entry-string @ ." ~ " emitstring newline
+          1 is-fresh-line!
         } if
 
         dup hex-output-metadata-entry-type @
         hex-output-metadata-entry-type-line-break = {
           newline
+          1 is-fresh-line!
         } if
 
         dup hex-output-metadata-entry-type @
@@ -2972,6 +2994,7 @@ allocate-transformation-state s" transformation-state" variable
           dup hex-output-metadata-entry-string @ emitstring
           0x22 value@ emitstring drop
           newline
+          1 is-fresh-line!
         } if
 
         dup hex-output-metadata-entry-type @
@@ -2980,6 +3003,7 @@ allocate-transformation-state s" transformation-state" variable
           ." ~ Alignment padding to width "
           dup hex-output-metadata-entry-string @ .
           newline
+          1 is-fresh-line!
         } if
 
       } if
@@ -2988,6 +3012,8 @@ allocate-transformation-state s" transformation-state" variable
     drop
 
     dup 8@ .hex8 space
+    0 is-fresh-line!
+
     1+ swap 1- swap
   } while ;