From: Jérémie Astor Date: Tue, 15 Dec 2020 13:53:22 +0000 (+0100) Subject: :art: Simplify template_name X-Git-Tag: nightly~1105^2~7 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=a3f94d7c6e5ad03c48323567d3e40adac6028ac2;p=gwion.git :art: Simplify template_name --- diff --git a/src/lib/lib_func.c b/src/lib/lib_func.c index 0185f6d6..c5d6e638 100644 --- a/src/lib/lib_func.c +++ b/src/lib/lib_func.c @@ -208,6 +208,8 @@ static OP_CHECK(opck_auto_fptr) { static OP_CHECK(opck_fptr_at) { Exp_Binary* bin = (Exp_Binary*)data; + if(bin->rhs->exp_type == ae_exp_decl) + UNSET_FLAG(bin->rhs->d.exp_decl.list->self->value, late); if(bin->rhs->info->type->info->func->def->base->tmpl && bin->rhs->info->type->info->func->def->base->tmpl->call) { struct FptrInfo info = { bin->lhs->info->type->info->func, bin->rhs->info->type->info->parent->info->func, diff --git a/src/lib/object_op.c b/src/lib/object_op.c index 19c9cf46..48bcea55 100644 --- a/src/lib/object_op.c +++ b/src/lib/object_op.c @@ -204,9 +204,10 @@ OP_EMIT(opem_object_dot) { const Instr instr = emit_add_instr(emit, RegPushImm); instr->m_val = (m_uint)value->type; } - if(GET_FLAG(value, late)) { + if(GET_FLAG(value, late) && !exp_getvar(exp_self(member))) { const Instr instr = emit_add_instr(emit, GWOP_EXCEPT); - instr->m_val = -SZ_INT; + if(!is_fptr(emit->gwion, value->type)) + instr->m_val = -SZ_INT; } return GW_OK; } @@ -256,7 +257,6 @@ ANN static Type _scan_class(const Env env, struct tmpl_info *info) { ANN Type tmpl_exists(const Env env, struct tmpl_info *const info); ANN Type scan_class(const Env env, const Type t, const Type_Decl *td) { -puts("here"); struct tmpl_info info = { .base=t, .td=td, .list=t->info->cdef->base.tmpl->list }; const Type exists = tmpl_exists(env, &info); if(exists) diff --git a/src/lib/tmpl_info.c b/src/lib/tmpl_info.c index f63e7bb2..47cd61f5 100644 --- a/src/lib/tmpl_info.c +++ b/src/lib/tmpl_info.c @@ -10,8 +10,8 @@ #include "tmpl_info.h" ANN static inline m_str tmpl_get(struct tmpl_info* info, m_str str) { - const Type t = (Type)vector_at(&info->type, info->index); - strcpy(str, t->name); + const m_str tmp = (m_str)vector_at(&info->type, info->index); + strcpy(str, tmp); return str += vector_at(&info->size, info->index); } @@ -31,23 +31,16 @@ ANN static void template_name(struct tmpl_info* info, m_str s) { *str = '\0'; } -ANN static inline size_t tmpl_set(struct tmpl_info* info, const Type t) { - vector_add(&info->type, (vtype)t); - const size_t len = strlen(t->name); +ANN static inline size_t tmpl_set(struct tmpl_info* info, const m_str str) { + vector_add(&info->type, (vtype)str); + const size_t len = strlen(str); vector_add(&info->size, len); return len; } ANN static ssize_t template_size(const Env env, struct tmpl_info* info) { - ID_List base = info->list; // ??? - Type_List call = info->td->types; - size_t size = 0; - do { - DECL_OB(const Type, t, = known_type(env, call->td)) - size += tmpl_set(info, t); - } while((call = call->next) && (base = base->next) && ++size); - size += tmpl_set(info, info->base); - return size + 4; + DECL_OB(const m_str, str, = tl2str(env, info->td->types)) + return tmpl_set(info, str) + tmpl_set(info, info->base->name) + 4; } ANEW ANN static Symbol template_id(const Env env, struct tmpl_info *const info) { diff --git a/src/parse/operator.c b/src/parse/operator.c index 2b8e2187..93faab19 100644 --- a/src/parse/operator.c +++ b/src/parse/operator.c @@ -34,18 +34,6 @@ ANN void free_op_map(Map map, struct Gwion_ *gwion) { map_release(map); } -ANN static Type op_parent(const Env env, const Type t) { - if(tflag(t, tflag_ctmpl)) { - const Type type = typedef_base(t); - char name[strlen(type->name) + 1]; - strcpy(name, type->name); - const m_str post = strchr(name, ':'); - *post = '\0'; - return nspc_lookup_type1(env->curr, insert_symbol(env->gwion->st, name)); - } - return t->info->parent; -} - static m_bool op_match(const restrict Type t, const restrict Type mo) { if(t == OP_ANY_TYPE || mo == OP_ANY_TYPE) return GW_OK; @@ -177,7 +165,7 @@ ANN static Type op_check_inner(struct OpChecker* ock) { else return mo->ret; } - } while(r && (r = op_parent(ock->env, r))); + } while(r && (r = r->info->parent)); return NULL; } @@ -197,7 +185,7 @@ ANN Type op_check(const Env env, struct Op_Import* opi) { set_nspc(&opi2, nspc); return ret; } - } while(l && (l = op_parent(env, l))); + } while(l && (l = l->info->parent)); } } while((nspc = nspc->parent)); // if(env->func && env->func->nspc) @@ -270,11 +258,10 @@ ANN m_bool op_emit(const Emitter emit, const struct Op_Import* opi) { const m_bool ret = mo->em(emit, (void*)opi->data); if(ret) return ret; - } - else if(mo->func || mo->instr) + } else if(mo->func || mo->instr) return handle_instr(emit, mo); } - } while(r && (r = op_parent(emit->env, r))); - } while(l && (l = op_parent(emit->env, l))); + } while(r && (r = r->info->parent)); + } while(l && (l = l->info->parent)); return GW_ERROR; } diff --git a/src/vm/vm.c b/src/vm/vm.c index c9032cae..f938223a 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -797,7 +797,7 @@ except: * VAL = offset (no default SZ_INT) * * VAL2 = error message * * grep for GWOP_EXCEPT and Except, exception... */ - if(!*(M_Object*)(reg-(m_int)VAL)) { + if(!*(void**)(reg-(m_int)VAL)) { shred->pc = PC; exception(shred, "NullPtrException"); continue;