From: fennecdjay Date: Sun, 3 Jul 2022 15:55:37 +0000 (+0200) Subject: :bug: Fix Dict globality X-Git-Tag: nightly~264^2~118 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=bb2023a2112097f1a649a060a1759b7986633d71;p=gwion.git :bug: Fix Dict globality --- diff --git a/include/tmpl_info.h b/include/tmpl_info.h index 39b7e26d..68188db4 100644 --- a/include/tmpl_info.h +++ b/include/tmpl_info.h @@ -12,4 +12,5 @@ struct tmpl_info { }; ANN Type tmpl_exists(const Env env, struct tmpl_info *const info); +ANN bool tmpl_global(const Env env, Type_List tl); #endif diff --git a/src/lib/closure.c b/src/lib/closure.c index 8e0428c9..ef5f8165 100644 --- a/src/lib/closure.c +++ b/src/lib/closure.c @@ -672,8 +672,6 @@ static FREEARG(freearg_dottmpl) { #include "traverse.h" #include "gwi.h" -ANN bool tmpl_global(const Env env, Type_List tl); - ANN static bool is_base(const Env env, const Type_List tl) { for(uint32_t i = 0; i < tl->len; i++) { Type_Decl *td = *mp_vector_at(tl, Type_Decl*, i); diff --git a/src/lib/dict.c b/src/lib/dict.c index 3fb81989..693e2ba9 100644 --- a/src/lib/dict.c +++ b/src/lib/dict.c @@ -634,10 +634,16 @@ static OP_CHECK(opck_dict_scan) { cdef->base.xid = info.name; cdef->base.tmpl->call = cpy_type_list(env->gwion->mp, info.td->types); + const bool is_global = tmpl_global(env, ts->td->types); + const m_uint scope = is_global ? env_push_global(env) : env->scope->depth; (void)scan0_class_def(env, cdef); const Type t = cdef->base.type; t->nspc->class_data_size = sizeof(struct HMapInfo); const m_bool ret = traverse_cdef(env, t); + if(is_global) { + env_pop(env, scope); + type_addref(t); + } HMapInfo *const hinfo = (HMapInfo*)t->nspc->class_data; hmapinfo_init(hinfo, env->gwion->type, key, val); if(hinfo->keyk + hinfo->valk) { diff --git a/src/lib/object_op.c b/src/lib/object_op.c index 912cad74..10e346c7 100644 --- a/src/lib/object_op.c +++ b/src/lib/object_op.c @@ -343,17 +343,6 @@ ANN static Type _scan_class(const Env env, struct tmpl_info *info) { return info->ret; } -ANN Type tmpl_exists(const Env env, struct tmpl_info *const info); - -ANN bool tmpl_global(const Env env, Type_List tl) { - for(uint32_t i = 0; i < tl->len; i++) { - Type_Decl *td = *mp_vector_at(tl, Type_Decl*, i); - if(!type_global(env, known_type(env, td))) - return false; - }; - return true; -} - ANN Type scan_class(const Env env, const Type t, const Type_Decl *td) { struct tmpl_info info = { .base = t, .td = td, .list = t->info->cdef->base.tmpl->list}; diff --git a/src/lib/tmpl_info.c b/src/lib/tmpl_info.c index 1f7fffce..6d9d4833 100644 --- a/src/lib/tmpl_info.c +++ b/src/lib/tmpl_info.c @@ -96,3 +96,12 @@ ANN Type tmpl_exists(const Env env, struct tmpl_info *const info) { info->name = template_id(env, info); return _tmpl_exists(env, info->name); } + +ANN bool tmpl_global(const Env env, Type_List tl) { + for(uint32_t i = 0; i < tl->len; i++) { + Type_Decl *td = *mp_vector_at(tl, Type_Decl*, i); + if(!type_global(env, known_type(env, td))) + return false; + } + return true; +}