From: fennecdjay Date: Tue, 5 Nov 2019 20:16:12 +0000 (+0100) Subject: :art: Use gwi_class_spe X-Git-Tag: nightly~2115^2~4 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=1cc5b3b8c4c14dadfbb22e0b479792be00ccdde7;p=gwion.git :art: Use gwi_class_spe --- diff --git a/include/import/cdef.h b/include/import/cdef.h index e02cde16..03285493 100644 --- a/include/import/cdef.h +++ b/include/import/cdef.h @@ -1,6 +1,7 @@ #ifndef __IMPORT_CLASS #define __IMPORT_CLASS ANN2(1,2) Type gwi_class_ini(const Gwi gwi, const m_str, const m_str parent); +ANN2(1,2) Type gwi_class_spe(const Gwi gwi, const m_str, const m_uint size); ANN2(1) void gwi_class_xtor(const Gwi gwi, const f_xtor ctor, const f_xtor dtor); ANN m_int gwi_class_end(const Gwi gwi); #endif diff --git a/plug b/plug index d0ae7373..a2fd43e0 160000 --- a/plug +++ b/plug @@ -1 +1 @@ -Subproject commit d0ae737367053420e17b8494a6a1922e1196758e +Subproject commit a2fd43e0ce60fec336694a2a6be0a90d09cfc072 diff --git a/src/import/cdef.c b/src/import/cdef.c index 11a6b7d1..c45eb331 100644 --- a/src/import/cdef.c +++ b/src/import/cdef.c @@ -44,7 +44,6 @@ ANN2(1,2) static void import_class_ini(const Env env, const Type t) { env_push_type(env, t); } - ANN2(1) void gwi_class_xtor(const Gwi gwi, const f_xtor ctor, const f_xtor dtor) { const Type t = gwi->gwion->env->class_def; if(ctor) @@ -53,6 +52,13 @@ ANN2(1) void gwi_class_xtor(const Gwi gwi, const f_xtor ctor, const f_xtor dtor) mk_xtor(gwi->gwion->mp, t, (m_uint)dtor, ae_flag_dtor); } +ANN static Type type_finish(const Gwi gwi, const Type t) { + SET_FLAG(t, scan1 | ae_flag_scan2 | ae_flag_check | ae_flag_emit); + gwi_add_type(gwi, t); + import_class_ini(gwi->gwion->env, t); + return t; +} + ANN2(1,2) Type gwi_class_ini(const Gwi gwi, const m_str name, const m_str parent) { struct ImportCK ck = { .name=name }; CHECK_BO(check_typename_def(gwi, &ck)) @@ -63,7 +69,7 @@ ANN2(1,2) Type gwi_class_ini(const Gwi gwi, const m_str name, const m_str parent const Type p = known_type(gwi->gwion->env, td); // check if(tmpl) nspc_pop_type(gwi->gwion->mp, gwi->gwion->env->curr); - const Type t = new_type(gwi->gwion->mp, gwi->gwion->env->scope->type_xid, s_name(ck.sym), p); + const Type t = new_type(gwi->gwion->mp, ++gwi->gwion->env->scope->type_xid, s_name(ck.sym), p); t->e->def = new_class_def(gwi->gwion->mp, 0, ck.sym, td, NULL, loc(gwi)); t->e->def->base.tmpl = tmpl; t->e->def->base.type = t; @@ -72,11 +78,14 @@ ANN2(1,2) Type gwi_class_ini(const Gwi gwi, const m_str name, const m_str parent SET_FLAG(t, typedef); if(ck.tmpl) SET_FLAG(t, template); - else - SET_FLAG(t, scan1 | ae_flag_scan2 | ae_flag_check | ae_flag_emit); - gwi_add_type(gwi, t); - import_class_ini(gwi->gwion->env, t); - return t; + return type_finish(gwi, t); +} + +ANN Type gwi_class_spe(const Gwi gwi, const m_str name, const m_uint size) { + CHECK_OO(str2sym(gwi, name)) + const Type t = new_type(gwi->gwion->mp, ++gwi->gwion->env->scope->type_xid, name, NULL); + t->size = size; + return type_finish(gwi, t); } ANN m_int gwi_class_end(const Gwi gwi) { diff --git a/src/lib/complex.c b/src/lib/complex.c index a3fba347..e2efac55 100644 --- a/src/lib/complex.c +++ b/src/lib/complex.c @@ -126,8 +126,7 @@ static GACK(gack_polar) { GWION_IMPORT(complex) { // should be special - const Type t_complex = gwi_class_ini(gwi, "complex", NULL); - t_complex->e->parent = NULL; + const Type t_complex = gwi_class_spe(gwi, "complex", SZ_COMPLEX); GWI_BB(gwi_gack(gwi, t_complex, gack_complex)) gwi->gwion->type[et_complex] = t_complex; // use func gwi_item_ini(gwi, "float", "re"); @@ -136,8 +135,7 @@ GWION_IMPORT(complex) { GWI_BB(gwi_item_end(gwi, ae_flag_member, NULL)) GWI_BB(gwi_class_end(gwi)) // should be special - const Type t_polar = gwi_class_ini(gwi, "polar", NULL); - t_polar->e->parent = NULL; + const Type t_polar = gwi_class_spe(gwi, "polar", SZ_COMPLEX); gwi->gwion->type[et_polar] = t_polar; GWI_BB(gwi_gack(gwi, t_polar, gack_polar)) GWI_BB(gwi_item_ini(gwi, "float", "mod")) diff --git a/src/lib/vec.c b/src/lib/vec.c index 1a246182..4ac56f66 100644 --- a/src/lib/vec.c +++ b/src/lib/vec.c @@ -164,9 +164,7 @@ static GACK(gack_vec3) { } GWION_IMPORT(vec3) { - const Type t_vec3 = gwi_class_ini(gwi, "Vec3", NULL); -t_vec3->size = SZ_VEC3; -t_vec3->e->parent = NULL; + const Type t_vec3 = gwi_class_spe(gwi, "Vec3", SZ_VEC3); gwi->gwion->type[et_vec3] = t_vec3; GWI_BB(gwi_gack(gwi, t_vec3, gack_vec3)) vecx_base(gwi); @@ -314,10 +312,7 @@ static GACK(gack_vec4) { } GWION_IMPORT(vec4) { -// should be special (gwi, "Vec4", SZ_VEC4) - const Type t_vec4 = gwi_class_ini(gwi, "Vec4", NULL); -t_vec4->size = SZ_VEC4; -t_vec4->e->parent = NULL; + const Type t_vec4 = gwi_class_spe(gwi, "Vec4", SZ_VEC4); gwi->gwion->type[et_vec4] = t_vec4; GWI_BB(gwi_gack(gwi, t_vec4, gack_vec4)) vecx_base(gwi);