From: Jérémie Astor Date: Fri, 29 Apr 2022 22:58:12 +0000 (+0200) Subject: :art: proper signature handling X-Git-Tag: nightly~275^2~13 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=57cae1ff067cfdd8a69a703e4e0373a08d036252;p=gwion.git :art: proper signature handling --- diff --git a/src/parse/type_decl.c b/src/parse/type_decl.c index 33b74385..4ff838a8 100644 --- a/src/parse/type_decl.c +++ b/src/parse/type_decl.c @@ -4,6 +4,10 @@ #include "vm.h" #include "traverse.h" #include "parse.h" +#include "object.h" +#include "operator.h" +#include "instr.h" +#include "import.h" ANN static Type _option(const Env env, Type_Decl *td, const uint8_t n) { Type_List tl = new_mp_vector(env->gwion->mp, sizeof(Type_Decl*), 1); @@ -39,10 +43,50 @@ ANN static inline Type ref(const Env env, Type_Decl *td) { return t; } +ANN static Symbol symname(const Env env, Func_Base *const base, bool *global) { + GwText text = { .mp = env->gwion->mp }; + text_add(&text, "("); + const Type t = known_type(env, base->td); + const m_str name = type2str(env->gwion, t, base->td->pos); + text_add(&text, name); + free_mstr(env->gwion->mp, name); + text_add(&text, "("); + *global = type_global(env, t); + if(base->args) { + for(uint32_t i = 0; i < base->args->len; i++) { + if(i) text_add(&text, ","); + Arg *arg = mp_vector_at(base->args, Arg, i); + const Type t = known_type(env, arg->td); + const m_str name = type2str(env->gwion, t, arg->td->pos); + text_add(&text, name); + free_mstr(env->gwion->mp, name); + if(*global) + *global = type_global(env, t); + } + } + text_add(&text, ")"); + text_add(&text, ")"); + base->xid = insert_symbol(text.str); + text_release(&text); + return base->xid; +} + 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; + bool global; + td->xid = symname(env, td->fptr->base, &global); + const Fptr_Def fptr = td->fptr; + td->fptr = NULL; + const Type exists = find_type(env, td); + if(exists) return exists; + const m_uint scope = !global + ? env_push_global(env) + : env_push(env, NULL, env->context->nspc); + const m_bool ret = traverse_fptr_def(env, fptr); + env_pop(env, scope); + const Type t = fptr->type; + free_fptr_def(env->gwion->mp, fptr); + return ret > 0 ? t : NULL; } ANN static inline Type find1(const Env env, const Type base, Type_Decl *td) {