summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--core.e3
-rw-r--r--transform.e134
2 files changed, 117 insertions, 20 deletions
diff --git a/core.e b/core.e
index 38ffd95..1d7d7bb 100644
--- a/core.e
+++ b/core.e
@@ -86,6 +86,9 @@ here !
 
 ~   We can't use colon to create docol, not even the part that's a word,
 ~ because colon tries to dynamically invoke docol to fill in the codeword.
+~ : blank-line
+~ : This is the dictionary entry for docol.
+~ : indent
 s" docol" create
 self-codeword
 here @
diff --git a/transform.e b/transform.e
index ee4f113..2ee0489 100644
--- a/transform.e
+++ b/transform.e
@@ -902,11 +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
+  ~   While we could put magic comments here, and be guaranteed to catch every
+  ~ word-defining word under the label transform, there's a subtle thing where
+  ~ we need to make sure the "indent" command happens in the same places it
+  ~ does when the same code runs under the log-load transform, and only those
+  ~ places. So, we do it in the callers of "create" instead.
   dup stringlen 1 +
   ~ : provide-data
   dup 3unroll
@@ -946,7 +946,13 @@ allocate-transformation-state s" transformation-state" variable
 ~ attempting to understand label-colon-alternate.
 : label-colon-alternate
   ~ This calls label-create-alternate instead of "create".
-  word value@ label-create-alternate dropstring
+  word value@
+  ~ : blank-line
+  ~ : blank-line
+  ~ : provide-string-copy
+  ~ : # is defined here via the label transform; this is its entry header.
+  ~ : indent
+  label-create-alternate dropstring
 
   ~ This looks up "docol" by label.
   ~ : 8     (docol codeword)
@@ -1028,6 +1034,11 @@ allocate-transformation-state s" transformation-state" variable
 ~
 ~ If it existed, that word would be (string pointer --).
 : label-keyword-alternate
+  ~ : blank-line
+  ~ : blank-line
+  ~ : provide-string-copy
+  ~ : # is defined here via the label transform; this is its entry header.
+  ~ : indent
   label-create-alternate
 
   here @ dup
@@ -1854,8 +1865,13 @@ allocate-transformation-state s" transformation-state" variable
   ~ which is the same thing that would happen if we didn't have an alternate
   ~ at all.
   interpreter-flags @ 0x01 & {
+    ~   Notice that when we're in compile mode, we aren't actually defining a
+    ~ word at the time the log-load routine runs, so we don't have magic
+    ~ comments.
     s" create" log-load-compile-dynamic-word
   } {
+    ~ : blank-line
+    ~ : create
     log-load-roll-log-address
 
     swap-transform-variables
@@ -1872,6 +1888,7 @@ allocate-transformation-state s" transformation-state" variable
     -1 transform-apply-stack-delta
 
     log-load-unroll-log-address
+    ~ : blank-line
   } if-else ;
 
 
