From: Jérémie Astor Date: Wed, 27 Apr 2022 10:00:34 +0000 (+0200) Subject: :art: All values have postion and filename X-Git-Tag: nightly~275^2~31 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=9e40edfd5064da78214db9225697801751093f44;p=gwion.git :art: All values have postion and filename --- diff --git a/include/env/env.h b/include/env/env.h index a93cab94..c6694309 100644 --- a/include/env/env.h +++ b/include/env/env.h @@ -62,7 +62,7 @@ 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_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 { diff --git a/include/env/value.h b/include/env/value.h index 35d5d513..dcae4d85 100644 --- a/include/env/value.h +++ b/include/env/value.h @@ -44,8 +44,8 @@ struct Value_ { 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 diff --git a/src/env/env_utils.c b/src/env/env_utils.c index 6e786b87..f1131567 100644 --- a/src/env/env_utils.c +++ b/src/env/env_utils.c @@ -85,8 +85,8 @@ 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->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); @@ -94,14 +94,14 @@ ANN Value mk_class(const Env env, const Type base, const loc_t loc) { 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; } diff --git a/src/env/value.c b/src/env/value.c index 5d144c9a..3813247f 100644 --- a/src/env/value.c +++ b/src/env/value.c @@ -18,19 +18,19 @@ ANN void free_value(Value a, Gwion gwion) { 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; } diff --git a/src/lib/deep_equal.c b/src/lib/deep_equal.c index ba177acb..cd379e94 100644 --- a/src/lib/deep_equal.c +++ b/src/lib/deep_equal.c @@ -148,7 +148,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->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; diff --git a/src/lib/lib_func.c b/src/lib/lib_func.c index 7ca4c554..2ee19198 100644 --- a/src/lib/lib_func.c +++ b/src/lib/lib_func.c @@ -669,7 +669,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->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; } diff --git a/src/lib/string.c b/src/lib/string.c index f1c27604..91bf1551 100644 --- a/src/lib/string.c +++ b/src/lib/string.c @@ -60,7 +60,7 @@ ID_CHECK(check_funcpp) { : 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; } diff --git a/src/parse/check.c b/src/parse/check.c index c2a8074f..676cea9e 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -386,7 +386,7 @@ ANN static Type prim_id_non_res(const Env env, const Symbol *data) { 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 } @@ -1119,8 +1119,7 @@ ANN m_bool check_type_def(const Env env, const Type_Def tdef) { // 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 @@ -1221,10 +1220,8 @@ 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->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); } @@ -1258,10 +1255,8 @@ 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->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); } @@ -1376,7 +1371,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->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; @@ -1793,8 +1788,7 @@ ANN static m_bool _check_trait_def(const Env env, const Trait_Def pdef) { 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); diff --git a/src/parse/scan0.c b/src/parse/scan0.c index 32c186ec..b13f278d 100644 --- a/src/parse/scan0.c +++ b/src/parse/scan0.c @@ -73,7 +73,7 @@ ANN m_bool scan0_fptr_def(const Env env, const Fptr_Def fptr) { } 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); diff --git a/src/parse/scan1.c b/src/parse/scan1.c index aadf3f41..b6c232c8 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -120,14 +120,14 @@ ANN static m_bool scan1_decl(const Env env, const Exp_Decl *decl) { 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)) { @@ -367,8 +367,8 @@ ANN m_bool scan1_enum_def(const Env env, const Enum_Def edef) { 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) @@ -386,14 +386,12 @@ 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_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; } @@ -495,17 +493,17 @@ ANN static inline m_bool scan1_union_def_inner_loop(const Env env, 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; } diff --git a/src/parse/scan2.c b/src/parse/scan2.c index ff31b001..6ce4a975 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -63,7 +63,7 @@ ANN static m_bool scan2_args(const Func_Def f) { 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) { @@ -360,8 +360,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->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); diff --git a/src/parse/template.c b/src/parse/template.c index 3cb6fcd1..7b5677cc 100644 --- a/src/parse/template.c +++ b/src/parse/template.c @@ -86,7 +86,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->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);