struct TupleForm_ {
struct Vector_ types;
struct Vector_ offset;
- Type_List list;
+// Type_List list;
+ m_uint start;
};
ANN Type tuple_type(const Env, const Vector, const loc_t);
ANN void tuple_info(const Env, Type_Decl*, const Var_Decl);
-ANN TupleForm new_tupleform(MemPool p);
+ANN2(1) TupleForm new_tupleform(MemPool p, const Type parent_type);
ANN void free_tupleform(MemPool p, const TupleForm tuple);
#ifdef __INSTR
#include "env/type.h"
#include "env/func.h"
#include "env/context.h"
+#include "env/tuple.h"
#endif
#include "import.h"
#include "match.h"
#include "parser.h"
-#include "tuple.h"
#include "specialid.h"
#include "vararg.h"
CHECK_BB(emit_exp(emit, exp_call->args))
emit_exp_addref(emit, exp_call->args, -exp_totalsize(exp_call->args));
}
- if(GET_FLAG(exp_call->m_func->def, variadic))
+ if(exp_call->m_func && GET_FLAG(exp_call->m_func->def, variadic))
emit_func_arg_vararg(emit, exp_call);
return GW_OK;
}
if(exp_call->m_func)
CHECK_OB(emit_exp_call1(emit, exp_call->m_func))
else {
- struct Op_Import opi = { .op=insert_symbol("@ctor"), .lhs=exp_call->func->info->type->e->d.base_type,
+ struct Op_Import opi = { .op=insert_symbol("@ctor"), .rhs=exp_call->func->info->type->e->d.base_type,
.data=(uintptr_t)exp_call, .pos=exp_self(exp_call)->pos, .op_type=op_exp };
CHECK_OB(op_emit(emit, &opi))
}
#include "object.h"
#include "gwion.h"
#include "operator.h"
-#include "tuple.h"
ANN void nspc_commit(const Nspc nspc) {
scope_commit(nspc->info->value);
#include "traverse.h"
#include "object.h"
#include "parse.h"
-#include "tuple.h"
#include "array.h"
ANN void tuple_info(const Env env, Type_Decl *base, const Var_Decl var) {
Type_Decl *td = cpy_type_decl(env->gwion->mp, base);
if(var->array)
td->array = cpy_array_sub(env->gwion->mp, var->array);
- 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->list = new_type_list(env->gwion->mp, td, NULL);
}
-ANN TupleForm new_tupleform(MemPool p) {
+ANN2(1) TupleForm new_tupleform(MemPool p, const Type parent_type) {
TupleForm tuple = mp_malloc(p, TupleForm);
vector_init(&tuple->types);
vector_init(&tuple->offset);
- vector_add(&tuple->offset, 0);
- tuple->list = NULL;
+ if(parent_type && parent_type->e->tuple) {
+ const TupleForm parent = parent_type->e->tuple;
+ const m_uint sz = vector_size(&parent->types);
+ tuple->start = parent->start + sz;
+ if(sz) {
+ const Type last = (Type)vector_back(&parent->types);
+ const m_uint offset = vector_back(&parent->offset);
+ vector_add(&tuple->offset, offset + last->size);
+ } else {
+ vector_add(&tuple->offset, 0);
+ }
+ } else {
+ vector_add(&tuple->offset, 0);
+ tuple->start = 0;
+ }
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);
}
#include "traverse.h"
#include "parse.h"
#include "gwion.h"
-#include "tuple.h"
ANN static inline m_bool freeable(const Type a) {
return !GET_FLAG(a, nonnull) &&
#include "mpool.h"
#include "specialid.h"
#include "template.h"
-#include "tuple.h"
ANN static m_bool mk_xtor(MemPool p, const Type type, const m_uint d, const ae_flag e) {
VM_Code* code = e == ae_flag_ctor ? &type->nspc->pre_ctor : &type->nspc->dtor;
t->e->def = new_class_def(gwi->gwion->mp, 0, ck.sym, td, NULL, loc(gwi));
t->e->def->base.tmpl = tmpl;
t->e->def->base.type = t;
- t->e->tuple = new_tupleform(gwi->gwion->mp);
+ t->e->tuple = new_tupleform(gwi->gwion->mp, p);
t->e->parent = p;
if(td->array)
SET_FLAG(t, typedef);
#include "gwi.h"
#include "gack.h"
-#include "tuple.h"
#undef insert_symbol
ANN void exception(const VM_Shred shred, const m_str c) {
#include "import.h"
#include "parse.h"
#include "match.h"
-#include "tuple.h"
#include "emit.h"
#include "specialid.h"
// use func flag?
if(isa(exp->func->info->type, env->gwion->type[et_class]) < 0)
ERR_O(exp->func->pos, _("function call using a non-function value"))
-// if(exp->args)
-// CHECK_OO(check_exp(env, exp->args))
- struct Op_Import opi = { .op=insert_symbol("@ctor"), .lhs=exp->func->info->type->e->d.base_type,
+ struct Op_Import opi = { .op=insert_symbol("@ctor"), .rhs=exp->func->info->type->e->d.base_type,
.data=(uintptr_t)exp, .pos=exp_self(exp)->pos, .op_type=op_exp };
const Type t = op_check(env, &opi);
exp_self(exp)->info->nspc = t ? t->e->owner : NULL;
#include "instr.h"
#include "operator.h"
#include "import.h"
-#include "tuple.h"
static inline void add_type(const Env env, const Nspc nspc, const Type t) {
nspc_add_type_front(nspc, insert_symbol(t->name), t);
SET_FLAG(t, struct);
t->e->gack = env->gwion->type[et_object]->e->gack;
}
- t->e->tuple = new_tupleform(env->gwion->mp);
+ t->e->tuple = new_tupleform(env->gwion->mp, parent);
t->e->owner = env->curr;
t->nspc = new_nspc(env->gwion->mp, t->name);
t->nspc->parent = env->curr;
if(GET_FLAG(func, member))
t->size += SZ_INT;
t->e->d.func = func;
-// t->e->tuple = NULL;
return t;
}
ANN2(1,2) static Value func_value(const Env env, const Func f,