commit 217157c2e5611b9da96bb6fa336a33f706aab777
parent 5a04a16383b93ba58379508ad79a2c3a1ce5e861
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Fri, 13 Jan 2023 21:13:18 -0500
Simplify
I wasn't thinking straight when I wrote this test unit. The usage of
"with-stdin<" is spurious and can be removed without adverse effect.
Without this spurious usage of with-stdin<, we can finally remove the weird
requirement in "fload" to override stdio in addition to the console. It didn't
make sense to me, but since it broke tests, I let it stay there.
But now that I got to the root of the problem, we can get rid of that
complexity.
Diffstat:
4 files changed, 26 insertions(+), 27 deletions(-)
diff --git a/fs/sys/io.fs b/fs/sys/io.fs
@@ -40,10 +40,9 @@ struct+[ IO
: stdout stdio :putc ;
: stdio$ console :self to stdio readio console :self to stdio writeio ;
-\ Call w with console readio being overwritten with stdio readio.
+\ Call w with in< being overwritten with stdin.
: with-stdin< ( w -- )
- 0 to@! stdio putback to console putback
- stdio readio to@! console readio >r execute r> to console readio ;
+ ['] stdin ['] in< realias execute ['] consolein ['] in< realias ;
extends IO struct[ SumIO
sfield fn
diff --git a/fs/tests/comp/c/type.fs b/fs/tests/comp/c/type.fs
@@ -12,46 +12,46 @@ TYPE_CHAR* typesize 4 #eq
\ with parseType, we systematically "peek" 1 token in stdin, which is why we
\ always end our test input with "STOP".
: _parse nextt parseType # nextt S" STOP" #s= ;
-current with-stdin< int STOP TYPE_INT #eq
-current with-stdin< unsigned int STOP TYPE_UINT #eq
-current with-stdin< char STOP TYPE_CHAR #eq
-current with-stdin< short STOP TYPE_SHORT #eq
-current with-stdin< void STOP TYPE_VOID #eq
-current with-stdin<
+_parse int STOP TYPE_INT #eq
+_parse unsigned int STOP TYPE_UINT #eq
+_parse char STOP TYPE_CHAR #eq
+_parse short STOP TYPE_SHORT #eq
+_parse void STOP TYPE_VOID #eq
+_parse
struct Struct1 { unsigned int foo; short *bar; char baz[2]; } STOP
( type ) dup typesize 10 #eq
S" bar" over CType :find
dup CType type TYPE_SHORT* #eq CType offset 4 #eq
\ once defined, parseType will find the struct in typedefs
-current with-stdin< Struct1 STOP over #eq
+_parse Struct1 STOP over #eq
capture printstruct
S" struct Struct1 {unsigned int foo, +04 short* bar, +08 char baz[2], }" #s=
\ Anonymous structs work too
-current with-stdin< struct { int foo; } STOP typesize 4 #eq
+_parse struct { int foo; } STOP typesize 4 #eq
\ And now, let's test parseDeclarator
: _parse nextt parseType # parseDeclarator nextt S" STOP" #s= ;
-current with-stdin< int *foo STOP
+_parse int *foo STOP
dup CType type TYPE_INT* #eq
CType name S" foo" #s=
-current with-stdin< unsigned int *foo STOP
+_parse unsigned int *foo STOP
dup CType type TYPE_UINT* #eq
CType name S" foo" #s=
-current with-stdin< unsigned short ***foo STOP
+_parse unsigned short ***foo STOP
CType type
dup type*lvl 3 #eq dup typeunsigned? #
type*lvl- type*lvl- type*lvl- typesize 2 #eq
-current with-stdin< int *foo[42] STOP
+_parse int *foo[42] STOP
dup CType type TYPE_INT* #eq
dup CType nbelem 42 #eq
CType name S" foo" #s=
-current with-stdin< int (*foo)[42] STOP
+_parse int (*foo)[42] STOP
dup CType type ctype? #
dup CType type type*lvl 1 #eq
dup CType nbelem 0 #eq
@@ -61,7 +61,7 @@ dup CType type TYPE_INT #eq
dup CType nbelem 42 #eq
CType name NULLSTR #s=
-current with-stdin< unsigned int (*foo)(char,short) STOP
+_parse unsigned int (*foo)(char,short) STOP
dup CType :funcptr? #
dup CType name S" foo" #s=
CType type ctype'
@@ -74,7 +74,7 @@ dup CType type TYPE_SHORT #eq
CType offset 0 #eq
\ We can also have a function signature with argument names.
-current with-stdin< unsigned int (*foo)(short bar,char baz) STOP
+_parse unsigned int (*foo)(short bar,char baz) STOP
dup CType :funcptr? #
dup CType name S" foo" #s=
CType type ctype'
@@ -87,7 +87,7 @@ dup CType name S" baz" #s=
dup CType type TYPE_CHAR #eq
CType offset 0 #eq
-current with-stdin< Struct1 *mystructptr STOP
+_parse Struct1 *mystructptr STOP
capture printtype
S" struct Struct1* mystructptr" #s=
testend
diff --git a/fs/xcomp/boothi.fs b/fs/xcomp/boothi.fs
@@ -1,9 +1,3 @@
-: \s console readio IO :close ;
-: fload ( fs id -- )
- dup floaded, swap Filesystem :open ( hdl )
- dup to@! console readio >r to@! stdio readio >r
- begin maybeword ?dup if runword 0 else 1 then until
- r> to stdio readio r> to@! console readio ( hdl ) File :close ;
0 S" sys" bootfs Filesystem :child S" file.fs" bootfs Filesystem :child
bootfs swap fload
0 S" init.fs" bootfs Filesystem :child bootfs swap fload
diff --git a/fs/xcomp/bootlo.fs b/fs/xcomp/bootlo.fs
@@ -300,7 +300,7 @@ create IONullOut 0 , ' _ioerr , ' _writebuf , ' _ioerr , ' _ioerr ,
BootIn IONullOut Pipe :new structbind Pipe console
0 value consoleecho
-: _ console :getc consoleecho if dup emit then ;
+: consolein console :getc consoleecho if dup emit then ;
current ' in< realias
console :self console :self Pipe :new structbind Pipe stdio
@@ -328,7 +328,13 @@ extends IO struct[ File
smethod :seek
]struct
-\ Autoloading
+\ File loading
\ TODO: support loading from multiple FSes.
create floaded 0 , \ address of the current "loaded file" structure
: floaded, ( id -- ) floaded lladd drop ( id ) , ;
+: \s console readio IO :close ;
+: fload ( fs id -- )
+ dup floaded, swap Filesystem :open ( hdl )
+ to@! console readio >r
+ begin maybeword ?dup while runword repeat
+ r> to@! console readio ( hdl ) File :close ;