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_error_footer(const Env env);
-ANN Value global_string(const Env env, const m_str str);
+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 {
REF_FUNC(Value, value)
FLAG_FUNC(Value, v)
-ANEW ANN Value new_value(MemPool p, const Type type, const m_str name);
-ANN void valuefrom(const Env, struct ValueFrom_ *, const loc_t loc);
+ANEW ANN Value new_value(const Env, const Type type, const m_str name, const loc_t loc);
+ANN void valuefrom(const Env, struct ValueFrom_ *);
ANN static inline void defined_here(const Value v) {
if (v->from->filename) // TODO: check why is that from check
ANN Value mk_class(const Env env, const Type base, const loc_t loc) {
const Type t = class_type(env, base);
const Symbol sym = insert_symbol(base->name);
- const Value v = new_value(env->gwion->mp, t, s_name(sym));
- valuefrom(env, v->from, loc);
+ const Value v = new_value(env, t, s_name(sym), loc);
+ valuefrom(env, v->from);
SET_FLAG(v, const);
set_vflag(v, vflag_valid);
nspc_add_value_front(env->curr, sym, v);
return v;
}
-ANN Value global_string(const Env env, const m_str str) {
+ANN Value global_string(const Env env, const m_str str, const loc_t loc) {
char c[strlen(str) + 8];
sprintf(c, "%s:string", str);
const Symbol sym = insert_symbol(c);
const Value v = nspc_lookup_value0(env->global_nspc, sym);
if (v) return v;
const Value value =
- new_value(env->gwion->mp, env->gwion->type[et_string], s_name(sym));
+ new_value(env, env->gwion->type[et_string], s_name(sym), loc);
nspc_add_value_front(env->global_nspc, sym, value);
return value;
}
mp_free(gwion->mp, Value, a);
}
-ANN Value new_value(MemPool p, const Type type, const m_str name) {
- const Value a = mp_calloc(p, Value);
- a->from = mp_calloc(p, ValueFrom);
- a->type = type;
- a->name = name;
- a->ref = 1;
+ANN Value new_value(const Env env, const Type type, const m_str name, const loc_t loc) {
+ const Value a = mp_calloc(env->gwion->mp, Value);
+ a->from = mp_calloc(env->gwion->mp, ValueFrom);
+ a->type = type;
+ a->name = name;
+ a->ref = 1;
+ a->from->filename = env->name;
+ a->from->loc = loc;
return a;
}
-ANN void valuefrom(const Env env, struct ValueFrom_ *from, const loc_t loc) {
+ANN void valuefrom(const Env env, struct ValueFrom_ *from) {
from->owner = env->curr;
from->owner_class = env->scope->depth ? NULL : env->class_def;
from->ctx = env->context;
- from->filename = env->name;
- from->loc = loc;
}
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->gwion->mp, deep_type(emit->gwion, d->exp->type), name);
+ 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);
d->tmp->d.prim.value = d->val;
d->tmp->type = d->val->type;
for(uint32_t i = 0; i < unary->captures->len; i++) {
Capture *const cap = mp_vector_at(unary->captures, Capture, i);
DECL_OO(const Type, t, = upvalue_type(env, cap));
- cap->v = new_value(env->gwion->mp, t, s_name(cap->xid));
+ cap->v = new_value(env, t, s_name(cap->xid), cap->pos);
cap->v->from->offset = offset;
offset += cap->v->type->size;
}
: env->class_def ? env->class_def->name
: env->name;
// handle delim?
- ((Exp_Primary *)prim)->value = global_string(env, prim->d.string.data);
+ ((Exp_Primary *)prim)->value = global_string(env, prim->d.string.data, prim_pos(prim));
return prim->value->type;
}
ANN Type check_prim_str(const Env env, const struct AstString *data) {
if (!prim_self(data)->value)
- prim_self(data)->value = global_string(env, data->data);
+ prim_self(data)->value = global_string(env, data->data, prim_pos(data));
return env->gwion->type[et_string]; // prim->value
}
// casting while defining it*
const Exp ret_id =
new_prim_id(env->gwion->mp, insert_symbol("self"), when->pos);
- ret_id->d.prim.value = new_value(env->gwion->mp, tdef->type, "self");
- // valuefrom?
+ ret_id->d.prim.value = new_value(env, tdef->type, "self", tdef->pos);
struct Stmt_ ret = {
.stmt_type = ae_stmt_return, .d = { .stmt_exp = { .val = ret_id }},
.pos = when->pos
}
ANN static void check_idx(const Env env, const Type base, struct EachIdx_ *const idx) {
- idx->v = new_value(env->gwion->mp, base, s_name(idx->sym));
+ idx->v = new_value(env, base, s_name(idx->sym), idx->pos);
valid_value(env, idx->sym, idx->v);
- idx->v->from->loc = idx->pos;
- idx->v->from->filename = env->name;
SET_FLAG(idx->v, const);
}
if (stmt->idx)
CHECK_BB(check_each_idx(env, stmt->exp, stmt->idx));
DECL_OB(const Type, ret, = check_each_val(env, stmt->exp));
- stmt->v = new_value(env->gwion->mp, ret, s_name(stmt->sym));
+ stmt->v = new_value(env, ret, s_name(stmt->sym), stmt->vpos);
valid_value(env, stmt->sym, stmt->v);
- stmt->v->from->loc = stmt->vpos;
- stmt->v->from->filename = env->name;
return check_conts(env, stmt_self(stmt), stmt->body);
}
ANN static Value match_value(const Env env, const Type base,
const Exp_Primary *prim) {
const Symbol sym = prim->d.var;
- const Value v = new_value(env->gwion->mp, base, s_name(sym));
+ const Value v = new_value(env, base, s_name(sym), prim_pos(prim));
// valuefrom?
valid_value(env, sym, v);
return v;
for(uint32_t i = 0; i < list->len; i++) {
Var_Decl vd = mp_vector_at(list, struct Var_Decl_, i);
const Value value = vd->value;
- valuefrom(env, value->from,
- vd->pos); // we do not need owner
+ valuefrom(env, value->from);
if (!trait->requested_values.ptr)
vector_init(&trait->requested_values);
vector_add(&trait->requested_values, (m_uint)value);
}
fptr->value = mk_class(env, t, fptr->base->pos);
if (global) env_pop(env, 0);
- valuefrom(env, fptr->value->from, fptr->base->pos);
+ valuefrom(env, fptr->value->from);
fptr_def(env, fptr);
if (env->class_def) fptr_assign(fptr);
set_vflag(fptr->value, vflag_func);
base->name);
const Value v = vd->value =
- vd->value ?: new_value(env->gwion->mp, t, s_name(vd->xid));
+ vd->value ?: new_value(env, t, s_name(vd->xid), vd->pos);
nspc_add_value(env->curr, vd->xid, v);
if (GET_FLAG(t, abstract) && !GET_FLAG(decl->td, late)) SET_FLAG(v, late);
v->type = t;
if (decl_ref || array_ref(vd->array)) SET_FLAG(v, late);
v->flag |= decl->td->flag;
if (!env->scope->depth) {
- valuefrom(env, v->from, vd->pos);
+ valuefrom(env, v->from);
if (env->class_def) {
if (env->class_def->info->tuple) tuple_contains(env, v);
if (!GET_FLAG(decl->td, static)) {
ID_List list = edef->list;
for(uint32_t i = 0; i < list->len; i++) {
Symbol xid = *mp_vector_at(list, Symbol, i);
- const Value v = new_value(env->gwion->mp, edef->t, s_name(xid));
- valuefrom(env, v->from, edef->pos);
+ const Value v = new_value(env, edef->t, s_name(xid), edef->pos);
+ valuefrom(env, v->from);
if (env->class_def) {
SET_FLAG(v, static);
SET_ACCESS(edef, v)
ANN static Value arg_value(const Env env, Arg *const arg) {
const Var_Decl vd = &arg->var_decl;
- const Value v = new_value(env->gwion->mp, arg->type,
- vd->xid ? s_name(vd->xid) : (m_str) __func__);
+ const Value v = new_value(env, arg->type,
+ vd->xid ? s_name(vd->xid) : (m_str) __func__, arg->var_decl.pos);
if (vd->array)
v->type = arg->type = array_type(env, arg->type, vd->array->depth);
if (arg->td)
v->flag = arg->td->flag;
- v->from->loc = arg->var_decl.pos;
- v->from->filename = env->name;
return v;
}
nspc_allocdata(env->gwion->mp, udef->type->nspc);
Union_List l = udef->l;
m_uint sz = 0;
- const Value v = new_value(env->gwion->mp, env->gwion->type[et_int], "@index");
+ const Value v = new_value(env, env->gwion->type[et_int], "@index", udef->pos);
nspc_add_value_front(env->curr, insert_symbol("@index"), v);
- valuefrom(env, v->from, udef->pos);
+ valuefrom(env, v->from);
for(uint32_t i = 0; i < l->len; i++) {
Union_Member *um = mp_vector_at(l, Union_Member, i);
DECL_OB(const Type, t, = known_type(env, um->td));
if (nspc_lookup_value0(env->curr, um->vd.xid))
ERR_B(um->vd.pos, _("'%s' already declared in union"), s_name(um->vd.xid))
- const Value v = new_value(env->gwion->mp, t, s_name(um->vd.xid));
+ const Value v = new_value(env, t, s_name(um->vd.xid), um->vd.pos);
tuple_contains(env, v);
- valuefrom(env, v->from, udef->pos);
+ valuefrom(env, v->from);
nspc_add_value_front(env->curr, um->vd.xid, v);
if (t->size > sz) sz = t->size;
}
ANN static Value scan2_func_assign(const Env env, const Func_Def d,
const Func f, const Value v) {
- valuefrom(env, v->from, d->base->pos);
+ valuefrom(env, v->from);
SET_FLAG(v, const);
set_vflag(v, vflag_func);
if (!env->class_def) {
ANN2(1, 2)
static Value func_value(const Env env, const Func f, const Value overload) {
const Type t = func_type(env, f);
- const Value v = t->info->value = new_value(env->gwion->mp, t, t->name);
- valuefrom(env, v->from, f->def->base->pos);
+ const Value v = t->info->value = new_value(env, t, t->name, f->def->base->pos);
+ valuefrom(env, v->from);
CHECK_OO(scan2_func_assign(env, f->def, f, v));
if (!overload)
func_no_overload(env, f, v);
const Func_Def def = cpy_func_def(env->gwion->mp, t->info->func->def);
const Func func = ret->info->func =
new_func(env->gwion->mp, s_name(sym), def);
- const Value value = new_value(env->gwion->mp, ret, s_name(sym));
+ const Value value = new_value(env, ret, s_name(sym), def->base->pos);
func->flag = def->base->flag;
if (vflag(t->info->func->value_ref, vflag_member))
set_vflag(value, vflag_member);