duskos

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

commit 99fefa94491054fd2ed731d0627e6947f8dc842c
parent 4440681cb84e5014b61528a62474eb77ac851f37
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Wed,  8 Jun 2022 15:23:57 -0400

cc: replace tree node's "intdata" with data{1,2,3}

Diffstat:
Mfs/cc/ast.fs | 10+++++-----
Mfs/cc/gen.fs | 12++++++------
Mfs/cc/tree.fs | 4+++-
Mtests/testccast.fs | 4++--
4 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/fs/cc/ast.fs b/fs/cc/ast.fs @@ -70,8 +70,8 @@ create astidnames : _[ '[' emit ; : _] ']' emit ; -: _s _[ dup intdata stype _] ; -: _i _[ dup intdata .x _] ; +: _s _[ dup data1 stype _] ; +: _i _[ dup data1 .x _] ; ASTIDCNT wordtbl astdatatbl ( node -- node ) 'w noop @@ -82,9 +82,9 @@ ASTIDCNT wordtbl astdatatbl ( node -- node ) 'w noop ( Statements ) 'w noop ( Arguments ) 'w noop ( Expression ) -:w ( UnaryOp ) _[ dup intdata uopchar emit _] ; +:w ( UnaryOp ) _[ dup data1 uopchar emit _] ; 'w noop ( Factor ) -:w ( BinaryOp ) _[ dup intdata boptoken stype _] ; +:w ( BinaryOp ) _[ dup data1 boptoken stype _] ; : printast ( node -- ) ?dup not if ." null" exit then @@ -184,7 +184,7 @@ ASTIDCNT wordtbl astparsetbl swap activeempty? if _err then \ can't start an expression with a binop ( bopid tok ) drop activenode lastchild ( bopid prev ) dup astid AST_BINARYOP = if - ( bopid tgt ) 2dup intdata bopprec swap bopprec > if ( bopid tgt ) + ( bopid tgt ) 2dup data1 bopprec swap bopprec > if ( bopid tgt ) \ new binop has a higher precedence, steal right operand! firstchild nextsibling then then binopswap exit then diff --git a/fs/cc/gen.fs b/fs/cc/gen.fs @@ -66,24 +66,24 @@ ASTIDCNT wordtbl gentbl ( node -- ) 'w _err 'w genchildren ( Unit ) :w ( Function ) - _debug if ." debugging: " dup intdata stype nl> then - dup intdata entry genchildren + _debug if ." debugging: " dup data1 stype nl> then + dup data1 entry genchildren _debug if current here current - spit nl> then ; :w ( Return ) genchildren ebp 4 i32 sub, [ebp] eax mov, ; -:w ( Constant ) eax intdata i32 mov, ; +:w ( Constant ) eax data1 i32 mov, ; :w ( Statements ) genchildren ret, ; 'w genchildren ( Arguments ) 'w genchildren ( Expression ) -:w ( UnaryOp ) dup genchildren intdata uopgentbl swap wexec ; +:w ( UnaryOp ) dup genchildren data1 uopgentbl swap wexec ; 'w genchildren ( Factor ) :w ( BinaryOp ) ( node ) >r r@ childcount 2 = not if abort" binop node with more than 2 children!" then r@ firstchild dup nextsibling swap ( n1 n2 ) - gennode bopgentblmiddle r@ intdata wexec eax push, - gennode ebx pop, bopgentblpost r> intdata wexec ; + gennode bopgentblmiddle r@ data1 wexec eax push, + gennode ebx pop, bopgentblpost r> data1 wexec ; : _ ( node -- ) gentbl over astid wexec ; current to gennode diff --git a/fs/cc/tree.fs b/fs/cc/tree.fs @@ -32,7 +32,9 @@ : prevsibling ( node -- prev ) 15 + @ ; : prevsibling! ( prev node -- ) 15 + ! ; : 'data ( node -- 'data ) 19 + ; -: intdata ( node -- n ) 'data @ ; +: data1 ( node -- n ) 'data @ ; +: data2 ( node -- n ) 'data 4 + @ ; +: data3 ( node -- n ) 'data 8 + @ ; : nextnode ( node -- next ) dup firstchild ?dup if nip else dup nextsibling ?dup if nip else diff --git a/tests/testccast.fs b/tests/testccast.fs @@ -7,9 +7,9 @@ parseast curunit firstchild dup astid AST_FUNCTION #eq ( fnode ) : s S" retconst" ; -dup intdata s s= # +dup data1 s s= # firstchild nextsibling dup astid AST_STATEMENTS #eq ( snode ) firstchild dup astid AST_RETURN #eq ( rnode ) firstchild ( expr ) firstchild ( factor ) firstchild dup astid AST_CONSTANT #eq ( cnode ) -intdata 42 #eq +data1 42 #eq