Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/hvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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];
}
}
Expand Down