duskos

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

commit 332594f0033b68025b06e9199fad13d4a655ede1
parent 0a256265b61b784975967a2b85637cb65b1bbecd
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Mon, 26 Jun 2023 16:43:39 -0400

sys/io: remove stdio structbind

It was a nice idea in theory, but in practice, it was clunky and I couldn't
think of a way to refactor it in a non-clunky way. The straightforward way of
passing IO handlers through PS ends up being more elegant and simple, all things
being considered.

Diffstat:
Mfs/ar/puff.c | 17+++++++++++------
Mfs/ar/ungz.fs | 28++++++++++++++--------------
Mfs/asm/uxntal.c | 6+++---
Mfs/asm/uxntal.fs | 4++--
Mfs/comp/c/cc.fs | 14++++++--------
Mfs/comp/c/egen.fs | 3++-
Mfs/comp/c/feed.fs | 8+++++---
Mfs/comp/c/lib.fs | 10+++-------
Mfs/comp/c/pp.fs | 2+-
Mfs/doc/cc/lib.txt | 9++++-----
Mfs/doc/deploy.txt | 2+-
Mfs/doc/emul/uxn.txt | 3++-
Mfs/doc/sys/file.txt | 6+++---
Mfs/doc/sys/io.txt | 23+----------------------
Mfs/drv/fbgrid/fbgrid.fs | 2+-
Mfs/emul/cos/cvm.fs | 2+-
Mfs/emul/cos/stage.fs | 4++--
Mfs/emul/cos/tools/blkpack.c | 16+++++++++-------
Mfs/emul/cos/tools/blkpack.fs | 7++++---
Mfs/emul/uxn/varvara.fs | 4++--
Mfs/lib/fmt.fs | 10+++++-----
Mfs/lib/str.fs | 2+-
Mfs/sys/file.fs | 4----
Mfs/sys/io.fs | 7-------
Mfs/tests/ar/ungz.fs | 7+++----
Mfs/tests/comp/c/tok.fs | 1+
Mfs/tests/comp/c/type.fs | 3++-
Mfs/tests/harness.fs | 2--
Mfs/tests/lib/fmt.fs | 2+-
Mfs/xcomp/arm/rpi/init.fs | 2+-
Mfs/xcomp/bootlo.fs | 1-
Mfs/xcomp/i386/pc/init.fs | 2+-
Mfs/xcomp/i386/pc/inittest.fs | 2+-
Mfs/xcomp/init.fs | 2+-
Mposix/init.fs | 2+-
35 files changed, 95 insertions(+), 124 deletions(-)

