diff options
Diffstat (limited to 'src/analyze.c')
| -rw-r--r-- | src/analyze.c | 43 |
1 files changed, 34 insertions, 9 deletions
diff --git a/src/analyze.c b/src/analyze.c index fd1aabb..df00b2f 100644 --- a/src/analyze.c +++ b/src/analyze.c @@ -2,6 +2,7 @@ /* Copyright 2024 Kim Kuparinen < kimi.h.kuparinen@gmail.com > */ #include <fwd/compiler.h> +#include <fwd/tracker.h> #include <fwd/analyze.h> #include <fwd/rewrite.h> #include <fwd/mod.h> @@ -65,9 +66,12 @@ static int analyze_proc(struct state *state, struct scope *scope, group++; /* start of new group */ /* otherwise same or ending group, don't increment */ + struct type *ct = clone_type(param->t); + if (!ct) + return -1; param->t->group = group; - type_append(&proc_type->t0, clone_type(param->t)); + type_append(&proc_type->t0, ct); } node->t = proc_type; @@ -432,7 +436,11 @@ static int analyze_closure(struct state *state, struct scope *scope, } foreach_node(binding, closure_bindings(node)) { - type_append(&callable->t0, clone_type(binding->t)); + struct type *ct = clone_type(binding->t); + if (!ct) + return -1; + + type_append(&callable->t0, ct); } node->t = callable; @@ -608,7 +616,8 @@ static int analyze_construct(struct state *state, struct scope *scope, * a memory allocation? */ } - node->t = tgen_id(strdup(construct_id(node)), node->loc); + + node->t = tgen_id(construct_id(node), node->loc); return 0; } @@ -797,7 +806,11 @@ static int analyze_nil_check(struct state *state, struct scope *scope, struct ast *var = nil_check_ref(node); struct type *base = tptr_base(expr->t); - struct type *ref = tgen_ref(clone_type(base), node->loc); + struct type *ct = clone_type(base); + if (!ct) + return -1; + + struct type *ref = tgen_ref(ct, node->loc); if (!var_type(var)) var_type(var) = ref; @@ -1190,8 +1203,13 @@ int fwd_register(struct fwd_state *state, const char *name, fwd_extern_t func, /* eight bytes is likely more than enough, since first three are * var, then we have four bytes for indexes and one trailing * NULL */ - char *name = calloc(8, sizeof(char)); - assert(name); + char *name = callocc(8, sizeof(char)); + if (!name) { + internal_error("failed allocating ext var name"); + return -1; + } + + track_ptr(name); sprintf(name, "%s%zu", "var", idx); struct ast *new = gen_var(name, fwd_type_kind(type), @@ -1208,8 +1226,7 @@ int fwd_register(struct fwd_state *state, const char *name, fwd_extern_t func, /* append 'return' as a continuation */ if (rtype != FWD_VOID) { - char *name = strdup("ret"); - struct ast *new = gen_var(name, + struct ast *new = gen_var("ret", tgen_closure( fwd_type_kind(rtype), NULL_LOC() @@ -1224,7 +1241,15 @@ int fwd_register(struct fwd_state *state, const char *name, fwd_extern_t func, vars = reverse_ast_list(vars); - struct ast *def = gen_proc(strdup(name), vars, + char *cname = strdupc(name); + if (!cname) { + internal_error("failed allocating ext name copy"); + return -1; + } + + track_ptr(cname); + + struct ast *def = gen_proc(cname, vars, fwd_type_kind(rtype), NULL, NULL_LOC() ); |
