const M_Object o = *(M_Object*)(shred->reg - SZ_INT);
const Type base = o->type_ref;
const m_bit* byte = shred->code->bytecode + shred->pc * BYTECODE_SZ;
- const Type t = (Type)vector_at(&base->e->tuple_form, instr->m_val);
- const m_uint offset = vector_at(&base->e->tuple_offset, instr->m_val);
+ const Type t = (Type)vector_at(&base->e->tuple->types, instr->m_val);
+ const m_uint offset = vector_at(&base->e->tuple->offset, instr->m_val);
*(m_uint*)(byte + SZ_INT) = offset;
if(!instr->m_val2) {
if(t->size == SZ_INT)
}
static m_bool tuple_match(const Env env, const Type type[2]) {
- const Vector lv = &type[0]->e->tuple_form;
- const Vector rv = &type[1]->e->tuple_form;
+ const Vector lv = &type[0]->e->tuple->types;
+ const Vector rv = &type[1]->e->tuple->types;
for(m_uint i = 0; i < vector_size(rv); i++) {
DECL_OB(const Type, l, = (Type)vector_at(lv, i))
const Type r = (Type)vector_at(rv, i);
do {
if(e->exp_type == ae_exp_decl) {
e->d.exp_decl.td->xid->xid = insert_symbol(//could be better
- ((Type)VPTR(&bin->lhs->type->e->tuple_form, i))->name);
+ ((Type)VPTR(&bin->lhs->type->e->tuple->types, i))->name);
CHECK_BO(traverse_decl(env, &e->d.exp_decl))
}
++i;
return GW_OK;
}
const Exp e = bin->rhs->d.exp_primary.d.tuple.exp;
- const Vector v = &bin->lhs->type->e->tuple_form;
+ const Vector v = &bin->lhs->type->e->tuple->types;
struct TupleEmit te = { .e=e, .v=v };
emit_unpack_instr(emit, &te);
return GW_OK;
ANN void tuple_info(const Env env, Type_Decl *base, const Var_Decl var) {
const Value v = var->value;
- const m_uint offset = vector_back(&env->class_def->e->tuple_offset);
- vector_add(&env->class_def->e->tuple_form, (vtype)v->type);
- vector_add(&env->class_def->e->tuple_offset, offset + v->type->size);
+ const m_uint offset = vector_back(&env->class_def->e->tuple->offset);
+ vector_add(&env->class_def->e->tuple->types, (vtype)v->type);
+ vector_add(&env->class_def->e->tuple->offset, offset + v->type->size);
Type_Decl *td = cpy_type_decl(env->gwion->mp, base);
if(var->array) {
if(td->array)
else
td->array = cpy_array_sub(env->gwion->mp, var->array);
}
- if(env->class_def->e->tuple_tl) {
- Type_List tl = env->class_def->e->tuple_tl;
+ if(env->class_def->e->tuple->list) {
+ Type_List tl = env->class_def->e->tuple->list;
while(tl->next)
tl = tl->next;
tl->next = new_type_list(env->gwion->mp, td, NULL);
} else
- env->class_def->e->tuple_tl = new_type_list(env->gwion->mp, td, NULL);
+ env->class_def->e->tuple->list = new_type_list(env->gwion->mp, td, NULL);
}
INSTR(TupleCtor) {
cdef->base.tmpl = tmpl;
CHECK_BO(scan0_class_def(env, cdef))
SET_FLAG(cdef->base.type, abstract);
- cdef->base.type->e->tuple_tl = tlbase;
+ cdef->base.type->e->tuple->list = tlbase;
// CHECK_BO(scan1_cdef(env, cdef))
CHECK_BO(traverse_cdef(env, cdef))
nspc_add_type(env->curr, sym, cdef->base.type);
// map_set((Map)vector_front(&env->curr->info->type), sym, cdef->base.type);
return cdef->base.type;
}
+
+ANN TupleForm new_tupleform(MemPool p) {
+ TupleForm tuple = mp_calloc(p, TupleForm);
+ vector_init(&tuple->types);
+ vector_init(&tuple->offset);
+ vector_add(&tuple->offset, 0);
+ tuple->list = NULL;
+ return tuple;
+}
+
+ANN void free_tupleform(MemPool p, const TupleForm tuple) {
+ vector_release(&tuple->types);
+ vector_release(&tuple->offset);
+ if(tuple->list)
+ free_type_list(p, tuple->list);
+}
}
if(a->nspc)
REM_REF(a->nspc, gwion);
- if(a->e->tuple_form.ptr)
- vector_release(&a->e->tuple_form);
- if(a->e->tuple_offset.ptr)
- vector_release(&a->e->tuple_offset);
- if(a->e->tuple_tl)
- free_type_list(gwion->mp, a->e->tuple_tl);
+ if(a->e->tuple)
+ free_tupleform(gwion->mp, a->e->tuple);
if(a->e->contains.ptr) {
for(m_uint i = 0; i < vector_size(&a->e->contains); ++i)
REM_REF((Type)vector_at(&a->e->contains, i), gwion);
type->e->parent = parent;
if(type->e->parent) {
type->size = parent->size;
- vector_init(&type->e->tuple_form);
- vector_init(&type->e->tuple_offset);
- vector_add(&type->e->tuple_offset, 0);
+ type->e->tuple = new_tupleform(p);
}
type->ref = new_refcount(p, free_type);
return type;
a->array_depth = type->array_depth;
a->e->def = type->e->def;
if(t_function && isa(type, t_function) > 0) {
- vector_release(&a->e->tuple_form);
- a->e->tuple_form.ptr = NULL;
- vector_release(&a->e->tuple_offset);
- a->e->tuple_offset.ptr = NULL;
+ if(a->e->tuple) {
+ free_tupleform(p, a->e->tuple);
+ a->e->tuple = NULL;
+ }
}
return a;
}
if(e->exp_type != ae_exp_primary ||
e->d.exp_primary.primary_type != ae_primary_num)
ERR_B(exp_self(array)->pos, _("tuple subscripts must be litteral"))
- if((Type)vector_at(&type->e->tuple_form, e->d.exp_primary.d.num) == t_undefined)
+ if((Type)vector_at(&type->e->tuple->types, e->d.exp_primary.d.num) == t_undefined)
ERR_B(exp_self(array)->pos, _("tuple subscripts is undefined"))
return 0;
}
e = e->next;
// if we implement tuple with no type, err_msg
const Type type = array_base(array->base->type) ?: array->base->type;
- if(e->d.exp_primary.d.num >= vector_size(&type->e->tuple_form))
+ if(e->d.exp_primary.d.num >= vector_size(&type->e->tuple->types))
ERR_O(exp_self(array)->pos, "Invalid tuple subscript")
- return (Type)vector_at(&type->e->tuple_form, e->d.exp_primary.d.num);
+ return (Type)vector_at(&type->e->tuple->types, e->d.exp_primary.d.num);
}
return at_depth(env, array->base->type, array->array->depth);
}