From: fennecdjay Date: Thu, 22 Sep 2022 13:25:01 +0000 (+0200) Subject: :bug: Fix u8 and the like in literal arrays X-Git-Tag: nightly~234 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=988c1d9acfffc43c8aeda5ccdaa20638484ce4b7;p=gwion.git :bug: Fix u8 and the like in literal arrays --- diff --git a/src/emit/emit.c b/src/emit/emit.c index 4c661453..e6e80fb0 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -624,18 +624,37 @@ static void emit_exp_addref(const Emitter emit, /* const */ Exp exp, } while ((exp = exp->next)); } +ANN static inline m_bool emit_exp1(const Emitter emit, const Exp e) { + const Exp next = e->next; + e->next = NULL; + const m_bool ret = emit_exp(emit, e); + e->next = next; + return ret; +} + +ANN static m_bool emit_prim_array_exp(const Emitter emit, const Type t, Exp e) { + do { + CHECK_BB(emit_exp1(emit, e)); + regpop(emit, t->size - t->actual_size); + } while((e = e->next)); + return GW_OK; +} + ANN static m_bool emit_prim_array(const Emitter emit, const Array_Sub *data) { Exp e = (*data)->exp; - CHECK_BB(emit_exp(emit, e)); + const Type type = (*data)->type; + const Type base = array_base_simple(type); + if(!base->actual_size) CHECK_BB(emit_exp(emit, e)); + else CHECK_BB(emit_prim_array_exp(emit, base, e)); emit_exp_addref(emit, e, -exp_totalsize(e)); m_uint count = 0; do ++count; while ((e = e->next)); - const Type type = (*data)->type; regseti(emit, count); const Instr instr = emit_add_instr(emit, ArrayInit); instr->m_val = (m_uint)type; - instr->m_val2 = type->array_depth == 1 ? array_base_simple(type)->size : SZ_INT; + const m_uint sz = base->actual_size ?: base->size; + instr->m_val2 = type->array_depth == 1 ? sz : SZ_INT; emit_local_exp(emit, prim_exp(data)); emit_notpure(emit); return GW_OK; @@ -2442,14 +2461,6 @@ ANN static m_bool emit_stmt_exp(const Emitter emit, return exp->val ? emit_exp(emit, exp->val) : GW_OK; } -ANN static inline m_bool emit_exp1(const Emitter emit, const Exp e) { - const Exp next = e->next; - e->next = NULL; - const m_bool ret = emit_exp(emit, e); - e->next = next; - return ret; -} - ANN static m_bool emit_case_head(const Emitter emit, const Exp base, const Exp e, const Symbol op, const Vector v) { CHECK_BB(emit_exp1(emit, base));