duskos

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

commit aa58a5fb007e5b469a7f61e18b4f50c885c5e076
parent 2a421f5e6d2e4e005a64c8490ab027e06840efde
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Sat,  1 Apr 2023 20:48:06 -0400

halcc: move funcsig args to new "args" fields

When args were directly in llnext, a funcsig being added to a struct would make
the struct contains the funcsig's args as well! This didn't make sense.

Diffstat:
Mfs/comp/c/egen.fs | 3++-
Mfs/comp/c/func.fs | 3++-
Mfs/comp/c/ptype.fs | 4+++-
Mfs/comp/c/type.fs | 11++++++-----
4 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/fs/comp/c/egen.fs b/fs/comp/c/egen.fs @@ -136,6 +136,7 @@ code _callA branchA, dup Result cdecl nextt ( res cdecl name ) swap CDecl type CDecl :find# tuck CDecl offset ( field-cdecl res offset ) over Result :?>W i) +, ( field-cdecl res ) tuck to Result cdecl + \ TODO: use :reference? instead of nbelem, but there's a mixup for funcs dup Result cdecl CDecl nbelem not if Result :* then ; \ parses, if possible, a postfix operator. If none, this is a noop. @@ -143,7 +144,7 @@ code _callA branchA, : parsePostfixOp ( res -- res ) nextt case ( ) '[' of isChar?^ \ x[y] is the equivalent of *(x+y) - dup Result :. nextt parseExpression _+, Result :* + nextt parseExpression _+, Result :* nextt ']' expectChar parsePostfixOp endof '(' of isChar?^ _funcall parsePostfixOp endof S" ->" of s= diff --git a/fs/comp/c/func.fs b/fs/comp/c/func.fs @@ -5,6 +5,7 @@ 0 value _locvars \ the root cdecl of local variables for current function : findIdent ( name -- cdecl-or-0 ) - _curfunc if dup _curfunc CDecl :find ?dup if nip exit then then ( name ) + _curfunc if + dup _curfunc to' CDecl args CDecl :find ?dup if nip exit then then ( name ) dup _locvars if to' _locvars CDecl :find else drop 0 then ( name cdecl-or-0 ) ?dup if nip else findSymbol then ; diff --git a/fs/comp/c/ptype.fs b/fs/comp/c/ptype.fs @@ -36,7 +36,9 @@ alias _err parseDeclarator ( type -- cdecl ) \ forward declaration '(' of isChar?^ dup CDecl :funcsig! STORAGE_PS to@! curstorage >r ')' readChar? not if ( cdecl tok ) - over swap _arg ( cdecl offset ) drop then + over swap _arg ( cdecl offset ) drop + \ args in nexttype, we want them in args + 0 over to@! CDecl nexttype over to CDecl args then r> to curstorage endof r> to nexttputback exit endcase again ; diff --git a/fs/comp/c/type.fs b/fs/comp/c/type.fs @@ -62,11 +62,12 @@ struct[ CDecl \ if this cdecl is a function, offset contains its address. sfield nbelem \ number of elements in array. 0 if not an array. sfield storage \ one of the STORAGE_* consts + sfield args \ funcsig args SZ &+ name \ name associated with this type within its list. : :new ( name type -- cdecl ) $100 SZ + _arena Arena :[ - 0 align4 here rot> 0 , , 0 , 0 , 0 , 0 , curstorage , s, + 0 align4 here rot> 0 , , 0 , 0 , 0 , 0 , curstorage , 0 , s, _arena Arena :] drop ; : _f? doer , does> ( self 'w ) @ swap flags and bool ; @@ -106,7 +107,7 @@ struct[ CDecl : :elemsize ( self -- size ) dup nbelem _assert dup lvl if drop 4 else type _typesize then ; - : :argssize ( self -- size ) dup :funcsig? _assert llcnt 1- CELLSZ * ; + : :argssize ( self -- size ) dup :funcsig? _assert args llcnt CELLSZ * ; : :offset! ( off self -- off+size ) 2dup to offset :size + ; \ Find "name" in CDecl's LL. return 0 if not found @@ -114,17 +115,17 @@ struct[ CDecl : :find ( name self -- cdecl ) llnext dup if _ then nip ; : :find# :find dup _assert ; - : _.children begin nexttype ?dup while dup _printtype ." , " repeat ; + : _.children begin ?dup while dup _printtype ." , " llnext repeat ; : :. ( self -- ) >r \ print without children r@ offset if '+' emit r@ offset .x? spc> then r@ :struct? if ." struct" else r@ type _printtype r@ lvl for '*' emit next then r@ name c@ if spc> r@ name stype then r@ nbelem if '[' emit r@ nbelem . ']' emit then - r@ :funcsig? if '(' emit r@ _.children ')' emit then rdrop ; + r@ :funcsig? if '(' emit r@ args _.children ')' emit then rdrop ; \ Because of possibilities of infinite recursion, structs are not fully \ expanded in vanilla :. - : :.struct dup :struct? _assert dup :. ." {" _.children '}' emit ; + : :.struct dup :struct? _assert dup :. ." {" llnext _.children '}' emit ; : :export ( self -- ) dup :struct? _assert \ we can only export structs