Closures 25

This commit is contained in:
nazrin 2025-06-11 00:30:22 +00:00
parent 1a614ac45b
commit dc4e6d33b2
16 changed files with 422 additions and 209 deletions

View file

@ -19,11 +19,12 @@ void main(){
"./test/ops.lox".match("1\n2\n3\n4\n5\n6\n7\ntrue\nfalse\ntrue\ntrue\nhello, world\n");
"./test/shortcircuit.lox".match("true\nAAAA!\nAAAA!\nAAAA?\n");
/* "./test/closure.lox".match("1\n2\n"); */
"./test/closure.lox".match("1\n2\n");
"./test/scope.lox".match("global first first second first ".replace(' ', '\n'));
"./test/fib_for.lox".match(fib(6765));
"./test/fib_recursive.lox".match(fib(34));
/* "./test/fib_closure.lox".match(fib(34)); */
"./test/fib_closure.lox".match(fib(34));
"./test/perverseclosure.lox".match("return from outer create inner closure value ".replace(" ", "\n"));
/* "./test/class.lox".match("The German chocolate cake is delicious!\n"); */
/* "./test/super.lox".match("Fry until golden brown.\nPipe full of custard and coat with chocolate.\nA method\n"); */

18
test/perverseclosure.lox Normal file
View file

@ -0,0 +1,18 @@
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();