From ab7f1d699eaf8815fc4b58097e625731c3caa9d0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Wed, 11 Aug 2021 08:47:54 +0200 Subject: [PATCH] :art: Introduce array_base_simple --- include/env/type.h | 5 +++++ src/env/type.c | 2 +- src/lib/array.c | 4 +--- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/include/env/type.h b/include/env/type.h index 7806a0ae..288cba6e 100644 --- a/include/env/type.h +++ b/include/env/type.h @@ -64,6 +64,11 @@ ANN Type array_type(const Env, const Type, const m_uint); ANN Type find_common_anc(const Type, const Type) __attribute__((pure)); ANN Type typedef_base(Type) __attribute__((pure)); ANN Type array_base(Type) __attribute__((pure)); +ANN Symbol array_sym(const Env env, const Type src, + const m_uint depth); +ANN static inline Type array_base_simple(Type t) { + return t->array_depth ? t->info->base_type : t; +} ANN m_bool type_ref(Type) __attribute__((pure)); ANN Type actual_type(const struct Gwion_ *gwion, const Type t); ANN static inline m_uint env_push_type(const Env env, const Type type) { diff --git a/src/env/type.c b/src/env/type.c index 1c794a80..b5e9ff99 100644 --- a/src/env/type.c +++ b/src/env/type.c @@ -79,7 +79,7 @@ ANN /*static */ Symbol array_sym(const Env env, const Type src, const m_uint depth) { if (src->array_depth == depth) return insert_symbol(src->name); const m_uint total_depth = src->array_depth + depth; - const Type t = array_base(src); + const Type t = array_base_simple(src); size_t len = strlen(t->name); char name[len + 2 * total_depth + 1]; strcpy(name, t->name); diff --git a/src/lib/array.c b/src/lib/array.c index 2f2f103c..19290677 100644 --- a/src/lib/array.c +++ b/src/lib/array.c @@ -627,8 +627,6 @@ static MFUN(vm_vector_foldr) { memcpy((m_bit *)RETURN, MEM(SZ_INT * 2), acc_sz); } -ANN /*static */ Symbol array_sym(const Env env, const Type src, - const m_uint depth); #include "template.h" static OP_CHECK(opck_array_scan) { struct TemplateScan *ts = (struct TemplateScan *)data; @@ -654,7 +652,7 @@ static OP_CHECK(opck_array_scan) { env_set_error(env); return env->gwion->type[et_error]; } - const Symbol sym = array_sym(env, array_base(base), base->array_depth + 1); + const Symbol sym = array_sym(env, array_base_simple(base), base->array_depth + 1); const Type type = nspc_lookup_type1(base->info->value->from->owner, sym); if (type) return type; const Class_Def cdef = cpy_class_def(env->gwion->mp, c); -- 2.43.0