From: fennecdjay Date: Thu, 3 Nov 2022 09:59:17 +0000 (+0100) Subject: :bug: Fixes X-Git-Tag: nightly~207^2~95 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=1cb2327956d7fc67f62ee64131c769ee478c6967;p=gwion.git :bug: Fixes --- diff --git a/src/emit/emit.c b/src/emit/emit.c index b419cb2f..dd10aae4 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -569,14 +569,14 @@ static void emit_exp_addref1(const Emitter emit, const Exp exp, m_int size) { emit_compound_addref(emit, exp->type, size, exp_getvar(exp)); } -ANN2(1) -static void emit_exp_addref(const Emitter emit, /* const */ Exp exp, +/*ANN2(1) +static void emit_exp_addref(const Emitter emit, Exp exp, m_int size) { do { emit_exp_addref1(emit, exp, size); size += exp_size(exp); } while ((exp = exp->next)); -} +}*/ ANN static inline m_bool emit_exp1(const Emitter emit, const Exp e) { const Exp next = e->next; @@ -589,6 +589,7 @@ ANN static inline m_bool emit_exp1(const Emitter emit, const Exp e) { ANN static m_bool emit_prim_array_exp(const Emitter emit, const Type t, Exp e) { do { CHECK_BB(emit_exp1(emit, e)); + emit_exp_addref1(emit, e, -t->size); emit_regmove(emit, - t->size + t->actual_size); } while((e = e->next)); return GW_OK; @@ -600,7 +601,6 @@ ANN static m_bool emit_prim_array(const Emitter emit, const Array_Sub *data) { const Type base = array_base_simple(type); if(!base->actual_size) CHECK_BB(emit_exp(emit, e)); else CHECK_BB(emit_prim_array_exp(emit, base, e)); - emit_exp_addref(emit, e, -exp_totalsize(e)); m_uint count = 0; do ++count; while ((e = e->next)); @@ -1309,6 +1309,7 @@ ANN static m_bool emit_new_struct(const Emitter emit,const Exp_Call *call) { emit_regpushmem4(emit, offset, 0); } emit_add_instr(emit, NoOp); + CHECK_BB(emit_exp_call1(emit, call->func->type->info->func, is_static_call(emit->gwion, call->func))); // is a ctor, is_static is true return GW_OK; } @@ -1340,28 +1341,22 @@ ANN static m_bool _emit_exp_call(const Emitter emit, const Exp_Call *call) { const Func f = t->info->func; if(unlikely(is_new_struct(f, exp_self(call)->type))) emit_new_struct(emit, call); - else if (f != emit->env->func || (f && f->value_ref->from->owner_class)) - CHECK_BB(prepare_call(emit, call)); - else CHECK_BB(emit_func_args(emit, call)); - CHECK_BB(emit_exp_call1(emit, f, is_static_call(emit->gwion, call->func))); + else { + if (f != emit->env->func || (f && f->value_ref->from->owner_class)) + CHECK_BB(prepare_call(emit, call)); + else CHECK_BB(emit_func_args(emit, call)); + CHECK_BB(emit_exp_call1(emit, f, is_static_call(emit->gwion, call->func))); + } return GW_OK; } ANN static m_bool emit_exp_call(const Emitter emit, const Exp_Call *exp_call) { - const Exp e = exp_self(exp_call); - if (exp_getvar(e)) emit_regmove(emit, SZ_INT); CHECK_BB(_emit_exp_call(emit, exp_call)); - const Type t = exp_self(exp_call)->type; + const Exp e = exp_self(exp_call); if (exp_getvar(e)) { emit_regmove(emit, -exp_self(exp_call)->type->size); - if(isa(t, emit->gwion->type[et_object]) > 0) - emit_local_exp(emit, e); - const Instr instr = emit_add_instr(emit, Reg2RegAddr); - instr->m_val = -SZ_INT; - } else { - if (!is_func(emit->gwion, exp_call->func->type) && // is_callable - tflag(e->type, tflag_struct)) - emit_regmove(emit, -SZ_INT); + const Instr instr = emit_add_instr(emit, RegPushMem4); + instr->m_val = emit_local_exp(emit, e); } return GW_OK; } diff --git a/src/lib/dict.c b/src/lib/dict.c index c662853e..0e8c2a81 100644 --- a/src/lib/dict.c +++ b/src/lib/dict.c @@ -84,7 +84,7 @@ static clear_fn* o_clear[3] = { clear_on, clear_oo, clear_os }; static clear_fn* s_clear[3] = { clear_sn, clear_so, clear_ss }; static clear_fn*const* clear[3] = { n_clear, o_clear, s_clear }; -ANN static void hmapinfo_init(HMapInfo *const info, const Type types[], const Type key, const Type val) { +ANN static void hmapinfo_init(HMapInfo *const info, const Type key, const Type val) { info->key = key; info->val = val; info->sz = key->size + val->size; @@ -643,7 +643,7 @@ static OP_CHECK(opck_dict_scan) { type_addref(t); } HMapInfo *const hinfo = (HMapInfo*)t->nspc->class_data; - hmapinfo_init(hinfo, env->gwion->type, key, val); + hmapinfo_init(hinfo, key, val); if(hinfo->keyk + hinfo->valk) { t->nspc->dtor = new_vmcode(env->gwion->mp, NULL, NULL, "@dtor", SZ_INT, true, false); t->nspc->dtor->native_func = (m_uint)dict_clear_dtor; diff --git a/src/lib/object_op.c b/src/lib/object_op.c index 4aa44c55..7f386984 100644 --- a/src/lib/object_op.c +++ b/src/lib/object_op.c @@ -171,7 +171,6 @@ ANN static inline void emit_struct_data(const Emitter emit, const Value v, const bool emit_addr) { const Instr instr = emit_structmember(emit, v->type->size, emit_addr); instr->m_val = v->from->offset; - instr->m_val2 = 3; if (!emit_addr) emit_regmove(emit, v->type->size - SZ_INT); } @@ -272,9 +271,8 @@ OP_EMIT(opem_object_dot) { const Exp_Dot *member = (Exp_Dot *)data; const Type t_base = member_type(emit->gwion, member->base->type); const Value value = find_value(t_base, member->xid); - if(!tflag(t_base, tflag_emit) /*&& emit->env->class_def != t_base*/) { - ensure_emit(emit, t_base); - } +// if(!tflag(t_base, tflag_emit) /*&& emit->env->class_def != t_base*/) +// ensure_emit(emit, t_base); if (is_class(emit->gwion, value->type)) { emit_pushimm(emit, (m_uint)value->type); return GW_OK; diff --git a/src/parse/check.c b/src/parse/check.c index 91cd41fa..ee4afd8f 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -593,12 +593,13 @@ ANN m_bool check_traverse_fdef(const Env env, const Func_Def fdef) { const m_uint scope = env->scope->depth; env->scope->depth = 0; vector_init(&v); - Vector w = (Vector)&env->curr->info->value->ptr; + const Vector w = (Vector)&env->curr->info->value->ptr; m_uint i = vector_size(w); while (i-- > 1) vector_add(&v, vector_at(w, i)); + VLEN(w) = 1; const m_bool ret = traverse_func_def(env, fdef); for (m_uint i = vector_size(&v) + 1; --i;) - vector_add((Vector)&env->curr->info->value->ptr, vector_at(&v, i - 1)); + vector_add(w, vector_at(&v, i - 1)); vector_release(&v); env->scope->depth = scope; return ret; @@ -1008,7 +1009,7 @@ ANN static Type check_exp_binary(const Env env, const Exp_Binary *bin) { e->exp_type = ae_exp_unary; unary->unary_type = unary_td; unary->op = insert_symbol("new"); - unary->ctor.td = new_type_decl(env->gwion->mp, insert_symbol("auto"), bin->rhs->d.exp_unary.ctor.td->pos); + unary->ctor.td = cpy_type_decl(env->gwion->mp, bin->rhs->d.exp_unary.ctor.td); unary->ctor.exp = lhs; free_exp(env->gwion->mp, rhs); return check_exp(env, e); @@ -1999,7 +2000,7 @@ ANN static m_bool check_body(const Env env, Section *const section) { return ret; } -ANN static bool class_def_has_body(const Env env, Ast ast) { +ANN static bool class_def_has_body(Ast ast) { for(m_uint i = 0; i < ast->len; i++) { const Section *section = mp_vector_at(ast, Section, i); if (section->section_type == ae_section_stmt) { @@ -2105,7 +2106,7 @@ ANN static m_bool _check_class_def(const Env env, const Class_Def cdef) { if (!tflag(t, tflag_struct)) inherit(t); if (cdef->body) { CHECK_BB(env_body(env, cdef, check_body)); - if (cflag(cdef, cflag_struct) || class_def_has_body(env, cdef->body)) + if (cflag(cdef, cflag_struct) || class_def_has_body(cdef->body)) set_tflag(t, tflag_ctor); } if (!GET_FLAG(cdef, abstract)) CHECK_BB(check_abstract(env, cdef));