From 70f1da0c7c14c20bad514d2dae1a15b075b66723 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Sat, 10 Feb 2024 12:57:14 +0100 Subject: [PATCH] :art: change new_value's signature --- include/env/value.h | 2 +- plug | 2 +- src/env/env_utils.c | 4 ++-- src/env/value.c | 6 +++--- src/lib/closure.c | 2 +- src/lib/deep_equal.c | 2 +- src/lib/xork.c | 2 +- src/parse/check.c | 15 ++++++++------- src/parse/partial.c | 2 +- src/parse/scan1.c | 15 ++++++++------- src/parse/scan2.c | 3 ++- src/parse/template.c | 2 +- 12 files changed, 30 insertions(+), 27 deletions(-) diff --git a/include/env/value.h b/include/env/value.h index 47ae58fd..a03191f0 100644 --- a/include/env/value.h +++ b/include/env/value.h @@ -44,7 +44,7 @@ struct Value_ { 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) { diff --git a/plug b/plug index 88b079e8..8eab3d20 160000 --- a/plug +++ b/plug @@ -1 +1 @@ -Subproject commit 88b079e8a888a883141170147c3c8e792360c8e1 +Subproject commit 8eab3d20a622cc86b3daf2d5760338f80f6856a0 diff --git a/src/env/env_utils.c b/src/env/env_utils.c index c5084ffb..551b17e5 100644 --- a/src/env/env_utils.c +++ b/src/env/env_utils.c @@ -86,7 +86,7 @@ ANN static Type class_type(const Env env, const Type base) { 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); @@ -102,7 +102,7 @@ ANN Value global_string(const Env env, const m_str str, const loc_t loc) { 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; } diff --git a/src/env/value.c b/src/env/value.c index e5b96913..a67c31ba 100644 --- a/src/env/value.c +++ b/src/env/value.c @@ -15,14 +15,14 @@ ANN void free_value(Value a, Gwion gwion) { 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; } diff --git a/src/lib/closure.c b/src/lib/closure.c index 45b39c57..01412b8a 100644 --- a/src/lib/closure.c +++ b/src/lib/closure.c @@ -291,7 +291,7 @@ ANN static m_bool _check_lambda(const Env env, Exp_Lambda *l, 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; } } diff --git a/src/lib/deep_equal.c b/src/lib/deep_equal.c index de953016..cad1eca4 100644 --- a/src/lib/deep_equal.c +++ b/src/lib/deep_equal.c @@ -159,7 +159,7 @@ ANN static inline Type deep_type(const Gwion gwion, const Type t) { 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; diff --git a/src/lib/xork.c b/src/lib/xork.c index 02b65294..f337a721 100644 --- a/src/lib/xork.c +++ b/src/lib/xork.c @@ -42,7 +42,7 @@ static OP_CHECK(opck_spork) { 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; } diff --git a/src/parse/check.c b/src/parse/check.c index 0ed1c408..74a5add4 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -1305,8 +1305,9 @@ ANN m_bool check_type_def(const Env env, const Type_Def tdef) { } // 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; @@ -1389,7 +1390,7 @@ ANN static inline m_bool for_empty(const Env env, const Stmt_For stmt) { } 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); } @@ -1425,7 +1426,7 @@ ANN static m_bool do_stmt_each(const Env env, const Stmt_Each stmt) { 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); } @@ -1535,7 +1536,7 @@ ANN static m_bool check_stmt_exp(const Env env, const Stmt_Exp stmt) { 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; @@ -1863,7 +1864,7 @@ ANN static m_bool check_fdef_effects(const Env env, const Func_Def fdef) { } 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); @@ -2205,7 +2206,7 @@ ANN static m_bool check_class_tmpl(const Env env, const Tmpl *tmpl, const Nspc n 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); diff --git a/src/parse/partial.c b/src/parse/partial.c index eca38c03..f1acab5f 100644 --- a/src/parse/partial.c +++ b/src/parse/partial.c @@ -50,7 +50,7 @@ ANN static Exp* partial_exp(const Env env, Arg_List args, Exp* e, const uint i) 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; } diff --git a/src/parse/scan1.c b/src/parse/scan1.c index 8ae5b0ca..7032a2df 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -120,7 +120,7 @@ ANN static m_bool scan1_decl(const Env env, Exp_Decl *const decl) { 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); @@ -399,7 +399,7 @@ ANN m_bool scan1_enum_def(const Env env, const Enum_Def edef) { 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); @@ -415,8 +415,8 @@ ANN m_bool scan1_enum_def(const Env env, const Enum_Def edef) { 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; @@ -529,8 +529,9 @@ ANN static inline m_bool scan1_union_def_inner_loop(const Env env, 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); @@ -539,7 +540,7 @@ ANN static inline m_bool scan1_union_def_inner_loop(const Env env, 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); diff --git a/src/parse/scan2.c b/src/parse/scan2.c index 01397dfc..f74c34b9 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -334,7 +334,8 @@ ANN static void func_no_overload(const Env env, const Func f, const Value 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) diff --git a/src/parse/template.c b/src/parse/template.c index f7cbe381..daaf2733 100644 --- a/src/parse/template.c +++ b/src/parse/template.c @@ -148,7 +148,7 @@ static ANN Type scan_func(const Env env, const Type t, const Type_Decl *td) { 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); -- 2.43.0