From: fennecdjay Date: Sat, 3 Sep 2022 10:40:05 +0000 (+0200) Subject: :art: Prepare ast2binary X-Git-Tag: nightly~264^2~2 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=ec3748035552698033595cb2755d012d4ca140bf;p=gwion.git :art: Prepare ast2binary --- diff --git a/include/env/tuple.h b/include/env/tuple.h index 9da2bfee..ea696b23 100644 --- a/include/env/tuple.h +++ b/include/env/tuple.h @@ -5,7 +5,7 @@ struct TupleForm_ { struct Vector_ contains; struct Vector_ types; struct Vector_ offset; - m_uint start; + uint64_t start; }; ANN Type tuple_type(const Env, const Vector, const loc_t); diff --git a/include/env/type.h b/include/env/type.h index 6c0b4fc4..f101936e 100644 --- a/include/env/type.h +++ b/include/env/type.h @@ -40,16 +40,15 @@ enum tflag { tflag_float = 1 << 20, tflag_union = 1 << 21, tflag_enum = 1 << 22, - tflag_error = 1 << 23, - tflag_ref = 1 << 24, + tflag_ref = 1 << 23, } __attribute__((packed)); struct Type_ { m_str name; Nspc nspc; struct TypeInfo_ *info; - size_t size; - size_t array_depth; + uint64_t size; + uint32_t array_depth; struct Vector_ effects; // pre-ctor effects uint16_t ref; uint16_t weight; diff --git a/include/env/value.h b/include/env/value.h index 44d93db2..193472ad 100644 --- a/include/env/value.h +++ b/include/env/value.h @@ -4,7 +4,7 @@ typedef struct ValueFrom_ { Nspc owner; Type owner_class; struct Context_ *ctx; - size_t offset; + uint32_t offset; m_str filename; loc_t loc; } ValueFrom; @@ -17,11 +17,9 @@ enum vflag { vflag_direct = 1 << 4, vflag_builtin = 1 << 5, vflag_member = 1 << 6, - vflag_inner = 1 << 7, // value is in a scope - vflag_release = 1 << 8, - vflag_assigned = 1 << 9, - vflag_arg = 1 << 10 - // vflag_used = 1 << 3 + vflag_release = 1 << 7, + vflag_assigned = 1 << 8, + vflag_arg = 1 << 9 } __attribute__((packed)); union value_data { diff --git a/src/clean.c b/src/clean.c index 83ce694e..65f07230 100644 --- a/src/clean.c +++ b/src/clean.c @@ -47,7 +47,7 @@ ANN static void clean_prim(Clean *a, Exp_Primary *b) { } ANN static void clean_var_decl(Clean *a, Var_Decl *b) { - if (a->scope && b->value && !tflag(b->value->type, tflag_error)) value_remref(b->value, a->gwion); + if (a->scope && b->value) value_remref(b->value, a->gwion); } ANN static void clean_exp_decl(Clean *a, Exp_Decl *b) { diff --git a/src/env/value.c b/src/env/value.c index 8d1e5e0b..ef8f4165 100644 --- a/src/env/value.c +++ b/src/env/value.c @@ -11,9 +11,6 @@ ANN void free_value(Value a, Gwion gwion) { _mp_free(gwion->mp, t->size, a->d.ptr); else if (is_class(gwion, t)) type_remref(t, gwion); - else if (vflag(a, vflag_inner)) - type_remref(t, gwion); - mp_free(gwion->mp, ValueFrom, a->from); mp_free(gwion->mp, Value, a); } diff --git a/src/parse/check.c b/src/parse/check.c index 57fb8b34..99914bf1 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -926,6 +926,7 @@ ANN Type _check_exp_call1(const Env env, Exp_Call *const exp) { */ exp->func->type = func->value_ref->type; call_add_effect(env, func, exp->func->pos); +// used in new. why??? return func->def->base->ret_type != env->gwion->type[et_auto] ? func->def->base->ret_type : exp->func->d.exp_dot.base->type; } @@ -1094,7 +1095,7 @@ ANN static Type check_exp_call(const Env env, Exp_Call *exp) { if (exp->tmpl) { DECL_BO(const m_bool, ret, = func_check(env, exp)); if (!ret) return exp_self(exp)->type; -/* const */Type t = actual_type(env->gwion, exp->func->type); + Type t = actual_type(env->gwion, exp->func->type); if(isa(exp->func->type, env->gwion->type[et_closure]) > 0) { t = typedef_base(t); t = mp_vector_at(t->info->cdef->body, Section , 0)->d.func_def->base->func->value_ref->type; @@ -1219,6 +1220,7 @@ ANN m_bool check_type_def(const Env env, const Type_Def tdef) { } if (tflag(tdef->type, tflag_cdef)) return check_class_def(env, tdef->type->info->cdef); + else inherit(tdef->type); return GW_OK; } @@ -1909,7 +1911,6 @@ ANN m_bool check_fptr_def(const Env env, const Fptr_Def fptr) { return ret; } -//#define check_fptr_def dummy_func HANDLE_SECTION_FUNC(check, m_bool, Env) ANN static m_bool check_parent(const Env env, const Class_Def cdef) { @@ -1917,10 +1918,7 @@ ANN static m_bool check_parent(const Env env, const Class_Def cdef) { const Type_Decl *td = cdef->base.ext; if (td->array && td->array->exp) CHECK_BB(check_subscripts(env, td->array, 1)); - CHECK_BB(ensure_check(env, parent)); - // if(tflag(parent, tflag_typedef)) { - // set_tflag(cdef->base.type, tflag_typedef); - // } + CHECK_BB(ensure_traverse(env, parent)); return GW_OK; } @@ -1973,7 +1971,6 @@ ANN static m_bool check_body(const Env env, Section *const section) { } ANN static bool class_def_has_body(const Env env, Ast ast) { -// do { for(m_uint i = 0; i < ast->len; i++) { const Section *section = mp_vector_at(ast, Section, i); if (section->section_type == ae_section_stmt) { @@ -1990,16 +1987,14 @@ ANN static bool class_def_has_body(const Env env, Ast ast) { if (GET_FLAG(vd.value, late)) continue; if (isa(vd.value->type, env->gwion->type[et_compound]) > 0) return true; - } else - return true; - } //while ((list = list->next)); + } else return true; + } } - } //while ((ast = ast->next)); + } return false; } ANN static inline bool type_is_recurs(const Type t, const Type tgt) { -// if(tflag(tgt, tflag_union)) return false; return isa(tgt, t) > 0 || isa(t, tgt) > 0 || (tgt->info->tuple && vector_find(&tgt->info->tuple->contains, (m_uint)t) > -1); } @@ -2013,10 +2008,8 @@ ANN static bool recursive_value(const Env env, const Type t, const Value v) { gwerr_secondary("in class", t->name, t->info->cdef->base.pos); const Type first = tgt->info->value->from->loc.first.line < t->info->value->from->loc.first.line ? -// tgt : t; v->type : t; const Type second = tgt->info->value->from->loc.first.line > t->info->value->from->loc.first.line ? -// tgt : t; v->type : t; if(first != second) { @@ -2033,7 +2026,6 @@ ANN static bool recursive_value(const Env env, const Type t, const Value v) { if(t->ref > 2) type_remref(t, env->gwion); } - set_tflag(t, tflag_error); set_tflag(t, tflag_infer); set_tflag(tgt, tflag_infer); unset_tflag(t, tflag_check); @@ -2087,14 +2079,6 @@ ANN static m_bool _check_class_def(const Env env, const Class_Def cdef) { if (cflag(cdef, cflag_struct) || class_def_has_body(env, cdef->body)) set_tflag(t, tflag_ctor); } -/* - // enforce new to be defined in every child class - if(t->info->parent->nspc && nspc_lookup_value0(t->info->parent->nspc, insert_symbol("new")) && !nspc_lookup_value0(t->nspc, insert_symbol("new"))) { - env_err(env, cdef->pos, "must define 'new' operator"); - env_warn(env, t->info->parent->info->value->from->loc, "defined here"); - return GW_ERROR; - } -*/ if (!GET_FLAG(cdef, abstract)) CHECK_BB(check_abstract(env, cdef)); if (cdef->traits) { ID_List list = cdef->traits; @@ -2137,7 +2121,7 @@ ANN static void check_extend(const Env env, Ast ast) { for(m_uint i = 0; i < ast->len; i++) { Section * section = mp_vector_at(ast, Section, i); (void)check_section(env, section); - mp_vector_add(env->gwion->mp, &env->context->extend, Section, *section); + mp_vector_add(env->gwion->mp, &env->context->tree, Section, *section); } free_mp_vector(env->gwion->mp, Section, env->context->extend); env->context->extend = NULL; diff --git a/src/parse/scan0.c b/src/parse/scan0.c index 7f99a85c..6a4a7066 100644 --- a/src/parse/scan0.c +++ b/src/parse/scan0.c @@ -154,8 +154,7 @@ ANN static m_bool typedef_complex(const Env env, const Type_Def tdef, ANN m_bool scan0_type_def(const Env env, const Type_Def tdef) { CHECK_BB(env_access(env, tdef->ext->flag, tdef->ext->pos)); - DECL_OB(const Type, base, = tdef->tmpl ? find_type(env, tdef->ext) - : known_type(env, tdef->ext)); + DECL_OB(const Type, base, = known_type(env, tdef->ext)); CHECK_BB(scan0_defined(env, tdef->xid, tdef->ext->pos)); const bool global = GET_FLAG(tdef->ext, global); // TODO: handle global in class @@ -171,14 +170,12 @@ ANN m_bool scan0_type_def(const Env env, const Type_Def tdef) { if (tdef->type != base && !tdef->distinct && !tdef->when) scan0_implicit_similar(env, base, tdef->type); if (tdef->distinct || tdef->when) { -// tdef->type->info->parent = base->info->parent; if (base->info->gack) vmcode_addref(tdef->type->info->gack = base->info->gack); set_tflag(tdef->type, tflag_distinct); struct Op_Import opi = {.lhs = base, .rhs = tdef->type}; op_cpy(env, &opi); scan0_explicit_distinct(env, base, tdef->type); - type_addref(tdef->type); // maybe because of scope_iter in nspc_free_values } else //if(tdef->ext->array) set_tflag(tdef->type, tflag_typedef); if(tflag(base, tflag_ref)) { @@ -186,8 +183,6 @@ ANN m_bool scan0_type_def(const Env env, const Type_Def tdef) { set_tflag(tdef->type, tflag_infer); } if (global) env_pop(env, 0); - if (tdef->type != base) - tdef->type->info->base_type = base; return GW_OK; } @@ -294,7 +289,7 @@ ANN static inline void cdef_flag(const Class_Def cdef, const Type t) { } ANN static Type get_parent_base(const Env env, Type_Decl *td) { - DECL_OO(const Type, t, = find_type(env, td)); + DECL_OO(const Type, t, = known_type(env, td)); Type owner = env->class_def; while (owner) { if (t == owner) @@ -305,7 +300,7 @@ ANN static Type get_parent_base(const Env env, Type_Decl *td) { } ANN static inline Type scan0_final(const Env env, Type_Decl *td) { - const Type t = find_type(env, td); + const Type t = known_type(env, td); if(!t) ERR_O(td->pos, _("can't find parent class %s\n."), s_name(td->xid)); return t; } diff --git a/src/parse/scan1.c b/src/parse/scan1.c index 54927603..232d171b 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -142,10 +142,6 @@ ANN static m_bool scan1_decl(const Env env, Exp_Decl *const decl) { } else set_vflag(v, vflag_fglobal); // file global } else if (GET_FLAG(decl->td, global)) SET_FLAG(v, global); - else if(v->type != env->gwion->type[et_auto] && v->type != env->class_def) { - type_addref(v->type); - set_vflag(v, vflag_inner); // file global - } nspc_add_value(env->curr, vd->xid, v); ((Exp_Decl *)decl)->type = decl->vd.value->type; return GW_OK; @@ -711,8 +707,7 @@ ANN m_bool scan1_func_def(const Env env, const Func_Def fdef) { HANDLE_SECTION_FUNC(scan1, m_bool, Env) ANN static Type scan1_get_parent(const Env env, const Type_Def tdef) { - const Type parent = known_type(env, tdef->ext); - CHECK_OO((tdef->type->info->parent = parent)); + const Type parent = tdef->type->info->parent; Type t = parent; do if (tdef->type == t) @@ -730,7 +725,6 @@ ANN static m_bool scan1_parent(const Env env, const Class_Def cdef) { if (isa(parent, env->gwion->type[et_object]) < 0 && !(tflag(cdef->base.type, tflag_cdef) || tflag(cdef->base.type, tflag_udef))) ERR_B(pos, _("cannot extend primitive type '%s'"), parent->name) - CHECK_BB(ensure_scan1(env, parent)); if (type_ref(parent)) ERR_B(pos, _("can't use ref type in class extend")) return GW_OK; } diff --git a/src/parse/scan2.c b/src/parse/scan2.c index ab075974..dcf04cfd 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -589,8 +589,6 @@ ANN m_bool scan2_func_def(const Env env, const Func_Def fdef) { HANDLE_SECTION_FUNC(scan2, m_bool, Env) ANN static m_bool scan2_parent(const Env env, const Class_Def cdef) { - const Type parent = cdef->base.type->info->parent; - CHECK_BB(ensure_scan2(env, parent)); if (cdef->base.ext->array && cdef->base.ext->array->exp) CHECK_BB(scan2_exp(env, cdef->base.ext->array->exp)); return GW_OK; diff --git a/tests/error/find_type.gw b/tests/error/find_type.gw index 6467ea75..b6f87553 100644 --- a/tests/error/find_type.gw +++ b/tests/error/find_type.gw @@ -1,4 +1,4 @@ -#! [contains] find parent +#! [contains] unknown type class C extends UserUGen { var D d; } diff --git a/tests/error/undef_parent.gw b/tests/error/undef_parent.gw index 37e9fe85..b4ca2ac7 100644 --- a/tests/error/undef_parent.gw +++ b/tests/error/undef_parent.gw @@ -1,4 +1,4 @@ -#! [contains] find parent +#! [contains] unknown type class C extends Undefined {} var C c; <<< c >>>;