ANN Map env_label(const Env);
ANN Type scan_type(const Env, const Type, const Type_Decl*);
ANN Type type_decl_resolve(const Env, const Type_Decl*);
+ANN Value mk_class(const Env env, const Type base);
// tl2str returns a mp_alloced string
ANEW ANN m_str tl2str(const Env, const Type_List); // in type_decl.c
ANN m_bool compat_func(const __restrict__ Func_Def, const __restrict__ Func_Def);
mp_free(((Gwion)gwion)->mp, ArrayInfo, info);
}
-static GACK(gack_array) {
- printf("%s", t->name);
-}
-
GWION_IMPORT(array) {
const Type t_array = gwi_class_ini(gwi, "@Array", NULL);
gwi->gwion->type[et_array] = t_array;
gwi_class_xtor(gwi, NULL, array_dtor);
- GWI_BB(gwi_gack(gwi, t_array, gack_array))
GWI_BB(gwi_item_ini(gwi, "@internal", "@array"))
GWI_BB(gwi_item_end(gwi, 0, NULL))
return GW_ERROR;
}
+
+ANN static Type class_type(const Env env, const Type base) {
+ const Type t = type_copy(env->gwion->mp, env->gwion->type[et_class]);
+ t->e->ctx = base->e->ctx;
+ t->e->d.base_type = base;
+ return t;
+}
+
+ANN Value mk_class(const Env env, const Type base) {
+ const Type t = class_type(env, base);
+ const Symbol sym = insert_symbol(base->name);
+ const Value v = new_value(env->gwion->mp, t, s_name(sym));
+ // set from
+ v->from->owner = base->e->owner;
+ SET_FLAG(v, const | ae_flag_checked);
+ // should we add t to front, too?
+ nspc_add_value_front(base->e->owner, sym, v);
+ return v;
+}
return t->e->d.base_type;
}
-ANN Type array_type(const Env env, const Type src, const m_uint depth) {
- m_uint i = depth + 1;
- if(depth > 1)
- array_type(env, src, depth-1);
+ANN static Symbol array_sym(const Env env, const Type src, const m_uint depth) {
size_t len = strlen(src->name);
char name[len + 2* depth + 1];
strcpy(name, src->name);
+ m_uint i = depth + 1;
while(--i) {
strcpy(name+len, "[]");
len += 2;
}
- const Symbol sym = insert_symbol(name);
+ return insert_symbol(name);
+}
+
+ANN Type array_type(const Env env, const Type src, const m_uint depth) {
+ const Symbol sym = array_sym(env, src, depth);
const Type type = nspc_lookup_type1(src->e->owner, sym);
if(type)
return type;
- const Type t = new_type(env->gwion->mp, env->gwion->type[et_array]->xid, src->name, env->gwion->type[et_array]);
- t->name = s_name(sym);
- t->size = SZ_INT;
+ const Type t = new_type(env->gwion->mp, env->gwion->type[et_array]->xid,
+ s_name(sym), env->gwion->type[et_array]);
t->array_depth = depth + src->array_depth;
t->e->d.base_type = array_base(src) ?: src;
- t->nspc = env->gwion->type[et_array]->nspc;
- ADD_REF(t->nspc);
- SET_FLAG(t, checked);
t->e->owner = src->e->owner;
+ ADD_REF((t->nspc = env->gwion->type[et_array]->nspc))
+ SET_FLAG(t, checked);
+ mk_class(env, t); // maybe add_type_front could go in mk_class ?
nspc_add_type_front(src->e->owner, sym, t);
return t;
}
ANN static Type check_exp_typeof(const Env env, const Exp_Typeof *exp) {
DECL_OO(const Type, t, = check_exp(env, exp->exp))
- if(!t->array_depth) {
- DECL_OO(Value, v, = nspc_lookup_value1(t->e->owner, insert_symbol(t->name)))
- return v->type;
- }
- return t;
+ DECL_OO(Value, v, = nspc_lookup_value1(t->e->owner, insert_symbol(t->name)))
+ return v->type;
}
static const _type_func exp_func[] = {
return type;
}
-ANN static Value mk_class(const Env env, const Type base) {
- const Symbol sym = insert_symbol(base->name);
- const Type t = type_copy(env->gwion->mp, env->gwion->type[et_class]);
-//t->e->ctx = env->context;
-t->e->ctx = base->e->ctx;
- const Value v = new_value(env->gwion->mp, t, s_name(sym));
- t->e->d.base_type = base;
-// set from
- v->from->owner = base->e->owner;
- SET_FLAG(v, const | ae_flag_checked);
- nspc_add_value_front(base->e->owner, sym, v);
- return v;
-}
-
ANN static inline m_bool scan0_defined(const Env env, const Symbol s, const loc_t pos) {
if(nspc_lookup_type0(env->curr, s))
ERR_B(pos, _("type '%s' already defined"), s_name(s));