summary refs log tree commit diff
path: root/transform.e
diff options
context:
space:
mode:
Diffstat (limited to 'transform.e')
-rw-r--r--transform.e79
1 files changed, 72 insertions, 7 deletions
diff --git a/transform.e b/transform.e
index 2470145..83eea8a 100644
--- a/transform.e
+++ b/transform.e
@@ -39,6 +39,40 @@
           { ~ If not, leave the word start alone.
             3roll pack8 } if-else } if-else } forever ;
 
+~   In logical terms, this modifies an input buffer metadata structure
+~ in-place to push a new, zeroed one into the start of the linked list formed
+~ through the next-source field.
+~
+~   In physical terms, it works by allocating a new structure, copying the
+~ fields of the existing one into it, and zeroing the existing one. That's
+~ necessary because otherwise we'd need a mutable handle (a pointer to a
+~ pointer) to update the start of the list, and there's no way to do that with
+~ the main-input-buffer variable working the way it presently does.
+~
+~ (input buffer metadata pointer --)
+: push-input-buffer
+  allocate-input-buffer-metadata
+  ~ (original metadata pointer, new metadata pointer)
+  2dup swap 6 8 * memcopy
+  ~ (original metadata pointer, new metadata pointer)
+  swap dup zero-input-buffer-metadata
+  input-buffer-next-source !
+  ;
+
+~   This does the inverse of push-input-buffer. In the event that the
+~ next-source field is null, it zeroes the buffer.
+~
+~   Note, however, that it doesn't deallocate the memory, because that's not
+~ how memory allocation on the log works. If necessary, it can be deallocated
+~ with "forget", though as usual that requires careful planning.
+~
+~ (input buffer metadata pointer --)
+: pop-input-buffer
+  dup input-buffer-next-source @
+  ~ (original metadata pointer, next source metadata pointer)
+  dup { 6 8 * memcopy }
+      { drop zero-input-buffer-metadata } if-else ;
+
 : L:
   ' L' entry-to-execution-token execute
   { ' set-label entry-to-execution-token , }
@@ -141,23 +175,54 @@
 
   swap ;
 
-1024 read-to-buffer
-foo bar baz biff
-pyrzqxgl
-stackhex dup hexdump emitstring bye
+
+
+~ ." input " main-input-buffer dup .hex64 newline dup hexdump @ dup .hex64 newline bye
+~ 1024 read-to-buffer
+~ foo bar baz biff
+~ pyrzqxgl
+~ stackhex dup hexdump emitstring bye
+~ 
+~ : breakza
+~   ." original" newline
+~   main-input-buffer dup 6 8 * hexdump-from
+~   dup push-input-buffer
+~   ." updated original" newline
+~   dup 6 8 * hexdump-from
+~   ." copy" newline
+~   dup input-buffer-next-source @ 6 8 * hexdump-from
+~   newline
+~   stackhex
+~   dup pop-input-buffer
+~   ." copied back" newline
+~   6 8 * hexdump-from
+~   stackhex
+~   bye ;
 
 ~ (output point -- output point)
-: transform { transform-one { exit } if } forever ;
+: transform
+  1024 read-to-buffer ." transformation input buffer" newline dup hexdump
+  ~ (output point, string pointer)
+
+  main-input-buffer dup push-input-buffer
+  ~ TODO the arguments for this seem to be backwards from the documentation
+  swap attach-string-to-input-buffer
+
+  { transform-one
+    { main-input-buffer pop-input-buffer
+      exit } if } forever ;
 
 1024 allocate dup
+." compilation output buffer" newline dup hexdump
 transform
 : za ." ZA" 12 13 - . ;
 : ' word value@ find dropstring-with-result
   interpreter-flags @ 1 & { literal } if ; make-immediate
 ~ ' za . newline
 pyrzqxgl
-." stack after " stackhex
-2dup swap hexdump-between
+." back back back " here @ .hex64 newline
+~ ." stack after " stackhex
+~ 2dup swap hexdump-between
 ~ : piz ." PIZ" ' za . newline ; piz
 bye