duskos

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

commit 68afc75d2fa373ac08d67ca661a0e7cdd7e2dae2
parent fe7cbdf69d36d1ddbb9634177954959297a468b7
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Sun, 26 Jun 2022 14:35:14 -0400

cc: move "sfoff" field from Varmap to AST_DECLARE and remove Varmap

Will make things simpler for my upcoming move...

Diffstat:
Mfs/cc/ast.fs | 32+++++++++++++++++---------------
Mfs/cc/gen.fs | 11+++++------
Mfs/cc/map.fs | 17+++++++----------
3 files changed, 29 insertions(+), 31 deletions(-)

diff --git a/fs/cc/ast.fs b/fs/cc/ast.fs @@ -51,19 +51,20 @@ create bopsprectbl 1 c, 1 c, 0 c, 0 c, 2 c, 2 c, 2 c, 2 c, \ 13 = unused 14 const AST_FUNCALL -NODESZ ufield ast.decl.name -NODESZ 4 + ufield ast.decl.type -NODESZ 8 + ufield ast.decl.nbelem -NODESZ ufield ast.func.name -NODESZ 4 + ufield ast.func.fmap -NODESZ 8 + ufield ast.func.type -NODESZ ufield ast.const.value -NODESZ ufield ast.lvalue.name -NODESZ ufield ast.uop.opid -NODESZ ufield ast.pop.opid -NODESZ ufield ast.bop.opid -NODESZ ufield ast.funcall.funcname -NODESZ 4 + ufield ast.funcall.fmap +NODESZ ufield ast.decl.name +NODESZ 4 + ufield ast.decl.type +NODESZ 8 + ufield ast.decl.nbelem +NODESZ 12 + ufield ast.decl.sfoff +NODESZ ufield ast.func.name +NODESZ 4 + ufield ast.func.fmap +NODESZ 8 + ufield ast.func.type +NODESZ ufield ast.const.value +NODESZ ufield ast.lvalue.name +NODESZ ufield ast.uop.opid +NODESZ ufield ast.pop.opid +NODESZ ufield ast.bop.opid +NODESZ ufield ast.funcall.funcname +NODESZ 4 + ufield ast.funcall.fmap ASTIDCNT stringlist astidnames "declare" "unit" "function" "return" "constant" "stmts" "args" "lvalue" "unaryop" "postop" "binop" "list" "if" "_" "call" @@ -79,7 +80,8 @@ ASTIDCNT wordtbl astdatatbl ( node -- node ) :w ( Declare ) _[ dup ast.decl.type printtype spc> dup ast.decl.name stype - dup ast.decl.nbelem dup 1 > if _[ .x _] else drop then _] ; + dup ast.decl.nbelem dup 1 > if _[ .x _] else drop then spc> + dup ast.decl.sfoff .x1 _] ; 'w noop ( Unit ) :w ( function ) _[ dup ast.func.type printtype spc> @@ -231,7 +233,7 @@ current to parseExpression expectIdent ( dnode type name ) , , ( dnode ) nextt dup S" [" s= if ( dnode tok ) drop nextt parse _assert nextt ']' expectChar ( nbelem ) else - to nexttputback 0 ( nbelem ) then , ; + to nexttputback 0 ( nbelem ) then , 0 ( sfoff ) , ; : parseDeclarationList ( type stmtsnode -- ) parseDeclare nextt dup S" =" s= not if ';' expectChar drop exit then diff --git a/fs/cc/gen.fs b/fs/cc/gen.fs @@ -55,9 +55,8 @@ alias noop gennode ( node -- ) \ forward declaration : spit ( a u -- ) A>r >r >A begin Ac@+ .x1 next r>A ; : getfuncmap ( node -- funcentry ) AST_FUNCTION parentnodeid ast.func.fmap ; -: lvvar ( lvnode -- ) \ sets Varmap - dup ast.lvalue.name swap getfuncmap ( name funcentry ) - findvarinmap to Varmap ; +: lv>decl ( lvnode -- dnode ) + dup ast.lvalue.name swap getfuncmap ( name funcentry ) findvarinmap ; \ Multiply the value of "node" by a factor of "n" \ TODO: support lvalues and expressions @@ -70,7 +69,7 @@ alias noop gennode ( node -- ) \ forward declaration \ Return the "pointer arithmetic size" of "node". : node*arisz ( node -- n ) dup nodeid AST_LVALUE = if ( node ) - lvvar vmap.decl ( dnode ) dup ast.decl.type ( dnode type ) + lv>decl dup ast.decl.type ( dnode type ) swap ast.decl.nbelem ( nbelem ) 1 > if type*lvl+ then *ariunitsz ( n ) else drop 1 then ; @@ -153,8 +152,8 @@ ASTIDCNT wordtbl gentbl ( node -- ) firstchild ?dup if begin dup gennode ops$ nextsibling ?dup not until then ; 'w genchildren ( ArgSpecs ) :w ( LValue ) - lvvar vmap.sfoff sf+>op ( ) - vmap.decl ast.decl.nbelem ( nbelem ) 1 > if &op>op then ; + lv>decl dup ast.decl.sfoff sf+>op ( dnode ) + ast.decl.nbelem ( nbelem ) 1 > if &op>op then ; :w ( UnaryOp ) _debug if ." unaryop: " dup printast nl> .ops then dup genchildren diff --git a/fs/cc/map.fs b/fs/cc/map.fs @@ -26,19 +26,15 @@ newxdict curmap 12 ufield fmap.address 16 'ufield fmap.vmap -struct Varmap - field vmap.sfoff - field vmap.decl - : _err ( -- ) abort" mapping error" ; \ print curmap in reverse order of parsing : printmap ( -- ) curmap @ ?dup not if exit then begin ( w ) dup wordname[] rtype spc> dup fmap.sfsize .x spc> dup fmap.argsize .x nl> - dup fmap.vmap @ ?dup if begin ( w vmap ) to Varmap - spc> spc> Varmap wordname[] rtype spc> vmap.sfoff .x nl> - Varmap prevword ?dup not until then ( w ) + dup fmap.vmap @ ?dup if begin ( w vmap ) + spc> spc> dup @ printast nl> + prevword ?dup not until then ( w ) prevword ?dup not until ; : Function ( astnode -- entry ) @@ -46,15 +42,16 @@ struct Varmap here swap , 16 allot0 ( entry ) ; : Variable ( dnode -- ) + curmap @ fmap.sfsize over to ast.decl.sfoff ( dnode ) dup ast.decl.name curmap @ fmap.vmap xentry ( dnode ) - curmap @ fmap.sfsize , dup , ( dnode ) + dup , ( dnode ) dup ast.decl.type ( dnode type ) typesize swap ast.decl.nbelem ( nbelem ) 1 max * ( sfsize ) curmap @ to+ fmap.sfsize ; -: findvarinmap ( name funcentry -- varentry ) - fmap.vmap xfind not if _err then ; +: findvarinmap ( name funcentry -- dnode ) + fmap.vmap xfind not if _err then @ ; : findfuncinmap ( name -- funcentry ) curmap xfind not if _err then ;