From 8cebed46abd4840805a42c17316de60fe90a2c0e Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Thu, 3 Oct 2019 03:10:00 +0200 Subject: [PATCH] :shirt: More clean --- src/lib/func.c | 29 ++++++++++++++++------------- src/vm/vm_shred.c | 8 ++++---- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/lib/func.c b/src/lib/func.c index c469bc2b..0d6d509e 100644 --- a/src/lib/func.c +++ b/src/lib/func.c @@ -150,10 +150,7 @@ ANN static Type fptr_type(const Env env, struct FptrInfo *info) { return type; } -ANN2(1,3,4) m_bool check_lambda(const Env env, const Type owner, - Exp_Lambda *l, const Func_Def def) { - const m_uint scope = ((l->owner = owner)) ? - env_push_type(env, owner) : env->scope->depth; +ANN static m_bool _check_lambda(const Env env, Exp_Lambda *l, const Func_Def def) { Arg_List base = def->base->args, arg = l->args; while(base && arg) { arg->td = base->td; @@ -171,9 +168,16 @@ ANN2(1,3,4) m_bool check_lambda(const Env env, const Type owner, arg->td = NULL; arg = arg->next; } + return GW_OK; +} +ANN2(1,3,4) m_bool check_lambda(const Env env, const Type owner, + Exp_Lambda *l, const Func_Def def) { + const m_uint scope = ((l->owner = owner)) ? + env_push_type(env, owner) : env->scope->depth; + const m_bool ret = _check_lambda(env, l, def); if(owner) env_pop(env, scope); - return GW_OK; + return ret; } ANN static m_bool fptr_lambda(const Env env, struct FptrInfo *info) { @@ -221,10 +225,10 @@ static OP_CHECK(opck_fptr_cast) { } static void member_fptr(const Emitter emit) { - const Instr instr = emit_add_instr(emit, RegPop); - instr->m_val = SZ_INT; - const Instr dup = emit_add_instr(emit, Reg2Reg); - dup->m_val = -SZ_INT; + const Instr instr = emit_add_instr(emit, RegPop); + instr->m_val = SZ_INT; + const Instr dup = emit_add_instr(emit, Reg2Reg); + dup->m_val = -SZ_INT; } static OP_EMIT(opem_fptr_cast) { @@ -264,7 +268,7 @@ static OP_CHECK(opck_spork) { ERR_O(exp_self(unary)->pos, _("spork/fork must not have next expression")) if(unary->exp && unary->exp->exp_type == ae_exp_call) return env->gwion->type[unary->op == insert_symbol("spork") ? et_shred : et_fork]; - else if(unary->code) { + if(unary->code) { ++env->scope->depth; nspc_push_value(env->gwion->mp, env->curr); const m_bool ret = check_stmt(env, unary->code); @@ -272,9 +276,8 @@ static OP_CHECK(opck_spork) { --env->scope->depth; CHECK_BO(ret) return env->gwion->type[unary->op == insert_symbol("spork") ? et_shred : et_fork]; - } else - ERR_O(exp_self(unary)->pos, _("only function calls can be sporked...")) - return NULL; + } + ERR_O(exp_self(unary)->pos, _("only function calls can be sporked...")) } static OP_EMIT(opem_spork) { diff --git a/src/vm/vm_shred.c b/src/vm/vm_shred.c index c755ab8a..e81944fd 100644 --- a/src/vm/vm_shred.c +++ b/src/vm/vm_shred.c @@ -30,13 +30,13 @@ static inline void free_shredinfo(MemPool mp, struct ShredInfo_ *info) { xfree((void*)vector_at(v, i - 1)); free_vector(mp, v); } - mp_free(mp, ShredInfo, info); // ??? info->p + mp_free(mp, ShredInfo, info); } VM_Shred new_vm_shred(MemPool p, VM_Code c) { const VM_Shred shred = mp_calloc(p, Stack); - shred->code = c; - shred->reg = (m_bit*)shred + sizeof(struct VM_Shred_); + shred->code = c; + shred->reg = (m_bit*)shred + sizeof(struct VM_Shred_); shred->base = shred->mem = shred->reg + SIZEOF_REG; shred->info = new_shredinfo(p, c->name); shred->info->orig = c; @@ -49,7 +49,7 @@ void free_vm_shred(VM_Shred shred) { release((M_Object)vector_at(&shred->gc, i - 1), shred); vector_release(&shred->gc); REM_REF(shred->info->orig, shred->info->vm->gwion); - MemPool mp = shred->info->mp; + const MemPool mp = shred->info->mp; mp_free(mp, ShredTick, shred->tick); free_shredinfo(mp, shred->info); mp_free(mp, Stack, shred); -- 2.43.0