From 30af8f4e4e2cb4a4120eca3de9370be81dc71835 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Sun, 25 Feb 2024 19:27:30 +0100 Subject: [PATCH] :fire: update --- ast | 2 +- fmt | 2 +- include/env/type.h | 1 + include/looper.h | 2 +- src/clean.c | 8 +++----- src/compile.c | 8 ++------ src/emit/emit.c | 27 +++++++++++++-------------- src/import/import_fdef.c | 4 ++-- src/import/import_internals.c | 1 + src/import/import_item.c | 2 +- src/import/import_prim.c | 2 +- src/lib/array.c | 10 +++++----- src/lib/dict.c | 6 +++--- src/parse/check.c | 29 ++++++++++++++++------------- src/parse/check_traits.c | 2 +- src/parse/default_arg.c | 2 +- src/parse/scan0.c | 2 +- src/parse/scan1.c | 21 ++++++++++++--------- src/parse/scan2.c | 7 ++++--- src/parse/spread.c | 6 +++--- src/parse/type_decl.c | 6 ++++++ 21 files changed, 79 insertions(+), 71 deletions(-) diff --git a/ast b/ast index 1292b905..f5b426bc 160000 --- a/ast +++ b/ast @@ -1 +1 @@ -Subproject commit 1292b905b96915cdce6627bcfce3490f415c37fa +Subproject commit f5b426bcc8570dabb40dcccc8f5b5ba3236b002e diff --git a/fmt b/fmt index a1d3a168..b6a9fa75 160000 --- a/fmt +++ b/fmt @@ -1 +1 @@ -Subproject commit a1d3a1680d6f680199f6793f599629847a8f9759 +Subproject commit b6a9fa7512897dc1420549c511561b94f722d34c diff --git a/include/env/type.h b/include/env/type.h index 62582a2e..b215a0b6 100644 --- a/include/env/type.h +++ b/include/env/type.h @@ -58,6 +58,7 @@ struct Type_ { uint16_t weight; ae_flag flag; enum tflag tflag; + bool error; }; REF_FUNC(Type, type) diff --git a/include/looper.h b/include/looper.h index 4cebe6cd..490f88ea 100644 --- a/include/looper.h +++ b/include/looper.h @@ -16,7 +16,7 @@ struct Looper { struct Vector_ unroll_v; Instr instr; // }; - struct EachIdx_ *idx; + Var_Decl *idx; bool init; }; #endif diff --git a/src/clean.c b/src/clean.c index 4dd6444e..d5905c34 100644 --- a/src/clean.c +++ b/src/clean.c @@ -161,16 +161,13 @@ ANN static void clean_stmt_for(Clean *a, Stmt_For b) { --a->scope; } -ANN static void clean_idx(Clean *a, struct EachIdx_ *b) { - if (b->var.value) value_remref(b->var.value, a->gwion); -} - ANN static void clean_stmt_each(Clean *a, Stmt_Each b) { ++a->scope; clean_exp(a, b->exp); clean_stmt(a, b->body); + // use clean var_decl? if (b->var.value) mp_free(a->gwion->mp, Value, b->var.value); - if (b->idx) clean_idx(a, b->idx); + if (b->idx.value) clean_var_decl(a, &b->idx); --a->scope; } @@ -178,6 +175,7 @@ ANN static void clean_stmt_loop(Clean *a, Stmt_Loop b) { ++a->scope; clean_exp(a, b->cond); clean_stmt(a, b->body); + if(b->idx.value) clean_var_decl(a, &b->idx); --a->scope; } diff --git a/src/compile.c b/src/compile.c index 9fe42f75..50ab04e3 100644 --- a/src/compile.c +++ b/src/compile.c @@ -118,7 +118,7 @@ ANN static inline bool passes(struct Gwion_ *gwion, struct Compiler *c) { if(isa(v->type, gwion->type[et_class])) { const Type t = (Type)v->d.ptr; type_addref(t); - mk_class(gwion->env, t, (loc_t) {}); + mk_class(gwion->env, t, t->info->value->from->loc); nspc_add_type(gwion->env->curr, insert_symbol(gwion->st, v->name), t); } else valid_value(gwion->env, insert_symbol(gwion->st, v->name), v); @@ -136,13 +136,9 @@ ANN static inline bool passes(struct Gwion_ *gwion, struct Compiler *c) { return ret; } -static pos_t pos = { 1 , 1 }; -void gwion_set_default_pos(const pos_t _pos) { - pos = _pos; -} ANN static inline bool _check(struct Gwion_ *gwion, struct Compiler *c) { struct AstGetter_ arg = {c->name, c->file, gwion->st, .ppa = gwion->ppa}; - CHECK_B((c->ast = parse_pos(&arg, pos))); + CHECK_B((c->ast = parse(&arg))); gwion->env->name = c->name; return passes(gwion, c); } diff --git a/src/emit/emit.c b/src/emit/emit.c index 6c9ad64c..1475e4d5 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -117,7 +117,7 @@ static const f_instr allocmember[4] = {RegPushImm, RegPushImm2, _staticmemset_, static const f_instr allocword[4] = {AllocWord, AllocWord2, AllocWord3, RegPushMem4}; -ANN static bool emit_class_def(const Emitter, const Class_Def); +ANN static bool emit_class_def(const Emitter, const Class_Def); ANN static bool emit_cdef(const Emitter, const Type); ANN static bool ensure_emit(const Emitter emit, const Type t) { @@ -919,8 +919,7 @@ ANN static bool struct_finish(const Emitter emit, const Exp_Decl *decl) { const Type t = decl->type; const bool emit_addr = exp_getvar(exp_self(decl)); if(GET_FLAG(decl->var.vd.value, late) || GET_FLAG(decl->var.td, late)) { - if(!emit_addr) - decl_expand(emit, t); + if(!emit_addr) decl_expand(emit, t); return true; } if(!decl->args && !tflag(t, tflag_ctor) && emit_addr) @@ -2246,13 +2245,13 @@ ANN static bool _emit_stmt_each(const Emitter emit, const Stmt_Each stmt, emit_memsetimm(emit, key_offset, -1); stmt->var.value->from->offset = val_offset; //value_addref(stmt->v); -_nspc_add_value(emit->env->curr, stmt->tag.sym, stmt->var.value); + _nspc_add_value(emit->env->curr, stmt->var.tag.sym, stmt->var.value); emit_debug(emit, stmt->var.value); - if (stmt->idx) { - stmt->idx->var.value->from->offset = key_offset; -_nspc_add_value(emit->env->curr, stmt->idx->var.tag.sym, stmt->idx->var.value); + if (stmt->idx.tag.sym) { + stmt->idx.value->from->offset = key_offset; +_nspc_add_value(emit->env->curr, stmt->idx.tag.sym, stmt->var.value); //value_addref(stmt->idx->v); - emit_debug(emit, stmt->idx->var.value); + emit_debug(emit, stmt->idx.value); } struct Looper loop = {.exp = stmt->exp, .stmt = stmt->body, @@ -2260,7 +2259,7 @@ _nspc_add_value(emit->env->curr, stmt->idx->var.tag.sym, stmt->idx->var.value); .n = n, .roll = each_op, .unroll = each_op, - .idx = stmt->idx, + .idx = stmt->idx.tag.sym ? &stmt->idx : NULL, .init = false }; if (n) { @@ -2296,7 +2295,7 @@ ANN static bool emit_stmt_each(const Emitter emit, const Stmt_Each stmt) { m_uint end_pc = 0; const bool ret = _emit_stmt_each(emit, stmt, &end_pc); emit_pop_stack(emit, end_pc); -nspc_pop_value(emit->gwion->mp, emit->env->curr); + nspc_pop_value(emit->gwion->mp, emit->env->curr); emit->status.unroll = 0; return ret; } @@ -2322,21 +2321,21 @@ ANN static bool _emit_stmt_loop(const Emitter emit, const Stmt_Loop stmt, emit->status.unroll = 0; } const m_uint offset = emit_local(emit, emit->gwion->type[et_int]); - if (stmt->idx) { + if (stmt->idx.tag.sym) { emit_memsetimm(emit, emit_local(emit, emit->gwion->type[et_int]), 0); emit_memsetimm(emit, offset, -1); - stmt->idx->var.value->from->offset = offset; + stmt->idx.value->from->offset = offset; } CHECK_B(emit_exp_pop_next(emit, stmt->cond)); emit_regmove(emit, -SZ_INT); - emit_regtomem(emit, offset + !!stmt->idx * SZ_INT, 0); + emit_regtomem(emit, offset + !!stmt->idx.tag.sym * SZ_INT, 0); *index = emit_code_size(emit); struct Looper loop = {.exp = stmt->cond, .stmt = stmt->body, .offset = offset, .n = n, .roll = - !stmt->idx ? stmt_loop_roll : stmt_loop_roll_idx}; + !stmt->idx.tag.sym ? stmt_loop_roll : stmt_loop_roll_idx}; CHECK_B(looper_run(emit, &loop)); const Instr _goto = emit_add_instr(emit, Goto); _goto->m_val = *index; diff --git a/src/import/import_fdef.c b/src/import/import_fdef.c index dd90d5c2..c035158b 100644 --- a/src/import/import_fdef.c +++ b/src/import/import_fdef.c @@ -59,7 +59,7 @@ ANEW ANN static Func_Def import_fdef(const Gwi gwi, ImportCK *ck) { } ANN static bool section_fdef(const Gwi gwi, const Func_Def fdef) { - Section section = MK_SECTION(func, func_def, fdef); + Section section = MK_SECTION(func, func_def, fdef, gwi->loc); gwi_body(gwi, §ion); return true; } @@ -117,7 +117,7 @@ ANN static Fptr_Def import_fptr(const Gwi gwi) { } ANN static bool section_fptr(const Gwi gwi, const Fptr_Def fdef) { - Section section = MK_SECTION(fptr, fptr_def, fdef); + Section section = MK_SECTION(fptr, fptr_def, fdef, gwi->loc); gwi_body(gwi, §ion); return true; } diff --git a/src/import/import_internals.c b/src/import/import_internals.c index 2b6daaef..786372ca 100644 --- a/src/import/import_internals.c +++ b/src/import/import_internals.c @@ -38,6 +38,7 @@ ANN static bool run_with_doc(const Gwi gwi, bool (*f)(const Gwi)) { gwi->gwfmt = &gwfmter; const bool ret = f(gwi); fprintf(stdout, "%s", ls.text.str); + free_mstr(gwi->gwion->mp, ls.text.str); return ret; } diff --git a/src/import/import_item.c b/src/import/import_item.c index 0d315f25..e9bcaa89 100644 --- a/src/import/import_item.c +++ b/src/import/import_item.c @@ -20,7 +20,7 @@ ANN bool gwi_item_ini(const Gwi gwi, const restrict m_str type, ANN static bool gwi_item_tmpl(const Gwi gwi) { Stmt_List slist = new_mp_vector(gwi->gwion->mp, Stmt, 1); mp_vector_set(slist, Stmt, 0, MK_STMT_EXP(gwi->loc, gwi->ck->exp)); - Section section = MK_SECTION(stmt, stmt_list, slist); + Section section = MK_SECTION(stmt, stmt_list, slist, gwi->loc); gwi_body(gwi, §ion); mp_free2(gwi->gwion->mp, sizeof(ImportCK), gwi->ck); gwi->ck = NULL; diff --git a/src/import/import_prim.c b/src/import/import_prim.c index 6fcf2491..fdbd7502 100644 --- a/src/import/import_prim.c +++ b/src/import/import_prim.c @@ -230,7 +230,7 @@ ANN bool gwi_primitive(const Gwi gwi, const m_str name, const m_uint size, const free_prim_def(gwi->gwion->mp, pdef); return ret; } - Section section = MK_SECTION(primitive, prim_def, pdef); + Section section = MK_SECTION(primitive, prim_def, pdef, gwi->loc); gwi_body(gwi, §ion); return true; } diff --git a/src/lib/array.c b/src/lib/array.c index 88cc7eb5..14d0f170 100644 --- a/src/lib/array.c +++ b/src/lib/array.c @@ -807,13 +807,13 @@ static OP_CHECK(opck_array_scan) { = ts->t != t_array ? ts->t : known_type(env, mp_vector_at(ts->td->types, TmplArg, 0)->d.td)); if (base->size == 0) { gwerr_basic("Can't use type of size 0 as array base", NULL, NULL, - "/dev/null", (loc_t) {}, 0); + env->context->name, ts->td->tag.loc, 0); env_set_error(env, true); return env->gwion->type[et_error]; } if (tflag(base, tflag_ref)) { - gwerr_basic("Can't use ref types as array base", NULL, NULL, "/dev/null", - (loc_t) {}, 0); + gwerr_basic("Can't use ref types as array base", NULL, NULL, + env->context->name, ts->td->tag.loc, 0); env_set_error(env, true); return env->gwion->type[et_error]; } @@ -821,10 +821,10 @@ static OP_CHECK(opck_array_scan) { const Type type = nspc_lookup_type1(base->info->value->from->owner, sym); if (type) return type; const Class_Def cdef = cpy_class_def(env->gwion->mp, c); - cdef->base.ext = type2td(env->gwion, t_array, (loc_t){}); + cdef->base.ext = type2td(env->gwion, t_array, t_array->info->value->from->loc); cdef->base.tag.sym = sym; cdef->base.tmpl->call = new_mp_vector(env->gwion->mp, TmplArg, 1); - TmplArg arg = {.type = tmplarg_td, .d = {.td = type2td(env->gwion, base, (loc_t){})} }; + TmplArg arg = {.type = tmplarg_td, .d = {.td = type2td(env->gwion, base, base->info->value->from->loc)} }; mp_vector_set(cdef->base.tmpl->call, TmplArg, 0, arg); const Context ctx = env->context; env->context = base->info->value->from->ctx; diff --git a/src/lib/dict.c b/src/lib/dict.c index 6f9ebd3b..a0fd7dfe 100644 --- a/src/lib/dict.c +++ b/src/lib/dict.c @@ -517,10 +517,10 @@ static INSTR(DictEachIdx) { static OP_EMIT(opem_dict_each) { Looper *loop = (Looper *)data; HMapInfo *const hinfo = (HMapInfo*)loop->exp->type->nspc->class_data; - if(loop->idx && !loop->init) loop->idx->var.value->from->offset = emit_localn(emit, hinfo->key); - const Instr instr = emit_add_instr(emit, !loop->idx ? DictEach : DictEachIdx); + if(loop->idx && !loop->init) loop->idx->value->from->offset = emit_localn(emit, hinfo->key); + const Instr instr = emit_add_instr(emit, !loop->idx->tag.sym ? DictEach : DictEachIdx); instr->m_val2 = loop->offset; - if(loop->idx) instr->m_val = loop->idx->var.value->from->offset; + if(loop->idx) instr->m_val = loop->idx->value->from->offset; if(loop->n)instr->m_val2 += SZ_INT; const Instr go = emit_add_instr(emit, BranchNeqInt); if(!loop->n) loop->instr = go; diff --git a/src/parse/check.c b/src/parse/check.c index c0d58fc9..37a047bc 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -1351,7 +1351,7 @@ ANN Type check_exp(const Env env, Exp* exp) { do { if(curr->type) continue; if(curr->poison) continue; - if(!(curr->type = check_exp_func[curr->exp_type](env, &curr->d))) { + if(!(curr->type = check_exp_func[curr->exp_type](env, &curr->d)) || curr->type->error) { POISON_NODE(ok, env, curr); continue; } @@ -1405,20 +1405,20 @@ ANN static inline bool for_empty(const Env env, const Stmt_For stmt) { return true; } -ANN static void check_idx(const Env env, const Type base, struct EachIdx_ *const idx) { - idx->var.value = new_value(env, base, idx->var.tag); - valid_value(env, idx->var.tag.sym, idx->var.value); - SET_FLAG(idx->var.value, const); +ANN static void check_idx(const Env env, const Type base, Var_Decl *const idx) { + idx->value = new_value(env, base, idx->tag); + valid_value(env, idx->tag.sym, idx->value); + SET_FLAG(idx->value, const); } /** sets for the key expression value with eg type *int* for an array or the *Key* type of a Dict **/ -ANN static bool check_each_idx(const Env env, Exp* exp, struct EachIdx_ *const idx) { +ANN static bool check_each_idx(const Env env, Exp* exp, Var_Decl *const idx) { struct Op_Import opi = { .lhs = exp->type, .op = insert_symbol("@each_idx"), .data = (m_uint)exp, - .loc = idx->var.tag.loc + .loc = idx->tag.loc }; DECL_B(const Type, t, = op_check(env, &opi)); check_idx(env, t, idx); @@ -1439,16 +1439,16 @@ ANN static Type check_each_val(const Env env, Exp* exp) { ANN static bool do_stmt_each(const Env env, const Stmt_Each stmt) { CHECK_B(check_exp(env, stmt->exp)); - if (stmt->idx) - CHECK_B(check_each_idx(env, stmt->exp, stmt->idx)); + if (stmt->idx.tag.sym) + CHECK_B(check_each_idx(env, stmt->exp, &stmt->idx)); DECL_B(const Type, ret, = check_each_val(env, stmt->exp)); - stmt->var.value = new_value(env, ret, stmt->tag); - valid_value(env, stmt->tag.sym, stmt->var.value); + stmt->var.value = new_value(env, ret, stmt->var.tag); + valid_value(env, stmt->var.tag.sym, stmt->var.value); return check_conts(env, stmt_self(stmt), stmt->body); } ANN static bool do_stmt_repeat(const Env env, const Stmt_Loop stmt) { - if (stmt->idx) check_idx(env, env->gwion->type[et_int], stmt->idx); + if (stmt->idx.tag.sym) check_idx(env, env->gwion->type[et_int], &stmt->idx); return check_conts(env, stmt_self(stmt), stmt->body); } @@ -2076,6 +2076,7 @@ ANN static bool check_trait_def(const Env env, const Trait_Def pdef) { } ANN bool check_fptr_def(const Env env, const Fptr_Def fptr) { +if(fptr->cdef->base.type->error) return false; if(GET_FLAG(fptr->cdef, global)) env_push_global(env); const bool ret = check_class_def(env, fptr->cdef); if(GET_FLAG(fptr->cdef, global)) env_pop(env, 0); @@ -2232,8 +2233,10 @@ ANN static bool check_class_tmpl(const Env env, const Tmpl *tmpl, const Nspc nsp for(uint32_t i = 0; i < tmpl->list->len; i++) { const TmplArg targ = *mp_vector_at(tmpl->call, TmplArg, i); if(likely(targ.type == tmplarg_td)) continue; - if(!check_exp(env, targ.d.exp)) + if(!check_exp(env, targ.d.exp)) { POISON_NODE(ok, env, targ.d.exp); + continue; + } const Specialized spec = *mp_vector_at(tmpl->list, Specialized, i); const Value v = new_value(env, targ.d.exp->type, MK_TAG(spec.tag.sym, targ.d.exp->loc)); valuefrom(env, v->from); diff --git a/src/parse/check_traits.c b/src/parse/check_traits.c index c52af181..883954e2 100644 --- a/src/parse/check_traits.c +++ b/src/parse/check_traits.c @@ -59,7 +59,7 @@ ANN static bool trait_inherit(const Env env, const Type t, const Func_Def req) { if(global) SET_FLAG(cpy->base, global); const bool ret = traverse_func_def(env, cpy); nspc_pop_type(env->gwion->mp, env->curr); - Section section = MK_SECTION(func, func_def, cpy); + Section section = MK_SECTION(func, func_def, cpy, t->info->value->from->loc); if(!env->context->extend) env->context->extend = new_mp_vector(env->gwion->mp, Section, 0); mp_vector_add(env->gwion->mp, &env->context->extend, Section, section); diff --git a/src/parse/default_arg.c b/src/parse/default_arg.c index 6d933de5..f46bf76d 100644 --- a/src/parse/default_arg.c +++ b/src/parse/default_arg.c @@ -62,7 +62,7 @@ ANN Func_Def default_args(const Env env, Func_Base *fb, Ast *acc, uint32_t max) ? std_code(env, fb, max) : new_code(env, fb, max); const Func_Def fdef = new_func_def(env->gwion->mp, base, code); - Section section = MK_SECTION(func, func_def, fdef); + Section section = MK_SECTION(func, func_def, fdef, fb->tag.loc); mp_vector_add(env->gwion->mp, acc, Section, section); return fdef; } diff --git a/src/parse/scan0.c b/src/parse/scan0.c index c3f3a139..55ac3dc5 100644 --- a/src/parse/scan0.c +++ b/src/parse/scan0.c @@ -64,7 +64,7 @@ ANN bool scan0_fptr_def(const Env env, const Fptr_Def fptr) { insert_symbol("func"), args, ae_flag_static | ae_flag_private, loc); const Func_Def fdef = new_func_def(env->gwion->mp, fbase, NULL); Ast body = new_mp_vector(env->gwion->mp, Section, 1); - mp_vector_set(body, Section, 0, MK_SECTION(func, func_def, fdef)); + mp_vector_set(body, Section, 0, MK_SECTION(func, func_def, fdef, loc)); Type_Decl* td = new_type_decl(env->gwion->mp, insert_symbol(env->gwion->type[et_closure]->name), loc); const Class_Def cdef = new_class_def(env->gwion->mp, ae_flag_final, fptr->base->tag, td, body); if(global) SET_FLAG(cdef, global); diff --git a/src/parse/scan1.c b/src/parse/scan1.c index 0d9b565a..5158d85e 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -308,12 +308,12 @@ ANN static inline bool scan1_stmt_try(const restrict Env env, ANN static inline bool stmt_each_defined(const restrict Env env, const Stmt_Each stmt) { bool ok = true; - if (nspc_lookup_value1(env->curr, stmt->tag.sym)) + if (nspc_lookup_value1(env->curr, stmt->var.tag.sym)) ERR_OK_NODE(ok, stmt_self(stmt), stmt_self(stmt)->loc, _("foreach value '%s' is already defined"), - s_name(stmt->tag.sym)); - if (stmt->idx && nspc_lookup_value1(env->curr, stmt->idx->var.tag.sym)) - ERR_OK_NODE(ok, stmt_self(stmt), stmt->idx->var.tag.loc, _("foreach index '%s' is already defined"), - s_name(stmt->idx->var.tag.sym)); + s_name(stmt->var.tag.sym)); + if (stmt->idx.tag.sym && nspc_lookup_value1(env->curr, stmt->idx.tag.sym)) + ERR_OK_NODE(ok, stmt_self(stmt), stmt->idx.tag.loc, _("foreach index '%s' is already defined"), + s_name(stmt->idx.tag.sym)); return ok; } @@ -356,7 +356,7 @@ describe_ret_nspc(for, Stmt_For,, !(!scan1_stmt(env, stmt->c1) || !scan1_stmt(env, stmt->body)) ? true : false) describe_ret_nspc(each, Stmt_Each,, !(!stmt_each_defined(env, stmt) || !scan1_exp(env, stmt->exp) || !scan1_stmt(env, stmt->body)) ? true : false) -describe_ret_nspc(loop, Stmt_Loop,, !( (!stmt->idx ? true : !shadow_var(env, stmt->idx->var.tag)) || +describe_ret_nspc(loop, Stmt_Loop,, !( (!stmt->idx.tag.sym ? true : !shadow_var(env, stmt->idx.tag)) || !scan1_exp(env, stmt->cond) || !scan1_stmt(env, stmt->body)) ? true : false) @@ -550,8 +550,10 @@ ANN static inline bool scan1_union_def_inner_loop(const Env env, ERR_OK(ok, um->vd.tag.loc, _("'%s' already declared in union"), s_name(um->vd.tag.sym)); const Type t = known_type(env, um->td); if(t) { - if(tflag(t, tflag_ref)) + if(tflag(t, tflag_ref)) { ERR_OK(ok, um->vd.tag.loc, _("can't declare ref type in union")); + continue; + } const Value v = new_value(env, t, um->vd.tag); tuple_contains(env, v); valuefrom(env, v->from); @@ -849,12 +851,13 @@ ANN static bool scan1_class_def_body(const Env env, const Class_Def cdef) { Symbol sym = insert_symbol("@ctor"); Func_Base *fb = new_func_base(mp, td, sym, NULL, ae_flag_none, cdef->base.tag.loc); Func_Def fdef = new_func_def(mp, fb, ctor); - mp_vector_set(body, Section, 0, MK_SECTION(func, func_def, fdef)); + mp_vector_set(body, Section, 0, MK_SECTION(func, func_def, fdef, cdef->base.tag.loc)); free_mp_vector(mp, Section, base); cdef->body = body; } // return -env_body(env, cdef, scan1_section); +// check for previous errors? +cdef->base.type->error = !env_body(env, cdef, scan1_section); return true; } diff --git a/src/parse/scan2.c b/src/parse/scan2.c index 91a77146..211fdfe7 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -75,6 +75,7 @@ ANN static Value scan2_func_assign(const Env env, const Func_Def d, } ANN bool scan2_fptr_def(const Env env NUSED, const Fptr_Def fptr) { + if(fptr->cdef->base.type->error) return false; if(GET_FLAG(fptr->cdef, global)) env_push_global(env); const bool ret = scan2_class_def(env, fptr->cdef); const Func_Def fdef = mp_vector_at(fptr->cdef->base.type->info->cdef->body, struct Section_ , 0)->d.func_def; @@ -360,7 +361,7 @@ static bool scan2_fdef_tmpl(const Env env, const Func_Def f, const Value overload) { const m_str name = s_name(f->base->tag.sym); const Func func = scan_new_func(env, f, name); - const Value value = func_value(env, func, overload); + DECL_B(const Value, value, = func_value(env, func, overload)); set_fflag(func, fflag_tmpl); set_vflag(value, vflag_valid); set_tflag(value->type, @@ -453,9 +454,9 @@ ANN static m_str func_tmpl_name(const Env env, const Func_Def f) { ANN2(1, 2, 4) static Value func_create(const Env env, const Func_Def f, const Value overload, const m_str name) { - const Func func = scan_new_func(env, f, name); + DECL_B(const Func, func, = scan_new_func(env, f, name)); nspc_add_func(env->curr, insert_symbol(func->name), func); - const Value v = func_value(env, func, overload); + DECL_B(const Value, v, = func_value(env, func, overload)); scan2_func_def_flag(env, f); nspc_add_value(env->curr, insert_symbol(func->name), v); return v; diff --git a/src/parse/spread.c b/src/parse/spread.c index abf56f49..f8640d97 100644 --- a/src/parse/spread.c +++ b/src/parse/spread.c @@ -53,7 +53,7 @@ ANN bool spread_ast(const Env env, const Spread_Def spread, const Tmpl *tmpl) { free_mp_vector(env->gwion->mp, Section , ast); } fclose(f); - mp_vector_add(env->gwion->mp, &env->context->extend, Section, MK_SECTION(stmt, stmt_list, NULL)); + mp_vector_add(env->gwion->mp, &env->context->extend, Section, MK_SECTION(stmt, stmt_list, NULL, spread->tag.loc)); return true; } @@ -70,7 +70,7 @@ ANN Ast spread_class(const Env env, const Ast body) { const Stmt stmt = *mp_vector_at(list, Stmt, j); if(stmt.stmt_type == ae_stmt_spread) { if(acc) { - mp_vector_add(env->gwion->mp, &new_body, Section, MK_SECTION(stmt, stmt_list, acc)); + mp_vector_add(env->gwion->mp, &new_body, Section, MK_SECTION(stmt, stmt_list, acc, stmt.loc)); acc = NULL; } const Ast extend = env->context->extend; @@ -90,7 +90,7 @@ ANN Ast spread_class(const Env env, const Ast body) { } } if(acc) { - mp_vector_add(env->gwion->mp, &new_body, Section, MK_SECTION(stmt, stmt_list, acc)); + mp_vector_add(env->gwion->mp, &new_body, Section, MK_SECTION(stmt, stmt_list, acc, section.loc)); } } } diff --git a/src/parse/type_decl.c b/src/parse/type_decl.c index 71924f64..e79884c1 100644 --- a/src/parse/type_decl.c +++ b/src/parse/type_decl.c @@ -8,6 +8,7 @@ #include "operator.h" #include "instr.h" #include "import.h" +#include "gwfmt.h" ANN static Type _option(const Env env, Type_Decl *td, const uint8_t n) { const Array_Sub array = td->array; @@ -117,7 +118,12 @@ ANN static Type resolve(const Env env, Type_Decl *td) { } ANN static inline void *type_unknown(const Env env, const Type_Decl *td) { + struct GwfmtState ls = {}; + text_init(&ls.text, env->gwion->mp); + Gwfmt gwfmter = {.mp = env->gwion->mp, .ls = &ls, .st = env->gwion->st }; + gwfmt_type_decl(&gwfmter, td); env_err(env, td->tag.loc, _("unknown type '%s'"), s_name(td->tag.sym)); + free_mstr(env->gwion->mp, ls.text.str); return NULL; } -- 2.43.0