summary refs log tree commit diff
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@irenes.space>2026-05-15 03:27:51 -0700
committerIrene Knapp <ireneista@irenes.space>2026-05-15 03:27:51 -0700
commitefaa8eeb003c3a36af18bf606d0fe524177e5729 (patch)
tree3954c1ead0f4a42efaa43926f5845f418f978389
parent64d4667d9ffec1f3386400f03e3b781733acd9b3 (diff)
now there's a concept of pushing and popping input sources
Force-Push: yes
Change-Id: Ib8e8f342b7fa3773071eca36accf060f6c20f3be
-rw-r--r--execution.e2
-rw-r--r--quine.asm1
-rw-r--r--transform.e79
3 files changed, 74 insertions, 8 deletions
diff --git a/execution.e b/execution.e
index fb83688..9ddcec6 100644
--- a/execution.e
+++ b/execution.e
@@ -478,7 +478,7 @@
   ~ word-aligned, it's highly likely that it helps performance. (Whether it
   ~ does is up to Intel's microcode.)
   8 packalign
-  current-offset L' warm-start set-label
+  current-offset L!' warm-start
 
   ~   Before handing off to us, cold-start pushed a single value onto the
   ~ stack, a pointer to the beginning of the heap. Now, we load our entire
diff --git a/quine.asm b/quine.asm
index df771db..aa36dc4 100644
--- a/quine.asm
+++ b/quine.asm
@@ -6412,6 +6412,7 @@ cold_start:
   ; In:
   ;   pointer to string
   ;   pointer to buffer metadata
+  ; TODO are these backwards
   dq litstring, "attach-string-to-input-buffer", early_create
   dq early_docol_codeword
   dq litstring, "swap", early_find, entry_to_execution_token, early_comma
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