about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--transform.e77
1 files changed, 65 insertions, 12 deletions
diff --git a/transform.e b/transform.e
index b9b6cd8..4201d64 100644
--- a/transform.e
+++ b/transform.e
@@ -2724,7 +2724,11 @@ allocate-transformation-state s" transformation-state" variable
 : hex-output-metadata-is-fresh-line 4 8 * + ;
 : hex-output-metadata-indentation-depth 5 8 * + ;
 : hex-output-metadata-current-column 6 8 * + ;
-: hex-output-metadata-first-entry 7 8 * + ;
+: hex-output-metadata-substring-entry-stack-depth 7 8 * + ;
+: hex-output-metadata-substring-entry-stack-zero 8 8 * + ;
+: hex-output-metadata-substring-entry-stack-capacity 3 ;
+: hex-output-metadata-first-entry
+  8 hex-output-metadata-substring-entry-stack-capacity + 8 * + ;
 : hex-output-metadata-entry-data-start ;
 : hex-output-metadata-entry-data-length 8 + ;
 : hex-output-metadata-entry-type 2 8 * + ;
@@ -2755,6 +2759,7 @@ allocate-transformation-state s" transformation-state" variable
   dup hex-output-metadata-is-fresh-line 1 swap !
   dup hex-output-metadata-indentation-depth 0 swap !
   dup hex-output-metadata-current-column 0 swap !
+  dup hex-output-metadata-substring-entry-stack-depth 0 swap !
   dup hex-output-metadata-first-entry 0 swap ! ;
 
 ~ (pointer -- boolean)
@@ -3021,6 +3026,53 @@ allocate-transformation-state s" transformation-state" variable
 
 : advance-current-column current-column@ + current-column! ;
 
+: describe-substring-entry-stack
+  transformation-state transformation-state-output-metadata @
+  ."    depth "
+  dup hex-output-metadata-substring-entry-stack-depth @ .hex64 newline
+  ." capacity "
+  hex-output-metadata-substring-entry-stack-capacity .hex64 newline
+  hex-output-metadata-substring-entry-stack-zero
+  hex-output-metadata-substring-entry-stack-capacity 8 * hexdump-from ;
+
+: substring-entry-stack-depth@
+  transformation-state transformation-state-output-metadata @
+  hex-output-metadata-substring-entry-stack-depth @ ;
+
+: substring-entry-stack-depth!
+  transformation-state transformation-state-output-metadata @
+  hex-output-metadata-substring-entry-stack-depth ! ;
+
+: is-substring-entry-stack-empty
+  substring-entry-stack-depth@ 0 = ;
+
+: is-substring-entry-stack-full
+  substring-entry-stack-depth@
+  hex-output-metadata-substring-entry-stack-capacity = ;
+
+: push-substring-entry-stack
+  is-substring-entry-stack-full not {
+    transformation-state transformation-state-output-metadata @
+    hex-output-metadata-substring-entry-stack-zero
+    substring-entry-stack-depth@ 8 * + !
+
+    substring-entry-stack-depth@ 1+ substring-entry-stack-depth!
+  } {
+    drop
+    ." Substring entry stack overflow." newline
+  } if-else ;
+
+: pop-substring-entry-stack
+  is-substring-entry-stack-empty not {
+    substring-entry-stack-depth@ 1- substring-entry-stack-depth!
+
+    transformation-state transformation-state-output-metadata @
+    hex-output-metadata-substring-entry-stack-zero
+    substring-entry-stack-depth@ 8 * + @
+  } {
+    ." Substring entry stack underflow." newline
+  } if-else ;
+
 ~   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
@@ -3188,7 +3240,17 @@ allocate-transformation-state s" transformation-state" variable
       ~ (input point, first non-word character or 0, word pointer)
 
       dup s" #" stringcmp 0 = {
-        ." zazen" drop
+        drop
+
+        pop-substring-entry-stack
+
+        dup hex-output-metadata-entry-type @
+        hex-output-metadata-entry-type-provide-substring-hex64 = {
+          ." 0x"
+          dup hex-output-metadata-entry-string @ .hex64
+        } if
+
+        drop
       } {
         emitstring
       } if-else
@@ -3323,17 +3385,8 @@ allocate-transformation-state s" transformation-state" variable
 
         dup hex-output-metadata-entry-type @
         hex-output-metadata-entry-type-provide-substring-hex64 = {
-          fresh-line
-          indentation-depth@ dup indent advance-current-column
-
-          ." ~ hex64 value 0x"
-          dup hex-output-metadata-entry-string @ .hex64
-
-          newline
-          1 is-fresh-line!
-          0 current-column!
+          dup push-substring-entry-stack
         } if
-
       } if
       hex-output-metadata-next-entry
     } while