diff options
-rw-r--r-- | data_structures.c | 17 | ||||
-rw-r--r-- | decls_cgen.c | 2 | ||||
-rw-r--r-- | main.c | 3 | ||||
-rw-r--r-- | misc.c | 8 | ||||
-rw-r--r-- | types.c | 10 | ||||
-rw-r--r-- | types.h | 2 |
6 files changed, 22 insertions, 20 deletions
diff --git a/data_structures.c b/data_structures.c index e16ea0d..37ae242 100644 --- a/data_structures.c +++ b/data_structures.c @@ -24,8 +24,8 @@ For more information, please refer to <http://unlicense.org/> */ typedef struct ArrHeader { - size_t len; - size_t cap; + U32 len; + U32 cap; MaxAlign data[]; } ArrHeader; @@ -44,13 +44,14 @@ static inline void arr_zero_(void *arr, size_t item_sz) { static WarnUnusedResult void *arr_resv_(void *arr, size_t n, size_t item_sz) { ArrHeader *hdr; + assert(n < U32_MAX); if (arr == NULL) { hdr = err_malloc(item_sz * n + sizeof(ArrHeader)); hdr->len = 0; - hdr->cap = n; + hdr->cap = (U32)n; } else { hdr = arr_hdr(arr); - hdr->cap = n; + hdr->cap = (U32)n; hdr = err_realloc(hdr, item_sz * n + sizeof(ArrHeader)); if (hdr->len > hdr->cap) hdr->len = hdr->cap; } @@ -61,11 +62,11 @@ static WarnUnusedResult void *arr_resva_(void *arr, size_t n, size_t item_sz, Al if (arr == NULL) { hdr = allocr_malloc(a, item_sz * n + sizeof(ArrHeader)); hdr->len = 0; - hdr->cap = n; + hdr->cap = (U32)n; } else { hdr = arr_hdr(arr); hdr = allocr_realloc(a, hdr, item_sz * hdr->cap + sizeof(ArrHeader), item_sz * n + sizeof(ArrHeader)); - hdr->cap = n; + hdr->cap = (U32)n; if (hdr->len > hdr->cap) hdr->len = hdr->cap; } return hdr->data; @@ -129,7 +130,7 @@ static WarnUnusedResult void *arr_set_len_(void *arr, size_t n, size_t item_sz) if (n > arr_len(arr)) { arr = arr_resv_(arr, n, item_sz); } - arr_hdr(arr)->len = n; + arr_hdr(arr)->len = (U32)n; /* @OPTIM: shrink */ return arr; } @@ -138,7 +139,7 @@ static WarnUnusedResult void *arr_set_lena_(void *arr, size_t n, size_t item_sz, return arr_cleara_(arr, item_sz, a); } arr = arr_resva_(arr, n, item_sz, a); - arr_hdr(arr)->len = n; + arr_hdr(arr)->len = (U32)n; return arr; } diff --git a/decls_cgen.c b/decls_cgen.c index 608b9fb..80b6a38 100644 --- a/decls_cgen.c +++ b/decls_cgen.c @@ -81,7 +81,7 @@ static void cgen_sdecls_expr(CGenerator *g, Expression *e) { case EXPR_NMS: { char *prefix_part = cgen_nms_prefix_part(g, e->nms); size_t prefix_part_len = strlen(prefix_part); - char const *prev_prefix = g->nms_prefixes ? arr_last(g->nms_prefixes) + const char *prev_prefix = g->nms_prefixes ? arr_last(g->nms_prefixes) : ""; size_t prev_prefix_len = strlen(prev_prefix); char *new_prefix = cgen_malloc(g, prev_prefix_len + prefix_part_len + 1); @@ -30,7 +30,7 @@ use point #except x; optional -Wshadow format errors so that vim/emacs can jump to them --- -make sure that floating point literals are exact as possible +make sure that floating point literals are as exact as possible have some way of doing Infinity and s/qNaN (you can have them be in std/math.toc) once you have a bunch of test code: @@ -38,7 +38,6 @@ once you have a bunch of test code: - try making more Expression members pointers - should val_stack be on the allocator? what about temporary arrays? -->on the contrary, should in_decls be off the allocator? -- branch data: #define if(x) bool join(cond, __LINE__) = x; register_branch(__FILE__, __LINE__, cond); if (join(cond, __LINE__)) error on x ::= {return; 3} struct param inference maybe macros are just inline functions @@ -48,21 +48,21 @@ size_t str_copy(char *dest, size_t destsz, const char *src) { return destsz-1; } -static char *str_dup(char *s) { +static char *str_dup(const char *s) { size_t bufsz = strlen(s)+1; char *ret = malloc(bufsz); memcpy(ret, s, bufsz); return ret; } -static char *cstr(char const *str, size_t len) { +static char *cstr(const char *str, size_t len) { char *ret = malloc(len+1); memcpy(ret, str, len); ret[len] = 0; return ret; } -static bool str_eq_cstr(String s, char const *str) { +static bool str_eq_cstr(String s, const char *str) { return strncmp(s.str, str, s.len) == 0; } @@ -77,7 +77,7 @@ static inline bool strs_equal(const char *a, const char *b) { } #define plural_suffix(x) ((x) == 1 ? "" : "s") -static char const *indefinite_article(char const *s) { +static const char *indefinite_article(const char *s) { /* usually, words starting with "u" use "a" - "a unique thing", "a u64" */ if (*s == 'a' || *s == 'e' || *s == 'i' || *s == 'o') return "an"; @@ -457,7 +457,7 @@ static Type *overriding_type(Type *a, Type *b) { prints an error and returns false if the given expression is not an l-value purpose is something like "take address of" */ -static Status expr_must_lval(Expression *e, char const *purpose) { +static Status expr_must_lval(Expression *e, const char *purpose) { /* NOTE: make sure you update eval when you change this */ assert(e->flags & EXPR_FOUND_TYPE); switch (e->kind) { @@ -2617,6 +2617,7 @@ static Status types_expr(Typer *tr, Expression *e) { } else if ((param->flags & DECL_ANNOTATES_TYPE) && !type_is_builtin(¶m->type, BUILTIN_VARARGS)) { /* add to stuff infer can use */ + /* @OPTIM: don't do this if we're not inferring */ arr_add(decl_types, ¶m->type); arr_add(arg_types, &arg_exprs[i].type); arr_add(arg_wheres, arg_exprs[i].where); @@ -2637,9 +2638,6 @@ static Status types_expr(Typer *tr, Expression *e) { } tr->block = prev; - arr_clear(inferred_idents); - arr_clear(arg_types); - arr_clear(decl_types); { Type *type = inferred_types; @@ -2677,6 +2675,10 @@ static Status types_expr(Typer *tr, Expression *e) { free(inferred_types); } + arr_clear(inferred_idents); + arr_clear(arg_types); + arr_clear(arg_wheres); + arr_clear(decl_types); /* eval compile time arguments */ for (i = 0; i < nparams; ++i) { @@ -1064,5 +1064,5 @@ typedef struct CGenerator { FnExpr *fn; /* which function are we in? (NULL for none) - not used during decls */ Identifier main_ident; Identifiers *globals; - char const **nms_prefixes; /* dynamic (null-terminated) array of namespace prefixes */ + const char **nms_prefixes; /* dynamic (null-terminated) array of namespace prefixes */ } CGenerator; |