@@ -5861,8 +5878,50 @@ allocate-transformation-state s" transformation-state" variable
   ~ (body string pointer, result code)
 
   {
-    ~   It's a magic comment, which may or may not be empty. We want to either
-    ~ compile or execute a call to hex-tilde-replacement.
+    ~ It's a magic comment, which may or may not be empty.
+    interpreter-flags @ 0x01 & {
+      ~   We're in compile mode. We ignore magic comments in compile mode,
+      ~ because they shouldn't become part of the program being compiled.
+      drop
+    } {
+      ~ We're in interpret mode. We run the magic comment immediately.
+      has-non-space-this-input-line@ swap
+      swap-transform-variables allocate-string swap-transform-variables
+      hex-tilde-replacement
+    } if-else
+  } {
+    ~ If it's a regular comment, we just ignore it.
+    drop
+  } if-else
+
+  ~   Regardless of what path we took, we just consumed a newline, so make
+  ~ note of the fact.
+  0 has-non-space-this-input-line! ;
+
+
+~   This word runs whenever the log-load transform, running inside the hex
+~ transform, encounters a tilde. It completely replaces the normal invocation
+~ of tilde, just as hex-tilde-alternate does. It has the same responsibilities
+~ around magic comments as hex-tilde-alternate, but for code which is
+~ lexically processed by log-load-transform-one rather than by
+~ hex-transform-one.
+~
+~   The actions it takes upon finding various sorts of comments differ from
+~ hex-tilde-alternate, because the behavior of the log-load transform is
+~ different from the behavior of the hex transform.
+~
+~   This is installed by hex-log-load-word-replacement, bypassing the log-load
+~ transform's normal precedence rules, so there's no need for it to be
+~ immediate.
+~
+~   Installing this word is the most significant change the hex transform
+~ makes to the behavior of the log-load transform.
+: hex-log-load-tilde-alternate
+  hex-read-magic-comment-introducer
+  ~ (body string pointer, result code)
+
+  {
+    ~ It's a magic comment, which may or may not be empty.
     interpreter-flags @ 0x01 & {
       ~   We're in compile mode. We ignore magic comments in compile mode,
       ~ because they shouldn't become part of the program being compiled.
@@ -5883,12 +5942,12 @@ allocate-transformation-state s" transformation-state" variable
   0 has-non-space-this-input-line! ;
 
 
-~   This input helper is a very unusual thing: It's used by hex-transform-one
-~ and hex-label-word-replacement to skip the space between words. That's
-~ necessary because we need to keep track of whether we've had any non-blank
-~ stuff on each line yet, so that the tilde replacement can figure out certain
-~ cases where a magic comment needs to be a suffix comment rather than a line
-~ comment.
+~   This input helper is a very unusual thing: It's used by hex-transform-one,
+~ hex-label-word-replacement, and hex-log-load-word-replacement to skip the
+~ space between words. That's necessary because we need to keep track of
+~ whether we've had any non-blank stuff on each line yet, so that the tilde
+~ replacement can figure out certain cases where a magic comment needs to be a
+~ suffix comment rather than a line comment.
 : hex-skip-space
   { peek dup is-space }
   { consume
@@ -5944,6 +6003,33 @@ allocate-transformation-state s" transformation-state" variable
   drop ;
 
 
+~   This word is installed into log-load-transform-one by the
+~ hex-word-alternate, when the log-load transform runs inside the hex
+~ transform. It has the job of performing substantive changes to the log-load
+~ transform's behavior, as required by the hex transform.
+~
+~   The most important changes to the base language that this word makes are
+~ to call hex-log-load-tilde-alternate any time a tilde is encountered as a
+~ word, and to call hex-skip-space before reading a word.
+: hex-log-load-word-replacement
+  hex-skip-space
+  word
+
+  value@
+  dup s" ~" stringcmp 0 = {
+    ~ We won't be going back to log-load-transform-one; clear away its state.
+    drop dropstring
+
+    hex-log-load-tilde-alternate
+
+    ~   Return directly to log-load-transform, faking the "not done" return
+    ~ value from log-load-transform-one.
+    0
+    2 nexit
+  } if
+  drop ;
+
+
 ~   Just as hex-allocate-alternate has the job of installing
 ~ hex-allocate-replacement in only one single spot, so hex-word-alternate has
 ~ the job of installing hex-label-word-replacement. It gets installed when
@@ -5959,15 +6045,23 @@ allocate-transformation-state s" transformation-state" variable
 : hex-word-alternate
   interpreter-flags @ 0x01 & {
     ~ Compile mode.
-    latest @ entry-to-name dup s" label-transform-one" stringcmp 0 = {
-      ~ In label-transform-one.
+    latest @ entry-to-name
+
+    dup s" label-transform-one" stringcmp 0 = {
       drop
       ' hex-label-word-replacement entry-to-execution-token ,
-    } {
-      ~ Not in label-transform-one.
+      exit
+    } if
+
+    dup s" log-load-transform-one" stringcmp 0 = {
       drop
-      s" word" find entry-to-execution-token ,
-    } if-else
+      ' hex-log-load-word-replacement entry-to-execution-token ,
+       exit
+    } if
+
+    ~ Not in a word we install stuff into.
+    drop
+    s" word" find entry-to-execution-token ,
   } {
     ~ Immediate mode.
     s" word" find