diff --git a/fs/ar/puff.c b/fs/ar/puff.c @@ -43,12 +43,15 @@ /* Output and buffering * The puff algorithm needs to access its previously outputted contents up to - * 32K back. For this reason, we can't spit directly to StdIO. Instead, what we + * 32K back. For this reason, we can't spit directly to outhdl. Instead, what we * do is we have a buffer of twice the required size (64K) and spit there. This * buffer is split in 2 pages. Whenever we hit the limit of one of the pages, we - * check if the other page is full. If yes, we spit it to StdIO and go on. + * check if the other page is full. If yes, we spit it to outhdl and go on. */ +static uint inhdl; +static uint outhdl; + /* input and output state */ struct state { unsigned char out[OUTBUFLEN]; /* output buffer */ @@ -67,13 +70,13 @@ static void spit(unsigned char c) { if ((s.outcnt>=OUTBUFLEN) && (!(s.outptr % (OUTBUFLEN/2)))) { // we finished a page and need to flush the "other" pageptr = s.outptr ^ (OUTBUFLEN/2); // ptr to "other" - fwrite(&s.out[pageptr], OUTBUFLEN/2, StdIO()); + fwrite(&s.out[pageptr], OUTBUFLEN/2, outhdl); } } static unsigned char getc() { int c; - c = stdin(); + c = fgetc(inhdl); if (c < 0) { fputs("out of input\n", Console()); abort(); @@ -670,12 +673,14 @@ static int dynamic() * block (if it was a fixed or dynamic block) are undefined and have no * expected values to check. */ -int puff() +int puff(uint in, uint out) { int last, type; /* block information */ int err; /* return value */ unsigned int pageptr; + inhdl = in; + outhdl = out; s.outptr = 0; s.outcnt = 0; s.bitbuf = 0; @@ -696,7 +701,7 @@ int puff() if (err <= 0) { pageptr = s.outptr & (OUTBUFLEN/2); if (s.outptr-pageptr) { - fwrite(&s.out[pageptr], s.outptr-pageptr, StdIO()); + fwrite(&s.out[pageptr], s.outptr-pageptr, outhdl); } } return err; diff --git a/fs/ar/ungz.fs b/fs/ar/ungz.fs @@ -5,20 +5,20 @@ cc<< /ar/puff.c : _err abort" ungz error" ; : _assert not if _err then ; -: _skiptonull begin stdin not until ; +: _skiptonull ( hdl -- ) begin dup IO :getc not until drop ; -\ Take a gzip file from stdin and spit the deflated version on stdout -: ungz ( -- err ) - stdin $1f = _assert stdin $8b = _assert \ ID1+ID2 - stdin 8 = _assert \ CM - stdin >r \ V1=FLG - here 6 stdio :read \ useless stuff - V1 $04 and if \ FLG.EXTRA - stdin stdin 8 lshift or ( xlen ) - here swap stdio :read \ read extra +\ Take a gzip file from inhdl (IO) and spit the deflated version on outhdl +: ungz ( inhdl outhdl -- err ) >r >r \ V1=out V2=in + V2 IO :getc $1f = _assert V2 IO :getc $8b = _assert \ ID1+ID2 + V2 IO :getc 8 = _assert \ CM + V2 IO :getc >r \ V3=FLG + here 6 V2 IO :read \ useless stuff + V3 $04 and if \ FLG.EXTRA + V2 IO :getc V2 IO :getc 8 lshift or ( xlen ) + here swap V2 IO :read \ read extra then - V1 $08 and if \ FLG.NAME - _skiptonull then + V3 $08 and if \ FLG.NAME + V2 _skiptonull then r> $10 and if \ FLG.COMMENT - _skiptonull then - puff ; + V2 _skiptonull then + r> r> puff ; diff --git a/fs/asm/uxntal.c b/fs/asm/uxntal.c @@ -468,7 +468,7 @@ review() } int -uxntal(int srchdl) +uxntal(uint in, uint out) { if (_arena == NULL) { _arena = arena_new(); @@ -478,11 +478,11 @@ uxntal(int srchdl) p.labels = NULL; p.macros = NULL; p.refs = NULL; - if(!assemble(srchdl)) + if(!assemble(in)) return !error("Assembly", "Failed to assemble rom."0); if(p.length <= TRIM) return !error("Assembly", "Output rom is empty."0); - fwrite(p.data + TRIM, p.length - TRIM, StdIO()); + fwrite(p.data + TRIM, p.length - TRIM, out); review(); return 0; } diff --git a/fs/asm/uxntal.fs b/fs/asm/uxntal.fs @@ -6,5 +6,5 @@ cc<< /asm/uxntal.c uxn_ram $10000 MemIO :new structbind MemIO _memio : tal>vm ( strpath -- res ) uxn_ram $100 + to _memio ptr - _memio :self to stdio writeio - curpath :find# Path :open dup uxntal stdio$ swap File :close ; + curpath :find# Path :open ( inhdl ) + dup _memio :self uxntal ( inhdl res ) swap File :close ; diff --git a/fs/comp/c/cc.fs b/fs/comp/c/cc.fs @@ -6,18 +6,16 @@ : _err ( -- ) abort" CC error" ; : _assert ( f -- ) not if _err then ; -\ Compiles input coming from the stdin alias and writes the -\ result to here. Aborts on error. -: cc1, ( -- ) - cctypes$ ccpp$ cctok$ begin ( ) nextt? ?dup while cparse repeat ; - -: :c cctok$ nextt cparse ; +: :c ccio$ cctok$ nextt cparse ; : calias - cctok$ ' nextt parseType _assert parseDeclarator ( w cdecl ) + ccio$ cctok$ ' nextt parseType _assert parseDeclarator ( w cdecl ) read; dup addSymbol to CDecl offset ; -: cc<< ( -- ) ['] cc1, word with-stdin-file ; +: cc<< ( -- ) + word curpath :find# Path :open to ccio + cctypes$ ccpp$ cctok$ begin ( ) nextt? ?dup while cparse repeat + ccio File :close ; :c typedef unsigned char uchar ; :c typedef unsigned short ushort ; diff --git a/fs/comp/c/egen.fs b/fs/comp/c/egen.fs @@ -200,7 +200,8 @@ MAXLITSZ Stack :new structbind Stack _list else ( tok ) parseExpression read) parsePostfixOp then endof '"' isChar? of MAXLITSZ _litarena :[ - here 0 c, ['] ," with-stdin< + here 0 c, + ['] ccin ['] in< realias ," ['] consolein ['] in< realias ccin dup '0' = if drop 1+ 0 c, \ null terminated else ccputback here over - 1- over c! then ( saddr ) diff --git a/fs/comp/c/feed.fs b/fs/comp/c/feed.fs @@ -1,16 +1,18 @@ \ C compiler feeding logic -\ We generally feed from "stdin", except when a macro is being processed. When +\ We generally feed from "ccio" except when a macro is being processed. When \ we're in that mode, we're feeding from the macro's range, until a NULL is \ encountered. This process is recursive. ?f<< /lib/stack.fs $10 Stack :new structbind Stack _feed +0 value ccio +: ccio$ console readio to ccio ; : ccin ( -- c ) _feed :count if _feed :peek' 8b @@+ ?dup not if _feed :pop drop ccin then - else stdin then ; + else ccio IO :getc then ; : ccin# ccin dup 0< if abort" unexpected EOF" then ; : ccputback ( c -- ) - _feed :count if _feed :peek' -1 over +! @ c! else stdio :putback then ; + _feed :count if _feed :peek' -1 over +! @ c! else ccio IO :putback then ; : ccpushmacro ( macro -- ) _feed :push ; diff --git a/fs/comp/c/lib.fs b/fs/comp/c/lib.fs @@ -17,12 +17,8 @@ :c void emit(char c); :c void stype(char *str); :c int zstrlen(char *zstr); -: _ stdio :self ; -calias _ int StdIO(); : _ console :self ; calias _ int Console(); -:c unsigned char stdin(); -:c void stdout(unsigned char c); :c int llend(int ll); :c void llappend(int elem, int ll); :c int llcnt(int ll); @@ -60,12 +56,12 @@ calias _ void memset(char *a, char c, unsigned int n); : fputs IO :puts ; :c void fputs(char *str, int hdl); -: puts ( str ) stdio :puts ; +: puts ( str ) console :puts ; :c void puts(char *str); : fprintf IO :printf ; :c void fprintf(char *fmt, int hdl); -: printf ( .. n1? n0? fmt -- ) stdio :printf ; +: printf ( .. n1? n0? fmt -- ) console :printf ; :c void printf(char *fmt); $100 MemFile :new const _sfile @@ -119,7 +115,7 @@ calias 0-9? int isdigit(char c); pspush(res); } -: scanf stdio :self fscanf ; +: scanf console :self fscanf ; :c int scanf(char* fmt); : sscanf 0 _sfile MemFile :seek c@+ _sfile IO :write diff --git a/fs/comp/c/pp.fs b/fs/comp/c/pp.fs @@ -4,7 +4,7 @@ \ #define creates a new macro, which simply copies the rest of the line in a \ buffer. Then, when the tokenizer hits an identifier, before sending it to the \ parser, it checks if a macro of the same name exists. If yes, it overrides its -\ core input (normally "stdin") with the contents of that saved stringm which is +\ core input (normally "ccio") with the contents of that saved string, which is \ then processed regularly until the end of string, at which point we go back to \ our previous feed. This system works recursively. \ Macro are stored as null-terminated ranges, *not* regular strings. diff --git a/fs/doc/cc/lib.txt b/fs/doc/cc/lib.txt @@ -20,7 +20,6 @@ void abort(); unsigned int min(unsigned int a, unsigned int b); unsigned int max(unsigned int a, unsigned int b); void stype(char *str); -int StdIO(); --> stdio :self int Console(); --> console :self unsigned char stdin(); void stdout(unsigned char c); @@ -56,13 +55,13 @@ int fwritebuf(int *addr, int n, int hdl) --> IO :writebuf void fseek(int pos, int hdl) --> File :seek void fclose(int hdl) --> IO :close void fputs(char *str, int hdl) --> IO :puts -void puts(char *str) --> stdio :puts +void puts(char *str) --> console :puts (see below for details about printf/scanf) void fprintf(... char *fmt, int hdl) --> IO :printf -void printf(... char *fmt) --> stdio :printf +void printf(... char *fmt) --> console :printf char* sprintf(... char *fmt) int fscanf(char *fmt, int hdl) --> see below -int scanf(char *fmt) --> fscanf(stdio readio) +int scanf(char *fmt) --> fscanf(console readio) int sscanf(char *fmt, char *str) ### freadbuf @@ -98,7 +97,7 @@ For example, `sscanf("%d %d %d", "5 6 7")` results in PS receiveing elements to PS. printf and scanf each have `f` and `s` variants. Without a variant, printing and -scanning is done through StdIO. The `f` variant allow us to choose another +scanning is done through Console. The `f` variant allow us to choose another target I/O handle. For the `s` variant, we have a static buffer wrapped around a `MemFile` that is diff --git a/fs/doc/deploy.txt b/fs/doc/deploy.txt @@ -109,7 +109,7 @@ driver to implement :readbuf and your output driver to implement :writebuf. I recommend looking at PC drivers for inspiration. Once you have those drivers, you instantiate them in your init.fs and plug them -to the Console and StdIO. +to the Console. That's all you need driver-wise. You're now ready to write the "user" part of your init.fs, the one that will load the sys/rdln subsystem and define the diff --git a/fs/doc/emul/uxn.txt b/fs/doc/emul/uxn.txt @@ -67,7 +67,8 @@ You can assemble ".tal" file with the uxntal assembler at asm/uxntal.fs. When loaded, exposes this API: uxntal ( srchdl -- res ) - Read IO handler "srchdl" until EOF and spits the resulting bytecode to stdio. + Read IO handler "srchdl" until EOF and spits the resulting bytecode to + uxn's VM RAM, starting at offset $100. Yields a numberical result code which is 0 on success and nonzero on error. tal>vm ( path -- res ) diff --git a/fs/doc/sys/file.txt b/fs/doc/sys/file.txt @@ -242,9 +242,9 @@ and also implicitly close themselves when being overwritten. This way, the sysop doesn't have to remember to close those handles as long as she use those structbinds. -Also, those structbinds serve as a kind of "stdio, but for seekable contents". -That is, some words will use them to simplify their API (you don't have to pass -them a handle, just have the structbinds properly set). +Also, those structbinds serve as a convenience. That is, some words will use +them to simplify their API (you don't have to pass them a handle, just have the +structbinds properly set). Words that use "file" and "dstfile" are expected to never set them themselves. They can seek, read, write to it, but the binding to the handles themselves is diff --git a/fs/doc/sys/io.txt b/fs/doc/sys/io.txt @@ -208,27 +208,6 @@ There is a "consoleecho" value, which is initialized to 0. When set to 1, all characters being read through in< are echoed through "emit". This can be useful for debugging, and it's also used in the test harness. -## StdIO - -StdIO is a Pipe with a global structbind to it named "stdio". This IO is at the -top of our I/O indirection pyramid. By default, it points to the Console, but -you will often want to redirect it to somewhere else when running higher level -words. At this level, you can redirect those aliases freely without breaking the -interpret loop, but at the same time, control the flow of most higher level -I/Os. - -"stdin" is a shortcut for "stdio :getc" -"stdout" is a shortcut for "stdio :putc" -"stdio$" plugs the Console back into StdIO - -## I/O and file loading - -When loading a file to be interpreted by the system (with ":fload" or "f<<"), -*both* Console's and StdIO's "readio" are set to the handle of the file being -read and those redirections are expected to stay as-is while the file is loaded. -For this reason, unless you know what you are doing, you shouldn't redirect -StdIO's readio at the "interpret" level of a Forth source file. - ## printf An interesting augmentation of the I/O subsystem is implemented in lib/fmt.fs, @@ -239,7 +218,7 @@ a letter. That formatting string must be preceded by a number of arguments equal to the number of placeholders in the string, in reverse order. Example: - 3 2 1 S" hello %d %d %d" stdio :printf --> prints "hello 1 2 3" + 3 2 1 S" hello %d %d %d" console :printf --> prints "hello 1 2 3" The letter following the '%' chars determines how the argument is formatted and these letters are supported (others produce an error): diff --git a/fs/drv/fbgrid/fbgrid.fs b/fs/drv/fbgrid/fbgrid.fs @@ -79,4 +79,4 @@ extends Grid struct[ FbGrid : fbgrid$ screen :activate FbGrid :new ['] grid rebind screen width 8 COLOR_RGB565 Plane :new ['] _scrollbuf rebind _scrollbuf :allotbuf - grid :self dup to console writeio to stdio writeio ; + grid :self to console writeio ; diff --git a/fs/emul/cos/cvm.fs b/fs/emul/cos/cvm.fs @@ -9,5 +9,5 @@ S" COSVM" findTypedef CDecl :export vm COSVM mem S" /emul/cos/serial.bin" curpath :find# Path :open tuck File :readall File :close ['] key vm COSVM iord ! - ['] stdout vm COSVM iowr ! + ['] emit vm COSVM iowr ! begin 100 COS_steps not until COS_printdbg ; diff --git a/fs/emul/cos/stage.fs b/fs/emul/cos/stage.fs @@ -46,14 +46,14 @@ S" XORG HERE BYE\r" 1+ value suffix xcomp_script dup if IO :getc dup 0< if drop ['] _readsuffix vm COSVM iord ! then - else S" No cross-compilation script loaded, aborting" stdio :printf abort then ; + else S" No cross-compilation script loaded, aborting" console :printf abort then ; : stage COS_init vm COSVM mem S" /emul/cos/serial.bin" curpath :find# Path :open tuck File :readall File :close ['] _readxcomp vm COSVM iord ! ( Will read from xcomp script file ) - ['] stdout vm COSVM iowr ! + ['] emit vm COSVM iowr ! begin 100 COS_steps not until COS_printdbg COS_pop COS_pop ( end start -- ) tuck - ( start length -- ) swap ( length start -- ) vm COSVM mem + ( length start -- ) swap diff --git a/fs/emul/cos/tools/blkpack.c b/fs/emul/cos/tools/blkpack.c @@ -1,12 +1,13 @@ #define BUMP_GRANULARITY 10 -int lineno; +static int lineno; +static uint outhdl; static void emptylines(int n) { int i; for (i=0; i<64*n; i++) { - stdout(' '); + fputc(' ', outhdl); } } @@ -30,7 +31,7 @@ static unsigned int expectmarker(char *line) return blkid; } -void blkpack() { +void blkpack(uint in, uint out) { int prevblkid = -1; int blkoff = 0; int blkid; @@ -39,8 +40,9 @@ void blkpack() { int n = 0; int cnt; int i; + outhdl = out; lineno = 1; - line = freadline(StdIO()); + line = freadline(in); if (!line) { fprintf("No input\n", Console()); abort(); @@ -65,7 +67,7 @@ void blkpack() { emptylines((blkid-prevblkid-1)*16); for (blkline=0; blkline<16; blkline++) { lineno++; - line = freadline(StdIO()); + line = freadline(in); if (!line) { break; } cnt = strlen(line); if (cnt > 64) { @@ -77,11 +79,11 @@ void blkpack() { if (getmarker(line) >= 0) { break; } // we have a marker early puts(line); // pad line to 64 chars - for (i=cnt; i<64; i++) { stdout(' '); } + for (i=cnt; i<64; i++) { fputc(' ', outhdl); } } if (blkline == 16) { lineno++; - line = freadline(StdIO()); + line = freadline(in); if (!line) { return; } } else { emptylines(16-blkline); diff --git a/fs/emul/cos/tools/blkpack.fs b/fs/emul/cos/tools/blkpack.fs @@ -4,8 +4,9 @@ cc<< /emul/cos/tools/blkpack.c 320 $400 * MemFile :new const cosfs +\ TODO: this seems to have been broken, but not by the commit adding this +\ comment. investigate. : cosfs$ 0 cosfs MemFile :seek - S" /emul/cos/blk.fs" curpath :find# Path :open to stdio readio - cosfs to stdio writeio - blkpack stdio readio File :close stdio$ ; + S" /emul/cos/blk.fs" curpath :find# Path :open ( inhdl ) + dup cosfs blkpack ( inhdl ) File :close ; diff --git a/fs/emul/uxn/varvara.fs b/fs/emul/uxn/varvara.fs @@ -17,9 +17,9 @@ 8 - 6 < if 1 to rgbchanged then drop ; : consoledei ( dev port -- c ) - nip 2 = if stdin else 0 then ; + nip 2 = if console :getc else 0 then ; : consoledeo ( dev port -- ) - 8 = if Device dat 8 + c@ stdout else drop then ; + 8 = if Device dat 8 + c@ console :putc else drop then ; \ Instead of holding file cursors around (as the official varvara does), we \ instead keep track of file positions, with a seek at the beginning of each diff --git a/fs/lib/fmt.fs b/fs/lib/fmt.fs @@ -37,12 +37,12 @@ struct+[ IO : _ console :printf ; : .f" [compile] S" compiling if compile _ else _ then ; immediate -: .x1 stdio :.x1 ; -: .x2 stdio :.x2 ; -: .x stdio :.x ; +: .x1 console :.x1 ; +: .x2 console :.x2 ; +: .x console :.x ; \ print in hexadecimal with a width that depends on the value : .x? dup $ffff > if .x else dup $ff > if .x2 else .x1 then then ; -: . stdio :. ; +: . console :. ; extends IO struct[ DumpIO sfield target \ IO instance that it wraps @@ -60,5 +60,5 @@ create _ ," KMG" 0 begin ( sz lvl ) swap 1024 /mod ( lvl r q ) ?dup while nip swap 1+ repeat ( lvl sz ) - . ?dup if 1- _ + c@ stdout then 'B' stdout ; + . ?dup if 1- _ + c@ emit then 'B' emit ; diff --git a/fs/lib/str.fs b/fs/lib/str.fs @@ -32,7 +32,7 @@ create _buf STR_MAXSZ allot : slistiter ( idx list -- str ) swap for s) next ; -: toword ( -- c ) begin stdin dup ws? while drop repeat ( c ) ; +: toword ( -- c ) begin in< dup ws? while drop repeat ( c ) ; : expectchar ( c -- ) toword over = not if emit abort" expected" else drop then ; diff --git a/fs/sys/file.fs b/fs/sys/file.fs @@ -111,10 +111,6 @@ Path _curpath structbind Path curpath : require word dup curpath :find# Path :floaded? not if stype abort" required" else drop then ; -: with-stdin-file ( w str -- ) - curpath :find# Path :open dup >r ( w hdl ) - to@! stdio readio >r execute - r> to stdio readio r> File :close ; 0 structbind File file 0 structbind File dstfile diff --git a/fs/sys/io.fs b/fs/sys/io.fs @@ -36,13 +36,6 @@ struct+[ IO : _consoleemit console :putc ; ' _consoleemit ' emit realias -: stdin stdio :getc ; -: stdout stdio :putc ; -: stdio$ console :self to stdio readio console :self to stdio writeio ; - -\ Call w with in< being overwritten with stdin. -: with-stdin< ( w -- ) - ['] stdin ['] in< realias execute ['] consolein ['] in< realias ; extends IO struct[ SumIO sfield fn diff --git a/fs/tests/ar/ungz.fs b/fs/tests/ar/ungz.fs @@ -4,9 +4,8 @@ testbegin \ Testing ar/ungz create _expected ," Hello from compressed file!" create _resultbuf $20 allot -_resultbuf $20 MemIO :new to stdio writeio -' ungz S" /tests/ar/hello.gz" with-stdin-file -stdio$ -( err ) 0 #eq +f" /tests/ar/hello.gz" file :self ( inhdl ) +_resultbuf $20 MemIO :new ( inhdl outhdl ) +ungz ( err ) 0 #eq _resultbuf _expected 27 []= # testend diff --git a/fs/tests/comp/c/tok.fs b/fs/tests/comp/c/tok.fs @@ -2,6 +2,7 @@ ?f<< /comp/c/cc.fs testbegin \ Tests for CC tokenizer +ccio$ : checktok ( expected n -- ) for nextt dup #s= s) next drop ; 9 stringlist expected "short" "retconst" "(" ")" "{" "return" "42" ";" "}" expected 9 checktok diff --git a/fs/tests/comp/c/type.fs b/fs/tests/comp/c/type.fs @@ -6,8 +6,9 @@ testbegin TYPE_VOID typesize 0 #eq TYPE_CHAR typesize 1 #eq +ccio$ : printstruct CDecl :.struct ; -\ with parseType, we systematically "peek" 1 token in stdin, which is why we +\ with parseType, we systematically "peek" 1 token in ccio, which is why we \ always end our test input with "STOP". : _parse nextt parseType # nextt S" STOP" #s= ; _parse int STOP TYPE_INT #eq diff --git a/fs/tests/harness.fs b/fs/tests/harness.fs @@ -12,9 +12,7 @@ _buf 1+ $ff MemIO :new structbind MemIO _memio word _memio :rewind _memio :self to@! console writeio >r - _memio :self to@! stdio writeio >r runword - r> to stdio writeio r> to console writeio _memio ptr _memio buf( - ( sz ) _buf c! _buf ; diff --git a/fs/tests/lib/fmt.fs b/fs/tests/lib/fmt.fs @@ -2,7 +2,7 @@ ?f<< /lib/fmt.fs testbegin \ Testing lib/fmt -: _printf stdio :printf ; +: _printf console :printf ; 10 11 12 13 S" foo %b bar %w baz %x bleh %d" capture _printf S" foo 0d bar 000c baz 0000000b bleh 10" #s= diff --git a/fs/xcomp/arm/rpi/init.fs b/fs/xcomp/arm/rpi/init.fs @@ -3,7 +3,7 @@ f<< /drv/rpi/uart.fs uart$ : _:emit ( c self -- ) drop uart! ; -' _:emit ByteWriter :new dup to console writeio to stdio writeio +' _:emit ByteWriter :new to console writeio f<< /sys/kbd.fs ' uart@? ' key? realias diff --git a/fs/xcomp/bootlo.fs b/fs/xcomp/bootlo.fs @@ -390,7 +390,6 @@ BootIn IONullOut Pipe :new structbind Pipe console 0 value consoleecho : consolein console :getc consoleecho if dup emit then ; current ' in< realias -console :self console :self Pipe :new structbind Pipe stdio struct+[ IO : :interpret ( self -- self ) diff --git a/fs/xcomp/i386/pc/init.fs b/fs/xcomp/i386/pc/init.fs @@ -9,7 +9,7 @@ f<< /drv/pc/acpi.fs f<< /sys/grid.fs f<< /drv/pc/vga.fs VgaGrid :new ' grid rebind -grid :self dup to console writeio to stdio writeio +grid :self to console writeio \ Overwrite the boot drive which depends on int13h with a real drive. \ Floppy boot drive diff --git a/fs/xcomp/i386/pc/inittest.fs b/fs/xcomp/i386/pc/inittest.fs @@ -1,7 +1,7 @@ f<< /drv/pc/com.fs com$ : _:emit ( c self -- ) drop >com ; -' _:emit ByteWriter :new dup to console writeio to stdio writeio +' _:emit ByteWriter :new to console writeio f<< sys/scratch.fs f<< lib/fmt.fs f<< lib/diag.fs diff --git a/fs/xcomp/init.fs b/fs/xcomp/init.fs @@ -5,4 +5,4 @@ f<< /lib/fmt.fs f<< /lib/diag.fs f<< /sys/rdln.fs f<< /text/pager.fs -: init S" Dusk OS\n" stype .free rdln$ stdio$ quit ; +: init S" Dusk OS\n" stype .free rdln$ quit ; diff --git a/posix/init.fs b/posix/init.fs @@ -2,7 +2,7 @@ : ARCH S" forth" ; : _:emit ( c self -- ) drop (emit) ; -' _:emit ByteWriter :new dup to console writeio to stdio writeio +' _:emit ByteWriter :new to console writeio f<< /sys/kbd.fs ' (key?) ' key? realias