From 702b1f7ee2dc6e6bd3d374b6aff0bfdc0d1c6c33 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Tue, 16 Mar 2021 20:17:04 +0100 Subject: [PATCH] :art: Fix some lambda uses --- src/lib/lib_func.c | 11 ++++++++--- src/vm/vm_code.c | 8 +++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/lib/lib_func.c b/src/lib/lib_func.c index 5302e379..93e08f06 100644 --- a/src/lib/lib_func.c +++ b/src/lib/lib_func.c @@ -150,12 +150,16 @@ ANN static m_bool _check_lambda(const Env env, Exp_Lambda *l, const Func_Def def if(base || arg) ERR_B(exp_self(l)->pos, _("argument number does not match for lambda")) l->def->base->flag = def->base->flag; + if(GET_FLAG(def->base, global) && !l->owner && def->base->func->value_ref->from->owner_class) + UNSET_FLAG(l->def->base, global); l->def->base->td = cpy_type_decl(env->gwion->mp, def->base->td); l->def->base->values = env->curr->info->value; const m_bool ret = traverse_func_def(env, l->def); if(l->def->base->func) { - free_scope(env->gwion->mp, env->curr->info->value); - env->curr->info->value = l->def->base->values; + if(env->curr->info->value != l->def->base->values) { + free_scope(env->gwion->mp, env->curr->info->value); + env->curr->info->value = l->def->base->values; + } } arg = l->def->base->args; while(arg) { @@ -167,7 +171,8 @@ ANN static m_bool _check_lambda(const Env env, Exp_Lambda *l, const Func_Def def ANN m_bool check_lambda(const Env env, const Type t, Exp_Lambda *l) { const Func_Def fdef = t->info->func->def; - l->owner = t->info->owner_class; + if(!GET_FLAG(t->info->func->value_ref, global)) + l->owner = t->info->owner_class; CHECK_BB(_check_lambda(env, l, fdef)) exp_self(l)->type = l->def->base->func->value_ref->type; return GW_OK; diff --git a/src/vm/vm_code.c b/src/vm/vm_code.c index c1d7e013..f30e1a1b 100644 --- a/src/vm/vm_code.c +++ b/src/vm/vm_code.c @@ -26,12 +26,13 @@ ANN void free_vmcode(VM_Code a, Gwion gwion) { memoize_end(gwion->mp, a->memoize); if(!a->builtin) { _mp_free(gwion->mp, vector_size(a->instr) * BYTECODE_SZ, a->bytecode); - if(likely(!a->callback)) + if(likely(!a->callback)) { + if(a->closure) + free_closure(a->closure, gwion); free_code_instr(a->instr, gwion); + } free_vector(gwion->mp, a->instr); } - if(a->closure) - free_closure(a->closure, gwion); free_mstr(gwion->mp, a->name); mp_free(gwion->mp , VM_Code, a); } @@ -160,6 +161,7 @@ VM_Code vmcode_callback(MemPool mp, VM_Code base) { const Instr instr = (Instr)vector_back(base->instr); instr->opcode = eEOC; VM_Code code = new_vmcode(mp, base->instr, base->stack_depth, base->builtin, name); + code->closure = base->closure; code->callback = 1; instr->opcode = eFuncReturn; return code; -- 2.43.0