From: Jérémie Astor Date: Mon, 16 Aug 2021 10:45:43 +0000 (+0200) Subject: :art: Improve array X-Git-Tag: nightly~470^2~77 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=16d7e1778882bee409e9fa7eb0b67a253b4a2426;p=gwion.git :art: Improve array --- diff --git a/src/emit/emit.c b/src/emit/emit.c index e941e38e..a26111c3 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -936,7 +936,7 @@ ANN static void set_late(const Gwion gwion, const Exp_Decl *decl, const uint array_ref = (decl->td->array && !decl->td->array->exp) || (var->array && !var->array->exp); if (!exp_getvar(exp_self(decl)) && - (GET_FLAG(array_base(v->type), abstract) || GET_FLAG(decl->td, late) || + (GET_FLAG(array_base_simple(v->type), abstract) || GET_FLAG(decl->td, late) || is_fptr(gwion, v->type) || array_ref)) { SET_FLAG(v, late); } else @@ -974,7 +974,7 @@ ANN static m_bool emit_decl(const Emitter emit, const Exp_Decl *decl) { CHECK_BB(op_emit(emit, &opi)); } set_late(emit->gwion, decl, list->self); - if (!exp_self(decl)->emit_var && GET_FLAG(array_base(v->type), abstract) && !GET_FLAG(decl->td, late) && + if (!exp_self(decl)->emit_var && GET_FLAG(array_base_simple(v->type), abstract) && !GET_FLAG(decl->td, late) && GET_FLAG(v, late) && late_array(decl->td, list->self)) { env_warn(emit->env, decl->td->pos, _("Type '%s' is abstract, use {+G}late{0} instead of {G+}%s{0}"), v->type->name, !GET_FLAG(decl->td, const) ? "var" : "const"); diff --git a/src/lib/array.c b/src/lib/array.c index 19290677..9675c969 100644 --- a/src/lib/array.c +++ b/src/lib/array.c @@ -104,15 +104,14 @@ static MFUN(vm_vector_random) { m_vector_get(array, idx, (void *)RETURN); } -#define ARRAY_OPCK(a, b, pos) \ - const Type l = array_base(a->type); \ - const Type r = array_base(b->type); \ +#define ARRAY_OPCK(a, b, pos) \ + const Type l = array_base(a->type); \ + const Type r = array_base(b->type); \ if (isa(r, l) < 0) ERR_N(pos, _("array types do not match.")); static OP_CHECK(opck_array_at) { const Exp_Binary *bin = (Exp_Binary *)data; - if (opck_const_rhs(env, data) == env->gwion->type[et_error]) - return env->gwion->type[et_error]; + CHECK_NN(opck_const_rhs(env, data)); if (bin->lhs->type != env->gwion->type[et_error]) { ARRAY_OPCK(bin->lhs, bin->rhs, exp_self(bin)->pos) if (bin->lhs->type->array_depth != bin->rhs->type->array_depth) @@ -138,9 +137,8 @@ ANN static Type check_array_shift(const Env env, const Exp a, const Exp b, b->type->array_depth > 1) return a->type;*/ ARRAY_OPCK(a, b, pos) - if (get_depth(a->type) == get_depth(b->type) + 1) - return a->type; - else if (shift_match(a->type, b->type)) + const m_int diff = get_depth(a->type) - get_depth(b->type); + if (diff >= 0 && diff <= 1) return a->type; ERR_N(pos, "array depths do not match for '%s'.", str); } @@ -953,8 +951,8 @@ INSTR(ArrayAlloc) { if (!ref) { gw_err("{-}[{0}{+}Gwion{0}{-}](VM):{0} (note: in shred[id=%" UINT_F ":%s])\n", shred->tick->xid, shred->code->name); - vm_shred_exit(shred); if (info->is_obj) free(aai.data); + handle(shred, "ArrayAllocException"); return; // TODO make exception vararg } *(void **)(ref->data + SZ_INT) = aai.data;