From: fennecdjay Date: Tue, 30 Jan 2024 17:07:47 +0000 (+0100) Subject: :fire: *unpointerize* Stmt X-Git-Tag: nightly~114 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=58366ba3a657c1f324a4b0bb1b055dadf6d0364b;p=gwion.git :fire: *unpointerize* Stmt --- diff --git a/ast b/ast index 3095d656..cc1bdcbd 160000 --- a/ast +++ b/ast @@ -1 +1 @@ -Subproject commit 3095d6563e507c752ad0010ac384ca487573b0fe +Subproject commit cc1bdcbd2b43cc3eb08c80de725dbdb1b94cb3ef diff --git a/fmt b/fmt index 1884860f..b9bb73a2 160000 --- a/fmt +++ b/fmt @@ -1 +1 @@ -Subproject commit 1884860fc01b25f295cd7c5e7ddc304a1a69e730 +Subproject commit b9bb73a25ec8c235c6c6ba9bb9711104f01bc573 diff --git a/include/clean.h b/include/clean.h index 5185a2c0..c92d9a94 100644 --- a/include/clean.h +++ b/include/clean.h @@ -39,7 +39,7 @@ ANN static void clean_stmt_return(Clean *a, Stmt_Exp b); ANN static void clean_case_list(Clean *a, Stmt_List b); ANN static void clean_stmt_match(Clean *a, Stmt_Match b); ANN static void clean_stmt_case(Clean *a, Stmt_Match b); -ANN static void clean_stmt(Clean *a, Stmt b); +ANN static void clean_stmt(Clean *a, Stmt* b); ANN static void clean_arg_list(Clean *a, Arg_List b); ANN static void clean_stmt_list(Clean *a, Stmt_List b); ANN static void clean_func_base(Clean *a, Func_Base *b); diff --git a/include/looper.h b/include/looper.h index d5553c86..80e19952 100644 --- a/include/looper.h +++ b/include/looper.h @@ -7,7 +7,7 @@ typedef Instr (*f_looper)(const Emitter, const Looper *); struct Looper { const Exp exp; - const Stmt stmt; + Stmt *const stmt; /*const */ m_uint offset; const m_uint n; const f_looper roll; diff --git a/include/parse.h b/include/parse.h index 14fd446b..b8651de4 100644 --- a/include/parse.h +++ b/include/parse.h @@ -55,7 +55,7 @@ ANN m_bool scan2_exp(const Env, Exp); RET_NSPC(exp) \ } -ANN m_bool check_stmt(const Env env, const Stmt stmt); +ANN m_bool check_stmt(const Env env, Stmt* stmt); ANN m_bool check_stmt_list(const Env env, const Stmt_List); typedef m_bool (*_exp_func)(const void *, const void *); diff --git a/plug b/plug index b873e18a..efdeca6a 160000 --- a/plug +++ b/plug @@ -1 +1 @@ -Subproject commit b873e18a508dcb46d9d0e3e6335cd262e3a9d6f8 +Subproject commit efdeca6a71c1cb39ad9bfdaef4c8a5e6e0d8a029 diff --git a/src/clean.c b/src/clean.c index e67b94a6..30ec780f 100644 --- a/src/clean.c +++ b/src/clean.c @@ -201,7 +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 Stmt stmt = mp_vector_at(b, struct Stmt_, i); + Stmt* stmt = mp_vector_at(b, struct Stmt_, i); clean_stmt_case(a, &stmt->d.stmt_match); } } @@ -251,7 +251,7 @@ ANN static void clean_dummy(Clean *a NUSED, void *b NUSED) {} #define clean_stmt_spread clean_dummy DECL_STMT_FUNC(clean, void, Clean *) -ANN static void clean_stmt(Clean *a, Stmt b) { +ANN static void clean_stmt(Clean *a, Stmt* b) { clean_stmt_func[b->stmt_type](a, &b->d); } @@ -264,7 +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 Stmt stmt = mp_vector_at(b, struct Stmt_, i); + Stmt* stmt = mp_vector_at(b, struct Stmt_, i); clean_stmt(a, stmt); } } diff --git a/src/emit/emit.c b/src/emit/emit.c index dd92eab6..4dc9c437 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -153,14 +153,14 @@ ANN void emit_struct_release(const Emitter emit, const Type type, instr->m_val2 = (m_uint)type; } -ANN static m_bool emit_stmt(const Emitter emit, const Stmt stmt); +ANN static m_bool emit_stmt(const Emitter emit, Stmt* stmt); ANN static m_bool emit_defers(const Emitter emit) { const Vector v = &emit->code->frame->defer; if (!vector_size(v)) return GW_OK; m_uint i; for(i = vector_size(v) + 1; --i;) { - const Stmt s = (Stmt)vector_at(v, i - 1); + Stmt* s = (Stmt*)vector_at(v, i - 1); if(s) CHECK_BB(emit_stmt(emit, s)); } VLEN(v) = i; @@ -170,7 +170,7 @@ ANN static m_bool emit_defers(const Emitter emit) { ANN static m_bool emit_defers2(const Emitter emit) { const Vector v = &emit->code->frame->defer; for (m_uint i = vector_size(v) + 1; --i;) { - const Stmt s = (Stmt)vector_at(v, i - 1); + Stmt* s = (Stmt*)vector_at(v, i - 1); if (!s) break; CHECK_BB(emit_stmt(emit, s)); } @@ -210,7 +210,6 @@ ANN static m_int frame_pop(const Emitter emit) { } ANN /*static */ m_bool emit_exp(const Emitter emit, Exp exp); -ANN static m_bool emit_stmt(const Emitter emit, const Stmt stmt); ANN static m_bool emit_stmt_list(const Emitter emit, Stmt_List list); ANN static m_bool emit_exp_dot(const Emitter emit, const Exp_Dot *member); @@ -842,7 +841,7 @@ ANN m_bool emit_ensure_func(const Emitter emit, const Func f) { ANN static m_bool emit_prim_locale(const Emitter emit, const Symbol *id) { if(emit->locale->def->d.code) { - const Stmt stmt = mp_vector_at((emit->locale->def->d.code), struct Stmt_, 0); + const Stmt* stmt = mp_vector_at((emit->locale->def->d.code), struct Stmt_, 0); const Func f = stmt->d.stmt_exp.val->d.exp_call.func->type->info->func; CHECK_OB(emit_ensure_func(emit, f)); } @@ -1178,7 +1177,7 @@ ANN static inline void scoped_end(const Emitter emit) { --emit->env->scope->depth; } -ANN static m_bool scoped_stmt(const Emitter emit, const Stmt stmt) { +ANN static m_bool scoped_stmt(const Emitter emit, Stmt* stmt) { scoped_ini(emit); const m_bool ret = emit_stmt(emit, stmt); scoped_end(emit); @@ -2173,7 +2172,7 @@ ANN static Instr each_op(const Emitter emit, const Looper *loop) { } ANN static inline m_bool roll(const Emitter emit, Looper*const loop) { -const Instr instr = loop->roll(emit, loop); + const Instr instr = loop->roll(emit, loop); // DECL_OB(const Instr, instr, = each_op(emit, loop)); // maybe check in check.c CHECK_BB(scoped_stmt(emit, loop->stmt)); instr->m_val = emit_code_size(emit) + 1; // pass after goto @@ -2556,7 +2555,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 Stmt stmt = mp_vector_at(list, struct Stmt_, i); + const Stmt* stmt = mp_vector_at(list, struct Stmt_, i); CHECK_BB(emit_stmt_match_case(emit, &stmt->d.stmt_match)); } return GW_OK; @@ -2613,7 +2612,7 @@ ANN static m_bool emit_stmt_retry(const Emitter emit, DECL_STMT_FUNC(emit, m_bool, Emitter); -ANN static m_bool emit_stmt(const Emitter emit, const Stmt stmt) { +ANN static m_bool emit_stmt(const Emitter emit, Stmt* stmt) { CHECK_BB(emit_stmt_func[stmt->stmt_type](emit, &stmt->d)); if (stmt->stmt_type == ae_stmt_exp && stmt->d.stmt_exp.val) pop_exp(emit, stmt->d.stmt_exp.val); @@ -2622,7 +2621,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 Stmt stmt = mp_vector_at(l, struct Stmt_, i); + Stmt* stmt = mp_vector_at(l, struct Stmt_, i); CHECK_BB(emit_stmt(emit, stmt)); } return GW_OK; diff --git a/src/lib/closure.c b/src/lib/closure.c index ac7b6979..becb08dc 100644 --- a/src/lib/closure.c +++ b/src/lib/closure.c @@ -16,7 +16,7 @@ #include "tmp_resolve.h" ANN static Exp uncurry(const Env env, const Exp_Binary *bin) { - const Stmt stmt = mp_vector_at(bin->rhs->type->info->func->def->d.code, struct Stmt_, 0); + const Stmt* stmt = mp_vector_at(bin->rhs->type->info->func->def->d.code, struct Stmt_, 0); const Exp ecall = stmt->d.stmt_exp.val; const Exp_Call *call = &ecall->d.exp_call; Exp args = call->args; @@ -60,7 +60,7 @@ ANN static Type mk_call(const Env env, const Exp e, const Exp func, const Exp ar static OP_CHECK(opck_func_call) { Exp_Binary *bin = (Exp_Binary *)data; if(!strncmp(bin->rhs->type->name, "partial:", 8)) { - const Stmt stmt = mp_vector_at(bin->rhs->type->info->func->def->d.code, struct Stmt_, 0); + const Stmt* stmt = mp_vector_at(bin->rhs->type->info->func->def->d.code, struct Stmt_, 0); const Exp_Call *call = &stmt->d.stmt_exp.val->d.exp_call; DECL_ON(const Exp, args, = uncurry(env, bin)); return mk_call(env, exp_self(bin), call->func, args); diff --git a/src/lib/sift.c b/src/lib/sift.c index c1e8ffce..c043d7f0 100644 --- a/src/lib/sift.c +++ b/src/lib/sift.c @@ -13,8 +13,8 @@ static OP_CHECK(opck_sift) { Exp_Binary *bin = (Exp_Binary*)data; const Exp lhs = bin->lhs; - Stmt stmt = mp_vector_at(lhs->d.exp_unary.code, struct Stmt_, 0); - Stmt fst = mp_vector_at(stmt->d.stmt_flow.body->d.stmt_code.stmt_list, struct Stmt_, 0); + Stmt* stmt = mp_vector_at(lhs->d.exp_unary.code, struct Stmt_, 0); + Stmt* fst = mp_vector_at(stmt->d.stmt_flow.body->d.stmt_code.stmt_list, struct Stmt_, 0); const Symbol chuck = insert_symbol(env->gwion->st, "=>"); Exp next = new_exp_binary(env->gwion->mp, fst->d.stmt_exp.val, chuck, bin->rhs, bin->rhs->loc); CHECK_BN(traverse_exp(env, next)); // how do we free it? @@ -55,7 +55,7 @@ static OP_CHECK(opck_ctrl) { Stmt_List slist = new_mp_vector(mp, struct Stmt_, 2); mp_vector_set(slist, struct Stmt_, 0, one); mp_vector_set(slist, struct Stmt_, 1, two); - const Stmt stmt = new_stmt_code(mp, slist, func->loc); + Stmt* stmt = new_stmt_code(mp, slist, func->loc); const Exp cond = new_prim_id(mp, insert_symbol(env->gwion->st, "true"), func->loc); check_exp(env, cond); diff --git a/src/parse/check.c b/src/parse/check.c index 8333fbed..df46e610 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -1375,17 +1375,17 @@ ANN static m_bool check_stmt_code(const Env env, const Stmt_Code stmt) { return GW_OK; } -ANN static inline m_bool _check_breaks(const Env env, const Stmt b) { +ANN static inline m_bool _check_breaks(const Env env, Stmt* b) { RET_NSPC(check_stmt(env, b))} -ANN static m_bool check_breaks(const Env env, const Stmt a, const Stmt b) { +ANN static m_bool check_breaks(const Env env, Stmt* a, Stmt* b) { vector_add(&env->scope->breaks, (vtype)a); const m_bool ret = _check_breaks(env, b); vector_pop(&env->scope->breaks); return ret; } -ANN static m_bool check_conts(const Env env, const Stmt a, const Stmt b) { +ANN static m_bool check_conts(const Env env, Stmt* a, Stmt* b) { vector_add(&env->scope->conts, (vtype)a); CHECK_BB(check_breaks(env, a, b)); vector_pop(&env->scope->conts); @@ -1519,7 +1519,7 @@ ANN static m_bool check_stmt_return(const Env env, const Stmt_Exp stmt) { } #define describe_check_stmt_stack(stack, name) \ - ANN static m_bool check_stmt_##name(const Env env, const Stmt stmt) { \ + ANN static m_bool check_stmt_##name(const Env env, const Stmt* stmt) { \ if (!vector_size(&env->scope->stack)) \ ERR_B(stmt->loc, _("'" #name "' found outside of for/while/until...")) \ return GW_OK; \ @@ -1630,7 +1630,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 Stmt s = mp_vector_at(stmt->list, struct Stmt_, i); + Stmt* s = mp_vector_at(stmt->list, struct Stmt_, i); CHECK_BB(check_stmt_case(env, &s->d.stmt_match)); } return GW_OK; @@ -1730,13 +1730,13 @@ ANN static m_bool check_stmt_defer(const Env env, const Stmt_Defer stmt) { #define check_stmt_spread dummy_func DECL_STMT_FUNC(check, m_bool, Env) -ANN m_bool check_stmt(const Env env, const Stmt stmt) { +ANN m_bool check_stmt(const Env env, Stmt* stmt) { return check_stmt_func[stmt->stmt_type](env, &stmt->d); } ANN m_bool check_stmt_list(const Env env, Stmt_List l) { for(m_uint i = 0; i < l->len; i++) { - const Stmt s = mp_vector_at(l, struct Stmt_, i); + Stmt* s = mp_vector_at(l, struct Stmt_, i); CHECK_BB(check_stmt(env, s)); } return GW_OK; @@ -2056,7 +2056,7 @@ ANN static m_bool _check_trait_def(const Env env, const Trait_Def pdef) { if (section->section_type == ae_section_stmt) { Stmt_List l = section->d.stmt_list; for(m_uint i = 0; i < l->len; i++) { - const Stmt stmt = mp_vector_at(l, struct Stmt_, i); + 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 vd = stmt->d.stmt_exp.val->d.exp_decl.var.vd; @@ -2133,7 +2133,7 @@ ANN static bool class_def_has_body(Ast ast) { if(strcmp(s_name(f->base->tag.sym), "@ctor"))return false; Stmt_List l = f->d.code; for(m_uint i = 0; i < l->len; i++) { - const Stmt stmt = mp_vector_at(l, struct Stmt_, i); + 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; diff --git a/src/parse/scan0.c b/src/parse/scan0.c index a0f1e20b..44d6a2bf 100644 --- a/src/parse/scan0.c +++ b/src/parse/scan0.c @@ -403,7 +403,7 @@ ANN static bool spreadable(const Env env) { ANN static m_bool scan0_stmt_list(const Env env, Stmt_List l) { for(m_uint i = 0; i < l->len; i++) { - const Stmt stmt = mp_vector_at(l, struct Stmt_, i); + 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; @@ -479,7 +479,7 @@ ANN static m_bool _scan0_trait_def(const Env env, const Trait_Def pdef) { } else if (section->section_type == ae_section_stmt) { Stmt_List list = section->d.stmt_list; for(uint32_t i = 0; i < list->len; i++) { - Stmt stmt = mp_vector_at(list, struct Stmt_, i); + Stmt* stmt = mp_vector_at(list, struct Stmt_, i); if(stmt->d.stmt_exp.val->exp_type != ae_exp_decl) ERR_B(stmt->loc, "trait can only contains variable requests and functions"); } diff --git a/src/parse/scan1.c b/src/parse/scan1.c index f49df21e..2cb0a1c9 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -11,7 +11,7 @@ #include "import.h" ANN static m_bool scan1_stmt_list(const Env env, Stmt_List list); -ANN static m_bool scan1_stmt(const Env env, Stmt stmt); +ANN static m_bool scan1_stmt(const Env env, Stmt* stmt); ANN static inline m_bool type_cyclic(const Env env, const Type t, const Type_Decl *td) { @@ -268,7 +268,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 Stmt s = mp_vector_at(l, struct Stmt_, i); + Stmt* s = mp_vector_at(l, struct Stmt_, i); CHECK_BB(scan1_stmt_match_case(env, &s->d.stmt_match)); } return GW_OK; @@ -354,11 +354,11 @@ describe_ret_nspc(loop, Stmt_Loop,, !( (!stmt->idx ? GW_OK : shadow_var(env, stm scan1_exp(env, stmt->cond) < 0 || scan1_stmt(env, stmt->body) < 0) ? 1 : -1) -ANN static inline bool if_stmt_is_return(const Stmt stmt) { +ANN static inline bool if_stmt_is_return(Stmt* stmt) { if (stmt->stmt_type == ae_stmt_return) return true; if (stmt->stmt_type == ae_stmt_code) { if (mp_vector_len(stmt->d.stmt_code.stmt_list)) { - Stmt s = mp_vector_back(stmt->d.stmt_code.stmt_list, struct Stmt_); + Stmt* s = mp_vector_back(stmt->d.stmt_code.stmt_list, struct Stmt_); if (s->stmt_type == ae_stmt_return) return true; } } @@ -601,11 +601,11 @@ ANN static m_bool scan1_stmt_spread(const Env env, const Spread_Def spread) { DECL_STMT_FUNC(scan1, m_bool, Env) -ANN static inline m_bool scan1_stmt(const Env env, const Stmt stmt) { +ANN static inline m_bool scan1_stmt(const Env env, Stmt* stmt) { return scan1_stmt_func[stmt->stmt_type](env, &stmt->d); } -ANN static inline bool end_flow(Stmt s) { +ANN static inline bool end_flow(Stmt* s) { const ae_stmt_t t = s->stmt_type; return t == ae_stmt_continue || t == ae_stmt_break || @@ -614,7 +614,7 @@ ANN static inline bool end_flow(Stmt s) { ANN static void dead_code(const Env env, Stmt_List l, uint32_t len) { for(uint32_t i = len; i < l->len; i++) { - const Stmt s = mp_vector_at(l, struct Stmt_, i); + Stmt* s = mp_vector_at(l, struct Stmt_, i); free_stmt(env->gwion->mp, s); } l->len = len; @@ -623,7 +623,7 @@ ANN static void dead_code(const Env env, Stmt_List l, uint32_t len) { ANN static m_bool scan1_stmt_list(const Env env, Stmt_List l) { uint32_t i; for(i = 0; i < l->len; i++) { - const Stmt s = mp_vector_at(l, struct Stmt_, i); + Stmt* s = mp_vector_at(l, struct Stmt_, i); CHECK_BB(scan1_stmt(env, s)); if(end_flow(s)) break; } @@ -819,7 +819,7 @@ ANN static m_bool scan1_class_def_body(const Env env, const Class_Def cdef) { if(section.section_type == ae_section_stmt) { Stmt_List list = section.d.stmt_list; for(uint32_t j = 0; j < list->len; j++) { - Stmt stmt = mp_vector_at(list, struct Stmt_, j); + Stmt* stmt = mp_vector_at(list, struct Stmt_, j); mp_vector_add(mp, &ctor, struct Stmt_, *stmt); } } else mp_vector_add(mp, &body, Section, section); diff --git a/src/parse/scan2.c b/src/parse/scan2.c index d940404b..24d69279 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -14,7 +14,7 @@ #include "spread.h" #include "closure.h" -ANN static m_bool scan2_stmt(const Env, const Stmt); +ANN static m_bool scan2_stmt(const Env, Stmt*); ANN static m_bool scan2_stmt_list(const Env, Stmt_List); ANN static inline m_bool ensure_scan2(const Env env, const Type t) { @@ -175,7 +175,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 Stmt s = mp_vector_at(l, struct Stmt_, i); + Stmt* s = mp_vector_at(l, struct Stmt_, i); CHECK_BB(scan2_stmt_match_case(env, &s->d.stmt_match)); } return GW_OK; @@ -262,13 +262,13 @@ ANN static m_bool scan2_stmt_defer(const Env env, const Stmt_Defer stmt) { DECL_STMT_FUNC(scan2, m_bool, Env) -ANN static m_bool scan2_stmt(const Env env, const Stmt stmt) { +ANN static m_bool scan2_stmt(const Env env, Stmt* stmt) { return scan2_stmt_func[stmt->stmt_type](env, &stmt->d); } ANN static m_bool scan2_stmt_list(const Env env, Stmt_List l) { for(m_uint i = 0; i < l->len; i++) { - const Stmt s = mp_vector_at(l, struct Stmt_, i); + Stmt* s = mp_vector_at(l, struct Stmt_, i); CHECK_BB(scan2_stmt(env, s)); } return GW_OK;