From 5851aca9a0da81c82ba26cd66f8d5b2b00dfd391 Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Tue, 8 Sep 2026 17:22:45 -0700 Subject: hex-transform comment output now goes through a lexer this will be used to substitute substrings, but that's not wired up yet Force-Push: yes Change-Id: I957ac153599b02ca8cdc46c7cb2ec487aa2af31c --- transform.e | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/transform.e b/transform.e index ea93ec3..b9b6cd8 100644 --- a/transform.e +++ b/transform.e @@ -3158,6 +3158,55 @@ allocate-transformation-state s" transformation-state" variable } while drop } while ; +~ (string pointer --) +: hex-emit-template-string + { unpack8 dup } { + dup is-space { + ~ Output space characters as we reach them, there's no need to do + ~ anything fancy. + value@ emitstring drop + } { + ~ (input point, first word character) + ~ We use the outer log's scratch space to accumulate each word in. + swap-transform-variables here @ swap-transform-variables + swap + pack8 + swap + ~ (scratch output point, input point) + + ~ Scan forward and find a space-separated word. + { unpack8 dup dup is-space not && } { + ~ (scratch output point, adjusted input point, next character) + 3roll swap pack8 swap + ~ (adjusted scratch output point, adjusted input point) + } while + ~ (scratch output point, input point, first non-word character or 0) + 3roll 0 pack8 drop + ~ (input point, first non-word character or 0) + + swap-transform-variables here @ swap-transform-variables + ~ (input point, first non-word character or 0, word pointer) + + dup s" #" stringcmp 0 = { + ." zazen" drop + } { + emitstring + } if-else + ~ (input point, first non-word character or 0) + + dup { + ~ If the character is non-zero, it's a space, so it can't be part of + ~ a word, so we can output it. + value@ emitstring drop + } { + ~ If this is the end of the string, we can discard the 0, but then + ~ we need to nudge the input point back so the loop will terminate. + drop 1- + } if-else + ~ (input point) + } if-else + } while drop 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 @@ -3188,7 +3237,9 @@ allocate-transformation-state s" transformation-state" variable fresh-line indentation-depth@ dup indent advance-current-column - dup hex-output-metadata-entry-string @ ." ~ " emitstring newline + ." ~ " + dup hex-output-metadata-entry-string @ hex-emit-template-string + newline 1 is-fresh-line! 0 current-column! @@ -3197,7 +3248,10 @@ allocate-transformation-state s" transformation-state" variable dup hex-output-metadata-entry-type @ hex-output-metadata-entry-type-suffix-comment = { 40 current-column@ - 1 max indent - dup hex-output-metadata-entry-string @ ." ~ " emitstring newline + + ." ~ " + dup hex-output-metadata-entry-string @ hex-emit-template-string + newline 1 is-fresh-line! 0 current-column! -- cgit 1.4.1