aboutsummaryrefslogtreecommitdiff
path: root/boot/tests/lower
diff options
context:
space:
mode:
Diffstat (limited to 'boot/tests/lower')
-rw-r--r--boot/tests/lower/closure_capture.cskt39
1 files changed, 39 insertions, 0 deletions
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))