From: fennecdjay Date: Mon, 12 Feb 2024 22:46:35 +0000 (+0100) Subject: :fire: core poisoning and m_bool removal X-Git-Tag: nightly~86 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=09dad476270cb98d50d08a45674e4af86abb0e3f;p=gwion.git :fire: core poisoning and m_bool removal --- diff --git a/ast b/ast index a9c86cda..8baa0aec 160000 --- a/ast +++ b/ast @@ -1 +1 @@ -Subproject commit a9c86cda990ff3e065dedf2b02c2843d42016f65 +Subproject commit 8baa0aec75a67e220fc9209351c9fbcf82659748 diff --git a/include/gack.h b/include/gack.h index e4d5f80c..858a3a59 100644 --- a/include/gack.h +++ b/include/gack.h @@ -9,5 +9,5 @@ ANN void gack(const VM_Shred, const m_uint); *(m_str *)(VALUE - SZ_INT) = ret; \ } -ANN m_bool mk_gack(MemPool p, const Type type, const f_gack d); +ANN bool mk_gack(MemPool p, const Type type, const f_gack d); #endif diff --git a/include/gwi.h b/include/gwi.h index 9493b188..d237ef30 100644 --- a/include/gwi.h +++ b/include/gwi.h @@ -36,6 +36,6 @@ static inline Tmpl *gwi_tmpl(const Gwi gwi) { return new_tmpl(gwi->gwion->mp, gwi->ck->sl); } -ANN void gwi_effects(const Gwi gwi, const m_str name); -ANN m_bool gwi_run(const Gwion gwion, m_bool (*f)(const Gwi)); +ANN void gwi_effects(const Gwi gwi, const m_str name); +ANN bool gwi_run(const Gwion gwion, m_bool (*f)(const Gwi)); #endif diff --git a/include/gwion.h b/include/gwion.h index 5f1e8b37..8675fa53 100644 --- a/include/gwion.h +++ b/include/gwion.h @@ -18,7 +18,7 @@ struct Gwion_ { struct PPArg_ * ppa; }; -ANN m_bool gwion_ini(const Gwion, CliArg*); +ANN bool gwion_ini(const Gwion, CliArg*); ANN VM * gwion_cpy(const VM *); ANN void gwion_run(const Gwion gwion); ANN void gwion_end(const Gwion gwion); diff --git a/include/import/checker.h b/include/import/checker.h index 35328d5f..07913da0 100644 --- a/include/import/checker.h +++ b/include/import/checker.h @@ -33,7 +33,7 @@ typedef struct OperCK { // name_checker ? m_str ret; Symbol sym; Type (*ck)(Env, void *); // oper - m_bool (*em)(Emitter, void *); // oper + m_bool (*em)(Emitter, void *); // oper should be opem m_str lhs; // oper m_str rhs; // oper struct Vector_ effect; diff --git a/include/plug.h b/include/plug.h index 7551eec0..7a59bdb1 100644 --- a/include/plug.h +++ b/include/plug.h @@ -24,14 +24,14 @@ ANN static inline Plug new_plug(MemPool p) { return (Plug)mp_calloc(p, Plug); } -ANN m_bool plug_ini(const struct Gwion_ *, const Vector); +ANN bool plug_ini(const struct Gwion_ *, const Vector); ANN gwdriver_t driver_ini(const struct Gwion_ *, struct SoundInfo_ *); -ANN m_bool plug_run(const struct Gwion_ *, const Map); +ANN bool plug_run(const struct Gwion_ *, const Map); ANN void free_plug(const Gwion); ANN void * get_module(const struct Gwion_ *, const m_str); -ANN m_bool set_module(const struct Gwion_ *gwion, const m_str name, +ANN bool set_module(const struct Gwion_ *gwion, const m_str name, void *const ptr); -ANN m_bool plugin_ini(struct Gwion_ *gwion, const m_str iname, const loc_t); +ANN bool plugin_ini(struct Gwion_ *gwion, const m_str iname, const loc_t); #define GWIMPORT_NAME(a) gwimport_##a diff --git a/plug b/plug index 8eab3d20..d4a5df74 160000 --- a/plug +++ b/plug @@ -1 +1 @@ -Subproject commit 8eab3d20a622cc86b3daf2d5760338f80f6856a0 +Subproject commit d4a5df7434b11b76b1b56b7132d7037840a4227a diff --git a/scripts/fuzzer.c b/scripts/fuzzer.c index 45d9fb92..d1238bf5 100644 --- a/scripts/fuzzer.c +++ b/scripts/fuzzer.c @@ -10,7 +10,7 @@ static struct Gwion_ gwion; static void initialize() { Arg arg = { .loop=-1 }; - const m_bool ini = gwion_ini(&gwion, &arg); + const bool ini = gwion_ini(&gwion, &arg); arg_release(&arg); } diff --git a/src/compile.c b/src/compile.c index 8eb79d32..69d8604d 100644 --- a/src/compile.c +++ b/src/compile.c @@ -50,64 +50,64 @@ ANN static void compiler_clean(const struct Compiler *c) { if (c->type != COMPILE_FILE && c->file) fclose(c->file); } -ANN static m_bool _compiler_open(struct Compiler *c) { +ANN static bool _compiler_open(struct Compiler *c) { if (c->type == COMPILE_NAME) { m_str name = c->name; c->name = realpath(name, NULL); xfree(name); - return c->name ? !!(c->file = fopen(c->name, "r")) : GW_ERROR; + return c->name ? !!(c->file = fopen(c->name, "r")) : false; } else if (c->type == COMPILE_MSTR) { c->file = c->data ? fmemopen(c->data, strlen(c->data), "r") : NULL; - return c->file ? GW_OK : GW_ERROR; + return !!c->file; } - return GW_OK; + return true; } #ifndef BUILD_ON_WINDOWS #include -ANN static int is_reg(const m_str path) { +ANN static bool is_reg(const m_str path) { struct stat s = {}; stat(path, &s); return !S_ISDIR(s.st_mode) && (S_ISREG(s.st_mode) || !S_ISFIFO(s.st_mode)); } #else -ANN static m_bool is_reg(const m_str path) { +ANN static bool is_reg(const m_str path) { const DWORD dw = GetFileAttributes(path); return !(dw == INVALID_FILE_ATTRIBUTES || dw & FILE_ATTRIBUTE_DIRECTORY); } #endif -ANN static inline m_bool compiler_open(struct Compiler *c) { +ANN static inline bool compiler_open(struct Compiler *c) { char name[strlen(c->name) + 1]; strcpy(name, c->name); #ifndef __FUZZING__ if ((c->type == COMPILE_FILE || c->type == COMPILE_NAME) && !is_reg(name)) { gw_err(_("'%s': is a not a regular file\n"), name); - return GW_ERROR; + return false; } #endif - if (_compiler_open(c) < 0) { + if (!_compiler_open(c)) { compiler_error(c); gw_err(_("can't open '%s'\n"), name); - return GW_ERROR; + return false; } - return GW_OK; + return true; } -ANN static inline m_bool _passes(struct Gwion_ *gwion, struct Compiler *c) { +ANN static inline bool _passes(struct Gwion_ *gwion, struct Compiler *c) { 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); if(pass(gwion->env, &c->ast) < 0) { gwion->data->errored = true; - return GW_ERROR; + return false; } } - return GW_OK; + return true; } -ANN static inline m_bool passes(struct Gwion_ *gwion, struct Compiler *c) { +ANN static inline bool passes(struct Gwion_ *gwion, struct Compiler *c) { const Env env = gwion->env; const Context ctx = new_context(env->gwion->mp, c->ast, env->name); env_reset(env); @@ -123,11 +123,11 @@ ANN static inline m_bool passes(struct Gwion_ *gwion, struct Compiler *c) { } else valid_value(gwion->env, insert_symbol(gwion->st, v->name), v); } - const m_bool ret = _passes(gwion, c); + const bool ret = _passes(gwion, c); ctx->tree = c->ast; - if (ret > 0) //{ + if (ret) //{ nspc_commit(env->curr); - if (ret > 0 || env->context->global) + if (ret || env->context->global) vector_add(&env->scope->known_ctx, (vtype)ctx); else { // nspc_rollback(env->global_nspc); context_remref(ctx, env->gwion); @@ -140,17 +140,16 @@ static pos_t pos = { 1 , 1 }; void gwion_set_default_pos(const pos_t _pos) { pos = _pos; } -ANN static inline m_bool _check(struct Gwion_ *gwion, struct Compiler *c) { +ANN static inline bool _check(struct Gwion_ *gwion, struct Compiler *c) { struct AstGetter_ arg = {c->name, c->file, gwion->st, .ppa = gwion->ppa}; - CHECK_OB((c->ast = parse_pos(&arg, pos))); + CHECK_B((c->ast = parse_pos(&arg, pos))); gwion->env->name = c->name; - const m_bool ret = passes(gwion, c); - return ret; + return passes(gwion, c); } ANN static m_uint _compile(struct Gwion_ *gwion, struct Compiler *c) { - if (compiler_open(c) < 0) return 0; - if (_check(gwion, c) < 0) return 0; + if (!compiler_open(c)) return 0; + if (!_check(gwion, c)) return 0; if (gwion->emit->info->code) { c->shred = new_vm_shred(gwion->mp, gwion->emit->info->code); c->shred->info->args.ptr = c->args.ptr; diff --git a/src/gwion.c b/src/gwion.c index e26cdfe7..0876be2e 100644 --- a/src/gwion.c +++ b/src/gwion.c @@ -16,13 +16,14 @@ #include "shreduler_private.h" #include "ugen.h" -ANN m_bool gwion_audio(const Gwion gwion) { +ANN static bool gwion_audio(const Gwion gwion) { Driver *const di = gwion->vm->bbq; - if (di->si->arg) CHECK_OB((di->func = driver_ini(gwion, di->si))); + if (di->si->arg) CHECK_B((di->func = driver_ini(gwion, di->si))); di->func(di->driver); - CHECK_BB(di->driver->ini(gwion->vm, di)); + if(di->driver->ini(gwion->vm, di) < 0) + return false; driver_alloc(di); - return GW_OK; + return true; } ANN static VM_Shred gwion_cleaner(const Gwion gwion) { @@ -73,22 +74,22 @@ ANN static Func gwion_locale(const Gwion gwion) { return v->d.func_ref; } -ANN static m_bool gwion_ok(const Gwion gwion, CliArg *arg) { - CHECK_BB(plug_ini(gwion, &arg->lib)); +ANN static bool gwion_ok(const Gwion gwion, CliArg *arg) { + if(!plug_ini(gwion, &arg->lib)) return false; shreduler_set_loop(gwion->vm->shreduler, arg->loop); if(arg->embed_libs) arg->embed_libs(gwion); - if (gwion_audio(gwion) > 0) { - CHECK_BB(plug_run(gwion, &arg->mod)); + if (gwion_audio(gwion)) { + if(!plug_run(gwion, &arg->mod)) return false; if (type_engine_init(gwion)) { vector_add(&gwion->data->plugs->vec, (m_uint)gwion->env->global_nspc); gwion->vm->cleaner_shred = gwion_cleaner(gwion); gwion->emit->locale = gwion_locale(gwion); if(arg->embed_scripts) arg->embed_scripts(gwion); arg_compile(gwion, arg); - return GW_OK; + return true; } } - return GW_ERROR; + return false; } #define LOCALE_INFO INSTALL_PREFIX "/share" @@ -101,7 +102,7 @@ ANN static void doc_mode(const Gwion gwion) { vector_release(&v); } -ANN m_bool gwion_ini(const Gwion gwion, CliArg *arg) { +ANN bool gwion_ini(const Gwion gwion, CliArg *arg) { #ifdef USE_GETTEXT setlocale(LC_ALL, NULL); bindtextdomain(GWION_PACKAGE, LOCALE_INFO); @@ -129,7 +130,7 @@ ANN m_bool gwion_ini(const Gwion gwion, CliArg *arg) { pass_default(gwion); else doc_mode(gwion); } - return !arg->quit ? gwion_ok(gwion, arg) : GW_ERROR; + return !arg->quit ? gwion_ok(gwion, arg) : false; } ANN void gwion_run(const Gwion gwion) { diff --git a/src/import/import_internals.c b/src/import/import_internals.c index 6a7e148d..19ef0cde 100644 --- a/src/import/import_internals.c +++ b/src/import/import_internals.c @@ -29,7 +29,7 @@ ANN void gwi_reset(const Gwi gwi) { env_reset(gwi->gwion->env); } -ANN static m_bool run_with_doc(const Gwi gwi, m_bool (*f)(const Gwi)) { +ANN static bool run_with_doc(const Gwi gwi, m_bool (*f)(const Gwi)) { struct GwfmtState ls = {.builtin = true, .nindent = 4}; text_init(&ls.text, gwi->gwion->mp); Gwfmt gwfmter = {.mp = gwi->gwion->mp, .ls = &ls, .st = gwi->gwion->st }; @@ -38,10 +38,10 @@ ANN static m_bool run_with_doc(const Gwi gwi, m_bool (*f)(const Gwi)) { gwi->gwfmt = &gwfmter; const m_bool ret = f(gwi); fprintf(stdout, "%s", ls.text.str); - return ret; + return ret > 0; } -ANN m_bool gwi_run(const Gwion gwion, m_bool (*f)(const Gwi)) { +ANN bool gwi_run(const Gwion gwion, m_bool (*f)(const Gwi)) { const m_str name = gwion->env->name; // const Context ctx = gwion->env->context; // gwion->env->context = NULL; @@ -51,6 +51,6 @@ ANN m_bool gwi_run(const Gwion gwion, m_bool (*f)(const Gwi)) { if (ret < 0) gwi_reset(&gwi); gwion->env->name = name; // gwion->env->context = ctx; - return ret; + return ret > 0; } diff --git a/src/import/import_prim.c b/src/import/import_prim.c index 94600012..a83e8a58 100644 --- a/src/import/import_prim.c +++ b/src/import/import_prim.c @@ -217,7 +217,7 @@ ANN Type mk_primitive(const Env env, const m_str name, const m_uint size) { prim_op(env, t, "$", NULL, (opem)dummy_func); prim_implicit(env, t); } // else provide function to get slices - CHECK_BO(mk_gack(env->gwion->mp, t, gack_prim)); + CHECK_O(mk_gack(env->gwion->mp, t, gack_prim)); return t; } diff --git a/src/import/import_special.c b/src/import/import_special.c index eacc236c..ca85ced4 100644 --- a/src/import/import_special.c +++ b/src/import/import_special.c @@ -44,11 +44,11 @@ ANN void gwi_set_loc(const Gwi gwi, const m_str file, const uint line) { gwi->gwion->env->name = file; } -ANN m_bool mk_gack(MemPool p, const Type type, const f_gack d) { +ANN bool mk_gack(MemPool p, const Type type, const f_gack d) { const VM_Code code = new_vmcode(p, NULL, NULL, "@gack", SZ_INT, true, false); code->native_func = (m_uint)d; type->info->gack = code; - return GW_OK; + return true; } ANN m_bool gwi_gack(const Gwi gwi, const Type type, const f_gack d) { diff --git a/src/lib/engine.c b/src/lib/engine.c index 0345d290..a3a744b2 100644 --- a/src/lib/engine.c +++ b/src/lib/engine.c @@ -171,7 +171,7 @@ ANN static m_bool import_core_libs(const Gwi gwi) { ANN m_bool type_engine_init(const Gwion gwion) { gwion->env->name = "[builtin]"; - CHECK_BB(gwi_run(gwion, import_core_libs)); + CHECK_b(gwi_run(gwion, import_core_libs)); gwion->data->cdoc = false; push_global(gwion, "[user]"); return GW_OK; diff --git a/src/main.c b/src/main.c index 9b5aa648..8c99fd2b 100644 --- a/src/main.c +++ b/src/main.c @@ -90,9 +90,9 @@ int main(int argc, char **argv) { .thread_count = 4, .queue_size = 16 }; - const m_bool ini = gwion_ini(&gwion, &arg); + const bool ini = gwion_ini(&gwion, &arg); arg_release(&arg); - if (ini > 0) gwion_run(&gwion); + if (ini) gwion_run(&gwion); const bool ret = gwion.data->errored; gwion_end(&gwion); gwion.vm = NULL; diff --git a/src/parse/scan0.c b/src/parse/scan0.c index fb51107e..453ba3e3 100644 --- a/src/parse/scan0.c +++ b/src/parse/scan0.c @@ -425,7 +425,7 @@ ANN static bool scan0_stmt_list(const Env env, Stmt_List l) { if (stmt->d.stmt_pp.pp_type == ae_pp_include) env->name = stmt->d.stmt_pp.data; else if (stmt->d.stmt_pp.pp_type == ae_pp_import) { - if(plugin_ini(env->gwion, stmt->d.stmt_pp.data, stmt->loc) < 0) + if(!plugin_ini(env->gwion, stmt->d.stmt_pp.data, stmt->loc)) ok = false; } } else if (stmt->stmt_type == ae_stmt_spread) { diff --git a/src/plug.c b/src/plug.c index f0d594d4..c0d3809e 100644 --- a/src/plug.c +++ b/src/plug.c @@ -74,7 +74,7 @@ ANN static void plug_get_all(struct PlugHandle *h, const m_str name) { #endif } -ANN m_bool plug_ini(const struct Gwion_ *gwion, const Vector list) { +ANN bool plug_ini(const struct Gwion_ *gwion, const Vector list) { gwion->data->plugs = mp_calloc2(gwion->mp, sizeof(Plugs)); const Map map = &gwion->data->plugs->map; map_init(map); @@ -84,10 +84,10 @@ ANN m_bool plug_ini(const struct Gwion_ *gwion, const Vector list) { const m_str dir = (m_str)vector_at(list, i - 1); h.len = strlen(dir); char name[PATH_MAX]; - sprintf(name, "%s/*.so", dir); + sprintf(name, "%s/" "*.so", dir); plug_get_all(&h, name); } - return GW_OK; + return true; } void free_plug(const Gwion gwion) { @@ -115,21 +115,21 @@ ANN static void plug_free_arg(MemPool p, const Vector v) { free_vector(p, v); } -ANN m_bool set_module(const struct Gwion_ *gwion, const m_str name, +ANN bool set_module(const struct Gwion_ *gwion, const m_str name, void *const ptr) { const Map map = &gwion->data->plugs->map; for (m_uint j = 0; j < map_size(map); ++j) { if (!strcmp(name, (m_str)VKEY(map, j))) { Plug plug = (Plug)VVAL(map, j); plug->self = ptr; - return GW_OK; + return true; } } gw_err("%s: no such module\n", name); - return GW_ERROR; + return false; } -ANN m_bool plug_run(const struct Gwion_ *gwion, const Map mod) { +ANN bool plug_run(const struct Gwion_ *gwion, const Map mod) { const Map map = &gwion->data->plugs->map; for (m_uint i = 0; i < map_size(mod); ++i) { const m_str name = (m_str)VKEY(mod, i); @@ -147,27 +147,27 @@ ANN m_bool plug_run(const struct Gwion_ *gwion, const Map mod) { } if(j == map_size(map)) { gw_err("%s: no such module\n", name); - return GW_ERROR; + return false; } } - return GW_OK; + return true; } -ANN static m_bool dependencies(struct Gwion_ *gwion, const Plug plug, const loc_t loc) { +ANN static bool dependencies(struct Gwion_ *gwion, const Plug plug, const loc_t loc) { const gwdepend_t dep = plug->depend; bool ret = true; if (dep) { m_str *const base = dep(); m_str * deps = base; while (*deps) { - if(plugin_ini(gwion, *deps, loc) < 0) { + if(!plugin_ini(gwion, *deps, loc)) { gw_err("%s: no such plugin (dependency)\n", *deps); ret = false; } ++deps; } } - return ret ? GW_OK : GW_ERROR; + return ret; } ANN static void plug_name(m_str name, const m_str iname, const m_uint size) { @@ -182,11 +182,11 @@ ANN static void set_parent(const Nspc nspc, const Gwion gwion ) { user->parent = nspc; } -ANN static m_bool start(const Plug plug, const Gwion gwion, const m_str iname, const loc_t loc) { - if(!plug->plugin) return GW_ERROR; +ANN static bool start(const Plug plug, const Gwion gwion, const m_str iname, const loc_t loc) { + if(!plug->plugin) return false; const bool cdoc = gwion->data->cdoc; gwion->data->cdoc = 0; // check cdoc - CHECK_BB(dependencies(gwion, plug, loc)); + CHECK_B(dependencies(gwion, plug, loc)); gwion->data->cdoc = cdoc; plug->nspc = new_nspc(gwion->mp, iname); vector_add(&gwion->data->plugs->vec, (m_uint)plug->nspc); @@ -194,22 +194,22 @@ ANN static m_bool start(const Plug plug, const Gwion gwion, const m_str iname, c const m_uint scope = env_push(gwion->env, NULL, plug->nspc); const m_str name = gwion->env->name; gwion->env->name = iname; - const m_bool ret = gwi_run(gwion, plug->plugin); + const bool ret = gwi_run(gwion, plug->plugin); gwion->env->name = name; env_pop(gwion->env, scope); return ret; } -ANN static m_bool started(const Plug plug, const Gwion gwion, const m_str iname) { +ANN static bool started(const Plug plug, const Gwion gwion, const m_str iname) { Nspc nspc = gwion->env->global_nspc->parent; do if(!strcmp(nspc->name, iname)) - return GW_OK; + return true; while((nspc = nspc->parent)); set_parent(plug->nspc, gwion); - return GW_OK; + return true; } -ANN static m_bool _plugin_ini(struct Gwion_ *gwion, const m_str iname, const loc_t loc) { +ANN static bool _plugin_ini(struct Gwion_ *gwion, const m_str iname, const loc_t loc) { const Map map = &gwion->data->plugs->map; for (m_uint i = 0; i < map_size(map); ++i) { const Plug plug = (Plug)VVAL(map, i); @@ -222,15 +222,15 @@ ANN static m_bool _plugin_ini(struct Gwion_ *gwion, const m_str iname, const loc else return started(plug, gwion, iname); } } - return GW_ERROR; + return false; } -ANN m_bool plugin_ini(struct Gwion_ *gwion, const m_str iname, const loc_t loc) { +ANN bool plugin_ini(struct Gwion_ *gwion, const m_str iname, const loc_t loc) { const Env env = gwion->env; - if(_plugin_ini(gwion, iname, loc) < 0) { + if(!_plugin_ini(gwion, iname, loc)) { if(gwion->env->context && !gwion->env->context->error) env_err(env, loc, "%s: no such plugin\n", iname); - return GW_ERROR; + return false; } return GW_OK; } diff --git a/tests/module/get_module.c b/tests/module/get_module.c index ec9cd361..f3224fa8 100644 --- a/tests/module/get_module.c +++ b/tests/module/get_module.c @@ -19,7 +19,7 @@ GWMODINI(get_module) { GWMODEND(get_module) { puts(__func__); } GWION_IMPORT(get_module) { - CHECK_BB(set_module(gwi->gwion, "get_module", (void *)1)); + CHECK_b(set_module(gwi->gwion, "get_module", (void *)1)); GWI_OB(get_module(gwi->gwion, "get_module")) puts("test passed"); get_module(gwi->gwion, "non_existant_module"); diff --git a/util b/util index 794ebb72..373c31f9 160000 --- a/util +++ b/util @@ -1 +1 @@ -Subproject commit 794ebb72427e9baf957ffbba306be864899d2728 +Subproject commit 373c31f93cc54f6dd0f04dee5b685bb8f73d4a88