} DL_Enum;
typedef struct {
- Symbol xid;
+ m_str type_name;
+ m_str name;
Decl_List list;
} DL_Union;
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);
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;
}
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;
}
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"))
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"))
#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;
}
--- /dev/null
+#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;
+}
#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))
#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))
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))
#!/bin/bash
-# [test] #60
+# [test] #61
n=0
[ "$1" ] && n="$1"