summary refs log tree commit diff
path: root/transform.e
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@irenes.space>2026-05-13 02:26:31 -0700
committerIrene Knapp <ireneista@irenes.space>2026-05-13 02:26:31 -0700
commit31d2a4d52330bb72f282333531594b48e1589975 (patch)
tree8673a28f6aa84dd7dd76f5f7b5898e7c38a03c55 /transform.e
parentab0492a826cfce9a6454cb52f81bac48407f64d6 (diff)
copy input to a memory buffer
this will help us process it repeatedly so that label resolution works

Force-Push: yes
Change-Id: Ibef3b473259feb2e8d89acd5d1a40a21d5ecafe9
Diffstat (limited to 'transform.e')
-rw-r--r--transform.e45
1 files changed, 45 insertions, 0 deletions
diff --git a/transform.e b/transform.e
index d018ad9..2470145 100644
--- a/transform.e
+++ b/transform.e
@@ -1,3 +1,44 @@
+~ (buffer size -- buffer address)
+: read-to-buffer
+  dup allocate dup dup
+  ~ (buffer size, buffer address, word start, output point)
+  { key
+    ~ Exit if it's a zero byte.
+    dup not {
+      ~ Make sure to pack the zero to serve as a null terminator.
+      pack8
+      drop drop swap drop exit } if
+    dup is-space
+      { ~ (buffer size, buffer address, word start, output point, key)
+        ~ Tuck the key out of the way until we've done some stuff.
+        3unroll
+        ~ If it's a space character, first check if we just consumed the magic
+        ~ word...
+        2dup swap - 8 = dup {
+          drop
+          ~ Add a null terminator so we can use stringcmp
+          dup 0 swap !
+          ~ Check for the magic word
+          over s" pyrzqxgl" stringcmp 0 =
+          } if
+        { ~ It's magic, so exit.
+          ~ Make sure to pack a zero to serve as a null terminator.
+          0 pack8
+          drop drop drop swap drop exit }
+        { ~ It's not magic, so reset the word start. Of course whitespace is
+          ~ not a word but this will help us keep track of things.
+          3roll pack8
+          swap drop dup } if-else }
+      { ~ (buffer size, buffer address, word start, output point, key)
+        ~ Tuck the key out of the way again.
+        3unroll
+        ~ Check if the word just started and the previous character is space.
+        2dup = dup { drop dup @ is-space } if
+          { ~ If so, this is the actual first character of the word.
+            drop swap pack8 dup }
+          { ~ If not, leave the word start alone.
+            3roll pack8 } if-else } if-else } forever ;
+
 : L:
   ' L' entry-to-execution-token execute
   { ' set-label entry-to-execution-token , }
@@ -100,6 +141,10 @@
 
   swap ;
 
+1024 read-to-buffer
+foo bar baz biff
+pyrzqxgl
+stackhex dup hexdump emitstring bye
 
 ~ (output point -- output point)
 : transform { transform-one { exit } if } forever ;