Closed vtereshkov closed 1 year ago
Beware of extremely perverse cases like the following one taken from Crafting Interpreters.
fun outer() {
var x = "value";
fun middle() {
fun inner() {
print x;
}
print "create inner closure";
return inner;
}
print "return from outer";
return middle;
}
var mid = outer();
var in = mid();
in();
The example from Crafting Interpreters rewritten in Umka:
fn outer(): fn(): fn() {
x := "value"
middle := fn(): fn() |x| {
inner := fn() |x| {
printf("%s\n", x)
}
printf("create inner closure\n")
return inner
}
printf("return from outer\n")
return middle
}
fn main() {
mid := outer()
inn := mid()
inn()
}
Output:
return from outer
create inner closure
value
Allow capturing variables from outer function's stack/heap frame:
This would require changing the internal representation of functions from
to
The API functions
umkaCall()
andumkaGetFunc()
will also have to be changed.