-Subproject commit 1ae66ea3a07f6282ce9c5bf60956c731addbecaa
+Subproject commit f80e75e38b2616b68e2cc764d598a8e74123a1d7
-Subproject commit 73f7b396500a94347857b600bf847d3ab6531767
+Subproject commit c980939e8fe7bb574b2a555dde1bbffc216d012f
ANN static void clean_func_base(Clean *a, Func_Base *b);
ANN static void clean_func_def(Clean *a, Func_Def b);
ANN static void clean_class_def(Clean *a, Class_Def b);
-ANN static void clean_enum_def(Clean *a, Enum_Def b);
+//ANN static void clean_enum_def(Clean *a, Enum_Def b);
ANN static void clean_union_def(Clean *a, Union_Def b);
ANN static void clean_fptr_def(Clean *a, Fptr_Def b);
ANN static void clean_type_def(Clean *a, Type_Def b);
free_class_def(gwion->mp, b);
}
-ANN static void clean_enum_def(Clean *a NUSED, Enum_Def b) {
- clean_id_list(a, b->list);
- if (b->values.ptr) vector_release(&b->values);
-}
-
+#define clean_enum_def clean_dummy
ANN static void clean_union_list(Clean *a, Union_List b) {
for(uint32_t i = 0; i < b->len; i++) {
Union_Member *tgt = mp_vector_at(b, Union_Member, i);
}
ANN static m_bool emit_enum_def(const Emitter emit NUSED, const Enum_Def edef) {
- LOOP_OPTIM
- for (m_uint i = 0; i < vector_size(&edef->values); ++i) {
- const Value v = (Value)vector_at(&edef->values, i);
- set_vflag(v, vflag_builtin);
- v->d.num = i;
- }
set_tflag(edef->type, tflag_emit);
return GW_OK;
}
static inline void _free_nspc_value(const Nspc a, const Value v, Gwion gwion) {
if(v->from->ctx && v->from->ctx->error) return; // this is quite a hack
- if (GET_FLAG(v, static) && a->class_data) {
- const m_bit *ptr = a->class_data + v->from->offset;
- anytype_release(gwion->vm->cleaner_shred, v->type, ptr);
- } else if (vflag(v, vflag_builtin) && v->d.ptr) {
- const m_bit *ptr = (m_bit*)v->d.ptr;
- //if(vflag(v, vflag_direct))
- anytype_release(gwion->vm->cleaner_shred, v->type, ptr);
- }
+ const bool is_static = GET_FLAG(v, static) && a->class_data;
+ const m_bit *ptr = is_static
+ ? a->class_data + v->from->offset
+ : (m_bit*)v->d.ptr;
+ anytype_release(gwion->vm->cleaner_shred, v->type, ptr);
value_remref(v, gwion);
}
//! \arg the importer
//! \arg string defining a primitive type
//! why is return type m_int ?
-
-__attribute__ ((visibility ("default")))
ANN m_int gwi_enum_ini(const Gwi gwi, const m_str type) {
CHECK_BB(ck_ini(gwi, ck_edef));
CHECK_OB((gwi->ck->xid = gwi_str2sym(gwi, type)));
- vector_init(&gwi->ck->v);
- gwi->ck->tmpl = new_mp_vector(gwi->gwion->mp, Symbol, 0);
+ gwi->ck->tmpl = new_mp_vector(gwi->gwion->mp, EnumValue, 0);
return GW_OK;
}
-/*
-// adds the id_list to the enum
-// change that algo?
-ANN static void add2list(struct ImportCK *ck, const ID_List list) {
- if (!ck->tmpl) {
- ck->tmpl = new_mp_vector(list, ;
- } else {
- ck->curr->next = list;
- }
- ck->curr = list;
-}
-*/
+
//! add an enum entry
//! \arg the importer
//! \arg name of the entry
//! TODO: change return type to m_bool
ANN m_int gwi_enum_add(const Gwi gwi, const m_str name, const m_uint i) {
CHECK_BB(ck_ok(gwi, ck_edef));
-// DECL_OB(const ID_List, list, = gwi_str2symlist(gwi, name));
-
DECL_OB(const Symbol, xid, = gwi_str2sym(gwi, name));
- mp_vector_add(gwi->gwion->mp, &gwi->ck->tmpl, Symbol, xid);
-// add2list(gwi->ck, list);
- vector_add(&gwi->ck->v, (vtype)i);
+ const EnumValue ev = { .xid = xid, .num = i, .set = true};
+ mp_vector_add(gwi->gwion->mp, &gwi->ck->tmpl, EnumValue, ev);
return GW_OK;
}
-//! set enum values
-//! \arg the importer
-//! \arg a vector of values
-//! \note [internal]
-ANN static void import_enum_end(const Gwi gwi, const Vector v) {
- ImportCK *ck = gwi->ck;
- for (m_uint i = 0; i < vector_size(v); i++) {
- const Value value = (Value)vector_at(v, i);
- const m_uint addr = vector_at(&ck->v, i);
- set_vflag(value, vflag_builtin);
- value->d.num = addr ?: i;
- }
- // better clean ?
-}
-
//! finish enum import
//! \arg the importer
-//! TODO: check what happens in inside template class
ANN Type gwi_enum_end(const Gwi gwi) {
CHECK_BO(ck_ok(gwi, ck_edef));
- if (!vector_size(&gwi->ck->v)) GWI_ERR_O("Enum is empty");
+ if (!gwi->ck->tmpl->len) GWI_ERR_O("Enum is empty");
const Gwion gwion = gwi->gwion;
const Enum_Def edef =
new_enum_def(gwion->mp, gwi->ck->tmpl, gwi->ck->xid, gwi->loc);
+// clean the vector
gwi->ck->tmpl = NULL;
const m_bool ret = traverse_enum_def(gwion->env, edef);
- if (ret > 0) import_enum_end(gwi, &edef->values);
- if (gwi->gwion->data->cdoc) {
- gwfmt_indent(gwi->gwfmt);
- gwfmt_enum_def(gwi->gwfmt, edef);
- }
+ if (gwi->gwion->data->cdoc) gwfmt_enum_def(gwi->gwfmt, edef);
const Type t = ret > 0 ? edef->type : NULL;
- if (edef->values.ptr) vector_release(&edef->values);
free_enum_def(gwion->mp, edef);
- vector_release(&gwi->ck->v);
- gwi->ck->v.ptr = NULL;
ck_end(gwi);
return t;
}
CHECK_BB(scan0_defined(env, edef->xid, edef->pos));
DECL_BB(const m_bool, global, = scan0_global(env, edef->flag, edef->pos));
edef->type = enum_type(env, edef);
- vector_init(&edef->values);
if (global) env_pop(env, 0);
return GW_OK;
}
t->nspc = new_nspc(env->gwion->mp, t->name);
const m_uint scope = env_push_type(env, t);
ID_List list = edef->list;
+ m_uint last = 0;
for(uint32_t i = 0; i < list->len; i++) {
- Symbol xid = *mp_vector_at(list, Symbol, i);
- const Value v = new_value(env, t, s_name(xid), edef->pos);
+ EnumValue ev = *mp_vector_at(list, EnumValue, i);
+ const Value v = new_value(env, t, s_name(ev.xid), edef->pos);
+ v->d.num = (ev.set ? ev.num : last);
+ last = v->d.num + 1;
valuefrom(env, v->from);
- nspc_add_value(env->curr, xid, v);
- if (env->class_def) {
- SET_FLAG(v, static);
- SET_ACCESS(edef, v)
- SET_ACCESS(edef, t)
- } else
- set_vflag(v, vflag_builtin);
- SET_FLAG(v, const);
- vector_add(&edef->values, (vtype)v);
+ nspc_add_value(env->curr, ev.xid, v);
+ SET_FLAG(v, static | ae_flag_const);
+ SET_ACCESS(edef, v)
+ SET_ACCESS(edef, t)
+ set_vflag(v, vflag_builtin);
}
env_pop(env, scope);
return GW_OK;
CHECK_BB(scan0_enum_def(env, def));
CHECK_BB(scan1_enum_def(env, def));
// CHECK_BB(scan2_enum_def(env, def));
- return check_enum_def(env, def);
+ // return check_enum_def(env, def);
+ return GW_OK;
}
ANN m_bool traverse_fptr_def(const Env env, const Fptr_Def def) {