From: fennecdjay Date: Mon, 25 Feb 2019 18:50:59 +0000 (+0100) Subject: :art: Clean dottmpl X-Git-Tag: nightly~2759 X-Git-Url: http://10.11.0.4:5575/?a=commitdiff_plain;h=3f0b6d9447a01a3820eac083ddec4c34c3fe6f1a;p=gwion.git :art: Clean dottmpl --- diff --git a/include/instr.h b/include/instr.h index e349f4ba..aa1bcc0a 100644 --- a/include/instr.h +++ b/include/instr.h @@ -73,10 +73,12 @@ struct dottmpl_ { size_t len; m_str name; Func_Def base, def; + Type owner; size_t overload; // => vtindex ? Type_List tl; }; ANN void free_dottmpl(struct dottmpl_*); +ANN m_bool traverse_dot_tmpl(const Emitter emit, const struct dottmpl_ *dt); // optimizations #ifdef OPTIMIZE INSTR(PutArgsInMem); diff --git a/src/emit/emit.c b/src/emit/emit.c index 443cc9e0..08b88153 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -86,7 +86,7 @@ ANN static m_bool emit_exp(const Emitter emit, Exp exp, const m_bool add_ref); ANN static m_bool emit_stmt(const Emitter emit, const Stmt stmt, const m_bool pop); ANN static m_bool emit_stmt_list(const Emitter emit, Stmt_List list); ANN static m_bool emit_exp_dot(const Emitter emit, const Exp_Dot* member); -ANN /*static */m_bool emit_func_def(const Emitter emit, const Func_Def func_def); +ANN static m_bool emit_func_def(const Emitter emit, const Func_Def func_def); ANEW static Code* new_code(const Emitter emit, const m_str name) { Code* code = mp_alloc(Code); @@ -690,10 +690,21 @@ ANN static Type_List tmpl_tl(const Env env, const m_str name) { return str2tl(env, c, &depth); } +ANN m_bool traverse_dot_tmpl(const Emitter emit, const struct dottmpl_ *dt) { + const m_uint scope = env_push_type(emit->env, dt->owner); + m_bool ret = GW_ERROR; + if(traverse_func_template(emit->env, dt->def, dt->tl) > 0) { + ret = emit_func_def(emit, dt->def); + nspc_pop_type(emit->env->curr); + } + env_pop(emit->env, scope); + return ret; +} + static inline m_bool push_func_code(const Emitter emit, const Func f) { if(GET_FLAG(f, template) && f->value_ref->owner_class) { - const Instr _instr = (Instr)vector_back(&emit->code->instr); -assert(_instr->execute == DotTmpl); + const Instr _instr = (Instr)vector_back(&emit->code->instr); + assert(_instr->execute == DotTmpl); size_t len = strlen(f->name); size_t sz = len - strlen(f->value_ref->owner_class->name); char c[sz + 1]; @@ -1588,7 +1599,7 @@ ANN static m_bool emit_func_def_body(const Emitter emit, const Func_Def func_def return GW_OK; } -ANN /*static */m_bool emit_func_def(const Emitter emit, const Func_Def func_def) { GWDEBUG_EXE +ANN static m_bool emit_func_def(const Emitter emit, const Func_Def func_def) { GWDEBUG_EXE const Func func = get_func(emit->env, func_def); if(func->code)return GW_OK; if(tmpl_list_base(func_def->tmpl)) { // don't check template definition diff --git a/src/lib/instr.c b/src/lib/instr.c index b56d81ab..e3718421 100644 --- a/src/lib/instr.c +++ b/src/lib/instr.c @@ -109,7 +109,7 @@ ANN static Func_Def from_base(const struct dottmpl_ *dt, const Type t) { } INSTR(DotTmpl) { - const struct dottmpl_ * dt = (struct dottmpl_*)instr->m_val; + struct dottmpl_ * dt = (struct dottmpl_*)instr->m_val; const m_str name = dt->name; const M_Object o = *(M_Object*)REG(-SZ_INT); Type t = o->type_ref; @@ -122,14 +122,9 @@ INSTR(DotTmpl) { const Func f = nspc_lookup_func1(t->nspc, insert_symbol(str)); if(f) { if(!f->code) { - const m_uint scope = env_push_type(emit->env, t); - m_bool ret = GW_ERROR; - if(traverse_func_template(emit->env, f->def, dt->tl) > 0) { - ret = emit_func_def(emit, f->def); - nspc_pop_type(emit->env->curr); - } - env_pop(emit->env, scope); - if(ret < 0) + dt->def = f->def;// + dt->owner = t; // + if(traverse_dot_tmpl(emit, dt) < 0) continue; } *(VM_Code*)shred->reg = f->code; @@ -139,14 +134,9 @@ INSTR(DotTmpl) { const Func_Def def = from_base(dt, t); if(!def) continue; - const m_uint scope = env_push_type(emit->env, t); - m_bool ret = GW_ERROR; - if(traverse_func_template(emit->env, def, dt->tl) > 0) { - ret = emit_func_def(emit, def); - nspc_pop_type(emit->env->curr); - } - env_pop(emit->env, scope); - if(ret > 0) { + dt->def = def; // + dt->owner = t; // + if(traverse_dot_tmpl(emit, dt) > 0) { *(VM_Code*)shred->reg = def->func->code; shred->reg += SZ_INT; return;