1# test native emitter can handle closures correctly 2 3# basic closure 4@micropython.native 5def f(): 6 x = 1 7 8 @micropython.native 9 def g(): 10 nonlocal x 11 return x 12 13 return g 14 15 16print(f()()) 17 18# closing over an argument 19@micropython.native 20def f(x): 21 @micropython.native 22 def g(): 23 nonlocal x 24 return x 25 26 return g 27 28 29print(f(2)()) 30 31# closing over an argument and a normal local 32@micropython.native 33def f(x): 34 y = 2 * x 35 36 @micropython.native 37 def g(z): 38 return x + y + z 39 40 return g 41 42 43print(f(2)(3)) 44