From: Jérémie Astor Date: Sat, 30 Apr 2022 14:38:38 +0000 (+0200) Subject: :art: Improve generic inference X-Git-Tag: nightly~275^2~12 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=c3e2817c8708605c16a7dcb341d3d4af126a21f3;p=gwion.git :art: Improve generic inference --- diff --git a/src/import/import_checker.c b/src/import/import_checker.c index 28848073..14e615eb 100644 --- a/src/import/import_checker.c +++ b/src/import/import_checker.c @@ -69,13 +69,7 @@ ANN Symbol str2sym(const Gwion gwion, const m_str path, const loc_t pos) { struct td_checker tdc = {.str = path, .pos = pos}; return _str2sym(gwion, &tdc, path); } -/* -// only in enum.c -ANN ID_List str2symlist(const Gwion gwion, const m_str path, const loc_t pos) { - DECL_OO(const Symbol, sym, = str2sym(gwion, path, pos)); - return new_id_list(gwion->mp, sym); -} -*/ + ANN m_bool str2var(const Gwion gwion, Var_Decl vd, const m_str path, const loc_t pos) { struct td_checker tdc = {.str = path, .pos = pos}; DECL_OB(const Symbol, sym, = __str2sym(gwion, &tdc)); @@ -204,16 +198,6 @@ ANN Type_Decl *str2td(const Gwion gwion, const m_str str, const loc_t pos) { struct td_checker tdc = {.str = str, .pos = pos}; DECL_OO(Type_Decl *, td, = _str2td(gwion, &tdc)); if(*tdc.str) { -/* - Type_Decl *tmp = td; - while(tmp->next) tmp = tmp->next; - while(!strcmp(tdc.str, "[]")) { - tdc.str += 2; - if(!td->array) td->array = new_array_sub(gwion->mp, NULL); - else td->array->depth++; - return td; - } -*/ free_type_decl(gwion->mp, td); GWION_ERR_O(pos, "excedental character '%c' in '%s'", *tdc.str, str); } @@ -245,7 +229,7 @@ ANN static m_bool td_info_run(const Env env, struct td_info *info) { Type_List tl = info->tl; for(uint32_t i = 0; i < tl->len; i++) { if (i) text_add(&info->text, ","); - Type_Decl *td = *mp_vector_at(tl, Type_Decl*, i); + DECL_OB(Type_Decl *, td, = *mp_vector_at(tl, Type_Decl*, i)); DECL_OB(const Type, t, = known_type(env, td)); td_fullname(env, &info->text, t); } @@ -255,12 +239,7 @@ ANN static m_bool td_info_run(const Env env, struct td_info *info) { ANEW ANN m_str type2str(const Gwion gwion, const Type t, const loc_t pos NUSED) { GwText text = {.mp = gwion->mp}; - const Type owner = t->info->value->from->owner_class; - if (owner) { - td_fullname(gwion->env, &text, owner); - text_add(&text, "."); - } - text_add(&text, t->name); + td_fullname(gwion->env, &text, t); return text.str; } diff --git a/src/lib/tmpl_info.c b/src/lib/tmpl_info.c index 65705889..1f7fffce 100644 --- a/src/lib/tmpl_info.c +++ b/src/lib/tmpl_info.c @@ -45,9 +45,10 @@ ANN static ssize_t template_size(const Env env, struct tmpl_info *info) { DECL_OB(const m_str, str, = tl2str(env->gwion, info->td->types, info->td->pos)); const size_t tmpl_sz = tmpl_set(info, str); - const m_str base = type2str(env->gwion, info->base, info->td->pos); + const m_str base = !is_func(env->gwion, info->base) + ? mstrdup(env->gwion->mp, info->base->name) + : type2str(env->gwion, info->base, info->td->pos); return tmpl_sz + tmpl_set(info, base) + 4; -// return tmpl_sz + tmpl_set(info, info->base->name) + 4; } ANEW ANN static Symbol _template_id(const Env env, struct tmpl_info *const info, diff --git a/src/parse/template.c b/src/parse/template.c index 4052bec8..1a9121f1 100644 --- a/src/parse/template.c +++ b/src/parse/template.c @@ -21,7 +21,6 @@ ANN static m_bool _push_types(const Env env, const Nspc nspc, if (i >= tl->len) return GW_OK; Type_Decl *td = *mp_vector_at(tl, Type_Decl*, i); const Type t = known_type(env, td); - if (!t) return GW_OK; Specialized *spec = mp_vector_at(sl, Specialized, i); nspc_add_type(nspc, spec->xid, t); }; @@ -51,12 +50,21 @@ ANN static m_bool _template_push(const Env env, const Type t) { } ANN m_bool template_push(const Env env, const Type t) { - nspc_push_type(env->gwion->mp, env->curr); - return _template_push(env, t); + nspc_push_type(env->gwion->mp, env->curr); + return _template_push(env, t); } +ANN void check_call(const Env env, const Tmpl *tmpl) { + for(uint32_t i = 0; i < tmpl->call->len; i++) { + Specialized *spec = mp_vector_at(tmpl->list, Specialized, i); + Type_Decl *call = *mp_vector_at(tmpl->call, Type_Decl*, i); + if(spec->xid == call->xid) + call->xid = insert_symbol("auto"); + } +} ANN m_bool template_push_types(const Env env, const Tmpl *tmpl) { nspc_push_type(env->gwion->mp, env->curr); + if(tmpl->call) check_call(env, tmpl); if (push_types(env, env->curr, tmpl) > 0) return GW_OK; POP_RET(GW_ERROR); }