diff --git a/src/hvm.c b/src/hvm.c index f5753f1..9b970ac 100644 --- a/src/hvm.c +++ b/src/hvm.c @@ -1955,8 +1955,9 @@ fn PBind* parse_bind_lookup(u32 name, int side, int *skipped) { // Count the number of uses of a target variable in a term // Variables are identified by tag + level (and ext for BJ mode). fn u32 count_uses(Term t, u32 lvl, u8 tgt, u32 ext) { - Term *ts = (Term*)malloc(sizeof(Term) * 1024); // not recursive, since this is a desugared term - int ts_idx = 0; + u32 ts_cap = 1024; + Term *ts = (Term*)malloc(sizeof(Term) * ts_cap); + u32 ts_idx = 0; ts[ts_idx++] = t; u32 uses = 0; @@ -1970,6 +1971,10 @@ fn u32 count_uses(Term t, u32 lvl, u8 tgt, u32 ext) { u32 ari = term_arity(t); for (u32 i = 0; i < ari; i++) { u64 loc = vl + i; + if (ts_idx == ts_cap) { + ts_cap *= 2; + ts = (Term*)realloc(ts, sizeof(Term) * ts_cap); + } ts[ts_idx++] = HEAP[loc]; } }