From: fennecdjay Date: Sun, 8 Nov 2020 15:52:26 +0000 (+0100) Subject: :art: Improve import system X-Git-Tag: nightly~1190 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=refs%2Fpull%2F220%2Fhead;p=gwion.git :art: Improve import system --- diff --git a/src/env/env.c b/src/env/env.c index b7fba815..b4729d3d 100644 --- a/src/env/env.c +++ b/src/env/env.c @@ -79,17 +79,14 @@ ANN void env_pop(const Env env, const m_uint scope) { } ANN void env_add_type(const Env env, const Type type) { - const Type v_type = type_copy(env->gwion->mp, env->gwion->type[et_class]); - type_addref(v_type); - v_type->e->d.base_type = type; + type->e->owner = env->curr; + type->e->owner_class = env->class_def; // t owner_class ? const Symbol sym = insert_symbol(type->name); nspc_add_type_front(env->curr, sym, type); - const Value v = new_value(env->gwion->mp, v_type, s_name(sym)); - SET_FLAG(v, const | ae_flag_global); - set_vflag(v, vflag_valid | vflag_builtin); - nspc_add_value(env->curr, insert_symbol(type->name), v); - v->from->owner = type->e->owner = env->curr; - v->from->owner_class = type->e->owner_class = env->class_def; // t owner_class ? + const Value v = mk_class(env, type); + SET_FLAG(v, global); + set_vflag(v, vflag_builtin); + set_tflag(type, tflag_scan0 | tflag_scan1 | tflag_scan2 | tflag_check | tflag_emit); type->xid = ++env->scope->type_xid; } diff --git a/src/import/import_checker.c b/src/import/import_checker.c index efd1db70..4b556234 100644 --- a/src/import/import_checker.c +++ b/src/import/import_checker.c @@ -218,10 +218,8 @@ ANN Type_Decl* str2decl(const Gwion gwion, const m_str str, const loc_t pos) { ANN Type str2type(const Gwion gwion, const m_str str, const loc_t pos) { DECL_OO(Type_Decl *, td, = str2decl(gwion, str, pos)) const Type t = known_type(gwion->env, td); - if(t) - return t; free_type_decl(gwion->mp, td); - return NULL; + return t; } ANN static inline m_bool ac_finish(const Gwion gwion, const struct AC *ac) { diff --git a/src/import/import_tdef.c b/src/import/import_tdef.c index 32006abc..cfd2b7bf 100644 --- a/src/import/import_tdef.c +++ b/src/import/import_tdef.c @@ -34,6 +34,7 @@ ANN Type gwi_typedef_end(const Gwi gwi, const ae_flag flag) { gwi->ck->tmpl = NULL; const m_bool ret = traverse_type_def(gwi->gwion->env, tdef); const Type t = tdef->type; + set_tflag(t, tflag_scan0 | tflag_scan1 | tflag_scan2 | tflag_check | tflag_emit); free_type_def(gwi->gwion->mp, tdef); ck_end(gwi); return ret > 0 ? t : NULL; diff --git a/src/lib/engine.c b/src/lib/engine.c index a438d67e..9d55f6eb 100644 --- a/src/lib/engine.c +++ b/src/lib/engine.c @@ -77,7 +77,6 @@ ANN static m_bool import_core_libs(const Gwi gwi) { set_tflag(t_class, tflag_infer); GWI_BB(gwi_set_global_type(gwi, t_class, et_class)) GWI_BB(gwi_gack(gwi, t_class, gack_class)) // not working yet - GWI_BB(gwi_add_type(gwi, t_class)) GWI_BB(gwi_oper_ini(gwi, (m_str)OP_ANY_TYPE, (m_str)OP_ANY_TYPE, NULL)) GWI_BB(gwi_oper_add(gwi, opck_object_dot)) GWI_BB(gwi_oper_emi(gwi, opem_object_dot)) diff --git a/src/lib/shred.c b/src/lib/shred.c index e0948c8a..a9c9ddcb 100644 --- a/src/lib/shred.c +++ b/src/lib/shred.c @@ -374,7 +374,7 @@ GWION_IMPORT(shred) { GWI_BB(gwi_func_end(gwi, shred_now, ae_flag_none)) GWI_BB(gwi_class_end(gwi)) SET_FLAG(t_shred, abstract | ae_flag_final); - gwi_set_global_type(gwi, t_shred, et_shred); + gwi->gwion->type[et_shred] = t_shred; struct SpecialId_ spid = { .type=t_shred, .exec=RegPushMe, .is_const=1 }; gwi_specialid(gwi, "me", &spid); diff --git a/src/lib/string.c b/src/lib/string.c index 7893c838..db68d0ed 100644 --- a/src/lib/string.c +++ b/src/lib/string.c @@ -377,9 +377,9 @@ static MFUN(string_erase) { GWION_IMPORT(string) { const Type t_string = gwi_class_ini(gwi, "string", NULL); + gwi->gwion->type[et_string] = t_string; // use func gwi_class_xtor(gwi, string_ctor, NULL); GWI_BB(gwi_gack(gwi, t_string, gack_string)) - gwi->gwion->type[et_string] = t_string; // use func gwi_item_ini(gwi, "@internal", "@data"); GWI_BB(gwi_item_end(gwi, ae_flag_const, NULL)) diff --git a/src/lib/vararg.c b/src/lib/vararg.c index c5a47898..41177b48 100644 --- a/src/lib/vararg.c +++ b/src/lib/vararg.c @@ -173,7 +173,7 @@ GWION_IMPORT(vararg) { GWI_BB(gwi_func_end(gwi, mfun_vararg_cpy, ae_flag_none)) GWI_BB(gwi_class_end(gwi)) SET_FLAG(t_vararg, abstract | ae_flag_final); - GWI_BB(gwi_set_global_type(gwi, t_vararg, et_vararg)) + gwi->gwion->type[et_vararg] = t_vararg; GWI_BB(gwi_oper_ini(gwi, "nonnull Vararg", (m_str)OP_ANY_TYPE, NULL)) GWI_BB(gwi_oper_add(gwi, opck_vararg_cast)) GWI_BB(gwi_oper_emi(gwi, opem_vararg_cast))