From 0877a8b98ce56d52c65c1f294f6d5c48f4f4a6d7 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Tue, 30 Jan 2024 14:56:36 +0100 Subject: [PATCH] :art: more ast cleaning --- ast | 2 +- include/env/env.h | 16 ++++----- include/import.h | 10 +++--- include/import/checker.h | 6 ++-- include/operator.h | 4 +-- include/tmp_resolve.h | 2 +- src/emit/emit.c | 36 ++++++++++---------- src/emit/escape.c | 16 ++++----- src/env/env.c | 4 +-- src/env/env_utils.c | 16 ++++----- src/gwion.c | 16 ++++----- src/import/import_checker.c | 68 ++++++++++++++++++------------------- src/import/import_oper.c | 2 +- src/lib/array.c | 10 +++--- src/lib/closure.c | 6 ++-- src/lib/deep_equal.c | 4 +-- src/lib/object_op.c | 2 +- src/parse/check.c | 60 ++++++++++++++++---------------- src/parse/operator.c | 22 ++++++------ src/parse/scan0.c | 4 +-- src/parse/scan1.c | 10 +++--- src/parse/scan2.c | 2 +- src/parse/template.c | 14 ++++---- 23 files changed, 167 insertions(+), 165 deletions(-) diff --git a/ast b/ast index 0ba7b3b1..56d8b92b 160000 --- a/ast +++ b/ast @@ -1 +1 @@ -Subproject commit 0ba7b3b15cbdfab20b35b8a84dcebded0501c054 +Subproject commit 56d8b92b822a2d2891e4d4cea954936538698a28 diff --git a/include/env/env.h b/include/env/env.h index a0b2db13..59f4e57b 100644 --- a/include/env/env.h +++ b/include/env/env.h @@ -53,24 +53,24 @@ ANN m_bool compat_func(const __restrict__ Func_Def, const __restrict__ Func_Def); ANN Type known_type(const Env env, Type_Decl *); ANN Type prim_ref(const Env env, const Type t, const Type_Decl *td); -ANN m_bool env_access(const Env env, const ae_flag flag, const loc_t pos); -ANN m_bool env_storage(const Env env, ae_flag flag, const loc_t pos); +ANN m_bool env_access(const Env env, const ae_flag flag, const loc_t); +ANN m_bool env_storage(const Env env, ae_flag flag, const loc_t); ANN void env_add_type(const Env, const Type, const loc_t); ANN Type find_type(const Env, Type_Decl *); ANN m_bool traverse_func_template(const Env, const Func_Def); -ANN void env_err(const Env, const loc_t pos, const m_str fmt, ...); -ANN void env_warn(const Env, const loc_t pos, const m_str fmt, ...); +ANN void env_err(const Env, const loc_t, const m_str fmt, ...); +ANN void env_warn(const Env, const loc_t, const m_str fmt, ...); ANN void env_error_footer(const Env env); ANN Value global_string(const Env env, const m_str str, const loc_t); ANN void release_ctx(struct Env_Scope_ *a, struct Gwion_ *gwion); struct ScopeEffect { Symbol sym; - loc_t pos; + loc_t loc; }; -ANN void env_add_effect(const Env a, const Symbol effect, const loc_t pos); -ANN void call_add_effect(const Env env, const Func func, const loc_t pos); +ANN void env_add_effect(const Env a, const Symbol effect, const loc_t); +ANN void call_add_effect(const Env env, const Func func, const loc_t); -ANN m_bool already_defined(const Env env, const Symbol s, const loc_t pos); +ANN m_bool already_defined(const Env env, const Symbol s, const loc_t); #endif diff --git a/include/import.h b/include/import.h index 45b0fa40..b3f85b5b 100644 --- a/include/import.h +++ b/include/import.h @@ -85,18 +85,18 @@ OP_EMIT(opem_new); ANN static inline M_Object new_object_str(const Gwion gwion, const m_str str) { - struct loc_t_ loc = {}; + loc_t loc = {}; DECL_OO(const Type, t, = str2type(gwion, str, loc)); return new_object(gwion->mp, t); } -static inline Type dict_type(const Gwion gwion, const Type key, const Type val, const loc_t pos) { +static inline Type dict_type(const Gwion gwion, const Type key, const Type val, const loc_t loc) { char c[1024]; - const m_str keyname = type2str(gwion, key, pos); - const m_str valname = type2str(gwion, key, pos); + const m_str keyname = type2str(gwion, key, loc); + const m_str valname = type2str(gwion, key, loc); sprintf(c, "Dict:[%s,%s]", key->name, val->name); free_mstr(gwion->mp, keyname); free_mstr(gwion->mp, valname); - return str2type(gwion, c, pos); + return str2type(gwion, c, loc); } #endif diff --git a/include/import/checker.h b/include/import/checker.h index 7fb8036c..22aa8b8d 100644 --- a/include/import/checker.h +++ b/include/import/checker.h @@ -53,9 +53,9 @@ ANEW ANN m_str tl2str(const Gwion, const TmplArg_List, const loc_t); ANEW ANN m_str type2str(const Gwion, const Type, const loc_t); ANN static inline Type_Decl *type2td(const Gwion gwion, const Type t, - const loc_t pos) { - const m_str str = type2str(gwion, t, pos); - Type_Decl * td = str2td(gwion, str, pos); + const loc_t loc) { + const m_str str = type2str(gwion, t, loc); + Type_Decl * td = str2td(gwion, str, loc); free_mstr(gwion->mp, str); return td; } diff --git a/include/operator.h b/include/operator.h index 54c1ed42..c0fb06ca 100644 --- a/include/operator.h +++ b/include/operator.h @@ -62,13 +62,13 @@ struct Op_Import { // could be put in a union with `ret` Nspc nspc; Symbol op; - loc_t pos; + loc_t loc; }; struct Implicit { Exp e; Type t; - loc_t pos; + loc_t loc; }; struct TemplateScan { diff --git a/include/tmp_resolve.h b/include/tmp_resolve.h index 4fa0185a..f88e75b2 100644 --- a/include/tmp_resolve.h +++ b/include/tmp_resolve.h @@ -3,5 +3,5 @@ ANN Func find_template_match(const Env env, const Value value, Exp_Call *const exp); ANN Func find_func_match(const Env env, const Func up, Exp_Call *const exp); -ANN2(1,2) m_bool check_tmpl(const Env env, const TmplArg_List tl, const Specialized_List sl, const loc_t pos, const bool is_spread); +ANN2(1,2) m_bool check_tmpl(const Env env, const TmplArg_List tl, const Specialized_List sl, const loc_t loc, const bool is_spread); #endif diff --git a/src/emit/emit.c b/src/emit/emit.c index e8203b93..d2840770 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -615,7 +615,7 @@ ANN static m_bool emit_prim_range(const Emitter emit, Range **data) { assert(e); struct Op_Import opi = {.op = sym, .lhs = e->type, - .pos = e->pos, + .loc = e->pos, .data = (uintptr_t)prim_exp(data)}; CHECK_BB(op_emit(emit, &opi)); emit_local_exp(emit, prim_exp(data)); @@ -706,7 +706,7 @@ ANN static m_bool emit_exp_slice(const Emitter emit, const Exp_Slice *range) { struct Op_Import opi = {.op = sym, .lhs = e->type, .rhs = range->base->type, - .pos = e->pos, + .loc = e->pos, .data = (uintptr_t)exp_self(range)}; CHECK_BB(op_emit(emit, &opi)); emit_local_exp(emit, exp_self(range)); @@ -1326,7 +1326,7 @@ ANN static m_bool _emit_exp_call(const Emitter emit, const Exp_Call *call) { struct Op_Import opi = {.op = insert_symbol("call_type"), .rhs = t, .data = (uintptr_t)call, - .pos = exp_self(call)->pos}; + .loc = exp_self(call)->pos}; CHECK_BB(op_emit(emit, &opi)); } const Func f = t->info->func; @@ -1390,7 +1390,7 @@ ANN static m_bool emit_exp_binary(const Emitter emit, const Exp_Binary *bin) { struct Op_Import opi = {.op = bin->op, .lhs = lhs->type, .rhs = rhs->type, - .pos = exp_self(bin)->pos, + .loc = exp_self(bin)->pos, .data = (uintptr_t)bin}; return op_emit(emit, &opi); } @@ -1552,7 +1552,7 @@ static m_bool me_cmp(MemoizeEmitter *me, const Arg *arg) { struct Op_Import opi = {.op = sym, .lhs = arg->type, .rhs = arg->type, - .pos = me->fdef->base->tag.loc, + .loc = me->fdef->base->tag.loc, .data = (uintptr_t)&bin.d}; CHECK_BB(op_emit(emit, &opi)); const Instr instr = emit_add_instr(emit, BranchEqInt); @@ -1653,9 +1653,9 @@ ANN static inline void stack_alloc(const Emitter emit) { #define FORK_CODE_PREFIX "fork~code:%u" static void push_spork_code(const Emitter emit, const m_str prefix, - const loc_t pos) { - char c[strlen(SPORK_FUNC_PREFIX) + num_digit(pos.first.line) + 1]; - sprintf(c, prefix, pos.first.line); + const loc_t loc) { + char c[strlen(SPORK_FUNC_PREFIX) + num_digit(loc.first.line) + 1]; + sprintf(c, prefix, loc.first.line); emit_push_code(emit, c); } @@ -1665,7 +1665,7 @@ struct Sporker { VM_Code vm_code; const Type type; const Capture_List captures; - const loc_t pos; + const loc_t loc; const bool emit_var; const bool is_spork; }; @@ -1674,7 +1674,7 @@ ANN static m_bool spork_prepare_code(const Emitter emit, const struct Sporker *sp) { emit_pushimm(emit, 0); push_spork_code(emit, sp->is_spork ? SPORK_CODE_PREFIX : FORK_CODE_PREFIX, - sp->pos); + sp->loc); if (emit->env->class_def) stack_alloc(emit); if (emit->env->func && vflag(emit->env->func->value_ref, vflag_member)) stack_alloc(emit); @@ -1736,7 +1736,7 @@ ANN m_bool emit_exp_spork(const Emitter emit, const Exp_Unary *unary) { .code = unary->unary_type == unary_code ? unary->code : NULL, .type = exp_self(unary)->type, .captures = unary->captures, - .pos = exp_self(unary)->pos, + .loc = exp_self(unary)->pos, .is_spork = (unary->op == insert_symbol("spork")), .emit_var = exp_getvar(exp_self(unary))}; CHECK_OB((sporker.vm_code = spork_prepare(emit, &sporker))); @@ -1804,12 +1804,14 @@ ANN static m_bool emit_exp_unary(const Emitter emit, const Exp_Unary *unary) { ANN static m_bool emit_implicit_cast(const Emitter emit, const restrict Exp from, const restrict Type to) { - const struct Implicit imp = { .e=from, .t=to, .pos=from->pos}; + const struct Implicit imp = { .e=from, .t=to, . loc = from->pos}; // no pos struct Op_Import opi = {.op = insert_symbol("@implicit"), .lhs = from->type, .rhs = to, - .data = (m_uint)&imp}; + .data = (m_uint)&imp, + .loc = from->pos + }; return op_emit(emit, &opi); } @@ -1828,7 +1830,7 @@ ANN2(1,2) static Instr _flow(const Emitter emit, const Exp e, Instr *const instr struct Op_Import opi = { .op = insert_symbol(b ? "@conditional" : "@unconditional"), .rhs = e->type, - .pos = e->pos, + .loc = e->pos, .data = (uintptr_t)e}; CHECK_BO(op_emit(emit, &opi)); return (Instr)vector_back(&emit->code->instr); @@ -2431,7 +2433,7 @@ ANN static m_bool emit_case_head(const Emitter emit, const Exp base, .lhs = base->type, .rhs = e->type, .data = (uintptr_t)&ebin.d.exp_binary, - .pos = e->pos}; + .loc = e->pos}; CHECK_BB(op_emit(emit, &opi)); const Instr instr = emit_add_instr(emit, BranchEqInt); vector_add(v, (vtype)instr); @@ -2506,7 +2508,7 @@ ANN static Symbol case_op(const Emitter emit, const Exp base, const Exp e, .lhs = base->type, .rhs = e->type, .data = (uintptr_t)&ebin.d.exp_binary, - .pos = e->pos}; + .loc = e->pos}; CHECK_BO(op_emit(emit, &opi)); const Instr instr = emit_add_instr(emit, BranchEqInt); vector_add(vec, (vtype)instr); @@ -2631,7 +2633,7 @@ ANN static m_bool emit_exp_dot(const Emitter emit, const Exp_Dot *member) { .lhs = member->base->type, .rhs = exp_self(member)->type, .data = (uintptr_t)member, - .pos = exp_self(member)->pos}; + .loc = exp_self(member)->pos}; return op_emit(emit, &opi); } diff --git a/src/emit/escape.c b/src/emit/escape.c index 8a5b4132..6e617309 100644 --- a/src/emit/escape.c +++ b/src/emit/escape.c @@ -22,13 +22,13 @@ char *escape_table(MemPool p) { return escape; } -static int get_escape(const Emitter emit, const char c, const loc_t pos) { +static int get_escape(const Emitter emit, const char c, const loc_t loc) { if (emit->info->escape[(int)c]) return emit->info->escape[(int)c]; - env_err(emit->env, pos, _("unrecognized escape sequence '\\%c'"), c); + env_err(emit->env, loc, _("unrecognized escape sequence '\\%c'"), c); return GW_ERROR; } -m_bool escape_str(const Emitter emit, const m_str base, const loc_t pos) { +m_bool escape_str(const Emitter emit, const m_str base, const loc_t loc) { unsigned char *str_lit = (unsigned char *)base; m_str str = base; while (*str_lit) { @@ -45,7 +45,7 @@ m_bool escape_str(const Emitter emit, const m_str base, const loc_t pos) { *str++ = (char)((c - '0') * 64 + (c2 - '0') * 8 + (c3 - '0')); str_lit += 2; } else { - env_err(emit->env, pos, + env_err(emit->env, loc, _("malformed octal escape sequence '\\%c%c%c'"), c, c2, c3); return GW_ERROR; } @@ -58,12 +58,12 @@ m_bool escape_str(const Emitter emit, const m_str base, const loc_t pos) { *str++ = (char)((c1 - '0') * 16 + (c3 - '0')); ++str_lit; } else { - env_err(emit->env, pos, _("malformed hex escape sequence '\\%c%c'"), + env_err(emit->env, loc, _("malformed hex escape sequence '\\%c%c'"), c1, c3); return GW_ERROR; } } else - CHECK_BB((*str++ = (char)get_escape(emit, (char)c, pos))); + CHECK_BB((*str++ = (char)get_escape(emit, (char)c, loc))); } else *str++ = (char)*str_lit; ++str_lit; @@ -72,6 +72,6 @@ m_bool escape_str(const Emitter emit, const m_str base, const loc_t pos) { return GW_OK; } -ANN char str2char(const Emitter emit, const m_str c, const loc_t pos) { - return c[0] != '\\' ? c[0] : get_escape(emit, c[1], pos); +ANN char str2char(const Emitter emit, const m_str c, const loc_t loc) { + return c[0] != '\\' ? c[0] : get_escape(emit, c[1], loc); } diff --git a/src/env/env.c b/src/env/env.c index ded3a4f7..f9e7853e 100644 --- a/src/env/env.c +++ b/src/env/env.c @@ -69,14 +69,14 @@ ANN static void free_env_scope(struct Env_Scope_ *a, Gwion gwion) { mp_free(gwion->mp, Env_Scope, a); } -ANN void env_add_effect(const Env a, const Symbol effect, const loc_t pos) { +ANN void env_add_effect(const Env a, const Symbol effect, const loc_t loc) { const Vector v = &a->scope->effects; MP_Vector *w = (MP_Vector*)vector_back(v); if (!w) { w = new_mp_vector(a->gwion->mp, struct ScopeEffect, 0); VPTR(v, VLEN(v) - 1) = (vtype)w; } - struct ScopeEffect eff = {effect, pos}; + struct ScopeEffect eff = {effect, loc}; mp_vector_add(a->gwion->mp, (MP_Vector**)&(VPTR(v, VLEN(v) - 1)) , struct ScopeEffect, eff); } diff --git a/src/env/env_utils.c b/src/env/env_utils.c index c9926064..c5084ffb 100644 --- a/src/env/env_utils.c +++ b/src/env/env_utils.c @@ -6,23 +6,23 @@ #include "parse.h" #define GET(a, b) ((a) & (b)) == (b) -ANN m_bool env_access(const Env env, const ae_flag flag, const loc_t pos) { +ANN m_bool env_access(const Env env, const ae_flag flag, const loc_t loc) { if (env->scope->depth) { if (GET(flag, ae_flag_global)) - ERR_B(pos, _("`{G}global{0}` can only be used at %s scope."), + ERR_B(loc, _("`{G}global{0}` can only be used at %s scope."), GET(flag, ae_flag_global) && !env->class_def ? "file" : "class") } if ((GET(flag, ae_flag_static) || GET(flag, ae_flag_private) || GET(flag, ae_flag_protect)) && (!env->class_def || env->scope->depth)) - ERR_B(pos, _("`{G}static/private/protect{0}` can only be used at class scope.")) + ERR_B(loc, _("`{G}static/private/protect{0}` can only be used at class scope.")) return GW_OK; } -ANN m_bool env_storage(const Env env, ae_flag flag, const loc_t pos) { - CHECK_BB(env_access(env, flag, pos)); +ANN m_bool env_storage(const Env env, ae_flag flag, const loc_t loc) { + CHECK_BB(env_access(env, flag, loc)); if(env->class_def && GET(flag, ae_flag_global)) - ERR_B(pos, _("`{G}global{0}` at class scope only valid for function pointers")); + ERR_B(loc, _("`{G}global{0}` at class scope only valid for function pointers")); return GW_OK; } #undef GET @@ -65,10 +65,10 @@ ANN Type find_type(const Env env, Type_Decl *td) { return type; } -ANN m_bool already_defined(const Env env, const Symbol s, const loc_t pos) { +ANN m_bool already_defined(const Env env, const Symbol s, const loc_t loc) { const Value v = nspc_lookup_value0(env->curr, s); if (!v || is_class(env->gwion, v->type)) return GW_OK; - gwerr_basic(_("already declared as variable"), NULL, NULL, env->name, pos, 0); + gwerr_basic(_("already declared as variable"), NULL, NULL, env->name, loc, 0); declared_here(v); env_error_footer(env); return GW_ERROR; diff --git a/src/gwion.c b/src/gwion.c index 487e7699..08ef77a8 100644 --- a/src/gwion.c +++ b/src/gwion.c @@ -192,7 +192,7 @@ ANN void env_error_footer(const Env env) { gwerr_secondary("in class", env->name, env->class_def->info->cdef->base.tag.loc); } -ANN static void env_xxx(const Env env, const loc_t pos, const m_str fmt, +ANN static void env_xxx(const Env env, const loc_t loc, const m_str fmt, va_list arg) { #ifndef __FUZZING__ va_list tmpa; @@ -201,12 +201,12 @@ ANN static void env_xxx(const Env env, const loc_t pos, const m_str fmt, va_end(tmpa); char c[size + 1]; vsprintf(c, fmt, arg); - gwerr_basic(c, NULL, NULL, env->name, pos, 0); + gwerr_basic(c, NULL, NULL, env->name, loc, 0); env_error_footer(env); #endif } -ANN static void _env_warn(const Env env, const loc_t pos, const m_str fmt, +ANN static void _env_warn(const Env env, const loc_t loc, const m_str fmt, va_list arg) { #ifndef __FUZZING__ va_list tmpa; @@ -215,26 +215,26 @@ ANN static void _env_warn(const Env env, const loc_t pos, const m_str fmt, va_end(tmpa); char c[size + 1]; vsprintf(c, fmt, arg); - gwerr_warn(c, NULL, NULL, env->name, pos); + gwerr_warn(c, NULL, NULL, env->name, loc); env_error_footer(env); #endif } -ANN void env_warn(const Env env, const loc_t pos, const m_str fmt, ...) { +ANN void env_warn(const Env env, const loc_t loc, const m_str fmt, ...) { #ifndef __FUZZING__ va_list arg; va_start(arg, fmt); - _env_warn(env, pos, fmt, arg); + _env_warn(env, loc, fmt, arg); va_end(arg); #endif } -ANN void env_err(const Env env, const loc_t pos, const m_str fmt, ...) { +ANN void env_err(const Env env, const loc_t loc, const m_str fmt, ...) { if (env->context && env->context->error) return; #ifndef __FUZZING__ va_list arg; va_start(arg, fmt); - env_xxx(env, pos, fmt, arg); + env_xxx(env, loc, fmt, arg); va_end(arg); #endif env_set_error(env, true); diff --git a/src/import/import_checker.c b/src/import/import_checker.c index 87e5378e..0e69a6d2 100644 --- a/src/import/import_checker.c +++ b/src/import/import_checker.c @@ -17,14 +17,14 @@ struct td_checker { m_str str; - const loc_t pos; + const loc_t loc; }; struct AC { m_str str; Exp base; Exp exp; - loc_t pos; + loc_t loc; m_uint depth; }; @@ -50,7 +50,7 @@ ANN static Symbol __str2sym(const Gwion gwion, struct td_checker *tdc) { if (!isalnum(c) && c != '_') break; *tmp++ = *tdc->str++; } - if (tmp == buf) GWION_ERR_O(tdc->pos, "empty symbol"); + if (tmp == buf) GWION_ERR_O(tdc->loc, "empty symbol"); *tmp = '\0'; return gwisym(gwion, buf); } @@ -59,23 +59,23 @@ ANN static inline Symbol _str2sym(const Gwion gwion, struct td_checker *tdc, const m_str path) { const Symbol sym = __str2sym(gwion, tdc); if (*tdc->str && *tdc->str != ':') - GWION_ERR_O(tdc->pos, _("illegal character '%c' in path '%s'."), *tdc->str, + GWION_ERR_O(tdc->loc, _("illegal character '%c' in path '%s'."), *tdc->str, path) return sym; } /** convert a string to a symbol, with error checking **/ -ANN Symbol str2sym(const Gwion gwion, const m_str path, const loc_t pos) { - struct td_checker tdc = {.str = path, .pos = pos}; +ANN Symbol str2sym(const Gwion gwion, const m_str path, const loc_t loc) { + struct td_checker tdc = {.str = path, .loc = loc}; return _str2sym(gwion, &tdc, path); } -ANN m_bool str2var(const Gwion gwion, Var_Decl *vd, const m_str path, const loc_t pos) { - struct td_checker tdc = {.str = path, .pos = pos}; +ANN m_bool str2var(const Gwion gwion, Var_Decl *vd, const m_str path, const loc_t loc) { + struct td_checker tdc = {.str = path, .loc = loc}; DECL_OB(const Symbol, sym, = __str2sym(gwion, &tdc)); - struct AC ac = {.str = tdc.str, .pos = pos}; + struct AC ac = {.str = tdc.str, .loc = loc}; CHECK_BB(ac_run(gwion, &ac)); - vd->tag = MK_TAG(sym, pos); + vd->tag = MK_TAG(sym, loc); vd->value = NULL; return GW_OK; } @@ -85,13 +85,13 @@ ANN static bool _tmpl_list(const Gwion gwion, struct td_checker *tdc, Specialized_List *sl) { if(unlikely(!strncmp(tdc->str, "...", 3))) { tdc->str += 3; - Specialized spec = { .tag = MK_TAG(insert_symbol(gwion->st, "..."), tdc->pos) }; + Specialized spec = { .tag = MK_TAG(insert_symbol(gwion->st, "..."), tdc->loc) }; mp_vector_add(gwion->mp, sl, Specialized, spec); return true; } DECL_OO(const Symbol, sym, = __str2sym(gwion, tdc)); // TODO: handle traits? - Specialized spec = { .tag = MK_TAG(sym, tdc->pos) }; + Specialized spec = { .tag = MK_TAG(sym, tdc->loc) }; mp_vector_add(gwion->mp, sl, Specialized, spec); if (*tdc->str == ',') { ++tdc->str; @@ -115,7 +115,7 @@ ANN static Specialized_List __tmpl_list(const Gwion gwion, } ANN m_bool check_typename_def(const Gwi gwi, ImportCK *ck) { - struct td_checker tdc = {.str = ck->name, .pos = gwi->loc}; + struct td_checker tdc = {.str = ck->name, .loc = gwi->loc}; if (!(ck->sym = _str2sym(gwi->gwion, &tdc, tdc.str))) return GW_ERROR; Specialized_List sl = __tmpl_list(gwi->gwion, &tdc); if (sl == SPEC_ERROR) return GW_ERROR; @@ -132,14 +132,14 @@ ANN bool str2tl(const Gwion gwion, struct td_checker *tdc, TmplArg_List *tl) { .type = tmplarg_td, .d = { .td = _str2td(gwion, tdc) } }; - if (!targ.d.td) GWION_ERR_B(tdc->pos, "invalid types"); + if (!targ.d.td) GWION_ERR_B(tdc->loc, "invalid types"); mp_vector_add(gwion->mp, tl, TmplArg, targ); if (*tdc->str == ',') { ++tdc->str; if (!str2tl(gwion, tdc, tl)) return false; } - } else GWION_ERR_B(tdc->pos, "invalid character in template list"); + } else GWION_ERR_B(tdc->loc, "invalid character in template list"); return true; } @@ -147,7 +147,7 @@ ANN static TmplArg_List td_tmpl(const Gwion gwion, struct td_checker *tdc) { if (*tdc->str != ':') return NULL; // GW_PASS ++tdc->str; if (*tdc->str != '[') { - GWION_ERR(tdc->pos, "invalid character"); + GWION_ERR(tdc->loc, "invalid character"); return (TmplArg_List)GW_ERROR; } ++tdc->str; @@ -158,7 +158,7 @@ ANN static TmplArg_List td_tmpl(const Gwion gwion, struct td_checker *tdc) { } if (tdc->str[0] != ']') { free_tmplarg_list(gwion->mp, tl); - GWION_ERR(tdc->pos, "unfinished template"); + GWION_ERR(tdc->loc, "unfinished template"); return (TmplArg_List)GW_ERROR; } ++tdc->str; @@ -212,15 +212,15 @@ ANN static Type_Decl *str2td_fptr(const Gwion gwion, struct td_checker *tdc) { return NULL; } tdc->str += 2; - struct AC ac = {.str = tdc->str, .pos = tdc->pos}; + struct AC ac = {.str = tdc->str, .loc = tdc->loc}; if(ac_run(gwion, &ac) < 0 ) { if(tl) free_tmplarg_list(gwion->mp, tl); if(args) free_arg_list(gwion->mp, args); return NULL; } - Func_Base *fbase = new_func_base(gwion->mp, ret_td, insert_symbol(gwion->st, base), args, ae_flag_none, tdc->pos); + Func_Base *fbase = new_func_base(gwion->mp, ret_td, insert_symbol(gwion->st, base), args, ae_flag_none, tdc->loc); const Fptr_Def fptr = new_fptr_def(gwion->mp, fbase); - Type_Decl *td = new_type_decl(gwion->mp, insert_symbol(gwion->st, base), tdc->pos); + Type_Decl *td = new_type_decl(gwion->mp, insert_symbol(gwion->st, base), tdc->loc); td->fptr = fptr; td->types = tl; if (ac.depth) td->array = mk_array(gwion->mp, &ac); @@ -238,7 +238,7 @@ ANN static Type_Decl *_str2td(const Gwion gwion, struct td_checker *tdc) { } DECL_OO(const Symbol, sym, = __str2sym(gwion, tdc)); TmplArg_List tl = td_tmpl(gwion, tdc); - struct AC ac = {.str = tdc->str, .pos = tdc->pos}; + struct AC ac = {.str = tdc->str, .loc = tdc->loc}; CHECK_BO(ac_run(gwion, &ac)); tdc->str = ac.str; if (tl == (TmplArg_List)GW_ERROR) return NULL; @@ -252,7 +252,7 @@ ANN static Type_Decl *_str2td(const Gwion gwion, struct td_checker *tdc) { return NULL; } } - Type_Decl *td = new_type_decl(gwion->mp, sym, tdc->pos); + Type_Decl *td = new_type_decl(gwion->mp, sym, tdc->loc); td->next = next; td->types = tl; td->option = option; @@ -261,18 +261,18 @@ ANN static Type_Decl *_str2td(const Gwion gwion, struct td_checker *tdc) { return td; } -ANN Type_Decl *str2td(const Gwion gwion, const m_str str, const loc_t pos) { - struct td_checker tdc = {.str = str, .pos = pos}; +ANN Type_Decl *str2td(const Gwion gwion, const m_str str, const loc_t loc) { + struct td_checker tdc = {.str = str, .loc = loc}; DECL_OO(Type_Decl *, td, = _str2td(gwion, &tdc)); if(*tdc.str) { free_type_decl(gwion->mp, td); - GWION_ERR_O(pos, "excedental character '%c' in '%s'", *tdc.str, str); + GWION_ERR_O(loc, "excedental character '%c' in '%s'", *tdc.str, str); } return td; } -ANN Type str2type(const Gwion gwion, const m_str str, const loc_t pos) { - DECL_OO(Type_Decl *, td, = str2td(gwion, str, pos)); +ANN Type str2type(const Gwion gwion, const m_str str, const loc_t loc) { + DECL_OO(Type_Decl *, td, = str2td(gwion, str, loc)); const Type t = known_type(gwion->env, td); free_type_decl(gwion->mp, td); return t; @@ -338,7 +338,7 @@ ANN static m_bool td_info_run(const Env env, struct td_info *info) { } ANEW ANN m_str type2str(const Gwion gwion, const Type t, - const loc_t pos NUSED) { + const loc_t loc NUSED) { GwText text; text_init(&text, gwion->mp); td_fullname(gwion->env, &text, t); @@ -346,7 +346,7 @@ ANEW ANN m_str type2str(const Gwion gwion, const Type t, } ANEW ANN m_str tl2str(const Gwion gwion, const TmplArg_List tl, - const loc_t pos NUSED) { + const loc_t loc NUSED) { struct GwfmtState ls = {.minimize=true, .ppa = gwion->ppa}; text_init(&ls.text, gwion->mp); Gwfmt l = {.mp = gwion->mp, .st = gwion->st, .ls = &ls, .line = 1, .last = cht_nl }; @@ -357,18 +357,18 @@ ANEW ANN m_str tl2str(const Gwion gwion, const TmplArg_List tl, ANN static inline m_bool ac_finish(const Gwion gwion, const struct AC *ac) { if (*ac->str == ']') return GW_OK; - GWION_ERR_B(ac->pos, "unfinished array"); + GWION_ERR_B(ac->loc, "unfinished array"); } ANN static inline m_bool ac_num(const Gwion gwion, const struct AC *ac, const m_int num) { if (num >= 0) return GW_OK; - GWION_ERR_B(ac->pos, "negative array dimension") + GWION_ERR_B(ac->loc, "negative array dimension") } ANN static inline m_bool ac_exp(const Gwion gwion, const struct AC *ac) { if (!ac->depth || ac->base) return GW_OK; - GWION_ERR_B(ac->pos, "malformed array [][...]") + GWION_ERR_B(ac->loc, "malformed array [][...]") } ANN static void ac_add_exp(struct AC *ac, const Exp exp) { @@ -380,7 +380,7 @@ ANN static void ac_add_exp(struct AC *ac, const Exp exp) { ANN static inline m_bool ac_noexp(const Gwion gwion, struct AC *ac) { if (!ac->exp) return GW_OK; - GWION_ERR_B(ac->pos, "malformed array [...][]") + GWION_ERR_B(ac->loc, "malformed array [...][]") } ANN static m_bool _ac_run(const Gwion gwion, struct AC *const ac) { @@ -390,7 +390,7 @@ ANN static m_bool _ac_run(const Gwion gwion, struct AC *const ac) { if (str != ac->str) { CHECK_BB(ac_num(gwion, ac, num)); CHECK_BB(ac_exp(gwion, ac)); - const Exp exp = new_prim_int(gwion->mp, num, ac->pos); + const Exp exp = new_prim_int(gwion->mp, num, ac->loc); // set type: otherwise could fail at emit time exp->type = gwion->type[et_int]; ac_add_exp(ac, exp); diff --git a/src/import/import_oper.c b/src/import/import_oper.c index 9d0be4f1..b88e6f67 100644 --- a/src/import/import_oper.c +++ b/src/import/import_oper.c @@ -40,7 +40,7 @@ static int import_op(const Gwi gwi, struct OperCK *const op, const f_instr f) { .ret = ret, .func = &opfunc, .data = (uintptr_t)f, - .pos = gwi->loc, + .loc = gwi->loc, .op = op->sym}; const m_bool b = add_op(gwi->gwion, &opi); op->effect.ptr = NULL; diff --git a/src/lib/array.c b/src/lib/array.c index f0cd2eee..d47954ba 100644 --- a/src/lib/array.c +++ b/src/lib/array.c @@ -130,10 +130,10 @@ static MFUN(vm_vector_random) { m_vector_get(array, idx, (void *)RETURN); } -#define ARRAY_OPCK(a, b, pos) \ +#define ARRAY_OPCK(a, b, loc) \ const Type l = array_base(a->type); \ const Type r = array_base(b->type); \ - if (isa(r, l) < 0) ERR_N(pos, _("array types do not match.")); + if (isa(r, l) < 0) ERR_N(loc, _("array types do not match.")); static OP_CHECK(opck_array_at) { const Exp_Binary *bin = (Exp_Binary *)data; @@ -161,15 +161,15 @@ ANN static inline bool shift_match(const Type base, const Type more) { } ANN static Type check_array_shift(const Env env, const Exp a, const Exp b, - const m_str str, const loc_t pos) { + const m_str str, const loc_t loc) { /* if(a->type == env->gwion->type[et_error] && b->type->array_depth > 1) return a->type;*/ - ARRAY_OPCK(a, b, pos) + ARRAY_OPCK(a, b, loc) const m_int diff = get_depth(a->type) - get_depth(b->type); if (diff >= 0 && diff <= 1) return a->type; - ERR_N(pos, "array depths do not match for '%s'.", str); + ERR_N(loc, "array depths do not match for '%s'.", str); } static OP_CHECK(opck_array_sl) { diff --git a/src/lib/closure.c b/src/lib/closure.c index 148f9e71..c2819902 100644 --- a/src/lib/closure.c +++ b/src/lib/closure.c @@ -561,7 +561,7 @@ static OP_CHECK(opck_op_impl) { .lhs = arg0->type, .rhs = arg1->type, .data = (uintptr_t)&self.d.exp_binary, - .pos = impl->e->pos}; + .loc = impl->e->pos}; vector_add(&env->scope->effects, 0); DECL_ON(const Type, t, = op_check(env, &opi)); CHECK_BN(isa(t, func->def->base->ret_type)); // error message? @@ -579,7 +579,7 @@ static OP_CHECK(opck_op_impl) { if (exists) { // improve me if (eff) { free_mp_vector(env->gwion->mp, struct ScopeEffect, eff); - ERR_N(impl->pos, + ERR_N(impl->loc, _("`{+Y}%s{0}` has effects not present in `{+G}%s{0}`\n"), s_name(impl->e->d.prim.d.var), func->name); } @@ -642,7 +642,7 @@ static OP_CHECK(opck_class_partial) { Exp_Call *call = (Exp_Call*)data; struct Op_Import opi = {.op = insert_symbol("@partial"), .lhs = actual_type(env->gwion, call->func->type), - .pos = call->func->pos, + .loc = call->func->pos, .data = (uintptr_t)data}; return op_check(env, &opi); } diff --git a/src/lib/deep_equal.c b/src/lib/deep_equal.c index e13bcde9..cbae67b7 100644 --- a/src/lib/deep_equal.c +++ b/src/lib/deep_equal.c @@ -20,7 +20,7 @@ static OP_##ACTION(op##action##_deep_##_t##_any) { \ .rhs = bin->rhs->type, \ .op = insert_symbol(_data->gwion->st, #_op), \ .data = (m_uint)bin, \ - .pos = exp_self(bin)->pos \ + .loc = exp_self(bin)->pos \ }; \ return op_##_name(_data, &opi); \ } @@ -121,7 +121,7 @@ static OP_CHECK(opck_deep_equal) { .lhs = bin->lhs->type, .rhs = bin->rhs->type, .data = (uintptr_t)bin, - .pos = exp_self(bin)->pos}; + .loc = exp_self(bin)->pos}; if(op_get(env, &opi)) { bin->op = base_op; return op_check(env, &opi); diff --git a/src/lib/object_op.c b/src/lib/object_op.c index a359f0e6..9c0b4ded 100644 --- a/src/lib/object_op.c +++ b/src/lib/object_op.c @@ -171,7 +171,7 @@ ANN static inline void emit_struct_data(const Emitter emit, const Value v, } ANN m_bool not_from_owner_class(const Env env, const Type t, const Value v, - const loc_t pos); + const loc_t loc); ANN static inline Value get_value(const Env env, const Exp_Dot *member, const Type t) { diff --git a/src/parse/check.c b/src/parse/check.c index 245b21ca..f76c17f1 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -23,12 +23,12 @@ ANN m_bool check_class_def(const Env env, const Class_Def class_def); ANN static Type check_internal(const Env env, const Symbol sym, const Exp e, const Type t) { - struct Implicit imp = {.e = e, .t = t, .pos = e->pos}; + struct Implicit imp = {.e = e, .t = t, .loc = e->pos}; struct Op_Import opi = {.op = sym, .lhs = e->type, .rhs = t, .data = (uintptr_t)&imp, - .pos = e->pos}; + .loc = e->pos}; return op_check(env, &opi); } @@ -155,9 +155,9 @@ ANN m_bool ensure_traverse(const Env env, const Type t) { } ANN static inline m_bool inferable(const Env env, const Type t, - const loc_t pos) { + const loc_t loc) { if (!tflag(t, tflag_infer)) return GW_OK; - ERR_B(pos, _("can't infer type.")) + ERR_B(loc, _("can't infer type.")) } ANN Type check_exp_decl(const Env env, Exp_Decl *const decl) { @@ -251,7 +251,7 @@ ANN static Type check_prim_range(const Env env, Range **data) { const Symbol sym = insert_symbol("[:]"); struct Op_Import opi = {.op = sym, .lhs = e->type, - .pos = e->pos, + .loc = e->pos, .data = (uintptr_t)prim_exp(data)}; return op_check(env, &opi); } @@ -275,10 +275,10 @@ ANN static Type check_prim_dict(const Env env, Exp *data) { } ANN m_bool not_from_owner_class(const Env env, const Type t, const Value v, - const loc_t pos) { + const loc_t loc) { if (!v->from->owner_class || isa(t, v->from->owner_class) < 0) { if(!is_class(env->gwion, v->type)) - ERR_B(pos, _("'%s' from owner namespace '%s' used in '%s'."), v->name, + ERR_B(loc, _("'%s' from owner namespace '%s' used in '%s'."), v->name, v->from->owner ? v->from->owner->name : "?", t->name) } return GW_OK; @@ -356,7 +356,7 @@ ANN static Type check_dot(const Env env, const Exp_Dot *member) { struct Op_Import opi = {.op = insert_symbol("."), .lhs = member->base->type, .data = (uintptr_t)member, - .pos = exp_self(member)->pos}; + .loc = exp_self(member)->pos}; env_weight(env, 1); return op_check(env, &opi); } @@ -512,7 +512,7 @@ ANN Type check_array_access(const Env env, const Array_Sub array) { struct Op_Import opi = {.op = sym, .lhs = array->exp->type, .rhs = array->type, - .pos = array->exp->pos, + .loc = array->exp->pos, .data = (uintptr_t)array}; return op_check(env, &opi); } @@ -534,7 +534,7 @@ static ANN Type check_exp_slice(const Env env, const Exp_Slice *range) { struct Op_Import opi = {.op = sym, .lhs = e->type, .rhs = range->base->type, - .pos = e->pos, + .loc = e->pos, .data = (uintptr_t)exp_self(range)}; return op_check(env, &opi); } @@ -698,11 +698,11 @@ ANN static void print_current_args(Exp e) { ANN2(1) static void function_alternative(const Env env, const Type t, const Exp args, - const loc_t pos) { + const loc_t loc) { if (env->context && env->context->error) // needed for ufcs return; gwerr_basic("Argument type mismatch", "call site", - "valid alternatives:", env->name, pos, 0); + "valid alternatives:", env->name, loc, 0); const bool is_closure = isa(t, env->gwion->type[et_closure]) < 0; Func up = is_closure ? t->info->func : closure_def(t)->base->func; @@ -956,7 +956,7 @@ ANN m_bool func_check(const Env env, Exp_Call *const exp) { const Exp e = exp_self(exp); struct Op_Import opi = {.op = insert_symbol("@func_check"), .rhs = t, - .pos = e->pos, + .loc = e->pos, .data = (uintptr_t)e}; if(op_get(env, &opi)) CHECK_OB(op_check(env, &opi)); @@ -964,11 +964,11 @@ ANN m_bool func_check(const Env env, Exp_Call *const exp) { return e->type != env->gwion->type[et_error] ? GW_OK : GW_ERROR; } -ANN void call_add_effect(const Env env, const Func func, const loc_t pos) { +ANN void call_add_effect(const Env env, const Func func, const loc_t loc) { if (func != env->func && func->def->base->effects.ptr) { const Vector v = &func->def->base->effects; for (m_uint i = 0; i < vector_size(v); i++) - env_add_effect(env, (Symbol)vector_at(v, i), pos); + env_add_effect(env, (Symbol)vector_at(v, i), loc); } } @@ -984,7 +984,7 @@ ANN Type call_type(const Env env, Exp_Call *const exp) { struct Op_Import opi = {.op = insert_symbol("call_type"), .rhs = actual_type(env->gwion, exp->func->type), .data = (uintptr_t)exp, - .pos = exp_self(exp)->pos}; + .loc = exp_self(exp)->pos}; return op_check(env, &opi); } @@ -1100,7 +1100,7 @@ ANN static Type check_exp_binary(const Env env, const Exp_Binary *bin) { .lhs = bin->lhs->type, .rhs = bin->rhs->type, .data = (uintptr_t)bin, - .pos = exp_self(bin)->pos}; + .loc = exp_self(bin)->pos}; exp_setuse(bin->lhs, 1); exp_setuse(bin->rhs, 1); const Type ret = op_check(env, &opi); @@ -1116,7 +1116,7 @@ ANN static Type check_exp_cast(const Env env, const Exp_Cast *cast) { .lhs = t, .rhs = exp_self(cast)->type, .data = (uintptr_t)cast, - .pos = exp_self(cast)->pos}; + .loc = exp_self(cast)->pos}; return op_check(env, &opi); } @@ -1124,7 +1124,7 @@ ANN static Type check_exp_post(const Env env, const Exp_Postfix *post) { struct Op_Import opi = {.op = post->op, .lhs = check_exp(env, post->exp), .data = (uintptr_t)post, - .pos = exp_self(post)->pos}; + .loc = exp_self(post)->pos}; CHECK_OO(opi.lhs); exp_setuse(post->exp, 1); const Type t = op_check(env, &opi); @@ -1134,10 +1134,10 @@ ANN static Type check_exp_post(const Env env, const Exp_Postfix *post) { } ANN static m_bool predefined_call(const Env env, const Type t, - const loc_t pos) { + const loc_t loc) { const m_str str = - tl2str(env->gwion, t->info->func->def->base->tmpl->call, pos); - env_err(env, pos, _("Type '%s' has '%s' as pre-defined types."), t->name, + tl2str(env->gwion, t->info->func->def->base->tmpl->call, loc); + env_err(env, loc, _("Type '%s' has '%s' as pre-defined types."), t->name, str); free_mstr(env->gwion->mp, str); if (tflag(t, tflag_typedef)) { @@ -1194,7 +1194,7 @@ ANN static Type check_exp_call(const Env env, Exp_Call *exp) { CHECK_OO(check_exp(env, exp->func)); struct Op_Import opi = {.op = insert_symbol("@partial"), .lhs = exp->func->type, - .pos = exp->func->pos, + .loc = exp->func->pos, .data = (uintptr_t)exp}; return op_check(env, &opi); } @@ -1224,7 +1224,7 @@ ANN static Type check_exp_unary(const Env env, const Exp_Unary *unary) { struct Op_Import opi = {.op = unary->op, .rhs = rhs, .data = (uintptr_t)unary, - .pos = exp_self(unary)->pos}; + .loc = exp_self(unary)->pos}; DECL_OO(const Type, ret, = op_check(env, &opi)); return ret; } @@ -1234,7 +1234,7 @@ ANN static Type _flow(const Env env, const Exp e, const m_bool b) { struct Op_Import opi = { .op = insert_symbol(b ? "@conditional" : "@unconditional"), .rhs = type, - .pos = e->pos, + .loc = e->pos, .data = (uintptr_t)e}; return op_check(env, &opi); } @@ -1414,7 +1414,7 @@ ANN static m_bool check_each_idx(const Env env, const Exp exp, struct EachIdx_ * .lhs = exp->type, .op = insert_symbol("@each_idx"), .data = (m_uint)exp, - .pos = idx->var.tag.loc + .loc = idx->var.tag.loc }; DECL_OB(const Type, t, = op_check(env, &opi)); check_idx(env, t, idx); @@ -1428,7 +1428,7 @@ ANN static Type check_each_val(const Env env, const Exp exp) { .lhs = exp->type, .op = insert_symbol("@each_val"), .data = (m_uint)exp, - .pos = exp->pos + .loc = exp->pos }; return op_check(env, &opi); } @@ -1560,7 +1560,7 @@ ANN Symbol case_basic_op(const Env env, const Type base, const Exp e) { .lhs = base, .rhs = e->type, .data = (uintptr_t)NULL, - .pos = e->pos}; + .loc = e->pos}; return op_get(env, &opi) ? insert_symbol("==") : insert_symbol("?="); @@ -1676,7 +1676,7 @@ ANN static inline m_bool check_stmt_try(const restrict Env env, const Stmt_Try s for (m_uint i = 0; i < v->len; i++) { struct ScopeEffect *eff = mp_vector_at(v, struct ScopeEffect, i); bool found = find_handler(stmt->handler, eff->sym); - if (!found) env_add_effect(env, eff->sym, eff->pos); + if (!found) env_add_effect(env, eff->sym, eff->loc); } free_mp_vector(env->gwion->mp, struct ScopeEffect, v); } @@ -2286,7 +2286,7 @@ ANN static inline void check_unhandled(const Env env) { struct ScopeEffect *eff = mp_vector_at(w, struct ScopeEffect, j); if(s_name(eff->sym)[0] == '!') continue; - gwerr_secondary("Unhandled effect", env->name, eff->pos); + gwerr_secondary("Unhandled effect", env->name, eff->loc); env_set_error(env, false); } free_mp_vector(env->gwion->mp, struct ScopeEffect, w); diff --git a/src/parse/operator.c b/src/parse/operator.c index e672faa9..f08875e0 100644 --- a/src/parse/operator.c +++ b/src/parse/operator.c @@ -129,7 +129,7 @@ ANN static m_bool _op_exist(const struct OpChecker *ock, const Nspc n) { if (idx == -1 || !operator_find2((Vector)&VVAL(ock->map, idx), ock->opi->lhs, ock->opi->rhs)) return GW_OK; - env_err(ock->env, ock->opi->pos, + env_err(ock->env, ock->opi->loc, _("operator '%s', for type '%s' and '%s' already imported"), s_name(ock->opi->op), type_name(ock->opi->lhs), type_name(ock->opi->rhs)); @@ -229,8 +229,8 @@ ANN bool tmpl_match(const Env env, const struct Op_Import *opi, } ANN static void op_tmpl_set(const Gwion gwion, TmplArg_List tl, - const Type t, const loc_t pos, const uint32_t idx) { - TmplArg arg = {.type = tmplarg_td, .d = { .td = type2td(gwion, t, pos)}}; + const Type t, const loc_t loc, const uint32_t idx) { + TmplArg arg = {.type = tmplarg_td, .d = { .td = type2td(gwion, t, loc)}}; mp_vector_set(tl, TmplArg, idx, arg); } @@ -241,11 +241,11 @@ ANN static Type op_def(const Env env, struct Op_Import *const opi, tmpl_fdef->base->tmpl->call = new_mp_vector(env->gwion->mp, TmplArg, fdef->base->tmpl->list->len); // we need to check op def for type, maybe if (opi->lhs) { - op_tmpl_set(env->gwion, tmpl_fdef->base->tmpl->call, opi->lhs, opi->pos, 0); + op_tmpl_set(env->gwion, tmpl_fdef->base->tmpl->call, opi->lhs, opi->loc, 0); if(opi->rhs) - op_tmpl_set(env->gwion, tmpl_fdef->base->tmpl->call, opi->rhs, opi->pos, 1); + op_tmpl_set(env->gwion, tmpl_fdef->base->tmpl->call, opi->rhs, opi->loc, 1); } else - op_tmpl_set(env->gwion, tmpl_fdef->base->tmpl->call, opi->rhs, opi->pos, 0); + op_tmpl_set(env->gwion, tmpl_fdef->base->tmpl->call, opi->rhs, opi->loc, 0); if (traverse_func_def(env, tmpl_fdef) < 0) { if (!tmpl_fdef->base->func) func_def_cleaner(env->gwion, tmpl_fdef); return NULL; @@ -304,7 +304,7 @@ ANN static Type chuck_rewrite(const Env env, const struct Op_Import *opi, const c[len - 2] = '\0'; // are there other expressions that would need such a test? if(!strcmp(c, "$")) { - env_err(env, opi->pos, "can't rewrite cast operations"); + env_err(env, opi->loc, "can't rewrite cast operations"); env_set_error(env, true); return NULL; } @@ -314,7 +314,7 @@ ANN static Type chuck_rewrite(const Env env, const struct Op_Import *opi, const const Type ret = check_exp(env, exp_self(base)); if(ret) return ret; env_set_error(env, false); - env_warn(env, opi->pos, _("during rewriting operation")); + env_warn(env, opi->loc, _("during rewriting operation")); env_set_error(env, true); return NULL; } @@ -337,7 +337,7 @@ ANN Type op_check(const Env env, struct Op_Import *opi) { if (ock.effect.ptr) { const Vector base = &ock.effect; for (m_uint i = 0; i < vector_size(base); i++) - env_add_effect(env, (Symbol)vector_at(base, i), opi->pos); + env_add_effect(env, (Symbol)vector_at(base, i), opi->loc); } opi->nspc = nspc; return ret; @@ -352,7 +352,7 @@ ANN Type op_check(const Env env, struct Op_Import *opi) { return opi->rhs; if (!strcmp(op, "@func_check")) return NULL; if(!strcmp(op, "=>") && !strcmp(opi->rhs->name, "@now")) { - gwerr_basic(_("no match found for operator"), "expected duration", "did you try converting to `dur`?", env->name, opi->pos, 0); + gwerr_basic(_("no match found for operator"), "expected duration", "did you try converting to `dur`?", env->name, opi->loc, 0); env_set_error(env, true); } else if (strcmp(op, "@implicit")) { if (opi->rhs && opi->lhs && is_func(env->gwion, opi->rhs)) { // is_callable @@ -360,7 +360,7 @@ ANN Type op_check(const Env env, struct Op_Import *opi) { if (len > 2 && !strcmp(op + len - 2, "=>")) return chuck_rewrite(env, opi, op, len); } - env_err(env, opi->pos, _("%s %s %s: no match found for operator"), + env_err(env, opi->loc, _("%s %s %s: no match found for operator"), type_name(opi->lhs), s_name(opi->op), type_name(opi->rhs)); } return NULL; diff --git a/src/parse/scan0.c b/src/parse/scan0.c index 9626183e..04a7a482 100644 --- a/src/parse/scan0.c +++ b/src/parse/scan0.c @@ -328,11 +328,11 @@ ANN static Type cdef_parent(const Env env, const Class_Def cdef) { return t; } -ANN static m_bool find_traits(const Env env, ID_List traits, const loc_t pos) { +ANN static m_bool find_traits(const Env env, ID_List traits, const loc_t loc) { for(uint32_t i = 0; i < traits->len; i++) { Symbol xid = *mp_vector_at(traits, Symbol, i); if (!nspc_lookup_trait1(env->curr, xid)) { - gwerr_basic(_("can't find trait"), NULL, NULL, env->name, pos, 0); + gwerr_basic(_("can't find trait"), NULL, NULL, env->name, loc, 0); did_you_mean_trait(env->curr, s_name(xid)); env_set_error(env, true); return GW_ERROR; diff --git a/src/parse/scan1.c b/src/parse/scan1.c index 9afa62a4..242748d6 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -38,14 +38,14 @@ ANN static inline m_bool ensure_scan1(const Env env, const Type t) { return envset_run(&es, t); } -ANN static m_bool check_global(const Env env, const Type t, const loc_t pos) { +ANN static m_bool check_global(const Env env, const Type t, const loc_t loc) { const ValueFrom *from = t->info->value->from; if(from->owner_class && isa(from->owner_class, env->class_def) > 0) return true; if(from_global_nspc(env, from->owner) || (from->owner_class && type_global(env, from->owner_class))) return true; - gwerr_basic("can't use non-global type in a global class", NULL, NULL, env->name, pos, 0); + gwerr_basic("can't use non-global type in a global class", NULL, NULL, env->name, loc, 0); gwerr_secondary_from("not declared global", from); const ValueFrom *ownerFrom = env->class_def->info->value->from; gwerr_secondary_from("is global", ownerFrom); @@ -780,15 +780,15 @@ ANN static Type scan1_get_parent(const Env env, const Type_Def tdef) { } ANN static m_bool scan1_parent(const Env env, const Class_Def cdef) { - const loc_t pos = cdef->base.ext->tag.loc; + const loc_t loc = cdef->base.ext->tag.loc; if (cdef->base.ext->array && cdef->base.ext->array->exp) CHECK_BB(scan1_exp(env, cdef->base.ext->array->exp)); DECL_OB(const Type, parent, = scan1_get_parent(env, &cdef->base)); if (isa(parent, env->gwion->type[et_object]) < 0 && // !(tflag(cdef->base.type, tflag_cdef) || tflag(cdef->base.type, tflag_udef))) !(tflag(cdef->base.type, tflag_cdef) || tflag(cdef->base.type, tflag_union))) - ERR_B(pos, _("cannot extend primitive type '%s'"), parent->name) - if (type_ref(parent)) ERR_B(pos, _("can't use ref type in class extend")) + ERR_B(loc, _("cannot extend primitive type '%s'"), parent->name) + if (type_ref(parent)) ERR_B(loc, _("can't use ref type in class extend")) return GW_OK; } diff --git a/src/parse/scan2.c b/src/parse/scan2.c index 295ffd39..d940404b 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -402,7 +402,7 @@ ANN static m_bool scan2_func_def_op(const Env env, const Func_Def f) { struct Op_Func opfunc = {.ck = strcmp(str, "@implicit") ? 0 : opck_usr_implicit}; struct Op_Import opi = {.ret = f->base->ret_type, - .pos = f->base->tag.loc, + .loc = f->base->tag.loc, .data = (uintptr_t)f->base->func, .func = &opfunc}; func_operator(f, &opi); diff --git a/src/parse/template.c b/src/parse/template.c index 310a0f60..e27f9f57 100644 --- a/src/parse/template.c +++ b/src/parse/template.c @@ -166,9 +166,9 @@ static ANN bool is_single_variadic(const MP_Vector *v) { return !strcmp(s_name(spec->tag.sym), "..."); } -ANN2(1,2) m_bool check_tmpl(const Env env, const TmplArg_List tl, const Specialized_List sl, const loc_t pos, const bool is_spread) { +ANN2(1,2) m_bool check_tmpl(const Env env, const TmplArg_List tl, const Specialized_List sl, const loc_t loc, const bool is_spread) { if (!sl || sl->len > tl->len || (tl->len != sl->len && !is_spread)) - ERR_B(pos, "invalid template type number"); + ERR_B(loc, "invalid template type number"); for (uint32_t i = 0; i < sl->len; i++) { TmplArg *arg = mp_vector_at(tl, TmplArg, i); Specialized *spec = mp_vector_at(sl, Specialized, i); @@ -195,7 +195,7 @@ ANN2(1,2) m_bool check_tmpl(const Env env, const TmplArg_List tl, const Speciali } next->next = last; } - ERR_B(pos, "template type argument mismatch. expected %s", + ERR_B(loc, "template type argument mismatch. expected %s", spec->td ? "constant" : "type"); } @@ -203,19 +203,19 @@ ANN2(1,2) m_bool check_tmpl(const Env env, const TmplArg_List tl, const Speciali if(spec->traits) { Symbol missing = miss_traits(t, spec); if (missing) { - ERR_B(pos, "does not implement requested trait '{/}%s{0}'", + ERR_B(loc, "does not implement requested trait '{/}%s{0}'", s_name(missing)); } } } else { if(!spec->td) { - ERR_B(pos, "template const argument mismatch. expected %s", + ERR_B(loc, "template const argument mismatch. expected %s", spec->td ? "constant" : "type"); } DECL_OB(const Type, t, = known_type(env, spec->td)); CHECK_OB(check_exp(env, arg->d.exp)); if(isa(arg->d.exp->type, t) < 0) - ERR_B(pos, "invalid type %s for template argument. expected %s", + ERR_B(loc, "invalid type %s for template argument. expected %s", arg->d.exp->type->name, t->name); } } @@ -250,7 +250,7 @@ ANN static Type _scan_type(const Env env, const Type t, Type_Decl *td) { struct Op_Import opi = {.op = insert_symbol("class"), .lhs = t, .data = (uintptr_t)&ts, - .pos = td->tag.loc}; + .loc = td->tag.loc}; return op_check(env, &opi); } else if (td->types) return maybe_func(env, t, td); -- 2.43.0