duskos

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

commit 92dea750dbe0c60307046301462264cfc8bfb590
parent 9961fac9d849d9ec27757d80aef544957052835a
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Fri, 10 Jun 2022 12:08:00 -0400

cc: clean up ast.fs further

Diffstat:
Mfs/cc/ast.fs | 40++++++++++++++--------------------------
1 file changed, 14 insertions(+), 26 deletions(-)

diff --git a/fs/cc/ast.fs b/fs/cc/ast.fs @@ -68,13 +68,6 @@ create astidnames 7 c, ," declare" 4 c, ," unit" 8 c, ," function" : astid ( node -- id ) nodeid $3f and ; : idname ( id -- str ) astidnames slistiter ; -\ is currently active node empty? -: activeempty? ( -- f ) activenode firstchild not ; -: seqclose ( -- ) - activenode ?dup not if abort" can't go beyond root!" then - 0 over cslots! begin parentnode dup nodeclosed? not until - to activenode ; - : _[ '[' emit ; : _] ']' emit ; @@ -108,27 +101,21 @@ ASTIDCNT wordtbl astdatatbl ( node -- node ) ')' emit then ; -: newnode - createnode dup activenode addnode ( node ) - dup nodeclosed? not if to activenode else drop then ; -: newnode2 ( parent cslots astid -- newnode ) +: newnode ( parent cslots astid -- newnode ) createnode ( parent node ) dup rot addnode ( node ) ; \ AST nodes : Declare ( parent name -- node ) - swap -1 AST_DECLARE newnode2 swap , ; + swap -1 AST_DECLARE newnode swap , ; : Unit ( -- node ) -1 AST_UNIT createnode dup to curunit dup to activenode ; : Function ( unitnode name -- node ) - swap 2 AST_FUNCTION newnode2 swap , 0 , ; -: Return ( -- ) -1 AST_RETURN newnode ; -: Constant ( parent n -- ) swap 0 AST_CONSTANT newnode2 drop , ; -: Statements ( funcnode -- node ) -1 AST_STATEMENTS newnode2 ; -: ArgSpecs ( funcnode -- node ) -1 AST_ARGSPECS newnode2 ; -: UnaryOp ( parentnode opid -- ) swap 1 AST_UNARYOP newnode2 swap , ; -: BinaryOp ( opid -- node ) 2 AST_BINARYOP newnode , ; -: Assign ( name -- ) 1 AST_ASSIGN newnode , ; -: Variable ( parentnode name -- ) swap 0 AST_VARIABLE newnode2 drop , ; -: FunCall ( parentnode name -- ) swap 0 AST_FUNCALL newnode2 drop , ; + swap 2 AST_FUNCTION newnode swap , 0 , ; +: Constant ( parent n -- ) swap 0 AST_CONSTANT newnode drop , ; +: Statements ( funcnode -- node ) -1 AST_STATEMENTS newnode ; +: ArgSpecs ( funcnode -- node ) -1 AST_ARGSPECS newnode ; +: UnaryOp ( parentnode opid -- ) swap 1 AST_UNARYOP newnode swap , ; +: Variable ( parentnode name -- ) swap 0 AST_VARIABLE newnode drop , ; +: FunCall ( parentnode name -- ) swap 0 AST_FUNCALL newnode drop , ; : _err ( tok -- ) stype spc> @@ -199,8 +186,9 @@ ASTIDCNT wordtbl astdatatbl ( node -- node ) then ; : parseDeclare ( tok -- ) - '=' expectChar activenode data1 Assign - _nextt parseExpression ';' expectChar activenode addnode seqclose ; + '=' expectChar _nextt parseExpression ';' expectChar ( expr ) + -1 AST_ASSIGN createnode activenode data1 ( name ) , + ( expr assign ) tuck addnode activenode addnode ; : parseDeclarationList ( stmtsnode -- ) _nextt expectIdent Declare to activenode _nextt parseDeclare ; @@ -218,8 +206,8 @@ ASTIDCNT wordtbl astdatatbl ( node -- node ) begin ( tok ) dup S" }" s= if drop exit then dup S" return" s= if - drop Return _nextt parseExpression ';' expectChar - activenode addnode seqclose + drop _nextt parseExpression ';' expectChar + -1 AST_RETURN createnode tuck addnode activenode addnode else expectType drop activenode parseDeclarationList then _nextt again ;