ANN Func_Def cpy_func_def(MemPool, Func_Def);
ANN struct Func_Base_* cpy_func_base(MemPool, struct Func_Base_*);
ANN Class_Def cpy_class_def(MemPool, Class_Def);
+ANN Type_List cpy_type_list(MemPool p, const Type_List src);
#endif
static inline Type new_force_type(MemPool p, const Type t, const Symbol sym) {
const Type ret = type_copy(p, t);
+ if(ret->nspc)
+ ADD_REF(ret->nspc)
ret->name = s_name(sym);
ret->flag = t->flag | ae_flag_force;
map_set(&t->e->owner->info->type->map, (vtype)sym, (vtype)ret);
static DTOR(shred_dtor) {
VM *vm = ME(o)->info->vm;
free_vm_shred(ME(o));
- if(isa(o->type_ref, t_fork) > 0)
+ if(isa(o->type_ref, t_fork) > 0) {
+//gwion_end(vm->gwion);
+// mp_free(shred->info->mp, Gwion, vm->gwion);
free_vm(vm);
}
+}
static MFUN(shred_lock) {
MUTEX_LOCK(ME(o)->tick->shreduler->mutex);
static DTOR(fork_dtor) {
THREAD_JOIN(FORK_THREAD(o));
- mp_free(shred->info->mp, Gwion, ME(o)->info->vm->gwion);
+// mp_free(shred->info->mp, Gwion, ME(o)->info->vm->gwion);
}
static MFUN(fork_join) {
const Type v_type = type_copy(env->gwion->mp, t_class);
v_type->e->d.base_type = type;
SET_FLAG(type, builtin);
- nspc_add_type(env->curr, insert_symbol(type->name), type);
-// map_set(&env->curr->info->type->map, insert_symbol(type->name), type);
-// map_set(vector_back(&env->curr->info->type->ptr), insert_symbol(type->name), type);
- const Value v = new_value(env->gwion->mp, v_type, type->name);
+ const Symbol sym = insert_symbol(type->name);
+ map_set(&env->curr->info->type->map, (vtype)sym, (vtype)type);
+ const Value v = new_value(env->gwion->mp, v_type, s_name(sym));
SET_FLAG(v, checked | ae_flag_const | ae_flag_global | ae_flag_builtin);
nspc_add_value(env->curr, insert_symbol(type->name), v);
type->e->owner = env->curr;
if(a->info->op_map.ptr)
free_op_map(&a->info->op_map, gwion);
nspc_free_type(a, gwion);
-
if(a->info->class_data)
mp_free2(gwion->mp, a->info->class_data_size, a->info->class_data);
if(a->info->vtable.ptr)
ANN static Type prim_str(const Env env, Exp_Primary *const prim) {
if(!prim->value) {
const m_str str = prim->d.str;
- const Value v = new_value(env->gwion->mp, t_string, str);
char c[strlen(str) + 8];
sprintf(c, "%s:string", str);
- nspc_add_value(env_nspc(env), insert_symbol(c), v);
- prim->value = v;
+ const Symbol sym = insert_symbol(c);
+ const Value exist = nspc_lookup_value0(env->global_nspc, sym);
+ if(exist)
+ prim->value = exist;
+ else {
+ const Value v = new_value(env->gwion->mp, t_string, s_name(sym));
+ nspc_add_value(env->global_nspc, sym, v);
+ prim->value = v;
+ }
}
return t_string;
}
}
ANN static Func _find_template_match(const Env env, const Value v, const Exp_Call* exp) {
-CHECK_BO(check_call(env, exp))
+ CHECK_BO(check_call(env, exp))
const Type_List types = exp->tmpl->call;
Func m_func = NULL, former = env->func;
DECL_OO(const m_str, tmpl_name, = tl2str(env, types))
Func_Base *fbase = cpy_func_base(env->gwion->mp, base->base);
fbase->xid = sym;
fbase->tmpl->base = 0;
- fbase->tmpl->call = types;
+ fbase->tmpl->call = cpy_type_list(env->gwion->mp, types);
if(template_push_types(env, fbase->tmpl) > 0) {
const Fptr_Def fptr = new_fptr_def(env->gwion->mp, fbase, base->flag);
if(value) {
continue;
const Func_Def fdef = (Func_Def)cpy_func_def(env->gwion->mp, value->d.func_ref->def);
SET_FLAG(fdef, template);
- fdef->base->tmpl->call = types;
+ fdef->base->tmpl->call = cpy_type_list(env->gwion->mp, types);
fdef->base->tmpl->base = i;
if((m_func = ensure_tmpl(env, fdef, exp)))
break;
if(f) {
Tmpl* tmpl = new_tmpl_call(env->gwion->mp, func->tmpl->call);
tmpl->list = v->d.func_ref ? v->d.func_ref->def->base->tmpl->list : func->func->type->e->d.func->def->base->tmpl->list;
+// tmpl->list = cpy_id_list(env->gwion->mp, tmpl->list);
((Exp_Call*)func)->tmpl = tmpl;
return ((Exp_Call*)func)->m_func = f;
}
CHECK_BO(check_exp_call1_check(env, exp->func))
if(exp->func->type == t_lambda)
return check_lambda_call(env, exp);
- if(GET_FLAG(exp->func->type->e->d.func, ref)) {
- const Value value = exp->func->type->e->d.func->value_ref;
- CHECK_BO(traverse_class_def(env, value->owner_class->e->def))
- }
if(exp->args)
CHECK_OO(check_exp(env, exp->args))
if(GET_FLAG(exp->func->type, func))
ptr = type_decl_resolve(env, &td);
if(!GET_FLAG(ptr, checked))
check_class_def(env, ptr->e->def);
+// CHECK_BB(traverse_class_def(env, ptr->e->def))
}
t = depth ? array_type(env, ptr, depth) : ptr;
stmt->v = new_value(env->gwion->mp, t, s_name(stmt->sym));
ANN static Stmt cpy_stmt(MemPool p, const Stmt src);
ANN static Exp cpy_exp(MemPool p, const Exp src);
ANN static ID_List cpy_id_list(MemPool p, const ID_List src);
-ANN static Type_List cpy_type_list(MemPool p, const Type_List src);
+ANN Type_List cpy_type_list(MemPool p, const Type_List src);
ANN static Arg_List cpy_arg_list(MemPool p, const Arg_List src);
ANN Class_Def cpy_class_def(MemPool p, const Class_Def src);
ANN static Stmt_List cpy_stmt_list(MemPool p, const Stmt_List src);
return a;
}
-ANN static Type_List cpy_type_list(MemPool p, const Type_List src) {
+ANN Type_List cpy_type_list(MemPool p, const Type_List src) {
Type_List a = mp_calloc(p, Type_List);
if(src->td)
a->td = cpy_type_decl(p, src->td); // 1
static inline void add_type(const Env env, const Nspc nspc, const Type t) {
map_set(&nspc->info->type->map, (m_uint)insert_symbol(t->name), (m_uint)t);
-// map_set((Map)vector_front((Vector)&nspc->info->type->ptr), (m_uint)insert_symbol(t->name), (m_uint)t);
}
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, t_class);
- const Value v = new_value(env->gwion->mp, t, base->name);
+ const Value v = new_value(env->gwion->mp, t, s_name(sym));
t->e->d.base_type = base;
v->owner = base->e->owner;
SET_FLAG(v, const | ae_flag_checked);
- nspc_add_value(base->e->owner, insert_symbol(base->name), v);
+ map_set(&base->e->owner->info->value->map, sym, v);
return v;
}
ANN static void typedef_fptr(const Env env, const Type_Def tdef, const Type base) {
tdef->type = type_copy(env->gwion->mp, base);
+ ADD_REF(tdef->type->nspc)
tdef->type->name = s_name(tdef->xid);
tdef->type->e->parent = base;
add_type(env, env->curr, tdef->type);
} else {
const Nspc nspc = !GET_FLAG(udef, global) ?
env->curr : env->global_nspc;
-// TODO make unique names
- const Type t = union_type(env, nspc, insert_symbol("union"), 1);
- udef->value = new_value(env->gwion->mp, t, "union");
+ char name[7 + strlen(env->name) + 1]; // add pos
+ sprintf(name, "@union:%s", env->name);
+ const Symbol sym = insert_symbol(name);
+ const Type t = union_type(env, nspc, sym, 1);
+ udef->value = new_value(env->gwion->mp, t, s_name(sym));
udef->value->owner_class = env->class_def;
udef->value->owner = nspc;
nspc_add_value(nspc, udef->xid, udef->value);
- char c[16];
- sprintf(c, "%p", udef);
- nspc_add_type(nspc, insert_symbol(c), t);
+ add_type(env, nspc, t);
SET_FLAG(udef->value, checked | udef->flag);
SET_FLAG(t, scan1);
}
const Type t = new_type(env->gwion->mp, ++env->scope->type_xid, s_name(cdef->base.xid), t_object);
t->e->owner = env->curr;
t->nspc = new_nspc(env->gwion->mp, t->name);
- t->nspc->parent = (GET_FLAG(cdef, global) ? env_nspc(env) : env->curr);
+// t->nspc->parent = GET_FLAG(cdef, global) ? env_nspc(env) : env->curr;
+ t->nspc->parent = GET_FLAG(cdef, global) ? env->global_nspc : env->curr;
t->e->def = cdef;
t->flag = cdef->flag;
if(!strstr(t->name, "<"))
CHECK_BB(scan2_args(env, def))
} else
SET_FLAG(fptr->type, func);
- nspc_add_func(fptr->type->e->owner, fptr->base->xid, fptr->base->func);
return GW_OK;
}
ANN2(1,2) static Value func_value(const Env env, const Func f,
const Value overload) {
const Type t = func_type(env, f);
- const Value v = new_value(env->gwion->mp, t, t->name);
+ const Value v = new_value(env->gwion->mp, t, s_name(insert_symbol(t->name)));
CHECK_OO(scan2_func_assign(env, f->def, f, v))
if(!overload) {
ADD_REF(v);
ANN m_bool scanx_cdef(const Env env, void* opt, const Class_Def cdef,
const _exp_func f_cdef, const _exp_func f_union) {
- if(cdef->base.type->e->parent != t_union)
+ if(cdef->base.type && cdef->base.type->e->parent != t_union)
return f_cdef(opt, cdef);
CHECK_BB(template_push_types(env, cdef->base.tmpl))
const m_bool ret = f_union(opt, cdef->union_def);
DECL_OO(const Symbol, name, = template_id(env, def, call))
if(env->class_def && name == insert_symbol(env->class_def->name))
return env->class_def->e->def;
- const Type t = nspc_lookup_type1(env->curr, name);
+ const Type t = nspc_lookup_type0(env->curr, name);
if(t)
return t->e->def;
const Class_Def c = cpy_class_def(env->gwion->mp, def);
ANN Tmpl* mk_tmpl(const Env env, const Type t, const Tmpl *tm, const Type_List types) {
Tmpl *tmpl = new_tmpl(env->gwion->mp, get_total_type_list(env, t, tm), 0);
- tmpl->call = types;
+ tmpl->call = cpy_type_list(env->gwion->mp, types);
return tmpl;
}
a->base.tmpl = mk_tmpl(env, t, t->e->def->base.tmpl, type->types);
if(t->e->parent != t_union) {
CHECK_BO(scan0_class_def(env, a))
- map_set(&t->e->owner->info->type->map, (vtype)a->base.xid, (vtype)a->base.type);
- map_set((Map)vector_front((Vector)&t->e->owner->info->type->ptr), (vtype)a->base.xid, (vtype)a->base.type);
+ map_set(&env->curr->info->type->map, (vtype)a->base.xid, (vtype)a->base.type);
} else {
a->union_def = new_union_def(env->gwion->mp, a->list, t->e->def->pos);
a->union_def->type_xid = a->base.xid;
if(base_type)
return base_type;
const Type ret = type_copy(env->gwion->mp, t);
+ ADD_REF(ret->nspc)
ret->e->parent = t;
ret->name = s_name(sym);
SET_FLAG(ret, func);
- nspc_add_type(env->curr, sym, ret);
+ map_set(&t->e->owner->info->type->map, sym, ret);
const Func_Def def = cpy_func_def(env->gwion->mp, t->e->d.func->def);
const Func func = ret->e->d.func = new_func(env->gwion->mp, s_name(sym), def);
const Value value = new_value(env->gwion->mp, ret, s_name(sym));
func->value_ref = value;
func->def->base->tmpl = mk_tmpl(env, t, t->e->d.func->def->base->tmpl, type->types);
def->base->func = func;
- nspc_add_value(env->curr, sym, value);
+ map_set(&t->e->owner->info->value->map, sym, value); // to base ?
return ret;
}
ERR_O(type->xid->pos,
ANN m_bool traverse_class_def(const Env env, const Class_Def def) {
if(!GET_FLAG(def, scan1))
CHECK_BB(scan1_class_def(env, def))
- CHECK_BB(scan2_class_def(env, def))
+ if(!GET_FLAG(def, scan2))
+ CHECK_BB(scan2_class_def(env, def))
return check_class_def(env, def);
}
if(exist)
return exist;
const Type t = type_copy(env->gwion->mp, ret);
+ if(t->nspc)
+ ADD_REF(t->nspc)
t->name = s_name(sym);
t->e->parent = ret;
SET_FLAG(t, nonnull);