diff options
| author | Irene Knapp <ireneista@irenes.space> | 2026-05-21 23:38:32 -0700 |
|---|---|---|
| committer | Irene Knapp <ireneista@irenes.space> | 2026-05-21 23:38:32 -0700 |
| commit | 5ae0fdad3c7df2fc02acfc3b8f36d96c5d07bcd4 (patch) | |
| tree | d3ef7a92ca411be57de91c27ad1881e976cd0d9e /input.e | |
| parent | ff9b791acf12688caec27e8ca883f3eefac8891d (diff) | |
the interpreter fully compiles now
doesn't work quite yet. close :) Force-Push: yes Change-Id: I71b6e788790fe2ca8e07dae95e9ad6e39d0664c0
Diffstat (limited to 'input.e')
| -rw-r--r-- | input.e | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/input.e b/input.e index 5cf2aeb..c7a1c02 100644 --- a/input.e +++ b/input.e @@ -166,7 +166,7 @@ buffer-logical-start @ 8@ ; -~ (metadata pointer) +~ (metadata pointer -- byte or 0) : key-from dup peek-from ~ (metadata pointer, result byte) @@ -175,6 +175,54 @@ swap consume-from ; +~ If the buffer is empty, make sure its logical position is at the +~ physical start. Otherwise, leave it alone. +~ +~ In: +~ pointer to buffer metadata +: normalize-buffer + dup buffer-logical-length @ 0 = + { dup buffer-physical-start @ swap + buffer-logical-start ! } { drop } if-else + ; + + +~ Find the next contiguous area of a buffer to write incoming data to. +~ This will begin at the logical end. Depending on the order things are in, +~ the available space might run from there to the physical end, or to the +~ logical start. Those are the only two possibilities. +~ +~ If the buffer is full, this will return as normal but the length will +~ be zero. The caller should make sure to respect that. +~ +~ In: +~ pointer to buffer metadata +~ Out: +~ destination start +~ destination length +: compute-next-buffer-free-block + dup buffer-physical-start @ swap dup buffer-physical-length @ + swap 3unroll + swap +~ (physical end, metadata pointer) + dup buffer-logical-start @ swap dup buffer-logical-length @ + swap 3unroll + swap 3unroll +~ (metadata pointer, physical end, logical end not yet wrapped) + + +~ (metadata pointer --) +: refill-input-buffer-from-stdin + dup normalize-buffer + dup compute-next-buffer-free-block + ~ Check whether the buffer is full. If not, do a read. If so, that's not + ~ an error, just clean up and take no action. + dup { swap sys-read + dup -2 = + { drop drop s" Read error." emitstring 0 sys-exit } + { swap dup buffer-logical-length @ 3roll + + swap buffer-logical-length ! } if-else } + { drop drop } if-else ; + + ~ Here we have some imperative code that runs immediately, to initialize ~ some runtime data structures. |