]> Nishi Git Mirror - gwion.git/commitdiff
:art: Still on import
authorfennecdjay <astor.jeremie@wanadoo.fr>
Fri, 11 Oct 2019 22:04:15 +0000 (00:04 +0200)
committerfennecdjay <astor.jeremie@wanadoo.fr>
Fri, 11 Oct 2019 22:04:15 +0000 (00:04 +0200)
src/lib/import.c
tests/import/func_too_many_arg.c [new file with mode: 0644]
tests/import/union_member.c [new file with mode: 0644]
tests/sh/import.sh

index 102317c6ddd67c6edb0f36ccef15c4d68ee98702..dc46786dc24c5f8ec55f9f631bea979c23c6d70a 100644 (file)
@@ -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 (file)
index 0000000..3f28a21
--- /dev/null
@@ -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 (file)
index 0000000..a002894
--- /dev/null
@@ -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;
+}
index ab2028c6dcd3de158027b9b01799cd8a2366671a..aec12dfb7f0d1dcbaaf493d78d6a2d93f1311a65 100644 (file)
@@ -1,5 +1,5 @@
 #!/bin/bash
-# [test] #43
+# [test] #45
 
 n=0
 [ "$1" ] && n="$1"