-Subproject commit 0ba7b3b15cbdfab20b35b8a84dcebded0501c054
+Subproject commit 56d8b92b822a2d2891e4d4cea954936538698a28
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
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
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;
}
// 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 {
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
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));
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));
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;
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);
}
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);
#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);
}
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;
};
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);
.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)));
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);
}
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);
.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);
.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);
.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);
}
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) {
*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;
}
*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;
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);
}
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);
}
#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
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;
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;
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;
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);
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;
};
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);
}
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;
}
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;
}
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;
.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;
}
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;
}
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;
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);
}
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;
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;
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;
}
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);
}
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 };
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) {
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) {
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);
.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;
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;
}
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) {
.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?
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);
}
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);
}
.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); \
}
.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);
}
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) {
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);
}
}
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) {
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);
}
}
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;
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);
}
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);
}
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);
}
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;
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));
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);
}
}
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);
}
.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);
.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);
}
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);
}
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)) {
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);
}
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;
}
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);
}
.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);
.lhs = exp->type,
.op = insert_symbol("@each_val"),
.data = (m_uint)exp,
- .pos = exp->pos
+ .loc = exp->pos
};
return op_check(env, &opi);
}
.lhs = base,
.rhs = e->type,
.data = (uintptr_t)NULL,
- .pos = e->pos};
+ .loc = e->pos};
return op_get(env, &opi)
? insert_symbol("==")
: insert_symbol("?=");
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);
}
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);
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));
}
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);
}
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;
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;
}
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;
}
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;
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
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;
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;
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);
}
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;
}
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);
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);
}
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");
}
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);
}
}
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);