From: Jérémie Astor Date: Tue, 18 May 2021 20:54:29 +0000 (+0200) Subject: :art: Introduce envset_pushv X-Git-Tag: nightly~633 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=48455224cca79974a03081b452814c70cec66dd5;p=gwion.git :art: Introduce envset_pushv --- diff --git a/ast b/ast index 5c6ff39a..40397642 160000 --- a/ast +++ b/ast @@ -1 +1 @@ -Subproject commit 5c6ff39a52550be2956e927091e58470d3cc6dc6 +Subproject commit 40397642ad13c18fc0edc65791b475e29d832d8a diff --git a/include/env/envset.h b/include/env/envset.h index c3981bf2..aff25a5f 100644 --- a/include/env/envset.h +++ b/include/env/envset.h @@ -8,11 +8,16 @@ struct EnvSet { const void *data; const m_int scope; const enum tflag flag; + Context _ctx; + m_str _filename; bool run; }; ANN m_bool envset_run(struct EnvSet*, const Type); ANN2(1,3) m_bool envset_push(struct EnvSet*, const Type, const Nspc); +ANN static inline m_bool envset_pushv(struct EnvSet *es, const Value v) { + return envset_push(es, v->from->owner_class, v->from->owner); +} ANN2(1) void envset_pop(struct EnvSet*, const Type); ANN static inline m_bool extend_push(const Env env, const Type t) { diff --git a/src/emit/emit.c b/src/emit/emit.c index 5e3ed476..6f23c45f 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -1095,7 +1095,7 @@ 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=tflag_emit }; - CHECK_BB(envset_push(&es, v->from->owner_class, v->from->owner)); + CHECK_BB(envset_pushv(&es, v)); (void)emit_push(emit, v->from->owner_class, v->from->owner); const m_bool ret = emit_func_def(emit, f->def); if(es.run) @@ -1505,7 +1505,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=tflag_emit }; - CHECK_BB(envset_push(&es, lambda->owner, lambda->def->base->func->value_ref->from->owner)); + CHECK_BB(envset_pushv(&es, lambda->def->base->func->value_ref)); const m_bool ret = emit_lambda(emit, lambda); if(es.run) envset_pop(&es, lambda->owner); @@ -1575,7 +1575,7 @@ ANN static m_bool emit_stmt_code(const Emitter emit, const Stmt_Code stmt) { return ret; } -ANN static m_bool optimize_taill_call(const Emitter emit, const Exp_Call* e) { +ANN static m_bool optimize_tail_call(const Emitter emit, const Exp_Call* e) { if(e->args) { emit_func_args(emit, e); const Func f = e->func->type->info->func; @@ -1592,7 +1592,7 @@ ANN static m_bool emit_stmt_return(const Emitter emit, const Stmt_Exp stmt) { if(stmt->val->exp_type == ae_exp_call) { const Func f = stmt->val->d.exp_call.func->type->info->func; if(stmt->val->exp_type == ae_exp_call && emit->env->func == f) - return optimize_taill_call(emit, &stmt->val->d.exp_call); + return optimize_tail_call(emit, &stmt->val->d.exp_call); } CHECK_BB(emit_exp_pop_next(emit, stmt->val)); } diff --git a/src/env/envset.c b/src/env/envset.c index 52d59559..0559da8a 100644 --- a/src/env/envset.c +++ b/src/env/envset.c @@ -29,6 +29,10 @@ ANN static m_bool push(struct EnvSet *es, const Type t) { env_push_type((void*)es->env, t); if(tflag(t, tflag_tmpl)) CHECK_BB(template_push_types(es->env, t->info->cdef->base.tmpl)); // incorrect templates? + es->_ctx = es->env->context; + es->_filename = es->env->name; + es->env->context = t->info->value->from->ctx; + es->env->name = t->info->value->from->filename; return GW_OK; } @@ -44,7 +48,7 @@ ANN2(1,3) m_bool envset_push(struct EnvSet *es, const Type t, const Nspc nspc) { return GW_OK; } -ANN2(1) void envset_pop(struct EnvSet *es, const Type t) { +ANN2(1) static void _envset_pop(struct EnvSet *es, const Type t) { if(safe_tflag(t, tflag_tmpl)) // might not be useful nspc_pop_type(es->env->gwion->mp, es->env->curr); env_pop(es->env, es->scope); @@ -57,6 +61,14 @@ ANN2(1) void envset_pop(struct EnvSet *es, const Type t) { env_pop(es->env, es->scope); } +ANN2(1) void envset_pop(struct EnvSet *es, const Type t) { + _envset_pop(es, t); + if(es->_ctx) + es->env->context = es->_ctx; + if(es->_filename) + es->env->name = es->_filename; +} + ANN m_bool envset_run(struct EnvSet *es, const Type t) { check(es, t); const Type owner_class = t->info->value->from->owner_class; diff --git a/src/lib/object_op.c b/src/lib/object_op.c index eb8b6a23..a1b6525a 100644 --- a/src/lib/object_op.c +++ b/src/lib/object_op.c @@ -277,7 +277,7 @@ ANN Type scan_class(const Env env, const Type t, const Type_Decl *td) { struct EnvSet es = { .env=env, .data=env, .func=(_exp_func)scan0_cdef, .scope=env->scope->depth, .flag=tflag_scan0 }; const Type owner = t->info->value->from->owner_class; - CHECK_BO(envset_push(&es, owner, t->info->value->from->owner)); + CHECK_BO(envset_pushv(&es, t->info->value)); const Type ret = _scan_class(env, &info); if(es.run) envset_pop(&es, owner); diff --git a/src/parse/check.c b/src/parse/check.c index 42a3713d..68100dec 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -646,7 +646,7 @@ ANN static Type check_predefined(const Env env, Exp_Call *exp, const Value v, co if(!fdef->base->ret_type) { // template fptr struct EnvSet es = { .env=env, .data=env, .func=(_exp_func)check_cdef, .scope=env->scope->depth, .flag=tflag_check }; - CHECK_BO(envset_push(&es, v->from->owner_class, v->from->owner)); + CHECK_BO(envset_pushv(&es, v)); func->def->base->fbflag |= fbflag_internal; const m_bool ret = check_traverse_fdef(env, func->def); if(es.run) @@ -786,7 +786,7 @@ ANN Type check_exp_call1(const Env env, Exp_Call *const exp) { // if(!fflag(func, fflag_valid)) { struct EnvSet es = { .env=env, .data=env, .func=(_exp_func)check_cdef, .scope=env->scope->depth, .flag=tflag_check }; - CHECK_BO(envset_push(&es, func->value_ref->from->owner_class, func->value_ref->from->owner)); + CHECK_BO(envset_pushv(&es, func->value_ref)); CHECK_BO(check_func_def(env, func->def)); if(es.run) envset_pop(&es, func->value_ref->from->owner_class); diff --git a/src/parse/func_resolve_tmpl.c b/src/parse/func_resolve_tmpl.c index 0b875de6..d65376f3 100644 --- a/src/parse/func_resolve_tmpl.c +++ b/src/parse/func_resolve_tmpl.c @@ -127,7 +127,7 @@ ANN static Func find_tmpl(const Env env, const Value v, Exp_Call *const exp, con struct EnvSet es = { .env=env, .data=env, .func=(_exp_func)check_cdef, .scope=scope, .flag=tflag_check }; struct ResolverArgs ra = {.v = v, .e = exp, .tmpl_name = tmpl_name, .types = types}; - CHECK_BO(envset_push(&es, v->from->owner_class, v->from->owner)); + CHECK_BO(envset_pushv(&es, v)); (void)env_push(env, v->from->owner_class, v->from->owner); if(v->from->owner_class && v->from->owner_class->info->cdef->base.tmpl) (void)template_push_types(env, v->from->owner_class->info->cdef->base.tmpl);