From 42a72e214776a4482f2ceaa789be0522bed96f19 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Sun, 17 Nov 2019 20:24:41 +0100 Subject: [PATCH] :art: Update passes --- Makefile | 8 ++++++-- ast | 2 +- include/gwion.h | 2 +- include/gwiondata.h | 6 +++--- include/pass.h | 6 ++++++ include/plug.h | 10 +++++----- src/arg.c | 1 + src/compile.c | 7 ++++--- src/gwion.c | 17 ++++++++++------- src/gwiondata.c | 19 +++++++++++-------- src/main.c | 2 +- src/pass.c | 19 ++++++++++++++++--- src/plug.c | 18 +++++++++--------- 13 files changed, 74 insertions(+), 43 deletions(-) diff --git a/Makefile b/Makefile index 41cf32fa..8f01df88 100644 --- a/Makefile +++ b/Makefile @@ -50,7 +50,8 @@ endif CFLAGS += -DGWION_BUILTIN -GWLIBS = libgwion.a ast/libgwion_ast.a util/libgwion_util.a +#GWLIBS = libgwion.a ast/libgwion_ast.a ast/libgwion_grammar.a util/libgwion_util.a +GWLIBS = libgwion.a ast/libgwion_grammar.a ast/libgwion_ast.a util/libgwion_util.a _LDFLAGS = ${GWLIBS} ${LDFLAGS} all: options-show util/libgwion_util.a ast/libgwion_ast.a libgwion.a src/main.o @@ -70,7 +71,10 @@ util: util/libgwion_util.a @(info build util) ast/libgwion_ast.a: - @make -C ast + @make -C ast libgwion_ast.a + +ast/libgwion_grammar.a: + @make -C ast libgwion_grammar.a ast: ast/libgwion_ast.a @(info build ast) diff --git a/ast b/ast index 353d33a3..252ebf19 160000 --- a/ast +++ b/ast @@ -1 +1 @@ -Subproject commit 353d33a37749f7509d43f477283a84cf350f462d +Subproject commit 252ebf19ecd24721e06a99b620cf20c55588a240 diff --git a/include/gwion.h b/include/gwion.h index f7393e36..d35b4498 100644 --- a/include/gwion.h +++ b/include/gwion.h @@ -8,13 +8,13 @@ typedef struct Gwion_* Gwion; struct Arg_; struct Gwion_ { - PlugInfo* plug; Env env; Emitter emit; VM* vm; struct GwionData_ *data; SymTable *st; MemPool mp; + struct PPArg_ *ppa; Type *type; }; diff --git a/include/gwiondata.h b/include/gwiondata.h index fdae6fa5..155879cf 100644 --- a/include/gwiondata.h +++ b/include/gwiondata.h @@ -7,10 +7,10 @@ typedef struct GwionData_ { struct Vector_ child; struct Vector_ child2; struct Vector_ reserved; - struct Map_ pass_map; - struct Vector_ pass; + struct Passes_ *passes; + PlugInfo* plug; } GwionData; ANN GwionData* new_gwiondata(MemPool); -ANN void free_gwiondata(MemPool, GwionData*); +ANN void free_gwiondata(const struct Gwion_*); #endif diff --git a/include/pass.h b/include/pass.h index e4552089..ef72d5e0 100644 --- a/include/pass.h +++ b/include/pass.h @@ -1,9 +1,15 @@ #ifndef __GWIONPASS #define __GWIONPASS +struct Passes_ { + struct Map_ map; + struct Vector_ vec; +}; // change this to gwion ? typedef m_bool (*compilation_pass)(Env, Ast); +ANEW ANN struct Passes_* new_passes(MemPool mp); +ANN void free_passes(struct Passes_*); ANN void pass_register(const Gwion, const m_str, const compilation_pass); ANN void pass_default(const Gwion); ANN m_bool pass_set(const Gwion, const Vector); diff --git a/include/plug.h b/include/plug.h index 06c922b1..54185abc 100644 --- a/include/plug.h +++ b/include/plug.h @@ -14,17 +14,17 @@ typedef struct PlugInfo_ { } PlugInfo; ANN PlugInfo* new_plug(MemPool, Vector); -ANN void plug_run(const Gwion gwion, const Vector); -ANN void free_plug(const Gwion gwion); -ANN void* get_module(const Gwion, const m_str); +ANN void plug_run(const struct Gwion_*, const Vector); +ANN void free_plug(const struct Gwion_*); +ANN void* get_module(const struct Gwion_*, const m_str); #define GWIMPORT_NAME import #define GWMODSTR_NAME gwmodstr #define GWMODINI_NAME gwmodini #define GWMODEND_NAME gwmodend #define GWDRIVER_NAME gwmodend #define GWMODSTR(a) m_str GWMODSTR_NAME() { return #a; } -#define GWMODINI(a) ANN2(1) void* GWMODINI_NAME(const Gwion gwion NUSED, const Vector args NUSED) -#define GWMODEND(a) ANN void GWMODEND_NAME(const Gwion gwion NUSED, void* self NUSED) +#define GWMODINI(a) ANN2(1) void* GWMODINI_NAME(const struct Gwion_ *gwion NUSED, const Vector args NUSED) +#define GWMODEND(a) ANN void GWMODEND_NAME(const struct Gwion_ *gwion NUSED, void* self NUSED) #define GWDRIVER(a) ANN void GWDRIVER_NAME(DriverData* d) ANN Vector split_args(MemPool, const m_str str); diff --git a/src/arg.c b/src/arg.c index d22587e6..36fa1db3 100644 --- a/src/arg.c +++ b/src/arg.c @@ -80,6 +80,7 @@ ANN static inline m_str _get_arg(Arg* arg, int *i) { gw_err(_("option '-%c' needs arguments\n"), key); return str; } + ANN m_bool _arg_parse(const Gwion gwion, Arg* arg) { for(int i = 1; i < arg->argc; ++i) { if(arg->argv[i][0] == '-') { diff --git a/src/compile.c b/src/compile.c index c1947b90..4f621c9d 100644 --- a/src/compile.c +++ b/src/compile.c @@ -80,11 +80,12 @@ static inline m_bool compiler_open(MemPool p, struct Compiler* c) { } static inline m_bool _check(struct Gwion_* gwion, struct Compiler* c) { - struct ScannerArg_ arg = { c->name, c->file, gwion->st }; + struct ScannerArg_ arg = { c->name, c->file, gwion->st, .ppa=gwion->ppa }; +// struct ScannerArg_ arg = { c->name, c->file, gwion->st, .ppa={} }; CHECK_OB((c->ast = parse(&arg))) gwion->env->name = c->name; - for(m_uint i = 0; i < vector_size(&gwion->data->pass); ++i) { - const compilation_pass pass = (compilation_pass)vector_at(&gwion->data->pass, i); + for(m_uint i = 0; i < vector_size(&gwion->data->passes->vec); ++i) { + const compilation_pass pass = (compilation_pass)vector_at(&gwion->data->passes->vec, i); CHECK_BB(pass(gwion->env, c->ast)) } return GW_OK; diff --git a/src/gwion.c b/src/gwion.c index 7f64b80c..31a3cdbe 100644 --- a/src/gwion.c +++ b/src/gwion.c @@ -16,11 +16,11 @@ ANN m_bool gwion_audio(const Gwion gwion) { Driver* di = gwion->vm->bbq; if(di->si->arg) { - for(m_uint i = 0; i < map_size(&gwion->plug->drv); ++i) { - const m_str name = (m_str)VKEY(&gwion->plug->drv, i); + for(m_uint i = 0; i < map_size(&gwion->data->plug->drv); ++i) { + const m_str name = (m_str)VKEY(&gwion->data->plug->drv, i); const size_t len = strlen(name); if(!strncmp(name, di->si->arg, len)) { - di->func = (f_bbqset)VVAL(&gwion->plug->drv, i); + di->func = (f_bbqset)VVAL(&gwion->data->plug->drv, i); break; } } @@ -32,7 +32,7 @@ ANN m_bool gwion_audio(const Gwion gwion) { } ANN static inline m_bool gwion_engine(const Gwion gwion) { - return type_engine_init(gwion->vm, &gwion->plug->vec[GWPLUG_IMPORT]) > 0; + return type_engine_init(gwion->vm, &gwion->data->plug->vec[GWPLUG_IMPORT]) > 0; } ANN static inline void gwion_compile(const Gwion gwion, const Vector v) { @@ -59,6 +59,8 @@ ANN m_bool gwion_ini(const Gwion gwion, Arg* arg) { gwion->mp = mempool_ini((sizeof(struct VM_Shred_) + SIZEOF_REG + SIZEOF_MEM)); gwion->st = new_symbol_table(gwion->mp, 65347); gwion->vm = new_vm(gwion->mp, 1); + gwion->ppa = mp_calloc(gwion->mp, PPArg); + pparg_ini(gwion->mp, gwion->ppa); gwion->emit = new_emitter(gwion->mp); gwion->env = new_env(gwion->mp); gwion->emit->env = gwion->env; @@ -72,8 +74,8 @@ ANN m_bool gwion_ini(const Gwion gwion, Arg* arg) { arg->si = gwion->vm->bbq->si; const m_bool ret = arg_parse(gwion, arg); if(ret) { + gwion->data->plug = new_plug(gwion->mp, &arg->lib); gwion->emit->info->memoize = arg->memoize; - gwion->plug = new_plug(gwion->mp, &arg->lib); shreduler_set_loop(gwion->vm->shreduler, arg->loop); if(gwion_audio(gwion) > 0 && gwion_engine(gwion)) { plug_run(gwion, &arg->mod); @@ -113,8 +115,9 @@ ANN void gwion_end(const Gwion gwion) { free_vm_shred(gwion->vm->cleaner_shred); free_emitter(gwion->mp, gwion->emit); free_vm(gwion->vm); - free_plug(gwion); - free_gwiondata(gwion->mp, gwion->data); + pparg_end(gwion->ppa); + mp_free(gwion->mp, PPArg, gwion->ppa); + free_gwiondata(gwion); free_symbols(gwion->st); xfree(gwion->type); mempool_end(gwion->mp); diff --git a/src/gwiondata.c b/src/gwiondata.c index 9c5e0435..9e617dbb 100644 --- a/src/gwiondata.c +++ b/src/gwiondata.c @@ -1,32 +1,35 @@ #include "gwion_util.h" #include "gwion_ast.h" #include "gwion_env.h" +#include "plug.h" #include "gwiondata.h" #include "vm.h" #include "instr.h" -#include "gwion.h" #include "emit.h" +#include "gwion.h" #include "specialid.h" +#include "pass.h" ANN GwionData* new_gwiondata(MemPool mp) { struct GwionData_ *data = mp_calloc(mp, GwionData); map_init(&data->freearg); map_init(&data->id); vector_init(&data->reserved); - map_init(&data->pass_map); - vector_init(&data->pass); + data->passes = new_passes(mp); MUTEX_SETUP(data->mutex); return data; } -ANN void free_gwiondata(MemPool mp, GwionData *data) { +ANN void free_gwiondata(const struct Gwion_ *gwion) { + struct GwionData_ *data = gwion->data; map_release(&data->freearg); for(m_uint i = 0; i < map_size(&data->id); ++i) - mp_free(mp, SpecialId, (struct SpecialId_*)map_at(&data->id, i)); + mp_free(gwion->mp, SpecialId, (struct SpecialId_*)map_at(&data->id, i)); map_release(&data->id); vector_release(&data->reserved); - map_release(&data->pass_map); - vector_release(&data->pass); + free_passes(data->passes); + if(data->plug) + free_plug(gwion); MUTEX_CLEANUP(data->mutex); - mp_free(mp, GwionData, data); + mp_free(gwion->mp, GwionData, data); } diff --git a/src/main.c b/src/main.c index eb630d98..7aaebfea 100644 --- a/src/main.c +++ b/src/main.c @@ -18,7 +18,7 @@ int main(int argc, char** argv) { Arg arg = { .argc=argc, .argv=argv, .loop=-1 }; signal(SIGINT, sig); signal(SIGTERM, sig); - struct Gwion_ gwion = { .plug=NULL }; + struct Gwion_ gwion = {}; const m_bool ini = gwion_ini(&gwion, &arg); arg_release(&arg); if(ini > 0) diff --git a/src/pass.c b/src/pass.c index 0ef7fb69..b48ba6a1 100644 --- a/src/pass.c +++ b/src/pass.c @@ -13,16 +13,16 @@ static const compilation_pass default_passes[] = { type_engine_check_prog, emit_ ANN void pass_register(const Gwion gwion, const m_str name, const compilation_pass pass) { const Symbol sym = insert_symbol(gwion->st, name); - map_set(&gwion->data->pass_map, (vtype)sym, (vtype)pass); + map_set(&gwion->data->passes->map, (vtype)sym, (vtype)pass); } ANN m_bool pass_set(const Gwion gwion, const Vector passes) { - const Vector v = &gwion->data->pass; + const Vector v = &gwion->data->passes->vec; vector_clear(v); for(m_uint i = 0; i < vector_size(passes); ++i) { const m_str name = (m_str)vector_at(passes, i); const Symbol sym = insert_symbol(gwion->st, name); - const compilation_pass pass = (compilation_pass)map_get(&gwion->data->pass_map, (vtype)sym); + const compilation_pass pass = (compilation_pass)map_get(&gwion->data->passes->map, (vtype)sym); if(!pass) { gw_err("Failed to set compilation passes, back to default\n"); pass_default(gwion); @@ -43,3 +43,16 @@ ANN void pass_default(const Gwion gwion) { pass_set(gwion, &v); vector_release(&v); } + + +ANEW ANN struct Passes_* new_passes(MemPool mp) { + struct Passes_ *a = mp_calloc(mp, Passes); + map_init(&a->map); + vector_init(&a->vec); + return a; +} + +ANN void free_passes(struct Passes_ *a) { + map_release(&a->map); + vector_release(&a->vec); +} diff --git a/src/plug.c b/src/plug.c index b702d2c4..6f9da98f 100644 --- a/src/plug.c +++ b/src/plug.c @@ -16,9 +16,9 @@ typedef m_bool (*import)(Gwi); typedef m_str (*modstr)(void); -typedef void* (*modini)(const Gwion, const Vector); -typedef void* (*modrun)(const Gwion, void*); -typedef void* (*modend)(const Gwion, void*); +typedef void* (*modini)(const struct Gwion_*, const Vector); +typedef void* (*modrun)(const struct Gwion_*, void*); +typedef void* (*modend)(const struct Gwion_*, void*); struct Plug_ { m_str name; @@ -97,8 +97,8 @@ ANN PlugInfo* new_plug(MemPool p, const Vector list) { return pi; } -void free_plug(const Gwion gwion) { - PlugInfo *p = gwion->plug; +void free_plug(const struct Gwion_ *gwion) { + PlugInfo *p = gwion->data->plug; struct Vector_ * const v = p->vec; for(m_uint i = 0; i < vector_size(&v[GWPLUG_MODULE]); ++i) { struct Plug_ *plug = (struct Plug_*)vector_at(&v[GWPLUG_MODULE], i); @@ -136,8 +136,8 @@ ANN static Vector get_arg(MemPool p, const m_str name, const Vector v) { return NULL; } -void plug_run(const Gwion gwion, const Vector args) { - const Vector v = &gwion->plug->vec[GWPLUG_MODULE]; +void plug_run(const struct Gwion_ *gwion, const Vector args) { + const Vector v = &gwion->data->plug->vec[GWPLUG_MODULE]; for(m_uint i = 0; i < vector_size(v); ++i) { struct Plug_ *plug = (struct Plug_*)vector_at(v, i); const Vector arg = get_arg(gwion->mp, plug->name, args); @@ -150,8 +150,8 @@ void plug_run(const Gwion gwion, const Vector args) { } } -ANN void* get_module(const Gwion gwion, const m_str name) { - const Vector v = &gwion->plug->vec[GWPLUG_MODULE]; +ANN void* get_module(const struct Gwion_ *gwion, const m_str name) { + const Vector v = &gwion->data->plug->vec[GWPLUG_MODULE]; for(m_uint i = 0; i < vector_size(v); ++i) { struct Plug_ *plug = (struct Plug_*)vector_at(v, i); if(!strcmp(name, plug->name)) -- 2.43.0