From 6de02ea74eb59c40863c7d078faee26cb4b30ea2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Mon, 9 Aug 2021 11:16:22 +0200 Subject: [PATCH] :art: Improe func_def checking --- src/emit/emit.c | 10 +++++++++- src/parse/check.c | 10 +++++++++- src/parse/scan1.c | 10 +++++++++- src/parse/scan2.c | 10 +++++++++- 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/emit/emit.c b/src/emit/emit.c index 9fc957a8..2144d6c5 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -2660,7 +2660,7 @@ ANN static void emit_fdef_finish(const Emitter emit, const Func_Def fdef) { func->code->memoize = memoize_ini(emit, func); } -ANN m_bool emit_func_def(const Emitter emit, const Func_Def f) { +ANN m_bool _emit_func_def(const Emitter emit, const Func_Def f) { if (tmpl_base(f->base->tmpl) && fbflag(f->base, fbflag_op)) return GW_OK; const Func func = f->base->func; const Func_Def fdef = func->def; @@ -2698,6 +2698,14 @@ ANN m_bool emit_func_def(const Emitter emit, const Func_Def f) { return ret; } +ANN m_bool emit_func_def(const Emitter emit, const Func_Def fdef) { + const uint16_t depth = emit->env->scope->depth; + emit->env->scope->depth = 0; + const m_bool ret = _emit_func_def(emit, fdef); + emit->env->scope->depth = depth; + return ret; +} + ANN static m_bool emit_extend_def(const Emitter emit, const Extend_Def xdef); #define emit_fptr_def dummy_func #define emit_trait_def dummy_func diff --git a/src/parse/check.c b/src/parse/check.c index 3489d332..75535e96 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -1574,7 +1574,7 @@ ANN m_bool check_fdef(const Env env, const Func_Def fdef) { return GW_OK; } -ANN m_bool check_func_def(const Env env, const Func_Def f) { +ANN m_bool _check_func_def(const Env env, const Func_Def f) { if (tmpl_base(f->base->tmpl) && fbflag(f->base, fbflag_op)) return GW_OK; const Func func = f->base->func; const Func_Def fdef = func->def; @@ -1634,6 +1634,14 @@ ANN m_bool check_func_def(const Env env, const Func_Def f) { return ret; } +ANN m_bool check_func_def(const Env env, const Func_Def fdef) { + const uint16_t depth = env->scope->depth; + env->scope->depth = 0; + const m_bool ret = _check_func_def(env, fdef); + env->scope->depth = depth; + return ret; +} + ANN static m_bool check_extend_def(const Env env, const Extend_Def xdef) { CHECK_BB(ensure_check(env, xdef->t)); CHECK_BB(extend_push(env, xdef->t)); diff --git a/src/parse/scan1.c b/src/parse/scan1.c index f748014e..52ef77d3 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -677,7 +677,7 @@ ANN static inline m_bool scan1_fdef_defined(const Env env, return GW_OK; } -ANN m_bool scan1_func_def(const Env env, const Func_Def fdef) { +ANN static m_bool _scan1_func_def(const Env env, const Func_Def fdef) { const bool global = GET_FLAG(fdef->base, global); const m_uint scope = !global ? env->scope->depth : env_push_global(env); if (fdef->base->td) @@ -695,6 +695,14 @@ ANN m_bool scan1_func_def(const Env env, const Func_Def fdef) { return ret; } +ANN m_bool scan1_func_def(const Env env, const Func_Def fdef) { + const uint16_t depth = env->scope->depth; + env->scope->depth = 0; + const m_bool ret = _scan1_func_def(env, fdef); + env->scope->depth = depth; + return ret; +} + ANN static m_bool scan1_extend_def(const Env env, const Extend_Def xdef) { CHECK_BB(ensure_scan1(env, xdef->t)); CHECK_BB(extend_push(env, xdef->t)); diff --git a/src/parse/scan2.c b/src/parse/scan2.c index fb60fcb4..b56419b2 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -543,7 +543,7 @@ static inline int is_cpy(const Func_Def fdef) { (fdef->base->tmpl && !fdef->base->tmpl->call); } -ANN m_bool scan2_func_def(const Env env, const Func_Def fdef) { +ANN m_bool _scan2_func_def(const Env env, const Func_Def fdef) { if (tmpl_base(fdef->base->tmpl) && fbflag(fdef->base, fbflag_op)) return GW_OK; if(!strcmp(s_name(fdef->base->xid), "new")) { @@ -568,6 +568,14 @@ ANN m_bool scan2_func_def(const Env env, const Func_Def fdef) { return GW_OK; } +ANN m_bool scan2_func_def(const Env env, const Func_Def fdef) { + const uint16_t depth = env->scope->depth; + env->scope->depth = 0; + const m_bool ret = _scan2_func_def(env, fdef); + env->scope->depth = depth; + return ret; +} + ANN static m_bool scan2_extend_def(const Env env, const Extend_Def xdef) { CHECK_BB(ensure_scan2(env, xdef->t)); CHECK_BB(extend_push(env, xdef->t)); -- 2.43.0