summary refs log tree commit diff
path: root/transform.e
diff options
context:
space:
mode:
Diffstat (limited to 'transform.e')
-rw-r--r--transform.e119
1 files changed, 108 insertions, 11 deletions
diff --git a/transform.e b/transform.e
index e24e4b7..dd417a3 100644
--- a/transform.e
+++ b/transform.e
@@ -2729,10 +2729,12 @@ allocate-transformation-state s" transformation-state" variable
 : hex-output-metadata-entry-string 3 8 * + ;
 : hex-output-metadata-next-entry 4 8 * + ;
 : hex-output-metadata-entry-type-line-comment 0 ;
-: hex-output-metadata-entry-type-line-break 1 ;
-: hex-output-metadata-entry-type-indent 2 ;
-: hex-output-metadata-entry-type-string-literal 3 ;
-: hex-output-metadata-entry-type-alignment 4 ;
+: hex-output-metadata-entry-type-suffix-comment 1 ;
+: hex-output-metadata-entry-type-fresh-line 2 ;
+: hex-output-metadata-entry-type-blank-line 3 ;
+: hex-output-metadata-entry-type-indent 4 ;
+: hex-output-metadata-entry-type-string-literal 5 ;
+: hex-output-metadata-entry-type-alignment 6 ;
 
 ~   Initialize the contents of the output metadata to all zeroes. This is
 ~ called from hex-transform at its top level, at the very start, to make sure
@@ -2845,7 +2847,7 @@ allocate-transformation-state s" transformation-state" variable
   s" is comments! Enjoy. :)"
   pack-hex-output-metadata-entry
 
-  over 0 hex-output-metadata-entry-type-line-break 0
+  over 0 hex-output-metadata-entry-type-blank-line 0
   pack-hex-output-metadata-entry
 
   0 swap ! ~ End-of-entries delimiter
@@ -2960,6 +2962,45 @@ allocate-transformation-state s" transformation-state" variable
   transformation-state transformation-state-output-metadata @
   hex-output-metadata-indentation-depth ! ;
 
+: postprocess-metadata-entries
+  transformation-state transformation-state-output-metadata @
+  hex-output-metadata-first-entry
+  { dup @ } {
+    ~ (entry pointer)
+
+    dup hex-output-metadata-entry-type @
+    hex-output-metadata-entry-type-suffix-comment =
+    over hex-output-metadata-entry-data-length @ 0 != && {
+      ~ (entry pointer)
+      dup dup
+
+      { dup @ } { hex-output-metadata-next-entry } while 8 +
+      ~ (entry pointer, entry pointer, entry array end pointer)
+      swap -
+      ~ (entry pointer, entry array tail length)
+      swap dup dup hex-output-metadata-next-entry 4 roll
+      ~ (entry pointer, entry pointer, adjusted entry pointer,
+      ~  entry array tail length)
+      memmove
+      ~ (entry pointer)
+
+      dup hex-output-metadata-entry-type
+      hex-output-metadata-entry-type-fresh-line swap !
+
+      dup hex-output-metadata-entry-data-length 0 swap !
+
+      dup hex-output-metadata-next-entry
+      ~ (entry pointer, next entry pointer)
+
+      dup hex-output-metadata-entry-data-length @
+      over hex-output-metadata-entry-data-start @ +
+      over hex-output-metadata-entry-data-start !
+      hex-output-metadata-entry-data-length 0 swap !
+    } if
+
+    hex-output-metadata-next-entry
+  } while drop ;
+
 ~   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
@@ -2974,6 +3015,8 @@ allocate-transformation-state s" transformation-state" variable
 ~
 ~ (length to write, base address --)
 : hex-sys-write-replacement
+  postprocess-metadata-entries
+
   { over } {
     transformation-state transformation-state-output-metadata @
     hex-output-metadata-first-entry
@@ -2995,7 +3038,21 @@ allocate-transformation-state s" transformation-state" variable
         } if
 
         dup hex-output-metadata-entry-type @
-        hex-output-metadata-entry-type-line-break = {
+        hex-output-metadata-entry-type-suffix-comment = {
+          space
+          dup hex-output-metadata-entry-string @ ." ~ " emitstring newline
+
+          1 is-fresh-line!
+        } if
+
+        dup hex-output-metadata-entry-type @
+        hex-output-metadata-entry-type-fresh-line = {
+          fresh-line
+          1 is-fresh-line!
+        } if
+
+        dup hex-output-metadata-entry-type @
+        hex-output-metadata-entry-type-blank-line = {
           fresh-line
           newline
           1 is-fresh-line!
@@ -3730,12 +3787,45 @@ allocate-transformation-state s" transformation-state" variable
 : hex-tilde-replacement
   transformation-state transformation-state-output-metadata @
   hex-output-metadata-latest-output-point @
-  0
-  3roll
-  ~ (data start, data length, string pointer)
+  swap
+  ~ (data start, string pointer)
+
+  ~   Copy the first space-separated word of the comment body into scratch
+  ~ space to see if it's a special instruction. To minimize interference with
+  ~ the program under transformation, we use the outer log's scratch space
+  ~ rather than the inner one's.
+  swap-transform-variables
+  dup
+  here @
+  ~ (... source pointer, destination pointer)
+  { over 8@ dup 0x20 != && } {
+    swap unpack8 swap 3unroll pack8
+  } while
+  0 pack8 drop drop
+
+  here @
+  swap-transform-variables
+
+  ~ (data start, string pointer, first word string pointer)
+  dup read-integer 0 = {
+    ~ (data start, string pointer, first word string pointer, data length)
+    3unroll stringlen 1+ +
+  } {
+    drop 0 swap
+  } if-else
+  ~ (data start, data length, adjusted string pointer)
+
+  ~   The first word wasn't special, so proceed to look for whole-line special
+  ~ instructions.
+
+  dup s" fresh-line" stringcmp 0 = {
+    drop hex-output-metadata-entry-type-fresh-line 0
+    add-hex-output-metadata-entry
+    exit
+  } if
 
   dup s" blank-line" stringcmp 0 = {
-    drop hex-output-metadata-entry-type-line-break 0
+    drop hex-output-metadata-entry-type-blank-line 0
     add-hex-output-metadata-entry
     exit
   } if
@@ -3752,11 +3842,18 @@ allocate-transformation-state s" transformation-state" variable
     exit
   } if
 
+  ~ If a nonzero length is specified, treat it as a suffix comment.
+  over 0 != {
+    hex-output-metadata-entry-type-suffix-comment swap
+    add-hex-output-metadata-entry
+    exit
+  } if
+
+  ~ It's just an ordinary line comment.
   hex-output-metadata-entry-type-line-comment swap
   add-hex-output-metadata-entry ;
 
 
-
 ~   The tilde alternate is a very important word for the hex transform; it has
 ~ the task of implementing a special comment syntax which can be used by words
 ~ that generate binary output, to define comments which will appear as part of