about summary refs log tree commit diff
path: root/boot/tests/lower/closure_capture.cskt
blob: f611326cc5e84f868d50063c85cdb523540746d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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))