From c1e187df2be9801106f4bc83b389e1404bf1b3d9 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Mon, 26 Feb 2024 21:00:16 +0100 Subject: [PATCH] :fire: use envset_pushf --- include/env/envset.h | 15 ++++++++++++--- src/emit/emit.c | 12 ++++-------- src/parse/func_resolve_tmpl.c | 15 ++++++--------- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/include/env/envset.h b/include/env/envset.h index 34351910..798d4c71 100644 --- a/include/env/envset.h +++ b/include/env/envset.h @@ -15,14 +15,23 @@ struct EnvSet { ANN bool envset_run(struct EnvSet *, const Type); ANN2(1, 3) bool envset_push(struct EnvSet *, const Type, const Nspc); +ANN2(1) void envset_pop(struct EnvSet *, const Type); + ANN static inline bool envset_pushv(struct EnvSet *es, const Value v) { es->_ctx = es->env->context; es->_filename = es->env->name; - CHECK_B(envset_push(es, v->from->owner_class, v->from->owner)); - return true; + return envset_push(es, v->from->owner_class, v->from->owner); } -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); } + +ANN static inline bool envset_pushf(struct EnvSet *es, const Value owner) { + CHECK_B(envset_pushv(es, owner)); + return env_pushv(es->env, owner); +} +ANN2(1) static inline void envset_popf(struct EnvSet *es, const Value owner) { + env_pop(es->env, es->scope); + envset_popv(es, owner); +} #endif diff --git a/src/emit/emit.c b/src/emit/emit.c index 0cfe754d..8df95410 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -1433,11 +1433,9 @@ ANN bool traverse_dot_tmpl(const Emitter emit, const Func_Def fdef, const Value .func = (_envset_func)emit_cdef, .scope = scope, .flag = tflag_emit}; - CHECK_B(envset_pushv(&es, v)); - (void)emit_pushv(emit, v); + CHECK_B(envset_pushf(&es, v)); const bool ret = traverse_emit_func_def(emit, fdef); - emit_pop(emit, scope); - envset_popv(&es, v); + envset_popf(&es, v); emit->env->scope->shadowing = shadowing; return ret; } @@ -1479,11 +1477,9 @@ ANN static bool emit_template_code(const Emitter emit, const Func f) { .func = (_envset_func)emit_cdef, .scope = scope, .flag = tflag_emit}; - CHECK_B(envset_pushv(&es, v)); - (void)emit_pushv(emit, v); + CHECK_B(envset_pushf(&es, v)); const bool ret = emit_func_def(emit, f->def); - envset_popv(&es, v); - emit_pop(emit, scope); + envset_popf(&es, v); return ret ? push_func_code(emit, f) : false; } diff --git a/src/parse/func_resolve_tmpl.c b/src/parse/func_resolve_tmpl.c index 7ec3f53d..1813d564 100644 --- a/src/parse/func_resolve_tmpl.c +++ b/src/parse/func_resolve_tmpl.c @@ -32,10 +32,10 @@ ANN static inline Value template_get_ready(const Env env, const Value v, ANN static inline bool tmpl_valid(const Env env, const Func_Def fdef, const m_str filename) { if (safe_fflag(fdef->base->func, fflag_valid)) return true; - const m_str old_file = env->name; - env->name = filename; +// const m_str old_file = env->name; +// env->name = filename; const bool ret = check_traverse_fdef(env, fdef); - env->name = old_file; +// env->name = old_file; if(!fdef->base->func) free_func_def(env->gwion->mp, fdef); return ret; } @@ -147,16 +147,14 @@ ANN static Func find_tmpl(const Env env, const Value v, Exp_Call *const exp, const m_str tmpl_name) { const TmplArg_List types = exp->tmpl->call; const Func former = env->func; - const m_uint scope = env->scope->depth; struct EnvSet es = {.env = env, .data = env, .func = (_envset_func)check_cdef, - .scope = scope, + .scope = env->scope->depth, .flag = tflag_check}; struct ResolverArgs ra = { .v = v, .e = exp, .tmpl_name = tmpl_name, .types = types}; - CHECK_O(envset_pushv(&es, v)); - (void)env_pushv(env, v); + CHECK_O(envset_pushf(&es, v)); const Tmpl *tmpl = v->from->owner_class && v->from->owner_class->info->cdef ? get_tmpl(v->from->owner_class) : NULL; if(tmpl) @@ -166,8 +164,7 @@ ANN static Func find_tmpl(const Env env, const Value v, Exp_Call *const exp, : fptr_match(env, &ra); if(tmpl) nspc_pop_type(env->gwion->mp, env->curr); - env_pop(env, scope); - envset_popv(&es, v); + envset_popf(&es, v); env->func = former; return m_func; } -- 2.43.0