From 761a2aa296abf68a75dae3eb68299449991ad6be Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Sun, 20 Jun 2021 17:11:37 +0200 Subject: [PATCH] :art: template ops stability --- src/parse/check.c | 3 +-- src/parse/operator.c | 25 ++++++++++++++++--------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/parse/check.c b/src/parse/check.c index eb38a44d..53e19d2c 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -721,7 +721,6 @@ ANN static Type check_exp_call_template(const Env env, Exp_Call *exp) { Tmpl *tm = fdef->base->tmpl; if (tm->call) return check_predefined(env, exp, value, tm, fdef); DECL_OO(const Type_List, tl, = check_template_args(env, exp, tm, fdef)); - ; Tmpl tmpl = {.call = tl}; ((Exp_Call *)exp)->tmpl = &tmpl; DECL_OO(const Func, func, = get_template_func(env, exp, value)); @@ -896,7 +895,7 @@ ANN2(1) static inline bool curried(const Env env, Exp exp) { } ANN static Type check_exp_call(const Env env, Exp_Call *exp) { - if (curried(env, exp->args)) return env->gwion->type[et_curry]; + if (env->scope->allow_curry && curried(env, exp->args)) return env->gwion->type[et_curry]; if (exp->tmpl) { DECL_BO(const m_bool, ret, = func_check(env, exp)); if (!ret) return exp_self(exp)->type; diff --git a/src/parse/operator.c b/src/parse/operator.c index c38e8efe..17be1b61 100644 --- a/src/parse/operator.c +++ b/src/parse/operator.c @@ -186,26 +186,32 @@ ANN static Type op_check_inner(const Env env, struct OpChecker *ock, //! check if type matches for template operator ANN bool _tmpl_match(const Env env, const Type t, Type_Decl *const td, - Specialized_List *sl) { - if (!td->next && td->xid == (*sl)->xid) { - *sl = (*sl)->next; + Specialized_List *slp) { + const Specialized_List sl = *slp; + if (sl && !td->next && !td->types && td->xid == sl->xid) { + *slp = sl->next; return true; } const Type base = known_type(env, td); - return isa(t, base) > 0; + return base ? isa(t, base) > 0 : false; } //! check Func_Base matches for template operator +// usage of `is_class` is supicious rn ANN bool tmpl_match(const Env env, const struct Op_Import *opi, Func_Base *const base) { Specialized_List sl = base->tmpl->list; const Arg_List arg = base->args; if (opi->lhs) { - if (fbflag(base, fbflag_unary) || - !_tmpl_match(env, opi->lhs, arg->td, &sl) || - (opi->rhs && fbflag(base, fbflag_postfix)) || - !_tmpl_match(env, opi->rhs, arg->next->td, &sl)) - return false; + if (!_tmpl_match(env, opi->lhs, arg->td, &sl)) + return false; + if (fbflag(base, fbflag_postfix)) + return !!opi->rhs; + if (!fbflag(base, fbflag_unary)) { + if(!opi->rhs)return false; + if (!_tmpl_match(env, opi->rhs, arg->next->td, &sl)) + return false; + } else if(opi->rhs) return false; } else { if (!fbflag(base, fbflag_unary) || !_tmpl_match(env, opi->rhs, arg->td, &sl)) @@ -248,6 +254,7 @@ ANN static Type op_check_tmpl(const Env env, struct Op_Import *opi) { const Vector v = &nspc->info->op_tmpl; for (m_uint i = vector_size(v) + 1; --i;) { const Func_Def fdef = (Func_Def)vector_at(v, i - 1); + if(opi->op != fdef->base->xid) continue; if (!tmpl_match(env, opi, fdef->base)) continue; return op_def(env, opi, fdef); } -- 2.43.0