From: fennecdjay Date: Thu, 15 Aug 2019 15:28:22 +0000 (+0200) Subject: :art: Improve check_exp_decl X-Git-Tag: nightly~2278 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=81bfdc08eed9a26bf008dfd9b3718ffd812d60de;p=gwion.git :art: Improve check_exp_decl --- diff --git a/src/emit/emit.c b/src/emit/emit.c index f1a4486f..9a7bc160 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -352,6 +352,10 @@ ANN static m_bool emit_symbol(const Emitter emit, const Exp_Primary* prim) { const Value v = prim->value; if(v->owner_class) return emit_symbol_owned(emit, prim); + if(isa(v->type, t_class) > 0) { + regpushi(emit, (m_uint)actual_type(v->type)); + return GW_OK; + } if(GET_FLAG(v, builtin) || GET_FLAG(v, union) || GET_FLAG(v, enum)) return emit_symbol_builtin(emit, prim); const m_uint size = v->type->size; @@ -1070,7 +1074,7 @@ ANN static m_bool emit_exp_lambda(const Emitter emit, const Exp_Lambda * lambda) } ANN static m_bool emit_exp_typeof(const Emitter emit, const Exp_Typeof *exp) { - regpushi(emit, (m_uint)exp->exp->type); + regpushi(emit, (m_uint)actual_type(exp->exp->type)); return GW_OK; } diff --git a/src/lib/engine.c b/src/lib/engine.c index 4313a2a3..4c13145e 100644 --- a/src/lib/engine.c +++ b/src/lib/engine.c @@ -34,6 +34,19 @@ static FREEARG(freearg_gack) { free_vector(((Gwion)gwion)->mp, (Vector)instr->m_val2); } + +#define mk_class_instr(op, arg0, arg1, ...) \ +static INSTR(instr_class_##op) { \ + POP_REG(shred, SZ_INT); \ + const Type l = *(Type*)(shred->reg - SZ_INT); \ + const Type r = *(Type*)(shred->reg); \ + *(m_uint*)(shred->reg - SZ_INT) = isa(arg0, arg1) > 0 __VA_ARGS__; \ +} +mk_class_instr(ge, l, r) +mk_class_instr(gt, l, r, && l != r) +mk_class_instr(le, r, l) +mk_class_instr(lt, r, l, && l != r) + ANN static m_bool import_core_libs(const Gwi gwi) { GWI_OB((t_class = gwi_mk_type(gwi, "Class", SZ_INT, NULL))) GWI_BB(gwi_add_type(gwi, t_class)) @@ -90,6 +103,14 @@ ANN static m_bool import_core_libs(const Gwi gwi) { GWI_BB(import_string(gwi)) GWI_BB(import_shred(gwi)) GWI_BB(import_modules(gwi)) + + GWI_BB(gwi_oper_ini(gwi, "Class", "Class", "int")) + GWI_BB(gwi_oper_end(gwi, "==", int_eq)) + GWI_BB(gwi_oper_end(gwi, ">=", instr_class_ge)) + GWI_BB(gwi_oper_end(gwi, ">", instr_class_gt)) + GWI_BB(gwi_oper_end(gwi, "<=", instr_class_le)) + GWI_BB(gwi_oper_end(gwi, "<", instr_class_lt)) + register_freearg(gwi, SwitchIni, freearg_switchini); register_freearg(gwi, SwitchBranch, freearg_switchbranch); register_freearg(gwi, Gack, freearg_gack); diff --git a/src/parse/check.c b/src/parse/check.c index b2851273..818907dc 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -89,15 +89,21 @@ ANN Type check_td(const Env env, Type_Decl *td) { return t; } +ANN static Type no_xid(const Env env, const Exp_Decl* decl) { + DECL_OO(const Type, t, = check_td(env, decl->td)) + ((Exp_Decl*)decl)->type = NULL; + Var_Decl_List list = decl->list; + do nspc_add_value(env->curr, list->self->xid, NULL); + while((list = list->next)); + CHECK_BO(traverse_decl(env, decl)) + return decl->type; +} + ANN Type check_exp_decl(const Env env, const Exp_Decl* decl) { Var_Decl_List list = decl->list; CHECK_BO(switch_decl(env, exp_self(decl)->pos)) - if(!decl->td->xid) { - DECL_OO(const Type, t, = check_td(env, decl->td)) - ((Exp_Decl*)decl)->type = NULL; - CHECK_BO(scan1_exp(env, exp_self(decl))) - CHECK_BO(scan2_exp(env, exp_self(decl))) - } + if(!decl->td->xid) + return no_xid(env, decl); if(decl->td->xid->xid == insert_symbol("auto")) { // should be better CHECK_BO(scan1_exp(env, exp_self(decl))) CHECK_BO(scan2_exp(env, exp_self(decl))) @@ -117,13 +123,14 @@ ANN Type check_exp_decl(const Env env, const Exp_Decl* decl) { CHECK_BO(check_exp_decl_parent(env, var)) if(var->array && var->array->exp) CHECK_BO(check_exp_array_subscripts(env, var->array->exp)) - if(GET_FLAG(decl->td, member) && env->class_def) { - decl_member(env, v); - if(isa(env->class_def, t_object) > 0) - tuple_info(env, decl->td, var); + if(env->class_def) { + if(GET_FLAG(decl->td, member)) { + decl_member(env, v); + if(isa(env->class_def, t_object) > 0) + tuple_info(env, decl->td, var); + } else if(GET_FLAG(decl->td, static)) + decl_static(env, v); } - else if(GET_FLAG(decl->td, static)) - decl_static(env, v); else if(global || (env->func && GET_FLAG(env->func->def, global))) SET_FLAG(v, abstract); if(isa(decl->type, t_fptr) > 0)