From: fennecdjay Date: Sat, 29 Oct 2022 08:43:58 +0000 (+0200) Subject: :art: use tflag_compound X-Git-Tag: nightly~207^2~99 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=b31589850954046115732d6f83bbe23b86d0afd6;p=gwion.git :art: use tflag_compound --- diff --git a/include/env/type.h b/include/env/type.h index 6c528adc..c330ca80 100644 --- a/include/env/type.h +++ b/include/env/type.h @@ -42,6 +42,7 @@ enum tflag { tflag_enum = 1 << 22, tflag_ref = 1 << 23, tflag_packed = 1 << 24, + tflag_compound = 1 << 25, } __attribute__((packed)); struct Type_ { diff --git a/src/emit/emit.c b/src/emit/emit.c index 61f3619d..034c49c7 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -137,7 +137,7 @@ 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(isa(t, emit->gwion->type[et_compound]) > 0) + if(tflag(t, tflag_compound)) return emit_object_release(emit, offset); emit_struct_release(emit, t, offset); } @@ -288,7 +288,7 @@ ANN static Local * add_local(const Emitter emit, const Type t, const bool is_com } ANN m_uint emit_local(const Emitter emit, const Type t) { - const bool is_compound = isa(t, emit->gwion->type[et_compound]) > 0; + const bool is_compound = tflag(t, tflag_compound); Local *const l = add_local(emit, t, is_compound); return l->offset; } @@ -385,7 +385,7 @@ ANEW ANN static ArrayInfo *new_arrayinfo(const Emitter emit, const Type t) { ANN static inline m_bool arrayinfo_ctor(const Emitter emit, ArrayInfo *info) { const Type base = info->base; - if (isa(base, emit->gwion->type[et_compound]) > 0 && + if (tflag(base, tflag_compound) && !GET_FLAG(base, abstract)) { CHECK_BB(emit_pre_constructor_array(emit, base)); info->is_obj = 1; @@ -565,7 +565,7 @@ ANN Instr emit_struct_addref(const Emitter emit, const Type t, const m_int size, ANN2(1) static void emit_exp_addref1(const Emitter emit, const Exp exp, m_int size) { const Type t = exp->cast_to ?: exp->type; - if (isa(t, emit->gwion->type[et_compound]) > 0) + if (tflag(t, tflag_compound)) emit_compound_addref(emit, exp->type, size, exp_getvar(exp)); } @@ -2028,7 +2028,7 @@ ANN static m_bool emit_stmt_return(const Emitter emit, const Stmt_Exp stmt) { if (stmt->val->exp_type == ae_exp_call && emit->env->func == f) return optimize_tail_call(emit, &stmt->val->d.exp_call); } -// if(!stmt->val->ref && isa(stmt->val->type, emit->gwion->type[et_compound]) > 0) +// if(!stmt->val->ref && tflag(stmt->val->type, tflag_compound)) // emit_local(emit, stmt->val->type); emit->status.in_return = true; CHECK_BB(emit_exp(emit, stmt->val)); diff --git a/src/env/nspc.c b/src/env/nspc.c index 83439b7c..f34326df 100644 --- a/src/env/nspc.c +++ b/src/env/nspc.c @@ -46,7 +46,7 @@ static inline void nspc_release_struct(const Nspc a, Value value, Gwion gwion) { static inline void _free_nspc_value(const Nspc a, const Value v, Gwion gwion) { if(v->from->ctx && v->from->ctx->error) return; // this is quite a hack - if (isa(v->type, gwion->type[et_compound]) > 0 ) { + if (tflag(v->type, tflag_compound) ) { if (!tflag(v->type, tflag_struct)) nspc_release_object(a, v, gwion); else nspc_release_struct(a, v, gwion); diff --git a/src/import/import_cdef.c b/src/import/import_cdef.c index 811a2e37..df6a7ccf 100644 --- a/src/import/import_cdef.c +++ b/src/import/import_cdef.c @@ -56,6 +56,7 @@ ANN static inline void gwi_type_flag(const Type t) { } ANN static Type type_finish(const Gwi gwi, const Type t) { + tflag(t, tflag_compound); gwi_add_type(gwi, t); import_class_ini(gwi->gwion->env, t); if (t->info->cdef && t->info->cdef->base.tmpl) { diff --git a/src/lib/array.c b/src/lib/array.c index cf8d5e73..6d37b159 100644 --- a/src/lib/array.c +++ b/src/lib/array.c @@ -212,7 +212,7 @@ static OP_EMIT(opem_array_sr) { if (shift_match(bin->lhs->type, bin->rhs->type)) return emit_array_shift(emit, ArrayConcatRight); emit_regmove(emit, -SZ_INT); - if (isa(bin->lhs->type, emit->gwion->type[et_compound]) > 0) + if (tflag(bin->lhs->type, tflag_compound)) emit_compound_addref(emit, bin->lhs->type, -SZ_INT*2, false); (void)emit_add_instr(emit, ArrayAppendFront); return GW_OK; @@ -222,7 +222,7 @@ static OP_EMIT(opem_array_sl) { const Exp_Binary *bin = (Exp_Binary *)data; if (shift_match(bin->rhs->type, bin->lhs->type)) return emit_array_shift(emit, ArrayConcatLeft); - if (isa(bin->rhs->type, emit->gwion->type[et_compound]) > 0) + if (tflag(bin->rhs->type, tflag_compound)) emit_compound_addref(emit, bin->rhs->type, -SZ_INT, false); emit_regmove(emit, -bin->rhs->type->size); emit_add_instr(emit, ArrayAppend); @@ -756,12 +756,12 @@ static OP_CHECK(opck_array_scan) { t->array_depth = base->array_depth + 1; t->info->base_type = array_base(base); set_tflag(t, tflag_cdef | tflag_tmpl); - void *rem = isa(base, env->gwion->type[et_compound]) > 0 + void *rem = tflag(base, tflag_compound) ? !tflag(base, tflag_struct) ? vm_vector_rem_obj : vm_vector_rem_struct : vm_vector_rem; builtin_func(env->gwion, (Func)vector_at(&t->nspc->vtable, 0), rem); - void *insert = isa(base, env->gwion->type[et_compound]) > 0 + void *insert = tflag(base, tflag_compound) ? !tflag(base, tflag_struct) ? vm_vector_insert_obj : vm_vector_insert_struct : vm_vector_insert; @@ -779,7 +779,7 @@ static OP_CHECK(opck_array_scan) { array_func(env, t, "foldr", vm_vector_foldr); // array_func(env, t, "new", vm_vector_new); - if (isa(base, env->gwion->type[et_compound]) > 0) { + if (tflag(base, tflag_compound)) { t->nspc->dtor = new_vmcode(env->gwion->mp, NULL, NULL, "array component dtor", SZ_INT, true, false); set_tflag(t, tflag_dtor); diff --git a/src/lib/closure.c b/src/lib/closure.c index 312e371d..0dd6a6ff 100644 --- a/src/lib/closure.c +++ b/src/lib/closure.c @@ -88,7 +88,7 @@ ANN void free_captures(const VM_Shred shred, m_bit *const caps) { const Capture_List captures = (*(Func_Def*)caps)->captures; for(m_uint i = 0; i < captures->len; i++) { Capture *const cap = mp_vector_at(captures, Capture, i); - if(isa(cap->temp->type, shred->info->vm->gwion->type[et_compound]) > 0) + if(tflag(cap->temp->type, tflag_compound)) compound_release(shred, cap->temp->type, caps + SZ_INT + sz); sz += cap->temp->type->size; } @@ -131,7 +131,7 @@ ANN static m_bool emit_fptr_assign(const Emitter emit, const Type lhs, const Typ e->type = cap->orig->type; exp_setvar(e, cap->is_ref); emit_exp(emit, e); - if(!cap->is_ref && isa(cap->temp->type, emit->gwion->type[et_compound]) > 0) + if(!cap->is_ref && tflag(cap->temp->type, tflag_compound)) emit_compound_addref(emit, cap->temp->type, cap->temp->type->size, 0); offset += cap->temp->type->size; } diff --git a/src/lib/dict.c b/src/lib/dict.c index fd332ca1..c662853e 100644 --- a/src/lib/dict.c +++ b/src/lib/dict.c @@ -88,8 +88,8 @@ ANN static void hmapinfo_init(HMapInfo *const info, const Type types[], const Ty info->key = key; info->val = val; info->sz = key->size + val->size; - info->keyk = isa(key, types[et_compound]) > 0 + tflag(key, tflag_struct); - info->valk = isa(val, types[et_compound]) > 0 + tflag(val, tflag_struct); + info->keyk = tflag(key, tflag_compound) + tflag(key, tflag_struct); + info->valk = tflag(val, tflag_compound) + tflag(val, tflag_struct); } static DTOR(dict_clear_dtor) { diff --git a/src/lib/object.c b/src/lib/object.c index 924c7c98..ade66475 100644 --- a/src/lib/object.c +++ b/src/lib/object.c @@ -70,7 +70,7 @@ ANN void struct_release(const VM_Shred shred, const Type base, 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; + if (!tflag(t, tflag_compound)) continue; const m_uint offset = vector_at(offsets, i); compound_release(shred, t, ptr + offset); } diff --git a/src/lib/union.c b/src/lib/union.c index 16cc754e..31a1f30f 100644 --- a/src/lib/union.c +++ b/src/lib/union.c @@ -57,7 +57,7 @@ static DTOR(UnionDtor) { if (idx) { const Map map = &o->type_ref->nspc->info->value->map; const Value v = (Value)map_at(map, idx - 1); - if (isa(v->type, shred->info->vm->gwion->type[et_compound]) > 0) + if (tflag(v->type, tflag_compound)) compound_release(shred, v->type, (o->data + SZ_INT)); } } diff --git a/src/parse/check.c b/src/parse/check.c index 7e576f07..91cd41fa 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -2014,7 +2014,7 @@ ANN static bool class_def_has_body(const Env env, Ast ast) { if (GET_FLAG(exp->d.exp_decl.td, late)) continue; Var_Decl vd = exp->d.exp_decl.vd; if (GET_FLAG(vd.value, late)) continue; - if (isa(vd.value->type, env->gwion->type[et_compound]) > 0) + if (tflag(vd.value->type, tflag_compound)) return true; } else return true; } @@ -2063,7 +2063,7 @@ ANN static bool recursive_value(const Env env, const Type t, const Value v) { } if(t != tgt && v->type->nspc && (!GET_FLAG(v, late) || vflag(v, vflag_assigned)) && strncmp(tgt->name, "Option:[", 8) && - isa(tgt, env->gwion->type[et_compound]) > 0) + tflag(tgt, tflag_compound)) return recursive_type(env, t, tgt); return false; @@ -2086,7 +2086,7 @@ ANN static m_bool recursive_type_base(const Env env, const Type t) { bool error = false; struct scope_iter iter = {t->nspc->info->value, 0, 0}; while (scope_iter(&iter, &value) > 0) { - if (isa(value->type, env->gwion->type[et_compound]) < 0) continue; + if (!tflag(value->type, tflag_compound)) continue; if (value->type->nspc && (!GET_FLAG(value, late) || vflag(value, vflag_assigned))) { if(value->type == t || recursive_type(env, t, value->type)) { env_err(env, value->from->loc, _("recursive type")); diff --git a/src/parse/scan0.c b/src/parse/scan0.c index 95a4ed9f..6161f172 100644 --- a/src/parse/scan0.c +++ b/src/parse/scan0.c @@ -346,6 +346,7 @@ ANN static Type scan0_class_def_init(const Env env, const Class_Def cdef) { t->size = 0; set_tflag(t, tflag_struct); } + set_tflag(t, tflag_compound); t->info->tuple = new_tupleform(env->gwion->mp, parent); t->nspc = new_nspc(env->gwion->mp, t->name); t->nspc->parent = env->curr;