From 7675205dacf3e3da9ce59d2e38fe3a04f48ae625 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Sat, 15 May 2021 02:05:39 +0200 Subject: [PATCH] :art improve passes and doc mode --- include/gwiondata.h | 4 ++-- include/pass.h | 2 +- src/env/env_utils.c | 7 +++++-- src/gwion.c | 13 ++++++++++++- src/gwiondata.c | 5 ++--- src/import/import_internals.c | 1 - src/pass.c | 23 ++++++++++++++--------- 7 files changed, 36 insertions(+), 19 deletions(-) diff --git a/include/gwiondata.h b/include/gwiondata.h index 2c621ef0..eb56f935 100644 --- a/include/gwiondata.h +++ b/include/gwiondata.h @@ -11,8 +11,8 @@ typedef struct GwionData_ { bool cdoc; } GwionData; -ANN GwionData* new_gwiondata(MemPool); +ANN GwionData* new_gwiondata(const MemPool); ANN GwionData* cpy_gwiondata(MemPool, const GwionData*); -ANN void free_gwiondata(const struct Gwion_*); +ANN void free_gwiondata(const Gwion); ANN void free_gwiondata_cpy(const MemPool, GwionData*); #endif diff --git a/include/pass.h b/include/pass.h index 42df4c4a..119a1cbf 100644 --- a/include/pass.h +++ b/include/pass.h @@ -13,7 +13,7 @@ struct Passes_ { // change this to gwion ? typedef m_bool (*compilation_pass)(const Env, PassArg); -ANEW ANN struct Passes_* new_passes(MemPool mp); +ANEW ANN struct Passes_* new_passes(const Gwion); ANN void free_passes(MemPool mp, struct Passes_*); ANN void pass_register(const Gwion, const m_str, const compilation_pass); ANN void pass_default(const Gwion); diff --git a/src/env/env_utils.c b/src/env/env_utils.c index c3672d9c..fe3c882c 100644 --- a/src/env/env_utils.c +++ b/src/env/env_utils.c @@ -108,7 +108,10 @@ ANN Value global_string(const Env env, const m_str str) { } ANN m_bool isres(const Env env, const Symbol xid, const loc_t pos) { - if(vector_find(&env->gwion->data->reserved, (vtype)xid) > -1) - ERR_B(pos, _("%s is reserved."), s_name(xid)); + const Map map = &env->gwion->data->id; + for(m_uint i = 0; i < map_size(map); i++) { + if(xid == (Symbol)VKEY(map, i)) + ERR_B(pos, _("%s is reserved."), s_name(xid)); + } return GW_OK; } diff --git a/src/gwion.c b/src/gwion.c index 092fc9f6..3bc2ebc4 100644 --- a/src/gwion.c +++ b/src/gwion.c @@ -76,6 +76,13 @@ ANN static m_bool gwion_ok(const Gwion gwion, Arg* arg) { #define LOCALE_INFO INSTALL_PREFIX "/share" +ANN static void doc_mode(const Gwion gwion) { + struct Vector_ v; + vector_init(&v); + vector_add(&v, (m_uint)"scan0"); + pass_set(gwion, &v); +} + ANN m_bool gwion_ini(const Gwion gwion, Arg* arg) { #ifdef USE_GETTEXT setlocale(LC_ALL, NULL); @@ -90,8 +97,8 @@ ANN m_bool gwion_ini(const Gwion gwion, Arg* arg) { gwion_core(gwion); gwion->data = new_gwiondata(gwion->mp); gwion->type = (Type*)xcalloc(MAX_TYPE, sizeof(struct Type_*)); - pass_default(gwion); arg->si = gwion->vm->bbq->si = new_soundinfo(gwion->mp); + new_passes(gwion); CHECK_BB(arg_parse(gwion, arg)); if(arg->color == COLOR_NEVER) tcol_override_color_checks(0); @@ -99,6 +106,10 @@ ANN m_bool gwion_ini(const Gwion gwion, Arg* arg) { tcol_override_color_checks(isatty(1)); else if(arg->color == COLOR_ALWAYS) tcol_override_color_checks(1); + if(!gwion->data->cdoc) + pass_default(gwion); + else + doc_mode(gwion); return !arg->quit ? gwion_ok(gwion, arg) : GW_ERROR; } diff --git a/src/gwiondata.c b/src/gwiondata.c index 13d88071..7b2af4b5 100644 --- a/src/gwiondata.c +++ b/src/gwiondata.c @@ -16,11 +16,10 @@ ANN static inline GwionData* gwiondata(MemPool mp) { return data; } -ANN GwionData* new_gwiondata(MemPool mp) { +ANN GwionData* new_gwiondata(const MemPool mp) { GwionData *data = gwiondata(mp); map_init(&data->freearg); map_init(&data->id); - data->passes = new_passes(mp); return data; } @@ -38,7 +37,7 @@ ANN void free_gwiondata_cpy(const MemPool mp, GwionData *data) { mp_free(mp, GwionData, data); } -ANN void free_gwiondata(const struct Gwion_ *gwion) { +ANN void free_gwiondata(const Gwion gwion) { GwionData *data = gwion->data; map_release(&data->freearg); for(m_uint i = 0; i < map_size(&data->id); ++i) diff --git a/src/import/import_internals.c b/src/import/import_internals.c index 19b25541..467184bd 100644 --- a/src/import/import_internals.c +++ b/src/import/import_internals.c @@ -38,7 +38,6 @@ ANN static m_bool run_with_doc(const Gwi gwi, m_bool (*f)(const Gwi)) { ANN m_bool gwi_run(const Gwion gwion, m_bool (*f)(const Gwi)) { const m_str name = gwion->env->name; OperCK oper = {}; -printf("cdoc %u\n", gwion->data->cdoc); struct Gwi_ gwi = { .gwion=gwion, .oper=&oper }; const m_bool ret = !gwion->data->cdoc ? f(&gwi) : run_with_doc(&gwi, f); diff --git a/src/pass.c b/src/pass.c index b2abca41..57cb6b78 100644 --- a/src/pass.c +++ b/src/pass.c @@ -8,9 +8,13 @@ #include "pass.h" #include "traverse.h" -static const m_str default_passes_name[] = { "check", "emit" }; -static const compilation_pass default_passes[] = { traverse_ast, emit_ast }; -#define NPASS sizeof(default_passes)/sizeof(default_passes[0]) +#define N_PASS 2 +#define N_SCANPASS 4 + +static const m_str default_passes_name[2] = { "check", "emit" }; +static const compilation_pass default_passes[4] = { traverse_ast, emit_ast }; +static const m_str scan_passes_name[4] = { "scan0", "scan1", "scan2", "type_check" }; +static const compilation_pass scan_passes[4] = { scan0_ast, scan1_ast, scan2_ast, check_ast }; ANN void pass_register(const Gwion gwion, const m_str name, const compilation_pass pass) { const Symbol sym = insert_symbol(gwion->st, name); @@ -37,18 +41,19 @@ ANN m_bool pass_set(const Gwion gwion, const Vector passes) { ANN void pass_default(const Gwion gwion) { struct Vector_ v; vector_init(&v); - for(m_uint i = 0; i < NPASS; ++i) { + for(m_uint i = 0; i < N_PASS; ++i) vector_add(&v, (vtype)default_passes_name[i]); - pass_register(gwion, default_passes_name[i], default_passes[i]); - } pass_set(gwion, &v); vector_release(&v); } - -ANEW ANN struct Passes_* new_passes(MemPool mp) { - struct Passes_ *a = mp_calloc(mp, Passes); +ANEW ANN struct Passes_* new_passes(const Gwion gwion) { + struct Passes_ *a = gwion->data->passes = mp_calloc(gwion->mp, Passes); map_init(&a->map); + for(m_uint i = 0; i < N_PASS; ++i) + pass_register(gwion, default_passes_name[i], default_passes[i]); + for(m_uint i = 0; i < N_SCANPASS; ++i) + pass_register(gwion, scan_passes_name[i], scan_passes[i]); vector_init(&a->vec); return a; } -- 2.43.0