1# mode: run
2# tag: closures
3# preparse: id
4# preparse: def_to_cdef
5#
6# closure_tests_2.pyx
7#
8# Battery of tests for closures in Cython. Based on the collection of
9# compiler tests from P423/B629 at Indiana University, Spring 1999 and
10# Fall 2000. Special thanks to R. Kent Dybvig, Dan Friedman, Kevin
11# Millikin, and everyone else who helped to generate the original
12# tests. Converted into a collection of Python/Cython tests by Craig
13# Citro.
14#
15# Note: This set of tests is split (somewhat randomly) into several
16# files, simply because putting all the tests in a single file causes
17# gcc and g++ to buckle under the load.
18#
19
20
21def g1526():
22    """
23    >>> g1526()
24    2
25    """
26    x_1134 = 0
27    def g1525():
28      x_1136 = 1
29      z_1135 = x_1134
30      def g1524(y_1137):
31        return (x_1136)+((z_1135)+(y_1137))
32      return g1524
33    f_1138 = g1525()
34    return f_1138(f_1138(x_1134))
35
36
37def g1535():
38    """
39    >>> g1535()
40    3050
41    """
42    def g1534():
43      def g1533():
44        def g1531(t_1141):
45          def g1532(f_1142):
46            return t_1141(f_1142(1000))
47          return g1532
48        return g1531
49      def g1530():
50        def g1529(x_1140):
51          return (x_1140)+(50)
52        return g1529
53      return g1533()(g1530())
54    def g1528():
55      def g1527(y_1139):
56        return (y_1139)+(2000)
57      return g1527
58    return g1534()(g1528())
59
60
61def g1540():
62    """
63    >>> g1540()
64    2050
65    """
66    def g1539():
67      t_1143 = 50
68      def g1538(f_1144):
69        return (t_1143)+(f_1144())
70      return g1538
71    def g1537():
72      def g1536():
73        return 2000
74      return g1536
75    return g1539()(g1537())
76
77
78def g1547():
79    """
80    >>> g1547()
81    2050
82    """
83    def g1546():
84      def g1545():
85        def g1543(t_1145):
86          def g1544(f_1146):
87            return (t_1145)+(f_1146())
88          return g1544
89        return g1543
90      return g1545()(50)
91    def g1542():
92      def g1541():
93        return 2000
94      return g1541
95    return g1546()(g1542())
96
97
98def g1550():
99    """
100    >>> g1550()
101    700
102    """
103    def g1549():
104      x_1147 = 300
105      def g1548(y_1148):
106        return (x_1147)+(y_1148)
107      return g1548
108    return g1549()(400)
109
110
111def g1553():
112    """
113    >>> g1553()
114    0
115    """
116    x_1152 = 3
117    def g1552():
118      def g1551(x_1150, y_1149):
119        return x_1150
120      return g1551
121    f_1151 = g1552()
122    if (f_1151(0, 0)):
123      return f_1151(f_1151(0, 0), x_1152)
124    else:
125      return 0
126
127
128def g1562():
129    """
130    >>> g1562()
131    False
132    """
133    def g1561():
134      def g1556(x_1153):
135        def g1560():
136          def g1559():
137            return isinstance(x_1153, list)
138          if (g1559()):
139            def g1558():
140              def g1557():
141                return (x_1153[0])
142              return (g1557() == 0)
143            return (not g1558())
144          else:
145            return False
146        if (g1560()):
147          return x_1153
148        else:
149          return False
150      return g1556
151    f_1154 = g1561()
152    def g1555():
153      def g1554():
154        return [0,[]]
155      return [0,g1554()]
156    return f_1154(g1555())
157
158
159def g1570():
160    """
161    >>> g1570()
162    False
163    """
164    def g1569():
165      def g1563(x_1155):
166        def g1568():
167          if (x_1155):
168            def g1567():
169              def g1566():
170                return isinstance(x_1155, list)
171              if (g1566()):
172                def g1565():
173                  def g1564():
174                    return (x_1155[0])
175                  return (g1564() == 0)
176                return (not g1565())
177              else:
178                return False
179            return (not g1567())
180          else:
181            return False
182        if (g1568()):
183          return x_1155
184        else:
185          return False
186      return g1563
187    f_1156 = g1569()
188    return f_1156(0)
189
190
191def g1575():
192    """
193    >>> g1575()
194    []
195    """
196    def g1574():
197      def g1571(x_1157):
198        def g1573():
199          def g1572():
200            return isinstance(x_1157, list)
201          if (g1572()):
202            return True
203          else:
204            return (x_1157 == [])
205        if (g1573()):
206          return x_1157
207        else:
208          return []
209      return g1571
210    f_1158 = g1574()
211    return f_1158(0)
212
213
214def g1578():
215    """
216    >>> g1578()
217    4
218    """
219    y_1159 = 4
220    def g1577():
221      def g1576(y_1160):
222        return y_1160
223      return g1576
224    f_1161 = g1577()
225    return f_1161(f_1161(y_1159))
226
227
228def g1581():
229    """
230    >>> g1581()
231    0
232    """
233    y_1162 = 4
234    def g1580():
235      def g1579(x_1164, y_1163):
236        return 0
237      return g1579
238    f_1165 = g1580()
239    return f_1165(f_1165(y_1162, y_1162), f_1165(y_1162, y_1162))
240
241
242def g1584():
243    """
244    >>> g1584()
245    0
246    """
247    y_1166 = 4
248    def g1583():
249      def g1582(x_1168, y_1167):
250        return 0
251      return g1582
252    f_1169 = g1583()
253    return f_1169(f_1169(y_1166, y_1166), f_1169(y_1166, f_1169(y_1166, y_1166)))
254
255
256def g1587():
257    """
258    >>> g1587()
259    0
260    """
261    y_1170 = 4
262    def g1586():
263      def g1585(x_1172, y_1171):
264        return 0
265      return g1585
266    f_1173 = g1586()
267    return f_1173(f_1173(y_1170, f_1173(y_1170, y_1170)), f_1173(y_1170, f_1173(y_1170, y_1170)))
268
269
270def g1594():
271    """
272    >>> g1594()
273    4
274    """
275    def g1593():
276      def g1588(y_1174):
277        def g1592():
278          def g1591(f_1176):
279            return f_1176(f_1176(y_1174))
280          return g1591
281        def g1590():
282          def g1589(y_1175):
283            return y_1175
284          return g1589
285        return g1592()(g1590())
286      return g1588
287    return g1593()(4)
288
289
290def g1598():
291    """
292    >>> g1598()
293    23
294    """
295    def g1597():
296      def g1596(x_1177):
297        return x_1177
298      return g1596
299    f_1178 = g1597()
300    def g1595():
301      if (False):
302        return 1
303      else:
304        return f_1178(22)
305    return (g1595()+1)
306
307
308def g1603():
309    """
310    >>> g1603()
311    22
312    """
313    def g1602():
314      def g1601(x_1179):
315        return x_1179
316      return g1601
317    f_1180 = g1602()
318    def g1600():
319      def g1599():
320        return 23 == 0
321      return f_1180(g1599())
322    if (g1600()):
323      return 1
324    else:
325      return 22
326
327
328def g1611():
329    """
330    >>> g1611()
331    5061
332    """
333    def g1610():
334      def g1609(x_1182):
335        if (x_1182):
336          return (not x_1182)
337        else:
338          return x_1182
339      return g1609
340    f_1185 = g1610()
341    def g1608():
342      def g1607(x_1181):
343        return (10)*(x_1181)
344      return g1607
345    f2_1184 = g1608()
346    x_1183 = 23
347    def g1606():
348      def g1605():
349        def g1604():
350          return x_1183 == 0
351        return f_1185(g1604())
352      if (g1605()):
353        return 1
354      else:
355        return (x_1183)*(f2_1184((x_1183-1)))
356    return (g1606()+1)
357
358
359def g1614():
360    """
361    >>> g1614()
362    1
363    """
364    def g1613():
365      def g1612():
366        return 0
367      return g1612
368    f_1186 = g1613()
369    x_1187 = f_1186()
370    return 1
371
372
373def g1617():
374    """
375    >>> g1617()
376    1
377    """
378    def g1616():
379      def g1615():
380        return 0
381      return g1615
382    f_1188 = g1616()
383    f_1188()
384    return 1
385
386
387def g1620():
388    """
389    >>> g1620()
390    4
391    """
392    def g1619():
393      def g1618(x_1189):
394        return x_1189
395      return g1618
396    f_1190 = g1619()
397    if (True):
398      f_1190(3)
399      return 4
400    else:
401      return 5
402
403
404def g1623():
405    """
406    >>> g1623()
407    6
408    """
409    def g1622():
410      def g1621(x_1191):
411        return x_1191
412      return g1621
413    f_1192 = g1622()
414    (f_1192(4)) if (True) else (5)
415    return 6
416
417
418def g1627():
419    """
420    >>> g1627()
421    120
422    """
423    def g1626():
424      def g1624(fact_1195, n_1194, acc_1193):
425        def g1625():
426          return n_1194 == 0
427        if (g1625()):
428          return acc_1193
429        else:
430          return fact_1195(fact_1195, (n_1194-1), (n_1194)*(acc_1193))
431      return g1624
432    fact_1196 = g1626()
433    return fact_1196(fact_1196, 5, 1)
434
435
436def g1632():
437    """
438    >>> g1632()
439    144
440    """
441    def g1631():
442      def g1628(b_1199, c_1198, a_1197):
443        b_1203 = (b_1199)+(a_1197)
444        def g1630():
445          def g1629():
446            a_1201 = (b_1199)+(b_1199)
447            c_1200 = (c_1198)+(c_1198)
448            return (a_1201)+(a_1201)
449          return (a_1197)+(g1629())
450        a_1202 = g1630()
451        return (a_1202)*(a_1202)
452      return g1628
453    return g1631()(2, 3, 4)
454
455
456def g1639():
457    """
458    >>> g1639()
459    3
460    """
461    def g1638():
462      def g1636(x_1204):
463        def g1637():
464          return x_1204()
465        return g1637
466      return g1636
467    f_1205 = g1638()
468    def g1635():
469      def g1634():
470        def g1633():
471          return 3
472        return g1633
473      return f_1205(g1634())
474    return g1635()()
475
476
477def g1646():
478    """
479    >>> g1646()
480    3628800
481    """
482    def g1645():
483      def g1643(x_1207):
484        def g1644():
485          return x_1207 == 0
486        if (g1644()):
487          return 1
488        else:
489          return (x_1207)*(f_1206((x_1207)-(1)))
490      return g1643
491    f_1206 = g1645()
492    q_1208 = 17
493    def g1642():
494      def g1640(a_1209):
495        q_1208 = 10
496        def g1641():
497          return a_1209(q_1208)
498        return g1641
499      return g1640
500    g_1210 = g1642()
501    return g_1210(f_1206)()
502
503