From: fennecdjay Date: Thu, 8 Dec 2022 21:59:10 +0000 (+0100) Subject: :art: some clean X-Git-Tag: nightly~207^2~51 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=133789d535b8f96cfd4873fe221d9a14a2f6c86d;p=gwion.git :art: some clean --- diff --git a/include/env/type.h b/include/env/type.h index c330ca80..d6cb26f9 100644 --- a/include/env/type.h +++ b/include/env/type.h @@ -39,10 +39,9 @@ enum tflag { tflag_contract = 1 << 19, tflag_float = 1 << 20, tflag_union = 1 << 21, - tflag_enum = 1 << 22, - tflag_ref = 1 << 23, - tflag_packed = 1 << 24, - tflag_compound = 1 << 25, + tflag_ref = 1 << 22, + tflag_packed = 1 << 23, + tflag_compound = 1 << 24, } __attribute__((packed)); struct Type_ { @@ -134,6 +133,7 @@ typedef enum { et_char, et_float, et_error, + et_enum, et_compound, et_object, et_shred, diff --git a/include/lang_private.h b/include/lang_private.h index cf949958..9973412c 100644 --- a/include/lang_private.h +++ b/include/lang_private.h @@ -2,6 +2,7 @@ #define __LANG_PRIVATE ANN m_bool import_class(const Gwi gwi); ANN m_bool import_prim(const Gwi gwi); +ANN m_bool import_enum(const Gwi gwi); ANN m_bool import_object(const Gwi gwi); ANN m_bool import_func(const Gwi gwi); ANN m_bool import_string(const Gwi gwi); diff --git a/src/lib/engine.c b/src/lib/engine.c index 13b23894..5cfe0f21 100644 --- a/src/lib/engine.c +++ b/src/lib/engine.c @@ -104,6 +104,9 @@ ANN static m_bool import_core_libs(const Gwi gwi) { gwi_specialid(gwi, "@predicate", &predicate); gwidoc(gwi, "internal base of all objects and structures."); + + GWI_BB(import_enum(gwi)); + const Type t_compound = gwi_mk_type(gwi, "@Compound", SZ_INT, NULL); GWI_BB(gwi_gack(gwi, t_compound, gack_compound)) GWI_BB(gwi_set_global_type(gwi, t_compound, et_compound)) diff --git a/src/lib/lib_class.c b/src/lib/lib_class.c index b4af11eb..6aa7df5a 100644 --- a/src/lib/lib_class.c +++ b/src/lib/lib_class.c @@ -48,7 +48,6 @@ static OP_EMIT(opem_implicit_class) { static OP_CHECK(opck_implicit_class) { struct Implicit *imp = (struct Implicit*)data; const Type t = actual_type(env->gwion, imp->e->type); - if(tflag(t, tflag_enum)) return env->gwion->type[et_int]; return env->gwion->type[et_error]; } diff --git a/src/parse/scan0.c b/src/parse/scan0.c index 6c71530e..a32d1ee1 100644 --- a/src/parse/scan0.c +++ b/src/parse/scan0.c @@ -17,14 +17,6 @@ static inline void add_type(const Env env, const Nspc nspc, const Type t) { nspc_add_type_front(nspc, insert_symbol(t->name), t); } -static inline void context_global(const Env env) { - if (env->context) env->context->global = true; -} - -static inline Type scan0_type(const Env env, const m_str name, const Type t) { - return new_type(env->gwion->mp, name, t); -} - ANN static inline m_bool scan0_defined(const Env env, const Symbol s, const loc_t pos) { if (nspc_lookup_type1(env->curr, s)) @@ -35,20 +27,15 @@ ANN static inline m_bool scan0_defined(const Env env, const Symbol s, ANN static Arg_List fptr_arg_list(const Env env, const Fptr_Def fptr) { if(env->class_def && !GET_FLAG(fptr->base, static)) { Arg arg = { .td = type2td(env->gwion, env->class_def, fptr->base->td->pos) }; - if(fptr->base->args) { - Arg_List args = new_mp_vector(env->gwion->mp, Arg, fptr->base->args->len + 1); - mp_vector_set(args, Arg, 0, arg); - for(uint32_t i = 0; i < fptr->base->args->len; i++) { - Arg *base = mp_vector_at(fptr->base->args, Arg, i); - Arg arg = { .td = cpy_type_decl(env->gwion->mp, base->td) }; - mp_vector_set(args, Arg, i+1, arg); - } - return args; - } else { - Arg_List args = new_mp_vector(env->gwion->mp, Arg, 1); - mp_vector_set(args, Arg, 0, arg); - return args; + const uint32_t len = mp_vector_len(fptr->base->args); + Arg_List args = new_mp_vector(env->gwion->mp, Arg, len + 1); + mp_vector_set(args, Arg, 0, arg); + for(uint32_t i = 0; i < len; i++) { + Arg *base = mp_vector_at(fptr->base->args, Arg, i); + Arg arg = { .td = cpy_type_decl(env->gwion->mp, base->td) }; + mp_vector_set(args, Arg, i+1, arg); } + return args; } else if(fptr->base->args) return cpy_arg_list(env->gwion->mp, fptr->base->args); return NULL; @@ -61,7 +48,7 @@ ANN static inline m_bool scan0_global(const Env env, const ae_flag flag, if (!global) return global; if (!env->class_def) { env_push_global(env); - context_global(env); + if (env->context) env->context->global = true; return GW_OK; } ERR_B(loc, _("can't declare as global in class def")) @@ -139,7 +126,7 @@ ANN static void scan0_explicit_distinct(const Env env, const Type lhs, ANN static void typedef_simple(const Env env, const Type_Def tdef, const Type base) { - const Type t = scan0_type(env, s_name(tdef->xid), base); + const Type t = new_type(env->gwion->mp, s_name(tdef->xid), base); t->size = base->size; const Nspc nspc = (!env->class_def && GET_FLAG(tdef->ext, global)) ? env->global_nspc @@ -202,27 +189,12 @@ ANN m_bool scan0_type_def(const Env env, const Type_Def tdef) { return GW_OK; } -#include "gack.h" -static GACK(gack_enum) { - const Map m = &t->nspc->info->value->map; - const m_uint value = *(m_uint*)VALUE; - if(value < map_size(m)) { - const Value v = (Value)map_at(&t->nspc->info->value->map, *(m_uint*)VALUE); - INTERP_PRINTF("%s", v->name); - } else - INTERP_PRINTF("%s", t->name); -} - ANN static Type enum_type(const Env env, const Enum_Def edef) { - const Type t = type_copy(env->gwion->mp, env->gwion->type[et_int]); + const Type t = type_copy(env->gwion->mp, env->gwion->type[et_enum]); t->name = s_name(edef->xid); - t->info->parent = env->gwion->type[et_int]; + t->info->parent = env->gwion->type[et_enum]; add_type(env, env->curr, t); mk_class(env, t, edef->pos); - set_tflag(t, tflag_enum); - CHECK_BO(mk_gack(env->gwion->mp, t, gack_enum)); -// scan0_implicit_similar(env, t, env->gwion->type[et_int]); -// scan0_implicit_similar(env, env->gwion->type[et_int], t); return t; } @@ -334,7 +306,7 @@ ANN static Type scan0_class_def_init(const Env env, const Class_Def cdef) { return NULL; } if (cdef->traits) CHECK_BO(find_traits(env, cdef->traits, cdef->pos)); - const Type t = scan0_type(env, s_name(cdef->base.xid), parent); + const Type t = new_type(env->gwion->mp, s_name(cdef->base.xid), parent); if (cflag(cdef, cflag_struct)) { t->size = 0; set_tflag(t, tflag_struct); diff --git a/src/parse/scan2.c b/src/parse/scan2.c index 00bb17d1..56f2dc4f 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -51,8 +51,7 @@ ANN static m_bool scan2_args(const Func_Def f) { Arg *arg = mp_vector_at(args, Arg, i); const Value v = arg->var_decl.value; v->from->offset = f->stack_depth; - // when can there be no type? - f->stack_depth += v->type ? v->type->size : SZ_INT; + f->stack_depth += v->type->size; set_vflag(v, vflag_arg); } return GW_OK; @@ -68,8 +67,7 @@ ANN static Value scan2_func_assign(const Env env, const Func_Def d, } else { if (GET_FLAG(d->base, static)) SET_FLAG(v, static); - else - set_vflag(v, vflag_member); + else set_vflag(v, vflag_member); SET_ACCESS(d->base, v) } d->base->func = v->d.func_ref = f; @@ -104,11 +102,6 @@ ANN static m_bool scan2_range(const Env env, Range *range) { ANN static inline m_bool scan2_prim(const Env env, const Exp_Primary *prim) { if (prim->prim_type == ae_prim_hack || prim->prim_type == ae_prim_dict || prim->prim_type == ae_prim_interp) CHECK_BB(scan2_exp(env, prim->d.exp)); - /* else if(prim->prim_type == ae_prim_id) { - const Value v = prim_value(env, prim->d.var); - if(v) - v->vflag |= used; - } */ else if (prim->prim_type == ae_prim_array && prim->d.array->exp) return scan2_exp(env, prim->d.array->exp); else if (prim->prim_type == ae_prim_range) @@ -452,7 +445,7 @@ ANN static m_str func_tmpl_name(const Env env, const Func_Def f) { vector_add(&v, (vtype)t); tlen += strlen(t->name); // this can be improved to use fully qualified name ++tlen; - } //while ((id = id->next) && ++tlen); + } if(spread && f->base->tmpl->call) { Type_List tl = f->base->tmpl->call;