diff options
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | cgen.c | 2 | ||||
-rwxr-xr-x | tests/test.sh | 5 | ||||
-rw-r--r-- | types.c | 8 | ||||
-rw-r--r-- | types.h | 8 |
5 files changed, 17 insertions, 8 deletions
@@ -3,7 +3,7 @@ toc a.out out.c point.c -*.top +*.swp tests/**/*.c tests/**/*.bin tests/**/got @@ -186,7 +186,7 @@ static inline void *cgen_malloc(CGenerator *g, size_t sz) { /* indent iff needed */ static inline void cgen_indent(CGenerator *g) { if (g->will_indent) { - for (int i = 0; i < g->indent_lvl; ++i) + for (unsigned i = 0; i < g->indent_lvl; ++i) fprintf(cgen_writing_to(g), "\t"); g->will_indent = false; } diff --git a/tests/test.sh b/tests/test.sh index 8adf412..4cb04dc 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -37,6 +37,11 @@ failed=false do_tests() { valgrind -q --exit-on-first-error=yes --error-exitcode=1 $TOC "$1.toc" -o out.c || exit 1 for CC in "gcc -O0 -g" "tcc" "clang -O3 -s"; do + if [ "$1" = "sizeof" ]; then + if [ "$CC" = "tcc" ]; then + continue # some versions of tcc don't have _Alignof + fi + fi printf "Running test $1 with C compiler $CC... " compile_c "$1" ./a.out > got @@ -676,12 +676,14 @@ static Status type_of_ident(Typer *tr, Location where, Identifier *ident, Type * if (d->flags & DECL_FOUND_TYPE) { *t = *decl_type_at_index(d, decl_ident_index(d, i)); + assert(t->flags & TYPE_IS_RESOLVED); return true; } else { if ((d->flags & DECL_HAS_EXPR) && (d->expr.kind == EXPR_FN)) { /* allow using a function before declaring it */ if (!type_of_fn(tr, d->expr.fn, &d->expr.type, 0)) return false; *t = d->expr.type; + t->flags |= TYPE_IS_RESOLVED; /* for function templates */ return true; } else { if (where.start <= d->where.end) { @@ -689,6 +691,7 @@ static Status type_of_ident(Typer *tr, Location where, Identifier *ident, Type * err_print(where, "Use of identifier %s before its declaration.", s); info_print(d->where, "%s will be declared here.", s); free(s); + return false; } else { if (d->flags & DECL_INFER) { err_print(where, "Use of identifier before it has been inferred. You are trying to do stuff with inference which toc doesn't support."); @@ -698,7 +701,6 @@ static Status type_of_ident(Typer *tr, Location where, Identifier *ident, Type * if (!types_decl(tr, d)) return false; return type_of_ident(tr, where, ident, t); } - return false; } } } break; @@ -720,6 +722,7 @@ static Status type_of_ident(Typer *tr, Location where, Identifier *ident, Type * if (i == fo->index) { t->kind = TYPE_BUILTIN; t->builtin = BUILTIN_I64; + t->flags = TYPE_IS_RESOLVED; } else { assert(i == fo->value); *t = fo->type; @@ -1469,6 +1472,7 @@ static Status types_expr(Typer *tr, Expression *e) { } if (fn_has_any_const_params(e->fn) || fn_type_has_varargs(&e->type.fn)) { e->fn->instances = typer_calloc(tr, 1, sizeof *e->fn->instances); + t->flags |= TYPE_IS_RESOLVED; /* pretend this type is resolved, even though its children aren't to fix some assertions */ } else { if (!types_fn(tr, e->fn, &e->type, NULL)) { return false; @@ -3025,7 +3029,7 @@ static Status types_expr(Typer *tr, Expression *e) { return false; } ret: - t->flags |= TYPE_IS_RESOLVED; + assert(t->flags & TYPE_IS_RESOLVED); return true; } @@ -1,6 +1,6 @@ /* toc's types. Note that although these types are in the public domain, -the code which uses them (i.e. most of the rest of toc) is not. +the code which uses them (i.e. most of the rest of toc) is not necessarily. This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or @@ -163,8 +163,8 @@ typedef union Value { I64 i64; bool boolv; char charv; - float f32; - double f64; + F32 f32; + F64 f64; struct FnExpr *fn; void *arr; void *ptr; @@ -1043,7 +1043,7 @@ typedef struct CGenerator { Allocator *allocr; FILE *outc; IdentID ident_counter, lbl_counter; - int indent_lvl; /* how many levels of indentation? */ + U16 indent_lvl; /* how many levels of indentation? */ bool will_indent; /* will the next thing be indented? */ ParsedFile *file; Block *block; |