Skip to content

Commit

Permalink
🎨 Global class fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
fennecdjay committed Jul 13, 2019
1 parent 1fafcd4 commit 106ec23
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
8 changes: 5 additions & 3 deletions src/emit/emit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
19 changes: 9 additions & 10 deletions src/parse/check.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/parse/scan1.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
2 changes: 1 addition & 1 deletion src/parse/scan2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 106ec23

Please sign in to comment.