duskos

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

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

cc: tweak AST for initialization assignment

When we have a declaration followed by an assignment, instead of generating a
"=" binop, we add the assigned expression as a children to AST_DECLARE.

This will simplify things for what's coming...

Diffstat:
Mfs/cc/ast.fs | 7++-----
Mfs/cc/gen.fs | 13+++++++++----
2 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/fs/cc/ast.fs b/fs/cc/ast.fs @@ -237,13 +237,10 @@ current to parseExpression : parseDeclarationList ( type stmtsnode -- ) parseDeclare nextt dup S" =" s= not if ';' expectChar drop exit then - drop ( dnode ) dup ast.decl.name ( dnode name ) - swap parentnode AST_BINARYOP newnode ( name anode ) 12 ( = ) , - AST_LVALUE newnode ( name lvnode ) swap , parentnode ( anode ) - nextt dup S" {" s= if + drop ( dnode ) nextt dup S" {" s= if drop parseList else parseExpression then - read; ( anode expr-or-list ) swap addnode ; + read; ( dnode expr-or-list ) swap addnode ; : parseArgSpecs ( funcnode -- ) nextt '(' expectChar AST_ARGSPECS newnode nextt ( argsnode tok ) diff --git a/fs/cc/gen.fs b/fs/cc/gen.fs @@ -132,8 +132,15 @@ BOPSCNT wordtbl bopgentblpost ( -- ) 'w vm||, ( || ) :w ( = ) vmmov, ; +: decl>op ( dnode -- ) + dup ast.decl.sfoff sf+>op ( dnode ) + ast.decl.nbelem ( nbelem ) 1 > if &op>op then ; + ASTIDCNT wordtbl gentbl ( node -- ) -'w drop ( Declare ) +:w ( Declare ) dup firstchild ?dup if ( dnode node ) + selop1 gennode ( value in op1 ) op1<>op2 ( dnode ) + selop1 decl>op vmmov, + else drop then ; 'w genchildren ( Unit ) :w ( Function ) _debug if ." debugging: " dup ast.func.name stype nl> then @@ -151,9 +158,7 @@ ASTIDCNT wordtbl gentbl ( node -- ) \ we run ops$ between each statement to discard any unused Result firstchild ?dup if begin dup gennode ops$ nextsibling ?dup not until then ; 'w genchildren ( ArgSpecs ) -:w ( LValue ) - lv>decl dup ast.decl.sfoff sf+>op ( dnode ) - ast.decl.nbelem ( nbelem ) 1 > if &op>op then ; +:w ( LValue ) lv>decl decl>op ; :w ( UnaryOp ) _debug if ." unaryop: " dup printast nl> .ops then dup genchildren