From abbf3fe3821ec7856b9d1cb059e52206e0f410fe Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Wed, 11 Nov 2020 22:17:40 +0100 Subject: [PATCH] :art: Fixes --- src/parse/func_resolve_tmpl.c | 46 +++++++++++++++++------------------ 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/src/parse/func_resolve_tmpl.c b/src/parse/func_resolve_tmpl.c index 7a8b796d..1e15b894 100644 --- a/src/parse/func_resolve_tmpl.c +++ b/src/parse/func_resolve_tmpl.c @@ -38,8 +38,25 @@ ANN static m_bool check_call(const Env env, const Exp_Call* exp) { return GW_OK; } +ANN static inline m_bool tmpl_valid(const Env env, const Func_Def fdef) { + return safe_fflag(fdef->base->func, fflag_valid) || + check_traverse_fdef(env, fdef) > 0; +} + +ANN static Func ensure_tmpl(const Env env, const Func_Def fdef, const Exp_Call *exp) { + if(!tmpl_valid(env, fdef)) + return NULL; + const Func f = fdef->base->func; + const Func next = f->next; + f->next = NULL; + const Func func = find_func_match(env, f, exp->args); + f->next = next; + if(func) + set_fflag(func, fflag_tmpl | fflag_valid); + return func; +} -ANN static inline Func fptr_ensure(const Env env, struct ResolverArgs* ra, const Fptr_Def fptr ) { +ANN static inline Func ensure_fptr(const Env env, struct ResolverArgs* ra, const Fptr_Def fptr) { CHECK_BO(traverse_fptr_def(env, fptr)) return find_func_match(env, fptr->base->func, ra->e->args); } @@ -52,16 +69,15 @@ ANN static Func fptr_match(const Env env, struct ResolverArgs* ra) { return exists->info->func; const Func_Def base = v->d.func_ref ? v->d.func_ref->def : ra->e->func->info->type->info->func->def; const Tmpl tmpl = { .list=base->base->tmpl->list, .call=ra->types }; - CHECK_BO(template_push_types(env, &tmpl)) - Func m_func = NULL; + CHECK_BO(template_push_types(env, &tmpl)); Func_Base *const fbase = cpy_func_base(env->gwion->mp, base->base); fbase->xid = sym; fbase->tmpl->base = 0; fbase->tmpl->call = cpy_type_list(env->gwion->mp, ra->types); const Fptr_Def fptr = new_fptr_def(env->gwion->mp, fbase); - const Func func = fptr_ensure(env, ra, fptr); - if(func) - nspc_add_type_front(v->from->owner, sym, actual_type(env->gwion, func->value_ref->type)); + const Func m_func = ensure_fptr(env, ra, fptr); + if(m_func) + nspc_add_type_front(v->from->owner, sym, actual_type(env->gwion, m_func->value_ref->type)); if(fptr->type) type_remref(fptr->type, env->gwion); free_fptr_def(env->gwion->mp, fptr); @@ -69,24 +85,6 @@ ANN static Func fptr_match(const Env env, struct ResolverArgs* ra) { return m_func; } -ANN static inline m_bool tmpl_valid(const Env env, const Func_Def fdef) { - return safe_fflag(fdef->base->func, fflag_valid) || - check_traverse_fdef(env, fdef) > 0; -} - -ANN static Func ensure_tmpl(const Env env, const Func_Def fdef, const Exp_Call *exp) { - if(!tmpl_valid(env, fdef)) - return NULL; - const Func f = fdef->base->func; - const Func next = f->next; - f->next = NULL; - const Func func = find_func_match(env, f, exp->args); - f->next = next; - if(func) - set_fflag(func, fflag_tmpl | fflag_valid); - return func; -} - ANN static Func tmpl_exists(const Env env, struct ResolverArgs* ra, const Value exists) { if(env->func == exists->d.func_ref) return find_func_match(env, env->func, ra->e->args) ? env->func : NULL; -- 2.43.0