Register function into globals even if it's a closure

This commit is contained in:
Konstantin Nazarov 2024-09-01 18:04:12 +01:00
parent 8816c62a9e
commit 3999ef97ff
Signed by: knazarov
GPG key ID: 4CFE0A42FA409C22
2 changed files with 13 additions and 0 deletions

View file

@ -679,6 +679,12 @@ Result<Expression> Compiler::compile_fn(Context& context, Symbol& op,
TRY(ex_res.add_opcode(Oc::MakeClosure, {0, (int64_t)reg}, TRY(ex_res.add_opcode(Oc::MakeClosure, {0, (int64_t)reg},
{0, (int64_t)reg + (int64_t)ctx.closures.size() + 1})); {0, (int64_t)reg + (int64_t)ctx.closures.size() + 1}));
if (context.toplevel && !name.is<Nil>()) {
int64_t gname = TRY(context.add_const(name));
TRY(ex_res.add_opcode(Oc::GlobalStore, {1, (int64_t)gname},
{0, (int64_t)reg}));
}
context.maxreg = reg + 1; context.maxreg = reg + 1;
ex_res.reg = reg; ex_res.reg = reg;

View file

@ -26,3 +26,10 @@
1)) 1))
43)) 43))
) )
(let ((x 42))
(fn foo() x)
)
(assert (= (foo) 42))