From d5f2f00e9273fb97e9524c69a45d1cf30e603b21 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Tue, 24 Sep 2019 00:14:27 +0200 Subject: [PATCH] :art: Introduce nspc_add_xxx_front() --- include/nspc.h | 3 +++ src/lib/object.c | 2 +- src/lib/tuple.c | 2 +- src/oo/env.c | 2 +- src/oo/type.c | 2 +- src/parse/check.c | 4 ++-- src/parse/scan0.c | 4 ++-- src/parse/template.c | 6 +++--- src/parse/type_decl.c | 2 +- 9 files changed, 15 insertions(+), 12 deletions(-) diff --git a/include/nspc.h b/include/nspc.h index 2814097d..cc59e8aa 100644 --- a/include/nspc.h +++ b/include/nspc.h @@ -47,6 +47,9 @@ describe_lookup1(A, b) \ static inline ANN void nspc_add_##b(const Nspc n, const Symbol s, const A a) { \ scope_add(n->info->b, (vtype)s, (vtype)a); \ } \ +static inline ANN void nspc_add_##b##_front(const Nspc n, const Symbol s, const A a) { \ + map_set(&n->info->b->map, (vtype)s, (vtype)a); \ +} \ ANN static inline void nspc_push_##b(MemPool p, const Nspc n) { scope_push(p, n->info->b); }\ ANN static inline void nspc_pop_##b (MemPool p, const Nspc n) { scope_pop (p, n->info->b); }\ describe_lookups(A, b) diff --git a/src/lib/object.c b/src/lib/object.c index fc5cad82..a3c47ddb 100644 --- a/src/lib/object.c +++ b/src/lib/object.c @@ -163,7 +163,7 @@ static inline Type new_force_type(MemPool p, const Type t, const Symbol sym) { ADD_REF(ret->nspc) ret->name = s_name(sym); ret->flag = t->flag | ae_flag_force; - map_set(&t->e->owner->info->type->map, (vtype)sym, (vtype)ret); + nspc_add_type_front(t->e->owner, sym, ret); return ret; } diff --git a/src/lib/tuple.c b/src/lib/tuple.c index a7d94469..f6d50ba7 100644 --- a/src/lib/tuple.c +++ b/src/lib/tuple.c @@ -304,7 +304,7 @@ ANN Type tuple_type(const Env env, const Vector v, const loc_t pos) { SET_FLAG(cdef->base.type, abstract); cdef->base.type->e->tuple->list = tlbase; CHECK_BO(traverse_cdef(env, cdef)) - map_set(&env->curr->info->type->map, (vtype)sym, (vtype)cdef->base.type); + nspc_add_type_front(env->curr, sym, cdef->base.type); return cdef->base.type; } diff --git a/src/oo/env.c b/src/oo/env.c index 0dda4c35..0b8e0598 100644 --- a/src/oo/env.c +++ b/src/oo/env.c @@ -86,7 +86,7 @@ ANN void env_add_type(const Env env, const Type type) { v_type->e->d.base_type = type; SET_FLAG(type, builtin); const Symbol sym = insert_symbol(type->name); - map_set(&env->curr->info->type->map, (vtype)sym, (vtype)type); + nspc_add_type_front(env->curr, sym, type); const Value v = new_value(env->gwion->mp, v_type, s_name(sym)); SET_FLAG(v, checked | ae_flag_const | ae_flag_global | ae_flag_builtin); nspc_add_value(env->curr, insert_symbol(type->name), v); diff --git a/src/oo/type.c b/src/oo/type.c index 87c9d900..418d0fb4 100644 --- a/src/oo/type.c +++ b/src/oo/type.c @@ -124,7 +124,7 @@ ANN Type array_type(const Env env, const Type base, const m_uint depth) { ADD_REF(t->nspc); SET_FLAG(t, checked); t->e->owner = base->e->owner; - map_set(&base->e->owner->info->type->map, (vtype)sym, (vtype)t); + nspc_add_type_front(base->e->owner, sym, t); return t; } diff --git a/src/parse/check.c b/src/parse/check.c index 30a4638e..33b194fb 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -244,7 +244,7 @@ ANN static inline Value prim_str_value(const Env env, const Symbol sym) { if(v) return v; const Value value = new_value(env->gwion->mp, t_string, s_name(sym)); - map_set(&env->global_nspc->info->value->map, (vtype)sym, (vtype)value); + nspc_add_value_front(env->global_nspc, sym, value); return value; } @@ -573,7 +573,7 @@ CHECK_BO(check_call(env, exp)) m_func = find_func_match(env, fbase->func, exp->args); nspc_pop_type(env->gwion->mp, env->curr); if(!value && m_func) - map_set(&v->owner->info->type->map, (vtype)sym, (vtype)actual_type(m_func->value_ref->type)); + nspc_add_type_front(v->owner, sym, actual_type(m_func->value_ref->type)); } free_fptr_def(env->gwion->mp, fptr); // ???? related } diff --git a/src/parse/scan0.c b/src/parse/scan0.c index b05e8d76..6036a898 100644 --- a/src/parse/scan0.c +++ b/src/parse/scan0.c @@ -15,7 +15,7 @@ #include "parser.h" static inline void add_type(const Env env, const Nspc nspc, const Type t) { - map_set(&nspc->info->type->map, (m_uint)insert_symbol(t->name), (m_uint)t); + nspc_add_type_front(nspc, insert_symbol(t->name), t); } ANN static Value mk_class(const Env env, const Type base) { @@ -25,7 +25,7 @@ ANN static Value mk_class(const Env env, const Type base) { t->e->d.base_type = base; v->owner = base->e->owner; SET_FLAG(v, const | ae_flag_checked); - map_set(&base->e->owner->info->value->map, (vtype)sym, (vtype)v); + nspc_add_value_front(base->e->owner, sym, v); return v; } diff --git a/src/parse/template.c b/src/parse/template.c index 2293c366..11cc1942 100644 --- a/src/parse/template.c +++ b/src/parse/template.c @@ -201,7 +201,7 @@ ANN Type scan_type(const Env env, const Type t, const Type_Decl* type) { a->base.tmpl = mk_tmpl(env, t, t->e->def->base.tmpl, type->types); if(t->e->parent != t_union) { CHECK_BO(scan0_class_def(env, a)) - map_set(&env->curr->info->type->map, (vtype)a->base.xid, (vtype)a->base.type); + nspc_add_type_front(env->curr, a->base.xid, a->base.type); } else { a->union_def = new_union_def(env->gwion->mp, a->list, loc_cpy(env->gwion->mp, t->e->def->pos)); @@ -232,7 +232,7 @@ ANN Type scan_type(const Env env, const Type t, const Type_Decl* type) { ret->e->parent = t; ret->name = s_name(sym); SET_FLAG(ret, func); - map_set(&t->e->owner->info->type->map, (vtype)sym, (vtype)ret); + nspc_add_type_front(t->e->owner, sym, ret); const Func_Def def = cpy_func_def(env->gwion->mp, t->e->d.func->def); const Func func = ret->e->d.func = new_func(env->gwion->mp, s_name(sym), def); const Value value = new_value(env->gwion->mp, ret, s_name(sym)); @@ -243,7 +243,7 @@ ANN Type scan_type(const Env env, const Type t, const Type_Decl* type) { func->value_ref = value; func->def->base->tmpl = mk_tmpl(env, t, t->e->d.func->def->base->tmpl, type->types); def->base->func = func; - map_set(&t->e->owner->info->value->map, (vtype)sym, (vtype)value); // to base ? + nspc_add_value_front(t->e->owner, sym, value); return ret; } ERR_O(type->xid->pos, diff --git a/src/parse/type_decl.c b/src/parse/type_decl.c index d361f317..21675e7a 100644 --- a/src/parse/type_decl.c +++ b/src/parse/type_decl.c @@ -29,7 +29,7 @@ ANN Type type_nonnull(const Env env, const Type base) { t->name = s_name(sym); t->flag = base->flag; SET_FLAG(t, nonnull); - map_set(&t->e->owner->info->type->map, (vtype)sym, (vtype)t); + nspc_add_type_front(t->e->owner, sym, t); return t; } -- 2.43.0