diff options
| author | Irene Knapp <ireneista@irenes.space> | 2026-10-13 16:54:12 -0700 |
|---|---|---|
| committer | Irene Knapp <ireneista@irenes.space> | 2026-10-13 16:57:43 -0700 |
| commit | 20c6e495b354457031ffe7a60dc674b2a6a69fa1 (patch) | |
| tree | ea7a35ac51686ec4d80f8cd9bfdad848e3b70724 /language/dynamic/files.e | |
| parent | 49ae891e54f86ea43a4ccfb0e6223ff2a71cd5b2 (diff) | |
the overall file API is not yet stable, this is subject to change, but it felt like the time had come for this first step Force-Push: yes Change-Id: Idad271b975748b67b5bb9a82fe22337080447e97
Diffstat (limited to 'language/dynamic/files.e')
| -rw-r--r-- | language/dynamic/files.e | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/language/dynamic/files.e b/language/dynamic/files.e index 4822c2f..e0ef533 100644 --- a/language/dynamic/files.e +++ b/language/dynamic/files.e @@ -150,7 +150,7 @@ ~ (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; + ~ the file succeeded. We can't leave it any longer than this; ~ push-input-buffer will allocate memory, which will overwrite the scratch ~ space. swap allocate-string-if-temporary swap @@ -176,3 +176,32 @@ : current-input-file-name main-input-buffer buffer-filename @ ; + +: open-file-for-reading +~ (filename -- metadata pointer or 0) + dup 0 0 sys-open + dup 0 > { + ." Couldn't open " swap emitstring space + ." because " space . ." ." newline + drop 0 exit + } if + ~ (filename, file descriptor) + + ~ As with include, we deferred this allocation until after successful open. + swap allocate-string-if-temporary swap + + allocate-input-buffer-metadata dup zero-input-buffer-metadata + ~ (filename, file descriptor) + + dup 3unroll swap attach-input-buffer-to-file-descriptor ; + + +~ Note that this doesn't clear data that's already in the buffer. +~ +~ (metadata pointer --) +: close-file + dup buffer-file-descriptor @ sys-close drop + ~ Ignore a failed close. + + buffer-file-descriptor -1 swap ! ; + |