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/dynamic.e | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'language/dynamic/dynamic.e') diff --git a/language/dynamic/dynamic.e b/language/dynamic/dynamic.e index 270e860..677a180 100644 --- a/language/dynamic/dynamic.e +++ b/language/dynamic/dynamic.e @@ -361,6 +361,29 @@ dup dup stringlen 1+ + 8 packalign here ! ; +~ Tests whether a string pointer is equal to the current value of "here". +~ If it is, the string is in the temporary allocation space. +~ +~ This is not a comprehensive test; there are other ways the string could be +~ temporary, such as being part of a larger data structure which is temporary, +~ or being a substring of a longer string, without itself being right at the +~ start of the scratch space. However, the most common way to wind up with a +~ temporary string is by using the string-literal syntax in immediate mode, +~ and a string allocated that way will always pass this test. +~ +~ (string pointer -- boolean) +: is-temporary-string here @ = ; + +~ Calls allocate-string if and only if the string it's given passes +~ is-temporary-string. This function is idempotent, since the string will no +~ longer be at "here" after allocating it, so it's safe to call on a parameter +~ you've received that you don't know where it came from. +~ +~ (string pointer -- string pointer) +: allocate-string-if-temporary + dup is-temporary-string { allocate-string } if ; + + ~ Allocate space by incrementing "here", and output a word entry header in ~ it. Also add it to the "latest" linked list. Use zero as the flag values; ~ accept a string pointer on the stack and use its contents as the name. @@ -558,3 +581,10 @@ ~ (value -- ) : literal lit lit , , ; +~ We also have the same thing but for string literals. This one is a bit +~ more involved, and less often needed, but it saves trouble when it does come +~ up. +~ +~ (string pointer --) +: literal-string lit litstring , here @ swap packstring 8 packalign here ! ; + -- cgit 1.4.1