From: Jérémie Astor Date: Sat, 15 May 2021 19:23:40 +0000 (+0200) Subject: :art: Introduce signatures X-Git-Tag: nightly~660 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=7722c22aba7926a539c184049d8c9617fa40a573;p=gwion.git :art: Introduce signatures --- diff --git a/ast b/ast index 13713de4..c245f1f3 160000 --- a/ast +++ b/ast @@ -1 +1 @@ -Subproject commit 13713de48c46bbbeb8d6b69518a959f6d378c00d +Subproject commit c245f1f3c808ded546f81360f21b82648f2d1720 diff --git a/fmt b/fmt index b71b85d2..7110235b 160000 --- a/fmt +++ b/fmt @@ -1 +1 @@ -Subproject commit b71b85d21cdf16981961180c2b7787f5e91bcf79 +Subproject commit 7110235b0e757145879b8b95a3ca271b3ad716e5 diff --git a/include/env/type.h b/include/env/type.h index 70e9a5fa..431dac00 100644 --- a/include/env/type.h +++ b/include/env/type.h @@ -33,7 +33,7 @@ enum tflag { tflag_tmpl = 1 << 15, tflag_typedef = 1 << 16, tflag_distinct = 1 << 17, - tflag_noret = 1 << 17, + tflag_noret = 1 << 18, } __attribute__((packed)); struct Type_ { diff --git a/src/emit/emit.c b/src/emit/emit.c index a1522d3a..90c5533f 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -2234,17 +2234,19 @@ ANN static VM_Code emit_internal(const Emitter emit, const Func f) { f->code = finalyze(emit, FuncReturn); return emit->env->class_def->info->gack = f->code; } - const VM_Code code = finalyze(emit, FuncReturn); - if(emit->info->memoize && fflag(emit->env->func, fflag_pure)) - code->is_memoize = true; - return code; + return finalyze(emit, FuncReturn); +} + +ANN static inline VM_Code _emit_func_def_code(const Emitter emit, const Func func) { + return !fbflag(func->def->base, fbflag_internal) ? + finalyze(emit, FuncReturn) : emit_internal(emit, func); } ANN static VM_Code emit_func_def_code(const Emitter emit, const Func func) { - if(fbflag(func->def->base, fbflag_internal)) - return emit_internal(emit, func); - else - return finalyze(emit, FuncReturn); + const VM_Code code = _emit_func_def_code(emit, func); + if(emit->info->memoize && fflag(func, fflag_pure)) + code->is_memoize = true; + return code; } ANN static m_bool emit_func_def_body(const Emitter emit, const Func_Def fdef) { diff --git a/src/parse/check.c b/src/parse/check.c index be09cde9..1e26a028 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -1581,7 +1581,7 @@ ANN static m_bool check_body(const Env env, Section *const section) { return ret; } -ANN static bool class_def_has_body(Ast ast) { +ANN static bool class_def_has_body(const Env env, Ast ast) { do { const Section *section = ast->section; if(section->section_type == ae_section_stmt) { @@ -1602,8 +1602,9 @@ ANN static bool class_def_has_body(Ast ast) { do { if(GET_FLAG(dlist->self->value, late)) continue; - if(tflag(dlist->self->value->type, tflag_ctor) || - dlist->self->value->type->array_depth) +if(isa(dlist->self->value->type, env->gwion->type[et_compound]) > 0) +// if(tflag(dlist->self->value->type, tflag_ctor) || +// dlist->self->value->type->array_depth) return true; } while((dlist = dlist->next)); } else @@ -1622,11 +1623,31 @@ ANN static m_bool _check_class_def(const Env env, const Class_Def cdef) { inherit(t); if(cdef->body) { CHECK_BB(env_body(env, cdef, check_body)); - if(class_def_has_body(cdef->body)) + if(class_def_has_body(env, cdef->body)) set_tflag(t, tflag_ctor); } if(!GET_FLAG(cdef, abstract)) CHECK_BB(check_abstract(env, cdef)); + Value value; + struct scope_iter iter = { t->nspc->info->value, 0, 0 }; + while(scope_iter(&iter, &value) > 0) { + if(isa(value->type, env->gwion->type[et_compound]) < 0) + continue; + if(value->type->nspc && !GET_FLAG(value, late)) { + Value v; + struct scope_iter inner = { value->type->nspc->info->value, 0, 0 }; + while(scope_iter(&inner, &v) > 0) { + if(isa(v->type, t) > 0 || isa(t, v->type) > 0) { +//exit(3); + env_err(env, v->from->loc, _("recursive type")); +env->context->error = false; + env_err(env, value->from->loc, _("recursive type")); +env->context->error = true; +return GW_ERROR; +} +} +} + } return GW_OK; } diff --git a/src/parse/type_decl.c b/src/parse/type_decl.c index 057575d7..603fec39 100644 --- a/src/parse/type_decl.c +++ b/src/parse/type_decl.c @@ -33,15 +33,33 @@ ANN static inline Type ref(const Env env, Type_Decl* td) { return t; } +ANN static inline Type find(const Env env, Type_Decl* td) { + if(!td->fptr) + return find_type(env, td); + if(!td->fptr->type) + CHECK_BO(traverse_fptr_def(env, td->fptr)); + return td->fptr->type; +} + +ANN static inline Type find1(const Env env, const Type base, Type_Decl* td) { + if(!td->fptr) + return scan_type(env, base, td); + if(!td->fptr->type) { + CHECK_BO(scan0_fptr_def(env, td->fptr)); + CHECK_BO(traverse_fptr_def(env, td->fptr)); + } + return td->fptr->type; +} + ANN static Type resolve(const Env env, Type_Decl* td) { Type_Decl *last = td; while(last->next) last = last->next; - DECL_OO(const Type, base, = find_type(env, td)); + DECL_OO(const Type, base, = find(env, td)); const Context ctx = base->info->value->from->ctx; if(ctx && ctx->error) ERR_O(td->pos, _("type '%s' is invalid"), base->name) - DECL_OO(const Type, type, = scan_type(env, base, td)); + DECL_OO(const Type, type, = find1(env, base, td)); const Type t = !td->ref ? type : ref(env, td); const Type ret = !td->option ? t : option(env, td); const Array_Sub array = last->array;