Register function into globals even if it's a closure
This commit is contained in:
parent
8816c62a9e
commit
3999ef97ff
2 changed files with 13 additions and 0 deletions
|
@ -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;
|
||||||
|
|
||||||
|
|
|
@ -26,3 +26,10 @@
|
||||||
1))
|
1))
|
||||||
43))
|
43))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
(let ((x 42))
|
||||||
|
(fn foo() x)
|
||||||
|
)
|
||||||
|
|
||||||
|
(assert (= (foo) 42))
|
||||||
|
|
Loading…
Reference in a new issue