From edb59a0f6613c1173ba9290c217f05afeddadf53 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Sat, 12 Oct 2019 00:04:15 +0200 Subject: [PATCH] :art: Still on import --- src/lib/import.c | 13 +++++------ tests/import/func_too_many_arg.c | 37 ++++++++++++++++++++++++++++++++ tests/import/union_member.c | 23 ++++++++++++++++++++ tests/sh/import.sh | 2 +- 4 files changed, 66 insertions(+), 9 deletions(-) create mode 100644 tests/import/func_too_many_arg.c create mode 100644 tests/import/union_member.c diff --git a/src/lib/import.c b/src/lib/import.c index 102317c6..dc46786d 100644 --- a/src/lib/import.c +++ b/src/lib/import.c @@ -561,13 +561,10 @@ ANN static Fptr_Def import_fptr(const Gwi gwi, DL_Func* dl_fun, ae_flag flag) { ANN Type gwi_fptr_end(const Gwi gwi, const ae_flag flag) { const Fptr_Def fptr = import_fptr(gwi, &gwi->func, flag); - if(traverse_fptr_def(gwi->gwion->env, fptr) < 0) { - if(!fptr->type) - free_fptr_def(gwi->gwion->mp, fptr); - return NULL; - } - SET_FLAG(fptr->base->func, builtin); - const Type t = fptr->type; + const m_bool ret = traverse_fptr_def(gwi->gwion->env, fptr); + if(ret > 0) + SET_FLAG(fptr->base->func, builtin); + const Type t = ret > 0 ? fptr->type : NULL; free_fptr_def(gwi->gwion->mp, fptr); return t; } @@ -627,7 +624,7 @@ ANN Type gwi_union_end(const Gwi gwi, const ae_flag flag) { udef->flag = flag; CHECK_BO(traverse_union_def(gwi->gwion->env, udef)) emit_union_offset(udef->l, udef->o); - if(GET_FLAG(udef, member)) + if(gwi->gwion->env->class_def && !GET_FLAG(udef, static)) gwi->gwion->env->class_def->nspc->info->offset = udef->o + udef->s; const Type t = udef->xid ? udef->value->type : diff --git a/tests/import/func_too_many_arg.c b/tests/import/func_too_many_arg.c new file mode 100644 index 00000000..3f28a21f --- /dev/null +++ b/tests/import/func_too_many_arg.c @@ -0,0 +1,37 @@ +#include "gwion_util.h" +#include "gwion_ast.h" +#include "oo.h" +#include "vm.h" +#include "env.h" +#include "type.h" +#include "instr.h" +#include "object.h" +#include "gwion.h" +#include "value.h" +#include "operator.h" +#include "import.h" +#include "instr.h" + +GWION_IMPORT(too_many_args) { + GWI_BB(gwi_func_ini(gwi, "int", "test", (f_xfun)1)) + GWI_BB(gwi_func_arg(gwi, "int", "i")) + GWI_BB(gwi_func_arg(gwi, "int", "j")) + GWI_BB(gwi_func_arg(gwi, "int", "k")) + GWI_BB(gwi_func_arg(gwi, "int", "l")) + GWI_BB(gwi_func_arg(gwi, "int", "m")) + GWI_BB(gwi_func_arg(gwi, "int", "n")) + GWI_BB(gwi_func_arg(gwi, "int", "o")) + GWI_BB(gwi_func_arg(gwi, "int", "p")) + GWI_BB(gwi_func_arg(gwi, "int", "q")) + GWI_BB(gwi_func_arg(gwi, "int", "r")) + GWI_BB(gwi_func_arg(gwi, "int", "s")) + GWI_BB(gwi_func_arg(gwi, "int", "t")) + GWI_BB(gwi_func_arg(gwi, "int", "u")) + GWI_BB(gwi_func_arg(gwi, "int", "v")) + GWI_BB(gwi_func_arg(gwi, "int", "w")) + GWI_BB(gwi_func_arg(gwi, "int", "x")) + GWI_BB(gwi_func_arg(gwi, "int", "y")) + GWI_BB(gwi_func_arg(gwi, "int", "z")) + GWI_BB(gwi_func_end(gwi, 0)) + return GW_OK; +} diff --git a/tests/import/union_member.c b/tests/import/union_member.c new file mode 100644 index 00000000..a0028944 --- /dev/null +++ b/tests/import/union_member.c @@ -0,0 +1,23 @@ +#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_member) { + const Type t_unionmember = gwi_mk_type(gwi, "UnionMember", SZ_INT, "Object"); + GWI_BB(gwi_class_ini(gwi, t_unionmember, NULL, NULL)) + GWI_BB(gwi_union_ini(gwi, "U")) + GWI_BB(gwi_union_add(gwi,"float", "f")) + GWI_BB(gwi_union_add(gwi,"int[]", "i")) + GWI_OB(gwi_union_end(gwi, ae_flag_none)) + GWI_BB(gwi_class_end(gwi)) + return GW_OK; +} diff --git a/tests/sh/import.sh b/tests/sh/import.sh index ab2028c6..aec12dfb 100644 --- a/tests/sh/import.sh +++ b/tests/sh/import.sh @@ -1,5 +1,5 @@ #!/bin/bash -# [test] #43 +# [test] #45 n=0 [ "$1" ] && n="$1" -- 2.43.0