From 4b84bb8a5596f2ddf41195714f43668c09bd72cb Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Mon, 12 Feb 2024 18:55:12 +0100 Subject: [PATCH] :fire: more progress --- include/env/envset.h | 12 ++++---- include/parse.h | 53 +++++++++----------------------- src/emit/emit.c | 46 ++++++++++++++++++---------- src/env/envset.c | 18 +++++------ src/lib/closure.c | 8 ++--- src/lib/object_op.c | 4 +-- src/parse/check.c | 12 ++++---- src/parse/func_resolve_tmpl.c | 4 +-- src/parse/scan0.c | 2 +- src/parse/scan1.c | 6 ++-- src/parse/scan2.c | 4 +-- src/parse/scanx.c | 57 +++++++++++------------------------ src/parse/traverse.c | 2 +- 13 files changed, 98 insertions(+), 130 deletions(-) diff --git a/include/env/envset.h b/include/env/envset.h index dc6db789..72fc4eba 100644 --- a/include/env/envset.h +++ b/include/env/envset.h @@ -1,10 +1,10 @@ #ifndef __ENVSET #define __ENVSET -typedef m_bool (*envset_func)(const void *, const void *); +typedef bool (*_envset_func)(const void *, const void *); struct EnvSet { const Env env; - const envset_func func; + const _envset_func func; const void * data; const enum tflag flag; Context _ctx; @@ -13,12 +13,12 @@ struct EnvSet { 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) { +ANN bool envset_run(struct EnvSet *, const Type); +ANN2(1, 3) bool envset_push(struct EnvSet *, const Type, const Nspc); +ANN static inline bool envset_pushv(struct EnvSet *es, const Value v) { es->_ctx = es->env->context; es->_filename = es->env->name; - CHECK_BB(envset_push(es, v->from->owner_class, v->from->owner)); + CHECK_B(envset_push(es, v->from->owner_class, v->from->owner)); return GW_OK; } ANN2(1) void envset_pop(struct EnvSet *, const Type); diff --git a/include/parse.h b/include/parse.h index 0d415056..d5643630 100644 --- a/include/parse.h +++ b/include/parse.h @@ -99,38 +99,23 @@ ANN bool check_stmt_list(const Env env, const Stmt_List); typedef m_bool (*_exp_func)(const void *, const void *); -ANN m_bool scanx_body(const Env env, const Class_Def cdef, const _exp_func f, - void *data); + +ANN bool scanx_body(const Env e, const Class_Def c, const _envset_func f, + void *d); + static inline ANN m_bool env_body(const Env env, const Class_Def cdef, - const _exp_func f) { + const _envset_func f) { return scanx_body(env, cdef, f, env); } -#define env_body(a, b, c) env_body(a, b, (_exp_func)c) - -typedef bool (*_exp_func_b)(const void *, const void *); -ANN bool scanx_body_b(const Env env, const Class_Def cdef, const _exp_func_b f, - void *data); -static inline ANN bool env_body_b(const Env env, const Class_Def cdef, - const _exp_func_b f) { - return scanx_body_b(env, cdef, f, env); -} -#define env_body_b(a, b, c) env_body_b(a, b, (_exp_func_b)c) - -ANN m_bool scanx_cdef(const Env, void *, const Type, const _exp_func f_cdef, - const _exp_func f_union); - -#define xxx_section_b(prefix) \ -static inline m_bool prefix##_section_b(const Env env, Section *section) { \ - return prefix##_section(env, section) ? GW_OK : GW_ERROR;} - -#define xxx_cdef_b(prefix) \ -static inline m_bool prefix##_class_def_b(const Env env, const Class_Def cdef) { \ - return prefix##_class_def(env, cdef) ? GW_OK : GW_ERROR;} \ -static inline m_bool prefix##_union_def_b(const Env env, const Union_Def udef) { \ - return prefix##_union_def(env, udef) ? GW_OK : GW_ERROR;} \ - static inline m_bool prefix##_cdef(const Env env, const Type t) { \ - return scanx_cdef(env, env, t, (_exp_func)prefix##_class_def_b, \ - (_exp_func)prefix##_union_def_b); \ +#define env_body(a, b, c) env_body(a, b, (_envset_func)c) + +ANN bool scanx_cdef(const Env, void *, const Type, const _envset_func f_cdef, + const _envset_func f_union); + +#define xxx_cdef_b(prefix) \ + static inline bool prefix##_cdef(const Env env, const Type t) { \ + return scanx_cdef(env, env, t, (_envset_func)prefix##_class_def, \ + (_envset_func)prefix##_union_def); \ } xxx_cdef_b(scan0); @@ -139,16 +124,8 @@ xxx_cdef_b(scan2); xxx_cdef_b(check); xxx_cdef_b(traverse); -#define xxx_cdef(prefix) \ - static inline m_bool prefix##_cdef(const Env env, const Type t) { \ - return scanx_cdef(env, env, t, (_exp_func)prefix##_class_def, \ - (_exp_func)prefix##_union_def); \ - } - -ANN m_bool -scanx_fdef(const Env, void *, const Func_Def, const _exp_func); ANN bool -scanx_fdef_b(const Env, void *, const Func_Def, const _exp_func_b); +scanx_fdef(const Env, void *, const Func_Def, const _envset_func); ANN bool check_subscripts(const Env, const Array_Sub, const bool is_decl); ANN bool check_implicit(const Env env, Exp* e, const Type t); diff --git a/src/emit/emit.c b/src/emit/emit.c index 4c2d0222..131bc658 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -118,7 +118,7 @@ static const f_instr allocword[4] = {AllocWord, AllocWord2, AllocWord3, RegPushMem4}; ANN static m_bool emit_class_def(const Emitter, const Class_Def); -ANN /*static */ m_bool emit_cdef(const Emitter, const Type); +ANN static bool emit_cdef(const Emitter, const Type); ANN /*static inline*/ m_bool ensure_emit(const Emitter emit, const Type t) { if (tflag(t, tflag_emit) || !(tflag(t, tflag_cdef) || tflag(t, tflag_udef))) @@ -126,10 +126,10 @@ ANN /*static inline*/ m_bool ensure_emit(const Emitter emit, const Type t) { if(!tflag(t, tflag_tmpl))return GW_OK; struct EnvSet es = {.env = emit->env, .data = emit, - .func = (_exp_func)emit_cdef, + .func = (_envset_func)emit_cdef, .scope = emit->env->scope->depth, .flag = tflag_emit}; - return envset_run(&es, t); + return envset_run(&es, t) ? GW_OK : GW_ERROR; } ANN void emit_object_release(const Emitter emit, const m_uint offset) { @@ -1430,10 +1430,10 @@ ANN m_bool traverse_dot_tmpl(const Emitter emit, const Func_Def fdef, const Valu emit->env->scope->shadowing = true; struct EnvSet es = {.env = emit->env, .data = emit, - .func = (_exp_func)emit_cdef, + .func = (_envset_func)emit_cdef, .scope = scope, .flag = tflag_emit}; - CHECK_BB(envset_pushv(&es, v)); + CHECK_b(envset_pushv(&es, v)); (void)emit_push(emit, v->from->owner_class, v->from->owner); const bool ret = traverse_emit_func_def(emit, fdef); emit_pop(emit, scope); @@ -1476,10 +1476,10 @@ 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, + .func = (_envset_func)emit_cdef, .scope = scope, .flag = tflag_emit}; - CHECK_BB(envset_pushv(&es, v)); + CHECK_b(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); envset_pop(&es, v->from->owner_class); @@ -1928,10 +1928,10 @@ ANN static m_bool emit_exp_lambda(const Emitter emit, } struct EnvSet es = {.env = emit->env, .data = emit, - .func = (_exp_func)emit_cdef, + .func = (_envset_func)emit_cdef, .scope = emit->env->scope->depth, .flag = tflag_emit}; - CHECK_BB(envset_pushv(&es, lambda->def->base->func->value_ref)); + CHECK_b(envset_pushv(&es, lambda->def->base->func->value_ref)); const m_bool ret = emit_lambda(emit, lambda); envset_pop(&es, lambda->owner); return ret; @@ -2808,6 +2808,10 @@ ANN static void emit_lambda_capture(const Emitter emit, const Func_Def fdef) { emit_regtomem4(emit, fdef->stack_depth, offset); } +ANN static bool emit_fdef_b(const Emitter emit, const Func_Def fdef) { + return emit_fdef(emit, fdef) > 0; +} + ANN static 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; @@ -2857,15 +2861,15 @@ ANN static m_bool _emit_func_def(const Emitter emit, const Func_Def f) { emit_local(emit, emit->gwion->type[et_int]); emit_memsetimm(emit, SZ_INT, 0); } else if(fdef->captures) emit_lambda_capture(emit, fdef); - const m_bool ret = scanx_fdef(emit->env, emit, fdef, (_exp_func)emit_fdef); + const bool ret = scanx_fdef(emit->env, emit, fdef, (_envset_func)emit_fdef_b); emit_pop_scope(emit); emit->env->func = former; - if (ret > 0) + if (ret) emit_fdef_finish(emit, fdef); else emit_pop_code(emit); if (global) env_pop(emit->env, scope); - return ret; + return ret ? GW_OK : GW_ERROR; } ANN m_bool emit_func_def(const Emitter emit, const Func_Def fdef) { @@ -2907,9 +2911,15 @@ ANN static m_bool emit_parent(const Emitter emit, const Class_Def cdef) { return ensure_emit(emit, parent); } -ANN /*static */ inline m_bool emit_cdef(const Emitter emit, const Type t) { - return scanx_cdef(emit->env, emit, t, (_exp_func)emit_class_def, - (_exp_func)emit_union_def); +ANN static bool emit_class_def_b(const Emitter emit, Class_Def cdef) { + return emit_class_def(emit, cdef) > 0; +} +ANN static bool emit_union_def_b(const Emitter emit, Union_Def udef) { + return emit_union_def(emit, udef) > 0; +} +ANN static inline bool emit_cdef(const Emitter emit, const Type t) { + return scanx_cdef(emit->env, emit, t, (_envset_func)emit_class_def_b, + (_envset_func)emit_union_def_b); } ANN static m_bool cdef_parent(const Emitter emit, const Class_Def cdef) { @@ -2945,6 +2955,10 @@ ANN static m_bool emit_class_tmpl(const Emitter emit, const Tmpl *tmpl, const Ns return GW_OK; } +ANN static bool emit_section_b(const Emitter emit, Section *b) { + return emit_section(emit, b) > 0; +} + ANN static m_bool _emit_class_def(const Emitter emit, const Class_Def cdef) { const Type t = cdef->base.type; set_tflag(t, tflag_emit); @@ -2954,7 +2968,7 @@ ANN static m_bool _emit_class_def(const Emitter emit, const Class_Def cdef) { CHECK_BB(cdef_parent(emit, c)); if (c->base.tmpl) CHECK_BB(emit_class_tmpl(emit, c->base.tmpl, c->base.type->nspc)); if (c->body) - return scanx_body(emit->env, c, (_exp_func)emit_section, emit); + return scanx_body(emit->env, c, (_envset_func)emit_section_b, emit); return GW_OK; } diff --git a/src/env/envset.c b/src/env/envset.c index 65922c2b..a113b7f8 100644 --- a/src/env/envset.c +++ b/src/env/envset.c @@ -19,11 +19,11 @@ ANN static void check(struct EnvSet *es, const Type t) { } } -ANN static m_bool push(struct EnvSet *es, const Type t) { +ANN static bool push(struct EnvSet *es, const Type t) { es->env->scope->depth = 0; const Type owner_class = t->info->value->from->owner_class; if (owner_class) - CHECK_BB(push(es, owner_class)); + CHECK_B(push(es, owner_class)); else env_push(es->env, NULL, t->info->value->from->ctx ? t->info->value->from->ctx->nspc @@ -33,22 +33,22 @@ ANN static m_bool push(struct EnvSet *es, const Type t) { const Tmpl *tmpl = get_tmpl(t); CHECK_b(template_push_types(es->env, tmpl)); } - return GW_OK; + return true; } ANN2(1, 3) -m_bool envset_push(struct EnvSet *es, const Type t, const Nspc nspc) { +bool envset_push(struct EnvSet *es, const Type t, const Nspc nspc) { if (t) { check(es, t); // if(es->run && type_global(es->env, t)) // env_push_global(es->env); - return es->run ? push(es, t) : GW_OK; + return es->run ? push(es, t) : true; } if (nspc != es->env->curr) { env_push(es->env, NULL, nspc); es->run = 1; } - return GW_OK; + return true; } ANN2(1) static void _envset_pop(struct EnvSet *es, const Type t) { @@ -71,13 +71,13 @@ ANN2(1) void envset_pop(struct EnvSet *es, const Type t) { if (es->_filename) es->env->name = es->_filename; } -ANN m_bool envset_run(struct EnvSet *es, const Type t) { +ANN bool envset_run(struct EnvSet *es, const Type t) { check(es, t); const Type owner_class = t->info->value->from->owner_class; - if (es->run) CHECK_BB(push(es, owner_class)); + if (es->run) CHECK_B(push(es, owner_class)); es->env->context = t->info->value->from->ctx; es->env->name = t->info->value->from->filename; - const m_bool ret = + const bool ret = t->info->cdef && !(t->tflag & es->flag) ? es->func(es->data, t) : GW_OK; envset_pop(es, owner_class); return ret; diff --git a/src/lib/closure.c b/src/lib/closure.c index b3815599..90498dba 100644 --- a/src/lib/closure.c +++ b/src/lib/closure.c @@ -299,10 +299,10 @@ ANN static m_bool _check_lambda(const Env env, Exp_Lambda *l, Type owner = fdef->base->func->value_ref->from->owner_class; struct EnvSet es = {.env = env, .data = env, - .func = (_exp_func)traverse_cdef, + .func = (_envset_func)traverse_cdef, .scope = env->scope->depth, .flag = tflag_scan0}; - CHECK_BB(envset_pushv(&es, owner->info->value)); + CHECK_b(envset_pushv(&es, owner->info->value)); while(owner) { const Tmpl *tmpl = get_tmpl(owner); if(tmpl) @@ -684,11 +684,11 @@ static OP_CHECK(opck_closure_scan) { fdef->base->tag.sym = info.name; struct EnvSet es = {.env = env, .data = env, - .func = (_exp_func)traverse_cdef, + .func = (_envset_func)traverse_cdef, .scope = env->scope->depth, .flag = tflag_scan0}; const Type owner = ts->t; - CHECK_BO(envset_pushv(&es, owner->info->value)); + CHECK_O(envset_pushv(&es, owner->info->value)); const bool ret = traverse_fptr_def(env, fdef); const Type t = ret ? fdef->cdef->base.type : NULL; envset_pop(&es, owner->info->value->from->owner_class); diff --git a/src/lib/object_op.c b/src/lib/object_op.c index c1aacea8..220b504d 100644 --- a/src/lib/object_op.c +++ b/src/lib/object_op.c @@ -326,11 +326,11 @@ ANN Type scan_class(const Env env, const Type t, const Type_Decl *td) { if (exists) return exists != env->gwion->type[et_error] ? exists : NULL; struct EnvSet es = {.env = env, .data = env, - .func = (_exp_func)scan0_cdef, + .func = (_envset_func)scan0_cdef, .scope = env->scope->depth, .flag = tflag_check}; const Type owner = t->info->value->from->owner_class; - CHECK_BO(envset_pushv(&es, t->info->value)); + CHECK_O(envset_pushv(&es, t->info->value)); const bool local = !owner && !tmpl_global(env, td->types) && from_global_nspc(env, env->curr); if(local && env->context) env_push(env, NULL, env->context->nspc); const Type ret = _scan_class(env, &info); diff --git a/src/parse/check.c b/src/parse/check.c index 8165e586..ab9363a2 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -144,7 +144,7 @@ ANN /*static inline*/ bool ensure_check(const Env env, const Type t) { if(!tflag(t, tflag_tmpl)) return GW_OK; struct EnvSet es = {.env = env, .data = env, - .func = (_exp_func)check_cdef, + .func = (_envset_func)check_cdef, .scope = env->scope->depth, .flag = tflag_check}; return envset_run(&es, t); @@ -156,7 +156,7 @@ ANN bool ensure_traverse(const Env env, const Type t) { if(!tflag(t, tflag_tmpl)) return true; struct EnvSet es = {.env = env, .data = env, - .func = (_exp_func)traverse_cdef, + .func = (_envset_func)traverse_cdef, .scope = env->scope->depth, .flag = tflag_check}; return envset_run(&es, t); @@ -753,10 +753,10 @@ ANN static Type check_predefined(const Env env, Exp_Call *exp, const Value v, if (!fdef->base->ret_type) { // template fptr struct EnvSet es = {.env = env, .data = env, - .func = (_exp_func)check_cdef, + .func = (_envset_func)check_cdef, .scope = env->scope->depth, .flag = tflag_check}; - CHECK_BO(envset_pushv(&es, v)); + CHECK_O(envset_pushv(&es, v)); func->def->base->fbflag |= fbflag_internal; const bool ret = check_traverse_fdef(env, func->def); envset_pop(&es, v->from->owner_class); @@ -1981,7 +1981,7 @@ ANN bool _check_func_def(const Env env, const Func_Def f) { } } vector_add(&env->scope->effects, 0); - const bool ret = scanx_fdef_b(env, env, fdef, (_exp_func_b)check_fdef); + const bool ret = scanx_fdef(env, env, fdef, (_envset_func)check_fdef); vector_pop(&env->scope->effects); if (fbflag(fdef->base, fbflag_op)) operator_resume(&opi); nspc_pop_value(env->gwion->mp, env->curr); @@ -2241,7 +2241,7 @@ ANN static bool _check_class_def(const Env env, const Class_Def cdef) { if (!tflag(t, tflag_struct)) inherit(t); if(cdef->base.tmpl) CHECK_B(check_class_tmpl(env, cdef->base.tmpl, cdef->base.type->nspc)); if (cdef->body) { - CHECK_B(env_body_b(env, cdef, check_section)); + CHECK_B(env_body(env, cdef, check_section)); if (cflag(cdef, cflag_struct) || class_def_has_body(cdef->body)) // if (class_def_has_body(cdef->body)) set_tflag(t, tflag_ctor); diff --git a/src/parse/func_resolve_tmpl.c b/src/parse/func_resolve_tmpl.c index 45d1ee1b..1eb7b549 100644 --- a/src/parse/func_resolve_tmpl.c +++ b/src/parse/func_resolve_tmpl.c @@ -151,12 +151,12 @@ ANN static Func find_tmpl(const Env env, const Value v, Exp_Call *const exp, const m_uint scope = env->scope->depth; struct EnvSet es = {.env = env, .data = env, - .func = (_exp_func)check_cdef, + .func = (_envset_func)check_cdef, .scope = scope, .flag = tflag_check}; struct ResolverArgs ra = { .v = v, .e = exp, .tmpl_name = tmpl_name, .types = types}; - CHECK_BO(envset_pushv(&es, v)); + CHECK_O(envset_pushv(&es, v)); (void)env_push(env, v->from->owner_class, v->from->owner); const Tmpl *tmpl = v->from->owner_class && v->from->owner_class->info->cdef ? get_tmpl(v->from->owner_class) : NULL; diff --git a/src/parse/scan0.c b/src/parse/scan0.c index 6f844334..fb51107e 100644 --- a/src/parse/scan0.c +++ b/src/parse/scan0.c @@ -550,7 +550,7 @@ ANN static bool scan0_class_def_inner(const Env env, const Class_Def cdef) { set_tflag(cdef->base.type, tflag_scan0); (void)mk_class(env, cdef->base.type, cdef->base.tag.loc); add_type(env, cdef->base.type->info->value->from->owner, cdef->base.type); - return cdef->body ? env_body_b(env, cdef, scan0_section) : true; + return cdef->body ? env_body(env, cdef, scan0_section) : true; } ANN Ast spread_class(const Env env, const Ast body); diff --git a/src/parse/scan1.c b/src/parse/scan1.c index 42a7c9ce..862dc557 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -39,7 +39,7 @@ ANN static inline bool ensure_scan1(const Env env, const Type t) { return true; struct EnvSet es = {.env = env, .data = env, - .func = (_exp_func)scan1_cdef, + .func = (_envset_func)scan1_cdef, .scope = env->scope->depth, .flag = tflag_scan1}; return envset_run(&es, t); @@ -763,7 +763,7 @@ ANN static bool _scan1_func_def(const Env env, const Func_Def fdef) { struct Func_ fake = {.name = s_name(fdef->base->tag.sym), .def = fdef }, *const former = env->func; env->func = &fake; - const bool ret = scanx_fdef_b(env, env, fdef, (_exp_func_b)scan1_fdef); + const bool ret = scanx_fdef(env, env, fdef, (_envset_func)scan1_fdef); env->func = former; if (global) env_pop(env, scope); if ((strcmp(s_name(fdef->base->tag.sym), "@implicit") || fbflag(fdef->base, fbflag_internal)) && !fdef->builtin && fdef->base->ret_type && @@ -857,7 +857,7 @@ ANN static bool scan1_class_def_body(const Env env, const Class_Def cdef) { free_mp_vector(mp, Section, base); cdef->body = body; } - return env_body_b(env, cdef, scan1_section); + return env_body(env, cdef, scan1_section); } ANN static bool scan1_class_tmpl(const Env env, const Class_Def c) { diff --git a/src/parse/scan2.c b/src/parse/scan2.c index ce52bd4c..695c35d1 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -30,7 +30,7 @@ ANN static inline bool ensure_scan2(const Env env, const Type t) { return true; struct EnvSet es = {.env = env, .data = env, - .func = (_exp_func)scan2_cdef, + .func = (_envset_func)scan2_cdef, .scope = env->scope->depth, .flag = tflag_scan2}; return envset_run(&es, t); @@ -548,7 +548,7 @@ ANN bool _scan2_func_def(const Env env, const Func_Def fdef) { !GET_FLAG(f->base, global)) ? SZ_INT : 0; - const bool ret = scanx_fdef_b(env, env, f, (_exp_func_b)scan2_fdef); + const bool ret = scanx_fdef(env, env, f, (_envset_func)scan2_fdef); if (GET_FLAG(f->base, global)) env_pop(env, scope); CHECK_B(ret); fdef->base->func = f->base->func; // only needed if 'is_cpy()' diff --git a/src/parse/scanx.c b/src/parse/scanx.c index 8f691c8d..c3eab3cc 100644 --- a/src/parse/scanx.c +++ b/src/parse/scanx.c @@ -6,15 +6,15 @@ #include "traverse.h" #include "parse.h" -ANN static inline m_bool _body(const Env e, Ast b, const _exp_func f) { +ANN static inline bool _body(const Env e, Ast b, const _exp_func f) { for(m_uint i = 0; i < b->len; i++) { Section *section = mp_vector_at(b, Section, i); - CHECK_BB(f(e, section)); + CHECK_B(f(e, section)); } - return GW_OK; + return true; } -ANN static inline bool _body_b(const Env e, Ast b, const _exp_func_b f) { +ANN static inline bool _body_b(const Env e, Ast b, const _envset_func f) { for(m_uint i = 0; i < b->len; i++) { Section *section = mp_vector_at(b, Section, i); CHECK_B(f(e, section)); @@ -26,13 +26,8 @@ ANN static inline int actual(const Tmpl *tmpl) { return tmpl->call && tmpl->call != (TmplArg_List)1 && tmpl->list; } -ANN static inline m_bool tmpl_push(const Env env, const Tmpl *tmpl) { - return actual(tmpl) ? template_push_types(env, tmpl) > 0 ? GW_OK : GW_ERROR: GW_ERROR; -} - -ANN static inline m_int _push(const Env env, const Class_Def c) { - DECL_BB(const m_int, scope, = env_push_type(env, c->base.type)); - return (!c->base.tmpl || tmpl_push(env, c->base.tmpl)) ? scope : GW_ERROR; +ANN static inline bool tmpl_push(const Env env, const Tmpl *tmpl) { + return actual(tmpl) ? template_push_types(env, tmpl) : true; } ANN static inline void _pop(const Env e, const Class_Def c, const m_uint s) { @@ -41,50 +36,32 @@ ANN static inline void _pop(const Env e, const Class_Def c, const m_uint s) { env_pop(e, s); } -// TODO: 'v' should be 2° argument -ANN m_bool scanx_body(const Env e, const Class_Def c, const _exp_func f, +ANN bool scanx_body(const Env e, const Class_Def c, const _envset_func f, void *d) { - DECL_BB(const m_int, scope, = _push(e, c)); - const m_bool ret = _body(d, c->body, f); - _pop(e, c, scope); - return ret; -} - -ANN bool scanx_body_b(const Env e, const Class_Def c, const _exp_func_b f, - void *d) { - const m_int scope = _push(e, c); // check me + const m_int scope = env_push_type(e, c->base.type); + if(c->base.tmpl) CHECK_B(tmpl_push(e, c->base.tmpl)); const bool ret = _body_b(d, c->body, f); _pop(e, c, scope); return ret; } -ANN static m_bool _scanx_cdef(const Env env, void *opt, const Type t, - const _exp_func f_cdef, const _exp_func f_udef) { +ANN static bool _scanx_cdef(const Env env, void *opt, const Type t, + const _envset_func f_cdef, const _envset_func f_udef) { if (t->info->parent != env->gwion->type[et_union]) return f_cdef(opt, t->info->cdef); - const m_bool ret = f_udef(opt, t->info->udef); - return ret; + return f_udef(opt, t->info->udef); } -ANN m_bool scanx_cdef(const Env env, void *opt, const Type t, - const _exp_func f_cdef, const _exp_func f_udef) { +ANN bool scanx_cdef(const Env env, void *opt, const Type t, + const _envset_func f_cdef, const _envset_func f_udef) { const bool in_try = env->scope->in_try; - const m_bool ret = _scanx_cdef(env, opt, t, f_cdef, f_udef); + const bool ret = _scanx_cdef(env, opt, t, f_cdef, f_udef); env->scope->in_try = in_try; return ret; } -ANN m_bool scanx_fdef(const Env env, void *data, const Func_Def fdef, - const _exp_func func) { - if (fdef->base->tmpl) CHECK_b(template_push_types(env, fdef->base->tmpl)); - const bool in_try = env->scope->in_try; - const m_bool ret = func(data, fdef); - if (fdef->base->tmpl) nspc_pop_type(env->gwion->mp, env->curr); - env->scope->in_try = in_try; - return ret; -} -ANN bool scanx_fdef_b(const Env env, void *data, const Func_Def fdef, - const _exp_func_b func) { +ANN bool scanx_fdef(const Env env, void *data, const Func_Def fdef, + const _envset_func func) { if (fdef->base->tmpl) CHECK_B(template_push_types(env, fdef->base->tmpl)); const bool in_try = env->scope->in_try; const bool ret = func(data, fdef); diff --git a/src/parse/traverse.c b/src/parse/traverse.c index 7ba42c6e..0e602492 100644 --- a/src/parse/traverse.c +++ b/src/parse/traverse.c @@ -18,7 +18,7 @@ ANN bool traverse_exp(const Env env, Exp* exp) { return true; } -ANN static m_bool _traverse_func_def(const Env env, const Func_Def fdef) { +ANN static bool _traverse_func_def(const Env env, const Func_Def fdef) { CHECK_B(scan0_func_def(env, fdef)); CHECK_B(scan1_func_def(env, fdef)); CHECK_B(scan2_func_def(env, fdef)); -- 2.43.0