From: Jérémie Astor Date: Tue, 23 Nov 2021 22:15:53 +0000 (+0100) Subject: :art: more clean X-Git-Tag: nightly~397 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=2939a8395d392c0cbf936094f1f0e8214fc75da7;p=gwion.git :art: more clean --- diff --git a/include/driver.h b/include/driver.h index 915fd009..2a13eb7d 100644 --- a/include/driver.h +++ b/include/driver.h @@ -23,7 +23,7 @@ typedef struct BBQ_ { f_bbqset func; f_bbqrun run; struct DriverData_ *driver; - volatile bool is_running; + bool is_running; } Driver; #define DRVINI(a) ANN m_bool a(struct VM_ *vm NUSED, Driver *di NUSED) diff --git a/include/memoize.h b/include/memoize.h index a926adff..1365fafd 100644 --- a/include/memoize.h +++ b/include/memoize.h @@ -3,7 +3,7 @@ typedef struct Memoize_ *Memoize; Memoize memoize_ini(const Emitter, const Func); -void memoize_end(MemPool, Memoize); +void memoize_end(MemPool, const Memoize); INSTR(MemoizeIni); INSTR(MemoizeStore); #endif diff --git a/src/compile.c b/src/compile.c index b4a96702..ad22aa57 100644 --- a/src/compile.c +++ b/src/compile.c @@ -27,7 +27,7 @@ ANN static void compiler_name(struct Compiler *c) { c->name = strsep(&d, ":"); if (d) vector_init(&c->args); while (d) vector_add(&c->args, (vtype)strdup(strsep(&d, ":"))); - free(d); + xfree(d); } ANN static inline void compiler_error(struct Compiler *const c) { diff --git a/src/emit/memoize.c b/src/emit/memoize.c index 176b272f..00438a24 100644 --- a/src/emit/memoize.c +++ b/src/emit/memoize.c @@ -16,7 +16,7 @@ struct Memoize_ { }; Memoize memoize_ini(const Emitter emit, const Func f) { - Memoize m = mp_calloc(emit->gwion->mp, Memoize); + const Memoize m = mp_calloc(emit->gwion->mp, Memoize); vector_init(&m->v); m->ret_sz = f->def->base->ret_type->size; m->arg_sz = f->def->stack_depth; @@ -24,14 +24,14 @@ Memoize memoize_ini(const Emitter emit, const Func f) { return m; } -void memoize_end(MemPool p, Memoize m) { +void memoize_end(MemPool p, const Memoize m) { for (m_uint i = 0; i < vector_size(&m->v); ++i) mp_free2(p, m->arg_sz + m->arg_sz, (void *)vector_at(&m->v, i)); vector_release(&m->v); mp_free(p, Memoize, m); } -ANN static inline m_bit *get_data(MemPool mp, Memoize m) { +ANN static inline m_bit *get_data(MemPool mp, const Memoize m) { if (vector_size(&m->v) >= m->limit) return (m_bit *)vector_at(&m->v, m->curr++ % m->limit); m_bit *data = mp_calloc2(mp, m->arg_sz + m->ret_sz); @@ -41,7 +41,7 @@ ANN static inline m_bit *get_data(MemPool mp, Memoize m) { INSTR(MemoizeStore) { const Memoize m = shred->code->memoize; - m_bit * data = get_data(shred->info->mp, m); + m_bit *const data = get_data(shred->info->mp, m); memcpy(data, shred->mem, m->arg_sz); memcpy(data + m->arg_sz, shred->reg - m->ret_sz, m->ret_sz); } diff --git a/src/gwion.c b/src/gwion.c index 5f5d9baf..42ba80b1 100644 --- a/src/gwion.c +++ b/src/gwion.c @@ -23,20 +23,16 @@ ANN m_bool gwion_audio(const Gwion gwion) { if (di->si->arg) driver_ini(gwion); di->func(di->driver); CHECK_BB(di->driver->ini(gwion->vm, di)); - ; driver_alloc(di); return GW_OK; } -ANN static inline m_bool gwion_engine(const Gwion gwion) { - return type_engine_init(gwion) > 0; -} - -ANN static void gwion_cleaner(const Gwion gwion) { +ANN static VM_Shred gwion_cleaner(const Gwion gwion) { const VM_Code code = new_vmcode(gwion->mp, NULL, NULL, "in code dtor", 0, true, false); - gwion->vm->cleaner_shred = new_vm_shred(gwion->mp, code); - vm_ini_shred(gwion->vm, gwion->vm->cleaner_shred); + const VM_Shred shred = new_vm_shred(gwion->mp, code); + vm_ini_shred(gwion->vm, shred); + return shred; } ANN VM *gwion_cpy(const VM *src) { @@ -66,8 +62,8 @@ ANN static m_bool gwion_ok(const Gwion gwion, Arg *arg) { shreduler_set_loop(gwion->vm->shreduler, arg->loop); if (gwion_audio(gwion) > 0) { plug_run(gwion, &arg->mod); - if (gwion_engine(gwion)) { - gwion_cleaner(gwion); + if (type_engine_init(gwion)) { + gwion->vm->cleaner_shred = gwion_cleaner(gwion); (void)arg_compile(gwion, arg); return GW_OK; } diff --git a/src/parse/scan1.c b/src/parse/scan1.c index 1dd7988b..09b056d4 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -15,11 +15,10 @@ ANN static inline m_bool type_cyclic(const Env env, const Type t, Type owner = env->class_def; do { Type parent = t; - while (parent) { + do { if (parent == owner) ERR_B(td->pos, _("%s declared inside %s"), t->name, owner->name); - parent = parent->info->parent; - } + } while ((parent = parent->info->parent)); } while ((owner = owner->info->value->from->owner_class)); return GW_OK; } @@ -77,7 +76,7 @@ ANN static Type scan1_exp_decl_type(const Env env, Exp_Decl *decl) { ERR_O(exp_self(decl)->pos, _("can't use private type %s"), t->name) if (GET_FLAG(t, protect) && (!env->class_def || isa(t, env->class_def) < 0)) ERR_O(exp_self(decl)->pos, _("can't use protected type %s"), t->name) - return decl->type = t; + return t; } static inline m_bool scan1_defined(const Env env, const Var_Decl var) { @@ -93,7 +92,7 @@ static inline m_bool scan1_defined(const Env env, const Var_Decl var) { return GW_OK; } -static inline uint array_ref(const Array_Sub array) { +static inline bool array_ref(const Array_Sub array) { return array && !array->exp; } @@ -103,7 +102,7 @@ static inline bool array_ref2(const Array_Sub array) { ANN static m_bool scan1_decl(const Env env, const Exp_Decl *decl) { Var_Decl_List list = decl->list; - const uint decl_ref = array_ref(decl->td->array); + const bool decl_ref = array_ref(decl->td->array); do { const Var_Decl var = list->self; CHECK_BB(isres(env, var->xid, exp_self(decl)->pos)); @@ -242,9 +241,8 @@ ANN static inline m_bool scan1_exp_cast(const Env env, const Exp_Cast *cast) { } ANN static m_bool scan1_exp_post(const Env env, const Exp_Postfix *post) { - if (opiscall(post->op)) { + if (opiscall(post->op)) return exp2call(env, exp_self(post), post->op, post->exp); - } CHECK_BB(scan1_exp(env, post->exp)); const m_str access = exp_access(post->exp); if (!access) return GW_OK; @@ -275,9 +273,8 @@ ANN static inline m_bool scan1_exp_unary(const restrict Env env, const Exp_Unary * unary) { if (unary->unary_type == unary_code) { RET_NSPC(scan1_stmt(env, unary->code)) - } else if (opiscall(unary->op)) { + } else if (opiscall(unary->op)) return exp2call(env, exp_self(unary), unary->op, unary->exp); - } return unary->unary_type == unary_exp ? scan1_exp(env, unary->exp) : GW_OK; } @@ -675,7 +672,6 @@ ANN static inline m_bool scan1_fdef_defined(const Env env, ANN static m_bool _scan1_func_def(const Env env, const Func_Def fdef) { if(GET_FLAG(fdef->base, abstract) && !env->class_def) ERR_B(fdef->base->pos, "file scope function can't be abstract"); -//exit(12); const bool global = GET_FLAG(fdef->base, global); const m_uint scope = !global ? env->scope->depth : env_push_global(env); if (fdef->base->td) @@ -715,7 +711,6 @@ HANDLE_SECTION_FUNC(scan1, m_bool, Env) ANN static Type scan1_get_parent(const Env env, const Type_Def tdef) { const Type parent = known_type(env, tdef->ext); CHECK_OO((tdef->type->info->parent = parent)); - ; Type t = parent; do if (tdef->type == t) diff --git a/src/vm/driver.c b/src/vm/driver.c index d229dd5b..8d68e8e1 100644 --- a/src/vm/driver.c +++ b/src/vm/driver.c @@ -10,7 +10,7 @@ ANN Driver *new_driver(MemPool p) { Driver *di = (Driver *)mp_calloc(p, BBQ); di->func = dummy_driver; di->driver = (DriverData *)mp_calloc(p, DriverData); - di->is_running = 1; + di->is_running = true; return di; }