From b8798f26ee09c4b30ffe033bd657a7f4c99210e5 Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Mon, 5 Oct 2026 13:00:41 -0700 Subject: track the filename of an input buffer this also includes some slightly better facilities for handling temporary strings Change-Id: Idf5e6fd8ade675d7ceb73264d10895fe8da578d6 Force-Push: yes --- language/dynamic/files.e | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'language/dynamic/files.e') 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 @ ; + -- cgit 1.4.1