From 8792821655a9eda71ba1fcb2a95a06750f5996bb Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Tue, 12 Nov 2019 13:38:37 +0100 Subject: [PATCH] :art: gwi_register_pass --- include/import/special.h | 5 ++++- include/pass.h | 2 ++ src/import/special.c | 7 ++++++- src/lib/array.c | 2 +- src/lib/func.c | 6 +++--- src/lib/tuple.c | 2 +- src/lib/vararg.c | 2 +- tests/import/pass.c | 19 +++++++++++++++++++ tests/sh/import.sh | 2 +- 9 files changed, 38 insertions(+), 9 deletions(-) create mode 100644 tests/import/pass.c diff --git a/include/import/special.h b/include/import/special.h index 428a3f82..afb9654d 100644 --- a/include/import/special.h +++ b/include/import/special.h @@ -1,9 +1,12 @@ #ifndef __IMPORT_SPECIAL #define __IMPORT_SPECIAL +#include "pass.h" + #define FREEARG(a) ANN void a(Instr instr NUSED, void *gwion NUSED) typedef void (*f_freearg)(Instr, void*); -ANN void register_freearg(const Gwi, const f_instr, const f_freearg); +ANN void gwi_register_freearg(const Gwi, const f_instr, const f_freearg); +ANN void gwi_register_pass(const Gwi, const m_str, const compilation_pass); ANN void gwi_reserve(const Gwi, const m_str); typedef struct SpecialId_* SpecialId; ANN void gwi_specialid(const Gwi gwi, const m_str id, const SpecialId); diff --git a/include/pass.h b/include/pass.h index b8bc7e65..e4552089 100644 --- a/include/pass.h +++ b/include/pass.h @@ -1,5 +1,7 @@ #ifndef __GWIONPASS #define __GWIONPASS + +// change this to gwion ? typedef m_bool (*compilation_pass)(Env, Ast); ANN void pass_register(const Gwion, const m_str, const compilation_pass); diff --git a/src/import/special.c b/src/import/special.c index 4a7be140..87133f8b 100644 --- a/src/import/special.c +++ b/src/import/special.c @@ -16,11 +16,16 @@ #include "gwi.h" #include "parser.h" #include "specialid.h" +#include "pass.h" -ANN void register_freearg(const Gwi gwi, const f_instr _exec, const f_freearg _free) { +ANN void gwi_register_freearg(const Gwi gwi, const f_instr _exec, const f_freearg _free) { map_set(&gwi->gwion->data->freearg, (vtype)_exec, (vtype)_free); } +ANN void gwi_register_pass(const Gwi gwi, const m_str name, const compilation_pass pass) { + pass_register(gwi->gwion, name, pass); +} + ANN void gwi_reserve(const Gwi gwi, const m_str str) { vector_add(&gwi->gwion->data->reserved, (vtype)insert_symbol(gwi->gwion->st, str)); } diff --git a/src/lib/array.c b/src/lib/array.c index e352c22d..ad5a5a0e 100644 --- a/src/lib/array.c +++ b/src/lib/array.c @@ -219,7 +219,7 @@ GWION_IMPORT(array) { GWI_BB(gwi_oper_add(gwi, opck_array_cast)) GWI_BB(gwi_oper_emi(gwi, opem_basic_cast)) GWI_BB(gwi_oper_end(gwi, "$", NULL)) - register_freearg(gwi, ArrayAlloc, freearg_array); + gwi_register_freearg(gwi, ArrayAlloc, freearg_array); return GW_OK; } diff --git a/src/lib/func.c b/src/lib/func.c index 3130b193..4e104305 100644 --- a/src/lib/func.c +++ b/src/lib/func.c @@ -314,8 +314,8 @@ GWION_IMPORT(func) { GWI_BB(gwi_oper_add(gwi, opck_spork)) GWI_BB(gwi_oper_emi(gwi, opem_spork)) GWI_BB(gwi_oper_end(gwi, "fork", NULL)) - register_freearg(gwi, SporkIni, freearg_xork); - register_freearg(gwi, ForkIni, freearg_xork); - register_freearg(gwi, DotTmpl, freearg_dottmpl); + gwi_register_freearg(gwi, SporkIni, freearg_xork); + gwi_register_freearg(gwi, ForkIni, freearg_xork); + gwi_register_freearg(gwi, DotTmpl, freearg_dottmpl); return GW_OK; } diff --git a/src/lib/tuple.c b/src/lib/tuple.c index 9182190d..832474ec 100644 --- a/src/lib/tuple.c +++ b/src/lib/tuple.c @@ -366,6 +366,6 @@ SET_FLAG(t_tuple, checked | ae_flag_scan2 | ae_flag_check | ae_flag_emit); GWI_BB(gwi_oper_add(gwi, opck_at_tuple)) GWI_BB(gwi_oper_emi(gwi, opem_at_tuple)) GWI_BB(gwi_oper_end(gwi, "@=>", NULL)) - register_freearg(gwi, TupleUnpack, freearg_tuple_at); + gwi_register_freearg(gwi, TupleUnpack, freearg_tuple_at); return GW_OK; } diff --git a/src/lib/vararg.c b/src/lib/vararg.c index ba52aa5c..69621f9b 100644 --- a/src/lib/vararg.c +++ b/src/lib/vararg.c @@ -113,7 +113,7 @@ GWION_IMPORT(vararg) { GWI_BB(gwi_oper_ini(gwi, "Object", "VarObject", NULL)) GWI_BB(gwi_oper_add(gwi, at_varobj)) GWI_BB(gwi_oper_end(gwi, "@=>", VarargAssign)) - register_freearg(gwi, VarargIni, freearg_vararg); + gwi_register_freearg(gwi, VarargIni, freearg_vararg); struct SpecialId_ spid = { .type=t_vararg, .exec=RegPushImm, .is_const=1, .ck=idck_vararg}; gwi_specialid(gwi, "vararg", &spid); return GW_OK; diff --git a/tests/import/pass.c b/tests/import/pass.c new file mode 100644 index 00000000..72be7146 --- /dev/null +++ b/tests/import/pass.c @@ -0,0 +1,19 @@ +#include "gwion_util.h" +#include "gwion_ast.h" +#include "gwion_env.h" +#include "vm.h" +#include "object.h" +#include "instr.h" +#include "gwion.h" +#include "operator.h" +#include "import.h" +#include "gwi.h" + +ANN static m_bool pass(Env nv NUSED, Ast ast NUSED) { + return GW_OK; +} + +GWION_IMPORT(array_test) { + gwi_register_pass(gwi, "dummy", pass); + return GW_OK; +} diff --git a/tests/sh/import.sh b/tests/sh/import.sh index 8ee56bf2..e4b35b68 100644 --- a/tests/sh/import.sh +++ b/tests/sh/import.sh @@ -1,5 +1,5 @@ #!/bin/bash -# [test] #73 +# [test] #74 n=0 [ "$1" ] && n="$1" -- 2.43.0