REF_FUNC(Value, value)
FLAG_FUNC(Value, v)
-ANEW ANN Value new_value(const Env, const Type type, const m_str name, const loc_t loc);
+ANEW ANN Value new_value(const Env, const Type type, const Tag tag);
ANN void valuefrom(const Env, ValueFrom *);
ANN static inline void defined_here(const Value v) {
-Subproject commit 88b079e8a888a883141170147c3c8e792360c8e1
+Subproject commit 8eab3d20a622cc86b3daf2d5760338f80f6856a0
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, t, s_name(sym), loc);
+ const Value v = new_value(env, t, MK_TAG(sym, loc));
valuefrom(env, v->from);
SET_FLAG(v, const);
set_vflag(v, vflag_valid);
const Value v = nspc_lookup_value0(env->global_nspc, sym);
if (v) return v;
const Value value =
- new_value(env, env->gwion->type[et_string], s_name(sym), loc);
+ new_value(env, env->gwion->type[et_string], MK_TAG(sym, loc));
_nspc_add_value_front(env->global_nspc, sym, value);
return value;
}
mp_free(gwion->mp, Value, a);
}
-ANN Value new_value(const Env env, const Type type, const m_str name, const loc_t loc) {
+ANN Value new_value(const Env env, const Type type, const Tag tag) {
const Value a = mp_calloc(env->gwion->mp, Value);
a->from = mp_calloc(env->gwion->mp, ValueFrom);
a->type = type;
- a->name = name;
+ a->name = s_name(tag.sym);
a->ref = 1;
a->from->filename = env->name;
- a->from->loc = loc;
+ a->from->loc = tag.loc;
return a;
}
const Value v = nspc_lookup_value1(env->curr, cap->var.tag.sym);
if(!v) ERR_B(cap->var.tag.loc, _("unknown value in capture"));
DECL_OB(const Type, t, = upvalue_type(env, cap));
- cap->temp = new_value(env, t, s_name(cap->var.tag.sym), cap->var.tag.loc);
+ cap->temp = new_value(env, t, cap->var.tag);
cap->var.value = v;
}
}
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->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->val = new_value(emit->env, deep_type(emit->gwion, d->exp->type), MK_TAG(insert_symbol(emit->gwion->st, 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;
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->temp = new_value(env, t, s_name(cap->var.tag.sym), cap->var.tag.loc);
+ cap->temp = new_value(env, t, cap->var.tag);
cap->temp->from->offset = offset;
offset += cap->temp->type->size;
}
}
// we handle the return after, so that we don't get *cant' use implicit
// casting while defining it*
- 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);
+ const Symbol sym = insert_symbol("self");
+ Exp* ret_id = new_prim_id(env->gwion->mp, sym, when->loc);
+ ret_id->d.prim.value = new_value(env, tdef->type, MK_TAG(sym, tdef->tag.loc));
Stmt ret = MK_STMT_RETURN(when->loc, ret_id);
mp_vector_set(fdef->d.code, Stmt, 1, ret);
ret_id->type = tdef->type;
}
ANN static void check_idx(const Env env, const Type base, struct EachIdx_ *const idx) {
- idx->var.value = new_value(env, base, s_name(idx->var.tag.sym), idx->var.tag.loc);
+ idx->var.value = new_value(env, base, idx->var.tag);
valid_value(env, idx->var.tag.sym, idx->var.value);
SET_FLAG(idx->var.value, const);
}
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->var.value = new_value(env, ret, s_name(stmt->tag.sym), stmt->tag.loc);
+ stmt->var.value = new_value(env, ret, stmt->tag);
valid_value(env, stmt->tag.sym, stmt->var.value);
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, base, s_name(sym), prim_pos(prim));
+ const Value v = new_value(env, base, MK_TAG(sym, prim_pos(prim)));
// valuefrom?
valid_value(env, sym, v);
return v;
}
ANN static void fdef_const_generic_value(const Env env, const Type owner, const Type t, const Tag tag) {
- const Value v = new_value(env, t, s_name(tag.sym), tag.loc);
+ const Value v = new_value(env, t, tag);
SET_FLAG(v, static|ae_flag_const);
valid_value(env, tag.sym, v);
nspc_add_value_front(owner->nspc, tag.sym, v);
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->loc);
+ const Value v = new_value(env, targ.d.exp->type, MK_TAG(spec.tag.sym, targ.d.exp->loc));
valuefrom(env, v->from);
set_vflag(v, vflag_valid);
nspc_add_value(nspc, spec.tag.sym, v);
sprintf(c, "@%u", i);
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->loc);
+ exp->d.prim.value = new_value(env, exp->type, MK_TAG(insert_symbol(c), e->loc));
valid_value(env, insert_symbol(c), exp->d.prim.value);
return exp;
}
if (!decl->args && GET_FLAG(base, abstract)) CHECK_BB(abstract_array(env, decl->var.td->array));
}
const Value v = vd->value =
- vd->value ?: new_value(env, t, s_name(vd->tag.sym), vd->tag.loc);
+ vd->value ?: new_value(env, t, vd->tag);
if (GET_FLAG(t, abstract) && !decl->args && !GET_FLAG(decl->var.td, late)) SET_FLAG(v, late);
v->type = t;
if (decl_ref) SET_FLAG(v, late);
m_int last = 0;
for(uint32_t i = 0; i < list->len; i++) {
EnumValue ev = *mp_vector_at(list, EnumValue, i);
- const Value v = new_value(env, t, s_name(ev.tag.sym), ev.tag.loc);
+ const Value v = new_value(env, t, ev.tag);
v->d.num = (ev.set ? ev.gwint.num : last);
last = v->d.num + 1;
valuefrom(env, v->from);
ANN static Value arg_value(const Env env, Arg *const arg) {
const Var_Decl *vd = &arg->var.vd;
- const Value v = new_value(env, arg->type,
- vd->tag.sym ? s_name(vd->tag.sym) : (m_str) __func__, arg->var.vd.tag.loc);
+ const Symbol sym = vd->tag.sym ?: insert_symbol((m_str)__func__);
+ const Value v = new_value(env, arg->type, MK_TAG(sym, arg->var.vd.tag.loc));
if (arg->var.td)
v->flag = arg->var.td->flag;
return v;
nspc_allocdata(env->gwion->mp, udef->type->nspc);
Variable_List l = udef->l;
m_uint sz = 0;
- const Value v = new_value(env, env->gwion->type[et_int], "@index", udef->tag.loc);
- nspc_add_value_front(env->curr, insert_symbol("@index"), v);
+ const Symbol sym = insert_symbol("@index");
+ const Value v = new_value(env, env->gwion->type[et_int], MK_TAG(sym, udef->tag.loc));
+ nspc_add_value_front(env->curr, sym, v);
valuefrom(env, v->from);
for(uint32_t i = 0; i < l->len; i++) {
Variable *um = mp_vector_at(l, Variable, i);
ERR_B(um->vd.tag.loc, _("'%s' already declared in union"), s_name(um->vd.tag.sym))
if(tflag(t, tflag_ref))
ERR_B(um->vd.tag.loc, _("can't declare ref type in union"));
- const Value v = new_value(env, t, s_name(um->vd.tag.sym), um->vd.tag.loc);
+ const Value v = new_value(env, t, um->vd.tag);
tuple_contains(env, v);
valuefrom(env, v->from);
nspc_add_value_front(env->curr, um->vd.tag.sym, v);
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, t, t->name, f->def->base->tag.loc);
+ const Symbol sym = insert_symbol(t->name);
+ const Value v = t->info->value = new_value(env, t, MK_TAG(sym, f->def->base->tag.loc));
valuefrom(env, v->from);
CHECK_OO(scan2_func_assign(env, f->def, f, v));
if (!overload)
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, ret, s_name(sym), def->base->tag.loc);
+ const Value value = new_value(env, ret, MK_TAG(sym, def->base->tag.loc));
func->flag = def->base->flag;
if (vflag(t->info->func->value_ref, vflag_member))
set_vflag(value, vflag_member);