From: fennecdjay Date: Mon, 9 Nov 2020 01:08:40 +0000 (+0100) Subject: :art: Improve Type X-Git-Tag: nightly~1188 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=26e4e778abfc85a39bbab72c5edf44f54d2de0e9;p=gwion.git :art: Improve Type --- diff --git a/include/env/type.h b/include/env/type.h index 5314dbb8..87c481e3 100644 --- a/include/env/type.h +++ b/include/env/type.h @@ -8,11 +8,9 @@ struct TypeInfo_ { union { Union_Def udef; Class_Def cdef; - }; - union type_data { Func func; Type base_type; - } d; + }; struct TupleForm_* tuple; struct VM_Code_ *gack; struct Context_ *ctx; @@ -44,7 +42,7 @@ enum tflag { struct Type_ { m_str name; Nspc nspc; - struct TypeInfo_ *e; + struct TypeInfo_ *info; size_t xid; size_t size; size_t array_depth; @@ -94,9 +92,9 @@ ANN void inherit(const Type); __attribute__((returns_nonnull)) ANN static inline Type get_gack(Type t) { - do if(t->e->gack) + do if(t->info->gack) return t; - while((t = t->e->parent)); + while((t = t->info->parent)); return t; // unreachable } diff --git a/include/gwion.h b/include/gwion.h index caf36790..a9dda19b 100644 --- a/include/gwion.h +++ b/include/gwion.h @@ -28,11 +28,11 @@ ANN void push_global(const Gwion gwion, const m_str name); ANN Nspc pop_global(const Gwion gwion); __attribute__((returns_nonnull)) ANN static inline Value type_value(const Gwion gwion, const Type t) { - return (Value)nspc_lookup_value1(t->e->owner, insert_symbol(gwion->st, t->name)); + return (Value)nspc_lookup_value1(t->info->owner, insert_symbol(gwion->st, t->name)); } __attribute__((returns_nonnull)) ANN static inline Type type_class(const Gwion gwion, const Type t) { - const Value v = nspc_lookup_value1(t->e->owner, insert_symbol(gwion->st, t->name)); + const Value v = nspc_lookup_value1(t->info->owner, insert_symbol(gwion->st, t->name)); return v->type; } #endif diff --git a/src/emit/emit.c b/src/emit/emit.c index 5155219c..4fc29dd7 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -78,15 +78,15 @@ ANN static inline void frame_push(Frame* frame) { } ANN static void struct_pop(const Emitter emit, const Type type, const m_uint offset) { - if(!type->e->tuple) + if(!type->info->tuple) return; - for(m_uint i = 0; i < vector_size(&type->e->tuple->types); ++i) { - const Type t = (Type)vector_at(&type->e->tuple->types, i); + for(m_uint i = 0; i < vector_size(&type->info->tuple->types); ++i) { + const Type t = (Type)vector_at(&type->info->tuple->types, i); if(isa(t, emit->gwion->type[et_object]) > 0) { const Instr instr = emit_add_instr(emit, ObjectRelease); - instr->m_val = offset + vector_at(&type->e->tuple->offset, i); + instr->m_val = offset + vector_at(&type->info->tuple->offset, i); } else if(tflag(t, tflag_struct)) - struct_pop(emit, t, offset + vector_at(&type->e->tuple->offset, i)); + struct_pop(emit, t, offset + vector_at(&type->info->tuple->offset, i)); } } @@ -171,11 +171,11 @@ ANN static inline void maybe_ctor(const Emitter emit, const Type t) { } ANN static void emit_pre_ctor(const Emitter emit, const Type type) { - if(type->e->parent) - emit_pre_ctor(emit, type->e->parent); + if(type->info->parent) + emit_pre_ctor(emit, type->info->parent); maybe_ctor(emit, type); - if(tflag(type, tflag_typedef) && type->e->parent->array_depth) - emit_array_extend(emit, type->e->parent, type->e->cdef->base.ext->array->exp); + if(tflag(type, tflag_typedef) && type->info->parent->array_depth) + emit_array_extend(emit, type->info->parent, type->info->cdef->base.ext->array->exp); } #define regxxx(name, instr) \ @@ -438,7 +438,7 @@ ANN static m_bool emit_prim_range(const Emitter emit, Range **data) { ANN m_bool emit_array_access(const Emitter emit, struct ArrayAccessInfo *const info) { if(tflag(info->array.type, tflag_typedef)) { - info->array.type = info->array.type->e->parent; + info->array.type = info->array.type->info->parent; return emit_array_access(emit, info); } // look mum no pos @@ -720,9 +720,12 @@ ANN static m_bool emit_class_def(const Emitter, const Class_Def); ANN static m_bool emit_cdef(const Emitter, const Type); ANN static inline m_bool ensure_emit(const Emitter emit, const Type t) { + const Type base = get_type(t); + if(tflag(base, tflag_emit) || !(tflag(base, tflag_cdef) || tflag(base, tflag_udef))) + return GW_OK;//clean callers struct EnvSet es = { .env=emit->env, .data=emit, .func=(_exp_func)emit_cdef, .scope=emit->env->scope->depth, .flag=tflag_emit }; - return envset_run(&es, t); + return envset_run(&es, base); } ANN static m_bool emit_decl(const Emitter emit, const Exp_Decl* decl) { @@ -744,8 +747,7 @@ ANN static m_bool emit_decl(const Emitter emit, const Exp_Decl* decl) { ANN /*static */m_bool emit_exp_decl(const Emitter emit, const Exp_Decl* decl) { const Type t = get_type(decl->type); - if(!tflag(t, tflag_emit)) - CHECK_BB(ensure_emit(emit, t)) + CHECK_BB(ensure_emit(emit, t)) const m_bool global = GET_FLAG(decl->td, global); const m_uint scope = !global ? emit->env->scope->depth : emit_push_global(emit); const m_bool ret = emit_decl(emit, decl); @@ -808,7 +810,7 @@ ANN static m_bool emit_exp_call(const Emitter emit, const Exp_Call* exp_call) { if(exp_call->m_func) CHECK_OB(emit_exp_call1(emit, exp_call->m_func)) else { - struct Op_Import opi = { .op=insert_symbol("@ctor"), .rhs=exp_call->func->info->type->e->d.base_type, + struct Op_Import opi = { .op=insert_symbol("@ctor"), .rhs=exp_call->func->info->type->info->base_type, .data=(uintptr_t)exp_call, .pos=exp_self(exp_call)->pos, .op_type=op_exp }; CHECK_OB(op_emit(emit, &opi)) } @@ -1258,8 +1260,7 @@ ANN Instr emit_exp_spork(const Emitter emit, const Exp_Unary* unary) { ANN static m_bool emit_exp_unary(const Emitter emit, const Exp_Unary* unary) { const Type t = exp_self(unary)->info->type; const Type base = get_type(actual_type(emit->gwion, t)); - if(base->e->cdef && !tflag(base, tflag_emit)) // ??? - CHECK_BB(ensure_emit(emit, base)) + CHECK_BB(ensure_emit(emit, base)) // no pos ? struct Op_Import opi = { .op=unary->op, .data=(uintptr_t)unary, .op_type=op_unary }; if(unary->op != insert_symbol("spork") && unary->op != insert_symbol("fork") && unary->exp) { @@ -1327,16 +1328,16 @@ DECL_EXP_FUNC(emit, m_bool, Emitter) ANN static void struct_addref(const Emitter emit, const Type type, const m_int size, const m_bool offset, const m_bool emit_var) { - if(!type->e->tuple) + if(!type->info->tuple) return; - for(m_uint i = 0; i < vector_size(&type->e->tuple->types); ++i) { - const Type t = (Type)vector_at(&type->e->tuple->types, i); + for(m_uint i = 0; i < vector_size(&type->info->tuple->types); ++i) { + const Type t = (Type)vector_at(&type->info->tuple->types, i); if(isa(t, emit->gwion->type[et_object]) > 0) { const Instr instr = emit_addref(emit, emit_var); instr->m_val = size; - instr->m_val2 = vector_at(&type->e->tuple->offset, i); + instr->m_val2 = vector_at(&type->info->tuple->offset, i); } else if(tflag(t, tflag_struct)) - struct_addref(emit, t, size, offset + vector_at(&type->e->tuple->offset, i), emit_var); + struct_addref(emit, t, size, offset + vector_at(&type->info->tuple->offset, i), emit_var); } } @@ -1612,7 +1613,8 @@ ANN static m_bool emit_stmt_jump(const Emitter emit, const Stmt_Jump stmt) { } ANN static m_bool emit_type_def(const Emitter emit, const Type_Def tdef) { - return tdef->type->e->cdef ? emit_class_def(emit, tdef->type->e->cdef) : GW_OK; + return (!is_fptr(emit->gwion, tdef->type) && tdef->type->info->cdef) ? + emit_class_def(emit, tdef->type->info->cdef) : GW_OK; } ANN static m_bool emit_enum_def(const Emitter emit, const Enum_Def edef) { @@ -1903,7 +1905,7 @@ ANN static VM_Code emit_internal(const Emitter emit, const Func f) { const Instr instr = emit_add_instr(emit, RegPushMem); instr->m_val = SZ_INT; f->code = finalyze(emit, FuncReturn); - return emit->env->class_def->e->gack = f->code; + return emit->env->class_def->info->gack = f->code; } return finalyze(emit, FuncReturn); } @@ -2047,8 +2049,8 @@ ANN Code* emit_class_code(const Emitter emit, const m_str name) { } ANN static m_bool emit_parent(const Emitter emit, const Class_Def cdef) { - const Type parent = cdef->base.type->e->parent; - return !tflag(parent, tflag_emit) ? ensure_emit(emit, parent) : GW_OK; + const Type parent = cdef->base.type->info->parent; + return ensure_emit(emit, parent); } ANN static inline m_bool emit_cdef(const Emitter emit, const Type t) { @@ -2072,9 +2074,9 @@ ANN static m_bool emit_class_def(const Emitter emit, const Class_Def cdef) { if(tflag(t, tflag_emit)) return GW_OK; set_tflag(t, tflag_emit); - if(t->e->owner_class && !tflag(t->e->owner_class, tflag_emit)) - CHECK_BB(ensure_emit(emit, t->e->owner_class)) - if(cdef->base.ext && t->e->parent->e->cdef && !tflag(t->e->parent, tflag_emit)) // ????? + if(t->info->owner_class) + CHECK_BB(ensure_emit(emit, t->info->owner_class)) + if(cdef->base.ext && t->info->parent->info->cdef && !tflag(t->info->parent, tflag_emit)) // ????? CHECK_BB(cdef_parent(emit, cdef)) nspc_allocdata(emit->gwion->mp, t->nspc); if(cdef->body) { diff --git a/src/env/env.c b/src/env/env.c index b4729d3d..73c8e4f3 100644 --- a/src/env/env.c +++ b/src/env/env.c @@ -79,8 +79,8 @@ ANN void env_pop(const Env env, const m_uint scope) { } ANN void env_add_type(const Env env, const Type type) { - type->e->owner = env->curr; - type->e->owner_class = env->class_def; // t owner_class ? + type->info->owner = env->curr; + type->info->owner_class = env->class_def; // t owner_class ? const Symbol sym = insert_symbol(type->name); nspc_add_type_front(env->curr, sym, type); const Value v = mk_class(env, type); diff --git a/src/env/env_utils.c b/src/env/env_utils.c index a3661a45..58e556da 100644 --- a/src/env/env_utils.c +++ b/src/env/env_utils.c @@ -34,7 +34,7 @@ ANN Type __find_type(const Type type, const Symbol xid) { const Type t = nspc_lookup_type1(base->nspc, xid); if(t) return t; - base = base->e->parent; + base = base->info->parent; } return NULL; } @@ -70,9 +70,9 @@ ANN m_bool already_defined(const Env env, const Symbol s, const loc_t pos) { ANN static Type class_type(const Env env, const Type base) { const Type t_class = env->gwion->type[et_class]; const Type t = type_copy(env->gwion->mp, t_class); - t->e->parent = t_class; - t->e->ctx = base->e->ctx; - t->e->d.base_type = base; + t->info->parent = t_class; + t->info->ctx = base->info->ctx; + t->info->base_type = base; set_tflag(t, tflag_infer); return t; } @@ -84,7 +84,7 @@ ANN Value mk_class(const Env env, const Type base) { valuefrom(env, v->from); SET_FLAG(v, const); set_vflag(v, vflag_valid); - nspc_add_value_front(base->e->owner, sym, v); + nspc_add_value_front(base->info->owner, sym, v); return v; } diff --git a/src/env/envset.c b/src/env/envset.c index 5bfa468c..4ee189dd 100644 --- a/src/env/envset.c +++ b/src/env/envset.c @@ -7,26 +7,26 @@ ANN static void check(struct EnvSet *es, const Type t) { const Vector v = &es->env->scope->class_stack; - Type owner = t->e->owner_class; + Type owner = t->info->owner_class; for(vtype i = vector_size(v) + 1; owner && --i;) { if(owner != (Type)vector_at(v, i - 1)) { es->run = 1; return; } - owner = owner->e->owner_class; + owner = owner->info->owner_class; } } ANN static m_bool push(struct EnvSet *es, const Type t) { es->env->scope->depth = 0; - if(t->e->owner_class) - CHECK_BB(push(es, t->e->owner_class)) + if(t->info->owner_class) + CHECK_BB(push(es, t->info->owner_class)) else - env_push(es->env, NULL, t->e->ctx ? t->e->ctx->nspc : es->env->curr); + env_push(es->env, NULL, t->info->ctx ? t->info->ctx->nspc : es->env->curr); if(es->func && !(t->tflag & es->flag)) CHECK_BB(es->func((void*)es->data, t)) if(tflag(t, tflag_tmpl)) - CHECK_BB(template_push_types(es->env, t->e->cdef->base.tmpl)) // incorrect templates + CHECK_BB(template_push_types(es->env, t->info->cdef->base.tmpl)) // incorrect templates env_push_type((void*)es->env, t); return GW_OK; } @@ -49,8 +49,8 @@ ANN2(1) void envset_pop(struct EnvSet *es, const Type t) { return; if(tflag(t, tflag_tmpl)) nspc_pop_type(es->env->gwion->mp, es->env->curr); - if(t->e->owner_class) - envset_pop(es, t->e->owner_class); + if(t->info->owner_class) + envset_pop(es, t->info->owner_class); else env_pop(es->env, es->scope); } @@ -58,11 +58,11 @@ ANN2(1) void envset_pop(struct EnvSet *es, const Type t) { ANN m_bool envset_run(struct EnvSet *es, const Type t) { check(es, t); if(es->run) - CHECK_BB(push(es, t->e->owner_class)) - const m_bool ret = t->e->cdef && + CHECK_BB(push(es, t->info->owner_class)) + const m_bool ret = t->info->cdef && !(t->tflag & es->flag) ? es->func(es->data, t) : GW_OK; if(es->run) - envset_pop(es, t->e->owner_class); + envset_pop(es, t->info->owner_class); return ret; } diff --git a/src/env/nspc.c b/src/env/nspc.c index c92cd7bd..e219b1d2 100644 --- a/src/env/nspc.c +++ b/src/env/nspc.c @@ -26,10 +26,10 @@ ANN2(1,3) static inline void nspc_release_struct(const Nspc a, Value value, Gwio (vflag(value, vflag_builtin) && value->d.ptr))) { const m_bit *ptr = (value && value->d.ptr) ? (m_bit*)value->d.ptr: (m_bit*)(a->info->class_data + value->from->offset); - for(m_uint i = 0; i < vector_size(&value->type->e->tuple->types); ++i) { - const Type t = (Type)vector_at(&value->type->e->tuple->types, i); + for(m_uint i = 0; i < vector_size(&value->type->info->tuple->types); ++i) { + const Type t = (Type)vector_at(&value->type->info->tuple->types, i); if(isa(t, gwion->type[et_object]) > 0) - release(*(M_Object*)(ptr + vector_at(&value->type->e->tuple->offset, i)), gwion->vm->cleaner_shred); + release(*(M_Object*)(ptr + vector_at(&value->type->info->tuple->offset, i)), gwion->vm->cleaner_shred); else if(tflag(t, tflag_struct)) nspc_release_struct(t->nspc, NULL, gwion); } diff --git a/src/env/tupleform.c b/src/env/tupleform.c index 82fe1df2..b8a3fbf9 100644 --- a/src/env/tupleform.c +++ b/src/env/tupleform.c @@ -16,16 +16,16 @@ #include "array.h" ANN void tuple_info(const Env env, const Value v) { - const m_uint offset = vector_back(&env->class_def->e->tuple->offset); - vector_add(&env->class_def->e->tuple->types, (vtype)v->type); - vector_add(&env->class_def->e->tuple->offset, offset + v->type->size); + const m_uint offset = vector_back(&env->class_def->info->tuple->offset); + vector_add(&env->class_def->info->tuple->types, (vtype)v->type); + vector_add(&env->class_def->info->tuple->offset, offset + v->type->size); } ANN void tuple_contains(const Env env, const Value value) { const Type t = value->type; - if(!env->class_def->e->tuple || env->class_def == value->type) + if(!env->class_def->info->tuple || env->class_def == value->type) return; - const Vector v = &env->class_def->e->tuple->contains; + const Vector v = &env->class_def->info->tuple->contains; const m_int idx = vector_size(v) ? vector_find(v, (vtype)t) : -1; if(idx == -1) { type_addref(t); @@ -38,8 +38,8 @@ ANN2(1) TupleForm new_tupleform(MemPool p, const Type parent_type) { vector_init(&tuple->contains); vector_init(&tuple->types); vector_init(&tuple->offset); - if(parent_type && parent_type->e->tuple) { - const TupleForm parent = parent_type->e->tuple; + if(parent_type && parent_type->info->tuple) { + const TupleForm parent = parent_type->info->tuple; const m_uint sz = vector_size(&parent->types); tuple->start = parent->start + sz; if(sz) { diff --git a/src/env/type.c b/src/env/type.c index 9da87fe0..e28dd86c 100644 --- a/src/env/type.c +++ b/src/env/type.c @@ -15,25 +15,25 @@ ANN static inline m_bool freeable(const Type a) { ANN void free_type(const Type a, struct Gwion_ *const gwion) { if(freeable(a)) { if(tflag(a, tflag_udef)) - free_union_def(gwion->mp, a->e->udef); + free_union_def(gwion->mp, a->info->udef); if(tflag(a, tflag_cdef)) - class_def_cleaner(gwion, a->e->cdef); + class_def_cleaner(gwion, a->info->cdef); } if(a->nspc) nspc_remref(a->nspc, gwion); - if(a->e->tuple) - free_tupleform(a->e->tuple, gwion); - mp_free(gwion->mp, TypeInfo, a->e); + if(a->info->tuple) + free_tupleform(a->info->tuple, gwion); + mp_free(gwion->mp, TypeInfo, a->info); mp_free(gwion->mp, Type, a); } Type new_type(MemPool p, const m_uint xid, const m_str name, const Type parent) { const Type type = mp_calloc(p, Type); - type->xid = xid; - type->name = name; - type->e = mp_calloc(p, TypeInfo); - type->e->parent = parent; + type->xid = xid; + type->name = name; + type->info = mp_calloc(p, TypeInfo); + type->info->parent = parent; if(parent) type->size = parent->size; type->ref = 1; @@ -41,19 +41,19 @@ Type new_type(MemPool p, const m_uint xid, const m_str name, const Type parent) } ANN Type type_copy(MemPool p, const Type type) { - const Type a = new_type(p, type->xid, type->name, type->e->parent); + const Type a = new_type(p, type->xid, type->name, type->info->parent); a->nspc = type->nspc; - a->e->owner = type->e->owner; - a->e->owner_class = type->e->owner_class; + a->info->owner = type->info->owner; + a->info->owner_class = type->info->owner_class; a->size = type->size; - a->e->d.base_type = type->e->d.base_type; + a->info->base_type = type->info->base_type; a->array_depth = type->array_depth; - a->e->gack = type->e->gack; + a->info->gack = type->info->gack; return a; } ANN m_bool isa(const restrict Type var, const restrict Type parent) { - return (var->xid == parent->xid) ? 1 : var->e->parent ? isa(var->e->parent, parent) : -1; + return (var->xid == parent->xid) ? 1 : var->info->parent ? isa(var->info->parent, parent) : -1; } ANN Type find_common_anc(const restrict Type lhs, const restrict Type rhs) { @@ -67,20 +67,20 @@ ANN t find_##name(const Type type, const Symbol xid) { \ if(val) \ return val; \ } \ - return type->e->parent ? find_##name(type->e->parent, xid) : NULL; \ + return type->info->parent ? find_##name(type->info->parent, xid) : NULL; \ } describe_find(value, Value) //describe_find(func, Func) ANN Type typedef_base(Type t) { while(tflag(t, tflag_typedef)) - t = t->e->parent; + t = t->info->parent; return t; } ANN Type array_base(Type type) { const Type t = typedef_base(type); - return t->array_depth ? t->e->d.base_type : t; + return t->array_depth ? t->info->base_type : t; } ANN static Symbol array_sym(const Env env, const Type src, const m_uint depth) { @@ -97,14 +97,14 @@ ANN static Symbol array_sym(const Env env, const Type src, const m_uint depth) { 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); + const Type type = nspc_lookup_type1(src->info->owner, sym); if(type) return type; 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->e->owner = src->e->owner; + t->info->base_type = array_base(src) ?: src; + t->info->owner = src->info->owner; if(depth > 1 || isa(src, env->gwion->type[et_compound]) > 0) { t->nspc = new_nspc(env->gwion->mp, s_name(sym)); inherit(t); @@ -115,7 +115,7 @@ ANN Type array_type(const Env env, const Type src, const m_uint depth) { } else nspc_addref((t->nspc = env->gwion->type[et_array]->nspc)); mk_class(env, t); - nspc_add_type_front(src->e->owner, sym, t); + nspc_add_type_front(src->info->owner, sym, t); return t; } @@ -123,17 +123,18 @@ ANN m_bool type_ref(Type t) { do { if(tflag(t, tflag_empty)) return GW_OK; - if(tflag(t, tflag_typedef) && t->e->cdef) - if(t->e->cdef->base.ext && t->e->cdef->base.ext->array) { - if(!t->e->cdef->base.ext->array->exp) + if(tflag(t, tflag_typedef) && tflag(t, tflag_cdef)) { + if(t->info->cdef->base.ext && t->info->cdef->base.ext->array) { + if(!t->info->cdef->base.ext->array->exp) return GW_OK; else { - const Type type = t->e->parent->e->d.base_type; + const Type type = t->info->parent->info->base_type; if(tflag(type, tflag_empty)) return GW_OK; } } - } while((t = t->e->parent)); + } + } while((t = t->info->parent)); return 0; } @@ -175,9 +176,9 @@ ANN m_uint get_depth(const Type type) { do { if(t->array_depth) { depth += t->array_depth; - t = t->e->d.base_type; + t = t->info->base_type; } else - t = t->e->parent; + t = t->info->parent; } while(t); return depth; } @@ -190,11 +191,11 @@ ANN inline m_bool is_class(const struct Gwion_* gwion, const Type t) { } ANN Type actual_type(const struct Gwion_* gwion, const Type t) { - return is_class(gwion, t) ? t->e->d.base_type : t; + return is_class(gwion, t) ? t->info->base_type : t; } ANN void inherit(const Type t) { - const Nspc nspc = t->nspc, parent = t->e->parent->nspc; + const Nspc nspc = t->nspc, parent = t->info->parent->nspc; if(!nspc || !parent) return; nspc->info->offset = parent->info->offset; diff --git a/src/env/type_special.c b/src/env/type_special.c index 05db3f35..8a7c5ccc 100644 --- a/src/env/type_special.c +++ b/src/env/type_special.c @@ -23,8 +23,8 @@ ANN static Type specialtype_create(const Env env, const SpecialType *s) { t->name = s_name(s->name); t->flag = s->type->flag; t->tflag |= s->type->tflag | s->flag; - t->e->parent = unflag_type(s->type); - nspc_add_type_front(s->type->e->owner, s->name, t); + t->info->parent = unflag_type(s->type); + nspc_add_type_front(s->type->info->owner, s->name, t); mk_class(env, t); return t; } @@ -57,6 +57,6 @@ ANN static void specialtype_init(SymTable *st, SpecialType *s) { ANN Type special_type(const Env env, const Type t, const uint st_type) { SpecialType s = { .type=t, .st_type=st_type }; specialtype_init(env->gwion->st, &s); - return nspc_lookup_type1(t->e->owner, s.name) ?: + return nspc_lookup_type1(t->info->owner, s.name) ?: specialtype_create(env, &s); } diff --git a/src/import/import_cdef.c b/src/import/import_cdef.c index aaa39879..9c6dbcaa 100644 --- a/src/import/import_cdef.c +++ b/src/import/import_cdef.c @@ -30,9 +30,9 @@ ANN2(1,2) static inline m_bool class_parent(const Env env, Type t) { do { if(tflag(t, tflag_check)) break; - if(t->e->cdef) - CHECK_BB(traverse_class_def(env, t->e->cdef)) - } while((t = t->e->parent)); + if(t->info->cdef) + CHECK_BB(traverse_class_def(env, t->info->cdef)) + } while((t = t->info->parent)); return GW_OK; } @@ -41,8 +41,8 @@ ANN2(1,2) static void import_class_ini(const Env env, const Type t) { t->nspc->parent = env->curr; if(isa(t, env->gwion->type[et_object]) > 0) inherit(t); - t->e->owner = env->curr; - t->e->owner_class = env->class_def; + t->info->owner = env->curr; + t->info->owner_class = env->class_def; env_push_type(env, t); } @@ -87,11 +87,11 @@ ANN2(1,2) Type gwi_class_ini(const Gwi gwi, const m_str name, const m_str parent 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); - t->e->cdef = new_class_def(gwi->gwion->mp, 0, ck.sym, td, NULL, loc(gwi)); - t->e->cdef->base.tmpl = tmpl; - t->e->cdef->base.type = t; - t->e->tuple = new_tupleform(gwi->gwion->mp, p); - t->e->parent = 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; + t->info->tuple = new_tupleform(gwi->gwion->mp, p); + t->info->parent = p; if(td->array) set_tflag(t, tflag_typedef); if(ck.tmpl) @@ -104,7 +104,7 @@ ANN2(1,2) Type gwi_class_ini(const Gwi gwi, const m_str name, const m_str parent ANN Type gwi_struct_ini(const Gwi gwi, const m_str name) { CHECK_OO(gwi_str2sym(gwi, name)) const Type t = new_type(gwi->gwion->mp, ++gwi->gwion->env->scope->type_xid, name, gwi->gwion->type[et_compound]); - t->e->tuple = new_tupleform(gwi->gwion->mp, NULL); + t->info->tuple = new_tupleform(gwi->gwion->mp, NULL); gwi_type_flag(t); set_tflag(t, tflag_struct); return type_finish(gwi, t); diff --git a/src/import/import_internals.c b/src/import/import_internals.c index 56292c20..a4fbefdf 100644 --- a/src/import/import_internals.c +++ b/src/import/import_internals.c @@ -11,7 +11,7 @@ #include "gwi.h" void gwi_body(const Gwi gwi, const Ast body) { - const Class_Def cdef = gwi->gwion->env->class_def->e->cdef; + const Class_Def cdef = gwi->gwion->env->class_def->info->cdef; if(!cdef->body) cdef->body = body; else diff --git a/src/import/import_special.c b/src/import/import_special.c index 36fd2967..6a518116 100644 --- a/src/import/import_special.c +++ b/src/import/import_special.c @@ -45,7 +45,7 @@ ANN void gwi_set_loc(const Gwi gwi, const m_str file, const uint line) { ANN static m_bool mk_gack(MemPool p, const Type type, const f_gack d) { const VM_Code code = new_vm_code(p, NULL, SZ_INT, 1, "@gack"); code->native_func = (m_uint)d; - type->e->gack = code; + type->info->gack = code; return GW_OK; } diff --git a/src/lib/array.c b/src/lib/array.c index 7262064c..0020a0ae 100644 --- a/src/lib/array.c +++ b/src/lib/array.c @@ -138,8 +138,8 @@ static MFUN(vm_vector_cap) { } ANN static Type get_array_type(Type t) { - while(t->e->d.base_type) - t = t->e->d.base_type; + while(t->info->base_type) + t = t->info->base_type; return t; } @@ -264,11 +264,11 @@ static OP_CHECK(opck_array_cast) { const Exp_Cast* cast = (Exp_Cast*)data; Type l = cast->exp->info->type; Type r = exp_self(cast)->info->type; - while(!l->e->d.base_type) - l = l->e->parent; - while(!r->e->d.base_type) - r = r->e->parent; - if(get_depth(cast->exp->info->type) == get_depth(exp_self(cast)->info->type) && isa(l->e->d.base_type, r->e->d.base_type) > 0) + while(!l->info->base_type) + l = l->info->parent; + while(!r->info->base_type) + r = r->info->parent; + if(get_depth(cast->exp->info->type) == get_depth(exp_self(cast)->info->type) && isa(l->info->base_type, r->info->base_type) > 0) return l; return env->gwion->type[et_null]; } @@ -320,7 +320,7 @@ static FREEARG(freearg_array) { static OP_CHECK(opck_not_array) { const Array_Sub array = (Array_Sub)data; if(get_depth(array->type)) { - struct Array_Sub_ next = { array->exp, array->type->e->parent, array->depth }; + struct Array_Sub_ next = { array->exp, array->type->info->parent, array->depth }; return check_array_access(env, &next); } ERR_O(array->exp->pos, _("array subscripts (%"UINT_F") exceeds defined dimension (%"UINT_F")"), diff --git a/src/lib/instr.c b/src/lib/instr.c index b1e9ef76..da192128 100644 --- a/src/lib/instr.c +++ b/src/lib/instr.c @@ -16,7 +16,7 @@ INSTR(DTOR_EOC) { const M_Object o = *(M_Object*)MEM(0); - o->type_ref = o->type_ref->e->parent; + o->type_ref = o->type_ref->info->parent; _release(o, shred); shred->info->me->ref = 1; vm_shred_exit(shred); @@ -90,7 +90,7 @@ INSTR(DotTmpl) { struct dottmpl_ *dt = (struct dottmpl_*)instr->m_val; const m_str name = dt->name; const M_Object o = *(M_Object*)REG(-SZ_INT); - Type t = !tflag(o->type_ref, tflag_nonnull) ? o->type_ref : o->type_ref->e->parent; + Type t = !tflag(o->type_ref, tflag_nonnull) ? o->type_ref : o->type_ref->info->parent; do { const Emitter emit = shred->info->vm->gwion->emit; emit->env->name = "runtime"; @@ -115,7 +115,7 @@ INSTR(DotTmpl) { *(VM_Code*)(shred->reg-SZ_INT) = f->code; return; } - } while((t = t->e->parent)); + } while((t = t->info->parent)); Except(shred, "MissigTmplException[internal]"); } diff --git a/src/lib/lib_func.c b/src/lib/lib_func.c index 9781373c..9d6cdf2b 100644 --- a/src/lib/lib_func.c +++ b/src/lib/lib_func.c @@ -31,10 +31,10 @@ static inline void fptr_instr(const Emitter emit, const Func f, const m_uint i) static OP_EMIT(opem_func_assign) { Exp_Binary* bin = (Exp_Binary*)data; - if(bin->rhs->info->type->e->d.func->def->base->tmpl) - fptr_instr(emit, bin->lhs->info->type->e->d.func, 2); + if(bin->rhs->info->type->info->func->def->base->tmpl) + fptr_instr(emit, bin->lhs->info->type->info->func, 2); const Instr instr = emit_add_instr(emit, int_r_assign); - if(!is_fptr(emit->gwion, bin->lhs->info->type) && vflag(bin->rhs->info->type->e->d.func->value_ref, vflag_member)) { + if(!is_fptr(emit->gwion, bin->lhs->info->type) && vflag(bin->rhs->info->type->info->func->value_ref, vflag_member)) { const Instr pop = emit_add_instr(emit, RegPop); pop->m_val = SZ_INT; const Instr cpy = emit_add_instr(emit, Reg2Reg); @@ -127,7 +127,7 @@ ANN static Type fptr_type(const Env env, struct FptrInfo *info) { CHECK_OO((info->lhs = nspc_lookup_func1(nspc, sym))) else { DECL_OO(const Type, t, = nspc_lookup_type1(nspc, info->lhs->def->base->xid)) - info->lhs = actual_type(env->gwion, t)->e->d.func; + info->lhs = actual_type(env->gwion, t)->info->func; } Func_Base *base[2] = { info->lhs->def->base, info->rhs->def->base }; if(fptr_tmpl_push(env, info) > 0) { @@ -165,11 +165,11 @@ ANN static m_bool _check_lambda(const Env env, Exp_Lambda *l, const Func_Def def } ANN m_bool check_lambda(const Env env, const Type t, Exp_Lambda *l) { - const Func_Def fdef = t->e->d.func->def; + const Func_Def fdef = t->info->func->def; struct EnvSet es = { .env=env, .data=env, .func=(_exp_func)check_cdef, .scope=env->scope->depth, .flag=tflag_check }; - l->owner = t->e->owner_class; - CHECK_BB(envset_push(&es, l->owner, t->e->owner)) + l->owner = t->info->owner_class; + CHECK_BB(envset_push(&es, l->owner, t->info->owner)) const m_bool ret = _check_lambda(env, l, fdef); if(es.run) envset_pop(&es, l->owner); @@ -198,7 +198,7 @@ static OP_CHECK(opck_auto_fptr) { return env->gwion->type[et_null]; // create a matching signature // TODO: we could check first if there a matching existing one - Func_Base *const fbase = cpy_func_base(env->gwion->mp, bin->lhs->info->type->e->d.func->def->base); + Func_Base *const fbase = cpy_func_base(env->gwion->mp, bin->lhs->info->type->info->func->def->base); const Fptr_Def fptr_def = new_fptr_def(env->gwion->mp, fbase); char name[13 + strlen(env->curr->name) + num_digit(bin->rhs->pos->first.line) + num_digit(bin->rhs->pos->first.column)]; @@ -215,15 +215,15 @@ static OP_CHECK(opck_auto_fptr) { static OP_CHECK(opck_fptr_at) { Exp_Binary* bin = (Exp_Binary*)data; - if(bin->rhs->info->type->e->d.func->def->base->tmpl && - bin->rhs->info->type->e->d.func->def->base->tmpl->call) { - struct FptrInfo info = { bin->lhs->info->type->e->d.func, bin->rhs->info->type->e->parent->e->d.func, + if(bin->rhs->info->type->info->func->def->base->tmpl && + bin->rhs->info->type->info->func->def->base->tmpl->call) { + struct FptrInfo info = { bin->lhs->info->type->info->func, bin->rhs->info->type->info->parent->info->func, bin->lhs, exp_self(bin)->pos }; CHECK_BO(fptr_do(env, &info)) exp_setvar(bin->rhs, 1); return bin->rhs->info->type; } - struct FptrInfo info = { bin->lhs->info->type->e->d.func, bin->rhs->info->type->e->d.func, + struct FptrInfo info = { bin->lhs->info->type->info->func, bin->rhs->info->type->info->func, bin->lhs, exp_self(bin)->pos }; CHECK_BO(fptr_do(env, &info)) exp_setvar(bin->rhs, 1); @@ -240,10 +240,10 @@ static OP_CHECK(opck_null_fptr_at) { static OP_CHECK(opck_fptr_cast) { Exp_Cast* cast = (Exp_Cast*)data; const Type t = exp_self(cast)->info->type; - struct FptrInfo info = { cast->exp->info->type->e->d.func, t->e->d.func, + struct FptrInfo info = { cast->exp->info->type->info->func, t->info->func, cast->exp, exp_self(cast)->pos }; CHECK_BO(fptr_do(env, &info)) - cast->func = cast->exp->info->type->e->d.func; + cast->func = cast->exp->info->type->info->func; return t; } @@ -255,14 +255,14 @@ static void member_fptr(const Emitter emit) { } static int is_member(const Type from, const Type to) { - return vflag(from->e->d.func->value_ref, vflag_member) && + return vflag(from->info->func->value_ref, vflag_member) && !(tflag(from, tflag_nonnull) || tflag(to, tflag_nonnull)); } static OP_EMIT(opem_fptr_cast) { const Exp_Cast* cast = (Exp_Cast*)data; - if(exp_self(cast)->info->type->e->d.func->def->base->tmpl) - fptr_instr(emit, cast->exp->info->type->e->d.func, 1); + if(exp_self(cast)->info->type->info->func->def->base->tmpl) + fptr_instr(emit, cast->exp->info->type->info->func, 1); if(is_member(cast->exp->info->type, exp_self(cast)->info->type)) member_fptr(emit); return (Instr)GW_OK; @@ -270,7 +270,7 @@ static OP_EMIT(opem_fptr_cast) { static OP_CHECK(opck_fptr_impl) { struct Implicit *impl = (struct Implicit*)data; - struct FptrInfo info = { impl->e->info->type->e->d.func, impl->t->e->d.func, + struct FptrInfo info = { impl->e->info->type->info->func, impl->t->info->func, impl->e, impl->e->pos }; CHECK_BO(fptr_do(env, &info)) return ((Exp)impl->e)->info->cast_to = impl->t; @@ -280,8 +280,8 @@ static OP_EMIT(opem_fptr_impl) { struct Implicit *impl = (struct Implicit*)data; if(is_member(impl->e->info->type, impl->t)) member_fptr(emit); - if(impl->t->e->d.func->def->base->tmpl) - fptr_instr(emit, ((Exp)impl->e)->info->type->e->d.func, 1); + if(impl->t->info->func->def->base->tmpl) + fptr_instr(emit, ((Exp)impl->e)->info->type->info->func, 1); return (Instr)GW_OK; } diff --git a/src/lib/modules.c b/src/lib/modules.c index 8a1af0bb..c60d07d3 100644 --- a/src/lib/modules.c +++ b/src/lib/modules.c @@ -207,15 +207,15 @@ static DTOR(usrugen_dtor) { static OP_CHECK(opck_usrugen) { Exp_Binary *bin = (Exp_Binary*)data; - const Arg_List arg = bin->lhs->info->type->e->d.func->def->base->args; + const Arg_List arg = bin->lhs->info->type->info->func->def->base->args; if(!arg || arg->next) ERR_N(exp_self(bin)->pos, _("Tick function take one and only one argument")) if(isa(arg->type, env->gwion->type[et_float]) < 0) ERR_N(exp_self(bin)->pos, _("Tick functions argument must be of type float")) - if(isa(bin->lhs->info->type->e->d.func->def->base->ret_type, env->gwion->type[et_float]) < 0) + if(isa(bin->lhs->info->type->info->func->def->base->ret_type, env->gwion->type[et_float]) < 0) ERR_N(exp_self(bin)->pos, _("Tick function must return float")) - if(bin->lhs->info->type->e->d.func->value_ref->from->owner_class) - CHECK_BN(isa(bin->lhs->info->type->e->d.func->value_ref->from->owner_class, + if(bin->lhs->info->type->info->func->value_ref->from->owner_class) + CHECK_BN(isa(bin->lhs->info->type->info->func->value_ref->from->owner_class, bin->rhs->info->type)) return bin->rhs->info->type; } @@ -270,7 +270,7 @@ static INSTR(UsrUGenTick) { static OP_EMIT(opem_usrugen) { Exp_Binary *bin = (Exp_Binary*)data; const Instr instr = emit_add_instr(emit, UsrUGenTick); - instr->m_val = !!bin->lhs->info->type->e->d.func->value_ref->from->owner_class; + instr->m_val = !!bin->lhs->info->type->info->func->value_ref->from->owner_class; return instr; } diff --git a/src/lib/object.c b/src/lib/object.c index 2d08cb34..01bd4edd 100644 --- a/src/lib/object.c +++ b/src/lib/object.c @@ -74,8 +74,8 @@ ANN void __release(const M_Object o, const VM_Shred shred) { isa(v->type, shred->info->vm->gwion->type[et_object]) > 0) release(*(M_Object*)(o->data + v->from->offset), shred); else if(tflag(v->type, tflag_struct) && - !GET_FLAG(v, static) && !vflag(v, vflag_union) && v->type->e->tuple) { - const TupleForm tf = v->type->e->tuple; + !GET_FLAG(v, static) && !vflag(v, vflag_union) && v->type->info->tuple) { + const TupleForm tf = v->type->info->tuple; for(m_uint i = 0; i < vector_size(&tf->types); ++i) { const m_bit *data = o->data + v->from->offset; const Type t = (Type)vector_at(&tf->types, i); @@ -94,7 +94,7 @@ ANN void __release(const M_Object o, const VM_Shred shred) { return; } } - } while((t = t->e->parent)); + } while((t = t->info->parent)); free_object(p, o); } @@ -110,7 +110,7 @@ static ID_CHECK(opck_this) { if(env->func && !vflag(env->func->value_ref, vflag_member)) ERR_O(exp_self(prim)->pos, _("keyword 'this' cannot be used inside static functions...")) if(env->func && !strcmp(s_name(env->func->def->base->xid), "@gack")) - return force_type(env, get_gack(env->class_def->e->parent)); // get_gack ? + return force_type(env, get_gack(env->class_def->info->parent)); // get_gack ? return env->class_def; } diff --git a/src/lib/object_op.c b/src/lib/object_op.c index 66a8b70d..18545e9e 100644 --- a/src/lib/object_op.c +++ b/src/lib/object_op.c @@ -42,7 +42,7 @@ static inline Type check_nonnull(const Env env, const Type l, const Type r, ERR_N(pos, _("can't %s '%s' to '%s'"), action, l->name, r->name); if(isa(l, r) < 0) ERR_N(pos, _("can't %s '%s' to '%s'"), action, l->name, r->name); - return r->e->parent; + return r->info->parent; } if(l != env->gwion->type[et_null] && isa(l, r) < 0) ERR_N(pos, _("can't %s '%s' to '%s'"), action, l->name, r->name); @@ -148,7 +148,7 @@ ANN static void emit_dot_static_import_data(const Emitter emit, const Value v, c static const f_instr dotmember[] = { DotMember, DotMember2, DotMember3, DotMember4 }; ANN static void emit_member_func(const Emitter emit, const Exp_Dot* member) { - const Func f = exp_self(member)->info->type->e->d.func; + const Func f = exp_self(member)->info->type->info->func; if(f->def->base->tmpl) emit_add_instr(emit, DotTmplVal); else @@ -196,7 +196,7 @@ OP_CHECK(opck_object_dot) { const Exp_Dot *member = (Exp_Dot*)data; const m_str str = s_name(member->xid); const m_bool base_static = is_class(env->gwion, member->t_base); - const Type the_base = base_static ? member->t_base->e->d.base_type : member->t_base; + const Type the_base = base_static ? member->t_base->info->base_type : member->t_base; if(!the_base->nspc) ERR_N(member->base->pos, _("type '%s' does not have members - invalid use in dot expression of %s"), @@ -340,14 +340,14 @@ ANN static Type tmpl_exists(const Env env, const Symbol name) { } ANN static m_bool scantmpl_class_def(const Env env, struct tmpl_info *info) { - const Class_Def c = info->base->e->cdef; + const Class_Def c = info->base->info->cdef; const Class_Def cdef = new_class_def(env->gwion->mp, c->flag, info->name, c->base.ext ? cpy_type_decl(env->gwion->mp, c->base.ext) : NULL, c->body ?cpy_ast(env->gwion->mp, c->body) : NULL, loc_cpy(env->gwion->mp, c->pos)); cdef->base.tmpl = mk_tmpl(env, c->base.tmpl, info->call); const m_bool ret = scan0_class_def(env, cdef); if((info->ret = cdef->base.type)) { - info->ret->e->cdef = cdef; + info->ret->info->cdef = cdef; set_tflag(info->ret, tflag_cdef); set_tflag(info->ret, tflag_ctmpl); } else @@ -356,7 +356,7 @@ ANN static m_bool scantmpl_class_def(const Env env, struct tmpl_info *info) { } ANN static m_bool scantmpl_union_def(const Env env, struct tmpl_info *info) { - const Union_Def u = info->base->e->udef; + const Union_Def u = info->base->info->udef; const Union_Def udef = new_union_def(env->gwion->mp, cpy_decl_list(env->gwion->mp, u->l), loc_cpy(env->gwion->mp, u->pos)); udef->type_xid = info->name; @@ -365,7 +365,7 @@ ANN static m_bool scantmpl_union_def(const Env env, struct tmpl_info *info) { SET_FLAG(udef, global); const m_bool ret = scan0_union_def(env, udef); if(udef->type) { - udef->type->e->udef = udef;// mark as udef + udef->type->info->udef = udef;// mark as udef info->ret = udef->type; set_tflag(info->ret, tflag_udef); // set_tflag(info->ret, tflag_tmpl); @@ -375,7 +375,7 @@ ANN static m_bool scantmpl_union_def(const Env env, struct tmpl_info *info) { } ANN static Type _scan_class(const Env env, struct tmpl_info *info) { - if(info->base->e->parent != env->gwion->type[et_union]) + if(info->base->info->parent != env->gwion->type[et_union]) CHECK_BO(scantmpl_class_def(env, info)) else CHECK_BO(scantmpl_union_def(env, info)) @@ -383,19 +383,19 @@ ANN static Type _scan_class(const Env env, struct tmpl_info *info) { } ANN Type scan_class(const Env env, const Type t, const Type_Decl* td) { - if(template_match(t->e->cdef->base.tmpl->list, td->types) < 0) // invalid template + if(template_match(t->info->cdef->base.tmpl->list, td->types) < 0) // invalid template ERR_O(td->pos, _("invalid template types number")) - struct tmpl_info info = { .base=t, .call=td->types, .list=t->e->cdef->base.tmpl->list }; + struct tmpl_info info = { .base=t, .call=td->types, .list=t->info->cdef->base.tmpl->list }; DECL_OO(const Symbol, name, = info.name = template_id(env, &info)) const Type exists = tmpl_exists(env, name); if(exists) return exists; struct EnvSet es = { .env=env, .data=env, .func=(_exp_func)scan0_cdef, .scope=env->scope->depth, .flag=tflag_scan0 }; - CHECK_BO(envset_push(&es, t->e->owner_class, t->e->ctx ? t->e->ctx->nspc : env->curr)) + CHECK_BO(envset_push(&es, t->info->owner_class, t->info->ctx ? t->info->ctx->nspc : env->curr)) const Type ret = _scan_class(env, &info); if(es.run) - envset_pop(&es, t->e->owner_class); + envset_pop(&es, t->info->owner_class); return ret; } @@ -417,8 +417,8 @@ ANN Exp symbol_owned_exp(const Gwion gwion, const Symbol *data) { } ANN void struct_release(const VM_Shred shred, const Type base, const m_bit *ptr) { - const Vector types = &base->e->tuple->types; - const Vector offsets = &base->e->tuple->offset; + const Vector types = &base->info->tuple->types; + const Vector offsets = &base->info->tuple->offset; for(m_uint i = 0; i < vector_size(types); ++i) { const Type t = (Type)vector_at(types, i); if(isa(t, shred->info->vm->gwion->type[et_compound]) < 0) diff --git a/src/lib/ptr.c b/src/lib/ptr.c index fa4378dd..c4e72def 100644 --- a/src/lib/ptr.c +++ b/src/lib/ptr.c @@ -35,8 +35,8 @@ static OP_CHECK(opck_ptr_assign) { const m_str str = get_type_name(env, u, 1); if(str && !strcmp(t->name, str)) return bin->lhs->info->type; // use rhs? - } while((u = u->e->parent)); - } while((t = t->e->parent)); + } while((u = u->info->parent)); + } while((t = t->info->parent)); return env->gwion->type[et_null]; } @@ -59,7 +59,7 @@ static OP_CHECK(opck_ptr_cast) { ERR_N(exp_self(cast)->pos, "'Ptr' needs types to cast") DECL_ON(const Type, t, = known_type(env, cast->td)) const Type _t = get_type(t); - if(_t->e->cdef && !tflag(_t, tflag_check)) + if(_t->info->cdef && !tflag(_t, tflag_check)) CHECK_BN(ensure_traverse(env, _t)) const Type to = known_type(env, cast->td->types->td); if(isa(cast->exp->info->type, to) > 0) @@ -79,7 +79,7 @@ static OP_CHECK(opck_ptr_implicit) { exp_setvar(e, 1); const Type t = get_type(imp->t); if(!tflag(t, tflag_check)) - CHECK_BN(traverse_class_def(env, t->e->cdef)) + CHECK_BN(traverse_class_def(env, t->info->cdef)) return imp->t; } return NULL; @@ -132,7 +132,7 @@ static DTOR(ptr_object_dtor) { } static DTOR(ptr_struct_dtor) { - const Type t = (Type)vector_front(&o->type_ref->e->tuple->types); + const Type t = (Type)vector_front(&o->type_ref->info->tuple->types); struct_release(shred, t, *(m_bit**)o->data); } @@ -141,7 +141,7 @@ static OP_CHECK(opck_ptr_scan) { DECL_ON(const Type, t, = (Type)scan_class(env, ts->t, ts->td)) set_tflag(t, tflag_tmpl); //if(!tflag(t, tflag_scan1))exit(3); - const Type base = known_type(env, t->e->cdef->base.tmpl->call->td); + const Type base = known_type(env, t->info->cdef->base.tmpl->call->td); if(isa(base, env->gwion->type[et_compound]) > 0 && !t->nspc->dtor) { t->nspc->dtor = new_vm_code(env->gwion->mp, NULL, SZ_INT, 1, "@PtrDtor"); if(!tflag(t, tflag_struct)) diff --git a/src/parse/check.c b/src/parse/check.c index 4d0650fa..3c82b6b4 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -47,7 +47,7 @@ ANN m_bool check_subscripts(Env env, const Array_Sub array, const m_bool is_decl } ANN static inline m_bool check_exp_decl_parent(const Env env, const Var_Decl var) { - const Value value = find_value(env->class_def->e->parent, var->xid); + const Value value = find_value(env->class_def->info->parent, var->xid); if(value) ERR_B(var->pos, _("in class '%s': '%s' has already been defined in parent class '%s' ..."), @@ -70,12 +70,12 @@ ANN static m_bool check_fptr_decl(const Env env, const Var_Decl var) { const Value v = var->value; Type t = v->type; while(tflag(t, tflag_typedef)) - t = t->e->parent; - if(!t->e->d.func) + t = t->info->parent; + if(!t->info->func) return GW_ERROR; if(!env->class_def) return GW_OK; - const Func func = t->e->d.func; + const Func func = t->info->func; const Type type = func->value_ref->from->owner_class; if(type && isa(type, env->class_def) < 0 && !GET_FLAG(func, global)) ERR_B(var->pos, _("can't use non global fptr of other class.")) @@ -102,7 +102,7 @@ ANN static Type no_xid(const Env env, const Exp_Decl *decl) { } ANN static m_bool check_var(const Env env, const Var_Decl var) { - if(env->class_def && !env->scope->depth && env->class_def->e->parent) + if(env->class_def && !env->scope->depth && env->class_def->info->parent) CHECK_BB(check_exp_decl_parent(env, var)) if(var->array && var->array->exp) return check_subscripts(env, var->array, 1); @@ -114,7 +114,7 @@ ANN static m_bool check_var_td(const Env env, const Var_Decl var, Type_Decl *con if(env->class_def) { if(vflag(v, vflag_member)) { decl_member(env, v); - if(env->class_def->e->tuple) + if(env->class_def->info->tuple) tuple_info(env, v); } else if(GET_FLAG(td, static)) decl_static(env, v); @@ -138,15 +138,21 @@ ANN static m_bool check_decl(const Env env, const Exp_Decl *decl) { } ANN static inline m_bool ensure_check(const Env env, const Type t) { + const Type base = get_type(t); + if(tflag(base, tflag_check) || !(tflag(base, tflag_cdef) || tflag(base, tflag_udef))) + return GW_OK; struct EnvSet es = { .env=env, .data=env, .func=(_exp_func)check_cdef, .scope=env->scope->depth, .flag=tflag_check }; - return envset_run(&es, t); + return envset_run(&es, base); } ANN m_bool ensure_traverse(const Env env, const Type t) { + const Type base = get_type(t); + if(tflag(base, tflag_check) || !(tflag(base, tflag_cdef) || tflag(base, tflag_udef))) + return GW_OK; struct EnvSet es = { .env=env, .data=env, .func=(_exp_func)traverse_cdef, .scope=env->scope->depth, .flag=tflag_check }; - return envset_run(&es, t); + return envset_run(&es, base); } ANN static inline m_bool inferable(const Env env, const Type t, const loc_t pos) { @@ -168,8 +174,7 @@ ANN Type check_exp_decl(const Env env, const Exp_Decl* decl) { { const Type t = get_type(decl->type); CHECK_BO(inferable(env, t, td_pos(decl->td))) - if(!tflag(t, tflag_check)) - CHECK_BO(ensure_check(env, t)) + CHECK_BO(ensure_check(env, t)) } const m_bool global = GET_FLAG(decl->td, global); const m_uint scope = !global ? env->scope->depth : env_push_global(env); @@ -407,10 +412,10 @@ ANN static Type_List mk_type_list(const Env env, const Type type, const loc_t po struct Vector_ v; vector_init(&v); vector_add(&v, (vtype)insert_symbol(type->name)); - Type owner = type->e->owner_class; + Type owner = type->info->owner_class; while(owner) { vector_add(&v, (vtype)insert_symbol(owner->name)); - owner = owner->e->owner_class; + owner = owner->info->owner_class; } Type_Decl *td = NULL; for(m_uint i = 0 ; i < vector_size(&v); ++i) @@ -533,7 +538,7 @@ ANN static void print_arg(Arg_List e) { ANN2(1) static void function_alternative(const Env env, const Type f, const Exp args, const loc_t pos){ env_err(env, pos, _("argument type(s) do not match for function. should be :")); - Func up = f->e->d.func; + Func up = f->info->func; do { gw_err("(%s) ", up->name); const Arg_List e = up->def->base->args; @@ -561,7 +566,7 @@ ANN static Func get_template_func(const Env env, const Exp_Call* func, const Val if(f) { // copy that tmpl->call? 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->info->type->e->d.func->def->base->tmpl->list; + tmpl->list = v->d.func_ref ? v->d.func_ref->def->base->tmpl->list : func->func->info->type->info->func->def->base->tmpl->list; ((Exp_Call*)func)->tmpl = tmpl; return ((Exp_Call*)func)->m_func = f; } @@ -626,7 +631,7 @@ ANN static Type_List check_template_args(const Env env, Exp_Call *exp, const Tmp ANN static Type check_exp_call_template(const Env env, Exp_Call *exp) { const Type t = exp->func->info->type; DECL_OO(const Value, value, = type_value(env->gwion, t)) - const Func_Def fdef = value->d.func_ref ? value->d.func_ref->def : t->e->d.func->def; + const Func_Def fdef = value->d.func_ref ? value->d.func_ref->def : t->info->func->def; Tmpl *tm = fdef->base->tmpl; if(tm->call) return check_predefined(env, exp, value, tm, fdef); @@ -663,24 +668,24 @@ ANN Type check_exp_call1(const Env env, const Exp_Call *exp) { // use func flag? if(isa(exp->func->info->type, env->gwion->type[et_class]) < 0) ERR_O(exp->func->pos, _("function call using a non-function value")) - struct Op_Import opi = { .op=insert_symbol("@ctor"), .rhs=exp->func->info->type->e->d.base_type, + struct Op_Import opi = { .op=insert_symbol("@ctor"), .rhs=exp->func->info->type->info->base_type, .data=(uintptr_t)exp, .pos=exp_self(exp)->pos, .op_type=op_exp }; const Type t = op_check(env, &opi); - exp_self(exp)->info->nspc = t ? t->e->owner : NULL; + exp_self(exp)->info->nspc = t ? t->info->owner : NULL; return t; } if(exp->func->info->type == env->gwion->type[et_lambda]) return check_lambda_call(env, exp); - if(fflag(exp->func->info->type->e->d.func, fflag_ftmpl)) { - const Value value = exp->func->info->type->e->d.func->value_ref; - if(value->from->owner_class && !tflag(value->from->owner_class, tflag_check)) + if(fflag(exp->func->info->type->info->func, fflag_ftmpl)) { + const Value value = exp->func->info->type->info->func->value_ref; + if(value->from->owner_class) CHECK_BO(ensure_traverse(env, value->from->owner_class)) } if(exp->args) CHECK_OO(check_exp(env, exp->args)) if(tflag(exp->func->info->type, tflag_ftmpl)) return check_exp_call_template(env, (Exp_Call*)exp); - const Func func = find_func_match(env, exp->func->info->type->e->d.func, exp->args); + const Func func = find_func_match(env, exp->func->info->type->info->func, exp->args); if((exp_self(exp)->d.exp_call.m_func = func)) { exp->func->info->type = func->value_ref->type; return func->def->base->ret_type; @@ -724,14 +729,14 @@ ANN static Type check_exp_post(const Env env, const Exp_Postfix* post) { } ANN static m_bool predefined_call(const Env env, const Type t, const loc_t pos) { - const m_str str = tl2str(env, t->e->d.func->def->base->tmpl->call); + const m_str str = tl2str(env, t->info->func->def->base->tmpl->call); env_err(env, pos, _("Type '%s' has '%s' as pre-defined types."), t->name, str); free_mstr(env->gwion->mp, str); if(tflag(t, tflag_typedef)) { - loc_header(t->e->d.func->def->pos, env->name); + loc_header(t->info->func->def->pos, env->name); gw_err(_("from definition:\n")); - loc_err(t->e->d.func->def->pos, env->name); + loc_err(t->info->func->def->pos, env->name); } return GW_ERROR; } @@ -742,10 +747,10 @@ ANN static Type check_exp_call(const Env env, Exp_Call* exp) { const Type t = actual_type(env->gwion, unflag_type(exp->func->info->type)); if(isa(t, env->gwion->type[et_function]) < 0) ERR_O(exp_self(exp)->pos, _("template call of non-function value.")) - if(!t->e->d.func->def->base->tmpl) + if(!t->info->func->def->base->tmpl) ERR_O(exp_self(exp)->pos, _("template call of non-template function.")) - if(t->e->d.func->def->base->tmpl->call) { - if(env->func == t->e->d.func) { + if(t->info->func->def->base->tmpl->call) { + if(env->func == t->info->func) { if(exp->args) CHECK_OO(check_exp(env, exp->args)) exp->m_func = env->func; @@ -767,8 +772,7 @@ ANN static Type check_exp_unary(const Env env, const Exp_Unary* unary) { return NULL; DECL_OO(const Type, ret, = op_check(env, &opi)) const Type t = get_type(actual_type(env->gwion, ret)); - if(!tflag(t, tflag_check)) - CHECK_BO(ensure_traverse(env, t)) + CHECK_BO(ensure_traverse(env, t)) return ret; } @@ -804,7 +808,8 @@ ANN static Type check_exp_dot(const Env env, Exp_Dot* member) { } ANN m_bool check_type_def(const Env env, const Type_Def tdef) { - return tdef->type->e->cdef ? check_class_def(env, tdef->type->e->cdef) : GW_OK; + return (!is_fptr(env->gwion, tdef->type) && tdef->type->info->cdef) ? + check_class_def(env, tdef->type->info->cdef) : GW_OK; } ANN static Type check_exp_lambda(const Env env, const Exp_If* exp_if NUSED) { return env->gwion->type[et_lambda]; } @@ -816,7 +821,7 @@ ANN Type check_exp(const Env env, const Exp exp) { do { CHECK_OO((curr->info->type = check_exp_func[curr->exp_type](env, &curr->d))) if(env->func && isa(curr->info->type, env->gwion->type[et_lambda]) < 0 && isa(curr->info->type, env->gwion->type[et_function]) > 0 && - !fflag(curr->info->type->e->d.func, fflag_pure)) + !fflag(curr->info->type->info->func, fflag_pure)) unset_fflag(env->func, fflag_pure); } while((curr = curr->next)); return exp->info->type; @@ -873,7 +878,7 @@ ANN static inline m_bool for_empty(const Env env, const Stmt_For stmt) { ANN static m_bool do_stmt_each(const Env env, const Stmt_Each stmt) { DECL_OB(Type, t, = check_exp(env, stmt->exp)) while(tflag(t, tflag_typedef)) - t = t->e->parent; + t = t->info->parent; Type ptr = array_base(t); const m_uint depth = t->array_depth - 1; if(!ptr || isa(t, env->gwion->type[et_array]) < 0) @@ -886,8 +891,7 @@ ANN static m_bool do_stmt_each(const Env env, const Stmt_Each stmt) { sprintf(c, "nonnull Ptr:[%s]", ptr->name); ptr = str2type(env->gwion, c, stmt->exp->pos); const Type base = get_type(ptr); - if(!tflag(base, tflag_check)) - CHECK_BB(ensure_traverse(env, base)) + CHECK_BB(ensure_traverse(env, base)) } t = (!stmt->is_ptr && depth) ? array_type(env, ptr, depth) : ptr; stmt->v = new_value(env->gwion->mp, t, s_name(stmt->sym)); @@ -1158,7 +1162,7 @@ ANN static m_bool parent_match_actual(const Env env, const restrict Func_Def fde ANN static m_bool check_parent_match(const Env env, const Func_Def fdef) { const Func func = fdef->base->func; - const Type parent = env->class_def->e->parent; + const Type parent = env->class_def->info->parent; if(!env->curr->info->vtable.ptr) vector_init(&env->curr->info->vtable); if(parent) { @@ -1195,8 +1199,8 @@ ANN static m_bool check_func_overload(const Env env, const Func_Def fdef) { ANN static m_bool check_func_def_override(const Env env, const Func_Def fdef) { const Func func = fdef->base->func; - if(env->class_def && env->class_def->e->parent) { - const Value override = find_value(env->class_def->e->parent, fdef->base->xid); + if(env->class_def && env->class_def->info->parent) { + const Value override = find_value(env->class_def->info->parent, fdef->base->xid); if(override && override->from->owner_class && isa(override->type, env->gwion->type[et_function]) < 0) ERR_B(fdef->pos, _("function name '%s' conflicts with previously defined value...\n" @@ -1256,12 +1260,11 @@ ANN m_bool check_func_def(const Env env, const Func_Def f) { HANDLE_SECTION_FUNC(check, m_bool, Env) ANN static m_bool check_parent(const Env env, const Class_Def cdef) { - const Type parent = cdef->base.type->e->parent; + const Type parent = cdef->base.type->info->parent; const Type_Decl *td = cdef->base.ext; if(td->array) CHECK_BB(check_subscripts(env, td->array, 1)) - if(!tflag(parent, tflag_check)) - CHECK_BB(ensure_check(env, parent)) + CHECK_BB(ensure_check(env, parent)) if(tflag(parent, tflag_typedef)) { set_tflag(cdef->base.type, tflag_typedef); } @@ -1292,8 +1295,8 @@ ANN m_bool check_class_def(const Env env, const Class_Def cdef) { if(tmpl_base(cdef->base.tmpl)) return GW_OK; const Type t = cdef->base.type; - if(t->e->owner_class && !tflag(t->e->owner_class, tflag_check)) - CHECK_BB(ensure_check(env, t->e->owner_class)) + if(t->info->owner_class) + CHECK_BB(ensure_check(env, t->info->owner_class)) if(tflag(t, tflag_check)) return GW_OK; set_tflag(t, tflag_check); diff --git a/src/parse/did_you_mean.c b/src/parse/did_you_mean.c index b5d5e119..11e4f0d6 100644 --- a/src/parse/did_you_mean.c +++ b/src/parse/did_you_mean.c @@ -65,7 +65,7 @@ ANN void did_you_mean_type(Type type, const char* name) { struct Vector_ v; vector_init(&v); do ressembles(&v, t->nspc, name); - while((t = t->e->parent) && t->nspc); + while((t = t->info->parent) && t->nspc); for(m_uint i = 0; i < vector_size(&v); ++i) gw_err(_(" (did you mean '%s'?)\n"), (m_str)vector_at(&v, i)); vector_release(&v); diff --git a/src/parse/func_resolve_tmpl.c b/src/parse/func_resolve_tmpl.c index e62b98f7..994f4966 100644 --- a/src/parse/func_resolve_tmpl.c +++ b/src/parse/func_resolve_tmpl.c @@ -64,10 +64,10 @@ ANN static Func fptr_match(const Env env, struct ResolverArgs* f_ptr_args) { const Symbol sym = func_symbol(env, v->from->owner->name, v->name, tmpl_name, 0); const Type exists = nspc_lookup_type0(v->from->owner, sym); if(exists) - return exists->e->d.func; + return exists->info->func; Func m_func = f_ptr_args->m_func; - Func_Def base = v->d.func_ref ? v->d.func_ref->def : exp->func->info->type->e->d.func->def; + Func_Def base = v->d.func_ref ? v->d.func_ref->def : exp->func->info->type->info->func->def; Func_Base *fbase = cpy_func_base(env->gwion->mp, base->base); fbase->xid = sym; fbase->tmpl->base = 0; @@ -157,7 +157,7 @@ ANN Func find_template_match(const Env env, const Value value, const Exp_Call* e return f; Type t = value->from->owner_class; while(t && t->nspc) { - Func_Def fdef = value->d.func_ref ? value->d.func_ref->def : value->type->e->d.func->def; + Func_Def fdef = value->d.func_ref ? value->d.func_ref->def : value->type->info->func->def; const Value v = nspc_lookup_value0(t->nspc, fdef->base->xid); if(!v) goto next; @@ -165,7 +165,7 @@ ANN Func find_template_match(const Env env, const Value value, const Exp_Call* e if(f) return f; next: - t = t->e->parent; + t = t->info->parent; } ERR_O(exp_self(exp)->pos, _("arguments do not match for template call")) } diff --git a/src/parse/operator.c b/src/parse/operator.c index fa3c27b7..f781edac 100644 --- a/src/parse/operator.c +++ b/src/parse/operator.c @@ -43,7 +43,7 @@ ANN static Type op_parent(const Env env, const Type t) { *post = '\0'; return nspc_lookup_type1(env->curr, insert_symbol(env->gwion->st, name)); } - return t->e->parent; + return t->info->parent; } static m_bool op_match(const restrict Type t, const restrict Type mo) { diff --git a/src/parse/scan0.c b/src/parse/scan0.c index 30ace78f..de2ba44a 100644 --- a/src/parse/scan0.c +++ b/src/parse/scan0.c @@ -24,7 +24,7 @@ static inline void context_global(const Env env) { 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); - type->e->ctx = env->context; + type->info->ctx = env->context; return type; } @@ -35,7 +35,7 @@ ANN static inline m_bool scan0_defined(const Env env, const Symbol s, const loc_ } ANN static void fptr_assign(const Env env, const Fptr_Def fptr) { - const Func_Def def = fptr->type->e->d.func->def; + const Func_Def def = fptr->type->info->func->def; if(GET_FLAG(fptr->base, global)) { context_global(env); SET_FLAG(fptr->value, global); @@ -61,7 +61,7 @@ static void fptr_def(const Env env, const Fptr_Def fptr) { fptr->base->func = new_func(env->gwion->mp, s_name(fptr->base->xid), def); fptr->value->d.func_ref = fptr->base->func; fptr->base->func->value_ref = fptr->value; - fptr->type->e->d.func = fptr->base->func; + fptr->type->info->func = fptr->base->func; def->base->func = fptr->base->func; } @@ -70,9 +70,9 @@ ANN m_bool scan0_fptr_def(const Env env, const Fptr_Def fptr) { 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]); - t->e->owner = !(!env->class_def && GET_FLAG(fptr->base, global)) ? + t->info->owner = !(!env->class_def && GET_FLAG(fptr->base, global)) ? env->curr : env->global_nspc; - t->e->owner_class = env->class_def; + t->info->owner_class = env->class_def; if(GET_FLAG(fptr->base, global)) context_global(env); t->nspc = new_nspc(env->gwion->mp, name); @@ -84,7 +84,7 @@ ANN m_bool scan0_fptr_def(const Env env, const Fptr_Def fptr) { if(env->class_def) fptr_assign(env, fptr); set_vflag(fptr->value, vflag_func); - add_type(env, t->e->owner, t); + add_type(env, t->info->owner, t); mk_class(env, t); type_addref(t); return GW_OK; @@ -120,8 +120,8 @@ ANN static void typedef_simple(const Env env, const Type_Def tdef, const Type ba if(GET_FLAG(tdef->ext, global)) context_global(env); add_type(env, nspc, t); - t->e->owner = nspc; - t->e->owner_class = env->class_def; + t->info->owner = nspc; + t->info->owner_class = env->class_def; tdef->type = t; if(base->nspc) nspc_addref((t->nspc = base->nspc)); @@ -132,7 +132,7 @@ ANN static void typedef_simple(const Env env, const Type_Def tdef, const Type ba } ANN static m_bool typedef_complex(const Env env, const Type_Def tdef, const Type base) { - const ae_flag flag = base->e->cdef ? base->e->cdef->flag : 0; + const ae_flag flag = base->info->cdef ? base->info->cdef->flag : 0; const Class_Def cdef = new_class_def(env->gwion->mp, flag, tdef->xid, cpy_type_decl(env->gwion->mp, tdef->ext), NULL, loc_cpy(env->gwion->mp, td_pos(tdef->ext))); @@ -144,12 +144,13 @@ ANN static m_bool typedef_complex(const Env env, const Type_Def tdef, const Type ANN static void typedef_fptr(const Env env, const Type_Def tdef, const Type base) { tdef->type = type_copy(env->gwion->mp, base); + tdef->type->info->func = base->info->func; nspc_addref(tdef->type->nspc); tdef->type->name = s_name(tdef->xid); - tdef->type->e->parent = base; + tdef->type->info->parent = base; add_type(env, env->curr, tdef->type); mk_class(env, tdef->type); - if(base->e->d.func->def->base->tmpl) + if(base->info->func->def->base->tmpl) set_tflag(tdef->type, tflag_ftmpl); } @@ -185,10 +186,10 @@ ANN static Type enum_type(const Env env, const Enum_Def edef) { 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->e->parent = env->gwion->type[et_int]; + t->info->parent = env->gwion->type[et_int]; const Nspc nspc = GET_FLAG(edef, global) ? env->global_nspc : env->curr; - t->e->owner = nspc; - t->e->owner_class = env->class_def; + t->info->owner = nspc; + t->info->owner_class = env->class_def; add_type(env, nspc, t); mk_class(env, t); scan0_implicit_similar(env, t, env->gwion->type[et_int]); @@ -217,10 +218,10 @@ ANN static Type union_type(const Env env, const Symbol s, const m_bool add) { t->xid = ++env->scope->type_xid; t->name = name; t->nspc = new_nspc(env->gwion->mp, name); - t->e->owner = t->nspc->parent = env->curr; - t->e->owner_class = env->class_def; - t->e->parent = env->gwion->type[et_union]; - t->e->tuple = new_tupleform(env->gwion->mp, NULL); + t->info->owner = t->nspc->parent = env->curr; + t->info->owner_class = env->class_def; + t->info->parent = env->gwion->type[et_union]; + t->info->tuple = new_tupleform(env->gwion->mp, NULL); add_type(env, env->curr, t); if(add) mk_class(env, t); @@ -231,7 +232,7 @@ ANN static void union_tmpl(const Env env, const Union_Def udef) { if(tmpl_base(udef->tmpl)) { const Union_Def u = cpy_union_def(env->gwion->mp, udef); u->type = udef->type; - udef->type->e->udef = u; + udef->type->info->udef = u; set_tflag(u->type, tflag_tmpl); set_tflag(u->type, tflag_udef); } @@ -303,7 +304,7 @@ ANN static Type get_parent_base(const Env env, Type_Decl *td) { while(owner) { if(t == owner) ERR_O(td_pos(td), _("'%s' as parent inside itself\n."), owner->name); - owner = owner->e->owner_class; + owner = owner->info->owner_class; } return t; } @@ -338,14 +339,14 @@ ANN static Type scan0_class_def_init(const Env env, const Class_Def cdef) { const Type t = scan0_type(env, ++env->scope->type_xid, s_name(cdef->base.xid), parent); if(cflag(cdef, cflag_struct)) set_tflag(t, tflag_struct); - t->e->tuple = new_tupleform(env->gwion->mp, parent); - t->e->owner = env->curr; - t->e->owner_class = env->class_def; + t->info->tuple = new_tupleform(env->gwion->mp, parent); + t->info->owner = env->curr; + t->info->owner_class = env->class_def; t->nspc = new_nspc(env->gwion->mp, t->name); t->nspc->parent = env->curr; - t->e->cdef = cdef; + t->info->cdef = cdef; t->flag |= cdef->flag; - add_type(env, t->e->owner, t); + add_type(env, t->info->owner, t); cdef_flag(cdef, t); if(cdef->base.ext && cdef->base.ext->array) set_tflag(t, tflag_typedef); @@ -388,7 +389,7 @@ ANN m_bool scan0_class_def(const Env env, const Class_Def c) { env->curr = (Nspc)vector_pop(&env->scope->nspc_stack); if(cpy && cdef->base.type) { c->base.type = cdef->base.type; - c->base.type->e->cdef = cdef; + c->base.type->info->cdef = cdef; set_tflag(c->base.type, tflag_cdef); set_tflag(cdef->base.type, tflag_scan0);// redundant } diff --git a/src/parse/scan1.c b/src/parse/scan1.c index da0e8d3a..03cc838d 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -17,16 +17,19 @@ ANN static inline m_bool type_cyclic(const Env env, const Type t, const Type_Dec while(parent) { if(parent == owner) ERR_B(td_pos(td), _("%s declared inside %s"), t->name, owner->name); - parent = parent->e->parent; + parent = parent->info->parent; } - } while((owner = owner->e->owner_class)); + } while((owner = owner->info->owner_class)); return GW_OK; } ANN static inline m_bool ensure_scan1(const Env env, const Type t) { + const Type base = get_type(t); + if(tflag(base, tflag_scan1) || !(tflag(base, tflag_cdef) || tflag(base, tflag_udef))) + return GW_OK; struct EnvSet es = { .env=env, .data=env, .func=(_exp_func)scan1_cdef, .scope=env->scope->depth, .flag=tflag_scan1 }; - return envset_run(&es, t); + return envset_run(&es, base); } ANN static Type scan1_type(const Env env, Type_Decl* td) { @@ -34,8 +37,7 @@ ANN static Type scan1_type(const Env env, Type_Decl* td) { const Type t = get_type(type); if(!env->func && env->class_def && !GET_FLAG(td, ref)) CHECK_BO(type_cyclic(env, t, td)) - if(!tflag(t, tflag_scan1)) - CHECK_BO(ensure_scan1(env, t)) + CHECK_BO(ensure_scan1(env, t)) return type; } @@ -52,7 +54,7 @@ ANN static Type scan1_exp_decl_type(const Env env, Exp_Decl* decl) { DECL_OO(const Type ,t, = void_type(env, decl->td)) if(decl->td->xid == insert_symbol("auto") && decl->type) return decl->type; - if(GET_FLAG(t, private) && t->e->owner != env->curr) + if(GET_FLAG(t, private) && t->info->owner != env->curr) ERR_O(exp_self(decl)->pos, _("can't use private type %s"), t->name) if(GET_FLAG(t, protect) && (!env->class_def || isa(t, env->class_def) < 0)) ERR_O(exp_self(decl)->pos, _("can't use protected type %s"), t->name) @@ -103,7 +105,7 @@ ANN static m_bool scan1_decl(const Env env, const Exp_Decl* decl) { if(var->array && !var->array->exp) SET_FLAG(decl->td, ref); if(env->class_def) { - if(env->class_def->e->tuple) + if(env->class_def->info->tuple) tuple_contains(env, v); } else if(!env->scope->depth) set_vflag(v, vflag_fglobal);// file global @@ -132,7 +134,7 @@ ANN m_bool scan1_exp_decl(const Env env, const Exp_Decl* decl) { if(global) { if(env->context) env->context->global = 1; - if(!is_global(decl->type->e->owner, env->global_nspc)) + if(!is_global(decl->type->info->owner, env->global_nspc)) ERR_B(exp_self(decl)->pos, _("type '%s' is not global"), decl->type->name) } const m_uint scope = !global ? env->scope->depth : env_push_global(env); @@ -321,7 +323,7 @@ ANN m_bool scan1_enum_def(const Env env, const Enum_Def edef) { SET_FLAG(v, const); set_vflag(v, vflag_valid); set_vflag(v, vflag_enum); - nspc_add_value(edef->t->e->owner, list->xid, v); + nspc_add_value(edef->t->info->owner, list->xid, v); vector_add(&edef->values, (vtype)v); } while((list = list->next)); return GW_OK; @@ -389,8 +391,8 @@ ANN m_bool scan1_fptr_def(const Env env, const Fptr_Def fptr) { ANN m_bool scan1_type_def(const Env env, const Type_Def tdef) { if(!tdef->type) tdef->type = nspc_lookup_type0(env->curr, tdef->xid); - if(!tdef->type->e->cdef)return GW_OK; - return !is_fptr(env->gwion, tdef->type) ? scan1_cdef(env, tdef->type) : GW_OK; + return (!is_fptr(env->gwion, tdef->type) && tdef->type->info->cdef) ? + scan1_cdef(env, tdef->type) : GW_OK; } ANN static m_bool scan1_union_def_action(const Env env, const Union_Def udef, @@ -579,11 +581,11 @@ HANDLE_SECTION_FUNC(scan1, m_bool, Env) ANN static Type scan1_get_parent(const Env env, const Type_Def tdef) { const Type parent = known_type(env, tdef->ext); - CHECK_OO((tdef->type->e->parent = parent)); + CHECK_OO((tdef->type->info->parent = parent)); Type t = parent; do if(tdef->type == t) ERR_O(td_pos(tdef->ext), _("recursive (%s <= %s) class declaration."), tdef->type->name, t->name) - while((t = t->e->parent)); + while((t = t->info->parent)); return parent; } @@ -592,13 +594,9 @@ ANN static m_bool scan1_parent(const Env env, const Class_Def cdef) { if(cdef->base.ext->array) CHECK_BB(scan1_exp(env, cdef->base.ext->array->exp)) DECL_OB(const Type , parent, = scan1_get_parent(env, &cdef->base)) -// if(GET_FLAG(parent, abstract)) // could be final -//SET_FLAG(cdef->base.type, abstract); -// ERR_B(td_pos(cdef->base.ext), _("can't inherit from abstract parent class '%s'\n."), parent->name); if(isa(parent, env->gwion->type[et_object]) < 0) ERR_B(pos, _("cannot extend primitive type '%s'"), parent->name) - if(!tflag(parent, tflag_scan1)) - CHECK_BB(ensure_scan1(env, parent)) + CHECK_BB(ensure_scan1(env, parent)) if(type_ref(parent)) ERR_B(pos, _("can't use ref type in class extend")) if(tflag(parent, tflag_nonnull)) @@ -622,8 +620,8 @@ ANN m_bool scan1_class_def(const Env env, const Class_Def cdef) { if(tflag(t, tflag_scan1)) return GW_OK; set_tflag(t, tflag_scan1); - if(t->e->owner_class && !tflag(t->e->owner_class, tflag_scan1)) - CHECK_BB(ensure_scan1(env, t->e->owner_class)) + if(t->info->owner_class) + CHECK_BB(ensure_scan1(env, t->info->owner_class)) if(cdef->base.ext) CHECK_BB(cdef_parent(env, cdef)) if(cdef->body) diff --git a/src/parse/scan2.c b/src/parse/scan2.c index 618dbc10..102b7c4e 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -14,15 +14,17 @@ ANN static m_bool scan2_stmt(const Env, const Stmt); ANN static m_bool scan2_stmt_list(const Env, Stmt_List); ANN static inline m_bool ensure_scan2(const Env env, const Type t) { + const Type base = get_type(t); + if(tflag(base, tflag_scan2) || !(tflag(base, tflag_cdef) || tflag(base, tflag_udef))) + return GW_OK; struct EnvSet es = { .env=env, .data=env, .func=(_exp_func)scan2_cdef, .scope=env->scope->depth, .flag=tflag_scan2 }; - return envset_run(&es, t); + return envset_run(&es, base); } ANN static m_bool scan2_decl(const Env env, const Exp_Decl* decl) { const Type t = get_type(decl->type); - if(!tflag(t, tflag_scan2)) - CHECK_BB(ensure_scan2(env, t)) + CHECK_BB(ensure_scan2(env, t)) Var_Decl_List list = decl->list; do { const Var_Decl var = list->self; @@ -74,7 +76,7 @@ ANN static Value scan2_func_assign(const Env env, const Func_Def d, ANN m_bool scan2_fptr_def(const Env env NUSED, const Fptr_Def fptr) { if(!tmpl_base(fptr->base->tmpl)) { - const Func_Def def = fptr->type->e->d.func->def; + const Func_Def def = fptr->type->info->func->def; if(def->base->args) { RET_NSPC(scan2_args(def)) } @@ -84,8 +86,9 @@ ANN m_bool scan2_fptr_def(const Env env NUSED, const Fptr_Def fptr) { } ANN m_bool scan2_type_def(const Env env, const Type_Def tdef) { - if(!tdef->type->e->cdef) return GW_OK; - return !is_fptr(env->gwion, tdef->type) ? scan2_class_def(env, tdef->type->e->cdef) : GW_OK; + if(!tdef->type->info->cdef) return GW_OK; + return (!is_fptr(env->gwion, tdef->type) && tdef->type->info->cdef) ? + scan2_class_def(env, tdef->type->info->cdef) : GW_OK; } ANN static inline Value prim_value(const Env env, const Symbol s) { @@ -307,7 +310,7 @@ ANN static m_bool scan2_func_def_overload(const Env env, const Func_Def f, const if(!fbflag(f->base, fbflag_internal)) ERR_B(f->pos, _("function name '%s' is already used by another value"), overload->name) } - const Func obase = !fptr ? overload->d.func_ref : overload->type->e->d.base_type->e->d.func; + const Func obase = !fptr ? overload->d.func_ref : overload->type->info->base_type->info->func; if(GET_FLAG(obase->def->base, final)) ERR_B(f->pos, _("can't overload final function %s"), overload->name) const m_bool base = tmpl_base(f->base->tmpl); @@ -330,11 +333,11 @@ ANN static Type func_type(const Env env, const Func func) { const Type base = env->gwion->type[func->def->base->td ? et_function : et_lambda]; const Type t = type_copy(env->gwion->mp, base); t->xid = ++env->scope->type_xid; - t->e->parent = base; + t->info->parent = base; t->name = func->name; - t->e->owner = env->curr; - t->e->owner_class = env->class_def; - t->e->d.func = func; + t->info->owner = env->curr; + t->info->owner_class = env->class_def; + t->info->func = func; return t; } @@ -393,7 +396,7 @@ ANN2(1, 2) static m_bool scan2_fdef_tmpl(const Env env, const Func_Def f, const } } while((ff = ff->next) && ++i); } - } while(type && (type = type->e->parent) && (nspc = type->nspc)); + } while(type && (type = type->info->parent) && (nspc = type->nspc)); --i; const Symbol sym = func_symbol(env, env->curr->name, name, "template", i); nspc_add_value(env->curr, sym, value); @@ -546,9 +549,8 @@ ANN m_bool scan2_func_def(const Env env, const Func_Def fdef) { HANDLE_SECTION_FUNC(scan2, m_bool, Env) ANN static m_bool scan2_parent(const Env env, const Class_Def cdef) { - const Type parent = cdef->base.type->e->parent; - if(!tflag(parent, tflag_scan2)) - CHECK_BB(ensure_scan2(env, parent)) + const Type parent = cdef->base.type->info->parent; + CHECK_BB(ensure_scan2(env, parent)) if(cdef->base.ext->array) CHECK_BB(scan2_exp(env, cdef->base.ext->array->exp)) return GW_OK; @@ -569,8 +571,8 @@ ANN m_bool scan2_class_def(const Env env, const Class_Def cdef) { const Type t = cdef->base.type; if(tflag(t, tflag_scan2)) return GW_OK; - if(t->e->owner_class && !tflag(t->e->owner_class, tflag_scan2)) - CHECK_BB(ensure_scan2(env, t->e->owner_class)) + if(t->info->owner_class) + CHECK_BB(ensure_scan2(env, t->info->owner_class)) set_tflag(t, tflag_scan2); if(cdef->base.ext) CHECK_BB(cdef_parent(env, cdef)) diff --git a/src/parse/scanx.c b/src/parse/scanx.c index 45345b92..39a491eb 100644 --- a/src/parse/scanx.c +++ b/src/parse/scanx.c @@ -43,8 +43,8 @@ scanx_body(const Env e, const Class_Def c, const _exp_func f, void* d) { __attribute__((returns_nonnull)) ANN Type unflag_type(const Type t) { - const Type type = !tflag(t, tflag_nonnull) ? t : t->e->parent; - return !tflag(type, tflag_force) ? type : type->e->parent; + const Type type = !tflag(t, tflag_nonnull) ? t : t->info->parent; + return !tflag(type, tflag_force) ? type : type->info->parent; } __attribute__((returns_nonnull)) @@ -56,9 +56,9 @@ ANN Type get_type(const Type t) { ANN m_bool scanx_cdef(const Env env, void* opt, const Type base, const _exp_func f_cdef, const _exp_func f_union) { const Type t = get_type(base); - if(t->e->parent != env->gwion->type[et_union]) - return f_cdef(opt, t->e->cdef); - const m_bool ret = f_union(opt, t->e->udef); + if(t->info->parent != env->gwion->type[et_union]) + return f_cdef(opt, t->info->cdef); + const m_bool ret = f_union(opt, t->info->udef); return ret; } diff --git a/src/parse/template.c b/src/parse/template.c index 63c159c3..9a0127ff 100644 --- a/src/parse/template.c +++ b/src/parse/template.c @@ -33,10 +33,10 @@ ANN static m_bool push_types(const Env env, const Tmpl *tmpl) { } ANN static m_bool _template_push(const Env env, const Type t) { - if(t->e->owner_class) - CHECK_BB(template_push(env, t->e->owner_class)) + if(t->info->owner_class) + CHECK_BB(template_push(env, t->info->owner_class)) if(tflag(t, tflag_tmpl)) - return push_types(env, t->e->cdef->base.tmpl); // incorrect + return push_types(env, t->info->cdef->base.tmpl); // incorrect return GW_OK; } @@ -60,41 +60,41 @@ ANN Tmpl* mk_tmpl(const Env env, const Tmpl *tm, const Type_List types) { static ANN Type scan_func(const Env env, const Type t, const Type_Decl* td) { DECL_OO(const m_str, tl_name, = tl2str(env, td->types)) - const Symbol sym = func_symbol(env, t->e->owner->name, t->e->d.func->name, tl_name, 0); + const Symbol sym = func_symbol(env, t->info->owner->name, t->info->func->name, tl_name, 0); free_mstr(env->gwion->mp, tl_name); - const Type base_type = nspc_lookup_type1(t->e->owner, sym); + const Type base_type = nspc_lookup_type1(t->info->owner, sym); if(base_type) return base_type; const Type ret = type_copy(env->gwion->mp, t); - ret->e->parent = t; + ret->info->parent = t; ret->name = s_name(sym); set_tflag(ret, tflag_ftmpl); - nspc_add_type_front(t->e->owner, sym, ret); - void* func_ptr = t->e->d.func->def->d.dl_func_ptr; - if(vflag(t->e->d.func->value_ref, vflag_builtin)) - t->e->d.func->def->d.dl_func_ptr = NULL; - 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); + nspc_add_type_front(t->info->owner, sym, ret); + void* func_ptr = t->info->func->def->d.dl_func_ptr; + if(vflag(t->info->func->value_ref, vflag_builtin)) + t->info->func->def->d.dl_func_ptr = NULL; + const Func_Def def = cpy_func_def(env->gwion->mp, t->info->func->def); + const Func func = ret->info->func = new_func(env->gwion->mp, s_name(sym), def); const Value value = new_value(env->gwion->mp, ret, s_name(sym)); func->flag = def->base->flag; - if(vflag(t->e->d.func->value_ref, vflag_member)) + if(vflag(t->info->func->value_ref, vflag_member)) set_vflag(value, vflag_member); value->d.func_ref = func; - value->from->owner = t->e->owner; - value->from->owner_class = t->e->owner_class; + value->from->owner = t->info->owner; + value->from->owner_class = t->info->owner_class; func->value_ref = value; - func->def->base->tmpl = mk_tmpl(env, t->e->d.func->def->base->tmpl, td->types); + func->def->base->tmpl = mk_tmpl(env, t->info->func->def->base->tmpl, td->types); def->base->func = func; - nspc_add_value_front(t->e->owner, sym, value); - if(vflag(t->e->d.func->value_ref, vflag_builtin)) { + nspc_add_value_front(t->info->owner, sym, value); + if(vflag(t->info->func->value_ref, vflag_builtin)) { builtin_func(env->gwion->mp, func, func_ptr); - t->e->d.func->def->d.dl_func_ptr = func_ptr; + t->info->func->def->d.dl_func_ptr = func_ptr; } return ret; } static ANN Type maybe_func(const Env env, const Type t, const Type_Decl* td) { - if(isa(t, env->gwion->type[et_function]) > 0 && t->e->d.func->def->base->tmpl) + if(isa(t, env->gwion->type[et_function]) > 0 && t->info->func->def->base->tmpl) return scan_func(env, t, td); ERR_O(td->pos, _("type '%s' is not template. You should not provide template types"), t->name) diff --git a/src/parse/type_decl.c b/src/parse/type_decl.c index 74fa427f..fae410c5 100644 --- a/src/parse/type_decl.c +++ b/src/parse/type_decl.c @@ -8,7 +8,7 @@ ANN static Type resolve(const Env env, Type_Decl* td) { DECL_OO(const Type, base, = find_type(env, td)) - if(base->e->ctx && base->e->ctx->error) + if(base->info->ctx && base->info->ctx->error) ERR_O(td_pos(td), _("type '%s' is invalid"), base->name) DECL_OO(const Type, t, = scan_type(env, base, td)) const Type ret = !td->array ? t : array_type(env, t, td->array->depth); diff --git a/src/vm/gack.c b/src/vm/gack.c index d6f08853..a4338d3f 100644 --- a/src/vm/gack.c +++ b/src/vm/gack.c @@ -58,7 +58,7 @@ ANN static void prepare_call(const VM_Shred shred, const m_uint offset) { ANN void gack(const VM_Shred shred, const m_uint offset) { const Type t = *(Type*)shred->reg; - const VM_Code code = get_gack(t)->e->gack; + const VM_Code code = get_gack(t)->info->gack; if(code->builtin) { const m_uint sz = *(m_uint*)(shred->reg + SZ_INT); ((f_gack)code->native_func)(t, (shred->reg - sz), shred);