about summary refs log tree commit diff
path: root/language/dynamic/files.e
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@irenes.space>2026-10-05 13:00:41 -0700
committerIrene Knapp <ireneista@irenes.space>2026-10-05 15:05:36 -0700
commitb8798f26ee09c4b30ffe033bd657a7f4c99210e5 (patch)
tree4e937c8e9e5072c202bff4b5aa281f969cbe8fbb /language/dynamic/files.e
parenta0ef3365458bdd8e99d0d4bb05c6de9f13527ad6 (diff)
track the filename of an input buffer
this also includes some slightly better facilities for handling temporary strings

Change-Id: Idf5e6fd8ade675d7ceb73264d10895fe8da578d6
Force-Push: yes
Diffstat (limited to 'language/dynamic/files.e')
-rw-r--r--language/dynamic/files.e23
1 files changed, 18 insertions, 5 deletions
diff --git a/language/dynamic/files.e b/language/dynamic/files.e
index 21d4096..4822c2f 100644
--- a/language/dynamic/files.e
+++ b/language/dynamic/files.e
@@ -100,7 +100,7 @@
 : push-input-buffer
   allocate-input-buffer-metadata
   ~ (original metadata pointer, new metadata pointer)
-  2dup 7 8 * memcopy
+  2dup 8 8 * memcopy
   ~ (original metadata pointer, new metadata pointer)
   swap dup zero-input-buffer-metadata
   input-buffer-next-source ! ;
@@ -117,7 +117,7 @@
 : pop-input-buffer
   dup input-buffer-next-source @
   ~ (original metadata pointer, next source metadata pointer)
-  dup { swap 7 8 * memcopy }
+  dup { swap 8 8 * memcopy }
       { drop zero-input-buffer-metadata } if-else ;
 
 
@@ -147,14 +147,22 @@
     ." because " space . ." ." newline
     drop 1 exit
   } if
-  ~ (file descriptor)
+  ~ (filename, file descriptor)
+
+  ~   Notice that we deferred this allocation until after we know that opening
+  ~ the file succeeded. We can't leave it any longer thaan this;
+  ~ push-input-buffer will allocate memory, which will overwrite the scratch
+  ~ space.
+  swap allocate-string-if-temporary swap
 
   main-input-buffer dup push-input-buffer
   swap attach-input-buffer-to-file-descriptor
 
+  main-input-buffer buffer-filename !
+
   ~   We don't know what the code we're including will do to the stack, so we
-  ~ have to discard the last of our information before running it.
-  drop
+  ~ have make sure there's no information of our own on the stack before
+  ~ running it. At this point, that's the case.
 
   { peek -1 != } { interpret } while
 
@@ -163,3 +171,8 @@
 
   main-input-buffer pop-input-buffer 0 ;
 
+
+~ (-- filename pointer or 0)
+: current-input-file-name
+  main-input-buffer buffer-filename @ ;
+