//Check whether all globals are constant
sem_check_constant(ast);
+ // Move all vardecls to the top of the function
+ sem_check_vardecls(ast);
+
// Check that all functions return and mark void
sem_check_return(ast);
// Check that a main function exists with the correct type
sem_check_main(ast);
- // Move all vardecls to the top of the function
- sem_check_vardecls(ast);
-
return ast;
}
struct type *a1, struct type *a2, struct type *rt, struct type *sigma)
{
struct subst *s1 = infer_expr(gamma, l, a1);
- struct subst *s2 = infer_expr(subst_apply_g(s1, gamma), r, a2);
+ struct subst *s2 = infer_expr(subst_apply_g(s1, gamma), r, subst_apply_t(s1, a2));
struct subst *s3 = subst_union(s2, s1);
struct subst *s4 = unify(l->loc, subst_apply_t(s3, sigma), rt);
return subst_union(s4, s3);
struct type *a, struct type *rt, struct type *sigma)
{
struct subst *s1 = infer_expr(gamma, e, a);
- struct subst *s2 = unify(e->loc, subst_apply_t(s1, sigma), rt);
+ struct subst *s2 = unify(e->loc, subst_apply_t(s1, sigma), subst_apply_t(s1, rt));
return subst_union(s2, s1);
}
return s0;
case svardecl:
f1 = gamma_fresh(gamma);
- s0 = infer_expr(gamma, stmt->data.svardecl->expr, f1);
+ if (stmt->data.svardecl->expr != NULL)
+ s0 = infer_expr(gamma, stmt->data.svardecl->expr, f1);
+ else
+ s0 = subst_id();
if (stmt->data.svardecl->type != NULL) {
s1 = unify(stmt->loc, f1, stmt->data.svardecl->type);
type_free(f1);