-Subproject commit aa633ad736df71d78d94346d79f0ed61bf5ef0d3
+Subproject commit 3095d6563e507c752ad0010ac384ca487573b0fe
-Subproject commit 04994e9dbc6acf0ff93c78c772a73ce4aab56b0e
+Subproject commit b873e18a508dcb46d9d0e3e6335cd262e3a9d6f8
ANN static m_bool emit_symbol(const Emitter emit, const Exp_Primary *prim) {
if (!prim->value) // assume it's an operator
- ERR_B(exp_self(prim)->pos, "missing value for operator");
+ ERR_B(exp_self(prim)->loc, "missing value for operator");
return _emit_symbol(emit, &prim->d.var);
}
assert(e);
struct Op_Import opi = {.op = sym,
.lhs = e->type,
- .loc = e->pos,
+ .loc = e->loc,
.data = (uintptr_t)prim_exp(data)};
CHECK_BB(op_emit(emit, &opi));
emit_local_exp(emit, prim_exp(data));
Exp e = *data;
const Type key = e->type;
const Type val = e->next->type;
- const Type t = dict_type(emit->gwion, key, val, e->pos);
+ const Type t = dict_type(emit->gwion, key, val, e->loc);
const Instr init = emit_add_instr(emit, dict_ctor_alt);
const Exp next = e->next;
e->next = NULL;
struct Op_Import opi = {.op = sym,
.lhs = e->type,
.rhs = range->base->type,
- .loc = e->pos,
+ .loc = e->loc,
.data = (uintptr_t)exp_self(range)};
CHECK_BB(op_emit(emit, &opi));
emit_local_exp(emit, exp_self(range));
ANN /*static */ m_bool emit_exp_decl(const Emitter emit, Exp_Decl *const decl) {
const Type t = decl->type;
if(decl->args && !strncmp(decl->args->type->name, "partial:", 8))
- ERR_B(decl->args->pos, "unresolved partial");
+ ERR_B(decl->args->loc, "unresolved partial");
CHECK_BB(ensure_emit(emit, t));
const m_bool global = GET_FLAG(decl->var.td, global);
const m_uint scope =
struct Op_Import opi = {.op = insert_symbol("call_type"),
.rhs = t,
.data = (uintptr_t)call,
- .loc = exp_self(call)->pos};
+ .loc = exp_self(call)->loc};
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,
- .loc = exp_self(bin)->pos,
+ .loc = exp_self(bin)->loc,
.data = (uintptr_t)bin};
return op_emit(emit, &opi);
}
struct Exp_ lhs = {
.exp_type = ae_exp_primary,
.type = arg->type,
- .pos = arg->var.td->tag.loc,
+ .loc = arg->var.td->tag.loc,
.d = {
.prim = { .prim_type = ae_prim_id }
}
struct Exp_ rhs = {
.exp_type = ae_exp_primary,
.type = me->emit->gwion->type[et_bool],
- .pos = arg->var.td->tag.loc,
+ .loc = arg->var.td->tag.loc,
.d = {
.prim = { .prim_type = ae_prim_id }
}
struct Exp_ bin = {
.exp_type = ae_exp_binary,
.type = arg->type,
- .pos = arg->var.td->tag.loc,
+ .loc = arg->var.td->tag.loc,
.d = {
.exp_binary = {
.lhs = &lhs,
if(!f->code && f != emit->env->func)
CHECK_BB(emit_ensure_func(emit, f));
push_spork_code(emit, sp->is_spork ? SPORK_FUNC_PREFIX : FORK_CODE_PREFIX,
- sp->exp->pos);
+ sp->exp->loc);
return emit_exp_call1(emit, f, f->def->base->ret_type->size, false);
}
.code = unary->unary_type == unary_code ? unary->code : NULL,
.type = exp_self(unary)->type,
.captures = unary->captures,
- .loc = exp_self(unary)->pos,
+ .loc = exp_self(unary)->loc,
.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, . loc = from->pos};
+ const struct Implicit imp = { .e=from, .t=to, . loc = from->loc};
// no pos
struct Op_Import opi = {.op = insert_symbol("@implicit"),
.lhs = from->type,
.rhs = to,
.data = (m_uint)&imp,
- .loc = from->pos
+ .loc = from->loc
};
return op_emit(emit, &opi);
}
struct Op_Import opi = {
.op = insert_symbol(b ? "@conditional" : "@unconditional"),
.rhs = e->type,
- .loc = e->pos,
+ .loc = e->loc,
.data = (uintptr_t)e};
CHECK_BO(op_emit(emit, &opi));
return (Instr)vector_back(&emit->code->instr);
ANN2(1) /*static */ m_bool emit_exp(const Emitter emit, /* const */ Exp e) {
Exp exp = e;
do {
- if (emit->info->debug && emit->status.line < e->pos.first.line) {
+ if (emit->info->debug && emit->status.line < e->loc.first.line) {
const Instr instr = emit_add_instr(emit, DebugLine);
- instr->m_val = emit->status.line = e->pos.first.line;
+ instr->m_val = emit->status.line = e->loc.first.line;
}
CHECK_BB(emit_exp_func[exp->exp_type](emit, &exp->d));
if (exp->cast_to) CHECK_BB(emit_implicit_cast(emit, exp, exp->cast_to));
e->exp_type == ae_exp_decl && GET_FLAG(e->d.exp_decl.var.td, late) &&
exp_getuse(e) && !exp_getvar(e) &&
GET_FLAG(e->d.exp_decl.var.vd.value, late))
- emit_fast_except(emit, e->d.exp_decl.var.vd.value->from, e->pos);
+ emit_fast_except(emit, e->d.exp_decl.var.vd.value->from, e->loc);
} while ((exp = exp->next));
return GW_OK;
}
CHECK_BB(emit_exp1(emit, base));
CHECK_BB(emit_exp1(emit, e));
const Exp_Binary bin = {.lhs = base, .rhs = e, .op = op};
- struct Exp_ ebin = { .d = {.exp_binary = bin}, .exp_type = ae_exp_binary, .pos = e->pos };
+ struct Exp_ ebin = { .d = {.exp_binary = bin}, .exp_type = ae_exp_binary, .loc = e->loc };
struct Op_Import opi = {.op = op,
.lhs = base->type,
.rhs = e->type,
.data = (uintptr_t)&ebin.d.exp_binary,
- .loc = e->pos};
+ .loc = e->loc};
CHECK_BB(op_emit(emit, &opi));
const Instr instr = emit_add_instr(emit, BranchEqInt);
vector_add(v, (vtype)instr);
emit_regmove(emit, SZ_INT);
CHECK_BO(emit_exp(emit, e));
const Exp_Binary bin = {.lhs = base, .rhs = e, .op = insert_symbol("?=")};
- struct Exp_ ebin = {.d = {.exp_binary = bin}, .pos = e->pos };
+ struct Exp_ ebin = {.d = {.exp_binary = bin}, .loc = e->loc };
struct Op_Import opi = {.op = insert_symbol("?="),
.lhs = base->type,
.rhs = e->type,
.data = (uintptr_t)&ebin.d.exp_binary,
- .loc = e->pos};
+ .loc = e->loc};
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,
- .loc = exp_self(member)->pos};
+ .loc = exp_self(member)->loc};
return op_emit(emit, &opi);
}
static OP_CHECK(opck_bit_access) {
Array_Sub array = data;
const Exp e = array->exp;
- if(e->next) ERR_N(e->next->pos, "too many expressions for bit access");
+ if(e->next) ERR_N(e->next->loc, "too many expressions for bit access");
if(is_prim_int(e)) {
m_int idx = e->d.prim.d.gwint.num;
if(idx < 0 || idx >= (m_int)array->type->size * CHAR_BIT)
- ERR_N(e->pos, "bit access out of bound");
+ ERR_N(e->loc, "bit access out of bound");
}
return env->gwion->type[et_bool];
}
const Exp_Binary *bin = (Exp_Binary *)data;
CHECK_NN(opck_const_rhs(env, data));
if (bin->lhs->type != env->gwion->type[et_error]) {
- ARRAY_OPCK(bin->lhs, bin->rhs, exp_self(bin)->pos)
+ ARRAY_OPCK(bin->lhs, bin->rhs, exp_self(bin)->loc)
if (bin->lhs->type->array_depth != bin->rhs->type->array_depth)
- ERR_N(exp_self(bin)->pos, _("array depths do not match."));
+ ERR_N(exp_self(bin)->loc, _("array depths do not match."));
}
if (bin->rhs->exp_type == ae_exp_decl) {
Type_Decl *td = bin->rhs->d.exp_decl.var.td;
if (td->array && td->array->exp)
- ERR_N(exp_self(bin)->pos,
+ ERR_N(exp_self(bin)->loc,
_("do not provide array for 'xxx => declaration'."));
SET_FLAG(bin->rhs->d.exp_decl.var.vd.value, late);
}
static OP_CHECK(opck_array_sl) {
const Exp_Binary *bin = (Exp_Binary *)data;
- return check_array_shift(env, bin->lhs, bin->rhs, "<<", exp_self(bin)->pos);
+ return check_array_shift(env, bin->lhs, bin->rhs, "<<", exp_self(bin)->loc);
}
static OP_CHECK(opck_array_sr) {
const Exp_Binary *bin = (Exp_Binary *)data;
- return check_array_shift(env, bin->rhs, bin->lhs, ">>", exp_self(bin)->pos);
+ return check_array_shift(env, bin->rhs, bin->lhs, ">>", exp_self(bin)->loc);
}
ANN static inline m_bool emit_array_shift(const Emitter emit,
}
parent = parent->info->parent;
}
- struct Exp_ e = { .type = l, .pos = cast->exp->pos };
+ struct Exp_ e = { .type = l, .loc = cast->exp->loc };
CHECK_BN(check_implicit(env, &e, r));
return t;
}
while ((e = e->next));
const Type t = get_array_type(array->type);
if (t->array_depth >= array->depth)
- return array_type(env, array_base(t), t->array_depth - array->depth, array->exp->pos);
+ return array_type(env, array_base(t), t->array_depth - array->depth, array->exp->loc);
const Exp curr = take_exp(array->exp, t->array_depth);
struct Array_Sub_ next = {curr->next, array_base(t),
DECL_OO(const Type, t, = array_base_simple(base));
if(!tflag(base, tflag_ref)) {
const m_uint depth = base->array_depth - 1;
- return depth ? array_type(env, t, depth, exp->pos) : t;
+ return depth ? array_type(env, t, depth, exp->loc) : t;
}
const Type inner = (Type)vector_front(&base->info->tuple->contains);
const Type refbase = array_base_simple(inner);
const m_uint depth = inner->array_depth - 1;
- return depth ? array_type(env, refbase, depth, exp->pos) : refbase;
+ return depth ? array_type(env, refbase, depth, exp->loc) : refbase;
}
// rewrite me
const Exp exp = (const Exp) data;
DECL_ON(const Type, base, = foreach_type(env, exp));
CHECK_BN(ensure_traverse(env, base));
- return ref_type(env->gwion, base, exp->pos);
+ return ref_type(env->gwion, base, exp->loc);
}
static OP_EMIT(opem_array_each) {
} else {
if(args)
gwerr_warn("array is empty", "no need to provide a lambda",
- NULL, env->name, td->array->exp->pos);
+ NULL, env->name, td->array->exp->loc);
}
return GW_OK;
}
ANN static bool fptr_effects(const Env env, struct FptrInfo *info) {
if (!info->lhs->def->base->effects.ptr) return true;
if (!info->rhs->def->base->effects.ptr) {
- gwerr_secondary("too many effects", env->name, info->exp->pos);
+ gwerr_secondary("too many effects", env->name, info->exp->loc);
return false;
}
const Vector lhs = &info->lhs->def->base->effects;
const Vector rhs = &info->rhs->def->base->effects;
for (m_uint i = 0; i < vector_size(lhs); i++) {
if (vector_find(rhs, vector_at(lhs, 0)) == -1) {
- gwerr_secondary("effect not handled", env->name, info->exp->pos);
+ gwerr_secondary("effect not handled", env->name, info->exp->loc);
return false;
}
}
// if(!info->lhs->def->base->tmpl != !info->rhs->def->base->tmpl)
// return GW_ERROR;
if(!info->lhs)
- ERR_B(info->exp->pos,
+ ERR_B(info->exp->loc,
_("can't resolve operator"))
return GW_OK;
}
Arg_List bases = fdef->base->args;
Arg_List args = l->def->base->args;
if (mp_vector_len(bases) != mp_vector_len(args))
- ERR_B(exp_self(l)->pos, _("argument number does not match for lambda"))
+ ERR_B(exp_self(l)->loc, _("argument number does not match for lambda"))
if(l->def->captures) {
// here move to arguments
Arg *base = mp_vector_at(bases, Arg, i);
Arg *arg = mp_vector_at(args, Arg, i);
DECL_OB(const Type, arg_type, = known_type(env, base->var.td));
- arg->var.td = type2td(env->gwion, arg_type, exp_self(l)->pos);
+ arg->var.td = type2td(env->gwion, arg_type, exp_self(l)->loc);
}
}
DECL_OB(const Type, ret_type, = known_type(env, fdef->base->td));
- l->def->base->td = type2td(env->gwion, ret_type, exp_self(l)->pos);
+ l->def->base->td = type2td(env->gwion, ret_type, exp_self(l)->loc);
/*Type*/ owner = fdef->base->func->value_ref->from->owner_class;
Upvalues upvalues = {
if(info->exp->type->info->func) {
CHECK_BB(fptr_check(env, info));
if (!(info->exp->type = fptr_type(env, info)))
- ERR_B(info->exp->pos, _("no match found"))
+ ERR_B(info->exp->loc, _("no match found"))
return GW_OK;
}
Exp_Lambda *l = &info->exp->d.exp_lambda;
// we'll only deal with auto fptr declaration
if (bin->rhs->exp_type != ae_exp_decl &&
bin->rhs->d.exp_decl.var.td->tag.sym != insert_symbol("auto"))
- ERR_N(bin->lhs->pos, "invalid {G+}function{0} {+}:=>{0} {+G}function{0} assignment");
+ ERR_N(bin->lhs->loc, "invalid {G+}function{0} {+}:=>{0} {+G}function{0} assignment");
if (bin->lhs->exp_type == ae_exp_td)
- ERR_N(bin->lhs->pos, "can't use {/}type decl expressions{0} in auto function pointer declarations");
+ ERR_N(bin->lhs->loc, "can't use {/}type decl expressions{0} in auto function pointer declarations");
// if(!bin->lhs->type->info->func)
if(!bin->lhs->type->info->func || !strncmp(bin->lhs->type->name, "partial:", 8))
return partial2auto(env, bin);
Func_Base *const fbase =
cpy_func_base(env->gwion->mp, bin->lhs->type->info->func->def->base);
const Fptr_Def fptr_def = new_fptr_def(env->gwion->mp, fbase);
- char name[13 + strlen(env->curr->name) + num_digit(bin->rhs->pos.first.line) +
- num_digit(bin->rhs->pos.first.column)];
- sprintf(name, "generated@%s@%u:%u", env->curr->name, bin->rhs->pos.first.line,
- bin->rhs->pos.first.column);
+ char name[13 + strlen(env->curr->name) + num_digit(bin->rhs->loc.first.line) +
+ num_digit(bin->rhs->loc.first.column)];
+ sprintf(name, "generated@%s@%u:%u", env->curr->name, bin->rhs->loc.first.line,
+ bin->rhs->loc.first.column);
fptr_def->base->tag.sym = insert_symbol(name);
const m_bool ret = traverse_fptr_def(env, fptr_def);
const Type t = fptr_def->cdef->base.type;
}
ANN Type check_op_call(const Env env, Exp_Call *const exp) {
- CHECK_BO(op_call_narg(env, exp->args, exp->func->pos));
+ CHECK_BO(op_call_narg(env, exp->args, exp->func->loc));
const Exp base = exp_self(exp);
const Exp op_exp = exp->func;
base->exp_type = ae_exp_binary;
static OP_CHECK(opck_op_impl) {
struct Implicit *impl = (struct Implicit *)data;
const Func func = closure_def(impl->t)->base->func;
- CHECK_BN(op_impl_narg(env, func->def, impl->e->pos));
+ CHECK_BN(op_impl_narg(env, func->def, impl->e->loc));
op_impl_ensure_types(env, func);
const Symbol lhs_sym = insert_symbol("@lhs");
const Symbol rhs_sym = insert_symbol("@rhs");
.d = {.prim = {.d = {.var = lhs_sym}, .prim_type = ae_prim_id}},
.exp_type = ae_exp_primary,
.type = arg0->type,
- .pos = arg0->var.td->tag.loc};
+ .loc = arg0->var.td->tag.loc};
struct Exp_ _rhs = {
.d = {.prim = {.d = {.var = rhs_sym}, .prim_type = ae_prim_id}},
.exp_type = ae_exp_primary,
.type = arg1->type,
- .pos = arg1->var.td->tag.loc};
- struct Exp_ self = {.pos = impl->e->pos};
+ .loc = arg1->var.td->tag.loc};
+ struct Exp_ self = {.loc = impl->e->loc};
self.d.exp_binary.lhs = &_lhs;
self.d.exp_binary.rhs = &_rhs;
self.d.exp_binary.op = impl->e->d.prim.d.var;
.lhs = arg0->type,
.rhs = arg1->type,
.data = (uintptr_t)&self.d.exp_binary,
- .loc = impl->e->pos};
+ .loc = impl->e->loc};
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?
MP_Vector *const eff = (MP_Vector*)vector_back(&env->scope->effects);
// if (eff && !check_effect_overload(eff, func))
-// ERR_N(impl->pos, _("`{+Y}%s{0}` has effects not present in `{+G}%s{0}`\n"),
+// 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);
const Value v = nspc_lookup_value0(opi.nspc, impl->e->d.prim.d.var);
if (v) {
larg0->var.vd.tag.sym = lhs_sym;
larg1->var.vd.tag.sym = rhs_sym;
Func_Base *base =
- new_func_base(env->gwion->mp, type2td(env->gwion, t, impl->e->pos),
- impl->e->d.prim.d.var, args, ae_flag_none, impl->e->pos);
+ new_func_base(env->gwion->mp, type2td(env->gwion, t, impl->e->loc),
+ impl->e->d.prim.d.var, args, ae_flag_none, impl->e->loc);
if (eff) {
for (m_uint i = 0; i < eff->len; i++) {
struct ScopeEffect *effect = mp_vector_at(eff, struct ScopeEffect, i);
free_mp_vector(env->gwion->mp, struct ScopeEffect, eff);
}
const Exp lhs =
- new_prim_id(env->gwion->mp, larg0->var.vd.tag.sym, impl->e->pos);
+ new_prim_id(env->gwion->mp, larg0->var.vd.tag.sym, impl->e->loc);
const Exp rhs =
- new_prim_id(env->gwion->mp, larg1->var.vd.tag.sym, impl->e->pos);
+ new_prim_id(env->gwion->mp, larg1->var.vd.tag.sym, impl->e->loc);
const Exp bin = new_exp_binary(env->gwion->mp, lhs, impl->e->d.prim.d.var,
- rhs, impl->e->pos);
+ rhs, impl->e->loc);
Stmt_List code = new_mp_vector(env->gwion->mp, struct Stmt_, 1);
mp_vector_set(code, struct Stmt_, 0,
((struct Stmt_) {
.stmt_type = ae_stmt_return, .d = { .stmt_exp = { .val = bin }},
- .loc = impl->e->pos
+ .loc = impl->e->loc
}));
const Func_Def def = new_func_def(env->gwion->mp, base, code);
def->base->tag.sym = impl->e->d.prim.d.var;
Exp_Call *call = (Exp_Call*)data;
struct Op_Import opi = {.op = insert_symbol("@partial"),
.lhs = actual_type(env->gwion, call->func->type),
- .loc = call->func->pos,
+ .loc = call->func->loc,
.data = (uintptr_t)data};
return op_check(env, &opi);
}
.rhs = bin->rhs->type, \
.op = insert_symbol(_data->gwion->st, #_op), \
.data = (m_uint)bin, \
- .loc = exp_self(bin)->pos \
+ .loc = exp_self(bin)->loc \
}; \
return op_##_name(_data, &opi); \
}
}, \
.type = _value->type, \
.exp_type = ae_exp_dot, \
- .pos = _exp->pos \
+ .loc = _exp->loc \
}
#define MK_BIN(_lhs, _rhs, _bin) \
} \
}, \
.exp_type = ae_exp_binary, \
- .pos = exp_self(_bin)->pos \
+ .loc = exp_self(_bin)->loc \
}
static bool deep_check(const Env env, const Exp_Binary *bin,
.lhs = bin->lhs->type,
.rhs = bin->rhs->type,
.data = (uintptr_t)bin,
- .loc = exp_self(bin)->pos};
+ .loc = exp_self(bin)->loc};
if(op_get(env, &opi)) {
bin->op = base_op;
return op_check(env, &opi);
const Type ret_type = check_exp(env, exp_self(bin));
env_set_error(env, false);
if(ret_type) return env->gwion->type[et_bool];
- ERR_N(exp_self(bin)->pos, "no deep operation for: {G+/}%s{0} {+}%s{0} {G+/}%s{0}",
+ ERR_N(exp_self(bin)->loc, "no deep operation for: {G+/}%s{0} {+}%s{0} {G+/}%s{0}",
bin->lhs->type->name, s_name(op), bin->rhs->type->name);
}
ANN static void deep_emit_init(const Emitter emit, struct DeepEmit *d, const m_int offset) {
char name[256];
- sprintf(name, "@%u:%u", d->exp->pos.first.line, d->exp->pos.first.column);
- d->val = new_value(emit->env, deep_type(emit->gwion, d->exp->type), name, d->exp->pos);
- d->tmp = new_prim_id(emit->gwion->mp, insert_symbol(emit->gwion->st, d->val->name), d->exp->pos);
+ sprintf(name, "@%u:%u", d->exp->loc.first.line, d->exp->loc.first.column);
+ d->val = new_value(emit->env, deep_type(emit->gwion, d->exp->type), name, d->exp->loc);
+ d->tmp = new_prim_id(emit->gwion->mp, insert_symbol(emit->gwion->st, d->val->name), d->exp->loc);
d->tmp->d.prim.value = d->val;
d->tmp->type = d->val->type;
check_deep_equal_exp(emit->env, d->exp, &d->vec);
const Type t = e->d.exp_binary.rhs->type;
HMapInfo *const hinfo = (HMapInfo*)t->nspc->class_data;
if(isa(args->type, hinfo->key) < 0 || args->next)
- ERR_N(e->pos, "dict.remove must be called with one Key argument");
+ ERR_N(e->loc, "dict.remove must be called with one Key argument");
return e->type = env->gwion->type[et_void];
}
static OP_CHECK(opck_basic_ctor) {
const Exp_Call *call = (Exp_Call *)data;
// change to *no know constructor for {+G}%s{0}*?
- ERR_N(call->func->pos, _("can't call a non-callable value"));
+ ERR_N(call->func->loc, _("can't call a non-callable value"));
}
/*
static OP_EMIT(opem_implicit_class) {
Exp_Binary * bin = (Exp_Binary *)data;
const Arg_List arg = bin->lhs->type->info->func->def->base->args;
if (!arg || arg->len > 1)
- ERR_N(exp_self(bin)->pos,
+ ERR_N(exp_self(bin)->loc,
_("Tick function take one and only one argument"));
if (isa(((Arg*)(arg->ptr))->type, env->gwion->type[et_float]) < 0)
- ERR_N(exp_self(bin)->pos,
+ ERR_N(exp_self(bin)->loc,
_("Tick functions argument must be of type float"));
if (isa(bin->lhs->type->info->func->def->base->ret_type,
env->gwion->type[et_float]) < 0)
- ERR_N(exp_self(bin)->pos, _("Tick function must return float"));
+ ERR_N(exp_self(bin)->loc, _("Tick function must return float"));
if (bin->lhs->type->info->func->value_ref->from->owner_class)
CHECK_BN(isa(bin->lhs->type->info->func->value_ref->from->owner_class,
bin->rhs->type));
static ID_CHECK(opck_this) {
if (!env->class_def)
- ERR_O(exp_self(prim)->pos,
+ ERR_O(exp_self(prim)->loc,
_("keyword 'this' can be used only inside class definition..."))
if(env->func) {
if (!vflag(env->func->value_ref, vflag_member))
- ERR_O(exp_self(prim)->pos,
+ ERR_O(exp_self(prim)->loc,
_("keyword 'this' cannot be used inside static functions..."))
if (!exp_getuse(exp_self(prim)) &&
!strcmp(s_name(env->func->def->base->tag.sym), "@gack"))
static ID_CHECK(opck_super) {
const Exp self = exp_self(prim);
if(!env->func || is_ctor(env->func->def))
- ERR_O(self->pos, "can't use 'super' outside of constructor");
+ ERR_O(self->loc, "can't use 'super' outside of constructor");
const Type parent = env->class_def->info->parent;
DECL_OO(const Value, v, = find_value(parent, insert_symbol("new")));
SET_FLAG(env->func, const);
const Env env = emit->env;
const Exp self = exp_self(prim);
if(!self->is_call)
- ERR_B(self->pos, "can only use 'super' as a function call");
+ ERR_B(self->loc, "can only use 'super' as a function call");
emit_regpushmem(emit, 0, SZ_INT, false);
emit_pushimm(emit, (m_uint)exp_self(prim)->type);
return GW_OK;
const Type to = known_type(env, cast->td);
if (isa(cast->exp->type, to) < 0) {
if (isa(to, cast->exp->type) > 0)
- ERR_N(exp_self(cast)->pos, _("can't upcast '%s' to '%s'"),
+ ERR_N(exp_self(cast)->loc, _("can't upcast '%s' to '%s'"),
cast->exp->type->name, to->name);
- ERR_N(exp_self(cast)->pos, _("can't cast '%s' to '%s'"),
+ ERR_N(exp_self(cast)->loc, _("can't cast '%s' to '%s'"),
cast->exp->type->name, to->name);
}
return exp_self(cast)->type;
if (!env->class_def || isa(env->class_def, value->from->owner_class) < 0) {
if (GET_FLAG(value, private)) {
gwerr_basic("invalid variable access", "is private", NULL, env->name,
- exp->pos, 0);
+ exp->loc, 0);
env_error_footer(env);
defined_here(value);
env_set_error(env, true);
return v->type;
}
}
- env_err(env, self->pos, _("class '%s' has no member '%s'"),
+ env_err(env, self->loc, _("class '%s' has no member '%s'"),
the_base->name, str);
if (member->base->type->nspc) did_you_mean_type(the_base, str);
return env->gwion->type[et_error];
}
- CHECK_BN(not_from_owner_class(env, the_base, value, self->pos));
+ CHECK_BN(not_from_owner_class(env, the_base, value, self->loc));
CHECK_BN(member_access(env, self, value));
if ((base_static && vflag(value, vflag_member)) ||
(value->from->owner_class != env->class_def && isa(value->from->owner_class, env->class_def) > 0))
- ERR_N(self->pos,
+ ERR_N(self->loc,
_("cannot access member '%s.%s' without object instance..."),
the_base->name, str);
if (GET_FLAG(value, const)) exp_setmeta(self, true);
if(isa(value->type, emit->gwion->type[et_object]) > 0 &&
!exp_getvar(exp_self(member)) &&
(GET_FLAG(value, static) || GET_FLAG(value, late)))
- emit_fast_except(emit, value->from, exp_self(member)->pos);
+ emit_fast_except(emit, value->from, exp_self(member)->loc);
return GW_OK;
}
if(f) {
// TODO: add call exp
struct Exp_ call = { .exp_type=ae_exp_call,
- .d={.exp_call={.args=imp->e}}, .pos=imp->e->pos, .type=f->value_ref->type };
+ .d={.exp_call={.args=imp->e}}, .pos=imp->e->loc, .type=f->value_ref->type };
struct Op_Import opi = { .op=insert_symbol("@func_check"),
- .rhs=f->value_ref->type, .pos=imp->e->pos, .data=(uintptr_t)&call };
+ .rhs=f->value_ref->type, .pos=imp->e->loc, .data=(uintptr_t)&call };
CHECK_NN(op_check(env, &opi));
}
}
const Exp_Binary *bin = (Exp_Binary *)data;
const m_str access = exp_access(bin->rhs);
if (access)
- ERR_N(bin->rhs->pos,
+ ERR_N(bin->rhs->loc,
_("cannot assign '%s' on types '%s' and '%s'.\n"
" ... (reason: --- right-side operand is %s.)"),
s_name(bin->op), bin->lhs->type->name, bin->rhs->type->name, access);
const Exp_Unary *unary = (Exp_Unary *)data;
const m_str access = exp_access(unary->exp);
if (access)
- ERR_N(unary->exp->pos,
+ ERR_N(unary->exp->loc,
_("unary operator '%s' cannot be used on %s data-types."),
s_name(unary->op), access);
exp_setvar(unary->exp, 1);
const Exp_Postfix *post = (Exp_Postfix *)data;
const m_str access = exp_access(post->exp);
if (access)
- ERR_N(post->exp->pos,
+ ERR_N(post->exp->loc,
_("post operator '%s' cannot be used on %s data-type."),
s_name(post->op), access);
exp_setvar(post->exp, 1);
if(unary->ctor.exp) {
const Exp self = exp_self(unary);
const Exp args = cpy_exp(env->gwion->mp, unary->ctor.exp);
- const Exp base = new_exp_unary2(env->gwion->mp, unary->op, unary->ctor.td, unary->ctor.exp, self->pos);
+ const Exp base = new_exp_unary2(env->gwion->mp, unary->op, unary->ctor.td, unary->ctor.exp, self->loc);
base->type = t;
- const Exp func = new_exp_dot(env->gwion->mp, base, insert_symbol("new"), self->pos);
+ const Exp func = new_exp_dot(env->gwion->mp, base, insert_symbol("new"), self->loc);
self->d.exp_call.func = func;
self->d.exp_call.args = args;
self->d.exp_call.tmpl = NULL;
ERR_N(unary->ctor.td->tag.loc, _("can't use 'new' on abstract type '%s'\n"),
t->name);
if (isa(t, env->gwion->type[et_object]) < 0)
- ERR_N(exp_self(unary)->pos, _("can't use 'new' on non-object types...\n"));
+ ERR_N(exp_self(unary)->loc, _("can't use 'new' on non-object types...\n"));
return t;
}
static OP_CHECK(opck_##ntype##_##name) { \
/*const*/ Exp_Binary *bin = (Exp_Binary *)data; \
const Type t = TYPE; \
- if (!exp_self(bin)->pos.first.line) return t; \
+ if (!exp_self(bin)->loc.first.line) return t; \
pre if (!funcl(bin->lhs) || !funcr(bin->rhs)) return t; \
const ctype num = \
bin->lhs->d.prim.d.lmember OP bin->rhs->d.prim.d.rmember; \
static OP_CHECK(opck_##ntype##_##name) { \
/*const*/ Exp_Binary *bin = (Exp_Binary *)data; \
const Type t = TYPE; \
- if (!exp_self(bin)->pos.first.line) return t; \
+ if (!exp_self(bin)->loc.first.line) return t; \
const bool rconst = funcr(bin->rhs); \
if(rconst && !bin->rhs->d.prim.d.retmember) \
- ERR_N(bin->rhs->pos, _("ZeroDivideException")); \
+ ERR_N(bin->rhs->loc, _("ZeroDivideException")); \
pre if (!funcl(bin->lhs) || !rconst) return t; \
const ctype num = \
bin->lhs->d.prim.d.lmember OP bin->rhs->d.prim.d.rmember; \
const Exp exp = (Exp)data;
const Range *range = exp->d.prim.d.range;
const Exp e = range->start ?: range->end;
- return array_type(env, e->type, 1, e->pos);
+ return array_type(env, e->type, 1, e->loc);
}
static OP_EMIT(opem_int_range) {
struct Implicit *impl = (struct Implicit *)data;
if(!env->context->error) {
gwerr_basic("Can't implicitely cast {G+}bool{0} to {G+}float{0}", NULL, "Did you forget a cast?",
- env->name, impl->e->pos, 0);
+ env->name, impl->e->loc, 0);
env_set_error(env, true);
}
return env->gwion->type[et_error];
static m_bool ref_access(const Env env, const Exp e) {
const m_str access = exp_access(e);
if (!access) return GW_OK;
- env_err(env, e->pos, _("operand is %s"), access);
+ env_err(env, e->loc, _("operand is %s"), access);
return GW_ERROR;
}
Stmt stmt = mp_vector_at(lhs->d.exp_unary.code, struct Stmt_, 0);
Stmt fst = mp_vector_at(stmt->d.stmt_flow.body->d.stmt_code.stmt_list, struct Stmt_, 0);
const Symbol chuck = insert_symbol(env->gwion->st, "=>");
- Exp next = new_exp_binary(env->gwion->mp, fst->d.stmt_exp.val, chuck, bin->rhs, bin->rhs->pos);
+ Exp next = new_exp_binary(env->gwion->mp, fst->d.stmt_exp.val, chuck, bin->rhs, bin->rhs->loc);
CHECK_BN(traverse_exp(env, next)); // how do we free it?
fst->d.stmt_exp.val = next;
const Exp exp = exp_self(bin);
Exp_Binary *bin = (Exp_Binary*)data;
MemPool mp = env->gwion->mp;
if(bin->lhs->exp_type == ae_exp_decl)
- ERR_N(bin->lhs->pos, _("can't use declaration to start sift `|>` operator"));
+ ERR_N(bin->lhs->loc, _("can't use declaration to start sift `|>` operator"));
const Symbol chuck = insert_symbol(env->gwion->st, "=>");
Exp exp = exp_self(data);
Exp func = cpy_exp(mp, exp);
- const Exp dot = new_exp_dot(mp, func->d.exp_binary.lhs, insert_symbol(env->gwion->st, "last"), func->pos);
- const Exp call = new_exp_call(mp, dot, NULL, func->pos);
+ const Exp dot = new_exp_dot(mp, func->d.exp_binary.lhs, insert_symbol(env->gwion->st, "last"), func->loc);
+ const Exp call = new_exp_call(mp, dot, NULL, func->loc);
func->d.exp_binary.lhs = call;
func->d.exp_binary.op = chuck;
CHECK_BN(traverse_exp(env, func));
- struct Stmt_ one = { .d = { .stmt_exp = { .val = func }}, .stmt_type = ae_stmt_exp, .loc = func->pos };
+ struct Stmt_ one = { .d = { .stmt_exp = { .val = func }}, .stmt_type = ae_stmt_exp, .loc = func->loc };
- Exp samp = new_prim_id(mp, insert_symbol(env->gwion->st, "samp"), func->pos);
- Exp _now = new_prim_id(mp, insert_symbol(env->gwion->st, "now"), func->pos);
- Exp time = new_exp_binary(mp, samp, chuck, _now, func->pos);
+ Exp samp = new_prim_id(mp, insert_symbol(env->gwion->st, "samp"), func->loc);
+ Exp _now = new_prim_id(mp, insert_symbol(env->gwion->st, "now"), func->loc);
+ Exp time = new_exp_binary(mp, samp, chuck, _now, func->loc);
CHECK_BN(traverse_exp(env, time));
- struct Stmt_ two = { .d = { .stmt_exp = { .val = time }}, .stmt_type = ae_stmt_exp, .loc = func->pos };
+ struct Stmt_ two = { .d = { .stmt_exp = { .val = time }}, .stmt_type = ae_stmt_exp, .loc = func->loc };
free_exp(mp, bin->lhs);
free_exp(mp, bin->rhs);
Stmt_List slist = new_mp_vector(mp, struct Stmt_, 2);
mp_vector_set(slist, struct Stmt_, 0, one);
mp_vector_set(slist, struct Stmt_, 1, two);
- const Stmt stmt = new_stmt_code(mp, slist, func->pos);
+ const Stmt stmt = new_stmt_code(mp, slist, func->loc);
- const Exp cond = new_prim_id(mp, insert_symbol(env->gwion->st, "true"), func->pos);
+ const Exp cond = new_prim_id(mp, insert_symbol(env->gwion->st, "true"), func->loc);
check_exp(env, cond);
const Stmt_List code = new_mp_vector(mp, struct Stmt_, 1);
.body = stmt
}
},
- .loc = func->pos
+ .loc = func->loc
}));
exp->exp_type = ae_exp_unary;
exp->d.exp_unary.unary_type = unary_code;
const Exp_Call *call = &e->d.exp_call;
const Exp exp = call->args;
if(!exp)
- ERR_N(e->pos, "Union.is() takes one argument of form id");
+ ERR_N(e->loc, "Union.is() takes one argument of form id");
if (exp->exp_type != ae_exp_primary || exp->d.prim.prim_type != ae_prim_id)
- ERR_N(exp->pos, "Union.is() argument must be of form id");
+ ERR_N(exp->loc, "Union.is() argument must be of form id");
const Type t = call->func->d.exp_dot.base->type;
const Value v = find_value(t, exp->d.prim.d.var);
if (!v)
- ERR_N(exp->pos, "'%s' has no member '%s'", t->name,
+ ERR_N(exp->loc, "'%s' has no member '%s'", t->name,
s_name(exp->d.prim.d.var));
const Map map = &t->nspc->info->value->map;
for (m_uint i = 0; i < map_size(map); ++i) {
e->d.exp_binary.lhs = cpy_exp(env->gwion->mp, exp_func);
e->d.exp_binary.lhs->d.exp_dot.xid =
insert_symbol(env->gwion->st, "index");
- // e->d.exp_binary.rhs = new_prim_int(env->gwion->mp, i+1, e->pos);
- e->d.exp_binary.rhs = new_prim_int(env->gwion->mp, i, e->pos);
+ // e->d.exp_binary.rhs = new_prim_int(env->gwion->mp, i+1, e->loc);
+ e->d.exp_binary.rhs = new_prim_int(env->gwion->mp, i, e->loc);
free_exp(env->gwion->mp, exp_func);
free_exp(env->gwion->mp, exp_args);
e->d.exp_binary.op = insert_symbol(env->gwion->st, "==");
Exp_Call *call = (Exp_Call *)data;
const Exp name = call->args;
if (!name)
- ERR_N(call->func->pos, "Union constructor takes one or two arguments, "
+ ERR_N(call->func->loc, "Union constructor takes one or two arguments, "
"'id' and 'value'");
if (name->exp_type != ae_exp_primary || name->d.prim.prim_type != ae_prim_id)
- ERR_N(call->func->pos, "Union constructor first argument me be an identifier");
+ ERR_N(call->func->loc, "Union constructor first argument me be an identifier");
const Exp val = name->next;
const Type base = call->func->d.exp_dot.base->type;
const Map map = &base->nspc->info->value->map;
name->d.prim.d.gwint.num = i;
name->type = env->gwion->type[et_int];
if(!val && v->type == env->gwion->type[et_none]) {
- const Exp e = new_prim_int(env->gwion->mp, SZ_INT, name->pos);
+ const Exp e = new_prim_int(env->gwion->mp, SZ_INT, name->loc);
e->next = name;
e->type = env->gwion->type[et_int];
- name->next = new_prim_int(env->gwion->mp, 0, name->pos);
+ name->next = new_prim_int(env->gwion->mp, 0, name->loc);
name->next->type = env->gwion->type[et_int];
call->args = e;
} else {
if (val->next)
- ERR_N(call->func->pos, "too many arguments for union constructor");
+ ERR_N(call->func->loc, "too many arguments for union constructor");
DECL_ON(const Type, t, = check_exp(env, val));
if (check_implicit(env, val, v->type) < 0) { // add implicit
- ERR_N(val->pos, "Invalid type '%s' for '%s', should be '%s'", t->name,
+ ERR_N(val->loc, "Invalid type '%s' for '%s', should be '%s'", t->name,
v->name, v->type->name);
}
- const Exp e = new_prim_int(env->gwion->mp, t->size + SZ_INT, val->pos);
+ const Exp e = new_prim_int(env->gwion->mp, t->size + SZ_INT, val->loc);
e->next = name;
e->type = env->gwion->type[et_int];
call->args = e;
return base;
}
}
- ERR_N(name->pos, "%s has no member %s\n", base->name, s_name(name->d.prim.d.var));
+ ERR_N(name->loc, "%s has no member %s\n", base->name, s_name(name->d.prim.d.var));
}
ANN GWION_IMPORT(union) {
sprintf(c, "TypedFork:[%s]", t->name);
const Type fork = env->gwion->type[et_fork];
UNSET_FLAG(fork, final);
- const Type typed = str2type(env->gwion, "TypedFork", exp_self(unary)->pos);
+ const Type typed = str2type(env->gwion, "TypedFork", exp_self(unary)->loc);
if (typed->nspc->offset == fork->nspc->offset)
typed->nspc->offset += t->size;
UNSET_FLAG(typed, final);
- const Type ret = str2type(env->gwion, c, exp_self(unary)->pos);
+ const Type ret = str2type(env->gwion, c, exp_self(unary)->loc);
SET_FLAG(typed, final);
SET_FLAG(fork, final);
return ret;
struct Value_ value = { .type = env->gwion->type[et_function]};
if(env->class_def)
set_vflag(&value, vflag_member);
- struct Func_Base_ fbase = { .tag=MK_TAG(insert_symbol("in spork"), exp_self(unary)->pos), .values = &upvalues, .fbflag = fbflag_lambda};
+ struct Func_Base_ fbase = { .tag=MK_TAG(insert_symbol("in spork"), exp_self(unary)->loc), .values = &upvalues, .fbflag = fbflag_lambda};
struct Func_Def_ fdef = { .base = &fbase};
struct Func_ func = { .name = "in spork", .def = &fdef, .value_ref = &value};
env->func = &func;
return env->gwion
->type[unary->op == insert_symbol("spork") ? et_shred : et_fork];
}
- ERR_O(exp_self(unary)->pos, _("only function calls can be sporked..."))
+ ERR_O(exp_self(unary)->loc, _("only function calls can be sporked..."))
}
static OP_EMIT(opem_spork) {
ANN static Type check_internal(const Env env, const Symbol sym, const Exp e,
const Type t) {
- struct Implicit imp = {.e = e, .t = t, .loc = e->pos};
+ struct Implicit imp = {.e = e, .t = t, .loc = e->loc};
struct Op_Import opi = {.op = sym,
.lhs = e->type,
.rhs = t,
.data = (uintptr_t)&imp,
- .loc = e->pos};
+ .loc = e->loc};
return op_check(env, &opi);
}
do {
if (is_decl) {
if(check_implicit(env, e, env->gwion->type[et_int]) < 0)
- ERR_B(array->exp->pos, _("invalid array declaration index type."))
+ ERR_B(array->exp->loc, _("invalid array declaration index type."))
}
} while (++depth && (e = e->next));
if (depth != array->depth)
- ERR_B(array->exp->pos, _("invalid array access expression."))
+ ERR_B(array->exp->loc, _("invalid array access expression."))
return GW_OK;
}
// suggested fix: rewrite int 2 as float 2.0"
char sec[16 + strlen(e->type->name)];
sprintf(sec, "got `{+/}%s{0}`", e->type->name);
- gwerr_secondary(sec, env->name, e->pos);
+ gwerr_secondary(sec, env->name, e->loc);
return GW_ERROR;
}
ANN static inline Type prim_array_match(const Env env, Exp e) {
const Type type = e->type;
bool err = false;
- const loc_t loc = e->pos;
+ const loc_t loc = e->loc;
do
if (check_collection(env, type, e, loc) < 0) err = true;
while ((e = e->next));
if (range->end) CHECK_OB(check_exp(env, range->end));
if (range->start && range->end) {
if (isa(range->end->type, range->start->type) < 0)
- ERR_B(range->start->pos, _("range types do not match"))
+ ERR_B(range->start->loc, _("range types do not match"))
}
return GW_OK;
}
const Symbol sym = insert_symbol("[:]");
struct Op_Import opi = {.op = sym,
.lhs = e->type,
- .loc = e->pos,
+ .loc = e->loc,
.data = (uintptr_t)prim_exp(data)};
return op_check(env, &opi);
}
const Type key = base->type;
const Type val = base->next->type;
bool err = false;
- const loc_t loc = base->pos;
+ const loc_t loc = base->loc;
Exp e = base;
env_weight(env, 1);
do {
e = e->next;
if (check_collection(env, val, e, loc) < 0) err = true;
} while ((e = e->next));
- if (!err) return dict_type(env->gwion, key, val, base->pos);
+ if (!err) return dict_type(env->gwion, key, val, loc);
env_set_error(env, true); return NULL;
}
struct Op_Import opi = {.op = insert_symbol("."),
.lhs = member->base->type,
.data = (uintptr_t)member,
- .loc = exp_self(member)->pos};
+ .loc = exp_self(member)->loc};
env_weight(env, 1);
return op_check(env, &opi);
}
ANN static m_bool check_upvalue(const Env env, const Exp_Primary *prim, const Value v) {
if(not_upvalue(env, v))
return GW_OK;
- gwerr_basic(_("value not in lambda scope"), NULL, NULL, env->name, exp_self(prim)->pos, 4242);
+ gwerr_basic(_("value not in lambda scope"), NULL, NULL, env->name, exp_self(prim)->loc, 4242);
declared_here(v);
gw_err("{-}hint:{0} try adding it to capture list");
env_set_error(env, true);
struct Op_Import opi = {.op = sym,
.lhs = array->exp->type,
.rhs = array->type,
- .loc = array->exp->pos,
+ .loc = array->exp->loc,
.data = (uintptr_t)array};
return op_check(env, &opi);
}
struct Op_Import opi = {.op = sym,
.lhs = e->type,
.rhs = range->base->type,
- .loc = e->pos,
+ .loc = e->loc,
.data = (uintptr_t)exp_self(range)};
return op_check(env, &opi);
}
}
((Exp_Call *)func)->tmpl = NULL;
assert(exp_self(func));
- ERR_O(exp_self(func)->pos,
+ ERR_O(exp_self(func)->loc,
_("function is a template for which automatic type inference is not fully implemented"));
}
}
}
if (args_number < len) //TODO: free tmplarg_list
- ERR_O(exp->func->pos, _("not able to infer types for template call."))
+ ERR_O(exp->func->loc, _("not able to infer types for template call."))
if(spread) {
Exp e = exp->args;
while(e) {
TmplArg targ = {
.type = tmplarg_td,
- .d = { .td = type2td(env->gwion, e->type, e->pos) }
+ .d = { .td = type2td(env->gwion, e->type, e->loc) }
};
mp_vector_add(env->gwion->mp, &tl, TmplArg, targ);
e = e->next;
Exp e = exp->args;
for(uint32_t i = 0; i < (args ? args->len : 0); i++) {
if(!e)
- ERR_O(exp_self(exp)->pos, _("argument number does not match for lambda"))
+ ERR_O(exp_self(exp)->loc, _("argument number does not match for lambda"))
Arg *arg = mp_vector_at(args, Arg, i);
arg->type = e->type;
if(is_class(env->gwion, arg->type))
e = e->next;
}
if(e)
- ERR_O(exp_self(exp)->pos, _("argument number does not match for lambda"))
+ ERR_O(exp_self(exp)->loc, _("argument number does not match for lambda"))
Upvalues upvalues = { .values = env->curr->info->value};
if(env->func && env->func->def->base->values)
upvalues.parent = env->func->def->base->values;
exp->func->is_call = true;
CHECK_OB(check_exp(env, exp->func));
if (exp->func->exp_type == ae_exp_decl)
- ERR_B(exp->func->pos, _("Can't call late function pointer at declaration "
+ ERR_B(exp->func->loc, _("Can't call late function pointer at declaration "
"site. did you meant to use `:=>`?"))
const Type t = actual_type(env->gwion, exp->func->type);
if (is_func(env->gwion, t) && exp->func->exp_type == ae_exp_dot && // is_callable
const Exp e = exp_self(exp);
struct Op_Import opi = {.op = insert_symbol("@func_check"),
.rhs = t,
- .loc = e->pos,
+ .loc = e->loc,
.data = (uintptr_t)e};
if(op_get(env, &opi))
CHECK_OB(op_check(env, &opi));
struct Op_Import opi = {.op = insert_symbol("call_type"),
.rhs = actual_type(env->gwion, exp->func->type),
.data = (uintptr_t)exp,
- .loc = exp_self(exp)->pos};
+ .loc = exp_self(exp)->loc};
return op_check(env, &opi);
}
const Func func) {
const Value v = func->value_ref;
exp->func->type = v->type;
- call_add_effect(env, func, exp->func->pos);
+ call_add_effect(env, func, exp->func->loc);
if(func->def->base->ret_type != env->gwion->type[et_auto])
return func->def->base->ret_type;
if(tflag(v->from->owner_class, tflag_struct))
!t->info->func ||
!GET_FLAG(t->info->func->def->base, abstract) ||
!is_static_call(env->gwion, e)) return t;
- env_err(env, e->pos, "making a static call to an abstract function");
+ env_err(env, e->loc, "making a static call to an abstract function");
declared_here(t->info->value);
return NULL;
}
if(t) return t;
}
}
- function_alternative(env, exp->func->type, exp->args, exp->func->pos);
+ function_alternative(env, exp->func->type, exp->args, exp->func->loc);
return NULL;
}
.lhs = bin->lhs->type,
.rhs = bin->rhs->type,
.data = (uintptr_t)bin,
- .loc = exp_self(bin)->pos};
+ .loc = exp_self(bin)->loc};
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,
- .loc = exp_self(cast)->pos};
+ .loc = exp_self(cast)->loc};
return op_check(env, &opi);
}
struct Op_Import opi = {.op = post->op,
.lhs = check_exp(env, post->exp),
.data = (uintptr_t)post,
- .loc = exp_self(post)->pos};
+ .loc = exp_self(post)->loc};
CHECK_OO(opi.lhs);
exp_setuse(post->exp, 1);
const Type t = op_check(env, &opi);
ANN static Type check_exp_call_tmpl(const Env env, Exp_Call *exp, const Type t) {
if (exp->args) CHECK_OO(check_exp(env, exp->args));
if (!t->info->func->def->base->tmpl)
- ERR_O(exp_self(exp)->pos, _("template call of non-template function."))
+ ERR_O(exp_self(exp)->loc, _("template call of non-template function."))
if (t->info->func->def->base->tmpl->call) {
if (env->func == t->info->func) {
exp->func->type = env->func->value_ref->type;
} else {
if(tl_match(env, t->info->func->def->base->tmpl->call, exp->tmpl->call))
return check_exp_call1(env, exp);
- CHECK_BO(predefined_call(env, t, exp_self(exp)->pos));
+ CHECK_BO(predefined_call(env, t, exp_self(exp)->loc));
}
}
const Value v = type_value(env->gwion, t);
CHECK_OO(check_exp(env, exp->func));
struct Op_Import opi = {.op = insert_symbol("@partial"),
.lhs = exp->func->type,
- .loc = exp->func->pos,
+ .loc = exp->func->loc,
.data = (uintptr_t)exp};
return op_check(env, &opi);
}
struct Op_Import opi = {.op = unary->op,
.rhs = rhs,
.data = (uintptr_t)unary,
- .loc = exp_self(unary)->pos};
+ .loc = exp_self(unary)->loc};
DECL_OO(const Type, ret, = op_check(env, &opi));
return ret;
}
struct Op_Import opi = {
.op = insert_symbol(b ? "@conditional" : "@unconditional"),
.rhs = type,
- .loc = e->pos,
+ .loc = e->loc,
.data = (uintptr_t)e};
return op_check(env, &opi);
}
exp_setmeta(exp_self(exp_if), meta);
const Type ret = find_common_anc(if_exp, else_exp);
if (!ret)
- ERR_O(exp_self(exp_if)->pos,
+ ERR_O(exp_self(exp_if)->loc,
_("incompatible types '%s' and '%s' in if expression..."),
if_exp->name, else_exp->name)
if (isa(if_exp, else_exp) < 0)
- ERR_O(exp_self(exp_if)->pos, _("condition type '%s' does not match '%s'"),
+ ERR_O(exp_self(exp_if)->loc, _("condition type '%s' does not match '%s'"),
cond->name, ret->name)
exp_setuse(exp_if->cond, true);
exp_setuse(exp_if->if_exp, true);
ANN m_bool check_type_def(const Env env, const Type_Def tdef) {
if (tdef->when) {
set_tflag(tdef->type, tflag_contract);
- struct Var_Decl_ decl = { .tag = MK_TAG(insert_symbol("self"), tdef->when->pos) };
+ struct Var_Decl_ decl = { .tag = MK_TAG(insert_symbol("self"), tdef->when->loc) };
Type_Decl *td = cpy_type_decl(env->gwion->mp, tdef->ext);
Arg_List args = new_mp_vector(env->gwion->mp, Arg, 1);
mp_vector_set(args, Arg, 0, ((Arg) { .var = MK_VAR(td, decl)}));
insert_symbol("@implicit"), args, ae_flag_none, tdef->tag.loc);
set_fbflag(fb, fbflag_op);
const Exp helper = new_prim_id(env->gwion->mp, insert_symbol("@predicate"),
- tdef->when->pos);
+ tdef->when->loc);
const Exp when = tdef->when;
tdef->when = NULL;
when->next = helper;
mp_vector_set(code, struct Stmt_, 0,
((struct Stmt_) {
.stmt_type = ae_stmt_exp, .d = { .stmt_exp = { .val = when }},
- .loc = when->pos
+ .loc = when->loc
}));
mp_vector_set(code, struct Stmt_, 1,
((struct Stmt_) {
.stmt_type = ae_stmt_exp,
- .loc = when->pos
+ .loc = when->loc
}));
const Func_Def fdef = new_func_def(env->gwion->mp, fb, code);
tdef->when_def = fdef;
char explain[strlen(when->type->name) + 20];
sprintf(explain, "found `{/+}%s{0}`", when->type->name);
gwerr_basic("Invalid `{/+}when{0}` predicate expression type", explain,
- "use `{/+}bool{0}`", env->name, when->pos, 0);
+ "use `{/+}bool{0}`", env->name, when->loc, 0);
char from[strlen(tdef->type->name) + 39];
sprintf(from, "in `{/+}%s{0}` definition", tdef->type->name);
gwerr_secondary(from, env->name, tdef->tag.loc);
}
// we handle the return after, so that we don't get *cant' use implicit
// casting while defining it*
- const Exp ret_id = new_prim_id(env->gwion->mp, insert_symbol("self"), when->pos);
+ const Exp ret_id = new_prim_id(env->gwion->mp, insert_symbol("self"), when->loc);
ret_id->d.prim.value = new_value(env, tdef->type, "self", tdef->tag.loc);
struct Stmt_ ret = {
.stmt_type = ae_stmt_return, .d = { .stmt_exp = { .val = ret_id }},
- .loc = when->pos
+ .loc = when->loc
};
mp_vector_set(fdef->d.code, struct Stmt_, 1, ret);
ret_id->type = tdef->type;
ANN static Type check_exp_td(const Env env, Type_Decl **td) {
DECL_OO(const Type, t, = known_type(env, *td));
if(t == env->gwion->type[et_class])
- ERR_O(exp_self(td)->pos, "can't use {G+}Class{0} in type decl expression");
+ ERR_O(exp_self(td)->loc, "can't use {G+}Class{0} in type decl expression");
if (!is_func(env->gwion, t)) return type_class(env->gwion, t);
return t;
}
.lhs = exp->type,
.op = insert_symbol("@each_val"),
.data = (m_uint)exp,
- .loc = exp->pos
+ .loc = exp->loc
};
return op_check(env, &opi);
}
sprintf(explain, "expected `{/+}int{0}`, got `{/+}%s{0}`", e->type->name);
gwerr_basic(_("invalid repeat condition type"), explain,
_("use an integer or cast to int if possible"), env->name,
- e->pos, 0);
+ e->loc, 0);
env_set_error(env, true);
return GW_ERROR;
}
}
if (isa(ret_type, env->func->def->base->ret_type) > 0) return GW_OK;
if (tflag(ret_type, tflag_noret))
- ERR_B(stmt->val->pos, _("Can't use type `{+G}%s{+G}` for return"),
+ ERR_B(stmt->val->loc, _("Can't use type `{+G}%s{+G}` for return"),
ret_type->name);
if (stmt->val) {
Arg *arg = mp_vector_at(env->func->def->base->args, Arg, 0);
.lhs = base,
.rhs = e->type,
.data = (uintptr_t)NULL,
- .loc = e->pos};
+ .loc = e->loc};
return op_get(env, &opi)
? insert_symbol("==")
: insert_symbol("?=");
ANN static m_bool match_case_exp(const Env env, Exp e) {
Exp last = e;
for (m_uint i = 0; i < vector_size(&env->scope->match->cond); e = e->next, ++i) {
- if (!e) ERR_B(last->pos, _("no enough to match"))
+ if (!e) ERR_B(last->loc, _("no enough to match"))
last = e;
const Exp base = (Exp)vector_at(&env->scope->match->cond, i);
const Symbol op = case_op(env, base->type, e);
e->next = next;
CHECK_OB(t);
Exp_Binary bin = {.lhs = cpy_exp(env->gwion->mp, base), .rhs = cpy_exp(env->gwion->mp, e), .op = op};
- struct Exp_ ebin = {.d = {.exp_binary = bin}, .exp_type = ae_exp_binary, .pos = e->pos };
+ struct Exp_ ebin = {.d = {.exp_binary = bin}, .exp_type = ae_exp_binary, .loc = e->loc };
CHECK_BB(traverse_exp(env, &ebin));
const Type ret = ebin.type;
if(ebin.exp_type == ae_exp_binary) {
CHECK_OB(ret);
}
}
- if (e) ERR_B(e->pos, _("too many expression to match"))
+ if (e) ERR_B(e->loc, _("too many expression to match"))
return GW_OK;
}
tcol_snprintf(msg, 255, "expected {G+}%s{0}", target->name);
gwerr_basic("invalid type for const generic argument", msg, NULL, env->name, spec->tag.loc, 0);
tcol_snprintf(msg, 255, "got {G+}%s{0}", targ->d.exp->type->name);
- gwerr_secondary(msg, env->name, targ->d.exp->pos);
+ gwerr_secondary(msg, env->name, targ->d.exp->loc);
return GW_ERROR;
}
return GW_OK;
if(likely(targ.type == tmplarg_td)) continue;
CHECK_OB(check_exp(env, targ.d.exp));
const Specialized spec = *mp_vector_at(tmpl->list, Specialized, i);
- const Value v = new_value(env, targ.d.exp->type, s_name(spec.tag.sym), targ.d.exp->pos);
+ const Value v = new_value(env, targ.d.exp->type, s_name(spec.tag.sym), targ.d.exp->loc);
valuefrom(env, v->from);
set_vflag(v, vflag_valid);
nspc_add_value(nspc, spec.tag.sym, v);
ANN static Stmt_List code(const MemPool p, const Exp func, const Arg_List lst,
const uint32_t max, const ae_stmt_t type) {
const Exp arg = mk_args(p, lst, max);
- const Exp call = new_exp_call(p, func, arg, func->pos);
+ const Exp call = new_exp_call(p, func, arg, func->loc);
Stmt_List code = new_mp_vector(p, struct Stmt_, 1);
mp_vector_set(code, struct Stmt_, 0,
((struct Stmt_) {
.stmt_type = type, .d = { .stmt_exp = { .val = call }},
- .loc = func->pos
+ .loc = func->loc
}));
return code;
}
const Func func = find_func_match(env, f, exp);
nspc_pop_type(env->gwion->mp, env->curr);
if (func)
- call_add_effect(env, func, exp->func->pos);
+ call_add_effect(env, func, exp->func->loc);
return func;
}
ANN static Func __find_template_match(const Env env, const Value v,
Exp_Call *const exp) {
DECL_OO(const m_str, tmpl_name,
- = tl2str(env->gwion, exp->tmpl->call, exp->func->pos));
+ = tl2str(env->gwion, exp->tmpl->call, exp->func->loc));
const Func f = find_tmpl(env, v, exp, tmpl_name);
free_mstr(env->gwion->mp, tmpl_name);
return f;
TmplArg arg = *mp_vector_at(tl, TmplArg, i);
if(unlikely(spec->td)) {
if(unlikely(arg.type == tmplarg_td))
- ERR_O(exp_self(exp)->pos, "expected contant, not type");
+ ERR_O(exp_self(exp)->loc, "expected contant, not type");
// check argument in call exp
continue;
} else {
if(unlikely(arg.type == tmplarg_exp)) {
- ERR_O(exp_self(exp)->pos, "expected type, not constant");
+ ERR_O(exp_self(exp)->loc, "expected type, not constant");
// check argument in call exp?
continue;
}
ANN static inline m_bool check_call(const Env env, const Exp_Call *exp) {
const ae_exp_t et = exp->func->exp_type;
if (et != ae_exp_primary && et != ae_exp_dot && et != ae_exp_cast)
- ERR_B(exp->func->pos, _("invalid expression for function call."))
+ ERR_B(exp->func->loc, _("invalid expression for function call."))
return GW_OK;
}
}
t = t->info->parent;
}
- ERR_O(exp_self(exp)->pos, _("arguments do not match for template call"))
+ ERR_O(exp_self(exp)->loc, _("arguments do not match for template call"))
}
ANN static Type chuck_rewrite(const Env env, const struct Op_Import *opi, const m_str op, const size_t len) {
Exp_Binary *base = (Exp_Binary*)opi->data;
const Exp lhs = cpy_exp(env->gwion->mp, base->lhs); // no need to copy
- const Exp call = new_exp_call(env->gwion->mp, cpy_exp(env->gwion->mp, base->rhs), NULL, lhs->pos);
+ const Exp call = new_exp_call(env->gwion->mp, cpy_exp(env->gwion->mp, base->rhs), NULL, lhs->loc);
char c[len - 1];
strncpy(c, op, len - 2);
c[len - 2] = '\0';
env_set_error(env, true);
return NULL;
}
- const Exp bin = new_exp_binary(env->gwion->mp, lhs, insert_symbol(env->gwion->st, c), call, exp_self(base)->pos);
+ const Exp bin = new_exp_binary(env->gwion->mp, lhs, insert_symbol(env->gwion->st, c), call, exp_self(base)->loc);
base->lhs = bin;
base->op = insert_symbol(env->gwion->st, "=>");
const Type ret = check_exp(env, exp_self(base));
if(is_hole(env, e) || is_typed_hole(env, e)) {
char c[256];
sprintf(c, "@%u", i);
- const Exp exp = new_prim_id(env->gwion->mp, insert_symbol(c), e->pos);
+ const Exp exp = new_prim_id(env->gwion->mp, insert_symbol(c), e->loc);
exp->type = known_type(env, mp_vector_at(args, Arg, i)->var.td);
- exp->d.prim.value = new_value(env, exp->type, c, e->pos);
+ exp->d.prim.value = new_value(env, exp->type, c, e->loc);
valid_value(env, insert_symbol(c), exp->d.prim.value);
return exp;
}
ANN static Stmt_List partial_code(const Env env, Arg_List args, const Exp efun, const Exp earg) {
const Exp arg = partial_call(env, args, earg);
- const Exp exp = new_exp_call(env->gwion->mp, efun, arg, efun->pos);
+ const Exp exp = new_exp_call(env->gwion->mp, efun, arg, efun->loc);
Stmt_List code = new_mp_vector(env->gwion->mp, struct Stmt_, 1);
mp_vector_set(code, struct Stmt_, 0, ((struct Stmt_) {
.stmt_type = ae_stmt_return,
// stmt->stmt_type = ae_stmt_return;
// stmt->d.stmt_exp.val = exp;
return code;
-// return new_stmt_code(env->gwion->mp, slist, efun->pos);
+// return new_stmt_code(env->gwion->mp, slist, efun->loc);
}
ANN static uint32_t count_args_exp(Exp args) {
ANN Type partial_type(const Env env, Exp_Call *const call) {
const Func base = call->func->type->info->func;
- if(!base) ERR_O(call->func->pos, _("can't do partial application on a literal lambda"));
- const Func f = partial_match(env, base, call->args, call->func->pos);
+ if(!base) ERR_O(call->func->loc, _("can't do partial application on a literal lambda"));
+ const Func f = partial_match(env, base, call->args, call->func->loc);
if(!f) {
- const Exp e = expand(env, call->func->type->info->func, call->args, call->func->pos);
+ const Exp e = expand(env, call->func->type->info->func, call->args, call->func->loc);
if(e) {
call->args = e;
return partial_type(env, call);
}
- ERR_O(call->func->pos, _("no match found for partial application"));
+ ERR_O(call->func->loc, _("no match found for partial application"));
}
nspc_push_value(env->gwion->mp, env->curr);
- Func_Base *const fbase = partial_base(env, f->def->base, call->args, call->func->pos);
+ Func_Base *const fbase = partial_base(env, f->def->base, call->args, call->func->loc);
const Stmt_List code = partial_code(env, f->def->base->args, call->func, call->args);
const Exp exp = exp_self(call);
exp->d.exp_lambda.def = new_func_def(env->gwion->mp, fbase, code);
Exp e = cdef->base.ext->array ? cdef->base.ext->array->exp : NULL;
while(e) {
if(!is_prim_int(e))
- ERR_O(e->pos, "non null array type extension must be literal");
+ ERR_O(e->loc, "non null array type extension must be literal");
e = e->next;
}
if (tmpl_base(cdef->base.tmpl)) return get_parent_base(env, cdef->base.ext);
return NULL;
if (decl->var.td->tag.sym == insert_symbol("auto") && decl->type) return decl->type;
if (GET_FLAG(t, private) && t->info->value->from->owner != env->curr)
- ERR_O(exp_self(decl)->pos, _("can't use private type %s"), t->name)
+ ERR_O(exp_self(decl)->loc, _("can't use private type %s"), t->name)
if (GET_FLAG(t, protect) && (!env->class_def || isa(t, env->class_def) < 0))
- ERR_O(exp_self(decl)->pos, _("can't use protected type %s"), t->name)
+ ERR_O(exp_self(decl)->loc, _("can't use protected type %s"), t->name)
return t;
}
Exp e = array->exp;
while(e) {
if(!exp_is_zero(e))
- ERR_B(e->pos, _("arrays of abstract type should use `0` size"));
+ ERR_B(e->loc, _("arrays of abstract type should use `0` size"));
e = e->next;
}
return GW_OK;
if (!GET_FLAG(decl->var.td, late) && !decl->var.td->array->exp)
ERR_B(decl->var.td->tag.loc, _("arrays with no expressions should be declared `late`"));
if (GET_FLAG(decl->var.td, late) && decl->var.td->array->exp)
- ERR_B(decl->var.td->array->exp->pos, _("late array should have no size"));
+ ERR_B(decl->var.td->array->exp->loc, _("late array should have no size"));
if (!decl->args && GET_FLAG(base, abstract)) CHECK_BB(abstract_array(env, decl->var.td->array));
}
const Value v = vd->value =
}
ANN m_bool scan1_exp_decl(const Env env, Exp_Decl *const decl) {
- CHECK_BB(env_storage(env, decl->var.td->flag, exp_self(decl)->pos));
+ CHECK_BB(env_storage(env, decl->var.td->flag, exp_self(decl)->loc));
((Exp_Decl *)decl)->type = scan1_exp_decl_type(env, (Exp_Decl *)decl);
CHECK_OB(decl->type);
if(decl->args) CHECK_BB(scan1_exp(env, decl->args));
if (global) {
if (env->context) env->context->global = true;
if (!type_global(env, decl->type))
- ERR_B(exp_self(decl)->pos, _("type '%s' is not global"), decl->type->name)
+ ERR_B(exp_self(decl)->loc, _("type '%s' is not global"), decl->type->name)
}
const m_uint scope = !global ? env->scope->depth : env_push_global(env);
const m_bool ret = scan1_decl(env, decl);
CHECK_BB(scan1_exp(env, post->exp));
const m_str access = exp_access(post->exp);
if (!access) return GW_OK;
- ERR_B(post->exp->pos,
+ ERR_B(post->exp->loc,
_("post operator '%s' cannot be used"
" on %s data-type..."),
s_name(post->op), access);
break;
}
/*
- const Value v = new_value(env, env->gwion->type[et_int], s_name(spec.xid), targ.d.exp->pos);
+ const Value v = new_value(env, env->gwion->type[et_int], s_name(spec.xid), targ.d.exp->loc);
valuefrom(env, v->from);
valid_value(env, spec.xid, v);
SET_FLAG(v, const| ae_flag_static);