duskos

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

commit 23aa55dfaa874d0a22c895d91eeca39a284db2ae
parent ac09572db0e618d9575da411b3c7b81b7818d233
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Wed, 20 Jul 2022 15:57:16 -0400

cc: allow multiple declarations of the same type on the same line

Diffstat:
Mfs/cc/ast.fs | 16+++++++++++-----
Mfs/lib/crc.c | 8++------
Mfs/tests/cc/test.c | 3+--
3 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/fs/cc/ast.fs b/fs/cc/ast.fs @@ -339,12 +339,12 @@ current to parseExpression dup AST_FUNCTION parentnodeid ?dup _assert ( dnode fnode ) 0 , over ast.decl.totsize swap to+ ast.func.sfsize ; -: parseDeclareInit ( dnode tok -- node ) - dup S" =" s= not if ';' expectChar drop exit then +: parseDeclareInit ( dnode tok -- ) + dup S" =" s= not if to nexttputback drop exit then drop ( dnode ) nextt dup S" {" s= if drop parseList else parseExpression then - read; ( dnode expr-or-list ) swap addnode ; + ( dnode expr-or-list ) swap addnode ; : parseArgSpecs ( funcnode -- ) \ First '(' is already parsed @@ -355,6 +355,12 @@ current to parseExpression nextt dup S" )" s= not while ',' expectChar nextt repeat ( argsnode tok ) 2drop ; +: parseDeclareStatement ( type parentnode -- ) + 2dup parseDeclare nextt parseDeclareInit ( type parentnode ) + nextt dup ',' isChar? if \ another declaration + drop parseDeclareStatement + else ';' expectChar 2drop then ; + alias noop parseStatements ( funcnode -- ) \ forward declaration 4 stringlist statementnames "return" "if" "for" "pspush" @@ -393,7 +399,7 @@ alias noop parseStatements ( funcnode -- ) \ forward declaration dup S" }" s= not while dup statementnames sfind dup 0< if ( snode tok -1 ) drop dup parseType if ( snode tok type ) - nip over parseDeclare nextt parseDeclareInit else ( snode tok ) + nip over parseDeclareStatement else ( snode tok ) parseExpression over addnode read; then ( snode ) else ( snode tok idx ) nip statementhandler swap wexec then ( snode ) nextt repeat ( snode tok ) 2drop ; @@ -414,7 +420,7 @@ current to parseStatements endof AST_DECLARE newnode ( type name dnode ) rot> , , ( dnode ) r@ parseNbelem , 0 ( address ) , - nextt parseDeclareInit + nextt parseDeclareInit read; endcase ( ) ; : parseast ( -- ) diff --git a/fs/lib/crc.c b/fs/lib/crc.c @@ -1,16 +1,12 @@ -// TODO: use char for "c" -// TODO: declare i and b on the same line // TODO: use >>= -// TODO: replace if (b==1) with if (b) extern unsigned int crc32(unsigned int crc, int c) { - unsigned int i; - unsigned int b; + unsigned int i, b; for (i=0; i<8; i++) { b = (c ^ crc) & 1; crc = crc >> 1; - if (b==1) { + if (b) { crc = crc ^ $EDB88320; } c = c >> 1; diff --git a/fs/tests/cc/test.c b/fs/tests/cc/test.c @@ -40,8 +40,7 @@ extern int boolops() { return 66 < 54 && 2 == 2; } extern int variables() { - unsigned int foo = 40; - unsigned int _bar = 2; + unsigned int foo = 40, _bar = 2; _bar = foo + _bar; return foo + _bar; }