From d1cb2cf245db395f5933b97f05caef139e15a494 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Sat, 11 May 2019 21:48:33 +0200 Subject: [PATCH] :shirt: Simplify Type --- include/type.h | 20 ++++++----- src/emit/emit.c | 24 ++++++------- src/lib/array.c | 14 ++++---- src/lib/func.c | 24 ++++++------- src/lib/gack.c | 8 ++--- src/lib/import.c | 30 ++++++++-------- src/lib/instr.c | 4 +-- src/lib/object.c | 8 ++--- src/lib/ptr.c | 4 +-- src/oo/env.c | 4 +-- src/oo/env_utils.c | 6 ++-- src/oo/type.c | 51 ++++++++++++++------------- src/parse/check.c | 76 ++++++++++++++++++++-------------------- src/parse/did_you_mean.c | 2 +- src/parse/operator.c | 4 +-- src/parse/scan0.c | 24 ++++++------- src/parse/scan1.c | 20 +++++------ src/parse/scan2.c | 22 ++++++------ src/parse/template.c | 22 ++++++------ 19 files changed, 186 insertions(+), 181 deletions(-) diff --git a/include/type.h b/include/type.h index c6f73cac..f286ca8d 100644 --- a/include/type.h +++ b/include/type.h @@ -1,16 +1,20 @@ #ifndef __TYPE #define __TYPE + struct TypeInfo_ { + Type parent; + Nspc owner; + Class_Def def; + union type_data { + Func func; + Type base_type; + } d; + }; + struct Type_ { m_str name; Nspc nspc; - Type parent; - Nspc owner; - Class_Def def; - union type_data { - Func func; - Type base_type; - } d; + struct TypeInfo_ *e; size_t xid; size_t size; size_t array_depth; @@ -39,7 +43,7 @@ ANN m_bool type_ref(Type) __attribute__((pure)); __attribute__((returns_nonnull)) ANN Type template_parent(const Env, const Type type); static inline Type actual_type(const Type t) { - return isa(t, t_class) > 0 ? t->d.base_type : t; + return isa(t, t_class) > 0 ? t->e->d.base_type : t; } ANN static inline m_uint env_push_type(const Env env, const Type type) { return env_push(env, type, type->nspc); } #endif diff --git a/src/emit/emit.c b/src/emit/emit.c index 2b55e889..4a9b536d 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -153,8 +153,8 @@ ANN static inline m_uint emit_local(const Emitter emit, const m_uint size, const } ANN static void emit_pre_ctor(const Emitter emit, const Type type) { - if(type->parent) - emit_pre_ctor(emit, type->parent); + if(type->e->parent) + emit_pre_ctor(emit, type->e->parent); if(type->nspc->pre_ctor) emit_ext_ctor(emit, type->nspc->pre_ctor); if(GET_FLAG(type, template) && GET_FLAG(type, builtin)) { @@ -382,7 +382,7 @@ ANN static m_bool prim_array(const Emitter emit, const Exp_Primary * primary) { ANN static m_uint get_depth(Type t) { m_uint depth = 0; do depth += t->array_depth; - while((t = t->parent)); + while((t = t->e->parent)); return depth; } @@ -615,8 +615,8 @@ ANN static m_bool emit_class_def(const Emitter, const Class_Def); ANN static m_bool emit_exp_decl_template(const Emitter emit, const Exp_Decl* decl) { const Type t = typedef_base(decl->type); if(!GET_FLAG(t, emit)) { - CHECK_BB(template_push_types(emit->env, t->def->tmpl->list.list, t->def->tmpl->base)) - CHECK_BB(emit_class_def(emit, t->def)) + CHECK_BB(template_push_types(emit->env, t->e->def->tmpl->list.list, t->e->def->tmpl->base)) + CHECK_BB(emit_class_def(emit, t->e->def)) emit_pop_type(emit); } return GW_OK; @@ -798,7 +798,7 @@ if(vector_size(&emit->code->instr)) { ANN static m_bool emit_template_code(const Emitter emit, const Func f) { if(GET_FLAG(f, ref)) - CHECK_BB(traverse_template(emit->env, f->value_ref->owner_class->def)) + CHECK_BB(traverse_template(emit->env, f->value_ref->owner_class->e->def)) const Value v = f->value_ref; size_t scope = emit_push(emit, v->owner_class, v->owner); CHECK_BB(emit_func_def(emit, f->def)) @@ -1041,7 +1041,7 @@ ANN2(1) static m_bool emit_exp(const Emitter emit, Exp exp, const m_bool ref) { instr->m_val = exp->emit_var; } if(emit->env->func && isa(exp->type, t_lambda) < 0 && isa(exp->type, t_function) > 0 && - !GET_FLAG(exp->type->d.func->value_ref->d.func_ref, pure)) + !GET_FLAG(exp->type->e->d.func->value_ref->d.func_ref, pure)) UNSET_FLAG(emit->env->func, pure); } while((exp = exp->next)); return GW_OK; @@ -1365,7 +1365,7 @@ ANN static m_bool emit_stmt_case(const Emitter emit, const Stmt_Exp stmt) { } ANN static m_bool emit_stmt_type(const Emitter emit, const Stmt_Type stmt) { - return stmt->type->def ? emit_class_def(emit, stmt->type->def) : 1; + return stmt->type->e->def ? emit_class_def(emit, stmt->type->e->def) : 1; } ANN static m_bool emit_stmt_enum(const Emitter emit, const Stmt_Enum stmt) { @@ -1755,19 +1755,19 @@ ANN static m_bool emit_class_def(const Emitter emit, const Class_Def class_def) const Nspc nspc = type->nspc; if(tmpl_class_base(class_def->tmpl)) return GW_OK; - if(class_def->base.ext && ((/*!GET_FLAG(type->parent, emit) &&*/ + if(class_def->base.ext && ((/*!GET_FLAG(type->e->parent, emit) &&*/ GET_FLAG(class_def->base.ext, typedef)) || class_def->base.ext->types)) { const Type base = class_def->base.ext->array ? - array_base(type->parent) : type->parent; + array_base(type->e->parent) : type->e->parent; if(!base->nspc->pre_ctor) - CHECK_BB(emit_class_def(emit, base->def)) + CHECK_BB(emit_class_def(emit, base->e->def)) } if(nspc->info->class_data_size) nspc->info->class_data = (m_bit*)xcalloc(1, nspc->info->class_data_size); emit_class_push(emit, type); emit_class_code(emit, type->name); if(class_def->base.ext && class_def->base.ext->array) - CHECK_BB(emit_array_extend(emit, type->parent, class_def->base.ext->array->exp)) + CHECK_BB(emit_array_extend(emit, type->e->parent, class_def->base.ext->array->exp)) if(class_def->body) { Class_Body body = class_def->body; do CHECK_BB(emit_section(emit, body->section)) diff --git a/src/lib/array.c b/src/lib/array.c index 528451d7..bc7b2e7d 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->d.base_type) - t = t->d.base_type; + while(t->e->d.base_type) + t = t->e->d.base_type; return t; } @@ -186,11 +186,11 @@ static OP_CHECK(opck_array_cast) { const Exp_Cast* cast = (Exp_Cast*)data; Type l = cast->exp->type; Type r = exp_self(cast)->type; - while(!l->d.base_type) - l = l->parent; - while(!r->d.base_type) - r = r->parent; - if(l->array_depth == r->array_depth || isa(l->d.base_type, r->d.base_type) > 0) + while(!l->e->d.base_type) + l = l->e->parent; + while(!r->e->d.base_type) + r = r->e->parent; + if(l->array_depth == r->array_depth || isa(l->e->d.base_type, r->e->d.base_type) > 0) return l; return t_null; } diff --git a/src/lib/func.c b/src/lib/func.c index 36adb8d6..05f8773b 100644 --- a/src/lib/func.c +++ b/src/lib/func.c @@ -39,7 +39,7 @@ static OP_CHECK(opck_func_call) { static OP_EMIT(opem_func_assign) { Exp_Binary* bin = (Exp_Binary*)data; emit_add_instr(emit, int_r_assign); - if((bin->lhs->type != t_lambda && isa(bin->lhs->type, t_fptr) < 0) && GET_FLAG(bin->rhs->type->d.func, member)) { + if((bin->lhs->type != t_lambda && isa(bin->lhs->type, t_fptr) < 0) && GET_FLAG(bin->rhs->type->e->d.func, member)) { const Instr instr = emit_add_instr(emit, LambdaAssign); instr->m_val = SZ_INT; } @@ -47,8 +47,8 @@ static OP_EMIT(opem_func_assign) { } ANN static Type fptr_type(const Env env, Exp_Binary* bin) { - const Func l_func = bin->lhs->type->d.func; - const Func r_func = bin->rhs->type->d.func; + const Func l_func = bin->lhs->type->e->d.func; + const Func r_func = bin->rhs->type->e->d.func; const Nspc nspc = l_func->value_ref->owner; const m_str c = s_name(l_func->def->base->xid); const Value v = l_func->value_ref; @@ -57,7 +57,7 @@ ANN static Type fptr_type(const Env env, Exp_Binary* bin) { const Func f = nspc_lookup_func1(nspc, sym); // was lookup2 CHECK_OO(f) if(compat_func(r_func->def, f->def) > 0) - return r_func->value_ref->type->d.base_type; + return r_func->value_ref->type->e->d.base_type; } return NULL; } @@ -92,15 +92,15 @@ static OP_CHECK(opck_fptr_at) { bin->rhs->emit_var = 1; if(isa(bin->lhs->type, t_lambda) > 0) { Exp_Lambda *l = &bin->lhs->d.exp_lambda; - const Type owner = nspc_lookup_type1(bin->rhs->type->owner->parent, - insert_symbol(bin->rhs->type->owner->name)); - CHECK_BO(check_lambda(env, owner, l, bin->rhs->type->d.func->def)) + const Type owner = nspc_lookup_type1(bin->rhs->type->e->owner->parent, + insert_symbol(bin->rhs->type->e->owner->name)); + CHECK_BO(check_lambda(env, owner, l, bin->rhs->type->e->d.func->def)) return bin->rhs->type; } - const Func l_func = bin->lhs->type->d.func; + const Func l_func = bin->lhs->type->e->d.func; const Func_Def l_fdef = l_func->def; const Type l_type = l_func->value_ref->owner_class; - const Func r_func = bin->rhs->type->d.func; + const Func r_func = bin->rhs->type->e->d.func; const Func_Def r_fdef = r_func->def; const Type r_type = r_func->value_ref->owner_class; if(!r_type && l_type) @@ -133,10 +133,10 @@ static OP_CHECK(opck_fptr_cast) { const Value v = nspc_lookup_value1(env->curr, cast->exp->d.exp_primary.d.var); CHECK_OO(v) const Func f = isa(v->type, t_fptr) > 0 ? - v->type->d.func : + v->type->e->d.func : nspc_lookup_func1(env->curr, insert_symbol(v->name)); CHECK_OO(f) - CHECK_BO(compat_func(t->d.func->def, f->def)) + CHECK_BO(compat_func(t->e->d.func->def, f->def)) cast->func = f; return t; } @@ -144,7 +144,7 @@ static OP_CHECK(opck_fptr_cast) { static OP_EMIT(opem_fptr_cast) { CHECK_BB(opem_basic_cast(emit, data)) Exp_Cast* cast = (Exp_Cast*)data; - if(GET_FLAG(cast->exp->type->d.func, member)) { + if(GET_FLAG(cast->exp->type->e->d.func, member)) { const Instr instr = emit_add_instr(emit, RegPop); instr->m_val = SZ_INT*2; const Instr dup = emit_add_instr(emit, Reg2Reg); diff --git a/src/lib/gack.c b/src/lib/gack.c index 0b3e8472..71be9ccd 100644 --- a/src/lib/gack.c +++ b/src/lib/gack.c @@ -18,7 +18,7 @@ static void print_type(const Type type) { free(name); if(GET_FLAG(type, typedef)) { gw_out(" aka "); - print_type(type->parent); + print_type(type->e->parent); } } @@ -76,9 +76,9 @@ ANN2(1) static inline void print_object(const Type type, const M_Object obj) { } ANN static inline void print_func(const Type type, const m_bit* stack) { - if(type->d.func) { + if(type->e->d.func) { const VM_Code code = isa(type, t_fptr) > 0 ? - *(VM_Code*)stack : type->d.func->code; + *(VM_Code*)stack : type->e->d.func->code; gw_out("%s %s %p", type->name, (void*)code ? code->name : NULL, code); } else gw_out("%s %p", type->name, NULL); @@ -116,7 +116,7 @@ ANN void gack(const m_bit* reg, const Instr instr) { else if(type == t_class) print_type(type); else if(isa(type, t_class) > 0) - print_type(type->d.base_type); + print_type(type->e->d.base_type); else if(isa(type, t_void) > 0) print_string1("void"); else diff --git a/src/lib/import.c b/src/lib/import.c index 89a82a9f..258012b8 100644 --- a/src/lib/import.c +++ b/src/lib/import.c @@ -205,12 +205,12 @@ ANN2(1,2) static void import_class_ini(const Env env, const Type type, mk_xtor(env->gwion->mp, type, (m_uint)pre_ctor, ae_flag_ctor); if(dtor) mk_xtor(env->gwion->mp, type, (m_uint)dtor, ae_flag_dtor); - if(type->parent) { - type->nspc->info->offset = type->parent->nspc->info->offset; - if(type->parent->nspc->info->vtable.ptr) - vector_copy2(&type->parent->nspc->info->vtable, &type->nspc->info->vtable); + if(type->e->parent) { + type->nspc->info->offset = type->e->parent->nspc->info->offset; + if(type->e->parent->nspc->info->vtable.ptr) + vector_copy2(&type->e->parent->nspc->info->vtable, &type->nspc->info->vtable); } - type->owner = env->curr; + type->e->owner = env->curr; SET_FLAG(type, checked); env_push_type(env, type); } @@ -220,9 +220,9 @@ ANN2(1,2) m_int gwi_class_ini(const Gwi gwi, const Type type, const f_xtor pre_c GWI_ERR_B("during import: class '%s' already imported.", type->name) if(gwi->templater.n) { const ID_List types = templater_def(gwi->gwion->st, gwi); - type->def = new_class_def(gwi->gwion->mp, 0, insert_symbol(gwi->gwion->st, type->name), NULL, NULL, loc_cpy(gwi->gwion->mp, gwi->loc)); - type->def->tmpl = new_tmpl_class(gwi->gwion->mp, types, -1); - type->def->base.type = type; + type->e->def = new_class_def(gwi->gwion->mp, 0, insert_symbol(gwi->gwion->st, type->name), NULL, NULL, loc_cpy(gwi->gwion->mp, gwi->loc)); + type->e->def->tmpl = new_tmpl_class(gwi->gwion->mp, types, -1); + type->e->def->base.type = type; SET_FLAG(type, template); } else SET_FLAG(type, scan1 | ae_flag_scan2 | ae_flag_check | ae_flag_emit); @@ -235,17 +235,17 @@ ANN m_int gwi_class_ext(const Gwi gwi, Type_Decl* td) { if(!gwi->gwion->env->class_def) GWI_ERR_B("gwi_class_ext invoked before gwi_class_ini") const VM_Code ctor = gwi->gwion->env->class_def->nspc->pre_ctor; - if(gwi->gwion->env->class_def->parent || - (gwi->gwion->env->class_def->def && gwi->gwion->env->class_def->def->base.ext)) + if(gwi->gwion->env->class_def->e->parent || + (gwi->gwion->env->class_def->e->def && gwi->gwion->env->class_def->e->def->base.ext)) GWI_ERR_B("class extend already set") if(td->array && !td->array->exp) GWI_ERR_B("class extend array can't be empty") - if(!gwi->gwion->env->class_def->def) { + if(!gwi->gwion->env->class_def->e->def) { const Type t = known_type(gwi->gwion->env, td); CHECK_OB(t) if(td->array) SET_FLAG(gwi->gwion->env->class_def, typedef); - gwi->gwion->env->class_def->parent = t; + gwi->gwion->env->class_def->e->parent = t; gwi->gwion->env->class_def->nspc->info->offset = t->nspc->info->offset; if(t->nspc->info->vtable.ptr) vector_copy2(&t->nspc->info->vtable, &gwi->gwion->env->class_def->nspc->info->vtable); @@ -259,7 +259,7 @@ ANN m_int gwi_class_ext(const Gwi gwi, Type_Decl* td) { free_type_decl(gwi->gwion->mp, td); } else { SET_FLAG(td, typedef); - gwi->gwion->env->class_def->def->base.ext = td; + gwi->gwion->env->class_def->e->def->base.ext = td; } return GW_OK; } @@ -311,8 +311,8 @@ ANN m_int gwi_item_ini(const Gwi gwi, const restrict m_str type, const restrict #undef gwi_item_end static void gwi_body(const Gwi gwi, const Class_Body body) { - if(!gwi->gwion->env->class_def->def->body) - gwi->gwion->env->class_def->def->body = body; + if(!gwi->gwion->env->class_def->e->def->body) + gwi->gwion->env->class_def->e->def->body = body; else gwi->body->next = body; gwi->body = body; diff --git a/src/lib/instr.c b/src/lib/instr.c index 3037f769..a2eb11a9 100644 --- a/src/lib/instr.c +++ b/src/lib/instr.c @@ -20,7 +20,7 @@ INSTR(EOC) { */ INSTR(DTOR_EOC) { const M_Object o = *(M_Object*)MEM(0); - o->type_ref = o->type_ref->parent; + o->type_ref = o->type_ref->e->parent; __release(o, shred); shred->info->me->ref = 1; vm_shred_exit(shred); @@ -113,6 +113,6 @@ INSTR(DotTmpl) { return; } } - } while((t = t->parent)); + } while((t = t->e->parent)); Except(shred, "MissigTmplException[internal]"); //unreachable } diff --git a/src/lib/object.c b/src/lib/object.c index 80d64c9f..71be400d 100644 --- a/src/lib/object.c +++ b/src/lib/object.c @@ -57,7 +57,7 @@ __attribute__((hot)) ANN void __release(const M_Object o, const VM_Shred shred) { MemPool p = shred->info->mp;// = shred->info->vm->gwion->mp; Type t = o->type_ref; - while(t->parent) { + while(t->e->parent) { struct scope_iter iter = { t->nspc->info->value, 0, 0 };\ Value v; while(scope_iter(&iter, &v) > 0) { @@ -73,7 +73,7 @@ ANN void __release(const M_Object o, const VM_Shred shred) { return; } } - t = t->parent; + t = t->e->parent; } free_object(p, o); } @@ -119,7 +119,7 @@ static OP_CHECK(at_object) { static inline Type new_force_type(MemPool p, const Type t, const Symbol sym) { const Type ret = type_copy(p, t); SET_FLAG(ret, force); - nspc_add_type(t->owner, sym, ret); + nspc_add_type(t->e->owner, sym, ret); return ret; } @@ -129,7 +129,7 @@ static Type get_force_type(const Env env, const Type t) { strcpy(name, t->name); strcpy(name + len, STR_FORCE); const Symbol sym = insert_symbol(env->gwion->st, name); - return nspc_lookup_type0(t->owner, sym) ?: new_force_type(env->gwion->mp, t, sym); + return nspc_lookup_type0(t->e->owner, sym) ?: new_force_type(env->gwion->mp, t, sym); } static OP_CHECK(opck_object_cast) { diff --git a/src/lib/ptr.c b/src/lib/ptr.c index 981b05e5..36cddd28 100644 --- a/src/lib/ptr.c +++ b/src/lib/ptr.c @@ -26,7 +26,7 @@ static OP_CHECK(opck_ptr_assign) { bin->lhs->emit_var = 1; return bin->lhs->type; } - } while((t = t->parent)); + } while((t = t->e->parent)); return t_null; } @@ -38,7 +38,7 @@ static INSTR(instr_ptr_assign) { static OP_CHECK(opck_ptr_deref) { const Exp_Unary* unary = (Exp_Unary*)data; - exp_self(unary)->type = nspc_lookup_type1(unary->exp->type->owner, insert_symbol(env->gwion->st, get_type_name(env, unary->exp->type->name, 1))); + exp_self(unary)->type = nspc_lookup_type1(unary->exp->type->e->owner, insert_symbol(env->gwion->st, get_type_name(env, unary->exp->type->name, 1))); return exp_self(unary)->type; } diff --git a/src/oo/env.c b/src/oo/env.c index 7d6a42af..ea3166a3 100644 --- a/src/oo/env.c +++ b/src/oo/env.c @@ -91,13 +91,13 @@ ANN void env_pop(const Env env, const m_uint scope) { ANN void env_add_type(const Env env, const Type type) { const Type v_type = type_copy(env->gwion->mp, t_class); - v_type->d.base_type = type; + v_type->e->d.base_type = type; SET_FLAG(type, builtin); nspc_add_type(env->curr, insert_symbol(type->name), type); const Value v = new_value(env->gwion->mp, v_type, type->name); SET_FLAG(v, checked | ae_flag_const | ae_flag_global | ae_flag_builtin); nspc_add_value(env->curr, insert_symbol(type->name), v); - type->owner = env->curr; + type->e->owner = env->curr; type->xid = ++env->scope->type_xid; } diff --git a/src/oo/env_utils.c b/src/oo/env_utils.c index 27155e5f..66b5911e 100644 --- a/src/oo/env_utils.c +++ b/src/oo/env_utils.c @@ -61,9 +61,9 @@ ANN Type find_type(const Env env, ID_List path) { const Symbol xid = path->xid; if(nspc) { Type t = nspc_lookup_type1(nspc, xid); - while(!t && type && type->parent && type->parent) { - t = nspc_lookup_type1(type->parent->nspc, xid); // was lookup2 - type = type->parent; + while(!t && type && type->e->parent && type->e->parent) { + t = nspc_lookup_type1(type->e->parent->nspc, xid); // was lookup2 + type = type->e->parent; } if(!t) ERR_O(path->pos, "...(cannot find class '%s' in nspc '%s')", s_name(xid), nspc->name) diff --git a/src/oo/type.c b/src/oo/type.c index 4595839e..a31d611a 100644 --- a/src/oo/type.c +++ b/src/oo/type.c @@ -11,7 +11,7 @@ ANN static void free_type(Type a, Gwion gwion) { if(GET_FLAG(a, template)) - free_class_def(gwion->mp, a->def); + free_class_def(gwion->mp, a->e->def); if(a->nspc) REM_REF(a->nspc, gwion); mp_free(gwion->mp, Type, a); @@ -21,53 +21,54 @@ Type new_type(MemPool p, const m_uint xid, const m_str name, const Type parent) const Type type = mp_alloc(p, Type); type->xid = xid; type->name = name; - type->parent = parent; - if(type->parent) + type->e = mp_alloc(p, TypeInfo); + type->e->parent = parent; + if(type->e->parent) type->size = parent->size; INIT_OO(p, type, free_type); return type; } ANN Type type_copy(MemPool p, const Type type) { - const Type a = new_type(p, type->xid, type->name, type->parent); + const Type a = new_type(p, type->xid, type->name, type->e->parent); a->nspc = type->nspc; - a->owner = type->owner; + a->e->owner = type->e->owner; a->size = type->size; - a->d.base_type = type->d.base_type; + a->e->d.base_type = type->e->d.base_type; a->array_depth = type->array_depth; - a->def = type->def; + a->e->def = type->e->def; return a; } ANN m_bool isa(const restrict Type var, const restrict Type parent) { - return (var->xid == parent->xid) ? 1 : var->parent ? isa(var->parent, parent) : -1; + return (var->xid == parent->xid) ? 1 : var->e->parent ? isa(var->e->parent, parent) : -1; } ANN Type find_common_anc(const restrict Type lhs, const restrict Type rhs) { return isa(lhs, rhs) > 0 ? rhs : isa(rhs, lhs) > 0 ? lhs : NULL; } -#define describe_find(name, t) \ -ANN t find_##name(const Type type, const Symbol xid) { \ - if(type->nspc) { \ - const t val = nspc_lookup_##name##0(type->nspc, xid); \ - if(val) \ - return val; \ - } \ - return type->parent ? find_##name(type->parent, xid) : NULL; \ +#define describe_find(name, t) \ +ANN t find_##name(const Type type, const Symbol xid) { \ + if(type->nspc) { \ + const t val = nspc_lookup_##name##0(type->nspc, xid); \ + if(val) \ + return val; \ + } \ + return type->e->parent ? find_##name(type->e->parent, xid) : NULL; \ } describe_find(value, Value) describe_find(func, Func) ANN Type typedef_base(Type t) { while(GET_FLAG(t, typedef)) - t = t->parent; + t = t->e->parent; return t; } ANN Type array_base(Type type) { const Type t = typedef_base(type); - return t->d.base_type; + return t->e->d.base_type; } ANN Type array_type(const Env env, const Type base, const m_uint depth) { @@ -80,19 +81,19 @@ ANN Type array_type(const Env env, const Type base, const m_uint depth) { len += 2; } const Symbol sym = insert_symbol(name); - const Type type = nspc_lookup_type1(base->owner, sym); + const Type type = nspc_lookup_type1(base->e->owner, sym); if(type) return type; const Type t = new_type(env->gwion->mp, t_array->xid, base->name, t_array); t->name = s_name(sym); t->size = SZ_INT; t->array_depth = depth + base->array_depth; - t->d.base_type = base; + t->e->d.base_type = base; t->nspc = t_array->nspc; ADD_REF(t->nspc); SET_FLAG(t, checked); - t->owner = base->owner; - nspc_add_type(base->owner, sym, t); + t->e->owner = base->e->owner; + nspc_add_type(base->e->owner, sym, t); return t; } @@ -106,10 +107,10 @@ ANN m_bool type_ref(Type t) { do { if(GET_FLAG(t, empty)) return GW_OK; - if(GET_FLAG(t, typedef) && t->def) - if(t->def->base.ext && t->def->base.ext->array && !t->def->base.ext->array->exp) + if(GET_FLAG(t, typedef) && t->e->def) + if(t->e->def->base.ext && t->e->def->base.ext->array && !t->e->def->base.ext->array->exp) return GW_OK; - } while((t = t->parent)); + } while((t = t->e->parent)); return 0; } diff --git a/src/parse/check.c b/src/parse/check.c index 467f841a..6432437d 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -31,7 +31,7 @@ ANN m_bool check_exp_array_subscripts(Env env, Exp exp) { } ANN static inline m_bool check_exp_decl_parent(const Env env, const Var_Decl var) { - const Value value = find_value(env->class_def->parent, var->xid); + const Value value = find_value(env->class_def->e->parent, var->xid); if(value) ERR_B(var->pos, "in class '%s': '%s' has already been defined in parent class '%s' ...", @@ -55,7 +55,7 @@ ANN static inline void decl_static(const Nspc nspc, const Value v) { \ ANN static m_bool check_fptr_decl(const Env env, const Var_Decl var) { const Value v = var->value; - const Func func = v->type->d.func; + const Func func = v->type->e->d.func; const Type type = func->value_ref->owner_class; if(!env->class_def) { if(!type || GET_FLAG(func, global)) @@ -110,14 +110,14 @@ ANN Type check_exp_decl(const Env env, const Exp_Decl* decl) { ERR_O(td_pos(decl->td), "can't infer type."); if(GET_FLAG(decl->type , template)) { const Type t = typedef_base(decl->type); - CHECK_BO(traverse_template(env, t->def)) + CHECK_BO(traverse_template(env, t->e->def)) } const m_bool global = GET_FLAG(decl->td, global); const m_uint scope = !global ? env->scope->depth : env_push_global(env); do { const Var_Decl var = list->self; const Value v = var->value; - if(env->class_def && !env->scope->depth && env->class_def->parent) + if(env->class_def && !env->scope->depth && env->class_def->e->parent) CHECK_BO(check_exp_decl_parent(env, var)) if(var->array && var->array->exp) CHECK_BO(check_exp_array_subscripts(env, var->array->exp)) @@ -310,8 +310,8 @@ ANN Type check_exp_array(const Env env, const Exp_Array* array) { while(t_base && array->array->depth > t_base->array_depth) { depth -= t_base->array_depth; - if(t_base->parent) - t_base = t_base->parent; + if(t_base->e->parent) + t_base = t_base->e->parent; else ERR_O(exp_self(array)->pos, "array subscripts (%i) exceeds defined dimension (%i)", @@ -325,7 +325,7 @@ ANN static Type_List mk_type_list(const Env env, const Type type) { struct Vector_ v; vector_init(&v); vector_add(&v, (vtype)insert_symbol(type->name)); - Nspc nspc = type->owner; + Nspc nspc = type->e->owner; while(nspc && nspc != env->curr && nspc != env->global_nspc) { const Type t = nspc_lookup_type0(nspc->parent, insert_symbol(nspc->name)); vector_add(&v, (vtype)insert_symbol(t->name)); @@ -347,9 +347,9 @@ ANN static m_bool func_match_inner(const Env env, const Exp e, const Type t, array_base(e->type) == array_base(t); if(!match) { if(e->type == t_lambda && isa(t, t_fptr) > 0) { - const Type owner = nspc_lookup_type1(t->owner->parent, - insert_symbol(t->owner->name)); - return check_lambda(env, owner, &e->d.exp_lambda, t->d.func->def); + const Type owner = nspc_lookup_type1(t->e->owner->parent, + insert_symbol(t->e->owner->name)); + return check_lambda(env, owner, &e->d.exp_lambda, t->e->d.func->def); } if(implicit) { const struct Implicit imp = { e, t }; @@ -478,7 +478,7 @@ ANN Func find_template_match(const Env env, const Value value, const Exp_Call* e if(f) return f; next: - t = t->parent; + t = t->e->parent; } assert(exp_self(exp)); ERR_O(exp_self(exp)->pos, "arguments do not match for template call") @@ -499,7 +499,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->d.func; + Func up = f->e->d.func; do { gw_err("(%s)\t", up->name); const Arg_List e = up->def->base->args; @@ -536,7 +536,7 @@ ANN static Type check_exp_call_template(const Env env, const Exp_Call *exp) { const Exp call = exp->func; const Exp args = exp->args; m_uint args_number = 0; - const Value value = nspc_lookup_value1(call->type->owner, insert_symbol(call->type->name)); + const Value value = nspc_lookup_value1(call->type->e->owner, insert_symbol(call->type->name)); CHECK_OO(value) const m_uint type_number = get_type_number(value->d.func_ref->def->tmpl->list); Type_List tl[type_number]; @@ -601,15 +601,15 @@ ANN Type check_exp_call1(const Env env, const Exp_Call *exp) { 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->d.func, ref)) { - const Value value = exp->func->type->d.func->value_ref; - CHECK_BO(traverse_template(env, value->owner_class->def)) + if(GET_FLAG(exp->func->type->e->d.func, ref)) { + const Value value = exp->func->type->e->d.func->value_ref; + CHECK_BO(traverse_template(env, value->owner_class->e->def)) } if(exp->args) CHECK_OO(check_exp(env, exp->args)) if(GET_FLAG(exp->func->type, func)) return check_exp_call_template(env, exp); - const Func func = find_func_match(env, exp->func->type->d.func, exp->args); + const Func func = find_func_match(env, exp->func->type->e->d.func, exp->args); return (exp_self(exp)->d.exp_call.m_func = func) ? func->def->base->ret_type : function_alternative(env, exp->func->type, exp->args, exp_self(exp)->pos); } @@ -648,7 +648,7 @@ ANN static Type check_exp_call(const Env env, Exp_Call* exp) { if(exp->tmpl) { CHECK_OO(check_exp(env, exp->func)) const Type t = actual_type(exp->func->type); - const Value v = nspc_lookup_value1(t->owner, insert_symbol(t->name)); + const Value v = nspc_lookup_value1(t->e->owner, insert_symbol(t->name)); if(!v) ERR_O(exp_self(exp)->pos, " template call of non-existant function.") if(!GET_FLAG(v, func)) @@ -695,7 +695,7 @@ ANN static Type check_exp_dot(const Env env, Exp_Dot* member) { const m_str str = s_name(member->xid); CHECK_OO((member->t_base = check_exp(env, member->base))) const m_bool base_static = isa(member->t_base, t_class) > 0; - const Type the_base = base_static ? member->t_base->d.base_type : member->t_base; + const Type the_base = base_static ? member->t_base->e->d.base_type : member->t_base; if(!the_base->nspc) ERR_O(member->base->pos, "type '%s' does not have members - invalid use in dot expression of %s", @@ -728,7 +728,7 @@ ANN static Type check_exp_dot(const Env env, Exp_Dot* member) { } ANN m_bool check_stmt_type(const Env env, const Stmt_Type stmt) { - return stmt->type->def ? check_class_def(env, stmt->type->def) : 1; + return stmt->type->e->def ? check_class_def(env, stmt->type->e->def) : 1; } ANN static Type check_exp_lambda(const Env env NUSED, const Exp_If* exp_if NUSED) { return t_lambda; } @@ -736,7 +736,7 @@ ANN static Type check_exp_lambda(const Env env NUSED, ANN static Type check_exp_typeof(const Env env, const Exp_Typeof *exp) { const Type t = check_exp(env, exp->exp); CHECK_OO(t) - const Value v = nspc_lookup_value1(t->owner, insert_symbol(t->name)); + const Value v = nspc_lookup_value1(t->e->owner, insert_symbol(t->name)); CHECK_OO(v) return v->type; } @@ -753,7 +753,7 @@ ANN static inline Type check_exp(const Env env, const Exp exp) { do { CHECK_OO((curr->type = exp_func[curr->exp_type](env, &curr->d))) if(env->func && isa(curr->type, t_lambda) < 0 && isa(curr->type, t_function) > 0 && - !GET_FLAG(curr->type->d.func, pure)) + !GET_FLAG(curr->type->e->d.func, pure)) UNSET_FLAG(env->func, pure); } while((curr = curr->next)); return exp->type; @@ -808,7 +808,7 @@ ANN static m_bool do_stmt_auto(const Env env, const Stmt_Auto stmt) { Type ptr = array_base(t); const m_uint depth = t->array_depth - 1; if(GET_FLAG(t, typedef)) - t = t->parent; + t = t->e->parent; if(!t || !ptr || isa(t, t_array) < 0) ERR_B(stmt_self(stmt)->pos, "type '%s' is not array.\n" " This is not allowed in auto loop", stmt->exp->type->name) @@ -835,7 +835,7 @@ ANN static m_bool do_stmt_auto(const Env env, const Stmt_Auto stmt) { } ptr = type_decl_resolve(env, &td); if(!GET_FLAG(ptr, checked)) - check_class_def(env, ptr->def); + check_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)); @@ -1029,7 +1029,7 @@ ANN static m_bool parent_match_actual(const Env env, const restrict Func_Def f, ANN static m_bool check_parent_match(const Env env, const Func_Def f) { const Func func = f->base->func; - const Type parent = env->class_def->parent; + const Type parent = env->class_def->e->parent; if(parent) { const Value v = find_value(parent, f->base->xid); if(v && isa(v->type, t_function) > 0) { @@ -1081,8 +1081,8 @@ ANN static m_bool check_func_overload(const Env env, const Func_Def f) { ANN static m_bool check_func_def_override(const Env env, const Func_Def f) { const Func func = f->base->func; - if(env->class_def && env->class_def->parent) { - const Value override = find_value(env->class_def->parent, f->base->xid); + if(env->class_def && env->class_def->e->parent) { + const Value override = find_value(env->class_def->e->parent, f->base->xid); if(override && override->owner_class && isa(override->type, t_function) < 0) ERR_B(f->pos, "function name '%s' conflicts with previously defined value...\n" @@ -1158,22 +1158,22 @@ ANN static m_bool check_class_parent(const Env env, const Class_Def class_def) { if(class_def->base.ext->array) { CHECK_BB(check_exp_array_subscripts(env, class_def->base.ext->array->exp)) if(!GET_FLAG(class_def->base.type, check) && class_def->tmpl) - REM_REF(class_def->base.type->parent->nspc, env->gwion); + REM_REF(class_def->base.type->e->parent->nspc, env->gwion); } if(class_def->base.ext->types) { - const Type t = class_def->base.type->parent->array_depth ? - array_base(class_def->base.type->parent) : class_def->base.type->parent; + const Type t = class_def->base.type->e->parent->array_depth ? + array_base(class_def->base.type->e->parent) : class_def->base.type->e->parent; if(!GET_FLAG(t, checked)) { if(class_def->tmpl) CHECK_BB(template_push_types(env, class_def->tmpl->list.list, class_def->tmpl->base)) - CHECK_BB(traverse_template(env, t->def)) + CHECK_BB(traverse_template(env, t->e->def)) if(class_def->tmpl) nspc_pop_type(env->gwion->mp, env->curr); } } - if(!GET_FLAG(class_def->base.type->parent, checked)) - CHECK_BB(check_class_def(env, class_def->base.type->parent->def)) - if(GET_FLAG(class_def->base.type->parent, typedef)) + if(!GET_FLAG(class_def->base.type->e->parent, checked)) + CHECK_BB(check_class_def(env, class_def->base.type->e->parent->e->def)) + if(GET_FLAG(class_def->base.type->e->parent, typedef)) SET_FLAG(class_def->base.type, typedef); return GW_OK; } @@ -1188,7 +1188,7 @@ ANN static m_bool check_class_body(const Env env, const Class_Def class_def) { } ANN static inline void inherit(const Type t) { - const Nspc nspc = t->nspc, parent = t->parent->nspc; + const Nspc nspc = t->nspc, parent = t->e->parent->nspc; nspc->info->offset = parent->info->offset; if(parent->info->vtable.ptr) vector_copy2(&parent->info->vtable, &nspc->info->vtable); @@ -1197,15 +1197,15 @@ ANN static inline void inherit(const Type t) { ANN m_bool check_class_def(const Env env, const Class_Def class_def) { if(tmpl_class_base(class_def->tmpl)) return GW_OK; - if(class_def->base.type->parent == t_undefined) { - class_def->base.type->parent = check_td(env, class_def->base.ext); + if(class_def->base.type->e->parent == t_undefined) { + class_def->base.type->e->parent = check_td(env, class_def->base.ext); return traverse_class_def(env, class_def); } const Type the_class = class_def->base.type; if(class_def->base.ext) CHECK_BB(check_class_parent(env, class_def)) else - the_class->parent = t_object; + the_class->e->parent = t_object; inherit(the_class); if(class_def->body) CHECK_BB(check_class_body(env, class_def)) diff --git a/src/parse/did_you_mean.c b/src/parse/did_you_mean.c index ad0e1a61..eb4fa609 100644 --- a/src/parse/did_you_mean.c +++ b/src/parse/did_you_mean.c @@ -64,7 +64,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->parent) && t->nspc); + while((t = t->e->parent) && t->nspc); for(m_uint i = 0; i < vector_size(&v); ++i) gw_err("\t(did you mean '%s'?)\n", (m_str)vector_at(&v, i)); did_you_mean_nspc(type->nspc, name); diff --git a/src/parse/operator.c b/src/parse/operator.c index 6fe647a0..bb5f9b3e 100644 --- a/src/parse/operator.c +++ b/src/parse/operator.c @@ -58,7 +58,7 @@ ANN static Type op_parent(const Env env, const Type t) { c[len] = 0; return nspc_lookup_type1(env->curr, insert_symbol(env->gwion->st, c)); } - return t->parent; + return t->e->parent; } static m_bool op_match(const restrict Type t, const restrict Type mo) { @@ -198,7 +198,7 @@ ANN static m_bool handle_instr(const Emitter emit, const M_Operator* mo) { ANN static Nspc get_nspc(const struct Op_Import* opi) { if(opi->op == op_impl) - return opi->rhs->owner; + return opi->rhs->e->owner; if(opi->op == op_cast) return ((Exp_Cast*)opi->data)->nspc; if(opi->lhs) { diff --git a/src/parse/scan0.c b/src/parse/scan0.c index bd98c82b..561577d6 100644 --- a/src/parse/scan0.c +++ b/src/parse/scan0.c @@ -14,10 +14,10 @@ ANN static Value mk_class(const Env env, const Type base) { const Type t = type_copy(env->gwion->mp, t_class); const Value v = new_value(env->gwion->mp, t, base->name); - t->d.base_type = base; - v->owner = base->owner; + t->e->d.base_type = base; + v->owner = base->e->owner; SET_FLAG(v, const | ae_flag_checked); - nspc_add_value(base->owner, insert_symbol(base->name), v); + nspc_add_value(base->e->owner, insert_symbol(base->name), v); return v; } @@ -32,12 +32,12 @@ ANN m_bool scan0_stmt_fptr(const Env env, const Stmt_Fptr stmt) { CHECK_BB(scan0_defined(env, stmt->base->xid, td_pos(stmt->base->td))); const m_str name = s_name(stmt->base->xid); const Type t = new_type(env->gwion->mp, t_fptr->xid, name, t_fptr); - t->owner = !(!env->class_def && GET_FLAG(stmt->base->td, global)) ? + t->e->owner = !(!env->class_def && GET_FLAG(stmt->base->td, global)) ? env->curr : env->global_nspc; t->nspc = new_nspc(env->gwion->mp, name); t->flag = stmt->base->td->flag; stmt->type = t; - nspc_add_type(t->owner, stmt->base->xid, t); + nspc_add_type(t->e->owner, stmt->base->xid, t); stmt->value = mk_class(env, t); return GW_OK; } @@ -53,13 +53,13 @@ ANN m_bool scan0_stmt_type(const Env env, const Stmt_Type stmt) { const Nspc nspc = (!env->class_def && GET_FLAG(stmt->ext, global)) ? env->global_nspc : env->curr; nspc_add_type(nspc, stmt->xid, t); - t->owner = nspc; + t->e->owner = nspc; stmt->type = t; t->flag = stmt->ext->flag | ae_flag_checked; if(stmt->ext->array && !stmt->ext->array->exp) SET_FLAG(t, empty); } else { - const ae_flag flag = base->def ? base->def->flag : 0; + const ae_flag flag = base->e->def ? base->e->def->flag : 0; const Class_Def cdef = new_class_def(env->gwion->mp, flag, stmt->xid, stmt->ext, NULL, loc_cpy(env->gwion->mp, td_pos(stmt->ext))); CHECK_BB(scan0_class_def(env, cdef)) @@ -81,9 +81,9 @@ ANN m_bool scan0_stmt_enum(const Env env, const Stmt_Enum stmt) { const Type t = type_copy(env->gwion->mp, t_int); t->xid = ++env->scope->type_xid; t->name = stmt->xid ? s_name(stmt->xid) : "int"; - t->parent = t_int; + t->e->parent = t_int; const Nspc nspc = GET_FLAG(stmt, global) ? env->global_nspc : env->curr; - t->owner = nspc; + t->e->owner = nspc; stmt->t = t; if(stmt->xid) { nspc_add_type(nspc, stmt->xid, t); @@ -99,7 +99,7 @@ ANN static Type union_type(const Env env, const Nspc nspc, const Symbol s, const t->name = name; t->nspc = new_nspc(env->gwion->mp, name); t->nspc->parent = nspc; - t->owner = nspc; + t->e->owner = nspc; if(add) { nspc_add_type(nspc, s, t); mk_class(env, t); @@ -189,10 +189,10 @@ ANN static m_bool scan0_class_def_pre(const Env env, const Class_Def cdef) { ANN static Type scan0_class_def_init(const Env env, const Class_Def cdef) { const Type t = new_type(env->gwion->mp, ++env->scope->type_xid, s_name(cdef->base.xid), t_object); - t->owner = env->curr; + 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->def = cdef; + t->e->def = cdef; t->flag = cdef->flag; if(!strstr(t->name, "<")) nspc_add_type(env->curr, cdef->base.xid, t); diff --git a/src/parse/scan1.c b/src/parse/scan1.c index 00878aa9..3804d27e 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -28,7 +28,7 @@ ANN static Type scan1_exp_decl_type(const Env env, Exp_Decl* decl) { return decl->type; if(GET_FLAG(t, abstract) && !GET_FLAG(decl->td, ref)) ERR_O(exp_self(decl)->pos, "Type '%s' is abstract, declare as ref. (use @)", t->name) - if(GET_FLAG(t, private) && t->owner != env->curr) + if(GET_FLAG(t, private) && t->e->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) @@ -40,7 +40,7 @@ ANN static Type scan1_exp_decl_type(const Env env, Exp_Decl* decl) { ERR_O(exp_self(decl)->pos, "...(note: object of type '%s' declared inside itself)", t->name) } } - decl->base = t->def; + decl->base = t->e->def; return decl->type = t; } @@ -197,7 +197,7 @@ ANN m_bool scan1_stmt_enum(const Env env, const Stmt_Enum stmt) { SET_ACCESS(stmt, v) } SET_FLAG(v, const | ae_flag_enum | ae_flag_checked); - nspc_add_value(stmt->t->owner, list->xid, v); + nspc_add_value(stmt->t->e->owner, list->xid, v); vector_add(&stmt->values, (vtype)v); } while((list = list->next)); return GW_OK; @@ -224,7 +224,7 @@ ANN m_bool scan1_stmt_fptr(const Env env, const Stmt_Fptr stmt) { ANN m_bool scan1_stmt_type(const Env env, const Stmt_Type stmt) { if(!stmt->type) CHECK_BB(scan0_stmt_type(env, stmt)) - return stmt->type->def ? scan1_class_def(env, stmt->type->def) : 1; + return stmt->type->e->def ? scan1_class_def(env, stmt->type->e->def) : 1; } ANN m_bool scan1_stmt_union(const Env env, const Stmt_Union stmt) { @@ -313,7 +313,7 @@ ANN static m_bool scan1_class_parent(const Env env, const Class_Def cdef) { const loc_t pos = td_pos(cdef->base.ext); if(cdef->base.ext->array) CHECK_BB(scan1_exp(env, cdef->base.ext->array->exp)) - const Type parent = cdef->base.type->parent = known_type(env, cdef->base.ext); + const Type parent = cdef->base.type->e->parent = known_type(env, cdef->base.ext); CHECK_OB(parent) if(parent == t_undefined) return GW_OK; @@ -321,15 +321,15 @@ ANN static m_bool scan1_class_parent(const Env env, const Class_Def cdef) { while(t) { if(cdef->base.type == t) ERR_B(pos, "recursive (%s <= %s) class declaration.", cdef->base.type->name, t->name); - t = t->parent; + t = t->e->parent; } if(parent == cdef->base.type) ERR_B(pos, "class '%s' cannot extend itself", cdef->base.type->name); - if(isa(cdef->base.type->parent, t_object) < 0) + if(isa(cdef->base.type->e->parent, t_object) < 0) ERR_B(pos, "cannot extend primitive type '%s'", - cdef->base.type->parent->name) - if(!GET_FLAG(parent, scan1) && parent->def) - CHECK_BB(scan1_class_def(env, parent->def)) + cdef->base.type->e->parent->name) + if(!GET_FLAG(parent, scan1) && parent->e->def) + CHECK_BB(scan1_class_def(env, parent->e->def)) if(type_ref(parent)) ERR_B(pos, "can't use ref type in class extend") return GW_OK; diff --git a/src/parse/scan2.c b/src/parse/scan2.c index c1415d50..58a5b557 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -21,8 +21,8 @@ ANN m_bool scan2_class_def(const Env, const Class_Def); ANN static m_bool scan2_exp_decl_template(const Env env, const Exp_Decl* decl) { CHECK_BB(template_push_types(env, decl->base->tmpl->list.list, decl->td->types)); - CHECK_BB(scan1_class_def(env, decl->type->def)) - CHECK_BB(scan2_class_def(env, decl->type->def)) + CHECK_BB(scan1_class_def(env, decl->type->e->def)) + CHECK_BB(scan2_class_def(env, decl->type->e->def)) nspc_pop_type(env->gwion->mp, env->curr); return GW_OK; } @@ -94,7 +94,7 @@ ANN m_bool scan2_stmt_fptr(const Env env, const Stmt_Fptr ptr) { ptr->base->func = new_func(env->gwion->mp, s_name(ptr->base->xid), def); ptr->value->d.func_ref = ptr->base->func; ptr->base->func->value_ref = ptr->value; - ptr->type->d.func = ptr->base->func; + ptr->type->e->d.func = ptr->base->func; SET_FLAG(ptr->value, func | ae_flag_checked); if(ptr->base->args) CHECK_BB(scan2_args(env, def)) @@ -113,12 +113,12 @@ ANN m_bool scan2_stmt_fptr(const Env env, const Stmt_Fptr ptr) { ptr->value->owner_class = env->class_def; } nspc_add_value(env->curr, ptr->base->xid, ptr->value); - nspc_add_func(ptr->type->owner, ptr->base->xid, ptr->base->func); + nspc_add_func(ptr->type->e->owner, ptr->base->xid, ptr->base->func); return GW_OK; } ANN m_bool scan2_stmt_type(const Env env, const Stmt_Type stmt) { - return stmt->type->def ? scan2_class_def(env, stmt->type->def) : 1; + return stmt->type->e->def ? scan2_class_def(env, stmt->type->e->def) : 1; } ANN static inline Value prim_value(const Env env, const Symbol s) { @@ -323,10 +323,10 @@ ANN static Func scan_new_func(const Env env, const Func_Def f, const m_str name) ANN static Type func_type(const Env env, const Func func) { const Type t = type_copy(env->gwion->mp, t_function); t->name = func->name; - t->owner = env->curr; + t->e->owner = env->curr; if(GET_FLAG(func, member)) t->size += SZ_INT; - t->d.func = func; + t->e->d.func = func; return t; } @@ -381,7 +381,7 @@ ANN2(1, 2) static m_bool scan2_func_def_template(const Env env, const Func_Def f } } while((ff = ff->next) && ++i); } - } while(type && (type = type->parent) && (nspc = type->nspc)); + } while(type && (type = type->e->parent) && (nspc = type->nspc)); --i; const Symbol sym = func_symbol(env, env->curr->name, func_name, "template", i); nspc_add_value(env->curr, sym, value); @@ -541,10 +541,10 @@ ANN m_bool scan2_func_def(const Env env, const Func_Def f) { DECL_SECTION_FUNC(scan2) ANN static m_bool scan2_class_parent(const Env env, const Class_Def cdef) { - const Type t = cdef->base.type->parent->array_depth ? - array_base(cdef->base.type->parent) : cdef->base.type->parent; + const Type t = cdef->base.type->e->parent->array_depth ? + array_base(cdef->base.type->e->parent) : cdef->base.type->e->parent; if(!GET_FLAG(t, scan2) && GET_FLAG(cdef->base.ext, typedef)) - CHECK_BB(scan2_class_def(env, t->def)) + CHECK_BB(scan2_class_def(env, t->e->def)) if(cdef->base.ext->array) CHECK_BB(scan2_exp(env, cdef->base.ext->array->exp)) return GW_OK; diff --git a/src/parse/template.c b/src/parse/template.c index 4fe5772c..d6d9ed36 100644 --- a/src/parse/template.c +++ b/src/parse/template.c @@ -19,7 +19,7 @@ ANN static inline Type owner_type(const Env env, const Type t) { ANEW ANN static Vector get_types(const Env env, Type t) { const Vector v = new_vector(env->gwion->mp); do if(GET_FLAG(t, template)) - vector_add(v, (vtype)t->def->tmpl->list.list); + vector_add(v, (vtype)t->e->def->tmpl->list.list); while((t = owner_type(env, t))); return v; } @@ -35,12 +35,12 @@ ANEW ANN static ID_List id_list_copy(MemPool p, ID_List src) { ANN static ID_List get_total_type_list(const Env env, const Type t) { const Type parent = owner_type(env, t); if(!parent) - return t->def->tmpl ? t->def->tmpl->list.list : NULL; + return t->e->def->tmpl ? t->e->def->tmpl->list.list : NULL; const Vector v = get_types(env, parent); const ID_List base = (ID_List)vector_pop(v); if(!base) { free_vector(env->gwion->mp, v); - return t->def->tmpl ? t->def->tmpl->list.list : NULL; + return t->e->def->tmpl ? t->e->def->tmpl->list.list : NULL; } const ID_List types = id_list_copy(env->gwion->mp, base); ID_List list, tmp = types; @@ -48,7 +48,7 @@ ANN static ID_List get_total_type_list(const Env env, const Type t) { list = (ID_List)vector_pop(v); tmp = (tmp->next = id_list_copy(env->gwion->mp, list)); } - tmp->next = t->def->tmpl->list.list; + tmp->next = t->e->def->tmpl->list.list; free_vector(env->gwion->mp, v); return types; } @@ -91,7 +91,7 @@ ANN static void template_name(const Env env, struct tmpl_info* info, m_str s) { str = tmpl_get(info, str); *str++ = (info->index < size - 1) ? ',' : '>'; } - if(info->cdef->base.type->owner == env->global_nspc) + if(info->cdef->base.type->e->owner == env->global_nspc) sprintf(str, "%p", (void*)env->curr); else *str = '\0'; @@ -116,7 +116,7 @@ ANN m_bool template_match(ID_List base, Type_List call) { ANN static Class_Def template_class(const Env env, const Class_Def def, const Type_List call) { const Symbol name = template_id(env, def, call); const Type t = nspc_lookup_type1(env->curr, name); - return t ? t->def : new_class_def(env->gwion->mp, def->flag, name, def->base.ext, def->body, + return t ? t->e->def : new_class_def(env->gwion->mp, def->flag, name, def->base.ext, def->body, loc_cpy(env->gwion->mp, def->pos)); } @@ -149,16 +149,16 @@ ANN Type scan_type(const Env env, const Type t, const Type_Decl* type) { if(!type->types) ERR_O(type->xid->pos, "you must provide template types for type '%s'", t->name) - if(template_match(t->def->tmpl->list.list, type->types) < 0) + if(template_match(t->e->def->tmpl->list.list, type->types) < 0) ERR_O(type->xid->pos, "invalid template types number") - CHECK_BO(template_push_types(env, t->def->tmpl->list.list, type->types)) - const Class_Def a = template_class(env, t->def, type->types); + CHECK_BO(template_push_types(env, t->e->def->tmpl->list.list, type->types)) + const Class_Def a = template_class(env, t->e->def, type->types); SET_FLAG(a, ref); if(a->base.type) POP_RET(a->base.type); CHECK_BO(scan0_class_def(env, a)) SET_FLAG(a->base.type, template | ae_flag_ref); - a->base.type->owner = t->owner; + a->base.type->e->owner = t->e->owner; if(GET_FLAG(t, builtin)) SET_FLAG(a->base.type, builtin); CHECK_BO(scan1_class_def(env, a)) @@ -170,7 +170,7 @@ ANN Type scan_type(const Env env, const Type t, const Type_Decl* type) { } a->tmpl = new_tmpl_class(env->gwion->mp, get_total_type_list(env, t), 0); a->tmpl->base = type->types; - nspc_add_type(t->owner, insert_symbol(a->base.type->name), a->base.type); + nspc_add_type(t->e->owner, insert_symbol(a->base.type->name), a->base.type); return a->base.type; } else if(type->types) ERR_O(type->xid->pos, -- 2.43.0