From f74440d8090e6b15abe47f71b169058e7b151447 Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Wed, 9 Sep 2026 00:02:32 -0700 Subject: provide a #swap operation in comment templates and use it in a couple places in amd64.e where it's needed Change-Id: Id73dcd13f08c03aa02ac09e45ab034fcd90f2569 Force-Push: yes --- transform.e | 47 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 7 deletions(-) (limited to 'transform.e') diff --git a/transform.e b/transform.e index 2227f2a..9816726 100644 --- a/transform.e +++ b/transform.e @@ -2778,6 +2778,7 @@ allocate-transformation-state s" transformation-state" variable ~ ~ : 1 suppress ~ ~ ~ : Do a thing with # and # ? +~ ~ : Do a different #swap # thing to # now. ~ ~ : provide-decimal ~ ~ : provide-hex8 ~ ~ : provide-hex16 @@ -3127,6 +3128,14 @@ allocate-transformation-state s" transformation-state" variable ~ comment entry pops it off the substring entry stack and pretty-prints the ~ value it holds. ~ +~ One more thing: The order in which provide-* commands execute will most +~ likely match the order in which the corresponding bytes are output. This may +~ not always match the order in which the comment template wants to +~ pretty-print them. Therefore, anywhere you can use # you can also use #swap +~ to manipulate the substring-entry stack. The #swap command must be its own +~ separate space-delimited word within a comment body; the space immediately +~ following it is stripped from the output. +~ ~ It's probably clear from the extreme emphasis this documentation has taken ~ on describing the order things happen in, but it is quite common to define ~ a suffix comment at the start of an assembly-instruction word; adjust its @@ -3699,6 +3708,7 @@ allocate-transformation-state s" transformation-state" variable ~ (input point, first non-word character or 0, word pointer) dup s" #" stringcmp 0 = { + ~ (input point, first non-word character or 0, word pointer) drop pop-substring-entry-stack @@ -3737,20 +3747,43 @@ allocate-transformation-state s" transformation-state" variable dup hex-output-metadata-entry-string @ emitstring } if - drop + ~ Tidy up. We want to treat the next character normally, so we + ~ return a zero to indicate that. + drop 0 } { - emitstring + dup s" #swap" stringcmp 0 = { + ~ (input point, first non-word character or 0, word pointer) + drop + + pop-substring-entry-stack + pop-substring-entry-stack + swap + push-substring-entry-stack + push-substring-entry-stack + + ~ We want to ignore the next character, so that this word can be + ~ used without creating spurious spaces in the output. + 1 + } { + ~ (input point, first non-word character or 0, word pointer) + + ~ Here as well, we want to treat the next character normally, so + ~ we return zero. + emitstring 0 + } if-else } if-else - ~ (input point, first non-word character or 0) + ~ (input point, first non-word character or 0, should ignore space) - dup { + over { ~ 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 + ~ a word, so we can output it... unless we were asked to skip it, + ~ of course. + not { value@ emitstring } if + 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- + drop drop 1- } if-else ~ (input point) } if-else -- cgit 1.4.1