summary refs log tree commit diff
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@irenes.space>2026-09-11 00:04:06 -0700
committerIrene Knapp <ireneista@irenes.space>2026-09-11 00:04:06 -0700
commit8ebb8540f19896f5553b8384f5c7790d91486302 (patch)
tree165da63e690d88ffe5e741a4a76065e8823bf65e
parent1b5ddcbadd1eaa0375da61a0eed0b810b239a4b4 (diff)
refactor the metadata postprocessing a little for readability
there's about to be a semantic change, but that will happen in a separate CL

Force-Push: yes
Change-Id: Ib32d542c02a640a964fdeed7bc16248b669d6a91
-rw-r--r--transform.e110
1 files changed, 64 insertions, 46 deletions
diff --git a/transform.e b/transform.e
index b466b58..52fa24f 100644
--- a/transform.e
+++ b/transform.e
@@ -3272,6 +3272,12 @@ allocate-transformation-state s" transformation-state" variable
   dup hex-output-metadata-entry-type-push-subitem-hex64 = 3roll || swap
   hex-output-metadata-entry-type-push-subitem-string = || ;
 
+: is-subitem-stack-manipulation-entry
+  hex-output-metadata-entry-type @
+  dup hex-output-metadata-entry-type-drop-subitem = swap
+  dup hex-output-metadata-entry-type-swap-subitems = 3roll || swap
+  hex-output-metadata-entry-type-roll-subitems = || ;
+
 : is-fresh-line@
   transformation-state transformation-state-output-metadata @
   hex-output-metadata-is-fresh-line @ ;
@@ -3616,6 +3622,59 @@ allocate-transformation-state s" transformation-state" variable
 
   s" swap" find entry-to-execution-token , ;
 
+~   This is a helper used by postprocess-metadata-entries, below. It
+~ duplicates the entry it's given, creating a second identical copy
+~ immediately after it in the entry array, sliding everything else forward to
+~ make room.
+~
+~ (entry pointer --)
+: dup-metadata-entry
+  ~   Find all the remaining entries, and the final terminator, and slide
+  ~ them forward by the length of one entry.
+  dup dup
+  ~ (entry pointer, entry pointer, entry pointer)
+
+  { 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 hex-output-metadata-next-entry 3roll
+  ~ (entry pointer, adjusted entry pointer, entry array tail length)
+  memmove ;
+
+~   This is a helper used by postprocess-metadata-entries, below. It swaps
+~ the contents of the entry it's given with the contents of the entry
+~ immediately after it in the entry array.
+~
+~ (entry pointer --)
+: swap-metadata-entries
+  ~ Copy the current entry to a scratch area.
+  dup dup dup hex-output-metadata-next-entry swap -
+  ~ (entry pointer, entry pointer, entry length)
+  swap-transform-variables here @ swap-transform-variables swap
+  ~ (entry pointer, entry pointer, scratch pointer, entry length)
+  memcopy
+  ~ (entry pointer)
+
+  ~ Copy the next entry over the current entry.
+  dup dup hex-output-metadata-next-entry dup
+  ~ (entry pointer, entry pointer, next entry pointer, next entry pointer)
+  3roll -
+  ~ (entry pointer, next entry pointer, entry length)
+  2 pick swap
+  ~ (entry pointer, next entry pointer, entry pointer, entry length)
+  memcopy
+  ~ (entry pointer)
+
+  ~ Copy the scratch area over the next entry.
+  dup hex-output-metadata-next-entry dup
+  ~ (entry pointer, next entry pointer, next entry pointer)
+  3roll -
+  ~ (next entry pointer, entry length)
+  swap-transform-variables here @ swap-transform-variables 3unroll
+  ~ (scratch pointer, next entry pointer, entry length)
+  memcopy ;
+
 ~   Metadata entries are post-processed before they're output, in order to
 ~ make the structure of the output code simpler. The post-processing won't
 ~ happen until output actually occurs, which is important for operations that
@@ -3641,17 +3700,7 @@ allocate-transformation-state s" transformation-state" variable
         ~ formatting.
         ~ (did anything, entry pointer)
 
-        ~   Find all the remaining entries, and the final terminator, and slide
-        ~ them forward by the length of one entry.
-        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
+        dup dup-metadata-entry
         ~ (..., entry pointer)
 
         ~   We have a feature which lets a suffix comment be created with a
@@ -3694,6 +3743,7 @@ allocate-transformation-state s" transformation-state" variable
         ~ (did anything, entry pointer)
         swap drop 1 swap
       } if
+      ~ (did anything, entry pointer)
 
       ~   Do this entry and the next entry both exist, and they're out of
       ~ order based on their data starts?
@@ -3704,38 +3754,8 @@ allocate-transformation-state s" transformation-state" variable
       {
         ~   Swap the order of the two entries. Since this whole thing is in a
         ~ loop, this functions as a bubble sort.
-        ~ (did anything, entry pointer)
-
-        ~ Copy the current entry to a scratch area.
-        dup dup dup hex-output-metadata-next-entry swap -
-        ~ (..., entry pointer, entry pointer, entry length)
-        swap-transform-variables here @ swap-transform-variables swap
-        ~ (..., entry pointer, entry pointer, scratch pointer, entry length)
-        memcopy
-        ~ (..., entry pointer)
-
-        ~ Copy the next entry over the current entry.
-        dup dup hex-output-metadata-next-entry dup
-        ~ (..., entry pointer, entry pointer, next entry pointer,
-        ~  next entry pointer)
-        3roll -
-        ~ (..., entry pointer, next entry pointer, entry length)
-        2 pick swap
-        ~ (..., entry pointer,
-        ~  next entry pointer, entry pointer, entry length)
-        memcopy
-        ~ (entry pointer)
-
-        ~ Copy the scratch area over the next entry.
-        dup hex-output-metadata-next-entry dup
-        ~ (..., entry pointer, next entry pointer, next entry pointer)
-        2 pick -
-        ~ (..., entry pointer, next entry pointer, entry length)
-        swap-transform-variables here @ swap-transform-variables 3unroll
-        ~ (..., entry pointer,
-        ~  scratch pointer, next entry pointer, entry length)
-        memcopy
-        ~ (..., entry pointer)
+        dup swap-metadata-entries
+        swap drop 1 swap
 
         ~   This rule won't fire again on the same pair of entries because now
         ~ they're in the correct order. It may fire again next iteration,
@@ -3744,10 +3764,8 @@ allocate-transformation-state s" transformation-state" variable
         ~   This rule does nothing to alter whether the suffix-comment rule
         ~ will fire on either of the entries it swapped, so there's no
         ~ possibility of an infinite loop through that one.
-
-        ~ (did anything, entry pointer)
-        swap drop 1 swap
       } if
+      ~ (did anything, entry pointer)
 
       hex-output-metadata-next-entry
     } while drop