about summary refs log tree commit diff
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@irenes.space>2026-09-16 01:27:39 -0700
committerIrene Knapp <ireneista@irenes.space>2026-09-16 01:27:39 -0700
commitdec2aaeedfa52d4d45db14c4a2ee09ebb8e9f537 (patch)
treedf7c6a7e40e98bb7473bc020f72b8fcbf5a4507d
parente1f5c4e72830cc9ce900e1884d3338f1c82060fd (diff)
fix the overwritten strings in the output
this probably shouldn't have required copying them, but ah well, copying worked

Force-Push: yes
Change-Id: I239f2633c61867f6c42a5b76a0e978aff0875a9d
-rw-r--r--transform.e46
1 files changed, 19 insertions, 27 deletions
diff --git a/transform.e b/transform.e
index 6d12ea1..17d1396 100644
--- a/transform.e
+++ b/transform.e
@@ -4247,7 +4247,7 @@ allocate-transformation-state s" transformation-state" variable
     3unroll 1+ swap 1- swap 3roll
   } while drop ;
 
-~ (data start, data length)
+~ (data start, data length --)
 : hex-pack-trace
   ~   We keep a running tally of the next address in the output, for the
   ~ benefit of hex-tilde-replacement, which needs to know where to attach its
@@ -4258,6 +4258,22 @@ allocate-transformation-state s" transformation-state" variable
     hex-output-metadata-latest-output-point !
   } { drop } if-else ;
 
+~ (output point, string pointer --)
+: hex-packstring-trace
+  dup stringlen 1+
+  ~ (output point, string pointer, string length)
+  2 pick over hex-pack-trace
+  swap
+  ~ (output point, string length, string pointer)
+  swap-transform-variables here @ swap-transform-variables
+  ~ (output point, string length, string pointer, temporary space pointer)
+  2 pick memcopy
+  ~ (output point, string length)
+  swap-transform-variables here @ allocate-string swap-transform-variables
+  ~ (output point, string length, moved string pointer)
+  hex-output-metadata-entry-type-string-literal swap
+  add-hex-output-metadata-entry ;
+
 ~   By overriding colon, we can special-case the definitions of particular
 ~ words. It's very metacircular.
 ~
@@ -4451,32 +4467,8 @@ allocate-transformation-state s" transformation-state" variable
 
     ~ (output point, string pointer)
     s" 2dup" find entry-to-execution-token ,
-    s" dup" find entry-to-execution-token ,
-    s" stringlen" find entry-to-execution-token ,
-    s" 1+" find entry-to-execution-token ,
-    ~ (output point, string pointer, string length including terminator)
-
-    ~   Before we add the metadata entry, we also want to call hex-pack-trace
-    ~ to make sure latest-output-point gets adjusted for the string.
-    ~ Otherwise, we'd see magic comments in the wrong place.
-    s" 3roll" find entry-to-execution-token ,
-    s" dup" find entry-to-execution-token ,
-    s" lit" find entry-to-execution-token ,
-    4 ,
-    s" unroll" find entry-to-execution-token ,
-    s" swap" find entry-to-execution-token ,
-    s" dup" find entry-to-execution-token ,
-    s" 3unroll" find entry-to-execution-token ,
-    ~ (output point, string pointer, string length including terminator,
-    ~  output point, string length including terminator)
-    ' hex-pack-trace entry-to-execution-token ,
-
-    ~ (output point, string pointer, string length including terminator)
-    s" swap" find entry-to-execution-token ,
-    ' hex-output-metadata-entry-type-string-literal entry-to-execution-token ,
-    s" swap" find entry-to-execution-token ,
-    ' add-hex-output-metadata-entry entry-to-execution-token ,
-    ~ (output point, string pointer)
+    ~ This one's a lot of work, so we defer to a single-purpose word.
+    ' hex-packstring-trace entry-to-execution-token ,
     ~ Fall through to the inner implementation.
 
     ' ] entry-to-execution-token execute