From: Jérémie Astor Date: Thu, 5 Aug 2021 14:04:28 +0000 (+0200) Subject: :art: Improve Nspc X-Git-Tag: nightly~486 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=1dbce4fdb52ce560da0ddcb0e6cb46c9a8504d2e;p=gwion.git :art: Improve Nspc --- diff --git a/include/env/nspc.h b/include/env/nspc.h index 1980cd09..dc590f69 100644 --- a/include/env/nspc.h +++ b/include/env/nspc.h @@ -1,25 +1,25 @@ #ifndef __NSPC #define __NSPC struct NspcInfo_ { - m_bit * class_data; struct Map_ op_map; Scope value; Scope type; Scope func; Scope trait; struct Vector_ op_tmpl; - uint16_t offset; - uint16_t class_data_size; }; struct Nspc_ { - struct NspcInfo_ *info; - Nspc parent; - m_str name; struct Vector_ vtable; + m_bit * class_data; struct VM_Code_ * pre_ctor; struct VM_Code_ * dtor; + Nspc parent; + m_str name; + struct NspcInfo_ *info; + uint16_t offset; uint16_t ref; + uint16_t class_data_size; }; REF_FUNC(Nspc, nspc) @@ -78,9 +78,9 @@ ANN void did_you_mean_type(const Type, const char *); if (strlen(b) < DID_YOU_MEAN_LIMIT) did_you_mean_type(a, b); ANN static inline void nspc_allocdata(MemPool mp, const Nspc nspc) { - if (nspc->info->class_data_size) { - nspc->info->class_data = - (m_bit *)mp_calloc2(mp, nspc->info->class_data_size); + if (nspc->class_data_size) { + nspc->class_data = + (m_bit *)mp_calloc2(mp, nspc->class_data_size); } } #endif diff --git a/plug b/plug index ac29ebb0..57d4e8c8 160000 --- a/plug +++ b/plug @@ -1 +1 @@ -Subproject commit ac29ebb012d01fda0eb1c84dc204941fc6a55d4f +Subproject commit 57d4e8c83af845579d08ebb7b1453aa6a98aaa47 diff --git a/src/emit/emit.c b/src/emit/emit.c index cddf0dbd..9fc957a8 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -799,7 +799,7 @@ ANN static m_bool emit_dot_static_data(const Emitter emit, const Value v, const bool emit_var) { const m_uint size = v->type->size; const Instr instr = emit_dotstatic(emit, size, emit_var); - instr->m_val = (m_uint)(v->from->owner->info->class_data + v->from->offset); + instr->m_val = (m_uint)(v->from->owner->class_data + v->from->offset); instr->m_val2 = size; return GW_OK; } @@ -2228,7 +2228,7 @@ ANN static m_bool emit_enum_def(const Emitter emit NUSED, const Enum_Def edef) { LOOP_OPTIM for (m_uint i = 0; i < vector_size(&edef->values); ++i) { const Value v = (Value)vector_at(&edef->values, i); - *(m_uint *)(v->from->owner->info->class_data + v->from->offset) = i; + *(m_uint *)(v->from->owner->class_data + v->from->offset) = i; } set_tflag(edef->t, tflag_emit); return GW_OK; diff --git a/src/env/nspc.c b/src/env/nspc.c index 5e4ed299..ff9a00f5 100644 --- a/src/env/nspc.c +++ b/src/env/nspc.c @@ -15,23 +15,23 @@ ANN void nspc_commit(const Nspc nspc) { ANN static inline void nspc_release_object(const Nspc a, Value value, Gwion gwion) { - if ((GET_FLAG(value, static) && a->info->class_data) || + if ((GET_FLAG(value, static) && a->class_data) || (value->d.ptr && vflag(value, vflag_builtin))) { const M_Object obj = value->d.ptr ? (M_Object)value->d.ptr - : *(M_Object *)(a->info->class_data + value->from->offset); + : *(M_Object *)(a->class_data + value->from->offset); release(obj, gwion->vm->cleaner_shred); } } ANN2(1, 3) static inline void nspc_release_struct(const Nspc a, Value value, Gwion gwion) { - if (value && ((GET_FLAG(value, static) && a->info->class_data) || + if (value && ((GET_FLAG(value, static) && a->class_data) || (vflag(value, vflag_builtin) && value->d.ptr))) { const m_bit *ptr = (value && value->d.ptr) ? (m_bit *)value->d.ptr - : (m_bit *)(a->info->class_data + value->from->offset); + : (m_bit *)(a->class_data + value->from->offset); for (m_uint i = 0; i < vector_size(&value->type->info->tuple->types); ++i) { const Type t = (Type)vector_at(&value->type->info->tuple->types, i); if (isa(t, gwion->type[et_object]) > 0) @@ -80,8 +80,8 @@ ANN void free_nspc(const Nspc a, const Gwion gwion) { if (a->info->op_map.ptr) free_op_map(&a->info->op_map, gwion); if (a->info->op_tmpl.ptr) free_op_tmpl(&a->info->op_tmpl, gwion); nspc_free_type(a, gwion); - if (a->info->class_data && a->info->class_data_size) - mp_free2(gwion->mp, a->info->class_data_size, a->info->class_data); + if (a->class_data && a->class_data_size) + mp_free2(gwion->mp, a->class_data_size, a->class_data); if (a->vtable.ptr) vector_release(&a->vtable); mp_free(gwion->mp, NspcInfo, a->info); if (a->pre_ctor) vmcode_remref(a->pre_ctor, gwion); diff --git a/src/env/type.c b/src/env/type.c index e964c15b..1c794a80 100644 --- a/src/env/type.c +++ b/src/env/type.c @@ -154,6 +154,6 @@ ANN Type actual_type(const struct Gwion_ *gwion, const Type t) { ANN void inherit(const Type t) { const Nspc nspc = t->nspc, parent = t->info->parent->nspc; if (!nspc || !parent) return; - nspc->info->offset = parent->info->offset; + nspc->offset = parent->offset; if (parent->vtable.ptr) vector_copy2(&parent->vtable, &nspc->vtable); } diff --git a/src/import/import_cdef.c b/src/import/import_cdef.c index d57b8a27..734cd180 100644 --- a/src/import/import_cdef.c +++ b/src/import/import_cdef.c @@ -130,7 +130,7 @@ ANN m_int gwi_class_end(const Gwi gwi) { if (!gwi->gwion->env->class_def) GWI_ERR_B(_("import: too many class_end called.")) const Type t = gwi->gwion->env->class_def; - if (t->nspc->info->class_data_size && !t->nspc->info->class_data) + if (t->nspc->class_data_size && !t->nspc->class_data) nspc_allocdata(gwi->gwion->mp, t->nspc); if (tflag(t, tflag_tmpl)) { --gwi->tmpls; diff --git a/src/import/import_udef.c b/src/import/import_udef.c index 97e89fa7..88f6d5f9 100644 --- a/src/import/import_udef.c +++ b/src/import/import_udef.c @@ -47,7 +47,7 @@ ANN static Type union_type(const Gwi gwi, const Union_Def udef) { // if(!udef->tmpl) // emit_union_offset(udef->l, udef->o); // if(gwi->gwion->env->class_def && !GET_FLAG(udef, static)) - // gwi->gwion->env->class_def->nspc->info->offset = + // gwi->gwion->env->class_def->nspc->offset = // udef->o + udef->s; // set_vflag(udef->value, vflag_builtin); // const M_Object o = new_object(gwi->gwion->mp, NULL, udef->value->type); diff --git a/src/lib/lib_func.c b/src/lib/lib_func.c index ba782e4b..8818dee4 100644 --- a/src/lib/lib_func.c +++ b/src/lib/lib_func.c @@ -608,8 +608,8 @@ ANN static Type fork_type(const Env env, const Exp_Unary *unary) { UNSET_FLAG(fork, final); const Type typed = str2type(env->gwion, "TypedFork", exp_self(unary)->pos); // ensure room for retval - if (typed->nspc->info->offset == fork->nspc->info->offset) - typed->nspc->info->offset += t->size; + if (typed->nspc->offset == fork->nspc->offset) + typed->nspc->offset += t->size; UNSET_FLAG(typed, final); const Type ret = str2type(env->gwion, c, exp_self(unary)->pos); SET_FLAG(typed, final); diff --git a/src/lib/object.c b/src/lib/object.c index 8854107f..2880c96f 100644 --- a/src/lib/object.c +++ b/src/lib/object.c @@ -26,8 +26,8 @@ M_Object new_object(MemPool p, const VM_Shred shred, const Type t) { a->type_ref = t; if (t->nspc) { a->vtable.ptr = t->nspc->vtable.ptr; - if (t->nspc->info->offset) - a->data = (m_bit *)_mp_calloc(p, t->nspc->info->offset); + if (t->nspc->offset) + a->data = (m_bit *)_mp_calloc(p, t->nspc->offset); } if (shred) vector_add(&shred->gc, (vtype)a); return a; @@ -86,8 +86,8 @@ __attribute__((hot)) ANN void __release(const M_Object o, } ANN void free_object(MemPool p, const M_Object o) { - if (o->type_ref->nspc && o->type_ref->nspc->info->offset) - mp_free2(p, o->type_ref->nspc->info->offset, o->data); + if (o->type_ref->nspc && o->type_ref->nspc->offset) + mp_free2(p, o->type_ref->nspc->offset, o->data); mp_free(p, M_Object, o); } diff --git a/src/lib/object_op.c b/src/lib/object_op.c index 26b93c77..cfff4546 100644 --- a/src/lib/object_op.c +++ b/src/lib/object_op.c @@ -88,7 +88,7 @@ ANN static void emit_dot_static_data(const Emitter emit, const Value v, const bool emit_addr) { const m_uint size = v->type->size; const Instr instr = emit_dotstatic(emit, size, emit_addr); - instr->m_val = (m_uint)(v->from->owner->info->class_data + v->from->offset); + instr->m_val = (m_uint)(v->from->owner->class_data + v->from->offset); instr->m_val2 = size; } diff --git a/src/lib/shred.c b/src/lib/shred.c index 7c2533e7..f9ac2e51 100644 --- a/src/lib/shred.c +++ b/src/lib/shred.c @@ -256,7 +256,7 @@ static ANN THREAD_FUNC(fork_run) { MUTEX_LOCK(vm->parent->shreduler->mutex); if (!*(m_int *)(me->data + o_shred_cancel) && me->type_ref != vm->gwion->type[et_fork]) - memcpy(me->data + vm->gwion->type[et_fork]->nspc->info->offset, ME(me)->reg, + memcpy(me->data + vm->gwion->type[et_fork]->nspc->offset, ME(me)->reg, FORK_RETSIZE(me)); *(m_int *)(me->data + o_fork_done) = 1; if (!*(m_int *)(me->data + o_shred_cancel)) diff --git a/src/parse/check.c b/src/parse/check.c index da633d90..3489d332 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -60,12 +60,12 @@ ANN static inline m_bool check_exp_decl_parent(const Env env, return GW_OK; } -#define describe_check_decl(a, b, flag) \ - ANN static inline void decl_##a(const Env env, const Value v) { \ - const Nspc nspc = env->curr; \ - flag; \ - v->from->offset = nspc->info->b; \ - nspc->info->b += v->type->size; \ +#define describe_check_decl(a, b, flag) \ + ANN static inline void decl_##a(const Env env, const Value v) { \ + const Nspc nspc = env->curr; \ + flag; \ + v->from->offset = nspc->b; \ + nspc->b += v->type->size; \ } describe_check_decl(member, offset, v->vflag |= vflag_member); diff --git a/src/parse/scan0.c b/src/parse/scan0.c index f29249e5..7c3adeda 100644 --- a/src/parse/scan0.c +++ b/src/parse/scan0.c @@ -266,9 +266,9 @@ ANN m_bool scan0_union_def(const Env env, const Union_Def udef) { CHECK_BB(scan0_defined(env, udef->xid, udef->pos)); udef->type = union_type(env, udef->xid, udef->pos); Union_List l = udef->l; - do udef->type->nspc->info->offset += SZ_INT; + do udef->type->nspc->offset += SZ_INT; while ((l = l->next)); - udef->type->nspc->info->offset += SZ_INT; + udef->type->nspc->offset += SZ_INT; SET_ACCESS(udef, udef->type); if (udef->tmpl) union_tmpl(env, udef); if (global) env_pop(env, 0); diff --git a/src/parse/scan1.c b/src/parse/scan1.c index 5860ece3..cc661dfc 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -499,7 +499,7 @@ ANN static inline m_bool scan1_union_def_inner_loop(const Env env, nspc_add_value_front(env->curr, l->xid, v); if (t->size > sz) sz = t->size; } while ((l = l->next)); - udef->type->nspc->info->offset = SZ_INT + sz; + udef->type->nspc->offset = SZ_INT + sz; return GW_OK; }