m_str name;
Nspc nspc;
struct TypeInfo_ *info;
- size_t xid;
size_t size;
size_t array_depth;
uint16_t ref;
REF_FUNC(Type, type)
FLAG_FUNC(Type, t)
-ANN2(1,3) ANEW Type new_type(MemPool, const m_uint xid, const m_str name, const Type);
+ANN2(1,2) ANEW Type new_type(MemPool, const m_str name, const Type);
ANEW ANN Type type_copy(MemPool, const Type type);
ANN m_str get_type_name(const Env, const Type t, const m_uint);
ANN Value find_value(const Type, const Symbol);
#define __IMPORT_TYPE
ANN2(1,2) ANEW Type gwi_mk_type(const Gwi, const m_str, const m_uint, const m_str);
-ANN m_int gwi_add_type(const Gwi gwi, Type type);
-ANN m_int gwi_set_global_type(const Gwi gwi, const Type type, const type_enum te);
+ANN void gwi_add_type(const Gwi gwi, Type type);
+ANN void gwi_set_global_type(const Gwi gwi, const Type type, const type_enum te);
#endif
SET_FLAG(v, global);
set_vflag(v, vflag_builtin);
set_tflag(type, tflag_scan0 | tflag_scan1 | tflag_scan2 | tflag_check | tflag_emit);
- type->xid = ++env->scope->type_xid;
}
ANN m_bool type_engine_check_prog(const Env env, const Ast ast) {
}
-Type new_type(MemPool p, const m_uint xid, const m_str name, const Type parent) {
+Type new_type(MemPool p, const m_str name, const Type parent) {
const Type type = mp_calloc(p, Type);
- type->xid = xid;
type->name = name;
type->info = mp_calloc(p, TypeInfo);
type->info->parent = parent;
}
ANN Type type_copy(MemPool p, const Type type) {
- const Type a = new_type(p, type->xid, type->name, type->info->parent);
+ const Type a = new_type(p, type->name, type->info->parent);
a->nspc = type->nspc;
a->info->owner = type->info->owner;
a->info->owner_class = type->info->owner_class;
}
ANN m_bool isa(const restrict Type var, const restrict Type parent) {
- return (var->xid == parent->xid) ? GW_OK : var->info->parent ? isa(var->info->parent, parent) : GW_ERROR;
+ return (var == parent) ? GW_OK : var->info->parent ? isa(var->info->parent, parent) : GW_ERROR;
}
ANN Type find_common_anc(const restrict Type lhs, const restrict Type rhs) {
const Type type = nspc_lookup_type1(src->info->owner, sym);
if(type)
return type;
- const Type t = new_type(env->gwion->mp, ++env->scope->type_xid,
- s_name(sym), env->gwion->type[et_array]);
+ const Type t = new_type(env->gwion->mp, s_name(sym), env->gwion->type[et_array]);
t->array_depth = depth + src->array_depth;
t->info->base_type = array_base(src) ?: src;
t->info->owner = src->info->owner;
if(tmpl)
nspc_pop_type(gwi->gwion->mp, gwi->gwion->env->curr);
CHECK_OO(p)
- const Type t = new_type(gwi->gwion->mp, ++gwi->gwion->env->scope->type_xid, s_name(ck.sym), p);
+ const Type t = new_type(gwi->gwion->mp, s_name(ck.sym), p);
t->info->cdef = new_class_def(gwi->gwion->mp, 0, ck.sym, td, NULL, loc(gwi));
t->info->cdef->base.tmpl = tmpl;
t->info->cdef->base.type = t;
ANN Type gwi_struct_ini(const Gwi gwi, const m_str name) {
struct ImportCK ck = { .name=name };
CHECK_BO(check_typename_def(gwi, &ck))
- const Type t = new_type(gwi->gwion->mp, ++gwi->gwion->env->scope->type_xid, s_name(ck.sym), gwi->gwion->type[et_compound]);
+ const Type t = new_type(gwi->gwion->mp, s_name(ck.sym), gwi->gwion->type[et_compound]);
set_tflag(t, tflag_struct);
if(!ck.tmpl)
gwi_type_flag(t);
ANN2(1,2) Type gwi_mk_type(const Gwi gwi, const m_str name, const m_uint size, const m_str parent_name) {
CHECK_OO(gwi_str2sym(gwi, name))
const Type parent = get_parent(gwi, parent_name);
- const Type t = new_type(gwi->gwion->mp, 0, name, parent);
+ const Type t = new_type(gwi->gwion->mp, name, parent);
t->size = size;
return t;
}
-ANN m_int gwi_add_type(const Gwi gwi, const Type type) {
- env_add_type(gwi->gwion->env, type);
- return (m_int)type->xid;
+ANN void gwi_add_type(const Gwi gwi, const Type type) {
+ return env_add_type(gwi->gwion->env, type);
}
-ANN m_int gwi_set_global_type(const Gwi gwi, const Type type, const type_enum te) {
+ANN void gwi_set_global_type(const Gwi gwi, const Type type, const type_enum te) {
gwi->gwion->type[te] = type;
- return gwi_add_type(gwi, type);
+ gwi_add_type(gwi, type);
}
if(a->info->type == env->gwion->type[et_null] &&
b->info->type->array_depth > 1)
return a->info->type;
- ARRAY_OPCK(a, b, pos)
+ ARRAY_OPCK(a, b, pos)
if(a->info->type->array_depth == b->info->type->array_depth + 1)
return a->info->type;
else if(a->info->type->array_depth == b->info->type->array_depth)
Exp e = array->exp;
do CHECK_BO(check_implicit(env, e, t_int))
while((e = e->next));
- const Type t = array->type;
+ const Type t = array->type->array_depth ? array->type : typedef_base(array->type);
if(t->array_depth >= array->depth)
return array_type(env, array_base(t), t->array_depth - array->depth);
- const Exp curr = take_exp(array->exp, array->type->array_depth);
- struct Array_Sub_ next = { curr->next, array_base(array->type), array->depth - array->type->array_depth };
+ const Exp curr = take_exp(array->exp, t->array_depth);
+ struct Array_Sub_ next = { curr->next, array_base(t), array->depth - t->array_depth };
return check_array_access(env, &next);
}
return !tflag(l, tflag_nonnull) && tflag(r, tflag_nonnull);
}
-static inline Type check_nonnull(const Env env, const Type l, const Type r,
+ANN static inline Type check_nonnull(const Env env, const Type l, const Type r,
const m_str action, const loc_t pos) {
if(tflag(r, tflag_nonnull)) {
if(isa(l, env->gwion->type[et_null]) > 0)
ERR_N(pos, _("can't %s '%s' to '%s'"), action, l->name, r->name);
- if(isa(l, r) < 0)
+ if(isa(l, unflag_type(r)) < 0)
ERR_N(pos, _("can't %s '%s' to '%s'"), action, l->name, r->name);
return r->info->parent;
}
static m_bool op_match(const restrict Type t, const restrict Type mo) {
if(t == OP_ANY_TYPE || mo == OP_ANY_TYPE)
return GW_OK;
- Type type = t;
- if((type && mo && mo->xid == type->xid) || (!type && !mo))
- return GW_OK;
- return 0;
+ if(t && mo)
+ return unflag_type(t) == unflag_type(mo);
+ return t == mo;
}
ANN2(1) static M_Operator* operator_find(const Vector v, const restrict Type lhs, const restrict Type rhs) {
return NULL;
}
-static m_bool op_match2(const restrict Type t, const restrict Type mo) {
-// if(t == OP_ANY_TYPE || mo == OP_ANY_TYPE)
-// return GW_OK;
- if((t && mo && (t != OP_ANY_TYPE && mo != OP_ANY_TYPE && mo->xid == t->xid)) || (!t && !mo))
- return GW_OK;
- return 0;
-}
-
ANN2(1) static M_Operator* operator_find2(const Vector v, const restrict Type lhs, const restrict Type rhs) {
for(m_uint i = vector_size(v) + 1; --i;) {
M_Operator* mo = (M_Operator*)vector_at(v, i - 1);
- if(op_match2(lhs, mo->lhs) && op_match2(rhs, mo->rhs))
+ if(lhs == mo->lhs && rhs == mo->rhs)
return mo;
}
return NULL;
const Vector v = (Vector)map_get(&n->info->op_map, (vtype)opi->op);
for(m_uint i = vector_size(v) + 1; --i;) {
M_Operator* mo = (M_Operator*)vector_at(v, i - 1);
- if(op_match2(opi->lhs, mo->lhs) && op_match2(opi->rhs, mo->rhs)) {
+ if(opi->lhs == mo->lhs && opi->rhs == mo->rhs) {
opi->data = (uintptr_t)mo;
opi->ret = (Type)&VPTR(v, i-1);
VPTR(v, i-1) = 0;
env->context->global = 1;
}
-static inline Type scan0_type(const Env env, const m_uint xid,
- const m_str name, const Type t) {
- const Type type = new_type(env->gwion->mp, xid, name, t);
+static inline Type scan0_type(const Env env, const m_str name, const Type t) {
+ const Type type = new_type(env->gwion->mp, name, t);
type->info->ctx = env->context;
return type;
}
CHECK_BB(env_access(env, fptr->base->flag, td_pos(fptr->base->td)))
CHECK_BB(scan0_defined(env, fptr->base->xid, td_pos(fptr->base->td)));
const m_str name = s_name(fptr->base->xid);
- const Type t = scan0_type(env, env->gwion->type[et_fptr]->xid, name, env->gwion->type[et_fptr]);
+ const Type t = scan0_type(env, name, env->gwion->type[et_fptr]);
t->info->owner = !(!env->class_def && GET_FLAG(fptr->base, global)) ?
env->curr : env->global_nspc;
t->info->owner_class = env->class_def;
}
ANN static void typedef_simple(const Env env, const Type_Def tdef, const Type base) {
- const Type t = scan0_type(env, ++env->scope->type_xid, s_name(tdef->xid), base);
+ const Type t = scan0_type(env, s_name(tdef->xid), base);
t->size = base->size;
const Nspc nspc = (!env->class_def && GET_FLAG(tdef->ext, global)) ?
env->global_nspc : env->curr;
ANN static Type enum_type(const Env env, const Enum_Def edef) {
const Type t = type_copy(env->gwion->mp, env->gwion->type[et_int]);
- t->xid = ++env->scope->type_xid;
const Symbol sym = scan0_sym(env, "enum", edef->pos);
t->name = edef->xid ? s_name(edef->xid) : s_name(sym);
t->info->parent = env->gwion->type[et_int];
ANN static Type union_type(const Env env, const Symbol s, const m_bool add) {
const m_str name = s_name(s);
const Type t = type_copy(env->gwion->mp, env->gwion->type[et_union]);
- t->xid = ++env->scope->type_xid;
t->name = name;
t->nspc = new_nspc(env->gwion->mp, name);
t->info->owner = t->nspc->parent = env->curr;
const Type parent = get_parent(env, cdef);
if(parent == (Type)GW_ERROR)
return NULL;
- const Type t = scan0_type(env, ++env->scope->type_xid, s_name(cdef->base.xid), parent);
+ const Type t = scan0_type(env, s_name(cdef->base.xid), parent);
if(cflag(cdef, cflag_struct))
set_tflag(t, tflag_struct);
t->info->tuple = new_tupleform(env->gwion->mp, parent);
ANN static Type func_type(const Env env, const Func func) {
const Type base = env->gwion->type[!fbflag(func->def->base, fbflag_lambda) ? et_function : et_lambda];
const Type t = type_copy(env->gwion->mp, base);
- t->xid = ++env->scope->type_xid;
t->info->parent = base;
t->name = func->name;
t->info->owner = env->curr;