diff options
author | Kimplul <kimi.h.kuparinen@gmail.com> | 2025-05-07 21:22:38 +0300 |
---|---|---|
committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2025-05-07 21:22:38 +0300 |
commit | 0e0c41af58a0f4ec5a39ce77822de71e5523fcba (patch) | |
tree | 4a02b2f93e61411cbfc6084b0855dba51b326cd9 /src/debug.c | |
parent | 1fadcec6d7b26d34edf3b5b3a293deea0edb4139 (diff) | |
download | fwd-gnc.tar.gz fwd-gnc.zip |
implement enough type analysis for vector examplegnc
+ Big commit, scary
+ Some details still a bit up in the air, mainly about move checking
structure member access ('register' types are freely copied I guess,
same as in rust? How about user types?)
Diffstat (limited to 'src/debug.c')
-rw-r--r-- | src/debug.c | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/src/debug.c b/src/debug.c index f3540f0..8ef4293 100644 --- a/src/debug.c +++ b/src/debug.c @@ -134,14 +134,27 @@ void semantic_error(struct scope *scope, struct ast *node, va_end(args); } +void type_error(struct scope *scope, struct type *type, + const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + struct src_issue issue; + issue.level = SRC_ERROR; + issue.loc = type->loc; + issue.fctx = scope->fctx; + _issue(issue, fmt, args); + va_end(args); +} + void type_mismatch(struct scope *scope, struct ast *node, struct type *l, struct type *r) { - const char *ls = type_str(l); - const char *rs = type_str(r); + char *ls = type_str(l); + char *rs = type_str(r); semantic_error(scope, node, "type mismatch: %s vs %s\n", ls, rs); - free((void *)ls); - free((void *)rs); + free(ls); + free(rs); } void move_error(struct ast *new_use, struct ast *prev_use) @@ -213,6 +226,16 @@ static void _type_str(FILE *f, struct type *type) fprintf(f, "void"); break; + case TYPE_NIL: + fprintf(f, "nil"); + break; + + case TYPE_ARR: + /** @todo length? */ + fprintf(f, "[]"); + _type_list_str(f, tarr_base(type)); + break; + case TYPE_PTR: fprintf(f, "*"); _type_list_str(f, tptr_base(type)); @@ -244,16 +267,10 @@ static void _type_str(FILE *f, struct type *type) _type_list_str(f, type->t0); fprintf(f, ")"); break; - - case TYPE_CONSTRUCT: - fprintf(f, "%s![", type->id); - _type_list_str(f, type->t0); - fprintf(f, "]"); - break; } } -const char *type_str(struct type *t) +char *type_str(struct type *t) { if (!t) return strdup("NULL"); |