]> Nishi Git Mirror - gwion.git/commitdiff
:art: Clean dottmpl
authorfennecdjay <astor.jeremie@wanadoo.fr>
Mon, 25 Feb 2019 18:50:59 +0000 (19:50 +0100)
committerfennecdjay <astor.jeremie@wanadoo.fr>
Mon, 25 Feb 2019 18:50:59 +0000 (19:50 +0100)
include/instr.h
src/emit/emit.c
src/lib/instr.c

index e349f4ba5c64b9e3b458bb676608d755b870878f..aa1bcc0a5dba845db7fc5e98dc26fd4b11227e32 100644 (file)
@@ -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);
index 443cc9e02cdcc770bc4b353c900d5b77fd3de994..08b88153697650a1708d7774192db106a1b623d4 100644 (file)
@@ -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
index b56d81ab4218bfd598e57c398a7575ef3bc3de4e..e3718421630076f24baa7f9cc228686766d6ce54 100644 (file)
@@ -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;