]> Nishi Git Mirror - gwion.git/commitdiff
:art: Test import named union
authorfennecdjay <astor.jeremie@wanadoo.fr>
Tue, 22 Oct 2019 12:07:55 +0000 (14:07 +0200)
committerfennecdjay <astor.jeremie@wanadoo.fr>
Tue, 22 Oct 2019 12:07:55 +0000 (14:07 +0200)
src/lib/import.c
src/lib/ptr.c
tests/import/union_name.c [new file with mode: 0644]
tests/import/union_name.gw [new file with mode: 0644]
tests/sh/import.sh

index d55cdf06552ea7fbeb1b0283d4fc8b444013b125..a9c4fce83cc41d37d34c8297eebcbdca57dc1bff 100644 (file)
@@ -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) {
index 9b9657dc824555e4e56441eb00574e33bd814b0a..67f189224f396f17cefee27c6c8dbf8cbd5b4b3a 100644 (file)
@@ -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 (file)
index 0000000..702356e
--- /dev/null
@@ -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 (file)
index 0000000..c5ad1d0
--- /dev/null
@@ -0,0 +1,2 @@
+<<< my_union >>>;
+<<<my_union.i>>>;
index 0d4e04505bea7271d457b3216344c112143e1e33..ca0a55f6db3e1a9c1d9f63e5f2caad3832dee36c 100644 (file)
@@ -1,5 +1,5 @@
 #!/bin/bash
-# [test] #61
+# [test] #62
 
 n=0
 [ "$1" ] && n="$1"