From 106ec2342016c0f14d703f8e9a261ab3ece6a40c Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Sat, 13 Jul 2019 15:54:34 +0200 Subject: [PATCH] :art: Global class fixes --- src/emit/emit.c | 8 +++++--- src/parse/check.c | 19 +++++++++---------- src/parse/scan1.c | 2 +- src/parse/scan2.c | 2 +- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/emit/emit.c b/src/emit/emit.c index ae00bef9..22ee628a 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -774,9 +774,9 @@ ANN m_bool traverse_dot_tmpl(const Emitter emit, const struct dottmpl_ *dt) { } static inline m_bool push_func_code(const Emitter emit, const Func f) { + const Instr instr = (Instr)vector_back(&emit->code->instr); if(GET_FLAG(f, template) && f->value_ref->owner_class) { - const Instr instr = (Instr)vector_back(&emit->code->instr); - assert(instr->opcode == eDotTmplVal); +// assert(instr->opcode == eDotTmplVal); size_t len = strlen(f->name); size_t sz = len - strlen(f->value_ref->owner_class->name); char c[sz + 1]; @@ -1599,7 +1599,8 @@ ANN static m_bool emit_member_func(const Emitter emit, const Exp_Dot* member, co func_i->m_val = (m_uint)(func->code ?: (VM_Code)func); return GW_OK; } - if(func->def->base->tmpl) +// if(func->def->base->tmpl) + if(GET_FLAG(func->def, template)) emit_add_instr(emit, DotTmplVal); else { const Instr instr = emit_add_instr(emit, GET_FLAG(func, member) ? DotFunc : DotStaticFunc); @@ -1779,6 +1780,7 @@ ANN static m_bool emit_parent(const Emitter emit, const Class_Def cdef) { const Type parent = cdef->base.type->e->parent; const Type base = parent->e->d.base_type; if(base && !GET_FLAG(base, emit)) +// if(parent && (!GET_FLAG(parent, emit) || GET_FLAG(parent, template))) CHECK_BB(scanx_parent(base, emit_parent_inner, emit)) return !GET_FLAG(parent, emit) ? GW_OK : scanx_parent(parent, emit_parent_inner, emit); } diff --git a/src/parse/check.c b/src/parse/check.c index 7e654f7a..da349024 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -415,15 +415,13 @@ static Func ensure_tmpl(const Env env, const Func_Def fdef, const Exp_Call *exp) const m_bool ret = traverse_func_def(env, fdef); if(ret > 0) { const Func f = fdef->base->func; - if(check_call(env, exp) > 0) { - const Func next = f->next; - f->next = NULL; - const Func func = find_func_match(env, f, exp->args); - f->next = next; - if(func) { - SET_FLAG(func, checked | ae_flag_template); - return 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_FLAG(func, checked | ae_flag_template); + return func; } } return NULL; @@ -739,6 +737,7 @@ ANN static Type check_exp_call(const Env env, Exp_Call* exp) { ERR_O(exp_self(exp)->pos, _("template call of non-template function.")) if(t->e->d.func->def->base->tmpl->call) CHECK_BO(predefined_call(env, t, exp_self(exp)->pos)) +CHECK_BO(check_call(env, exp)) const Func ret = find_template_match(env, v, exp); CHECK_OO((exp->m_func = ret)) return ret->def->base->ret_type; @@ -1226,7 +1225,7 @@ ANN static m_bool check_class_parent(const Env env, const Class_Def cdef) { const Type_Decl *td = cdef->base.ext; if(td->array) CHECK_BB(check_exp_array_subscripts(env, td->array->exp)) - if(parent->e->def) + if(parent->e->def && (!GET_FLAG(parent, check) || GET_FLAG(parent, template))) CHECK_BB(scanx_parent(parent, traverse_class_def, env)) if(GET_FLAG(parent, typedef)) SET_FLAG(cdef->base.type, typedef); diff --git a/src/parse/scan1.c b/src/parse/scan1.c index 6b2684e2..3a83cbdd 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -367,7 +367,7 @@ ANN static m_bool scan1_parent(const Env env, const Class_Def cdef) { } while((t = t->e->parent)); if(isa(parent, t_object) < 0) ERR_B(pos, _("cannot extend primitive type '%s'"), parent->name) - if(parent->e->def) + if(parent->e->def && (!GET_FLAG(parent, scan1) || GET_FLAG(parent, template))) CHECK_BB(scanx_parent(parent, scan1_class_def, env)) if(type_ref(parent)) ERR_B(pos, _("can't use ref type in class extend")) diff --git a/src/parse/scan2.c b/src/parse/scan2.c index 50fb06d4..ae676cb8 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -537,7 +537,7 @@ DECL_SECTION_FUNC(scan2) ANN static m_bool scan2_class_parent(const Env env, const Class_Def cdef) { const Type parent = cdef->base.type->e->parent; - if(parent->e->def) + if(parent->e->def && (!GET_FLAG(parent, scan2) || GET_FLAG(parent, template))) CHECK_BB(scanx_parent(parent, scan2_cdef, env)) if(cdef->base.ext->array) CHECK_BB(scan2_exp(env, cdef->base.ext->array->exp)) -- 2.43.0