From d1ab76d9fb96a1e6ed7f52c75b21a6d7e8a40f41 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Mon, 26 Feb 2024 19:55:21 +0100 Subject: [PATCH] :fire: use envset_pushv --- include/env/envset.h | 3 +++ src/emit/emit.c | 4 ++-- src/lib/array.c | 12 +++++++----- src/lib/closure.c | 2 +- src/lib/object_op.c | 5 +---- src/lib/ref.c | 10 ++++++++-- src/parse/check.c | 2 +- src/parse/func_resolve_tmpl.c | 2 +- src/parse/template.c | 12 +++--------- 9 files changed, 27 insertions(+), 25 deletions(-) diff --git a/include/env/envset.h b/include/env/envset.h index 7aec557b..34351910 100644 --- a/include/env/envset.h +++ b/include/env/envset.h @@ -22,4 +22,7 @@ ANN static inline bool envset_pushv(struct EnvSet *es, const Value v) { return true; } ANN2(1) void envset_pop(struct EnvSet *, const Type); +ANN2(1) static inline void envset_popv(struct EnvSet *es, const Value v) { + envset_pop(es, v->from->owner_class); +} #endif diff --git a/src/emit/emit.c b/src/emit/emit.c index 6b7356f6..0cfe754d 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -1437,7 +1437,7 @@ ANN bool traverse_dot_tmpl(const Emitter emit, const Func_Def fdef, const Value (void)emit_pushv(emit, v); const bool ret = traverse_emit_func_def(emit, fdef); emit_pop(emit, scope); - envset_pop(&es, v->from->owner_class); + envset_popv(&es, v); emit->env->scope->shadowing = shadowing; return ret; } @@ -1482,7 +1482,7 @@ ANN static bool emit_template_code(const Emitter emit, const Func f) { CHECK_B(envset_pushv(&es, v)); (void)emit_pushv(emit, v); const bool ret = emit_func_def(emit, f->def); - envset_pop(&es, v->from->owner_class); + envset_popv(&es, v); emit_pop(emit, scope); return ret ? push_func_code(emit, f) : false; } diff --git a/src/lib/array.c b/src/lib/array.c index bf2e11fc..6910dfd8 100644 --- a/src/lib/array.c +++ b/src/lib/array.c @@ -826,9 +826,12 @@ static OP_CHECK(opck_array_scan) { cdef->base.tmpl->call = new_mp_vector(env->gwion->mp, TmplArg, 1); TmplArg arg = {.type = tmplarg_td, .d = {.td = type2td(env->gwion, base, base->info->value->from->loc)} }; mp_vector_set(cdef->base.tmpl->call, TmplArg, 0, arg); - const Context ctx = env->context; - env->context = base->info->value->from->ctx; - const m_uint scope = env_pushv(env, base->info->value); + struct EnvSet es = { + .env = env, + .data = env, + .scope = env->scope->depth + }; + envset_pushv(&es, base->info->value); CHECK_ON(scan0_class_def(env, cdef)); const Type t = cdef->base.type; if (GET_FLAG(base, abstract) && !tflag(base, tflag_union)) @@ -837,8 +840,7 @@ static OP_CHECK(opck_array_scan) { UNSET_FLAG(t, abstract); const bool ret = traverse_cdef(env, t); UNSET_FLAG(t, abstract); - env_pop(env, scope); - env->context = ctx; + envset_popv(&es, base->info->value); if (!ret) return NULL; set_tflag(t, tflag_emit); t->array_depth = base->array_depth + 1; diff --git a/src/lib/closure.c b/src/lib/closure.c index f118e76a..497c1c2f 100644 --- a/src/lib/closure.c +++ b/src/lib/closure.c @@ -689,7 +689,7 @@ static OP_CHECK(opck_closure_scan) { CHECK_O(envset_pushv(&es, owner->info->value)); const bool ret = traverse_fptr_def(env, fdef); const Type t = ret ? fdef->cdef->base.type : NULL; - envset_pop(&es, owner->info->value->from->owner_class); + envset_popv(&es, owner->info->value); free_fptr_def(env->gwion->mp, fdef); // clean? if(t) set_tflag(t, tflag_emit); return t; diff --git a/src/lib/object_op.c b/src/lib/object_op.c index fd271dd6..a24a61be 100644 --- a/src/lib/object_op.c +++ b/src/lib/object_op.c @@ -326,11 +326,8 @@ ANN Type scan_class(const Env env, const Type t, const Type_Decl *td) { .flag = tflag_check}; const Type owner = t->info->value->from->owner_class; CHECK_O(envset_pushv(&es, t->info->value)); - const bool local = !owner && !tmpl_global(env, td->types) && from_global_nspc(env, env->curr); - if(local && env->context) env_push_nspc(env, env->context->nspc); const Type ret = _scan_class(env, &info); - if(local && env->context)env_pop(env, es.scope); - envset_pop(&es, owner); + envset_popv(&es, t->info->value); return ret; } diff --git a/src/lib/ref.c b/src/lib/ref.c index d09bb8be..93fa602c 100644 --- a/src/lib/ref.c +++ b/src/lib/ref.c @@ -162,12 +162,18 @@ static OP_CHECK(opck_ref_scan) { set_tflag(t, tflag_check); set_tflag(t, tflag_emit); set_tflag(t, tflag_ref); - const m_uint scope = env_pushv(env, base->info->value); + + struct EnvSet es = { + .env = env, + .data = env, + .scope = env->scope->depth, + }; + envset_pushv(&es, base->info->value); mk_class(env, t, ts->td->tag.loc); base2ref(env, base, t); ref2base(env, t, base); ref2ref(env, t, t); - env_pop(env, scope); + envset_popv(&es, base->info->value); t->info->tuple = new_tupleform(env->gwion->mp, base); type_addref(base); vector_add(&t->info->tuple->contains, (vtype)base); diff --git a/src/parse/check.c b/src/parse/check.c index a947218b..3daceb3f 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -756,7 +756,7 @@ ANN static Type check_predefined(const Env env, Exp_Call *exp, const Value v, CHECK_O(envset_pushv(&es, v)); func->def->base->fbflag |= fbflag_internal; const bool ret = check_traverse_fdef(env, func->def); - envset_pop(&es, v->from->owner_class); + envset_popv(&es, v); CHECK_O(ret); } exp->func->type = func->value_ref->type; diff --git a/src/parse/func_resolve_tmpl.c b/src/parse/func_resolve_tmpl.c index 1251f45d..7ec3f53d 100644 --- a/src/parse/func_resolve_tmpl.c +++ b/src/parse/func_resolve_tmpl.c @@ -167,7 +167,7 @@ ANN static Func find_tmpl(const Env env, const Value v, Exp_Call *const exp, if(tmpl) nspc_pop_type(env->gwion->mp, env->curr); env_pop(env, scope); - envset_pop(&es, v->from->owner_class); + envset_popv(&es, v); env->func = former; return m_func; } diff --git a/src/parse/template.c b/src/parse/template.c index 348aa745..a1371caa 100644 --- a/src/parse/template.c +++ b/src/parse/template.c @@ -282,17 +282,11 @@ ANN Type scan_type(const Env env, const Type t, Type_Decl *td) { .data = env, .scope = env->scope->depth, .flag = tflag_none}; - const Context ctx = env->context; - const m_str name = env->name; - envset_push(&es, owner, owner->nspc); - (void)env_push_type(env, owner); // TODO: is this needed? - env->context = owner->info->value->from->ctx; - env->name = owner->info->value->from->filename; + envset_pushv(&es, owner->info->value); + (void)env_push_type(env, owner); const Type ret = known_type(env, td->next); env_pop(env, es.scope); - envset_pop(&es, owner); - env->context = ctx; - env->name = name; + envset_popv(&es, owner->info->value); if (!td->array) return ret; return array_type(env, ret, td->array->depth, td->tag.loc); } -- 2.43.0