From: fennecdjay Date: Tue, 12 Nov 2019 00:13:01 +0000 (+0100) Subject: :art: Resolve typeof/array conflict X-Git-Tag: nightly~2109 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=8639e080cfd2c38e8b8606a80e0e180435762996;p=gwion.git :art: Resolve typeof/array conflict --- diff --git a/include/env/env.h b/include/env/env.h index da7fd647..c9072067 100644 --- a/include/env/env.h +++ b/include/env/env.h @@ -36,6 +36,7 @@ ANN void env_pop(const Env, const m_uint); ANN Map env_label(const Env); ANN Type scan_type(const Env, const Type, const Type_Decl*); ANN Type type_decl_resolve(const Env, const Type_Decl*); +ANN Value mk_class(const Env env, const Type base); // tl2str returns a mp_alloced string ANEW ANN m_str tl2str(const Env, const Type_List); // in type_decl.c ANN m_bool compat_func(const __restrict__ Func_Def, const __restrict__ Func_Def); diff --git a/src/lib/array.c b/src/lib/array.c index cbcc5ac2..e352c22d 100644 --- a/src/lib/array.c +++ b/src/lib/array.c @@ -189,15 +189,10 @@ static FREEARG(freearg_array) { mp_free(((Gwion)gwion)->mp, ArrayInfo, info); } -static GACK(gack_array) { - printf("%s", t->name); -} - GWION_IMPORT(array) { const Type t_array = gwi_class_ini(gwi, "@Array", NULL); gwi->gwion->type[et_array] = t_array; gwi_class_xtor(gwi, NULL, array_dtor); - GWI_BB(gwi_gack(gwi, t_array, gack_array)) GWI_BB(gwi_item_ini(gwi, "@internal", "@array")) GWI_BB(gwi_item_end(gwi, 0, NULL)) diff --git a/src/oo/env_utils.c b/src/oo/env_utils.c index fcadeb40..97dbe740 100644 --- a/src/oo/env_utils.c +++ b/src/oo/env_utils.c @@ -73,3 +73,22 @@ ANN m_bool already_defined(const Env env, const Symbol s, const loc_t pos) { return GW_ERROR; } + +ANN static Type class_type(const Env env, const Type base) { + const Type t = type_copy(env->gwion->mp, env->gwion->type[et_class]); + t->e->ctx = base->e->ctx; + t->e->d.base_type = base; + return t; +} + +ANN Value mk_class(const Env env, const Type base) { + 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)); + // set from + v->from->owner = base->e->owner; + SET_FLAG(v, const | ae_flag_checked); + // should we add t to front, too? + nspc_add_value_front(base->e->owner, sym, v); + return v; +} diff --git a/src/oo/type.c b/src/oo/type.c index 5cd0d2bf..6d70d1cb 100644 --- a/src/oo/type.c +++ b/src/oo/type.c @@ -96,30 +96,31 @@ ANN Type array_base(Type type) { return t->e->d.base_type; } -ANN Type array_type(const Env env, const Type src, const m_uint depth) { - m_uint i = depth + 1; - if(depth > 1) - array_type(env, src, depth-1); +ANN static Symbol array_sym(const Env env, const Type src, const m_uint depth) { size_t len = strlen(src->name); char name[len + 2* depth + 1]; strcpy(name, src->name); + m_uint i = depth + 1; while(--i) { strcpy(name+len, "[]"); len += 2; } - const Symbol sym = insert_symbol(name); + return insert_symbol(name); +} + +ANN Type array_type(const Env env, const Type src, const m_uint depth) { + const Symbol sym = array_sym(env, src, depth); const Type type = nspc_lookup_type1(src->e->owner, sym); if(type) return type; - const Type t = new_type(env->gwion->mp, env->gwion->type[et_array]->xid, src->name, env->gwion->type[et_array]); - t->name = s_name(sym); - t->size = SZ_INT; + const Type t = new_type(env->gwion->mp, env->gwion->type[et_array]->xid, + s_name(sym), env->gwion->type[et_array]); t->array_depth = depth + src->array_depth; t->e->d.base_type = array_base(src) ?: src; - t->nspc = env->gwion->type[et_array]->nspc; - ADD_REF(t->nspc); - SET_FLAG(t, checked); t->e->owner = src->e->owner; + ADD_REF((t->nspc = env->gwion->type[et_array]->nspc)) + SET_FLAG(t, checked); + mk_class(env, t); // maybe add_type_front could go in mk_class ? nspc_add_type_front(src->e->owner, sym, t); return t; } diff --git a/src/parse/check.c b/src/parse/check.c index e3df1ea9..9922f79d 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -932,11 +932,8 @@ ANN static Type check_exp_lambda(const Env env, ANN static Type check_exp_typeof(const Env env, const Exp_Typeof *exp) { DECL_OO(const Type, t, = check_exp(env, exp->exp)) - if(!t->array_depth) { - DECL_OO(Value, v, = nspc_lookup_value1(t->e->owner, insert_symbol(t->name))) - return v->type; - } - return t; + DECL_OO(Value, v, = nspc_lookup_value1(t->e->owner, insert_symbol(t->name))) + return v->type; } static const _type_func exp_func[] = { diff --git a/src/parse/scan0.c b/src/parse/scan0.c index 92ff1262..dfd0912f 100644 --- a/src/parse/scan0.c +++ b/src/parse/scan0.c @@ -28,20 +28,6 @@ static inline Type scan0_type(const Env env, const m_uint xid, return type; } -ANN static Value mk_class(const Env env, const Type base) { - const Symbol sym = insert_symbol(base->name); - const Type t = type_copy(env->gwion->mp, env->gwion->type[et_class]); -//t->e->ctx = env->context; -t->e->ctx = base->e->ctx; - const Value v = new_value(env->gwion->mp, t, s_name(sym)); - t->e->d.base_type = base; -// set from - v->from->owner = base->e->owner; - SET_FLAG(v, const | ae_flag_checked); - nspc_add_value_front(base->e->owner, sym, v); - return v; -} - ANN static inline m_bool scan0_defined(const Env env, const Symbol s, const loc_t pos) { if(nspc_lookup_type0(env->curr, s)) ERR_B(pos, _("type '%s' already defined"), s_name(s));