From: fennecdjay Date: Mon, 9 Jan 2023 23:32:25 +0000 (+0100) Subject: :art: check structs have smth to release X-Git-Tag: nightly~207^2~15 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=137e8f3d3210c5cd1e0a21253fef7a7b73c682d1;p=gwion.git :art: check structs have smth to release --- diff --git a/include/emit.h b/include/emit.h index 6a540235..4b373004 100644 --- a/include/emit.h +++ b/include/emit.h @@ -84,11 +84,11 @@ ANN m_uint emit_local_exp(const Emitter emit, const Exp); ANN m_bool emit_exp_spork(const Emitter, const Exp_Unary *); ANN m_bool emit_exp(const Emitter, const Exp); -ANN Instr emit_object_addref(const Emitter emit, const m_int size, +ANN void emit_object_addref(const Emitter emit, const m_int size, const bool emit_var); -ANN Instr emit_struct_addref(const Emitter emit, const Type t, const m_int size, +ANN void emit_struct_addref(const Emitter emit, const Type t, const m_int size, const bool emit_var); -ANN static inline Instr emit_compound_addref(const Emitter emit, const Type t, +ANN static inline void emit_compound_addref(const Emitter emit, const Type t, const m_int size, const m_bool emit_var) { return !tflag(t, tflag_struct) ? emit_object_addref(emit, size, emit_var) diff --git a/include/env/tuple.h b/include/env/tuple.h index ea696b23..440fe105 100644 --- a/include/env/tuple.h +++ b/include/env/tuple.h @@ -8,14 +8,9 @@ struct TupleForm_ { uint64_t start; }; -ANN Type tuple_type(const Env, const Vector, const loc_t); ANN void tuple_contains(const Env, const Value); ANN void tuple_info(const Env, const Value); ANN2(1) TupleForm new_tupleform(MemPool p, const Type parent_type); ANN void free_tupleform(const TupleForm tuple, const struct Gwion_ *gwion); -#ifdef __INSTR -INSTR(TupleCtor); -INSTR(TupleMember); -#endif #endif diff --git a/include/env/type.h b/include/env/type.h index 6a1a6bba..d2cf0f41 100644 --- a/include/env/type.h +++ b/include/env/type.h @@ -42,6 +42,7 @@ enum tflag { tflag_ref = 1 << 22, tflag_packed = 1 << 23, tflag_compound = 1 << 24, + tflag_release = 1 << 25, // mark structs that need release } __attribute__((packed)); struct Type_ { diff --git a/src/emit/emit.c b/src/emit/emit.c index 9ec0bad7..7d7cb519 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -139,7 +139,8 @@ ANN void emit_object_release(const Emitter emit, const m_uint offset) { ANN void emit_compound_release(const Emitter emit, const Type t, const m_uint offset) { if(tflag(t, tflag_compound)) return emit_object_release(emit, offset); - emit_struct_release(emit, t, offset); + if(tflag(t, tflag_release)) + emit_struct_release(emit, t, offset); } ANN void emit_struct_release(const Emitter emit, const Type type, @@ -544,21 +545,20 @@ ANN static inline m_uint exp_totalsize(Exp e) { return size; } -ANN Instr emit_object_addref(const Emitter emit, const m_int size, +ANN void emit_object_addref(const Emitter emit, const m_int size, const bool emit_var) { const f_instr exec = !emit_var ? RegAddRef : RegAddRefAddr; const Instr instr = emit_add_instr(emit, exec); instr->m_val = size; - return instr; } -ANN Instr emit_struct_addref(const Emitter emit, const Type t, const m_int size, +ANN void emit_struct_addref(const Emitter emit, const Type t, const m_int size, const bool emit_var) { + if(!tflag(t, tflag_release)) return; const Instr instr = emit_add_instr(emit, !emit_var ? StructRegAddRef : StructRegAddRefAddr); instr->m_val2 = (m_uint)t; instr->m_val = !emit_var ? size : (m_int)-SZ_INT; - return instr; } ANN2(1) diff --git a/src/parse/scan0.c b/src/parse/scan0.c index 466d4c20..a3546c61 100644 --- a/src/parse/scan0.c +++ b/src/parse/scan0.c @@ -310,7 +310,7 @@ ANN static Type scan0_class_def_init(const Env env, const Class_Def cdef) { if (cflag(cdef, cflag_struct)) { t->size = 0; set_tflag(t, tflag_struct); - } + } else set_tflag(t, tflag_release); set_tflag(t, tflag_compound); t->info->tuple = new_tupleform(env->gwion->mp, parent); t->nspc = new_nspc(env->gwion->mp, t->name); @@ -487,9 +487,11 @@ static OP_EMIT(opem_struct_assign) { const Type t = bin->lhs->type; const Exp e = exp_self(bin); - const Instr release = emit_add_instr(emit, StructReleaseRegAddr); - release->m_val = -SZ_INT; - release->m_val2 = (m_uint)t; + if(tflag(t, tflag_release)) { + const Instr release = emit_add_instr(emit, StructReleaseRegAddr); + release->m_val = -SZ_INT; + release->m_val2 = (m_uint)t; + } const Instr instr = emit_add_instr(emit, StructAssign); instr->m_val = -t->size - SZ_INT; diff --git a/src/parse/scan1.c b/src/parse/scan1.c index 10d86881..b128801a 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -130,6 +130,8 @@ ANN static m_bool scan1_decl(const Env env, Exp_Decl *const decl) { if (env->class_def->info->tuple) tuple_contains(env, v); if (!GET_FLAG(decl->td, static)) { set_vflag(v, vflag_member); + if(tflag(t, tflag_release)) + set_tflag(env->class_def, tflag_release); if(isa(t, env->gwion->type[et_object]) > 0) set_vflag(v, vflag_release); if (tflag(env->class_def, tflag_struct)) {