From 9fc509935750f9583d8f36cc465876da03b9a682 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Wed, 6 Jan 2021 13:21:58 +0100 Subject: [PATCH] :art: Fix enums alloc --- include/env/value.h | 2 ++ src/emit/emit.c | 7 +++---- src/env/value.c | 4 +++- src/import/import_enum.c | 9 ++------- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/include/env/value.h b/include/env/value.h index c87da142..153a3cde 100644 --- a/include/env/value.h +++ b/include/env/value.h @@ -27,6 +27,8 @@ struct Value_ { m_str name; struct ValueFrom_ *from; union value_data{ + m_uint num; + m_float fnum; m_uint* ptr; Func func_ref; } d; diff --git a/src/emit/emit.c b/src/emit/emit.c index 44ddd2f3..c4cb1406 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -395,8 +395,8 @@ ANN static m_bool emit_symbol_builtin(const Emitter emit, const Symbol *data) { } else { const m_uint size = v->type->size; const Instr instr = emit_kind(emit, size, exp_getvar(prim_exp(data)), regpushimm); - if(!exp_getvar(prim_exp(data)) && size == SZ_INT) { - if(isa(v->type, emit->gwion->type[et_object]) > 0) + if((!exp_getvar(prim_exp(data)) && size == SZ_INT)) { + if(isa(v->type, emit->gwion->type[et_object]) > 0 || vflag(v, vflag_enum)) instr->m_val = (m_uint)v->d.ptr; else if(v->d.ptr) instr->m_val = *(m_uint*)v->d.ptr; @@ -1737,9 +1737,8 @@ ANN static m_bool emit_enum_def(const Emitter emit, const Enum_Def edef) { for(m_uint i = 0; i < vector_size(&edef->values); ++i) { const Value v = (Value)vector_at(&edef->values, i); if(!emit->env->class_def) { - ALLOC_PTR(emit->gwion->mp, addr, m_uint, i); v->from->offset = emit_local(emit, emit->gwion->type[et_int]); - v->d.ptr = addr; + v->d.num = i; } else *(m_bit*)(emit->env->class_def->nspc->info->class_data + v->from->offset) = i; } diff --git a/src/env/value.c b/src/env/value.c index dfbf80b8..fc52ef7c 100644 --- a/src/env/value.c +++ b/src/env/value.c @@ -6,12 +6,14 @@ ANN void free_value(Value a, Gwion gwion) { const Type t = a->type; +if(!vflag(a, vflag_enum)) { if(!vflag(a, vflag_func) && a->d.ptr && !vflag(a, vflag_direct) && - !(vflag(a, vflag_enum) && vflag(a, vflag_builtin) && a->from->owner_class) + !(vflag(a, vflag_builtin) && a->from->owner_class) && isa(t, gwion->type[et_object]) < 0) _mp_free(gwion->mp, t->size, a->d.ptr); else if(vflag(a, vflag_freeme)) xfree(a->d.ptr); +} if(is_class(gwion, t)) type_remref(t, gwion); mp_free(gwion->mp, ValueFrom, a->from); diff --git a/src/import/import_enum.c b/src/import/import_enum.c index 866c1d92..f48233af 100644 --- a/src/import/import_enum.c +++ b/src/import/import_enum.c @@ -51,8 +51,7 @@ ANN m_int gwi_enum_add(const Gwi gwi, const m_str name, const m_uint i) { CHECK_BB(ck_ok(gwi, ck_edef)) DECL_OB(const ID_List, list, = gwi_str2symlist(gwi, name)) add2list(gwi->ck, list); - ALLOC_PTR(gwi->gwion->mp, addr, m_int, i); - vector_add(&gwi->ck->v, (vtype)addr); + vector_add(&gwi->ck->v, (vtype)i); return GW_OK; } @@ -66,11 +65,7 @@ ANN static void import_enum_end(const Gwi gwi, const Vector v) { const Value value = (Value)vector_at(v, i); const m_uint addr = vector_at(&ck->v, i); set_vflag(value, vflag_builtin); -// ADD_REF(value->type); // what ? - if(!gwi->gwion->env->class_def) - value->d.ptr = (m_uint*)(addr ? addr : i); - else - value->d.ptr = (m_uint*)(addr ? *(m_uint*)addr : i); + value->d.num = addr ?: i; } // better clean ? } -- 2.43.0