From 02dbe3f84aab2502a0c9ce376fc70a0426ca919c Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Tue, 22 Oct 2019 14:07:55 +0200 Subject: [PATCH] :art: Test import named union --- src/lib/import.c | 9 +++++++-- src/lib/ptr.c | 2 +- tests/import/union_name.c | 20 ++++++++++++++++++++ tests/import/union_name.gw | 2 ++ tests/sh/import.sh | 2 +- 5 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 tests/import/union_name.c create mode 100644 tests/import/union_name.gw diff --git a/src/lib/import.c b/src/lib/import.c index d55cdf06..a9c4fce8 100644 --- a/src/lib/import.c +++ b/src/lib/import.c @@ -760,8 +760,13 @@ ANN static Type union_type(const Gwi gwi, const Union_Def udef) { if(gwi->gwion->env->class_def && !GET_FLAG(udef, static)) gwi->gwion->env->class_def->nspc->info->offset = udef->o + udef->s; - return udef->xid ? udef->value->type : - udef->type_xid ? udef->type : udef->value->type; + if(udef->xid || !udef->type_xid) { + SET_FLAG(udef->value, builtin); + const M_Object o = new_object(gwi->gwion->mp, NULL, udef->value->type); + udef->value->d.ptr = (m_uint*)o; + return udef->value->type; + } + return udef->type; } ANN Type gwi_union_end(const Gwi gwi, const ae_flag flag) { diff --git a/src/lib/ptr.c b/src/lib/ptr.c index 9b9657dc..67f18922 100644 --- a/src/lib/ptr.c +++ b/src/lib/ptr.c @@ -117,7 +117,7 @@ GWION_IMPORT(ptr) { GWI_BB(gwi_item_ini(gwi, "int", "@val")) GWI_BB(gwi_item_end(gwi, 0, NULL)) GWI_BB(gwi_class_end(gwi)) - t_ptr->nspc->info->offset = SZ_INT; + t_ptr->nspc->info->offset = SZ_INT; // TODO: should be an assert GWI_BB(gwi_oper_ini(gwi, (m_str)OP_ANY_TYPE, "Ptr", NULL)) GWI_BB(gwi_oper_add(gwi, opck_ptr_assign)) GWI_BB(gwi_oper_emi(gwi, opem_ptr_assign)) diff --git a/tests/import/union_name.c b/tests/import/union_name.c new file mode 100644 index 00000000..702356e0 --- /dev/null +++ b/tests/import/union_name.c @@ -0,0 +1,20 @@ +#include "gwion_util.h" +#include "gwion_ast.h" +#include "oo.h" +#include "vm.h" +#include "env.h" +#include "type.h" +#include "object.h" +#include "instr.h" +#include "gwion.h" +#include "value.h" +#include "operator.h" +#include "import.h" + +GWION_IMPORT(union_test) { + GWI_BB(gwi_union_ini(gwi, NULL, "my_union")) + GWI_BB(gwi_union_add(gwi,"float", "f")) + GWI_BB(gwi_union_add(gwi,"int", "i")) + GWI_OB(gwi_union_end(gwi, 0)) + return GW_OK; +} diff --git a/tests/import/union_name.gw b/tests/import/union_name.gw new file mode 100644 index 00000000..c5ad1d05 --- /dev/null +++ b/tests/import/union_name.gw @@ -0,0 +1,2 @@ +<<< my_union >>>; +<<>>; diff --git a/tests/sh/import.sh b/tests/sh/import.sh index 0d4e0450..ca0a55f6 100644 --- a/tests/sh/import.sh +++ b/tests/sh/import.sh @@ -1,5 +1,5 @@ #!/bin/bash -# [test] #61 +# [test] #62 n=0 [ "$1" ] && n="$1" -- 2.43.0