From a541f735c8a1ed1a909ded7d3ab6ee5ebc432fdf Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Mon, 15 Jun 2020 14:18:40 +0200 Subject: [PATCH] :art: Lambdas are not file global funcs --- src/emit/emit.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/emit/emit.c b/src/emit/emit.c index 18c127b6..9f19e4d5 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -1965,10 +1965,16 @@ ANN static m_bool emit_fdef(const Emitter emit, const Func_Def fdef) { return GW_OK; } +static ANN int fdef_is_file_global(const Emitter emit, const Func_Def fdef) { + return isa(fdef->base->func->value_ref->type, emit->gwion->type[et_lambda]) < 0 && + !emit->env->class_def && !GET_FLAG(fdef, global) && !fdef->base->tmpl && + !emit->env->scope->depth; +} + ANN static void emit_fdef_finish(const Emitter emit, const Func_Def fdef) { const Func func = fdef->base->func; func->code = emit_func_def_code(emit, func); - if(!emit->env->class_def && !GET_FLAG(fdef, global) && !fdef->base->tmpl) + if(fdef_is_file_global(emit, fdef)) emit_func_def_global(emit, func->value_ref); if(emit->info->memoize && GET_FLAG(func, pure)) func->code->memoize = memoize_ini(emit, func); @@ -1982,8 +1988,7 @@ ANN static m_bool emit_func_def(const Emitter emit, const Func_Def f) { return GW_OK; if(SAFE_FLAG(emit->env->class_def, builtin) && GET_FLAG(emit->env->class_def, template)) return GW_OK; - // TODO: we might not need lambdas here - if(!emit->env->class_def && !GET_FLAG(fdef, global) && !fdef->base->tmpl && !emit->env->scope->depth) + if(fdef_is_file_global(emit, fdef)) func->value_ref->from->offset = emit_local(emit, emit->gwion->type[et_int]); emit_func_def_init(emit, func); if(GET_FLAG(func, member)) -- 2.43.0