From a22dbc87a3d34282799744c9d84c602c7a75f9ac Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Thu, 12 Aug 2021 13:35:00 +0200 Subject: [PATCH] :art: More on array classes --- src/emit/emit.c | 2 +- src/parse/check.c | 4 ++-- src/parse/operator.c | 9 ++++++--- src/parse/scan1.c | 5 +++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/emit/emit.c b/src/emit/emit.c index dbc95e48..7021c684 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -588,7 +588,7 @@ ANN static m_bool emit_prim_array(const Emitter emit, const Array_Sub *data) { regseti(emit, count); const Instr instr = emit_add_instr(emit, ArrayInit); instr->m_val = (m_uint)type; - instr->m_val2 = array_base(type)->size; + instr->m_val2 = array_base_simple(type)->size; emit_gc(emit, -SZ_INT); emit_notpure(emit); return GW_OK; diff --git a/src/parse/check.c b/src/parse/check.c index c2e3e5d3..ce7cf859 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -198,7 +198,7 @@ ANN static inline Type prim_array_match(const Env env, Exp e) { do if (prim_array_inner(env, type, e, loc) < 0) err = true; while ((e = e->next)); - if (!err) return array_type(env, array_base(type), type->array_depth + 1); + if (!err) return array_type(env, array_base_simple(type), type->array_depth + 1); env_set_error(env); return NULL; } @@ -1152,7 +1152,7 @@ ANN static inline Type foreach_type(const Env env, const Exp exp) { " This is not allowed in foreach loop"), et->name) DECL_OO(Type, base, = typedef_base(et)); - DECL_OO(const Type, t, = array_base(base)); + DECL_OO(const Type, t, = array_base_simple(base)); const m_uint depth = base->array_depth - 1; return depth ? array_type(env, t, depth) : t; } diff --git a/src/parse/operator.c b/src/parse/operator.c index 525b1f40..8186a23a 100644 --- a/src/parse/operator.c +++ b/src/parse/operator.c @@ -159,9 +159,12 @@ ANN m_bool add_op(const Gwion gwion, const struct Op_Import *opi) { ANN static inline Type op_parent(const Env env, const Type t) { const size_t depth = t->array_depth; - return !depth || !array_base(t)->info->parent - ? t->info->parent - : array_type(env, array_base(t)->info->parent, depth); + if (!depth) + return t->info->parent; + const Type base = array_base_simple(t); + return !base->info->parent + ? t->info->parent + : array_type(env, base->info->parent, depth); } ANN static Type op_check_inner(const Env env, struct OpChecker *ock, diff --git a/src/parse/scan1.c b/src/parse/scan1.c index 0a22703d..32a2bc4d 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -109,11 +109,12 @@ ANN static m_bool scan1_decl(const Env env, const Exp_Decl *decl) { if (var->array->exp) CHECK_BB(scan1_exp(env, var->array->exp)); CHECK_OB((t = array_type(env, decl->type, var->array->depth))); } - if (GET_FLAG(array_base(t), abstract) && + const Type base = array_base_simple(t); + if (GET_FLAG(base, abstract) && ((var->array && var->array->exp) || (decl->td->array && decl->td->array->exp))) ERR_B(var->pos, _("arrays of abstract type '%s' must be declared empty"), - array_base(t)->name); + base->name); const Value v = var->value = var->value ?: new_value(env->gwion->mp, t, s_name(var->xid)); nspc_add_value(env->curr, var->xid, v); -- 2.43.0