From: Jérémie Astor Date: Sun, 16 May 2021 13:44:11 +0000 (+0200) Subject: :art: Improve contracts (check at instantation) X-Git-Tag: nightly~652 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=324460f8813188f09286faea507d58cce50ca669;p=gwion.git :art: Improve contracts (check at instantation) --- diff --git a/src/emit/emit.c b/src/emit/emit.c index 90c5533f..f66d5888 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -891,6 +891,11 @@ ANN static m_bool emit_decl(const Emitter emit, const Exp_Decl* decl) { CHECK_BB(emit_exp_decl_non_static(emit, decl, list->self, r, var)); else CHECK_BB(emit_exp_decl_global(emit, decl, list->self, r, var)); + if(tflag(list->self->value->type, tflag_contract) && !exp_getvar(exp_self(decl))) { + const Type t = list->self->value->type; + struct Op_Import opi = { .lhs=t->info->base_type, .op=insert_symbol("@implicit"), .rhs=t }; + CHECK_BB(op_emit(emit, &opi)); + } set_late(emit->gwion, decl, list->self); if(GET_FLAG(array_base(v->type), abstract) && !GET_FLAG(decl->td, late) && GET_FLAG(v, late)) { env_warn(emit->env, decl->td->pos, _("Type '%s' is abstract, use late"), v->type->name); diff --git a/src/env/env.c b/src/env/env.c index 4105abba..1331ea86 100644 --- a/src/env/env.c +++ b/src/env/env.c @@ -41,6 +41,7 @@ ANN void env_reset(const Env env) { env->class_def = NULL; env->func = NULL; env->scope->depth = 0; + env->scope->in_try = false; } ANN void release_ctx(struct Env_Scope_ *a, struct Gwion_ *gwion) { diff --git a/src/parse/check.c b/src/parse/check.c index ccaf3651..5e6a37f3 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -938,6 +938,7 @@ const Func f = exp_self(call)->type->info->func; ANN m_bool check_type_def(const Env env, const Type_Def tdef) { if(tdef->when) { + set_tflag(tdef->type, tflag_contract); const Var_Decl decl = new_var_decl(env->gwion->mp, insert_symbol("self"), NULL, tdef->when->pos); const Arg_List args = new_arg_list(env->gwion->mp, cpy_type_decl(env->gwion->mp, tdef->ext), decl, NULL); Func_Base *fb = new_func_base(env->gwion->mp, type2td(env->gwion, tdef->type, tdef->pos), diff --git a/src/parse/scan0.c b/src/parse/scan0.c index ff214eb5..02caef21 100644 --- a/src/parse/scan0.c +++ b/src/parse/scan0.c @@ -179,11 +179,12 @@ ANN m_bool scan0_type_def(const Env env, const Type_Def tdef) { struct Op_Import opi = { .lhs=base, .rhs=tdef->type }; op_cpy(env, &opi); scan0_explicit_distinct(env, base, tdef->type); -// type_addref(tdef->type); // maybe because of scope_iter in nspc_free_values + type_addref(tdef->type); // maybe because of scope_iter in nspc_free_values } else set_tflag(tdef->type, tflag_typedef); if(global) env_pop(env, 0); + tdef->type->info->base_type = base; return GW_OK; }