]> Nishi Git Mirror - gwion.git/commitdiff
:art: Start templating Union import
authorfennecdjay <astor.jeremie@wanadoo.fr>
Tue, 22 Oct 2019 10:49:58 +0000 (12:49 +0200)
committerfennecdjay <astor.jeremie@wanadoo.fr>
Tue, 22 Oct 2019 10:49:58 +0000 (12:49 +0200)
include/gwi.h
include/import.h
src/lib/import.c
src/lib/shred.c
src/lib/vararg.c
tests/import/empty_union.c
tests/import/typedef_tmpl.c [new file with mode: 0644]
tests/import/union.c
tests/import/union_fail_exp.c
tests/import/union_member.c
tests/sh/import.sh

index b9c6f5b1935d42e6cfb4f8bcf515ef5e0e4e2fed..d638a806476a456a0a28aad9181c1e98a7d1fa7c 100644 (file)
@@ -40,7 +40,8 @@ typedef struct {
 } DL_Enum;
 
 typedef struct {
-  Symbol xid;
+  m_str type_name;
+  m_str name;
   Decl_List list;
 } DL_Union;
 
index db21018f0f8a9ad253c918d137bb3277ea908f30..8a30e93c46b167211f3c230170c2c3f41c627af1 100644 (file)
@@ -54,7 +54,7 @@ ANN Type gwi_typedef_end(const Gwi gwi, const ae_flag flag);
 ANN m_int gwi_tmpl_ini(const Gwi gwi, const m_uint n, const m_str *name);
 ANN m_int gwi_tmpl_end(const Gwi gwi);
 
-ANN2(1) m_int gwi_union_ini(const Gwi gwi, const m_str name);
+ANN2(1) m_int gwi_union_ini(const Gwi gwi, const m_str type, const m_str name);
 ANN m_int gwi_union_add(const Gwi gwi, const __restrict__ m_str type, const __restrict__ m_str name);
 ANN Type gwi_union_end(const Gwi gwi, const ae_flag flag);
 
index 4df6d1e29167ab967808ccc9ad302ee919fca4e3..9fdbf0c4bc1e0be69ae4e62dcd3a0da5bd348b90 100644 (file)
@@ -734,9 +734,9 @@ ANN static Exp make_exp(const Gwi gwi, const m_str type, const m_str name) {
   return new_exp_decl(env->gwion->mp, type_decl, var_decl_list);
 }
 
