commit ae1f937b4e7dca07bbd7a2752c26e58fedcea5dd
parent 5a7c26b53082b3f3127bc24fcd008427c298aded
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Fri, 17 Jun 2022 09:58:54 -0400
cc: add return type info to function AST
Diffstat:
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/fs/cc/ast.fs b/fs/cc/ast.fs
@@ -37,7 +37,7 @@ create bopsprectbl 1 c, 1 c, 0 c, 0 c, 2 c, 2 c, 2 c, 2 c,
15 const ASTIDCNT
0 const AST_DECLARE \ data1=name data2='*' levels data3=type
1 const AST_UNIT
-2 const AST_FUNCTION \ data1=name data2=MAP_FUNCTION
+2 const AST_FUNCTION \ data1=name data2=MAP_FUNCTION data3=type
3 const AST_RETURN
4 const AST_CONSTANT \ data1=value
5 const AST_STATEMENTS
@@ -67,11 +67,13 @@ ASTIDCNT stringlist astidnames
ASTIDCNT wordtbl astdatatbl ( node -- node )
:w ( Declare ) _[
+ dup data3 printtype spc>
dup data1 stype spc>
- dup data2 .x1 spc>
- dup data3 printtype _] ;
+ dup data2 .x1 _] ;
'w noop ( Unit )
-'w _s ( Function )
+:w ( function ) _[
+ dup data3 printtype spc>
+ dup data1 stype _] ;
'w noop ( Return )
'w _i ( Constant )
'w noop ( Statements )
@@ -235,12 +237,11 @@ alias noop parseStatements ( funcnode -- ) \ forward declaration
current to parseStatements
: parseFunction ( unitnode tok -- )
- swap AST_FUNCTION newnode swap , 0 , ( funcnode )
+ parseType _assert ( unode type ) swap AST_FUNCTION newnode ( type fnode )
+ nextt expectIdent , 0 , ( type fnode ) swap ,
dup parseArgSpecs parseStatements ;
: parseast ( -- )
AST_UNIT createnode dup to curunit
nextt? ?dup not if exit then begin ( unitnode tok )
- parseType _assert drop
- nextt expectIdent over swap parseFunction ( unitnode )
- nextt? ?dup not until ( unitnode ) drop ;
+ over swap parseFunction ( unitnode ) nextt? ?dup not until ( unitnode ) drop ;