commit 5a365c6e0cccc9fbc686abd9125a670c41aff994
parent 359a6cfb850204d3cb0f9e8f4555dae05bfa4016
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Thu, 1 Dec 2022 21:04:11 -0500
comp/c: consolidate
Diffstat:
1 file changed, 18 insertions(+), 20 deletions(-)
diff --git a/fs/comp/c/pgen.fs b/fs/comp/c/pgen.fs
@@ -119,7 +119,7 @@ alias noop parseExpression ( tok -- ) \ forward declaration
begin ( ctype ) nextt case
'[' of isChar?^
nextt parseExpression
- vmop^ :noop# vmop :isconst# vmop arg ( ctype nbelem )
+ vmop^ :noop# vmop :isconst# vmop arg ops$ ( ctype nbelem )
nextt ']' expectChar ( ctype nbelem )
over to CType nbelem endof
'(' of isChar?^
@@ -235,6 +235,18 @@ alias noop parseFactor ( tok -- ) \ forward declaration
r@ to nexttputback
endcase ;
+$400 const CONSTARRAYBUFSZ
+create _constarray CONSTARRAYBUFSZ allot
+: _!+ ( sz -- ) case 1 of = c!+ endof 2 of = 16b !+ endof !+ endcase ;
+: parseList ( typesize -- ) >r \ V1=typesize
+ _constarray CELLSZ + begin ( ctype a )
+ nextt parseFactor vmop :isconst#
+ vmop arg vmop :init swap r@ _!+ ( ctype a )
+ ',' readChar? not until ( ctype a tok )
+ '}' expectChar ( ctype a )
+ _constarray - CELLSZ - ( len ) _constarray !
+ _constarray constarray>op rdrop ;
+
\ A factor can be:
\ 1. A constant
\ 2. A lvalue
@@ -258,6 +270,8 @@ alias noop parseFactor ( tok -- ) \ forward declaration
here 0 c, ['] ," with-stdin< here over - 1- swap c! ( jaddr saddr )
const>op ]vmjmp
endof
+ '{' of isChar?^ \ vmop^ must be set to target for list
+ vmop^ :hasop# vmop^ type *ariunitsz parseList endof
S" pspop" of s= read( read) vmpspop, parsePostfixOp endof
S" NULL" of s= 0 const>op endof
of uopid ( opid )
@@ -363,27 +377,10 @@ alias noop parseStatement ( tok -- ) \ forward declaration
ops$ r> to _laststmtid ;
current to parseStatement
-$400 const CONSTARRAYBUFSZ
-create _constarray CONSTARRAYBUFSZ allot
-: _!+ ( sz -- ) case 1 of = c!+ endof 2 of = 16b !+ endof !+ endcase ;
-: parseList ( ctype -- ctype )
- dup CType type typesize >r \ V1=typesize
- _constarray CELLSZ + begin ( ctype a )
- nextt parseFactor vmop :isconst#
- vmop arg vmop :init swap r@ _!+ ( ctype a )
- ',' readChar? not until ( ctype a tok )
- '}' expectChar ( ctype a )
- _constarray - CELLSZ - ( len ) _constarray !
- _constarray constarray>op rdrop ;
-
\ When there's variable initialization code, it has to come before the prelude
\ and we jump to it after we've created the stack frame.
0 value _initcode
-\ result in vmop
-: parseDeclInit ( ctype -- ctype )
- '{' readChar? if parseList else parseExpression then ;
-
: parseDeclLine ( type -- )
parseDeclarator ( ctype )
dup _locvars ?dup if CType :append else to _locvars then begin ( ctype )
@@ -394,7 +391,8 @@ create _constarray CONSTARRAYBUFSZ allot
\ init code. that's bad. To avoid this, we "reserve" an arena buf now.
cctypearena Arena :reserve
here to _initcode then
- parseDeclInit selop^ dup ctype>op vm=, ops$ nextt then ( ctype tok )
+ dup ctype>op selop^ nextt parseExpression
+ selop^ vm=, ops$ nextt then ( ctype tok )
dup ';' isChar? not while ( ctype tok )
',' expectChar CType type parseDeclarator ( ctype )
dup _locvars CType :append repeat ( ctype tok ) 2drop ;
@@ -420,7 +418,7 @@ create _constarray CONSTARRAYBUFSZ allot
dup CType name NEXTWORD ! create then ( ctype )
here over to CType offset ( ctype )
'=' readChar? if ( ctype )
- parseDeclInit vmop loc case ( ctype )
+ dup ctype>op selop^ nextt parseExpression vmop loc case ( ctype )
VM_CONSTANT of = vmop arg , endof
VM_CONSTARRAY of = vmop arg @+ move, endof
_err endcase ops$