commit 2270d5ebe03e413d5eb19995694035f897d339cc parent 53054204ba87660ece62fa68f21653e5053055aa Author: Virgil Dupras <hsoft@hardcoded.net> Date: Sat, 4 Jun 2022 15:04:04 -0400 Allow recursive f<< calls Diffstat:
M | boot.fs | | | 12 | +++++++----- |
A | fs/cc/cc.fs | | | 9 | +++++++++ |
M | tests/testcc.fs | | | 10 | +--------- |
3 files changed, 17 insertions(+), 14 deletions(-)
diff --git a/boot.fs b/boot.fs @@ -60,12 +60,14 @@ create _ $100 allot create _ 1 allot : fread ( fd -- c-or-0 ) 3 ( read ) swap _ 1 lnxcall 1 = if _ c@ else 0 then ; -0 value curfd -: >fd ( fd -- ) to curfd ; -: fd@ ( -- fd ) curfd ; -: fd~ ( -- ) fd@ ?dup if fclose 0 to curfd then ; +create _fds $20 allot0 \ 8 levels max +_fds value 'curfd +: >fd ( fd -- ) 'curfd 4 + tuck ! to 'curfd ; +: fd@ ( -- fd ) 'curfd @ ; +: fd~ ( -- ) fd@ fclose 'curfd 4 - to 'curfd ; : f< ( -- c-or-0 ) fd@ fread ; -: fin< f< ?dup not if ['] iin< to in< SPC then ; +: fin< f< ?dup not if ( EOF ) + fd~ fd@ not if ['] iin< to in< then SPC then ; : f<< word fopen >fd ['] fin< to in< ; 64 value LNSZ diff --git a/fs/cc/cc.fs b/fs/cc/cc.fs @@ -0,0 +1,9 @@ +f<< str.fs +f<< wordtbl.fs +f<< asm.fs +f<< cc/tok.fs +f<< cc/tree.fs +f<< cc/gen.fs +f<< cc/ops.fs +f<< cc/ast.fs +f<< cc/cc1.fs diff --git a/tests/testcc.fs b/tests/testcc.fs @@ -1,13 +1,5 @@ \ Tests for the C compiler -f<< str.fs -f<< wordtbl.fs -f<< asm.fs -f<< cc/tok.fs -f<< cc/tree.fs -f<< cc/gen.fs -f<< cc/ops.fs -f<< cc/ast.fs -f<< cc/cc1.fs +f<< cc/cc.fs : opentestc S" test.c" fopen >fd ; opentestc ' f< to cc<