commit 0cc6db52d64bf6f3a9fdc7cbd3db3beb302d8668
parent a526bce947a2cbed6f857b1363dd3bec506116b3
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Sun, 9 Oct 2022 19:07:32 -0400
cc/lib: add File struct global definition
Diffstat:
3 files changed, 23 insertions(+), 20 deletions(-)
diff --git a/fs/app/cos/cvm.c b/fs/app/cos/cvm.c
@@ -36,17 +36,6 @@ struct COSVM {
word minSP;
int running;
};
-struct File { // TODO: create system C header
- unsigned int putback;
- void *_readbuf;
- void *_writebuf;
- void *_flush;
- void *_close;
- unsigned int pos;
- unsigned int size;
- void *_seek;
-};
-
static COSVM vm;
static File *blkfp;
/* Stores blkop command. Bytes flow from left (byte 0) to right (byte 3)
diff --git a/fs/cc/lib.fs b/fs/cc/lib.fs
@@ -129,3 +129,15 @@ $100 MemIO :new const _sio
(S fmt str -- f )
: sscanf
_sio MemIO :rewind c@+ _sio IO :write _sio MemIO :rewind _sio fscanf ;
+
+:c struct File {
+ unsigned int putback;
+ void *_readbuf;
+ void *_writebuf;
+ void *_flush;
+ void *_close;
+ unsigned int pos;
+ unsigned int size;
+ void *_seek;
+};
+
diff --git a/fs/cc/type.fs b/fs/cc/type.fs
@@ -9,6 +9,8 @@
16 $400 * Scratchpad :new structbind Scratchpad _pad
0 to _pad allowrollover
+0 value _globalmode \ are we adding a global type?
+
: _err ( -- ) abort" type error" ;
: _assert ( f -- ) not if _err then ;
@@ -81,9 +83,9 @@ struct[ CType
sfield storage \ one of the STORAGE_* consts
SZ &+ name \ name associated with this type within its list.
+ : _ 0 align4 here rot> 0 , , 0 , 0 , 0 , STORAGE_SF , s, ;
: :new ( name type -- ctype )
- 0 align4 here rot> 0 , , 0 , 0 , 0 , STORAGE_SF , s, ;
- : :newInPad $100 SZ + _pad :[ :new _pad :] drop ;
+ _globalmode if _ else $100 SZ + _pad :[ _ _pad :] drop then ;
: :struct? flags 1 and ;
: :funcsig? flags 2 and ;
@@ -157,7 +159,7 @@ current to _typesize
: parseFuncSig ( type -- ctype )
nextt '*' expectChar nextt expectIdent ( type name )
- swap CType :newInPad ( ctype )
+ swap CType :new ( ctype )
2 over to CType flags ( ctype )
nextt ')' expectChar nextt '(' expectChar begin ( ctype )
\ TODO: don't ignore funcsig arguments
@@ -169,7 +171,7 @@ current to _typesize
\ ([]). This always returns a CType.
: parseVariable ( type -- ctype )
nextt dup '(' isChar? if drop parseFuncSig exit else to nexttputback then
- parseType* expectIdent swap CType :newInPad ( ctype )
+ parseType* expectIdent swap CType :new ( ctype )
nextt dup S" [" s= if ( ctype tok )
drop nextt dup S" #[" s= if drop #[1 else parse _assert then
nextt ']' expectChar ( ctype nbelem )
@@ -184,17 +186,17 @@ current to _typesize
drop nextt parseType _assert parseVariable ( ctype )
dup addLocalTypedef 1 exit then
dup S" struct" s= if
- drop nextt dup isIdent? if ( name )
- TYPE_VOID CType :new dup addGlobalTypedef nextt
- else ( tok ) NULLSTR TYPE_VOID CType :newInPad swap then ( ctype tok )
- '{' expectChar 1 over to CType flags
+ drop nextt dup isIdent? if nextt 1 to _globalmode else NULLSTR swap then
+ '{' expectChar ( name ) TYPE_VOID CType :new ( res )
+ 1 over to CType flags
+ _globalmode if dup addGlobalTypedef then
0 >r dup begin ( res prev ) \ V1=offset
nextt dup '}' isChar? not while ( res prev tok )
parseType _assert parseVariable ( res prev new )
tuck swap to CType nexttype ( res new )
V1 over to CType offset
dup typesize to+ V1 read;
- repeat ( res prev tok ) rdrop 2drop 1
+ repeat ( res prev tok ) rdrop 2drop 1 0 to _globalmode
else
dup S" unsigned" s= if drop $10 nextt else $00 swap then ( type tok )
dup typenames sfind dup 0>= if ( type tok idx )