From 7558fc8366f3646b7d501cc822f0a270bfd14357 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Sat, 5 Dec 2020 13:34:47 +0100 Subject: [PATCH] :art: Get rid of type->xid --- include/env/type.h | 3 +-- include/import/type.h | 4 ++-- src/env/env.c | 1 - src/env/type.c | 10 ++++------ src/import/import_cdef.c | 4 ++-- src/import/import_type.c | 11 +++++------ src/lib/array.c | 8 ++++---- src/lib/object_op.c | 4 ++-- src/parse/operator.c | 19 +++++-------------- src/parse/scan0.c | 13 +++++-------- src/parse/scan2.c | 1 - 11 files changed, 30 insertions(+), 48 deletions(-) diff --git a/include/env/type.h b/include/env/type.h index 4a37b669..21811c0b 100644 --- a/include/env/type.h +++ b/include/env/type.h @@ -43,7 +43,6 @@ struct Type_ { m_str name; Nspc nspc; struct TypeInfo_ *info; - size_t xid; size_t size; size_t array_depth; uint16_t ref; @@ -54,7 +53,7 @@ struct Type_ { REF_FUNC(Type, type) FLAG_FUNC(Type, t) -ANN2(1,3) ANEW Type new_type(MemPool, const m_uint xid, const m_str name, const Type); +ANN2(1,2) ANEW Type new_type(MemPool, const m_str name, const Type); ANEW ANN Type type_copy(MemPool, const Type type); ANN m_str get_type_name(const Env, const Type t, const m_uint); ANN Value find_value(const Type, const Symbol); diff --git a/include/import/type.h b/include/import/type.h index a3b04adf..814a58a4 100644 --- a/include/import/type.h +++ b/include/import/type.h @@ -2,7 +2,7 @@ #define __IMPORT_TYPE ANN2(1,2) ANEW Type gwi_mk_type(const Gwi, const m_str, const m_uint, const m_str); -ANN m_int gwi_add_type(const Gwi gwi, Type type); -ANN m_int gwi_set_global_type(const Gwi gwi, const Type type, const type_enum te); +ANN void gwi_add_type(const Gwi gwi, Type type); +ANN void gwi_set_global_type(const Gwi gwi, const Type type, const type_enum te); #endif diff --git a/src/env/env.c b/src/env/env.c index 122dee71..b7dc1e95 100644 --- a/src/env/env.c +++ b/src/env/env.c @@ -92,7 +92,6 @@ ANN void env_add_type(const Env env, const Type type) { SET_FLAG(v, global); set_vflag(v, vflag_builtin); set_tflag(type, tflag_scan0 | tflag_scan1 | tflag_scan2 | tflag_check | tflag_emit); - type->xid = ++env->scope->type_xid; } ANN m_bool type_engine_check_prog(const Env env, const Ast ast) { diff --git a/src/env/type.c b/src/env/type.c index 24ae4ce4..73dbd1c0 100644 --- a/src/env/type.c +++ b/src/env/type.c @@ -28,9 +28,8 @@ ANN void free_type(const Type a, struct Gwion_ *const gwion) { } -Type new_type(MemPool p, const m_uint xid, const m_str name, const Type parent) { +Type new_type(MemPool p, const m_str name, const Type parent) { const Type type = mp_calloc(p, Type); - type->xid = xid; type->name = name; type->info = mp_calloc(p, TypeInfo); type->info->parent = parent; @@ -41,7 +40,7 @@ Type new_type(MemPool p, const m_uint xid, const m_str name, const Type parent) } ANN Type type_copy(MemPool p, const Type type) { - const Type a = new_type(p, type->xid, type->name, type->info->parent); + const Type a = new_type(p, type->name, type->info->parent); a->nspc = type->nspc; a->info->owner = type->info->owner; a->info->owner_class = type->info->owner_class; @@ -53,7 +52,7 @@ ANN Type type_copy(MemPool p, const Type type) { } ANN m_bool isa(const restrict Type var, const restrict Type parent) { - return (var->xid == parent->xid) ? GW_OK : var->info->parent ? isa(var->info->parent, parent) : GW_ERROR; + return (var == parent) ? GW_OK : var->info->parent ? isa(var->info->parent, parent) : GW_ERROR; } ANN Type find_common_anc(const restrict Type lhs, const restrict Type rhs) { @@ -100,8 +99,7 @@ ANN Type array_type(const Env env, const Type src, const m_uint depth) { const Type type = nspc_lookup_type1(src->info->owner, sym); if(type) return type; - const Type t = new_type(env->gwion->mp, ++env->scope->type_xid, - s_name(sym), env->gwion->type[et_array]); + const Type t = new_type(env->gwion->mp, s_name(sym), env->gwion->type[et_array]); t->array_depth = depth + src->array_depth; t->info->base_type = array_base(src) ?: src; t->info->owner = src->info->owner; diff --git a/src/import/import_cdef.c b/src/import/import_cdef.c index f71cf098..cdb73487 100644 --- a/src/import/import_cdef.c +++ b/src/import/import_cdef.c @@ -80,7 +80,7 @@ ANN2(1,2) Type gwi_class_ini(const Gwi gwi, const m_str name, const m_str parent if(tmpl) nspc_pop_type(gwi->gwion->mp, gwi->gwion->env->curr); CHECK_OO(p) - const Type t = new_type(gwi->gwion->mp, ++gwi->gwion->env->scope->type_xid, s_name(ck.sym), p); + const Type t = new_type(gwi->gwion->mp, s_name(ck.sym), p); t->info->cdef = new_class_def(gwi->gwion->mp, 0, ck.sym, td, NULL, loc(gwi)); t->info->cdef->base.tmpl = tmpl; t->info->cdef->base.type = t; @@ -98,7 +98,7 @@ ANN2(1,2) Type gwi_class_ini(const Gwi gwi, const m_str name, const m_str parent ANN Type gwi_struct_ini(const Gwi gwi, const m_str name) { struct ImportCK ck = { .name=name }; CHECK_BO(check_typename_def(gwi, &ck)) - const Type t = new_type(gwi->gwion->mp, ++gwi->gwion->env->scope->type_xid, s_name(ck.sym), gwi->gwion->type[et_compound]); + const Type t = new_type(gwi->gwion->mp, s_name(ck.sym), gwi->gwion->type[et_compound]); set_tflag(t, tflag_struct); if(!ck.tmpl) gwi_type_flag(t); diff --git a/src/import/import_type.c b/src/import/import_type.c index d5a64244..44e58ac8 100644 --- a/src/import/import_type.c +++ b/src/import/import_type.c @@ -32,17 +32,16 @@ ANN2(1) static Type get_parent(const Gwi gwi, const m_str parent_name) { ANN2(1,2) Type gwi_mk_type(const Gwi gwi, const m_str name, const m_uint size, const m_str parent_name) { CHECK_OO(gwi_str2sym(gwi, name)) const Type parent = get_parent(gwi, parent_name); - const Type t = new_type(gwi->gwion->mp, 0, name, parent); + const Type t = new_type(gwi->gwion->mp, name, parent); t->size = size; return t; } -ANN m_int gwi_add_type(const Gwi gwi, const Type type) { - env_add_type(gwi->gwion->env, type); - return (m_int)type->xid; +ANN void gwi_add_type(const Gwi gwi, const Type type) { + return env_add_type(gwi->gwion->env, type); } -ANN m_int gwi_set_global_type(const Gwi gwi, const Type type, const type_enum te) { +ANN void gwi_set_global_type(const Gwi gwi, const Type type, const type_enum te) { gwi->gwion->type[te] = type; - return gwi_add_type(gwi, type); + gwi_add_type(gwi, type); } diff --git a/src/lib/array.c b/src/lib/array.c index 1d8c30d6..1064d31e 100644 --- a/src/lib/array.c +++ b/src/lib/array.c @@ -173,7 +173,7 @@ ANN static Type check_array_shift(const Env env, if(a->info->type == env->gwion->type[et_null] && b->info->type->array_depth > 1) return a->info->type; - ARRAY_OPCK(a, b, pos) + ARRAY_OPCK(a, b, pos) if(a->info->type->array_depth == b->info->type->array_depth + 1) return a->info->type; else if(a->info->type->array_depth == b->info->type->array_depth) @@ -325,11 +325,11 @@ static OP_CHECK(opck_array) { Exp e = array->exp; do CHECK_BO(check_implicit(env, e, t_int)) while((e = e->next)); - const Type t = array->type; + const Type t = array->type->array_depth ? array->type : typedef_base(array->type); if(t->array_depth >= array->depth) return array_type(env, array_base(t), t->array_depth - array->depth); - const Exp curr = take_exp(array->exp, array->type->array_depth); - struct Array_Sub_ next = { curr->next, array_base(array->type), array->depth - array->type->array_depth }; + const Exp curr = take_exp(array->exp, t->array_depth); + struct Array_Sub_ next = { curr->next, array_base(t), array->depth - t->array_depth }; return check_array_access(env, &next); } diff --git a/src/lib/object_op.c b/src/lib/object_op.c index 343a154c..14fb911f 100644 --- a/src/lib/object_op.c +++ b/src/lib/object_op.c @@ -35,12 +35,12 @@ static inline m_bool nonnull_check(const Type l, const Type r) { return !tflag(l, tflag_nonnull) && tflag(r, tflag_nonnull); } -static inline Type check_nonnull(const Env env, const Type l, const Type r, +ANN static inline Type check_nonnull(const Env env, const Type l, const Type r, const m_str action, const loc_t pos) { if(tflag(r, tflag_nonnull)) { if(isa(l, env->gwion->type[et_null]) > 0) ERR_N(pos, _("can't %s '%s' to '%s'"), action, l->name, r->name); - if(isa(l, r) < 0) + if(isa(l, unflag_type(r)) < 0) ERR_N(pos, _("can't %s '%s' to '%s'"), action, l->name, r->name); return r->info->parent; } diff --git a/src/parse/operator.c b/src/parse/operator.c index ade5cbdb..b9c6cff5 100644 --- a/src/parse/operator.c +++ b/src/parse/operator.c @@ -49,10 +49,9 @@ ANN static Type op_parent(const Env env, const Type t) { 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; - Type type = t; - if((type && mo && mo->xid == type->xid) || (!type && !mo)) - return GW_OK; - return 0; + if(t && mo) + return unflag_type(t) == unflag_type(mo); + return t == mo; } ANN2(1) static M_Operator* operator_find(const Vector v, const restrict Type lhs, const restrict Type rhs) { @@ -66,18 +65,10 @@ ANN2(1) static M_Operator* operator_find(const Vector v, const restrict Type lhs return NULL; } -static m_bool op_match2(const restrict Type t, const restrict Type mo) { -// if(t == OP_ANY_TYPE || mo == OP_ANY_TYPE) -// return GW_OK; - if((t && mo && (t != OP_ANY_TYPE && mo != OP_ANY_TYPE && mo->xid == t->xid)) || (!t && !mo)) - return GW_OK; - return 0; -} - ANN2(1) static M_Operator* operator_find2(const Vector v, const restrict Type lhs, const restrict Type rhs) { for(m_uint i = vector_size(v) + 1; --i;) { M_Operator* mo = (M_Operator*)vector_at(v, i - 1); - if(op_match2(lhs, mo->lhs) && op_match2(rhs, mo->rhs)) + if(lhs == mo->lhs && rhs == mo->rhs) return mo; } return NULL; @@ -87,7 +78,7 @@ ANN void operator_suspend(const Nspc n, struct Op_Import *opi) { const Vector v = (Vector)map_get(&n->info->op_map, (vtype)opi->op); for(m_uint i = vector_size(v) + 1; --i;) { M_Operator* mo = (M_Operator*)vector_at(v, i - 1); - if(op_match2(opi->lhs, mo->lhs) && op_match2(opi->rhs, mo->rhs)) { + if(opi->lhs == mo->lhs && opi->rhs == mo->rhs) { opi->data = (uintptr_t)mo; opi->ret = (Type)&VPTR(v, i-1); VPTR(v, i-1) = 0; diff --git a/src/parse/scan0.c b/src/parse/scan0.c index ea84c0a1..5c5b3eea 100644 --- a/src/parse/scan0.c +++ b/src/parse/scan0.c @@ -20,9 +20,8 @@ static inline void context_global(const Env env) { env->context->global = 1; } -static inline Type scan0_type(const Env env, const m_uint xid, - const m_str name, const Type t) { - const Type type = new_type(env->gwion->mp, xid, name, t); +static inline Type scan0_type(const Env env, const m_str name, const Type t) { + const Type type = new_type(env->gwion->mp, name, t); type->info->ctx = env->context; return type; } @@ -68,7 +67,7 @@ ANN m_bool scan0_fptr_def(const Env env, const Fptr_Def fptr) { CHECK_BB(env_access(env, fptr->base->flag, td_pos(fptr->base->td))) CHECK_BB(scan0_defined(env, fptr->base->xid, td_pos(fptr->base->td))); const m_str name = s_name(fptr->base->xid); - const Type t = scan0_type(env, env->gwion->type[et_fptr]->xid, name, env->gwion->type[et_fptr]); + const Type t = scan0_type(env, name, env->gwion->type[et_fptr]); t->info->owner = !(!env->class_def && GET_FLAG(fptr->base, global)) ? env->curr : env->global_nspc; t->info->owner_class = env->class_def; @@ -112,7 +111,7 @@ ANN static void scan0_implicit_similar(const Env env, const Type lhs, const Type } ANN static void typedef_simple(const Env env, const Type_Def tdef, const Type base) { - const Type t = scan0_type(env, ++env->scope->type_xid, s_name(tdef->xid), base); + const Type t = scan0_type(env, s_name(tdef->xid), base); t->size = base->size; const Nspc nspc = (!env->class_def && GET_FLAG(tdef->ext, global)) ? env->global_nspc : env->curr; @@ -182,7 +181,6 @@ ANN static Symbol scan0_sym(const Env env, const m_str name, const loc_t pos) { ANN static Type enum_type(const Env env, const Enum_Def edef) { const Type t = type_copy(env->gwion->mp, env->gwion->type[et_int]); - t->xid = ++env->scope->type_xid; const Symbol sym = scan0_sym(env, "enum", edef->pos); t->name = edef->xid ? s_name(edef->xid) : s_name(sym); t->info->parent = env->gwion->type[et_int]; @@ -214,7 +212,6 @@ ANN m_bool scan0_enum_def(const Env env, const Enum_Def edef) { ANN static Type union_type(const Env env, const Symbol s, const m_bool add) { const m_str name = s_name(s); const Type t = type_copy(env->gwion->mp, env->gwion->type[et_union]); - t->xid = ++env->scope->type_xid; t->name = name; t->nspc = new_nspc(env->gwion->mp, name); t->info->owner = t->nspc->parent = env->curr; @@ -335,7 +332,7 @@ ANN static Type scan0_class_def_init(const Env env, const Class_Def cdef) { const Type parent = get_parent(env, cdef); if(parent == (Type)GW_ERROR) return NULL; - const Type t = scan0_type(env, ++env->scope->type_xid, s_name(cdef->base.xid), parent); + const Type t = scan0_type(env, s_name(cdef->base.xid), parent); if(cflag(cdef, cflag_struct)) set_tflag(t, tflag_struct); t->info->tuple = new_tupleform(env->gwion->mp, parent); diff --git a/src/parse/scan2.c b/src/parse/scan2.c index c7d63c71..4c17b75a 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -325,7 +325,6 @@ ANN static Func scan_new_func(const Env env, const Func_Def f, const m_str name) ANN static Type func_type(const Env env, const Func func) { const Type base = env->gwion->type[!fbflag(func->def->base, fbflag_lambda) ? et_function : et_lambda]; const Type t = type_copy(env->gwion->mp, base); - t->xid = ++env->scope->type_xid; t->info->parent = base; t->name = func->name; t->info->owner = env->curr; -- 2.43.0