From 0802fee0e77e42dfaf9a02690a0e775923149106 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Thu, 10 Oct 2019 18:41:31 +0200 Subject: [PATCH] :art: Global union testing --- src/emit/emit.c | 3 ++- src/oo/value.c | 2 ++ src/parse/check.c | 8 +++----- tests/tree/global_named_union.gw | 8 ++++++++ 4 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 tests/tree/global_named_union.gw diff --git a/src/emit/emit.c b/src/emit/emit.c index cd9b920d..6fc26fdf 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -1413,7 +1413,7 @@ ANN static m_bool emit_union_def(const Emitter emit, const Union_Def udef) { const M_Object o = new_object(emit->gwion->mp, NULL, udef->value->type); udef->value->d.ptr = (m_uint*)o; SET_FLAG(udef->value, builtin); - SET_FLAG(udef->value, global); + UNSET_FLAG(udef->value, union); } scope = emit_push_type(emit, udef->value->type); } else if(udef->type_xid) { @@ -1432,6 +1432,7 @@ ANN static m_bool emit_union_def(const Emitter emit, const Union_Def udef) { SET_FLAG(list->self->value, union); } while((l = l->next)); SET_FLAG(udef->l->self->d.exp_decl.list->self->value, enum); + SET_FLAG(udef->l->self->d.exp_decl.list->self->value, dtor); } if(udef->xid) regpop(emit, SZ_INT); diff --git a/src/oo/value.c b/src/oo/value.c index 3f1cbfbe..f069b3b3 100644 --- a/src/oo/value.c +++ b/src/oo/value.c @@ -14,6 +14,8 @@ ANN static void free_value(Value a, Gwion gwion) { !(GET_FLAG(a, enum) && GET_FLAG(a, builtin) && a->from->owner_class) && isa(t, gwion->type[et_object]) < 0) _mp_free(gwion->mp, t->size, a->d.ptr); + if(GET_FLAG(a, enum) && GET_FLAG(a, dtor)) + xfree(a->d.ptr); if(is_class(gwion, t)) REM_REF(t, gwion) mp_free(gwion->mp, ValueFrom, a->from); diff --git a/src/parse/check.c b/src/parse/check.c index be8cc423..2f4a100d 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -1127,11 +1127,9 @@ ANN m_bool check_union_decl(const Env env, const Union_Def udef) { Decl_List l = udef->l; do { CHECK_OB(check_exp(env, l->self)) - if(isa(l->self->type, env->gwion->type[et_object]) > 0) { - Var_Decl_List list = l->self->d.exp_decl.list; - do SET_FLAG(list->self->value, pure); - while((list = list->next)); - } + Var_Decl_List list = l->self->d.exp_decl.list; + do SET_FLAG(list->self->value, pure); + while((list = list->next)); if(l->self->type->size > udef->s) udef->s = l->self->type->size; } while((l = l->next)); diff --git a/tests/tree/global_named_union.gw b/tests/tree/global_named_union.gw new file mode 100644 index 00000000..a5e51c97 --- /dev/null +++ b/tests/tree/global_named_union.gw @@ -0,0 +1,8 @@ +union global { + int int_from_global_union; + float float_from_global_union; +} global_union; + +<<< "HERE", global_union >>>; +<<< 123.456 => global_union.float_from_global_union >>>; +<<< global_union.float_from_global_union >>>; -- 2.43.0