From: fennecdjay Date: Sat, 18 May 2019 19:41:56 +0000 (+0200) Subject: :art: One tmpl to rule them All X-Git-Tag: nightly~2454^2 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=e960a46978e2c2b7d2920fd2240d1e80039bdbc7;p=gwion.git :art: One tmpl to rule them All --- diff --git a/ast b/ast index 94e10ded..c902b188 160000 --- a/ast +++ b/ast @@ -1 +1 @@ -Subproject commit 94e10dede128475686da71e1f35b5a89b88073fd +Subproject commit c902b1888ae8aadcb2cdf6000308e0d55043b8ed diff --git a/src/emit/emit.c b/src/emit/emit.c index a45afe3c..24e804e7 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -691,7 +691,7 @@ ANN static inline m_int push_tmpl_func(const Emitter emit, const Func f, ANN static m_bool emit_exp_call_template(const Emitter emit, const Exp_Call* exp_call) { if(emit->env->func && emit->env->func == exp_call->m_func) return prepare_call(emit, exp_call); - const m_int scope = push_tmpl_func(emit, exp_call->m_func, exp_call->tmpl->types); + const m_int scope = push_tmpl_func(emit, exp_call->m_func, exp_call->tmpl->call); CHECK_BB(scope); CHECK_BB(prepare_call(emit, exp_call)) emit_pop_type(emit); @@ -1685,7 +1685,7 @@ ANN static m_bool emit_func_def(const Emitter emit, const Func_Def func_def) { const Func former = emit->env->func; if(func->code) return GW_OK; - if(tmpl_list_base(func_def->tmpl)) { + if(tmpl_base(func_def->tmpl)) { UNSET_FLAG(func_def, template); return GW_OK; } @@ -1750,7 +1750,7 @@ ANN static inline void emit_class_pop(const Emitter emit) { ANN static m_bool emit_class_def(const Emitter emit, const Class_Def cdef) { const Type type = cdef->base.type; const Nspc nspc = type->nspc; - if(tmpl_list_base(cdef->tmpl)) + if(tmpl_base(cdef->tmpl)) return GW_OK; if(cdef->base.ext && ((/*!GET_FLAG(type->e->parent, emit) &&*/ GET_FLAG(cdef->base.ext, typedef)) || cdef->base.ext->types)) { diff --git a/src/lib/import.c b/src/lib/import.c index 7f5aee96..039f75e0 100644 --- a/src/lib/import.c +++ b/src/lib/import.c @@ -221,7 +221,7 @@ ANN2(1,2) m_int gwi_class_ini(const Gwi gwi, const Type type, const f_xtor pre_c if(gwi->templater.n) { const ID_List types = templater_def(gwi->gwion->st, gwi); type->e->def = new_class_def(gwi->gwion->mp, 0, insert_symbol(gwi->gwion->st, type->name), NULL, NULL, loc_cpy(gwi->gwion->mp, gwi->loc)); - type->e->def->tmpl = new_tmpl_list(gwi->gwion->mp, types, -1); + type->e->def->tmpl = new_tmpl(gwi->gwion->mp, types, -1); type->e->def->base.type = type; SET_FLAG(type, template); } else @@ -454,7 +454,7 @@ ANN m_int gwi_func_end(const Gwi gwi, const ae_flag flag) { if(gwi->templater.n) { def = new_func_def(gwi->gwion->mp, new_func_base(gwi->gwion->mp, NULL, NULL, NULL), NULL, 0, loc_cpy(gwi->gwion->mp, gwi->loc)); const ID_List list = templater_def(gwi->gwion->st, gwi); - def->tmpl = new_tmpl_list(gwi->gwion->mp, list, -1); + def->tmpl = new_tmpl(gwi->gwion->mp, list, -1); SET_FLAG(def, template); } if(gwi->gwion->env->class_def && GET_FLAG(gwi->gwion->env->class_def, template)) { diff --git a/src/lib/instr.c b/src/lib/instr.c index 034d5ab5..4929dc44 100644 --- a/src/lib/instr.c +++ b/src/lib/instr.c @@ -66,7 +66,7 @@ ANN static Func_Def from_base(const Env env, const struct dottmpl_ *dt, const Ty const Func_Def base = v->d.func_ref->def; const Func_Def def = new_func_def(env->gwion->mp, new_func_base(env->gwion->mp, base->base->td, insert_symbol(env->gwion->st, v->name), base->base->args), base->d.code, base->flag, loc_cpy(env->gwion->mp, base->pos)); - def->tmpl = new_tmpl_list(env->gwion->mp, base->tmpl->list, dt->overload); + def->tmpl = new_tmpl(env->gwion->mp, base->tmpl->list, dt->overload); SET_FLAG(def, template); return def; } diff --git a/src/parse/check.c b/src/parse/check.c index 83f56484..a34ebc58 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -406,7 +406,7 @@ ANN static inline Value template_get_ready(const Env env, const Value v, const m ANN static Func _find_template_match(const Env env, const Value v, const Exp_Call* exp) { const Exp args = exp->args; - const Type_List types = exp->tmpl->types; + const Type_List types = exp->tmpl->call; Func m_func = exp->m_func, former = env->func; if(types->td->types)exit(12); const m_str tmpl_name = tl2str(env, types); @@ -427,7 +427,7 @@ if(types->td->types)exit(12); if(!(value = template_get_ready(env, v, "template", i))) continue; base = value->d.func_ref->def; - def->tmpl = new_tmpl_list(env->gwion->mp, base->tmpl->list, (m_int)i); + def->tmpl = new_tmpl(env->gwion->mp, base->tmpl->list, (m_int)i); } } else { if(!(value = template_get_ready(env, v, "template", i))) @@ -435,7 +435,7 @@ if(types->td->types)exit(12); base = value->d.func_ref->def; def = new_func_def(env->gwion->mp, new_func_base(env->gwion->mp, base->base->td, insert_symbol(v->name), base->base->args), base->d.code, base->flag, loc_cpy(env->gwion->mp, base->pos)); - def->tmpl = new_tmpl_list(env->gwion->mp, base->tmpl->list, (m_int)i); + def->tmpl = new_tmpl(env->gwion->mp, base->tmpl->list, (m_int)i); SET_FLAG(def, template); } if(traverse_func_template(env, def, types) > 0) { @@ -516,8 +516,8 @@ ANN static m_uint get_type_number(ID_List list) { ANN static Func get_template_func(const Env env, const Exp_Call* func, const Value v) { const Func f = find_template_match(env, v, func); if(f) { - Tmpl_Call* tmpl = new_tmpl_call(env->gwion->mp, func->tmpl->types); - tmpl->base = v->d.func_ref->def->tmpl->list; + Tmpl* tmpl = new_tmpl_call(env->gwion->mp, func->tmpl->call); + tmpl->list = v->d.func_ref->def->tmpl->list; ((Exp_Call*)func)->tmpl = tmpl; return ((Exp_Call*)func)->m_func = f; } @@ -557,7 +557,7 @@ ANN static Type check_exp_call_template(const Env env, const Exp_Call *exp) { } if(args_number < type_number) ERR_O(call->pos, "not able to guess types for template call.") - Tmpl_Call tmpl = { .types=tl[0] }; + Tmpl tmpl = { .call=tl[0] }; ((Exp_Call*)exp)->tmpl = &tmpl; const Func func = get_template_func(env, exp, value); return func ? func->def->base->ret_type : NULL; @@ -1112,7 +1112,7 @@ ANN static void operator_func(const Func f) { ANN m_bool check_func_def(const Env env, const Func_Def f) { const Func func = get_func(env, f); m_bool ret = GW_OK; - if(tmpl_list_base(f->tmpl)) + if(tmpl_base(f->tmpl)) return env->class_def ? check_parent_match(env, f) : 1; if(f->base->td && !f->base->td->xid) { f->base->ret_type = check_td(env, f->base->td); @@ -1180,7 +1180,7 @@ ANN static inline void inherit(const Type t) { } ANN m_bool check_class_def(const Env env, const Class_Def cdef) { - if(tmpl_list_base(cdef->tmpl)) + if(tmpl_base(cdef->tmpl)) return GW_OK; const Type type = cdef->base.type; if(type->e->parent == t_undefined) { diff --git a/src/parse/func.c b/src/parse/func.c index 043b3ff5..40871c2f 100644 --- a/src/parse/func.c +++ b/src/parse/func.c @@ -11,7 +11,7 @@ ANN static void free_func(Func a, Gwion gwion) { if(GET_FLAG(a, template)) { - free_tmpl_list(gwion->mp, a->def->tmpl); + free_tmpl(gwion->mp, a->def->tmpl); free_func_base(gwion->mp, a->def->base); free_loc(gwion->mp, a->def->pos); mp_free(gwion->mp, Func_Def, a->def); diff --git a/src/parse/scan1.c b/src/parse/scan1.c index e4d9c29f..a5fe7efa 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -287,7 +287,7 @@ ANN static m_bool scan1_stmt_list(const Env env, Stmt_List l) { ANN m_bool scan1_func_def(const Env env, const Func_Def fdef) { if(fdef->base->td) CHECK_BB(env_storage(env, fdef->flag, td_pos(fdef->base->td))) - if(tmpl_list_base(fdef->tmpl)) + if(tmpl_base(fdef->tmpl)) return GW_OK; struct Func_ fake = { .name=s_name(fdef->base->xid) }, *const former = env->func; env->func = &fake; @@ -338,7 +338,7 @@ ANN static m_bool scan1_class_parent(const Env env, const Class_Def cdef) { ANN m_bool scan1_class_def(const Env env, const Class_Def cdef) { if(!cdef->base.type) CHECK_BB(scan0_class_def(env, cdef)) - if(tmpl_list_base(cdef->tmpl)) + if(tmpl_base(cdef->tmpl)) return GW_OK; if(cdef->base.ext) CHECK_BB(scan1_class_parent(env, cdef)) diff --git a/src/parse/scan2.c b/src/parse/scan2.c index 538d20ad..01809a5b 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -298,7 +298,7 @@ ANN static m_bool scan2_stmt_list(const Env env, Stmt_List list) { } ANN static m_bool scan2_func_def_overload(const Env env, const Func_Def f, const Value overload) { - const m_bool base = tmpl_list_base(f->tmpl); + const m_bool base = tmpl_base(f->tmpl); const m_bool tmpl = GET_FLAG(overload, template); if(isa(overload->type, t_function) < 0 || isa(overload->type, t_fptr) > 0) ERR_B(f->pos, "function name '%s' is already used by another value", overload->name) @@ -495,7 +495,7 @@ ANN m_bool scan2_func_def(const Env env, const Func_Def f) { ERR_B(f->pos, "'%s' already declared as type", func_name) if(overload) CHECK_BB(scan2_func_def_overload(env, f, overload)) - if(tmpl_list_base(f->tmpl)) + if(tmpl_base(f->tmpl)) return scan2_func_def_template(env, f, overload); if(!f->tmpl) { const Symbol sym = func_symbol(env, env->curr->name, func_name, NULL, overload ? ++overload->offset : 0); @@ -549,7 +549,7 @@ ANN static m_bool scan2_class_parent(const Env env, const Class_Def cdef) { } ANN m_bool scan2_class_def(const Env env, const Class_Def cdef) { - if(tmpl_list_base(cdef->tmpl)) + if(tmpl_base(cdef->tmpl)) return GW_OK; if(cdef->base.ext) CHECK_BB(scan2_class_parent(env, cdef)) diff --git a/src/parse/template.c b/src/parse/template.c index 26ba90fc..84cdd61d 100644 --- a/src/parse/template.c +++ b/src/parse/template.c @@ -155,7 +155,7 @@ ANN Type scan_type(const Env env, const Type t, const Type_Decl* type) { SET_FLAG(a, ref); if(a->base.type) return a->base.type; - a->tmpl = new_tmpl_list(env->gwion->mp, get_total_type_list(env, t), 0); + a->tmpl = new_tmpl(env->gwion->mp, get_total_type_list(env, t), 0); a->tmpl->call = type->types; CHECK_BO(scan0_class_def(env, a))