From: Jérémie Astor Date: Thu, 17 Mar 2022 11:37:25 +0000 (+0100) Subject: :art: cosmetics X-Git-Tag: nightly~371 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=e028443111f79e9e1c2048b7650e00757bb32761;p=gwion.git :art: cosmetics --- diff --git a/ast b/ast index 1d6209b5..971a79a2 160000 --- a/ast +++ b/ast @@ -1 +1 @@ -Subproject commit 1d6209b5b7f19379d36440f70f9fdd2c90429953 +Subproject commit 971a79a2f613db01129d7e52b4f738640bee00a9 diff --git a/src/clean.c b/src/clean.c index 2c4aeed8..b8058983 100644 --- a/src/clean.c +++ b/src/clean.c @@ -201,8 +201,7 @@ ANN static void clean_stmt_return(Clean *a, Stmt_Exp b) { ANN static void clean_case_list(Clean *a, Stmt_List b) { for(m_uint i = 0; i < b->len; i++) { - const m_uint offset = i * sizeof(struct Stmt_); - const Stmt stmt = (Stmt)(b->ptr + offset); + const Stmt stmt = mp_vector_at(b, struct Stmt_, i); clean_stmt_case(a, &stmt->d.stmt_match); } } @@ -257,7 +256,7 @@ ANN static void clean_stmt(Clean *a, Stmt b) { ANN static void clean_arg_list(Clean *a, Arg_List b) { for(uint32_t i = 0; i < b->len; i++) { - Arg *arg = (Arg*)(b->ptr + i * sizeof(Arg)); + Arg *arg = mp_vector_at(b, Arg, i); if (arg->td) clean_type_decl(a, arg->td); clean_var_decl(a, &arg->var_decl); } @@ -265,8 +264,7 @@ ANN static void clean_arg_list(Clean *a, Arg_List b) { ANN static void clean_stmt_list(Clean *a, Stmt_List b) { for(m_uint i = 0; i < b->len; i++) { - const m_uint offset = i * sizeof(struct Stmt_); - const Stmt stmt = (Stmt)(b->ptr + offset); + const Stmt stmt = mp_vector_at(b, struct Stmt_, i); clean_stmt(a, stmt); } } @@ -356,8 +354,8 @@ ANN static inline void clean_section(Clean *a, Section *b) { ANN static void clean_ast(Clean *a, Ast b) { for(m_uint i = 0; i < b->len; i++) { - const m_uint offset = i * sizeof(Section); - clean_section(a, (Section*)(b->ptr + offset)); + Section *section = mp_vector_at(b, Section, i); + clean_section(a, section); } } diff --git a/src/emit/emit.c b/src/emit/emit.c index 635a4b78..5167adc5 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -1661,7 +1661,7 @@ static m_bool me_cmp(MemoizeEmitter *me, const Arg *arg) { ANN static m_bool me_arg(MemoizeEmitter *me) { Arg_List args = me->fdef->base->args; for(uint32_t i = 0; i < args->len; i++) { - Arg *arg = (Arg*)(args->ptr + i * sizeof(Arg)); + Arg *arg = mp_vector_at(args, Arg, i); const m_uint sz = arg->type->size; (void)me_push(me, sz); const Instr instr = me_push(me, sz); @@ -2139,7 +2139,7 @@ ANN2(1) /*static */ m_bool emit_exp(const Emitter emit, /* const */ Exp e) { (e->cast_to ? isa(e->cast_to, emit->gwion->type[et_object]) > 0 : 1) && e->exp_type == ae_exp_decl && GET_FLAG(e->d.exp_decl.td, late) && exp_getuse(e) && !exp_getvar(e) && - GET_FLAG((mp_vector_at(e->d.exp_decl.list, struct Var_Decl_, 0))->value, late)) { + GET_FLAG(mp_vector_at(e->d.exp_decl.list, struct Var_Decl_, 0)->value, late)) { // GET_FLAG(e->d.exp_decl.list->self->value, late)) { // e->exp_type == ae_exp_decl && !exp_getvar(e)) { // const Instr instr = emit_add_instr(emit, GWOP_EXCEPT); @@ -2781,8 +2781,7 @@ ANN static inline void match_unvec(struct Match_ *const match, ANN static m_bool emit_stmt_cases(const Emitter emit, Stmt_List list) { for(m_uint i = 0; i < list->len; i++) { - const m_uint offset = i * sizeof(struct Stmt_); - const Stmt stmt = (Stmt)(list->ptr + offset); + const Stmt stmt = mp_vector_at(list, struct Stmt_, i); CHECK_BB(emit_stmt_match_case(emit, &stmt->d.stmt_match)); } return GW_OK; @@ -2845,8 +2844,7 @@ ANN static m_bool emit_stmt(const Emitter emit, const Stmt stmt, ANN static m_bool emit_stmt_list(const Emitter emit, Stmt_List l) { for(m_uint i = 0; i < l->len; i++) { - const m_uint offset = i * sizeof(struct Stmt_); - const Stmt stmt = (Stmt)(l->ptr + offset); + const Stmt stmt = mp_vector_at(l, struct Stmt_, i); CHECK_BB(emit_stmt(emit, stmt, 1)); } return GW_OK; @@ -2867,7 +2865,7 @@ ANN static inline void emit_func_def_init(const Emitter emit, const Func func) { ANN static void emit_func_def_args(const Emitter emit, Arg_List args) { for(uint32_t i = 0; i < args->len; i++) { - Arg *arg = (Arg*)(args->ptr + i * sizeof(Arg)); + Arg *arg = mp_vector_at(args, Arg, i); const Type type = arg->var_decl.value->type; emit->code->stack_depth += type->size; arg->var_decl.value->from->offset = emit_localn(emit, type); @@ -3063,8 +3061,8 @@ HANDLE_SECTION_FUNC(emit, m_bool, Emitter) ANN static inline m_bool emit_ast_inner(const Emitter emit, Ast ast) { for(m_uint i = 0; i < ast->len; i++) { - const m_uint offset = i * sizeof(struct Section_); - CHECK_BB(emit_section(emit, (Section*)(ast->ptr + offset))); + Section * section = mp_vector_at(ast, Section, i); + CHECK_BB(emit_section(emit, section)); } return emit_defers(emit); } diff --git a/src/import/import_internals.c b/src/import/import_internals.c index 795884e1..af161b4c 100644 --- a/src/import/import_internals.c +++ b/src/import/import_internals.c @@ -13,8 +13,8 @@ void gwi_body(const Gwi gwi, const Section *section) { const Class_Def cdef = gwi->gwion->env->class_def->info->cdef; if (!cdef->body) { - mp_vector_first(gwi->gwion->mp, a, Section, *section); - cdef->body = a; + cdef->body = new_mp_vector(gwi->gwion->mp, sizeof(Section), 1); + mp_vector_set(cdef->body, Section, 0, *section); } else { mp_vector_add(gwi->gwion->mp, &cdef->body, Section, (*section)); } diff --git a/src/import/import_item.c b/src/import/import_item.c index 886b4e97..93fbdc67 100644 --- a/src/import/import_item.c +++ b/src/import/import_item.c @@ -18,8 +18,8 @@ ANN m_int gwi_item_ini(const Gwi gwi, const restrict m_str type, } ANN static m_int gwi_item_tmpl(const Gwi gwi) { - mp_vector_first(gwi->gwion->mp, slist, struct Stmt_, - ((struct Stmt_) { + Stmt_List slist = new_mp_vector(gwi->gwion->mp, sizeof(struct Stmt_), 1); + mp_vector_set(slist, struct Stmt_, 0, ((struct Stmt_) { .stmt_type = ae_stmt_exp, .d = { .stmt_exp = { .val = gwi->ck->exp } }, .pos = gwi->loc @@ -52,7 +52,7 @@ m_int gwi_item_end(const Gwi gwi, const ae_flag flag, union value_data addr) { if (env->class_def && tflag(env->class_def, tflag_tmpl)) return gwi_item_tmpl(gwi); CHECK_BB(traverse_exp(env, gwi->ck->exp)); - const Value value = (mp_vector_at(gwi->ck->exp->d.exp_decl.list, struct Var_Decl_, 0))->value; + const Value value = mp_vector_at(gwi->ck->exp->d.exp_decl.list, struct Var_Decl_, 0)->value; value->d = addr; set_vflag(value, vflag_builtin); if (!env->class_def) SET_FLAG(value, global); diff --git a/src/lib/lib_func.c b/src/lib/lib_func.c index 2ff080fc..b8c33a10 100644 --- a/src/lib/lib_func.c +++ b/src/lib/lib_func.c @@ -289,8 +289,8 @@ ANN static m_bool _check_lambda(const Env env, Exp_Lambda *l, def->base->func->value_ref->from->owner_class->info->cdef->base.tmpl); if(bases) { for(uint32_t i = 0; i < bases->len; i++) { - Arg *base = (Arg*)(bases->ptr + i * sizeof(Arg)); - Arg *arg = (Arg*)(args->ptr + i * sizeof(Arg)); + Arg *base = mp_vector_at(bases, Arg, i); + Arg *arg = mp_vector_at(args, Arg, i); arg->td = type2td(env->gwion, known_type(env, base->td), exp_self(l)->pos); } @@ -324,7 +324,7 @@ ANN static m_bool _check_lambda(const Env env, Exp_Lambda *l, if(ret < 0) { if(args) { for(uint32_t i = 0; i < bases->len; i++) { - Arg *arg = (Arg*)(args->ptr + i * sizeof(Arg)); + Arg *arg = mp_vector_at(args, Arg, i); free_value(arg->var_decl.value, env->gwion); arg->var_decl.value = NULL; } @@ -534,7 +534,7 @@ static inline void op_impl_ensure_types(const Env env, const Func func) { Arg_List args = func->def->base->args; for(uint32_t i = 0; i < args->len; i++) { - Arg *arg = (Arg*)(args->ptr + i * sizeof(Arg)); + Arg *arg = mp_vector_at(args, Arg, i); if (!arg->type) arg->type = known_type(env, arg->td); } /* @@ -628,7 +628,8 @@ static OP_CHECK(opck_op_impl) { new_prim_id(env->gwion->mp, larg1->var_decl.xid, impl->e->pos); const Exp bin = new_exp_binary(env->gwion->mp, lhs, impl->e->d.prim.d.var, rhs, impl->e->pos); - mp_vector_first(env->gwion->mp, slist, struct Stmt_, + Stmt_List slist = new_mp_vector(env->gwion->mp, sizeof(struct Stmt_), 1); + mp_vector_set(slist, struct Stmt_, 0, ((struct Stmt_) { .stmt_type = ae_stmt_return, .d = { .stmt_exp = { .val = bin }}, .pos = impl->e->pos @@ -659,7 +660,8 @@ static OP_EMIT(opem_op_impl) { ANN Type check_exp_unary_spork(const Env env, const Stmt code); ANN static void fork_exp(const Env env, const Exp_Unary *unary) { - mp_vector_first(env->gwion->mp, slist, struct Stmt_, + Stmt_List slist = new_mp_vector(env->gwion->mp, sizeof(struct Stmt_), 1); + mp_vector_set(slist, struct Stmt_, 0, ((struct Stmt_) { .stmt_type = ae_stmt_exp, .d = { .stmt_exp = { .val = unary->exp, } }, .pos = unary->exp->pos diff --git a/src/lib/object_op.c b/src/lib/object_op.c index c882f56d..e511e46d 100644 --- a/src/lib/object_op.c +++ b/src/lib/object_op.c @@ -340,7 +340,7 @@ ANN bool tmpl_global(const Env env, Type_List tl) { ANN Type scan_class(const Env env, const Type t, const Type_Decl *td) { struct tmpl_info info = { .base = t, .td = td, .list = t->info->cdef->base.tmpl->list}; - const Type exists = tmpl_exists(env, &info); + const Type exists = t->info->cdef->base.tmpl->call ? t : tmpl_exists(env, &info); if (exists) return exists != env->gwion->type[et_error] ? exists : NULL; struct EnvSet es = {.env = env, .data = env, diff --git a/src/parse/check.c b/src/parse/check.c index 8fe93b99..4b16d1e6 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -179,7 +179,7 @@ ANN Type check_exp_decl(const Env env, const Exp_Decl *decl) { const m_bool ret = check_decl(env, decl); if (global) env_pop(env, scope); env_weight(env, 1 + isa(decl->type, env->gwion->type[et_object]) > 0); - return ret > 0 ? (mp_vector_at(decl->list, struct Var_Decl_, 0))->value->type : NULL; + return ret > 0 ? mp_vector_at(decl->list, struct Var_Decl_, 0)->value->type : NULL; } ANN static m_bool check_collection(const Env env, Type type, const Exp e, @@ -878,7 +878,7 @@ ANN static Type check_exp_binary(const Env env, const Exp_Binary *bin) { if (is_auto) { assert(bin->rhs->type == bin->lhs->type); // bin->rhs->type = bin->lhs->type; - set_vflag((mp_vector_at(bin->rhs->d.exp_decl.list, struct Var_Decl_, 0))->value, vflag_assigned); + set_vflag(mp_vector_at(bin->rhs->d.exp_decl.list, struct Var_Decl_, 0)->value, vflag_assigned); } struct Op_Import opi = {.op = bin->op, .lhs = bin->lhs->type, @@ -889,7 +889,7 @@ ANN static Type check_exp_binary(const Env env, const Exp_Binary *bin) { exp_setuse(bin->rhs, 1); const Type ret = op_check(env, &opi); if (!ret && is_auto && exp_self(bin)->exp_type == ae_exp_binary) - (mp_vector_at(bin->rhs->d.exp_decl.list, struct Var_Decl_, 0))->value->type = env->gwion->type[et_auto]; + mp_vector_at(bin->rhs->d.exp_decl.list, struct Var_Decl_, 0)->value->type = env->gwion->type[et_auto]; return ret; } @@ -1047,9 +1047,8 @@ ANN m_bool check_type_def(const Env env, const Type_Def tdef) { set_tflag(tdef->type, tflag_contract); struct Var_Decl_ decl = { .xid = insert_symbol("self"), .pos = tdef->when->pos }; Type_Decl *td = cpy_type_decl(env->gwion->mp, tdef->ext); - mp_vector_first(env->gwion->mp, args, Arg, ((Arg) { .td = td, .var_decl = decl })); -// const Arg_List args = new_arg_list( -// env->gwion->mp, cpy_type_decl(env->gwion->mp, tdef->ext), decl, NULL); + Arg_List args = new_mp_vector(env->gwion->mp, sizeof(Arg), 1); + mp_vector_set(args, Arg, 0, ((Arg) { .td = td, .var_decl = decl })); Func_Base *fb = new_func_base( env->gwion->mp, type2td(env->gwion, tdef->type, tdef->pos), insert_symbol("@implicit"), args, ae_flag_none, tdef->pos); @@ -1058,16 +1057,12 @@ ANN m_bool check_type_def(const Env env, const Type_Def tdef) { tdef->when->pos); const Exp when = cpy_exp(env->gwion->mp, tdef->when); when->next = helper; -// const Stmt stmt = -// new_stmt_exp(env->gwion->mp, ae_stmt_exp, when, when->pos); -// const Stmt_List body = -// new_stmt_list(env->gwion->mp, stmt, NULL); // ret_list); -// Stmt_List body; - mp_vector_first(env->gwion->mp, body, struct Stmt_, - ((struct Stmt_) { - .stmt_type = ae_stmt_exp, .d = { .stmt_exp = { .val = when }}, - .pos = when->pos - })); + Stmt_List body = new_mp_vector(env->gwion->mp, sizeof(struct Stmt_), 1); + mp_vector_set(body, struct Stmt_, 0, + ((struct Stmt_) { + .stmt_type = ae_stmt_exp, .d = { .stmt_exp = { .val = when }}, + .pos = when->pos + })); const Stmt code = new_stmt_code(env->gwion->mp, body, when->pos); const Func_Def fdef = new_func_def(env->gwion->mp, fb, code); if(traverse_func_def(env, fdef) < 0) { @@ -1408,8 +1403,7 @@ ANN static m_bool check_stmt_case(const Env env, const Stmt_Match stmt) { ANN static m_bool case_loop(const Env env, const Stmt_Match stmt) { for(m_uint i = 0; i < stmt->list->len; i++) { - const m_uint offset = i * sizeof(struct Stmt_); - const Stmt s = (Stmt)(stmt->list->ptr + offset); + const Stmt s = mp_vector_at(stmt->list, struct Stmt_, i); CHECK_BB(check_stmt_case(env, &s->d.stmt_match)); } return GW_OK; @@ -1508,8 +1502,7 @@ ANN m_bool check_stmt(const Env env, const Stmt stmt) { ANN static m_bool check_stmt_list(const Env env, Stmt_List l) { for(m_uint i = 0; i < l->len; i++) { - const m_uint offset = i * sizeof(struct Stmt_); - const Stmt s = (Stmt)(l->ptr + offset); + const Stmt s = mp_vector_at(l, struct Stmt_, i); CHECK_BB(check_stmt(env, s)); } return GW_OK; @@ -1738,16 +1731,11 @@ ANN static m_bool _check_trait_def(const Env env, const Trait_Def pdef) { // while (ast) { // Section *section = ast->section; for(m_uint i = 0; i < ast->len; i++) { - const m_uint offset = i * sizeof(Section); - Section * section = (Section*)(ast->ptr + offset); + Section * section = mp_vector_at(ast, Section, i); if (section->section_type == ae_section_stmt) { Stmt_List l = section->d.stmt_list; for(m_uint i = 0; i < l->len; i++) { - const m_uint offset = i * sizeof(struct Stmt_); - const Stmt stmt = (Stmt)(l->ptr + offset); -// Stmt_List list = section->d.stmt_list; -// while (list) { -// const Stmt stmt = list->stmt; + const Stmt stmt = mp_vector_at(l, struct Stmt_, i); if (stmt->stmt_type == ae_stmt_exp) { CHECK_BB(traverse_exp(env, stmt->d.stmt_exp.val)); Var_Decl_List list = stmt->d.stmt_exp.val->d.exp_decl.list; @@ -1841,14 +1829,11 @@ ANN static m_bool check_body(const Env env, Section *const section) { ANN static bool class_def_has_body(const Env env, Ast ast) { // do { for(m_uint i = 0; i < ast->len; i++) { - const m_uint offset = i * sizeof(Section); -// const Section *section = ast->section; - const Section *section = (Section*)(ast->ptr + offset); + const Section *section = mp_vector_at(ast, Section, i); if (section->section_type == ae_section_stmt) { Stmt_List l = section->d.stmt_list; for(m_uint i = 0; i < l->len; i++) { - const m_uint offset = i * sizeof(struct Stmt_); - const Stmt stmt = (Stmt)(l->ptr + offset); + const Stmt stmt = mp_vector_at(l, struct Stmt_, i); if (stmt->stmt_type == ae_stmt_pp) continue; if (stmt->stmt_type == ae_stmt_exp) { const Exp exp = stmt->d.stmt_exp.val; @@ -2012,8 +1997,7 @@ ANN static inline void check_unhandled(const Env env) { ANN m_bool check_ast(const Env env, Ast *ast) { Ast a = *ast; for(m_uint i = 0; i < a->len; i++) { - const m_uint offset = i * sizeof(Section); - Section * section = (Section*)(a->ptr + offset); + Section * section = mp_vector_at(a, Section, i); CHECK_BB(check_section(env, section)); } check_unhandled(env); diff --git a/src/parse/scan0.c b/src/parse/scan0.c index c2d07e5f..b5e41bd3 100644 --- a/src/parse/scan0.c +++ b/src/parse/scan0.c @@ -284,10 +284,6 @@ ANN m_bool scan0_union_def(const Env env, const Union_Def udef) { if (GET_FLAG(udef, global)) context_global(env); CHECK_BB(scan0_defined(env, udef->xid, udef->pos)); udef->type = union_type(env, udef->xid, udef->pos); - Union_List l = udef->l; -// do udef->type->nspc->offset += SZ_INT; -// while ((l = l->next)); - udef->type->nspc->offset += SZ_INT; SET_ACCESS(udef, udef->type); if (udef->tmpl) union_tmpl(env, udef); if (global) env_pop(env, 0); @@ -369,8 +365,7 @@ ANN static Type scan0_class_def_init(const Env env, const Class_Def cdef) { ANN static m_bool scan0_stmt_list(const Env env, Stmt_List l) { for(m_uint i = 0; i < l->len; i++) { - const m_uint offset = i * sizeof(struct Stmt_); - const Stmt stmt = (Stmt)(l->ptr + offset); + const Stmt stmt = mp_vector_at(l, struct Stmt_, i); if (stmt->stmt_type == ae_stmt_pp) { if (stmt->d.stmt_pp.pp_type == ae_pp_include) env->name = stmt->d.stmt_pp.data; @@ -418,7 +413,8 @@ ANN2(1) static void scan0_func_def_default(const MemPool p, const Section *s, const Exp efunc = new_prim_id(p, base->xid, base->pos); const Exp exp_arg = mk_default_args(p, args, len); const Exp ecall = new_exp_call(p, efunc, exp_arg, base->pos); - mp_vector_first(p, slist, struct Stmt_, + Stmt_List slist = new_mp_vector(p, sizeof(struct Stmt_), 1); + mp_vector_set(slist, struct Stmt_, 0, ((struct Stmt_) { .stmt_type = ae_stmt_return, .d = { .stmt_exp = { .val = ecall }}, .pos = base_fdef->base->pos @@ -441,8 +437,7 @@ ANN static m_bool scan0_extend_def(const Env env, const Extend_Def xdef) { ERR_B(xdef->td->pos, _("can't extend final type")) Ast ast = xdef->body; for(m_uint i = 0; i < ast->len; i++) { - const m_uint offset = i * sizeof(Section); - Section * section = (Section*)(ast->ptr + offset); + Section * section = mp_vector_at(ast, Section, i); if (section->section_type == ae_section_func && GET_FLAG(section->d.func_def->base, abstract)) ERR_B(section->d.func_def->base->pos, @@ -461,8 +456,7 @@ ANN static m_bool _scan0_trait_def(const Env env, const Trait_Def pdef) { Ast ast = pdef->body; if(!ast) return GW_OK; // ??? for(m_uint i = 0; i < ast->len; i++) { - const m_uint offset = i * sizeof(Section); - Section *section = (Section*)(ast->ptr + offset); + Section *section = mp_vector_at(ast, Section, i); if (section->section_type == ae_section_func) { const Func_Def fdef = section->d.func_def; if (!trait->requested_funcs.ptr) vector_init(&trait->requested_funcs); @@ -529,8 +523,7 @@ ANN m_bool scan0_ast(const Env env, Ast *ast) { Ast a = *ast; Ast acc = new_mp_vector(env->gwion->mp, sizeof(Section), 0); for(m_uint i = 0; i < a->len; i++) { - const m_uint offset = i * sizeof(Section); - Section * section = (Section*)(a->ptr + offset); + Section * section = mp_vector_at(a, Section, i); CHECK_BB(scan0_section(env, section)); if (section->section_type != ae_section_func || @@ -541,7 +534,7 @@ ANN m_bool scan0_ast(const Env env, Ast *ast) { } for(m_uint i = 0; i < acc->len; i++) { - Section *section = (Section*)(acc->ptr + i * sizeof(Section)); + Section * section = mp_vector_at(acc, Section, i); mp_vector_add(env->gwion->mp, ast, Section, *section); } free_mp_vector(env->gwion->mp, sizeof(Section), acc); diff --git a/src/parse/scan1.c b/src/parse/scan1.c index c9609aa0..cc2d969c 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -149,7 +149,7 @@ ANN static m_bool scan1_decl(const Env env, const Exp_Decl *decl) { set_vflag(v, vflag_inner); // file global } } - ((Exp_Decl *)decl)->type = (mp_vector_at(decl->list, struct Var_Decl_, 0))->value->type; + ((Exp_Decl *)decl)->type = mp_vector_at(decl->list, struct Var_Decl_, 0)->value->type; return GW_OK; } @@ -298,8 +298,7 @@ ANN static inline m_bool if (stmt->where) CHECK_BB(scan1_stmt(env, stmt->where)); Stmt_List l = stmt->list; for(m_uint i = 0; i < l->len; i++) { - const m_uint offset = i * sizeof(struct Stmt_); - const Stmt s = (Stmt)(l->ptr + offset); + const Stmt s = mp_vector_at(l, struct Stmt_, i); CHECK_BB(scan1_stmt_match_case(env, &s->d.stmt_match)); } return GW_OK; @@ -584,8 +583,7 @@ ANN static inline m_bool scan1_stmt(const Env env, const Stmt stmt) { ANN static m_bool scan1_stmt_list(const Env env, Stmt_List l) { for(m_uint i = 0; i < l->len; i++) { - const m_uint offset = i * sizeof(struct Stmt_); - const Stmt s = (Stmt)(l->ptr + offset); + const Stmt s = mp_vector_at(l, struct Stmt_, i); CHECK_BB(scan1_stmt(env, s)); } /* @@ -781,8 +779,7 @@ ANN m_bool scan1_class_def(const Env env, const Class_Def cdef) { ANN m_bool scan1_ast(const Env env, Ast *ast) { Ast a = *ast; for(m_uint i = 0; i < a->len; i++) { - const m_uint offset = i * sizeof(Section); - Section *section = (Section*)(a->ptr + offset); + Section *section = mp_vector_at(a, Section, i); CHECK_BB(scan1_section(env, section)); } return GW_OK; diff --git a/src/parse/scan2.c b/src/parse/scan2.c index 86f233d9..6a426cd8 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -197,8 +197,7 @@ ANN static inline m_bool if (stmt->where) CHECK_BB(scan2_stmt(env, stmt->where)); Stmt_List l = stmt->list; for(m_uint i = 0; i < l->len; i++) { - const m_uint offset = i * sizeof(struct Stmt_); - const Stmt s = (Stmt)(l->ptr + offset); + const Stmt s = mp_vector_at(l, struct Stmt_, i); CHECK_BB(scan2_stmt_match_case(env, &s->d.stmt_match)); } return GW_OK; @@ -291,8 +290,7 @@ ANN static m_bool scan2_stmt(const Env env, const Stmt stmt) { ANN static m_bool scan2_stmt_list(const Env env, Stmt_List l) { for(m_uint i = 0; i < l->len; i++) { - const m_uint offset = i * sizeof(struct Stmt_); - const Stmt s = (Stmt)(l->ptr + offset); + const Stmt s = mp_vector_at(l, struct Stmt_, i); CHECK_BB(scan2_stmt(env, s)); } return GW_OK; @@ -641,8 +639,7 @@ ANN m_bool scan2_class_def(const Env env, const Class_Def cdef) { ANN m_bool scan2_ast(const Env env, Ast *ast) { Ast a = *ast; for(m_uint i = 0; i < a->len; i++) { - const m_uint offset = i * sizeof(Section); - Section *section = (Section*)(a->ptr + offset); + Section *section = mp_vector_at(a, Section, i); CHECK_BB(scan2_section(env, section)); } return GW_OK; diff --git a/src/parse/scanx.c b/src/parse/scanx.c index bc65f34a..03e0d992 100644 --- a/src/parse/scanx.c +++ b/src/parse/scanx.c @@ -8,8 +8,7 @@ ANN static inline m_bool _body(const Env e, Ast b, const _exp_func f) { for(m_uint i = 0; i < b->len; i++) { - const m_uint offset = i * sizeof(Section); - Section *section = (Section*)(b->ptr + offset); + Section *section = mp_vector_at(b, Section, i); CHECK_BB(f(e, section)); } return GW_OK; diff --git a/src/parse/template.c b/src/parse/template.c index 789ec175..00392f10 100644 --- a/src/parse/template.c +++ b/src/parse/template.c @@ -133,14 +133,14 @@ ANN Type _scan_type(const Env env, const Type t, Type_Decl *td) { for(uint32_t i = 0; i < tl->len; i++) { Type_Decl *td = *mp_vector_at(tl, Type_Decl*, i); DECL_OO(const Type, t, = known_type(env, td)); - Specialized *spec = mp_vector_at(sl, Specialized, i); - if(spec->traits) { - Symbol missing = miss_traits(t, spec); - if (missing) { - ERR_O(td->pos, "does not implement requested trait '{/}%s{0}'", - s_name(missing)); + Specialized *spec = mp_vector_at(sl, Specialized, i); + if(spec->traits) { + Symbol missing = miss_traits(t, spec); + if (missing) { + ERR_O(td->pos, "does not implement requested trait '{/}%s{0}'", + s_name(missing)); + } } - } } struct Op_Import opi = {.op = insert_symbol("@scan"), .lhs = t, diff --git a/util b/util index 620ab68b..923e360e 160000 --- a/util +++ b/util @@ -1 +1 @@ -Subproject commit 620ab68b3234178145f080e370b9ff5c0cede772 +Subproject commit 923e360e10f309a23cc36c50e9e0ca44f22bd2d4