summary refs log tree commit diff
path: root/input.e
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@irenes.space>2026-05-22 00:29:03 -0700
committerIrene Knapp <ireneista@irenes.space>2026-05-22 00:29:03 -0700
commited702c3b88953112a3682c818a6e801549e1b461 (patch)
treef53e5e9c1ac40250552ba0f9cb6e627cd8caeb9e /input.e
parent5ae0fdad3c7df2fc02acfc3b8f36d96c5d07bcd4 (diff)
it runs!!!!!! it interactively reads input and everything
only some of that actually works, but hey, it's a start

Force-Push: yes
Change-Id: Ib82beb695be1a18de8aaaf3040b7c632851c6002
Diffstat (limited to 'input.e')
-rw-r--r--input.e31
1 files changed, 22 insertions, 9 deletions
diff --git a/input.e b/input.e
index c7a1c02..8203673 100644
--- a/input.e
+++ b/input.e
@@ -178,8 +178,7 @@
 ~   If the buffer is empty, make sure its logical position is at the
 ~ physical start. Otherwise, leave it alone.
 ~
-~ In:
-~   pointer to buffer metadata
+~ (metadata pointer --)
 : normalize-buffer
   dup buffer-logical-length @ 0 =
   { dup buffer-physical-start @ swap
@@ -195,18 +194,32 @@
 ~   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
+~ (metadata pointer -- 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)
+  ~ (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, physical end, logical end not yet wrapped)
+
+  2dup >= {
+    ~    If the logical end is greater than or equal to the physical end, find
+    ~  where it wraps to and start from there.
+    swap - swap dup buffer-physical-start @ swap 3unroll +
+    ~  (metadata pointer, destination start)
+    ~    In this scenario, the logical start is the end of the free space, so
+    ~  compute how far away it is.
+    dup 3roll
+    ~  (destination start, destination start, metadata pointer)
+    buffer-logical-start @ swap -
+  } {
+    3roll drop
+    dup 3roll swap -
+    ~    If the logical end is less than the physical end, it is the destination;
+    ~  the physical end is also the end of the free space, so compute how far
+    ~  away it is.
+  } if-else ;
 
 
 ~ (metadata pointer --)