From 49c8a1b598ed648c9baf3c4cbcda10edae23607e Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Thu, 29 Apr 2021 18:34:17 +0200 Subject: [PATCH] :art: Gwi effects --- include/gwi.h | 2 ++ src/import/import_cdef.c | 5 +++++ src/import/import_fdef.c | 5 +++++ src/import/import_special.c | 7 +++++++ 4 files changed, 19 insertions(+) diff --git a/include/gwi.h b/include/gwi.h index fbac94e4..94b22772 100644 --- a/include/gwi.h +++ b/include/gwi.h @@ -6,6 +6,7 @@ struct Gwi_ { Ast body; struct ImportCK *ck; struct OperCK *oper; // _misc + struct Vector_ effects; uint tmpls; loc_t loc; }; @@ -15,5 +16,6 @@ static inline Tmpl* gwi_tmpl(const Gwi gwi) { return new_tmpl_base(gwi->gwion->mp, gwi->ck->tmpl); } +ANN void gwi_effects(const Gwi gwi, const m_str name); ANN m_bool gwi_run(const Gwion gwion, m_bool (*f)(const Gwi)); #endif diff --git a/src/import/import_cdef.c b/src/import/import_cdef.c index 9d298bb3..48586753 100644 --- a/src/import/import_cdef.c +++ b/src/import/import_cdef.c @@ -125,6 +125,11 @@ ANN m_int gwi_class_end(const Gwi gwi) { --gwi->tmpls; nspc_pop_type(gwi->gwion->mp, gwi->gwion->env->curr); } + if(gwi->effects.ptr) { + vector_init(&t->effects); + vector_copy2(&gwi->effects, &t->effects); + vector_release(&gwi->effects); + } env_pop(gwi->gwion->env, 0); return GW_OK; } diff --git a/src/import/import_fdef.c b/src/import/import_fdef.c index 2815a729..bafa8e7c 100644 --- a/src/import/import_fdef.c +++ b/src/import/import_fdef.c @@ -54,6 +54,11 @@ ANEW ANN static Func_Base* gwi_func_base(const Gwi gwi, ImportCK *ck) { ANEW ANN static Func_Def import_fdef(const Gwi gwi, ImportCK *ck) { Func_Base* base = gwi_func_base(gwi, ck); const Func_Def fdef = new_func_def(gwi->gwion->mp, base, NULL); + if(gwi->effects.ptr) { + vector_init(&fdef->base->effects); + vector_copy2(&gwi->effects, &fdef->base->effects); + vector_release(&gwi->effects); + } return fdef; } diff --git a/src/import/import_special.c b/src/import/import_special.c index f81684d8..0e8d80ca 100644 --- a/src/import/import_special.c +++ b/src/import/import_special.c @@ -55,3 +55,10 @@ ANN m_bool gwi_gack(const Gwi gwi, const Type type, const f_gack d) { ANN VM* gwi_vm(const Gwi gwi) { return gwi->gwion->vm; } + +ANN void gwi_effects(const Gwi gwi, const m_str name) { + if(!gwi->effects.ptr) + vector_init(&gwi->effects); + const Symbol sym = insert_symbol(gwi->gwion->st, name); + vector_add(&gwi->effects, (m_uint)sym); +} -- 2.43.0