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);
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];
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
}
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;
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;
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;