about summary refs log tree commit diff
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@irenes.space>2026-09-22 03:07:23 -0700
committerIrene Knapp <ireneista@irenes.space>2026-09-22 03:07:23 -0700
commita569f93740bbbac3230434ee56bc51aa38be21ac (patch)
treeae7bd7a2165ddb6c8d7ff433f9eeb3252f23007d
parent70361dab75dd03c17df24a807859135fc423e766 (diff)
add a file descriptor field to the input buffer metadata struct
and use it where appropriate

Force-Push: yes
Change-Id: I68c478460780a6ea6ac8d1cc437981e2899ef122
-rw-r--r--input.e27
-rw-r--r--interpret.e3
2 files changed, 18 insertions, 12 deletions
diff --git a/input.e b/input.e
index 9abbcb6..a9e73cb 100644
--- a/input.e
+++ b/input.e
@@ -13,11 +13,13 @@
 : buffer-logical-start 2 8 * + ;
 ~ (pointer to buffer metadata -- pointer to buffer "logical-length" field)
 : buffer-logical-length 3 8 * + ;
+~ (pointer to buffer metadata -- pointer to buffer "file-descriptor" field)
+: buffer-file-descriptor 4 8 * + ;
 ~ (pointer to input buffer metadata -- pointer to input buffer "refill" field)
-: input-buffer-refill 4 8 * + ;
+: input-buffer-refill 5 8 * + ;
 ~ (pointer to input buffer metadata
 ~  -- pointer to input buffer "next-source" field)
-: input-buffer-next-source 5 8 * + ;
+: input-buffer-next-source 6 8 * + ;
 
 
 ~   Given an initialized buffer (input or otherwise), sets its logical-start
@@ -35,9 +37,9 @@
   buffer-logical-length 0 swap ! ;
 
 
-~   Sets all fields in an input buffer metadata structure to zero,
-~ effectively detaching and leaking any backing store that had been attached
-~ to it. Suitable for use during initialization.
+~   Sets all fields in an input buffer metadata structure to their default
+~ values, mostly zero, effectively detaching and leaking any backing store
+~ that had been attached to it. Suitable for use during initialization.
 ~
 ~ (pointer to input buffer metadata --)
 : zero-input-buffer-metadata
@@ -45,6 +47,7 @@
   dup buffer-physical-length 0 swap !
   dup buffer-logical-start 0 swap !
   dup buffer-logical-length 0 swap !
+  dup buffer-file-descriptor -1 swap !
   dup input-buffer-refill 0 swap !
   ~ Notice the absence of a dup this time.
   input-buffer-next-source 0 swap ! ;
@@ -55,7 +58,7 @@
 ~
 ~ (-- pointer to input buffer metadata)
 : allocate-input-buffer-metadata
-  6 8 * allocate
+  7 8 * allocate
   dup zero-input-buffer-metadata ;
 
 
@@ -64,10 +67,10 @@
 ~
 ~ (buffer capacity in bytes -- pointer to input buffer metadata)
 : allocate-input-buffer
-  dup 6 8 * + allocate
+  dup 7 8 * + allocate
   dup zero-input-buffer-metadata
   ~ (capacity in bytes, metadata pointer)
-  dup dup 6 8 * +
+  dup dup 7 8 * +
   ~ (capacity in bytes, metadata pointer, metadata pointer, physical start)
   swap buffer-physical-start !
   ~ (capacity in bytes, metadata pointer)
@@ -91,7 +94,9 @@
   ~ (string length, metadata pointer)
   2dup buffer-physical-length !
   ~ (string length, metadata pointer)
-  buffer-logical-length ! ;
+  dup 3unroll buffer-logical-length !
+  ~ (metadata pointer)
+  -1 swap buffer-file-descriptor ! ;
 
 
 ~ (metadata pointer --)
@@ -223,7 +228,7 @@
 
 
 ~ (metadata pointer --)
-: refill-input-buffer-from-stdin
+: refill-input-buffer-from-stream
   dup normalize-buffer
   dup compute-next-buffer-free-block
   ~ (metadata pointer, destination start, destination length)
@@ -231,7 +236,7 @@
   ~ an error, just clean up and take no action.
   dup { swap
         ~ (metadata pointer, destination length, destination start)
-        { 2dup 0 sys-read
+        { 3 ndup 3roll buffer-file-descriptor @ sys-read
           ~ (metadata pointer, destination length, destination start,
           ~  read result)
           dup 0 > {
diff --git a/interpret.e b/interpret.e
index 7d5d429..7f839ac 100644
--- a/interpret.e
+++ b/interpret.e
@@ -574,7 +574,8 @@ dup entry-flags@ 0x80 invert & swap entry-flags!
   main-input-buffer buffer-logical-start !
   1024 main-input-buffer buffer-physical-length !
   0 main-input-buffer buffer-logical-length !
-  [ s" refill-input-buffer-from-stdin"
+  0 main-input-buffer buffer-file-descriptor !
+  [ s" refill-input-buffer-from-stream"
     find entry-to-execution-token literal ]
   main-input-buffer input-buffer-refill !
   ;