From a5b24e3eedc8bd48de99cfb90abb3bececa5d29f Mon Sep 17 00:00:00 2001 From: Mel Date: Thu, 28 May 2026 01:17:32 +0200 Subject: Add tests for function value passing and capturing closure behavior Signed-off-by: Mel --- boot/tests/lower/closure_capture.cskt | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 boot/tests/lower/closure_capture.cskt (limited to 'boot/tests/lower/closure_capture.cskt') diff --git a/boot/tests/lower/closure_capture.cskt b/boot/tests/lower/closure_capture.cskt new file mode 100644 index 0000000..f611326 --- /dev/null +++ b/boot/tests/lower/closure_capture.cskt @@ -0,0 +1,39 @@ +a lambda that closes over a local from its enclosing function +synthesizes both a fat-closure type for the signature and a state +type holding pointers to each captured local. +the body's references to any captured names should be recognized. + +<<< + +main = fun () { + var bump int = 10 + var f fun (i int) int = fun (i int) int { + return i + bump + } + var r int = f(5) +} + +>>> + +(unit + (types + (type 0 int primitive) + (type 1 uint primitive) + (type 2 bool primitive) + (type 3 string primitive) + (type 4 float primitive) + (type 5 byte primitive) + (type 6 ascii primitive) + (type 7 void primitive) + (type 8 __cat_type_0 synthetic function (returns (ref int)) (param (ref int)) (depends_on 0 0)) + (type 9 __cat_type_1 synthetic structure (field bump (ref & int)))) + (functions + (function 0 main main (returns (ref void)) (block + (declaration bump (ref int) (initializer (expr 10))) + (declaration f (ref __cat_type_0) (initializer (expr (fn-ref __cat_lambda_0)))) + (declaration r (ref int) (initializer (expr (call (expr (name f)) (slot 0 (expr 5)))))) + )) + (function 1 __cat_lambda_0 synthetic (returns (ref int)) (param i (ref int)) (block + (return (expr (binary + (expr (name i)) (expr (capture bump))))) + ))) + (emission_order 0 1 2 3 4 5 6 7 8 9)) -- cgit 1.4.1