From a63878ddbb82f0bebc2a50e9932053658506607c Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Fri, 28 Oct 2022 06:23:13 +0200 Subject: [PATCH] :art: improve struct_release --- src/emit/emit.c | 20 -------------------- src/lib/object.c | 11 +++++++++++ src/lib/object_op.c | 15 --------------- 3 files changed, 11 insertions(+), 35 deletions(-) diff --git a/src/emit/emit.c b/src/emit/emit.c index 348c3065..8c4c7405 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -131,25 +131,6 @@ if(!tflag(t, tflag_tmpl))return GW_OK; return envset_run(&es, t); } -ANN static void emit_struct_dtor(const Emitter emit, const Type type, - const m_uint offset) { - const m_uint code_offset = emit_code_offset(emit); - emit->code->frame->curr_offset += SZ_INT; - emit_regpushmem4(emit, offset, 0); - emit_regtomem(emit, code_offset, -SZ_INT); - emit_pushimm(emit, (m_uint)type); - emit_regtomem(emit, code_offset + SZ_INT, -SZ_INT); - emit_setimm(emit, (m_uint)type->nspc->dtor, SZ_INT); - emit_setimm(emit, code_offset, SZ_INT*2); - emit_regmove(emit, SZ_INT * 2); - const Instr prelude = emit_add_instr(emit, SetCode); - prelude->m_val = -SZ_INT * 4; - prelude->udata.one = 2; - const Instr next = emit_add_instr(emit, Overflow); - next->m_val2 = code_offset; - emit->code->frame->curr_offset -= SZ_INT; -} - ANN void emit_object_release(const Emitter emit, const m_uint offset) { const Instr instr = emit_add_instr(emit, ObjectRelease); instr->m_val = offset; @@ -164,7 +145,6 @@ ANN void emit_compound_release(const Emitter emit, const Type t, const m_uint of ANN void emit_struct_release(const Emitter emit, const Type type, const m_uint offset) { if (!type->info->tuple) return; - if (type->nspc->dtor) emit_struct_dtor(emit, type, offset); const Vector v = &type->info->tuple->types; for (m_uint i = 0; i < vector_size(v); i++) { const Type t = (Type)vector_at(v, i); diff --git a/src/lib/object.c b/src/lib/object.c index 66b02acf..23688de2 100644 --- a/src/lib/object.c +++ b/src/lib/object.c @@ -64,6 +64,17 @@ ANN static void do_release(const M_Object o, return do_release(o, shred, t->info->parent); } +ANN void struct_release(const VM_Shred shred, const Type base, + const m_bit *ptr) { + const Vector types = &base->info->tuple->types; + const Vector offsets = &base->info->tuple->offset; + for (m_uint i = 0; i < vector_size(types); ++i) { + const Type t = (Type)vector_at(types, i); + if (isa(t, shred->info->vm->gwion->type[et_compound]) < 0) continue; + const m_uint offset = vector_at(offsets, i); + compound_release(shred, t, *(m_bit **)(ptr + offset)); + } +} INSTR(DTOR_EOC) { const M_Object o = *(M_Object *)MEM(0); diff --git a/src/lib/object_op.c b/src/lib/object_op.c index a91886d6..ad031595 100644 --- a/src/lib/object_op.c +++ b/src/lib/object_op.c @@ -371,21 +371,6 @@ ANN Type scan_class(const Env env, const Type t, const Type_Decl *td) { return ret; } -ANN void struct_release(const VM_Shred shred, const Type base, - const m_bit *ptr) { - const Vector types = &base->info->tuple->types; - const Vector offsets = &base->info->tuple->offset; - for (m_uint i = 0; i < vector_size(types); ++i) { - const Type t = (Type)vector_at(types, i); - if (isa(t, shred->info->vm->gwion->type[et_compound]) < 0) continue; - const m_uint offset = vector_at(offsets, i); - if (!tflag(t, tflag_struct)) - release(*(M_Object *)(ptr + offset), shred); - else - struct_release(shred, t, *(m_bit **)(ptr + offset)); - } -} - static OP_EMIT(opem_not_object) { const Vector v = &emit->code->instr; const Instr back = (Instr)vector_back(v); -- 2.43.0