Re: Fleet Forth design considerations
Posted: Wed Mar 20, 2019 8:48 pm
I'm still working on getting multitasking and vectored I/O playing nice together. One of my test tasks is a clock that displays the time in the top right corner of the screen and I don't want the time to be printed when I am listing something or logging a session. I had thought about user deferred words but really didn't like the idea much (the user area for each task would increase.)
I'm thinking of trying something like this:
CIO is a value that holds the CFA of the current I/O redirection word. Each of the three I/O redirection words in Fleet Forth stores the address of it's own CFA in CIO. If a background task has to temporarily redirect I/O, it could do something like this:
If a background task is setup for running one shot routines as needed and is normally asleep until activated, it could run a word with something like this:
I'm thinking of trying something like this:
Code: Select all
' NOOP VALUE CIO // CURRENT I/O
SCR# 32
// CONSOLE PRINTER
: CONSOLE ( -- )
[ LATEST NAME> ] LITERAL IS CIO
#LP CLOSE CLRCHN
['] (EMIT) IS EMIT
['] (TYPE) IS TYPE
['] (QTYPE) IS QTYPE
['] (EXPECT) IS EXPECT ;
: PRINTER ( -- )
[ LATEST NAME> ] LITERAL IS CIO
#LP CLOSE
0 0 #LP DUP #LP2 (OPEN) IOERR
['] (PEMIT) IS EMIT
['] (PTYPE) IS TYPE
['] (PQTYPE) IS QTYPE
['] (EXPECT) IS EXPECT ;
SCR# 33
// LOGGER
: LOGGER ( -- )
PRINTER
[ LATEST NAME> ] LITERAL IS CIO
['] (LEMIT) IS EMIT
['] (LTYPE) IS TYPE
['] (LQTYPE) IS QTYPE
['] (LEXPECT) IS EXPECT ;
CONSOLE
Code: Select all
... SINGLE CIO
<REDIRECT I/O AND DO SOMETHING>
EXECUTE MULTI PAUSE ...
Code: Select all
... SINGLE CIO
<REDIRECT I/O AND DO SOMETHING>
EXECUTE MULTI STOP ;