Skip to content

Commit

Permalink
new cast syntax and fix assignment to parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
apache-hb committed Aug 9, 2024
1 parent 39a8470 commit 8802768
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion data/examples/config/config.ct
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def isSpace(letter: char): bool = letter == ' ' || letter == '\t' || letter == '
def readUntil(current: *char, terminator: char): StringView {
var front = current;
while *current != terminator && *current != '\0' {
current = current + 1;
current = &current[1];
}

return .{
Expand Down
2 changes: 2 additions & 0 deletions src/cthulhu/check/src/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "cthulhu/events/events.h"

#include "cthulhu/tree/ops.h"
#include "cthulhu/util/util.h"
#include "cthulhu/util/types.h"

Expand Down Expand Up @@ -491,6 +492,7 @@ static void check_single_expr(check_t *check, const tree_t *expr)
case eTreeExprField:
case eTreeExprSizeOf:
case eTreeExprAlignOf:
case eTreeExprAddressOf:
break;

case eTreeExprOffsetOf:
Expand Down
1 change: 1 addition & 0 deletions src/language/ctu/src/ctu.l
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ SUFFIX ("u"|"ul"|"l"|"uz")?
"out" { return OUT; }

"as" { return AS; }
"cast" { return CAST; }

"__sizeof" { return SIZEOF; }
"__alignof" { return ALIGNOF; }
Expand Down
2 changes: 2 additions & 0 deletions src/language/ctu/src/ctu.y
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ void ctuerror(where_t *where, void *state, scan_t *scan, const char *msg);
OUT "`out`"

AS "`as`"
CAST "`cast`"

SIZEOF "`__sizeof`"
ALIGNOF "`__alignof`"
Expand Down Expand Up @@ -473,6 +474,7 @@ primary_expr: LPAREN expr RPAREN { $$ = $2; }
| STRING { $$ = ctu_expr_string(x, @$, $1.text, $1.length); }
| CHARACTER { $$ = ctu_expr_char(x, @$, $1.text, $1.length); }
| path { $$ = ctu_expr_name(x, @$, $1); }
| CAST LPAREN expr AS type RPAREN { $$ = ctu_expr_cast(x, @$, $3, $5); }
| AS LT type GT LPAREN expr RPAREN { $$ = ctu_expr_cast(x, @$, $6, $3); }
| init { $$ = $1; }
| SIZEOF LPAREN type RPAREN { $$ = ctu_builtin_sizeof(x, @$, $3); }
Expand Down
10 changes: 5 additions & 5 deletions src/language/ctu/src/sema/decl/function.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ static void add_param(ctu_sema_t *sema, tree_t *param)
const char *id = tree_get_name(param);
const node_t *node = tree_get_node(param);

if (!tree_is(ty, eTreeTypeStruct))
{
ctu_add_decl(sema->sema, eCtuTagValues, id, param);
return;
}
// if (!tree_is(ty, eTreeTypeStruct))
// {
// ctu_add_decl(sema->sema, eCtuTagValues, id, param);
// return;
// }

tree_t *ref = tree_type_reference(node, id, ty);

Expand Down

0 comments on commit 8802768

Please sign in to comment.