-ANN2(1) m_int gwi_union_ini(const Gwi gwi, const m_str name) {
-  if(name)
-    gwi->union_data.xid = insert_symbol(gwi->gwion->st, name);
+ANN2(1) m_int gwi_union_ini(const Gwi gwi, const m_str type, const m_str name) {
+  gwi->union_data.type_name = type;
+  gwi->union_data.name = name;
   return GW_OK;
 }
 
@@ -766,12 +766,24 @@ ANN static Type union_type(const Gwi gwi, const Union_Def udef) {
 ANN Type gwi_union_end(const Gwi gwi, const ae_flag flag) {
   if(!gwi->union_data.list)
     GWI_ERR_O(_("union is empty"));
+  if(gwi->union_data.name)
+    CHECK_BO(name_valid(gwi, gwi->union_data.name))
+  struct func_checker ck = { .name=gwi->union_data.type_name, .flag=flag };
+  if(gwi->union_data.type_name)
+    CHECK_BO(check_typename_def(gwi, &ck))
+  const Symbol xid = gwi->union_data.name ? insert_symbol(gwi->gwion->st, gwi->union_data.name) : NULL;
+  const Symbol type_xid = gwi->union_data.type_name ? insert_symbol(gwi->gwion->st, gwi->union_data.type_name) : NULL;
   const Union_Def udef = new_union_def(gwi->gwion->mp, gwi->union_data.list, loc_cpy(gwi->gwion->mp, gwi->loc));
   udef->flag = flag;
+  udef->xid = xid;
+  udef->type_xid = type_xid;
+  udef->tmpl = ck.tmpl ? new_tmpl(gwi->gwion->mp, ck.tmpl, -1) : NULL;
   const Type t = union_type(gwi, udef);
-  free_union_def(gwi->gwion->mp, udef);
+  if(!SAFE_FLAG(t, template))
+    free_union_def(gwi->gwion->mp, udef);
   gwi->union_data.list = NULL;
-  gwi->union_data.xid  = NULL;
+  gwi->union_data.name  = NULL;
+  gwi->union_data.type_name  = NULL;
   return t;
 }
 
index ba8bd8436ecb3bc1416680032ce9966515c692ba..b8f773ee2d3df259531261f40896796fe53e95c9 100644 (file)
@@ -322,7 +322,7 @@ GWION_IMPORT(shred) {
   gwi_item_ini(gwi, "int", "@orig");
   GWI_BB((o_fork_orig = gwi_item_end(gwi, ae_flag_const, NULL)))
   o_fork_retval = t_fork->nspc->info->offset;
-  GWI_BB(gwi_union_ini(gwi, NULL))
+  GWI_BB(gwi_union_ini(gwi, NULL, NULL))
   GWI_BB(gwi_union_add(gwi, "int", "i"))
   GWI_BB(gwi_union_add(gwi, "float", "f"))
   GWI_BB(gwi_union_add(gwi, "Vec3", "v"))
index e6996c21b217600528ae9bebdf725a71846a80ea..204dd87b5f6a063b2adb1432be66e84a7abab37d 100644 (file)
@@ -100,7 +100,7 @@ GWION_IMPORT(vararg) {
   GWI_BB(gwi_set_global_type(gwi, t_varloop, et_varloop))
   GWI_BB(gwi_class_ini(gwi, t_vararg, NULL, NULL))
   gwi->gwion->type[et_vararg] = t_vararg;
-  GWI_BB(gwi_union_ini(gwi, NULL))
+  GWI_BB(gwi_union_ini(gwi, NULL, NULL))
   GWI_BB(gwi_union_add(gwi, "@VarLoop",  "start"))
   GWI_BB(gwi_union_add(gwi, "@VarLoop",  "end"))
   GWI_BB(gwi_union_add(gwi, "int",       "i"))
index 1f20d554b2009b801e95ae16903aa909c536f406..bb1a9346f13c9e41927de7103bc281f32e2e12c1 100644 (file)
@@ -12,7 +12,7 @@
 #include "import.h"
 
 GWION_IMPORT(empty_union_test) {
-  GWI_BB(gwi_union_ini(gwi, NULL))
+  GWI_BB(gwi_union_ini(gwi, NULL, NULL))
   GWI_OB(gwi_union_end(gwi, 0))
   return GW_OK;
 }
diff --git a/tests/import/typedef_tmpl.c b/tests/import/typedef_tmpl.c
new file mode 100644 (file)
index 0000000..2a48bed
--- /dev/null
@@ -0,0 +1,18 @@
+#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(typedef_test) {
+  GWI_OB(gwi_typedef_ini(gwi, "int", "<~A~>Typedef"))
+  GWI_OB(gwi_typedef_end(gwi, ae_flag_none))
+  return GW_OK;
+}
index f86a986ee6a5ba78aeb65546c77623c470f498f2..b76c32509fb697ea41ca8e9a7d02a8b7c2526809 100644 (file)
@@ -12,7 +12,7 @@
 #include "import.h"
 
 GWION_IMPORT(union_test) {
-  GWI_BB(gwi_union_ini(gwi, NULL))
+  GWI_BB(gwi_union_ini(gwi, NULL, NULL))
   GWI_BB(gwi_union_add(gwi,"float", "f"))
   GWI_BB(gwi_union_add(gwi,"int", "i"))
   GWI_OB(gwi_union_end(gwi, 0))
index 7ecf58e4c7edff90f5eddb18931eb3f54e898c1f..32d43199386449b193625cc29b8a736f39d3cd40 100644 (file)
@@ -12,7 +12,7 @@
 #include "import.h"
 
 GWION_IMPORT(union_test) {
-  GWI_BB(gwi_union_ini(gwi, NULL))
+  GWI_BB(gwi_union_ini(gwi, NULL, NULL))
   GWI_BB(gwi_union_add(gwi,"Float", "f"))
   GWI_BB(gwi_union_add(gwi,"int", "i"))
   GWI_OB(gwi_union_end(gwi, 0))
index a00289443cd2e55b540468e66957bf9c243b7fd0..7fcdb934ff7a59f743089d30b06775810bec4fa9 100644 (file)
@@ -14,7 +14,7 @@
 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_ini(gwi, "U", NULL))
     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))
index 6edaf1a99c9148367c20245c440ae0577fac5bd0..0d4e04505bea7271d457b3216344c112143e1e33 100644 (file)
@@ -1,5 +1,5 @@
 #!/bin/bash
-# [test] #60
+# [test] #61
 
 n=0
 [ "$1" ] && n="$1"