commit 5c062d154cbed8c0623679d58a020cce270fda51
parent b3ce4a8da5d95243b805e161159815eab497719e
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Tue, 19 Jul 2022 16:28:41 -0400
More I/O restructuring
Diffstat:
3 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/fs/fs/fatlo.fs b/fs/fs/fatlo.fs
@@ -154,10 +154,10 @@ here const )fnbuf
\ Xb current cluster X=ClusterSize
10 const FCURSORCNT \ maximum number of opened files
: FCursorSize ClusterSize 36 + ;
-: FCUR_flags ( fcur -- n ) @ ;
+: FCUR_flags ( fcur -- n ) 12 + @ ;
: FCUR_free? ( fcur -- f ) FCUR_flags not ;
: FCUR_dirty? ( fcur -- f ) FCUR_flags 2 and ;
-: FCUR_flags! ( n fcur -- ) ! ;
+: FCUR_flags! ( n fcur -- ) 12 + ! ;
: FCUR_cluster ( fcur -- n ) 16 + @ ;
: FCUR_cluster! ( n fcur -- ) 16 + ! ;
: FCUR_clusteridx ( fcur -- n ) 20 + @ ;
diff --git a/fs/sys/file.fs b/fs/sys/file.fs
@@ -7,6 +7,7 @@
\ our cursors.
$200 scratchpad$ filespad
+: fgetc ( fcursor -- c ) 1 swap freadbuf if c@ else -1 ( EOF ) then ;
\ This creates a "f<" reader with the file descriptor embedded in it. This
\ allows for a straightforward override of input/output words.
: [f<] ( curfd -- word )
diff --git a/fs/xcomp/boothi.fs b/fs/xcomp/boothi.fs
@@ -1,14 +1,15 @@
bootfile xcomp/boothi.fs
-0 value curfd \ file descriptor of the file currently being read
+0 value curhdl \ handle of the file currently being read
0 value fecho
-: fgetc ( fcursor -- c ) 1 swap freadbuf if c@ else -1 ( EOF ) then ;
-: f< ( -- c ) curfd fgetc fecho if dup emit then ;
+: f< ( -- c )
+ 1 curhdl dup @ ( 'freadbuf ) execute if c@ else -1 ( EOF ) then
+ fecho if dup emit then ;
: fload ( fname -- )
- floaded, curfd >r
- floaded 4 + fopen to curfd
+ floaded, curhdl >r
+ floaded 4 + fopen to curhdl
to' in< @ >r ['] f< to in<
begin maybeword ?dup if runword 0 else 1 then until
- r> to in< curfd fclose r> to curfd ;
+ r> to in< curhdl fclose r> to curhdl ;
: f<< word fload ;
\ TODO: record absolute paths or some kind of unique ID here. "lib/str.fs" and
\ "/lib/str.fs" are considered different.