duskos

dusk os fork
git clone git://git.alexwennerberg.com/duskos
Log | Files | Refs | README | LICENSE

commit 53054204ba87660ece62fa68f21653e5053055aa
parent d6d0a04dad4b8891b84ac4dd60259746aef03fba
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Sat,  4 Jun 2022 14:37:15 -0400

Decouple raw lnxcalls in boot from their "curfd" counterparts

I'm trying to allow recursive file load, but it's tricky to do it right...

Diffstat:
Mboot.fs | 15+++++++++------
Mtests/testcc.fs | 3++-
2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/boot.fs b/boot.fs @@ -53,17 +53,20 @@ current to (psufl) \ transform a fstring into a null-terminated string. create _ $100 allot : tocstr ( sa sl -- a ) >r _ r@ move 0 _ r> + c! _ ; -0 value curfd : fclose ( fd -- ) 6 ( close ) swap 0 0 ( close fd 0 0 ) lnxcall drop ; -: fopen ( sa sl -- ) - curfd ?dup if fclose 0 to curfd then +: fopen ( sa sl -- fd ) tocstr 5 ( open ) swap 0 0 ( open cstr noflag O_RDONLY ) lnxcall - dup 0< if S" Can't open" stype abort then to curfd ; + dup 0< if S" Can't open" stype abort then ; create _ 1 allot : fread ( fd -- c-or-0 ) 3 ( read ) swap _ 1 lnxcall 1 = if _ c@ else 0 then ; -: f< ( -- c-or-0 ) curfd fread ; + +0 value curfd +: >fd ( fd -- ) to curfd ; +: fd@ ( -- fd ) curfd ; +: fd~ ( -- ) fd@ ?dup if fclose 0 to curfd then ; +: f< ( -- c-or-0 ) fd@ fread ; : fin< f< ?dup not if ['] iin< to in< SPC then ; -: f<< word fopen ['] fin< to in< ; +: f<< word fopen >fd ['] fin< to in< ; 64 value LNSZ create in( LNSZ allot diff --git a/tests/testcc.fs b/tests/testcc.fs @@ -8,10 +8,11 @@ f<< cc/gen.fs f<< cc/ops.fs f<< cc/ast.fs f<< cc/cc1.fs -: opentestc S" test.c" fopen ; +: opentestc S" test.c" fopen >fd ; opentestc ' f< to cc< cc1, +fd~ retconst 42 #eq neg -42 #eq bwnot $ffffffd5 #eq