commit fb22e6486514d8509448b7ec0182d30db6c886d0
parent 606e534395c9548ac7f6f52d01f2f3dc10d8f0a6
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Wed, 5 Oct 2022 07:46:54 -0400
cc: add support for typecasting syntax
It has no effect, but it doesn't generate parsing errors anymore.
Diffstat:
3 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/fs/app/cos/cvm.c b/fs/app/cos/cvm.c
@@ -1,9 +1,9 @@
// This doesn't compile. It's a prototype of what it will look like.
// TODO: NULL
-// TODO: typecasting studs (we don't have a checker yet, but support the syntax)
// TODO: memset()
// TODO: fseek() fopen() fclose()
// TODO: implement "static" logic for global variables
+// TODO: allow usage of system structs
#[
$10000 const MEMSIZE
diff --git a/fs/cc/ast.fs b/fs/cc/ast.fs
@@ -345,10 +345,16 @@ alias noop parseFactor ( tok -- node ) \ forward declaration
\ 5. An expression inside () parens.
\ 6. A string literal
\ 7. pspop()
+\ 8. a typecast followed by an expression
: _ ( tok -- node )
case
'(' of isChar?^ ( )
- nextt parseExpression nextt ')' expectChar endof
+ \ can be an expression or a typecast
+ nextt dup parseType if ( tok type )
+ \ TODO: actually process the typecast
+ nip parseType* nip ')' expectChar nextt parseExpression
+ else ( tok ) parseExpression nextt ')' expectChar then
+ endof
'"' of isChar?^ ( )
StrLit :new here 0 c, ['] ," with-stdin<
here over - 1- swap c! ( node )
diff --git a/fs/tests/cc/test.c b/fs/tests/cc/test.c
@@ -24,7 +24,7 @@ int exprbinops() {
}
int binopand() {
int a=$ff;
- return a & 42;
+ return (unsigned int)a & 42;
}
int binopor() {
int a=2;