summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.c2
-rw-r--r--parse.c13
-rw-r--r--test.toc3
-rw-r--r--types.c2
4 files changed, 17 insertions, 3 deletions
diff --git a/main.c b/main.c
index 3c0e4ef..ab17fe6 100644
--- a/main.c
+++ b/main.c
@@ -1,7 +1,5 @@
/*
TODO:
-structs
-structs can't have tuple members
dot
length of slice/arr with .len
verify size of struct, align of fields
diff --git a/parse.c b/parse.c
index 639ec90..78ad636 100644
--- a/parse.c
+++ b/parse.c
@@ -479,6 +479,15 @@ static bool parse_type(Parser *p, Type *type) {
if (!parse_decl(p, &field_decl, DECL_END_SEMICOLON, 0)) {
return false;
}
+ if (field_decl.flags & DECL_FLAG_CONST) {
+ /* TODO */
+ err_print(field_decl.where, "Constant struct members are not supported (yet).");
+ return false;
+ }
+ if (field_decl.flags & DECL_FLAG_HAS_EXPR) {
+ err_print(field_decl.where, "struct members cannot have initializers.");
+ return false;
+ }
long idx = 0;
arr_foreach(field_decl.idents, Identifier, fident) {
Type *ftype = field_decl.type.kind == TYPE_TUPLE ? &field_decl.type.tuple[idx] : &field_decl.type;
@@ -1544,6 +1553,10 @@ static bool parse_decl(Parser *p, Declaration *d, DeclEndKind ends_with, uint16_
goto ret_false;
}
d->type = type;
+ if (type.kind == TYPE_TUPLE && arr_len(d->type.tuple) != arr_len(d->idents)) {
+ err_print(d->where, "Expected to have %lu things declared in declaration, but got %lu.", (unsigned long)arr_len(d->type.tuple), (unsigned long)arr_len(d->idents));
+ goto ret_false;
+ }
}
const char *end_str = NULL;
switch (ends_with) {
diff --git a/test.toc b/test.toc
index ebf613f..be70155 100644
--- a/test.toc
+++ b/test.toc
@@ -6,8 +6,11 @@ puti @= fn(x: int) {
Point @= struct {
x, y : int;
something:fn(f32);
+ z,asdfasdfasdf:(int,int);
+ safdasdjfhsj@int=3;
};
main @= fn() {
p:Point;
+ // asasdfdsfa:(int,int);
};
diff --git a/types.c b/types.c
index 65534a1..0932496 100644
--- a/types.c
+++ b/types.c
@@ -1206,7 +1206,7 @@ static bool types_decl(Typer *tr, Declaration *d) {
size_t n_idents = arr_len(d->idents);
if (d->type.kind == TYPE_TUPLE) {
if (n_idents != arr_len(d->type.tuple)) {
- err_print(d->where, "Expected to have %lu things declared in declaration, but got %lu.", (unsigned long)n_idents);
+ err_print(d->where, "Expected to have %lu things declared in declaration, but got %lu.", (unsigned long)arr_len(d->type.tuple), (unsigned long)n_idents);
success = false;
goto ret;
}