commit 9a24c269b6be9185674169562c720d20cfa54f50
parent ae1f937b4e7dca07bbd7a2752c26e58fedcea5dd
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Fri, 17 Jun 2022 10:08:09 -0400
cc: allow void functions to return no value
... that is, to not push a result on PS on return.
Diffstat:
3 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/fs/cc/ast.fs b/fs/cc/ast.fs
@@ -213,8 +213,10 @@ alias noop parseStatements ( funcnode -- ) \ forward declaration
2 wordtbl statementhandler ( snode -- snode )
:w ( return )
dup AST_RETURN newnode ( snode rnode )
- nextt parseExpression read; ( snode rnode expr )
- swap addnode ( snode ) ;
+ nextt dup S" ;" s= if \ empty returns are allowed
+ 2drop else
+ parseExpression read; ( snode rnode expr ) swap addnode
+ then ( snode ) ;
:w ( if ) dup AST_IF newnode ( snode ifnode )
nextt '(' expectChar
nextt parseExpression ( sn ifn expr ) over addnode
diff --git a/fs/tests/cc/cc.fs b/fs/tests/cc/cc.fs
@@ -20,4 +20,5 @@ ptrset 54 #eq
42 incdec 43 #eq
54 incdecp 55 #eq
exprparens 9 #eq
+cnoop ( no result! ) scnt 0 #eq
testend
diff --git a/fs/tests/cc/test.c b/fs/tests/cc/test.c
@@ -58,3 +58,4 @@ int incdecp(int x) {
int exprparens() {
return (1 + 2) * 3;
}
+void cnoop() {return;}