#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);
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) {
}
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);
}
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)