summary refs log tree commit diff
path: root/transform.e
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@irenes.space>2026-09-13 02:11:54 -0700
committerIrene Knapp <ireneista@irenes.space>2026-09-13 02:11:54 -0700
commitee81c1c2aa94ff92496e9c3a840cb6e87bb61e6d (patch)
treebe77d482d47ba6cd192ca173ea02bb9c4a8a2cff /transform.e
parent4817f471aed592cb8e389edfe37df7247418304c (diff)
work on making the label transform pretty-print word entry headers
this involved instrumenting label-create-alternate and some other stuff

it also involved adding provide-string and provide-string-copy magic-comment commands

Force-Push: yes
Change-Id: I52f87decc02bf6f2516ee009f27c783a2c5bd715
Diffstat (limited to 'transform.e')
-rw-r--r--transform.e41
1 files changed, 36 insertions, 5 deletions
diff --git a/transform.e b/transform.e
index 30a744c..c53a40a 100644
--- a/transform.e
+++ b/transform.e
@@ -902,6 +902,11 @@ allocate-transformation-state s" transformation-state" variable
 ~ below. It is likely to be extremely useful to read and understand "create"
 ~ in dynamic.e before attempting to understand label-create-alternate.
 : label-create-alternate
+  ~ : blank-line
+  ~ : blank-line
+  ~ : provide-string-copy
+  ~ : # is defined here via the label transform; this is its entry header.
+  ~ : indent
   dup stringlen 1 + dup 3unroll
   here @ 10 + swap memmove
   here @
@@ -973,6 +978,7 @@ allocate-transformation-state s" transformation-state" variable
   L@' exit
   swap-transform-variables
   offset-to-target-address-space ,
+  ~ : deindent
 
   latest @ dup entry-flags@ 0x80 invert & swap entry-flags!
 
@@ -988,6 +994,8 @@ allocate-transformation-state s" transformation-state" variable
 ~ before attempting to understand label-semicolon-assembly-alternate.
 : label-semicolon-assembly-alternate
   here @ pack-next 8 packalign here !
+  ~ : deindent
+
   latest @ dup dup entry-flags@ 0x80 invert & swap entry-flags!
   entry-to-execution-token
   ~ The codeword needs to be transformed to the target address space.
@@ -1015,6 +1023,7 @@ allocate-transformation-state s" transformation-state" variable
   pack-next
   8 packalign
   here !
+  ~ : deindent
   ; make-immediate
 
 
@@ -2806,6 +2815,8 @@ allocate-transformation-state s" transformation-state" variable
 ~   ~ : provide-hex16
 ~   ~ : provide-hex32
 ~   ~ : provide-hex64
+~   ~ : provide-string
+~   ~ : provide-string-copy
 ~   ~ : provide-keyword
 ~   ~ : drop-subitem
 ~   ~ : swap-subitems
@@ -3143,11 +3154,15 @@ allocate-transformation-state s" transformation-state" variable
 ~   The provide-* commands are deeper than that. They peek at the top item on
 ~ the stack OF THE COMPILER, the code being transformed. The -decimal and
 ~ -hex* variants create a corresponding -entry-type-push-subitem- metadata
-~ entry of the matching type, and copy the numeric value into it. The -keyword
-~ variant expects to find a keyword (a word which, when executed, pushes its
-~ own execution token onto the stack); the command extracts the name of the
-~ keyword from the dictionary entry header, and saves a pointer to the name in
-~ a push-subitem-string metadata entry.
+~ entry of the matching type, and copy the numeric value into it.
+~
+~   The -string variant expects to find a pointer to a null-terminated string;
+~ -string-copy does too, but copies the contents of it to a safe place
+~ immediately, on the assumption they'll be overwritten. The -keyword variant
+~ expects to find a keyword (a word which, when executed, pushes its own
+~ execution token onto the stack); the command extracts the name of the
+~ keyword from the dictionary entry header. All three of these save pointer to
+~ their respective strings in a push-subitem-string metadata entry.
 ~
 ~   Admit it, you thought writing out "metadata entry" so many times instead
 ~ of just "entry" was silly because there was no other kind of entry in
@@ -5049,6 +5064,22 @@ allocate-transformation-state s" transformation-state" variable
     add-hex-output-metadata-entry
     exit
   } if
+  dup s" provide-string" stringcmp 0 = {
+    drop drop
+    2 pick hex-output-metadata-entry-type-push-subitem-string swap
+    add-hex-output-metadata-entry
+    exit
+  } if
+  dup s" provide-string-copy" stringcmp 0 = {
+    drop drop
+    2 pick hex-output-metadata-entry-type-push-subitem-string swap
+    swap-transform-variables here @ swap-transform-variables dup 3unroll
+    ~ (copy, original, copy)
+    over stringlen 1+ memcopy
+    swap-transform-variables allocate-string swap-transform-variables
+    add-hex-output-metadata-entry
+    exit
+  } if
   dup s" provide-keyword" stringcmp 0 = {
     ~ Create a new "push subitem string" entry given a keyword pointer.
     drop drop