summary refs log tree commit diff
path: root/transform.e
diff options
context:
space:
mode:
Diffstat (limited to 'transform.e')
-rw-r--r--transform.e68
1 files changed, 56 insertions, 12 deletions
diff --git a/transform.e b/transform.e
index e69545e..30a744c 100644
--- a/transform.e
+++ b/transform.e
@@ -1460,6 +1460,27 @@ allocate-transformation-state s" transformation-state" variable
 ~ (output buffer start, output point, input string pointer, delimiter pointer
 ~  -- output buffer start, output point)
 : label-transform
+  ~ : blank-line
+  ~ : blank-line
+  ~ :   This is the start of a long block of code which has been processed by
+  ~ : the label transform, meaning it consists of ready-to-run Forth word
+  ~ : definitions that reference each other by address, suitable for direct
+  ~ : execution as soon as the cold-start routine has set up the basic
+  ~ : registers, flags, and memory areas that form Evocation's internal ABI.
+  ~ :
+  ~ :   Each word definition consists of a dictionary entry header, a
+  ~ : codeword, and a word body. For words implemented as Forth code, the
+  ~ : codeword points to the "docol" routine, and the word body is an array of
+  ~ : pointers to the codewords of other words, occasionally interspersed with
+  ~ : literal values. For words implemented as machine code, the codeword
+  ~ : points to the start of the body, and the body is the machine code.
+  ~ :
+  ~ :   All the word entry headers in this code link to each other, from last
+  ~ : backwards to first, forming an Evocation dictionary.
+  ~ :
+  ~ :   The warm-start routine relies on words defined by the label transform,
+  ~ : as does the log-load routine.
+
   main-input-buffer dup push-input-buffer
   3roll attach-string-to-input-buffer
 
@@ -3921,6 +3942,12 @@ allocate-transformation-state s" transformation-state" variable
     } if-else
   } while drop drop ;
 
+~ (string pointer --)
+: hex-emit-comment
+  ." ~"
+  dup @ { space } if
+  hex-emit-template-string ;
+
 ~   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
@@ -3959,8 +3986,7 @@ allocate-transformation-state s" transformation-state" variable
           fresh-line
           indentation-depth@ dup indent advance-current-column
 
-          ." ~ "
-          dup hex-output-metadata-entry-content @ hex-emit-template-string
+          dup hex-output-metadata-entry-content @ hex-emit-comment
           newline
 
           1 is-fresh-line!
@@ -3971,8 +3997,7 @@ allocate-transformation-state s" transformation-state" variable
         hex-output-metadata-entry-type-suffix-comment = {
           40 current-column@ - 1 max indent
 
-          ." ~ "
-          dup hex-output-metadata-entry-content @ hex-emit-template-string
+          dup hex-output-metadata-entry-content @ hex-emit-comment
           newline
 
           1 is-fresh-line!
@@ -5093,6 +5118,9 @@ allocate-transformation-state s" transformation-state" variable
   ~ for a total sequence of three bytes we need to match. We can't just skip
   ~ over the space with "consume", because it might also be a linefeed, which
   ~ would satisfy the exit criterion. We need to properly match it.
+  ~
+  ~   We also recognize a colon followed immediately by a linefeed, as
+  ~ denoting an empty comment.
   key dup dup 0x0a != && {
     ~ If we got here, the first byte was not 0 or 0x0a. Now we check if it's
     ~ colon.
@@ -5101,8 +5129,9 @@ allocate-transformation-state s" transformation-state" variable
       key dup dup 0x0a != && {
         0x3a = {
           ~ The second byte was 0x3a. Now check the third.
-          key dup dup 0x0a != && {
-            0x20 = {
+          key dup {
+            ~ The third byte is not 0.
+            dup 0x20 = {
               ~   The special test succeeded, so we want to insert a call to
               ~ hex-tilde-replacement. First, though, we must save the rest of
               ~ the comment body so we can provide it to the replacement at
@@ -5119,6 +5148,7 @@ allocate-transformation-state s" transformation-state" variable
               ~   Fortunately, we can pack the string directly into the output
               ~ buffer, so we don't need to mess around with
               ~ accumulate-string.
+              drop
               s" lit" find entry-to-execution-token ,
               has-non-space-this-input-line@ ,
               s" litstring" find entry-to-execution-token ,
@@ -5129,13 +5159,27 @@ allocate-transformation-state s" transformation-state" variable
               0 pack8
               8 packalign here !
               ' hex-tilde-replacement entry-to-execution-token ,
-
             } {
-              ~   The third byte was not 0, 0x0a, or 0x20. So our special
-              ~ test failed, but the exit condition isn't met. So we're done
-              ~ unrolling and can just do the original tilde loop for the
-              ~ rest.
-              key { dup dup 0x0a != && } { drop key } while drop
+              ~   The third byte is not 0 or 0x20.
+              0x0a = {
+                ~   The third byte is 0x0a. This is the alternate version of
+                ~ our special test, denoting a magic comment that happens to
+                ~ be empty. As with nonempty ones, we pack the string directly
+                ~ into the output buffer.
+                s" lit" find entry-to-execution-token ,
+                has-non-space-this-input-line@ ,
+                s" litstring" find entry-to-execution-token ,
+                here @
+                0 pack8
+                8 packalign here !
+                ' hex-tilde-replacement entry-to-execution-token ,
+              } {
+                ~   The third byte was not 0, 0x0a, or 0x20. So our special
+                ~ test failed, but the exit condition isn't met. So we're done
+                ~ unrolling and can just do the original tilde loop for the
+                ~ rest.
+                key { dup dup 0x0a != && } { drop key } while drop
+              } if-else
             } if-else
           } {
             ~ The exit condition is met, so we're done.