+++ /dev/null
-fun (x) { return fun(x); }
break;
case dfundecl: {
struct type *f1 = gamma_fresh(gamma);
- struct subst *s = infer_fundecl(gamma, ast->decls[i]->data.dfun, f1);
+ struct subst *s = infer_fundecl(gamma,
+ ast->decls[i]->data.dfun, f1);
f1 = subst_apply_t(s, f1);
- gamma_insert(gamma, ast->decls[i]->data.dfun->ident, scheme_generalise(gamma, subst_apply_t(s, f1)));
-// type_free(f1);
- subst_free(s);
+ gamma_insert(gamma, ast->decls[i]->data.dfun->ident,
+ scheme_generalise(gamma, f1));
gamma_print(gamma, stderr);
fprintf(stderr, "done\n");
+ subst_free(s);
+ type_free(f1);
break;
}
case dcomp:
type_print(type, stderr);
fprintf(stderr, "\n");
-// struct subst *s1, *s2;
+ struct subst *s1;//, *s2;
// struct type *f1, *f2, *f3;
// struct scheme *s;
switch (stmt->type) {
case sassign:
break;
case sif:
+ s1 = infer_expr(gamma, stmt->data.sif.pred, &tybool);
+ subst_apply_g(s1, gamma);
+ subst_free(s1);
break;
case sreturn:
return infer_expr(gamma, stmt->data.sreturn, type);
subst_free(s2);
}
- for (int i = 0; i<fundecl->nargs; i++)
- fundecl->atypes[i] = subst_apply_t(s, fundecl->atypes[i]);
+ for (int i = 0; i<fundecl->nargs; i++) {
+ struct type *t = subst_apply_t(s, fundecl->atypes[i]);
+ type_free(fundecl->atypes[i]);
+ fundecl->atypes[i] = t;
+ }
fundecl->rtype = subst_apply_t(s, fundecl->rtype);
+ ftype = subst_apply_t(s, ftype);
struct subst *r = unify(fundecl->loc, fty, ftype);
type_free(ftype);
+ subst_free(s);
return r;
}
}
}
gamma->nschemes++;
- gamma->vars = realloc(gamma->vars, gamma->nschemes*sizeof(char *));
- gamma->schemes = realloc(gamma->schemes,
+ gamma->vars = safe_realloc(gamma->vars,
+ gamma->nschemes*sizeof(char *));
+ gamma->schemes = safe_realloc(gamma->schemes,
gamma->nschemes*sizeof(struct scheme *));
gamma->vars[gamma->nschemes-1] = safe_strdup(ident);
gamma->schemes[gamma->nschemes-1] = scheme;
if (skip)
continue;
s->nvar++;
- s->var[i] = ftv[i];
+ s->var[i] = safe_strdup(ftv[i]);
}
+ free(ftv);
return s;
}
for (int i = 0; i<*nftv; i++)
if (strcmp((*ftv)[i], r->data.tvar) == 0)
return;
- *ftv = realloc(*ftv, (*nftv+1)*sizeof(char *));
- if (*ftv == NULL)
- perror("realloc");
+ *ftv = safe_realloc(*ftv, (*nftv+1)*sizeof(char *));
(*ftv)[(*nftv)++] = r->data.tvar;
break;
default: