From f636d1cf84b8e8132e0c86c2efb044e07581aa09 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Fri, 29 Mar 2024 14:48:38 +0100 Subject: [PATCH] :art: add a few functionalities to import --- include/import/checker.h | 2 +- include/import/tdef.h | 1 + src/import/import_fdef.c | 19 ++++++++++++++----- src/import/import_tdef.c | 8 ++++++++ 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/include/import/checker.h b/include/import/checker.h index dda8e370..4b2d9e56 100644 --- a/include/import/checker.h +++ b/include/import/checker.h @@ -13,7 +13,7 @@ typedef struct ImportCK { // name_checker ? }; union { Symbol xid; // union name - f_xfun addr; + Exp *when; // typedef when }; union { Variable_List list; // union diff --git a/include/import/tdef.h b/include/import/tdef.h index 816055e8..37c9dce1 100644 --- a/include/import/tdef.h +++ b/include/import/tdef.h @@ -3,6 +3,7 @@ ANN bool gwi_typedef_ini(const Gwi gwi, const restrict m_str type, const restrict m_str name); +ANN bool gwi_typedef_exp(const Gwi gwi, const restrict m_str data); ANN Type gwi_typedef_end(const Gwi gwi, const ae_flag flag); ANN void ck_clean_tdef(MemPool, ImportCK *); diff --git a/src/import/import_fdef.c b/src/import/import_fdef.c index c035158b..3af28254 100644 --- a/src/import/import_fdef.c +++ b/src/import/import_fdef.c @@ -14,6 +14,7 @@ #include "import.h" #include "gwi.h" #include "clean.h" +#include "gwion_parse.h" ANN2(1, 2, 3) static bool dl_func_init(const Gwi gwi, const restrict m_str t, @@ -69,29 +70,37 @@ ANN static bool error_fdef(const Gwi gwi, const Func_Def fdef) { return false; } -ANN bool gwi_func_valid(const Gwi gwi, ImportCK *ck) { +ANN static bool gwi_func_valid(const Gwi gwi, const f_xfun addr, ImportCK *ck) { const Func_Def fdef = import_fdef(gwi, ck); fdef->builtin = true; if (safe_tflag(gwi->gwion->env->class_def, tflag_tmpl)) { section_fdef(gwi, fdef); - fdef->d.dl_func_ptr = ck->addr; + fdef->d.dl_func_ptr = addr; return true; } if (!traverse_func_def(gwi->gwion->env, fdef)) return error_fdef(gwi, fdef); - builtin_func(gwi->gwion, fdef->base->func, ck->addr); + builtin_func(gwi->gwion, fdef->base->func, addr); return true; } ANN bool gwi_func_end(const Gwi gwi, const f_xfun addr, const ae_flag flag) { CHECK_B(ck_ok(gwi, ck_fdef)); - gwi->ck->addr = addr; gwi->ck->flag = flag; - const bool ret = gwi_func_valid(gwi, gwi->ck); + const bool ret = gwi_func_valid(gwi, addr, gwi->ck); ck_end(gwi); return ret; } +ANN bool gwi_func_code(const Gwi gwi, const char *data) { + Func_Def fdef = gwion_parse_func_def(gwi->gwion, data, gwi->loc); + if (safe_tflag(gwi->gwion->env->class_def, tflag_tmpl)) + return section_fdef(gwi, fdef); + if (!traverse_func_def(gwi->gwion->env, fdef)) + return error_fdef(gwi, fdef); + return true; +} + ANN bool gwi_func_arg(const Gwi gwi, const restrict m_str t, const restrict m_str n) { CHECK_B(ck_ok(gwi, ck_fdef)); diff --git a/src/import/import_tdef.c b/src/import/import_tdef.c index 65786d13..f6e713d0 100644 --- a/src/import/import_tdef.c +++ b/src/import/import_tdef.c @@ -10,6 +10,7 @@ #include "operator.h" #include "import.h" #include "gwi.h" +#include "gwion_parse.h" ANN bool gwi_typedef_ini(const Gwi gwi, const restrict m_str type, const restrict m_str name) { @@ -19,12 +20,18 @@ ANN bool gwi_typedef_ini(const Gwi gwi, const restrict m_str type, return !!(gwi->ck->td = gwi_str2td(gwi, type)); } +ANN bool gwi_typedef_exp(const Gwi gwi, const restrict m_str data) { + CHECK_B((gwi->ck->when = gwion_parse_expression(gwi->gwion, data, gwi->loc))); + return true; +} + ANN Type gwi_typedef_end(const Gwi gwi, const ae_flag flag) { CHECK_O(ck_ok(gwi, ck_tdef)); Type_Decl *td = gwi->ck->td; td->flag |= flag; const Type_Def tdef = new_type_def(gwi->gwion->mp, td, gwi->ck->sym, gwi->loc); + if (gwi->ck->when) tdef->when = gwi->ck->when; if (gwi->ck->tmpl) tdef->tmpl = gwi_tmpl(gwi); gwi->ck->td = NULL; gwi->ck->tmpl = NULL; @@ -44,5 +51,6 @@ ANN Type gwi_typedef_end(const Gwi gwi, const ae_flag flag) { ANN void ck_clean_tdef(MemPool mp, ImportCK *ck) { if (ck->td) free_type_decl(mp, ck->td); + if (ck->when) free_exp(mp, ck->when); if (ck->tmpl) free_id_list(mp, ck->tmpl); } -- 2.43.0