From: Jérémie Astor Date: Sat, 5 Dec 2020 11:03:09 +0000 (+0100) Subject: Improve array extend X-Git-Tag: nightly~1130 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=2509d853f128a9a3f571e54ef4d524be660ca1c7;p=gwion.git Improve array extend --- diff --git a/include/instr.h b/include/instr.h index d709f7e4..3fa4fdde 100644 --- a/include/instr.h +++ b/include/instr.h @@ -50,8 +50,6 @@ INSTR(ArrayAlloc); INSTR(VarargIni); INSTR(VarargCheck); -INSTR(PopArrayClass); - INSTR(DotTmpl); INSTR(GTmpl); diff --git a/src/emit/emit.c b/src/emit/emit.c index b5cd7f29..5cc0e65e 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -231,9 +231,9 @@ ANN static inline void maybe_ctor(const Emitter emit, const Type t) { ANN static void emit_pre_ctor(const Emitter emit, const Type type) { if(type->info->parent) emit_pre_ctor(emit, type->info->parent); - maybe_ctor(emit, type); if(tflag(type, tflag_typedef) && type->info->parent->array_depth) - emit_array_extend(emit, type->info->parent, type->info->cdef->base.ext->array->exp); + emit_array_extend(emit, type, type->info->cdef->base.ext->array->exp); + maybe_ctor(emit, type); } ANN static void struct_expand(const Emitter emit, const Type t) { @@ -287,7 +287,7 @@ ANEW ANN static ArrayInfo* new_arrayinfo(const Emitter emit, const Type t) { for(m_uint i = 1; i < t->array_depth; ++i) vector_add(&info->type, (vtype)array_type(emit->env, base, i)); vector_add(&info->type, (vtype)t); - info->depth = (m_int)t->array_depth; + info->depth = !tflag(t, tflag_typedef) ? t->array_depth : t->info->parent->array_depth; info->base = base; return info; } @@ -334,7 +334,9 @@ ANN void emit_ext_ctor(const Emitter emit, const Type t) { ANN m_bool emit_array_extend(const Emitter emit, const Type t, const Exp e) { CHECK_OB(emit_array_extend_inner(emit, t, e, 0)) - emit_add_instr(emit, PopArrayClass); + regpop(emit, SZ_INT); + const Instr instr = emit_add_instr(emit, Reg2Reg); + instr->m_val = -SZ_INT; emit_add_instr(emit, RegAddRef); return GW_OK; } diff --git a/src/lib/array.c b/src/lib/array.c index d413f071..a14cb6f4 100644 --- a/src/lib/array.c +++ b/src/lib/array.c @@ -63,7 +63,7 @@ static DTOR(array_dtor) { ANN M_Object new_array(MemPool p, const Type t, const m_uint length) { const M_Object a = new_object(p, NULL, t); - const m_uint depth = t->array_depth; + const m_uint depth = !tflag(t, tflag_typedef) ? t->array_depth : t->info->parent->array_depth; const m_uint size = depth > 1 ? SZ_INT : array_base(t)->size; ARRAY(a) = new_m_vector(p, size,length); return a; diff --git a/src/lib/instr.c b/src/lib/instr.c index 775c3f3f..ffe2839b 100644 --- a/src/lib/instr.c +++ b/src/lib/instr.c @@ -22,14 +22,6 @@ INSTR(DTOR_EOC) { vm_shred_exit(shred); } -INSTR(PopArrayClass) { - POP_REG(shred, SZ_INT); - const M_Object obj = *(M_Object*)REG(-SZ_INT); - const M_Object tmp = *(M_Object*)REG(0); - ARRAY(obj) = ARRAY(tmp); - free_object(shred->info->mp, tmp); -} - ANN static Func_Def from_base(const Env env, struct dottmpl_ *const dt, const Nspc nspc) { const Func_Def fdef = dt->def ?: dt->base; const Symbol sym = func_symbol(env, nspc->name, s_name(fdef->base->xid),