From b59d5e7d21ea7d7d7d44a8850a93f2d5d2811cf9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Wed, 6 May 2020 15:55:45 +0200 Subject: [PATCH] :bug: Reintroduce contains --- include/env/tuple.h | 2 ++ src/env/tupleform.c | 19 ++++++++++++++++--- src/parse/scan1.c | 5 ++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/include/env/tuple.h b/include/env/tuple.h index 5cdda4f1..690afc07 100644 --- a/include/env/tuple.h +++ b/include/env/tuple.h @@ -2,12 +2,14 @@ #define __TUPLE typedef struct TupleForm_* TupleForm; struct TupleForm_ { + struct Vector_ contains; struct Vector_ types; struct Vector_ offset; m_uint start; }; ANN Type tuple_type(const Env, const Vector, const loc_t); +ANN void tuple_contains(const Env, const Value); ANN void tuple_info(const Env, const Value); ANN2(1) TupleForm new_tupleform(MemPool p, const Type parent_type); ANN void free_tupleform(const TupleForm tuple, const struct Gwion_ *gwion); diff --git a/src/env/tupleform.c b/src/env/tupleform.c index 59f77001..033365bf 100644 --- a/src/env/tupleform.c +++ b/src/env/tupleform.c @@ -17,13 +17,25 @@ ANN void tuple_info(const Env env, const Value v) { const m_uint offset = vector_back(&env->class_def->e->tuple->offset); - ADD_REF(v->type); vector_add(&env->class_def->e->tuple->types, (vtype)v->type); vector_add(&env->class_def->e->tuple->offset, offset + v->type->size); } +ANN void tuple_contains(const Env env, const Value value) { + if(!env->class_def->e->tuple) + return; + const Type t = value->type; + const Vector v = &env->class_def->e->tuple->contains; + const m_int idx = vector_size(v) ? vector_find(v, (vtype)t) : -1; + if(idx == -1) { + ADD_REF(t); + vector_add(v, (vtype)t); + } +} + ANN2(1) TupleForm new_tupleform(MemPool p, const Type parent_type) { TupleForm tuple = mp_malloc(p, TupleForm); + vector_init(&tuple->contains); vector_init(&tuple->types); vector_init(&tuple->offset); if(parent_type && parent_type->e->tuple) { @@ -45,8 +57,9 @@ ANN2(1) TupleForm new_tupleform(MemPool p, const Type parent_type) { } ANN void free_tupleform(const TupleForm tuple, const struct Gwion_ *gwion) { - for(m_uint i = 0; i < vector_size(&tuple->types); ++i) - REM_REF((Type)vector_at(&tuple->types, i), (void*)gwion); + for(m_uint i = 0; i < vector_size(&tuple->contains); ++i) + REM_REF((Type)vector_at(&tuple->contains, i), (void*)gwion); + vector_release(&tuple->contains); vector_release(&tuple->types); vector_release(&tuple->offset); } diff --git a/src/parse/scan1.c b/src/parse/scan1.c index b00d0d75..ab876aa8 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -78,7 +78,10 @@ ANN static m_bool scan1_decl(const Env env, const Exp_Decl* decl) { v->type = t; if(var->array && !var->array->exp) SET_FLAG(v, ref); - if(!env->scope->depth && !env->class_def) + if(env->class_def) { + if(env->class_def->e->tuple) + tuple_contains(env, v); + } else if(!env->scope->depth) SET_FLAG(v, global); v->d.ptr = var->addr; if(!env->scope->depth) -- 2.43.0