From 5ab7a6bdde8ebc0ed634ff2f979379e1708c289a Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Thu, 29 Jul 2021 18:27:24 +0200 Subject: [PATCH] :art: use npsc_allocdata in type checking --- plug | 2 +- src/emit/emit.c | 8 ++++---- src/import/import_cdef.c | 1 - src/lib/opfunc.c | 2 +- src/parse/check.c | 4 +++- src/parse/scan0.c | 3 ++- 6 files changed, 11 insertions(+), 9 deletions(-) diff --git a/plug b/plug index 5bbcb7bd..6dc4bc7c 160000 --- a/plug +++ b/plug @@ -1 +1 @@ -Subproject commit 5bbcb7bd4c570fe76b0b868e8b1fbdf6dfa8b5f9 +Subproject commit 6dc4bc7ca452a1a44168135c7e8dcf9ebdba94f7 diff --git a/src/emit/emit.c b/src/emit/emit.c index 5a215ba9..c84c5b3c 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -1342,7 +1342,7 @@ ANN static Instr get_prelude(const Emitter emit, const Func f, if (is_fptr(emit->gwion, t)) { if (f->def->base->tmpl) tmpl_prelude(emit, f); } - if (fp || f != emit->env->func || !is_static || + if (fp || f != emit->env->func || (!is_static && strcmp(s_name(f->def->base->xid), "new"))|| strstr(emit->code->name, "ork~")) { const Instr instr = emit_add_instr(emit, SetCode); instr->udata.one = 1; @@ -2217,9 +2217,10 @@ ANN static m_bool emit_enum_def(const Emitter emit, const Enum_Def edef) { v->from->offset = emit_local(emit, emit->gwion->type[et_int]); v->d.num = i; } else - *(m_bit *)(emit->env->class_def->nspc->info->class_data + + *(m_uint *)(emit->env->class_def->nspc->info->class_data + v->from->offset) = i; } + set_tflag(edef->t, tflag_emit); return GW_OK; } @@ -2736,15 +2737,14 @@ ANN static m_bool cdef_parent(const Emitter emit, const Class_Def cdef) { ANN static m_bool emit_class_def(const Emitter emit, const Class_Def cdef) { if (tmpl_base(cdef->base.tmpl)) return GW_OK; const Type t = cdef->base.type; - const Class_Def c = t->info->cdef; if (tflag(t, tflag_emit)) return GW_OK; set_tflag(t, tflag_emit); + const Class_Def c = t->info->cdef; const Type owner = t->info->value->from->owner_class; if (owner) CHECK_BB(ensure_emit(emit, owner)); if (c->base.ext && t->info->parent->info->cdef && !tflag(t->info->parent, tflag_emit)) // ????? CHECK_BB(cdef_parent(emit, c)); - nspc_allocdata(emit->gwion->mp, t->nspc); if (c->body) { emit_class_code(emit, t->name); if (scanx_body(emit->env, c, (_exp_func)emit_section, emit) > 0) diff --git a/src/import/import_cdef.c b/src/import/import_cdef.c index ee5a1dad..8a0058a1 100644 --- a/src/import/import_cdef.c +++ b/src/import/import_cdef.c @@ -129,7 +129,6 @@ ANN m_int gwi_class_end(const Gwi gwi) { } if (!gwi->gwion->env->class_def) GWI_ERR_B(_("import: too many class_end called.")) - nspc_allocdata(gwi->gwion->mp, gwi->gwion->env->class_def->nspc); const Type t = gwi->gwion->env->class_def; if (tflag(t, tflag_tmpl)) { --gwi->tmpls; diff --git a/src/lib/opfunc.c b/src/lib/opfunc.c index 79b6c091..4bef3204 100644 --- a/src/lib/opfunc.c +++ b/src/lib/opfunc.c @@ -114,7 +114,7 @@ base->type = t; self->d.exp_call.func = func; self->d.exp_call.args = args; self->d.exp_call.tmpl = NULL; - self->d.exp_call.allow_curry = 0; + self->d.exp_call.allow_curry = false; self->exp_type = ae_exp_call; CHECK_BN(traverse_exp(env, self)); return self->type; diff --git a/src/parse/check.c b/src/parse/check.c index c8f29420..dc509863 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -31,6 +31,7 @@ ANN static Type check_internal(const Env env, const Symbol sym, const Exp e, ANN m_bool check_implicit(const Env env, const Exp e, const Type t) { if (e->type == t) return GW_OK; + if (isa(e->type, t) > 0) return GW_OK; const Symbol sym = insert_symbol("@implicit"); return (e->cast_to = check_internal(env, sym, e, t)) ? GW_OK : GW_ERROR; } @@ -820,7 +821,6 @@ ANN Type check_exp_call1(const Env env, Exp_Call *const exp) { if (func) { if (!is_fptr(env->gwion, func->value_ref->type)) // skip function pointers if (func != env->func && func->def && !fflag(func, fflag_valid)) { - // if(!fflag(func, fflag_valid)) { struct EnvSet es = {.env = env, .data = env, .func = (_exp_func)check_cdef, @@ -830,6 +830,7 @@ ANN Type check_exp_call1(const Env env, Exp_Call *const exp) { CHECK_BO(check_func_def(env, func->def)); if (es.run) envset_pop(&es, func->value_ref->from->owner_class); } + exp->func->type = func->value_ref->type; call_add_effect(env, func, exp->func->pos); if (func == env->func) set_fflag(env->func, fflag_recurs); @@ -1815,6 +1816,7 @@ ANN static m_bool _check_class_def(const Env env, const Class_Def cdef) { } } } + nspc_allocdata(env->gwion->mp, t->nspc); return GW_OK; } diff --git a/src/parse/scan0.c b/src/parse/scan0.c index 54a8fb82..d05038ef 100644 --- a/src/parse/scan0.c +++ b/src/parse/scan0.c @@ -218,7 +218,8 @@ ANN static Type enum_type(const Env env, const Enum_Def edef) { add_type(env, env->curr, t); mk_class(env, t, edef->pos); if (global) env_pop(env, 0); - // scan0_implicit_similar(env, t, env->gwion->type[et_int]); +// scan0_implicit_similar(env, t, env->gwion->type[et_int]); +// scan0_implicit_similar(env, env->gwion->type[et_int], t); return t; } -- 2.43.0