diff options
| author | Irene Knapp <ireneista@irenes.space> | 2026-10-05 13:00:41 -0700 |
|---|---|---|
| committer | Irene Knapp <ireneista@irenes.space> | 2026-10-05 15:05:36 -0700 |
| commit | b8798f26ee09c4b30ffe033bd657a7f4c99210e5 (patch) | |
| tree | 4e937c8e9e5072c202bff4b5aa281f969cbe8fbb /language/dynamic/dynamic.e | |
| parent | a0ef3365458bdd8e99d0d4bb05c6de9f13527ad6 (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/dynamic.e')
| -rw-r--r-- | language/dynamic/dynamic.e | 30 |
1 files changed, 30 insertions, 0 deletions
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 ! ; + |