From 6f948a0d3c069c1255bd432d7cbf8c05096f612f Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Fri, 3 Apr 2020 02:11:46 +0200 Subject: [PATCH] :art: Update tuple --- include/{ => env}/tuple.h | 5 +++-- include/gwion_env.h | 1 + src/emit/emit.c | 5 ++--- src/env/nspc.c | 1 - src/env/tupleform.c | 29 ++++++++++++++++------------- src/env/type.c | 1 - src/import/cdef.c | 3 +-- src/lib/object.c | 1 - src/parse/check.c | 5 +---- src/parse/scan0.c | 3 +-- src/parse/scan2.c | 1 - 11 files changed, 25 insertions(+), 30 deletions(-) rename include/{ => env}/tuple.h (78%) diff --git a/include/tuple.h b/include/env/tuple.h similarity index 78% rename from include/tuple.h rename to include/env/tuple.h index 22759d21..ec08289d 100644 --- a/include/tuple.h +++ b/include/env/tuple.h @@ -4,12 +4,13 @@ typedef struct TupleForm_* TupleForm; 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 diff --git a/include/gwion_env.h b/include/gwion_env.h index c6b95277..0c53207f 100644 --- a/include/gwion_env.h +++ b/include/gwion_env.h @@ -9,4 +9,5 @@ #include "env/type.h" #include "env/func.h" #include "env/context.h" +#include "env/tuple.h" #endif diff --git a/src/emit/emit.c b/src/emit/emit.c index 4e2719fd..d4d93cfb 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -16,7 +16,6 @@ #include "import.h" #include "match.h" #include "parser.h" -#include "tuple.h" #include "specialid.h" #include "vararg.h" @@ -721,7 +720,7 @@ ANN static m_bool emit_func_args(const Emitter emit, const Exp_Call* exp_call) { 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; } @@ -736,7 +735,7 @@ ANN static m_bool emit_exp_call(const Emitter emit, const Exp_Call* exp_call) { 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)) } diff --git a/src/env/nspc.c b/src/env/nspc.c index 606ad597..27743ccd 100644 --- a/src/env/nspc.c +++ b/src/env/nspc.c @@ -5,7 +5,6 @@ #include "object.h" #include "gwion.h" #include "operator.h" -#include "tuple.h" ANN void nspc_commit(const Nspc nspc) { scope_commit(nspc->info->value); diff --git a/src/env/tupleform.c b/src/env/tupleform.c index f14fec28..6f828716 100644 --- a/src/env/tupleform.c +++ b/src/env/tupleform.c @@ -13,7 +13,6 @@ #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) { @@ -24,27 +23,31 @@ 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); } diff --git a/src/env/type.c b/src/env/type.c index a1264dc1..0ed28187 100644 --- a/src/env/type.c +++ b/src/env/type.c @@ -5,7 +5,6 @@ #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) && diff --git a/src/import/cdef.c b/src/import/cdef.c index e8243b12..a751416b 100644 --- a/src/import/cdef.c +++ b/src/import/cdef.c @@ -16,7 +16,6 @@ #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; @@ -89,7 +88,7 @@ ANN2(1,2) Type gwi_class_ini(const Gwi gwi, const m_str name, const m_str parent 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); diff --git a/src/lib/object.c b/src/lib/object.c index 6d008654..a5db437c 100644 --- a/src/lib/object.c +++ b/src/lib/object.c @@ -17,7 +17,6 @@ #include "gwi.h" #include "gack.h" -#include "tuple.h" #undef insert_symbol ANN void exception(const VM_Shred shred, const m_str c) { diff --git a/src/parse/check.c b/src/parse/check.c index e0c17008..581468ca 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -11,7 +11,6 @@ #include "import.h" #include "parse.h" #include "match.h" -#include "tuple.h" #include "emit.h" #include "specialid.h" @@ -727,9 +726,7 @@ ANN Type check_exp_call1(const Env env, const Exp_Call *exp) { // 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; diff --git a/src/parse/scan0.c b/src/parse/scan0.c index 2b660dfb..fe8befdf 100644 --- a/src/parse/scan0.c +++ b/src/parse/scan0.c @@ -11,7 +11,6 @@ #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); @@ -320,7 +319,7 @@ ANN static Type scan0_class_def_init(const Env env, const Class_Def cdef) { 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; diff --git a/src/parse/scan2.c b/src/parse/scan2.c index 90a2d202..16558b78 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -330,7 +330,6 @@ ANN static Type func_type(const Env env, const Func func) { 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, -- 2.43.0