diff options
| -rw-r--r-- | transform.e | 45 |
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 ; |