From: Jérémie Astor Date: Fri, 8 May 2020 11:52:07 +0000 (+0200) Subject: :art: Make envset account for owner nspc X-Git-Tag: nightly~1630 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=22de800f385227d71d099aa9e298ec83cb10a975;p=gwion.git :art: Make envset account for owner nspc --- diff --git a/include/env/envset.h b/include/env/envset.h index e6d54985..1e11c9b9 100644 --- a/include/env/envset.h +++ b/include/env/envset.h @@ -11,7 +11,7 @@ struct EnvSet { m_bool run; }; -ANN m_bool envset_run(struct EnvSet *es, const Type t); -ANN m_bool envset_push(struct EnvSet *es, const Type t); -ANN void envset_pop(struct EnvSet *es, const Type t); +ANN m_bool envset_run(struct EnvSet*, const Type); +ANN2(1,3) m_bool envset_push(struct EnvSet*, const Type, const Nspc); +ANN2(1) void envset_pop(struct EnvSet*, const Type); #endif diff --git a/src/emit/emit.c b/src/emit/emit.c index 579445d6..806efee2 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -844,12 +844,11 @@ ANN m_bool traverse_dot_tmpl(const Emitter emit, const struct dottmpl_ *dt) { const m_uint scope = emit->env->scope->depth; struct EnvSet es = { .env=emit->env, .data=emit, .func=(_exp_func)emit_cdef, .scope=scope, .flag=ae_flag_emit }; - if(dt->owner_class) - envset_push(&es, dt->owner_class); + CHECK_BB(envset_push(&es, dt->owner_class, dt->owner)) (void)emit_push(emit, dt->owner_class, dt->owner); const m_bool ret = traverse_emit_func_def(emit, dt->def); if(es.run) - envset_pop(&es, dt->owner_class->e->owner_class); + envset_pop(&es, dt->owner_class); emit_pop(emit, scope); return ret; } @@ -885,12 +884,11 @@ ANN static m_bool emit_template_code(const Emitter emit, const Func f) { const size_t scope = emit->env->scope->depth; struct EnvSet es = { .env=emit->env, .data=emit, .func=(_exp_func)emit_cdef, .scope=scope, .flag=ae_flag_emit }; - if(v->from->owner_class) - envset_push(&es, v->from->owner_class); + CHECK_BB(envset_push(&es, v->from->owner_class, v->from->owner)) (void)emit_push(emit, v->from->owner_class, v->from->owner); const m_bool ret = emit_func_def(emit, f->def); if(es.run) - envset_pop(&es, v->from->owner_class->e->owner_class); + envset_pop(&es, v->from->owner_class); emit_pop(emit, scope); return ret > 0 ? push_func_code(emit, f) : GW_ERROR; } @@ -1215,8 +1213,7 @@ ANN static m_bool emit_exp_lambda(const Emitter emit, const Exp_Lambda * lambda) } struct EnvSet es = { .env=emit->env, .data=emit, .func=(_exp_func)emit_cdef, .scope=emit->env->scope->depth, .flag=ae_flag_emit }; - if(lambda->owner) - envset_push(&es, lambda->owner); + CHECK_BB(envset_push(&es, lambda->owner, lambda->def->base->func->value_ref->from->owner)) const m_bool ret = emit_lambda(emit, lambda); if(es.run) envset_pop(&es, lambda->owner); diff --git a/src/env/envset.c b/src/env/envset.c index 3ff71a90..de3917a5 100644 --- a/src/env/envset.c +++ b/src/env/envset.c @@ -28,19 +28,26 @@ ANN static m_bool push(struct EnvSet *es, const Type t) { return GW_OK; } -ANN m_bool envset_push(struct EnvSet *es, const Type t) { - check(es, t); - if(es->run) - CHECK_BB(envset_push(es, t->e->owner_class)) +ANN2(1,3) m_bool envset_push(struct EnvSet *es, const Type t, const Nspc nspc) { + if(t) { + check(es, t); + return es->run ? push(es, t) : GW_OK; + } + if(nspc != es->env->curr) { + env_push(es->env, NULL, nspc); + es->run = 1; + } return GW_OK; } -ANN void envset_pop(struct EnvSet *es, const Type t) { +ANN2(1) void envset_pop(struct EnvSet *es, const Type t) { env_pop(es->env, es->scope); + if(!t) + return; if(GET_FLAG(t, template)) nspc_pop_type(es->env->gwion->mp, es->env->curr); if(t->e->owner_class) - envset_pop(es, t->e->owner_class); + envset_pop(es, t); } ANN m_bool envset_run(struct EnvSet *es, const Type t) { diff --git a/src/lib/func.c b/src/lib/func.c index cd148023..105d5678 100644 --- a/src/lib/func.c +++ b/src/lib/func.c @@ -169,8 +169,8 @@ ANN m_bool check_lambda(const Env env, const Type t, Exp_Lambda *l) { const Func_Def fdef = t->e->d.func->def; struct EnvSet es = { .env=env, .data=env, .func=(_exp_func)check_cdef, .scope=env->scope->depth, .flag=ae_flag_check }; - if((l->owner = t->e->owner_class)) - envset_push(&es, l->owner); + l->owner = t->e->owner_class; + CHECK_BB(envset_push(&es, l->owner, t->e->owner)) const m_bool ret = _check_lambda(env, l, fdef); if(es.run) envset_pop(&es, l->owner); diff --git a/src/lib/object_op.c b/src/lib/object_op.c index 031aac07..86e69862 100644 --- a/src/lib/object_op.c +++ b/src/lib/object_op.c @@ -406,8 +406,7 @@ ANN static Type scan_class(const Env env, const Type t, const Type_Decl* td) { return a->base.type; struct EnvSet es = { .env=env, .data=env, .func=(_exp_func)scan0_cdef, .scope=env->scope->depth, .flag=ae_flag_scan0 }; - if(t->e->owner_class) - CHECK_BO(envset_push(&es, t->e->owner_class)) + CHECK_BO(envset_push(&es, t->e->owner_class, t->e->owner)) a->base.tmpl = mk_tmpl(env, t->e->def->base.tmpl, td->types); const m_bool ret = _scan_class(env, t, a); if(es.run) diff --git a/src/parse/check.c b/src/parse/check.c index d8ba501e..a1147bda 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -498,8 +498,7 @@ ANN static Func _find_template_match(const Env env, const Value v, const Exp_Cal const m_uint scope = env->scope->depth; struct EnvSet es = { .env=env, .data=env, .func=(_exp_func)check_cdef, .scope=scope, .flag=ae_flag_check }; - if(v->from->owner_class) - envset_push(&es, v->from->owner_class); + CHECK_BO(envset_push(&es, v->from->owner_class, v->from->owner)) (void)env_push(env, v->from->owner_class, v->from->owner); if(is_fptr(env->gwion, v->type)) { const Symbol sym = func_symbol(env, v->from->owner->name, v->name, tmpl_name, 0); @@ -659,8 +658,7 @@ ANN static Type check_predefined(const Env env, Exp_Call *exp, const Value v, co const m_uint scope = env->scope->depth; struct EnvSet es = { .env=env, .data=env, .func=(_exp_func)check_cdef, .scope=scope, .flag=ae_flag_check }; - if(v->from->owner_class) - envset_push(&es, v->from->owner_class); + CHECK_BO(envset_push(&es, v->from->owner_class, v->from->owner)) (void)env_push(env, v->from->owner_class, v->from->owner); const m_bool ret = traverse_func_def(env, func->def); if(es.run)