From: fennecdjay Date: Thu, 26 Sep 2019 01:09:27 +0000 (+0200) Subject: :art: Use is_class X-Git-Tag: nightly~2199^2~5 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=f7a8349892f95cfbecba2e811718fbd027a27be1;p=gwion.git :art: Use is_class --- diff --git a/include/type.h b/include/type.h index c84b17a1..8b6b56e8 100644 --- a/include/type.h +++ b/include/type.h @@ -45,6 +45,7 @@ ANN Type template_parent(const Env, const Type type); ANN Type actual_type(const struct Gwion_* gwion, const Type t); ANN static inline m_uint env_push_type(const Env env, const Type type) { return env_push(env, type, type->nspc); } ANN m_bool is_fptr(const struct Gwion_*, const Type t); +ANN m_bool is_class(const struct Gwion_*, const Type t); ANN m_uint get_depth(const Type type); typedef enum { diff --git a/src/emit/emit.c b/src/emit/emit.c index 4672516a..8f1eddd6 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -349,7 +349,7 @@ ANN static m_bool emit_symbol(const Emitter emit, const Exp_Primary* prim) { const Value v = prim->value; if(v->from->owner_class) return emit_symbol_owned(emit, prim); - if(isa(v->type, emit->gwion->type[et_class]) > 0) { + if(is_class(emit->gwion, v->type)) { regpushi(emit, (m_uint)actual_type(emit->gwion, v->type)); return GW_OK; } @@ -592,7 +592,7 @@ ANN static m_bool emit_exp_primary(const Emitter emit, const Exp_Primary* prim) ANN static m_bool emit_dot_static_data(const Emitter emit, const Value v, const uint emit_var) { const m_uint size = v->type->size; - if(isa(v->type, emit->gwion->type[et_class]) < 0) { + if(!is_class(emit->gwion, v->type)) { const Instr instr = emit_kind(emit, size, emit_var, dotstatic); instr->m_val = (m_uint)(v->from->owner->info->class_data + v->from->offset); instr->m_val2 = size; @@ -1658,7 +1658,7 @@ ANN static m_bool emit_exp_dot_special(const Emitter emit, const Exp_Dot* member ANN static m_bool emit_member_func(const Emitter emit, const Exp_Dot* member) { const Func f = exp_self(member)->type->e->d.func; - if(isa(member->t_base, emit->gwion->type[et_class]) > 0 || GET_FLAG(member->base->type, force)) { + if(is_class(emit->gwion, member->t_base) || GET_FLAG(member->base->type, force)) { const Instr func_i = emit_add_instr(emit, f->code ? RegPushImm : PushStaticCode); if(f->code) func_i->m_val = (m_uint)(f->code ?: (VM_Code)f); @@ -1689,7 +1689,7 @@ ANN static m_bool emit_exp_dot(const Emitter emit, const Exp_Dot* member) { if(is_special(emit, member->t_base) > 0) return emit_exp_dot_special(emit, member); const Value value = find_value(actual_type(emit->gwion, member->t_base), member->xid); - if(isa(member->t_base, emit->gwion->type[et_class]) < 0 && (GET_FLAG(value, member) || + if(!is_class(emit->gwion, member->t_base) && (GET_FLAG(value, member) || (isa(exp_self(member)->type, emit->gwion->type[et_function]) > 0 && !is_fptr(emit->gwion, exp_self(member)->type))) ) { CHECK_BB(emit_exp(emit, member->base, 0)) diff --git a/src/lib/func.c b/src/lib/func.c index aac3ab48..c469bc2b 100644 --- a/src/lib/func.c +++ b/src/lib/func.c @@ -132,7 +132,7 @@ ANN static Type fptr_type(const Env env, struct FptrInfo *info) { for(m_uint i = 0; i <= v->from->offset && !type; ++i) { const Symbol sym = (!info->lhs->def->base->tmpl || i != 0) ? func_symbol(env, nspc->name, c, stmpl, i) : info->lhs->def->base->xid; - if(isa(info->lhs->value_ref->type, env->gwion->type[et_class]) < 0) + if(!is_class(env->gwion, info->lhs->value_ref->type)) CHECK_OO((info->lhs = nspc_lookup_func1(nspc, sym))) else { DECL_OO(const Type, t, = nspc_lookup_type1(nspc, info->lhs->def->base->xid)) diff --git a/src/oo/env_utils.c b/src/oo/env_utils.c index 69362ac9..52dd0a9d 100644 --- a/src/oo/env_utils.c +++ b/src/oo/env_utils.c @@ -64,7 +64,7 @@ ANN Type find_type(const Env env, ID_List path) { ANN m_bool already_defined(const Env env, const Symbol s, const loc_t pos) { const Value v = nspc_lookup_value0(env->curr, s); - if(!v || isa(v->type, env->gwion->type[et_class]) > 0) + if(!v || is_class(env->gwion, v->type)) return GW_OK; env_err(env, pos, _("'%s' already declared as variable of type '%s'."), s_name(s), v->type->name); diff --git a/src/oo/type.c b/src/oo/type.c index d2274bea..e9d95231 100644 --- a/src/oo/type.c +++ b/src/oo/type.c @@ -195,7 +195,10 @@ ANN m_uint get_depth(const Type type) { ANN m_bool is_fptr(const struct Gwion_* gwion, const Type t) { return isa(actual_type(gwion, t), gwion->type[et_fptr]) > 0; } +ANN inline m_bool is_class(const struct Gwion_* gwion, const Type t) { + return isa(t, gwion->type[et_class]) > 0; +} ANN Type actual_type(const struct Gwion_* gwion, const Type t) { - return isa(t, gwion->type[et_class]) > 0 ? t->e->d.base_type : t; + return is_class(gwion, t) ? t->e->d.base_type : t; } diff --git a/src/oo/value.c b/src/oo/value.c index 7b2c587e..3f1cbfbe 100644 --- a/src/oo/value.c +++ b/src/oo/value.c @@ -14,7 +14,7 @@ ANN static void free_value(Value a, Gwion gwion) { !(GET_FLAG(a, enum) && GET_FLAG(a, builtin) && a->from->owner_class) && isa(t, gwion->type[et_object]) < 0) _mp_free(gwion->mp, t->size, a->d.ptr); - if(isa(t, gwion->type[et_class]) > 0/* || isa(a->type, t_function) > 0*/) + if(is_class(gwion, t)) REM_REF(t, gwion) mp_free(gwion->mp, ValueFrom, a->from); mp_free(gwion->mp, Value, a); diff --git a/src/parse/check.c b/src/parse/check.c index 440e10ea..a0c05072 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -76,8 +76,9 @@ ANN Type check_td(const Env env, Type_Decl *td) { CHECK_BO(scan1_exp(env, td->exp)) CHECK_BO(scan2_exp(env, td->exp)) CHECK_OO(check_exp(env, td->exp)) +// TODO: check me const Type t = actual_type(env->gwion, td->exp->type); - if(!t || (isa(td->exp->type, env->gwion->type[et_class]) < 0 && t == env->gwion->type[et_class])) + if(!t || (is_class(env->gwion, td->exp->type) && t == env->gwion->type[et_class])) ERR_O(td->exp->pos, _("Expression must be of type '%s', not '%s'\n" "maybe you meant typeof(Expression)"), env->gwion->type[et_class]->name, td->exp->type->name); m_uint depth; @@ -113,7 +114,7 @@ ANN Type check_exp_decl(const Env env, const Exp_Decl* decl) { clear_decl(env, decl); CHECK_BO(scan1_exp(env, exp_self(decl))) CHECK_BO(scan2_exp(env, exp_self(decl))) - if(isa(decl->type, env->gwion->type[et_class]) > 0) { + if(is_class(env->gwion, decl->type)) { do { list->self->value->type = env->gwion->type[et_auto]; } while((list = list->next)); @@ -890,7 +891,7 @@ ANN static Type check_exp_if(const Env env, const Exp_If* exp_if) { 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, env->gwion->type[et_class]) > 0; + 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; if(!the_base->nspc) ERR_O(member->base->pos,