From 10d851670fdd9dca2c4be839bd53cba8c94553a6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Wed, 18 Nov 2020 17:47:50 +0100 Subject: [PATCH] :bug: Fix overriding --- ast | 2 +- src/compile.c | 3 ++- src/env/env.c | 9 +++++++-- src/parse/scan2.c | 22 ++++++++++++++++++---- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/ast b/ast index bea5d76b..1c926997 160000 --- a/ast +++ b/ast @@ -1 +1 @@ -Subproject commit bea5d76b2bdb10a0cbc68b0549d1202db7e5f9e6 +Subproject commit 1c926997c46cacddf13085217523a93f36a3b1c5 diff --git a/src/compile.c b/src/compile.c index 4227f17d..5e30d46d 100644 --- a/src/compile.c +++ b/src/compile.c @@ -112,7 +112,8 @@ ANN static inline m_bool _check(struct Gwion_* gwion, struct Compiler* c) { CHECK_BB(pass[1](gwion->env, &ret)) CHECK_BB(ret) } - ast_cleaner(gwion, c->ast); + if(!arg.global) + ast_cleaner(gwion, c->ast); return GW_OK; } diff --git a/src/env/env.c b/src/env/env.c index 73c8e4f3..122dee71 100644 --- a/src/env/env.c +++ b/src/env/env.c @@ -7,6 +7,7 @@ #include "traverse.h" #include "vm.h" #include "parse.h" +#include "clean.h" ANN static struct Env_Scope_ *new_envscope(MemPool p) { struct Env_Scope_ *a = mp_calloc(p, Env_Scope); @@ -42,8 +43,12 @@ ANN void env_reset(const Env env) { ANN void release_ctx(struct Env_Scope_ *a, struct Gwion_ *gwion) { const m_uint size = vector_size(&a->known_ctx); - for(m_uint i = size + 1; --i;) - context_remref((Context)vector_at(&a->known_ctx, i - 1), gwion); + for(m_uint i = size + 1; --i;) { + const Context ctx = (Context)vector_at(&a->known_ctx, i - 1); + if(!ctx->error && ctx->global) + ast_cleaner(gwion, ctx->tree); + context_remref(ctx, gwion); + } } ANN static void free_env_scope(struct Env_Scope_ *a, Gwion gwion) { diff --git a/src/parse/scan2.c b/src/parse/scan2.c index 3d85bcd6..ccaeb95e 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -501,11 +501,25 @@ ANN2(1,2) m_bool scan2_fdef_std(const Env env, const Func_Def f, const Value ove return GW_OK; } -ANN m_bool scan2_fdef(const Env env, const Func_Def f) { - const Value overload = nspc_lookup_value2(env->curr, f->base->xid); // try0 +//! use function from parent class as next. +ANN static void upfunction(const Env env, const Func_Base *fb) { + const Value v = find_value(env->class_def->info->parent, fb->xid); + if(!v) + return; + Func func = fb->func; + while(func->next && func->next->value_ref->from->owner == env->curr) + func = func->next; + func->next = v->d.func_ref; +} + +ANN m_bool scan2_fdef(const Env env, const Func_Def fdef) { + const Value overload = nspc_lookup_value2(env->curr, fdef->base->xid); if(overload) - CHECK_BB(scan2_func_def_overload(env, f, overload)) - return (!tmpl_base(f->base->tmpl) ? scan2_fdef_std : scan2_fdef_tmpl)(env, f, overload); + CHECK_BB(scan2_func_def_overload(env, fdef, overload)) + CHECK_BB((!tmpl_base(fdef->base->tmpl) ? scan2_fdef_std : scan2_fdef_tmpl)(env, fdef, overload)) + if(env->class_def) + upfunction(env, fdef->base); + return GW_OK; } __attribute__((returns_nonnull)) -- 2.43.0