summaryrefslogtreecommitdiff
path: root/gcc/melt/warmelt-genobj.melt
blob: 84b3c8b08bb9d8c8d44c9c85d7100a7017f6174d (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
 ;; File warmelt-genobj.melt -*- Lisp -*-
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 (comment "***
     Copyright 2008 - 2014  Free Software Foundation, Inc.
     Contributed by Basile Starynkevitch <basile@starynkevitch.net>

     This file is part of GCC.

     GCC is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation; either version 3, or (at your option)
     any later version.

     GCC is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.

     You should have received a copy of the GNU General Public License
     along with GCC; see the file COPYING3.  If not see
     <http://www.gnu.org/licenses/>.
 ***")

 ;; the copyright notice above apply both to warmelt-genobj.melt and 
 ;; to the generated file  warmelt-genobj*.c


;; This MELT module is GPL compatible since it is GPLv3+ licensed.
(module_is_gpl_compatible "GPLv3+")

 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

 ;;    This file is part of a bootstrapping compiler for the MELT lisp
 ;;    dialect, compiler which should be able to compile itself (into
 ;;    generated C file[s])
 ;;    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


 ;; Notice: the threshold governing the splitting and length of
 ;; generated secondary C files are wired in constants inside the
 ;; compile2obj_procedure function.


 ;;;; value like objects;; value here is meant in the sense of the C or C++
 ;;;; language so can be any thing.
 (defclass class_objvalue
   :super class_generated_c_code
   :fields ( obv_type			;the ctype
	     ))


 ;;; pure values expressions are side-effect free
 (defclass class_objpurevalue
   :super class_objvalue
   :fields ())


 ;; formal arguments in C routines, notably in hooks
 (defclass class_objcformal
   :super class_objpurevalue
   :fields (oformal_name			;the verbatim name
	    oformal_proc			;the containing proc
	    oformal_bind			;the associated formal binding
	    oformal_locv			;the associated stack location
	    ))

 ;; object local variable
 ;;;; disposed local variables can be reused.
 (defclass class_objlocv
   :super class_objpurevalue
   :fields (obl_off			;offset in frame
	    obl_proc			;containing procedure or nil if disposed
	    obl_cname			;symbolic cname string
	    ))


 ;; closed occurrence
 (defclass class_objcloccv
   :super class_objpurevalue
   :fields (obc_off			;offset in closure
	    obc_proc			;containing procedure
	    obc_name			;symbolic name
	    ))


 ;; constant [closed] occurrence
 (defclass class_objconstv
   :super class_objcloccv
   :fields (
	    ))

 ;; hook closed occurrence
 (defclass class_objclohookv
   :super class_objcloccv
   :fields (
	    ))

 ;; fetch a module variable
 (defclass class_objfetchmodvar 
   :super class_objpurevalue
   :fields (obfetchmodvar_bind ;; the normal module variable binding
	    ))

 ;; predefined object
 (defclass class_objpredef
   :super class_objpurevalue
   :fields (obpredef
	    ))

 ;; nil
 (defclass class_objnil
   :super class_objpurevalue
   :fields ())

 ;; expanded pure C value, side-effect-free so could be non-emitted
 (defclass class_objexpandpureval
   :super class_objpurevalue
   :fields (oxpurval_loc			;optional source location
	    oxpurval_comm		;optional comment
	    oxpurval_cont		;expanded content chunk
 ))

 ;; initial element 
 (defclass class_objinitelem
   :super class_objpurevalue
   :fields (oie_cname 			;symbolic cname string - fieldname in cdat
	    oie_data			;normal data
	    oie_discr			;compiled discriminant
	    oie_locvar			;initial routine's local variable
	    ;; the size, if any is the obj_num
	    ))

 ;;; initial object - see MELT_OBJECT_STRUCT in melt-runtime.h
 (defclass class_objinitobject
   :super class_objinitelem
   :fields (
	    oio_predef			;the predef name or number to contain this object
	    oio_class			;the class of the object
	    ))

 ;;; some initial objects, such as existing symbols, should not be
 ;;; recreated if they already exist. Use this class for them.
 (defclass class_objinituniqueobject
   :super class_objinitobject
   :fields (
	    ))


 ;;; initial multiple - see MELT_MULTIPLE_STRUCT in melt-runtime.h
 (defclass class_objinitmultiple
   :super class_objinitelem
   :fields (
	    ;; we may need to tuple of compiled values for accessing
	    ;; the nth at compilation time in compilobj_nrep_multacc
	    oim_tupval			;tuple of compiled values
	    ))

 ;;; initial closure - see MELT_CLOSURE_STRUCT in melt-runtime.h
 (defclass class_objinitclosure 
   :super  class_objinitelem
   :fields (oiclo_rout			;the compiled routine of the
					 ;closure, useful for lambda-s
					 ;in letrec-s
	    ))

 ;;; initial routine - see  MELT_ROUTINE_STRUCT in melt-runtime.h
 (defclass class_objinitroutine
   :super class_objinitelem
   :fields (
	    oir_procroutine		;the associated procroutine
	    ))


 ;;; initial hook - see MELT_HOOK_STRUCT 
 (defclass class_objinithook 
   :super class_objinitelem
   :fields (oihk_prochook		;the associated prochook
	    oihk_data			;the data description
	    oihk_cloval			;the tuple of closed values in the hook
	    oihk_predef 			;the predefined, if any
	    oihk_modvarbind		;the module variable binding if any
	    ))

 ;;; initial string - see MELT_STRING_STRUCT in melt-runtime.h
 (defclass class_objinitstring
   :super class_objinitelem
   :fields (
	    ))

 ;;; initial pair - see struct meltpair_st in melt-runtime.h
 (defclass class_objinitpair
   :super class_objinitelem
   :fields ())

 ;;; initial list - see struct meltlist_st in melt-runtime.h
 (defclass class_objinitlist
   :super class_objinitelem
   :fields ())


 ;;; initial boxed int - see struct meltint_st in melt-runtime.h
 (defclass class_objinitboxinteger
   :super class_objinitelem
   :fields (
	    ))


 ;; expanded value
 (defclass class_objexpv
   :super class_objvalue
   :fields (obx_cont
	    ))

 ;; expanded value with location 
 (defclass class_objlocatedexpv
   :super class_objexpv
   :fields (obcx_loc			;optional location
	    ))


 (defclass class_objflag
   :super class_objpurevalue
   :fields (obflag_matchflag
	    obflag_name
	    obflag_rank
	    ))

 ;;;; instructions
 (defclass class_objinstr
   :super class_generated_c_code
   :fields (obi_loc			;src location
	    ))

 (defclass class_objcommentinstr		;just a comment, useful only for debugging our generator
   :super class_objinstr
   :fields (obci_comment
	    ))

 (defclass class_objchecksignal
   :super class_objinstr
   :fields (
	    ))

 ;;;; instructions with a list of destinations (computes, calls, sends, etc...)
 (defclass class_objdestinstr
   :super class_objinstr
   :fields (obdi_destlist		;a list of destination lovations
	    ))

 ;;; compute instruction
 (defclass class_objcompute
   :super class_objdestinstr
   :fields (obcpt_expr			;expression list or object or tuple
	    obcpt_type			;ctype of expression
	    ))

 (defclass class_objputmodvar
   :super class_objinstr
   :fields (obputmodvar_bind
	    obputmodvar_val))

 ;; get argument instruction
 (defclass class_objgetarg
   :super class_objinstr
   :fields (obarg_obloc			;objlocation
	    obarg_bind			;formal binding
	    ))

 ;; put output argument instruction, usful inside hooks
 (defclass class_objputoutarg
   :super class_objinstr
   :fields (oboutarg_formal			;;formal out argument of class_objcformal
	    ))

 ;; get argument & update rest index in variadic instruction
 (defclass class_objgetargrest
   :super class_objgetarg
   :fields (obarg_rest ;name prefix of rest index, as a string
	    ))


 ;; put extra result instruction
 (defclass class_objputxtraresult
   :super class_objinstr
   :fields (obxres_rank 			;boxed rank
	    obxres_obloc			;objlocation
	    ))

 ;; final return
 (defclass class_objfinalreturn
   :super class_objinstr
   :fields (				;no argument
	    ))

 ;; clear instruction
 (defclass class_objclear
   :super class_objinstr
   :fields (oclr_vloc			;varlocation to clear
	    ))



 ;; block instruction
 (defclass class_objanyblock
   :super class_objinstr
   :fields ( oblo_bodyl			;body list
	     oblo_epil			;epilogue list
	     ))

 (defclass class_objplainblock
   :super class_objanyblock
   :fields (
	    ))



 ;; multi-allocation block instruction, used for letrec compilation
 (defclass class_objmultiallocblock
   :super class_objanyblock
   :fields ( omalblo_allstruct		;the allocated structure is a
					 ;tuple of class_objinitelem
	     omalblo_name		;unique name
 ))

 ;; a block with a comment string appearing in the generated code
 (defclass class_objcommentedblock
   :super class_objanyblock
   :fields ( ocomblo_comment		;the comment string
	     ))


 ;; a block for compiling matches. We need to redistribute put_objdest
 ;; inside appropriately
 (defclass class_objmultiblock
   :super class_objanyblock
   :fields (omulblo_subcomp		;the tuple of subcomponents
					 ;into which redistribute
					 ;destination
	    ))

 ;; a block for compiling new matches with flags
 (defclass class_objmatchflagblock
   :super class_objanyblock
   :fields (omchflgblo_flags 		;the tuple of flags
	    ))

 ;; unique label instr
 (defclass class_objlabelinstr
   :super class_objinstr
   :fields (oblab_prefix			;unique prefix string
	    oblab_rank			;additional rank
	    ))

 ;; unconditional goto label
 (defclass class_objgotoinstr
   :super class_objinstr
   :fields (obgoto_prefix		;unique prefix string
	    obgoto_rank			;additional rank
	    ))

 ;; looping block
 (defclass class_objloop
   :super class_objanyblock		 ;the body is looped, not the epilogue
   :fields (obloop_label		 ;cloned symbol
	    obloop_resv		 ;the result of the loop
	    ))

 ;; exit a loop
 (defclass class_objexit
   :super class_objinstr
   :fields (obexit_label			;cloned symbol for goto destination
	    ))

 ;; start again a loop
 (defclass class_objagain
   :super class_objinstr
   :fields (obagain_label			;cloned symbol for goto destination
	    ))


 ;; citeration block
 (defclass class_objciterblock
   :super class_objanyblock
   :fields (obciter_citer
	    obciter_before
	    obciter_after
	    ))

 ;; conditional instruction
 (defclass class_objcond
   :super class_objinstr
   :fields (obcond_test
	    obcond_then
	    obcond_else
	    ))

 ;; preprocessor conditional instruction
 (defclass class_objcppif
   :super class_objinstr
   :fields (obifp_cond
	    obifp_then
	    obifp_else
	    ))


 ;;; keyword & symbol intern instruction
 (defclass class_objinterncommon
   :super class_objinstr
   :fields (obintern_iobj			;the objinitobject for
					 ;the symbol or keyword
	    ))

 (defclass class_objinternsymbol
   :super class_objinterncommon
   :fields (
	    ))

 (defclass class_objinternkeyword
   :super class_objinterncommon
   :fields (
	    ))

 ;;; keyword & symbol getnamed instruction
 (defclass class_objgetnamedcommon
   :super class_objinstr
   :fields (obgnamed_iobj		;the objinitobject for the
					 ;symbol or keyword
	    ))

 (defclass class_objgetnamedsymbol
   :super class_objgetnamedcommon
   :fields (
	    ))

 (defclass class_objgetnamedkeyword
   :super class_objgetnamedcommon
   :fields (
	    ))

 ;;; apply instruction
 (defclass class_objapply
   :super class_objdestinstr
   :fields (obapp_clos			;closure to be applied
	    obapp_args			;argument tuple
	    ))

 ;;; multiapply instruction
 (defclass class_objmultiapply
   :super class_objapply
   :fields (obmultapp_xres		;extraresult tuple
	    ))

 ;;; message send instruction
 (defclass class_objmsend
   :super class_objdestinstr
   :fields (obmsnd_sel			;selector object (compiled)
	    obmsnd_recv			;message receiver (compiled)
	    obmsnd_args 			;argument tuple (compiled)
	    ))

 ;;; multisend instruction
 (defclass class_objmultimsend
   :super class_objmsend
   :fields (obmultsnd_xres		;extraresult tuple
	    ))

 ;; raw object allocation instruction
 (defclass class_objrawallocobj
   :super class_objdestinstr
   :fields (
	    obrallobj_class		;the class data
	    obrallobj_len		;the boxed integer length
	    obrallobj_classname		;the class name
	    ))

 ;; instruction for debugtracing of written or created objects, for low
 ;; level debug purposes using GDB, see melt_dbgtrace_write_object in
 ;; runtime.
 (defclass class_objdbgtracewriteobj
   :super  class_objinstr
   :fields (obdtw_writtenobj		;the changed object
	    obdtw_message			;the message
	    ))


 ;; new closure allocation
 (defclass class_objnewclosure
   :super class_objdestinstr
   :fields (obnclo_discr		     ;the discriminant
	    obnclo_rout		     ;the routine
	    obnclo_len		     ;the boxed integer length
	    ))

 ;; put a component inside a tuple
 (defclass class_objputuple
   :super class_objinstr
   :fields (oputu_tupled			;the tuple data
	    oputu_offset			;numerical offset
	    oputu_value			;the new value
	    ))


 ;; put inside a pair
 (defclass class_objputpair
   :super class_objinstr
   :fields (oputp_pair 			;the pair to update
	    ))

 (defclass class_objputpairhead
   :super class_objputpair
   :fields (oputp_head			;the head to put
	    ))

 (defclass class_objputpairtail
   :super class_objputpair
   :fields (oputp_tail			;the tail to put
	    ))

 ;; put the first and last inside a list
 (defclass class_objputlist
   :super class_objinstr
   :fields (oputl_list			;the list to update
	    oputl_first			;the first pair
	    oputl_last			;the last pair
	    ))

 ;; put a slot inside an object
 (defclass class_objputslot
   :super class_objinstr
   :fields ( oslot_odata			;the object data to put
	     oslot_offset		;numerical offset
	     oslot_field			;the [optional] field 
	     oslot_value			;the new value
	     ))


 ;; get a slot from an object
 (defclass class_objgetslot
   :super class_objdestinstr
   :fields (ogetsl_obj		   ;the object to get from
	    ogetsl_field		   ;the fieldname
	    ))

 ;; put the routine inside a closure
 (defclass class_objputclosurout
   :super class_objinstr
   :fields (opclor_clos			;the closure data
	    opclor_rout			;the routine data
	    ))

 ;; put a closed value inside a closure
 (defclass class_objputclosedv
   :super class_objinstr
   :fields (opclov_clos			;the closure data or local
	    opclov_off 			;the boxed offset
	    opclov_cval			;the closed value
	    ))

 ;; likewise, but check that the closed value is notnull
 (defclass class_objputclosednotnullv
   :super class_objputclosedv
   :fields (
	    ))

 ;; put a constant value inside a hook
 (defclass class_objputhookconst
   :super class_objinstr
   :fields (ophconst_hook	 ;the hook data
	    ophconst_off		 ;the boxed offset
	    ophconst_cval	 ;the constant value
	    ))

 ;; unsafely retrieve the hook nth "closed" data
 (defclass class_objhooknth
   :super class_objpurevalue
   :fields (ohknth_hook			;the hook
	    ohknth_off			;the boxed offset
	    ))

 ;; put a constant data inside a hook
 (defclass class_objputhookdata
   :super class_objinstr
   :fields (ophkdata_hook	 ;the hook
	    ophkdata_data	 ;the data
	    ))

 ;; put a constant value inside a routine
 (defclass class_objputroutconst
   :super class_objinstr
   :fields (oprconst_rout	 ;the routine data
	    oprconst_off		 ;the boxed offset
	    oprconst_cval	 ;the constant value
	    ))

 ;; likewise, but check that the constant is notnull
 (defclass class_objputroutconstnotnull
   :super class_objputroutconst
   :fields (
	    ))

 ;; touch a value, with a tiny comment
 (defclass class_objtouch
   :super class_objinstr
   :fields (otouch_val
	    otouch_comment
	    ))

 ;; set a predef
 (defclass class_objsetpredef
   :super class_objinstr
   :fields ( ospr_object			;the object 
	     ospr_predef			;its predef rank
	     ))


 ;;; routines
(defclass class_protoroutineobj
  :super class_named
  :fields (oprout_loc 			;source location
	   oprout_filenum		;boxed C file number
	   ))
	   
 (defclass class_routineobj
   :super class_protoroutineobj
   :fields (obrout_proc			;the associated procedure
	    obrout_body			;the body (a list)
	    obrout_nbval			;the boxed number of value pointers
	    obrout_nblong		;the boxed number of longs
	    obrout_others		;the list of other (nonvalue,
					 ;nonlongs) locals (usually C
					 ;pointers like tree-s,
					 ;cstrings, ...)
	    obrout_retval		;the main return value
	    obrout_cntciter		;the boxed counter of citerations
	    obrout_cntletrec		;the boxed counter of letrecs
	    ))

 ;; procedure routine
 (defclass class_procroutineobj
   :super class_routineobj
   :fields (oprout_getargs		;the get arguments tuple of instructions
	    oprout_funam			;function name
	    oprout_restnam		;the name used for variadic arguments, or else null
	    ))


 ;; any initial or hook routine is a start routine
 (defclass class_any_start_routineobj
   :super class_routineobj
   :fields (
	    )
   )

 ;; hook routine
 (defclass class_hookroutineobj
   :super class_any_start_routineobj
   :fields (
	    ohookrout_datarg		;the argument for the data
	    ohookrout_inargs
	    ohookrout_outargs
	    ohookrout_epilog		;list of objinstr after the
					 ;meltlabend_rout label
	    ))

 ;; initial routine common super-class
 (defclass class_initialroutineobj
   :super class_any_start_routineobj
   :fields (
	    oirout_data			;the tuple of initial data
	    oirout_prolog       ;the prologue (list of instr) before filling the data. Imports should go here!
	    oirout_fill			;the fill of the data (a list of instr)
	    oirout_modctx		;the module context
	    ))

 ;; initial routine in modules
 (defclass class_initial_module_routineobj
   :super class_initialroutineobj
   :fields (
	    ))

 ;; initial routine in extensions
 (defclass class_initial_extension_routineobj
   :super class_initialroutineobj
   :fields (
	    ))

 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;; export the above classes
 (export_class				;alphabetical order
  class_any_start_routineobj
  class_hookroutineobj
  class_initial_extension_routineobj
  class_initial_module_routineobj
  class_initialroutineobj
  class_objagain
  class_objanyblock
  class_objapply
  class_objcformal
  class_objchecksignal
  class_objciterblock
  class_objclear
  class_objcloccv 
  class_objclohookv
  class_objcommentedblock
  class_objcommentinstr
  class_objcompute
  class_objcond
  class_objconstv
  class_objcppif
  class_objdbgtracewriteobj
  class_objdestinstr
  class_objexit
  class_objexpandpureval
  class_objexpv
  class_objfetchmodvar
  class_objfinalreturn
  class_objflag
  class_objgetarg
  class_objgetargrest
  class_objgetnamedcommon
  class_objgetnamedkeyword
  class_objgetnamedsymbol
  class_objgetslot
  class_objgotoinstr
  class_objhooknth
  class_objinitboxinteger
  class_objinitclosure
  class_objinitelem
  class_objinithook
  class_objinitlist
  class_objinitmultiple
  class_objinitobject
  class_objinitpair
  class_objinitroutine
  class_objinitstring
  class_objinituniqueobject
  class_objinstr
  class_objinterncommon
  class_objinternkeyword
  class_objinternsymbol
  class_objlabelinstr
  class_objlocatedexpv
  class_objlocv
  class_objloop
  class_objmatchflagblock
  class_objmsend
  class_objmultiallocblock
  class_objmultiapply
  class_objmultiblock
  class_objmultimsend
  class_objnewclosure
  class_objnil
  class_objplainblock
  class_objpredef
  class_objpurevalue
  class_objputclosednotnullv
  class_objputclosedv
  class_objputclosurout
  class_objputhookconst
  class_objputhookdata
  class_objputlist
  class_objputoutarg
  class_objputpair
  class_objputpairhead
  class_objputpairtail
  class_objputmodvar
  class_objputroutconst
  class_objputroutconstnotnull
  class_objputslot
  class_objputuple
  class_objputxtraresult
  class_objrawallocobj
  class_objsetpredef
  class_objtouch
  class_objvalue
  class_procroutineobj
  class_protoroutineobj
  class_routineobj
  )					;end export_class

 (export_synonym class_objblock class_objplainblock)
 (export_synonym class_objcheckinterrupt class_objchecksignal)

 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; variadic function to make an objlocatedexpv out of a macrostring
 (defun make_objlocatedexp (loc cty :rest)
   (debug "make_objlocatedexp loc=" loc " cty=" cty)
   (assert_msg "make_objlocatedexp check loc" (or (null loc)
						  (is_a loc discr_mixed_location)
						  (is_a loc discr_mixed_integer))
	       loc)
   (assert_msg "make_objlocatedexp check cty" (is_a cty class_ctype) cty)
   (let ( (arglist (make_list discr_list)) 
	  )
     (forever 
      argloop
      (variadic ( () 
		  (exit argloop))
		( (:long l)
		  (let ( (bl (make_integerbox discr_constant_integer l))
			 )
		    (list_append arglist bl)))
		( (:cstring s)
		  (let ( (bs (make_stringconst discr_verbatim_string s)) 
			 )
		    (list_append arglist bs)))
		( (:value v)
		  (cond ( (is_list v)
			  (list_append2list arglist v))
			( (is_multiple v)
			  (foreach_in_multiple
			   (v)
			   (curcomp :long ix)
			   (list_append arglist curcomp)))
			( (is_closure v)
			  (v arglist))
			(:else
			 (list_append arglist v))))
		( :else
		  (debug "make_objlocatedexp varargctype=" (variadic_ctype 0))
		  (assert_msg "unexpected variable argument for make_objlocatedexp" () (variadic_ctype 0)))
		))
     (debug "make_objlocatedexp arglist=" arglist)
     (let ( (res
	     (instance  class_objlocatedexpv
			:obv_type cty
			:obx_cont (list_to_multiple arglist discr_multiple)
			:obcx_loc loc))
	    )
       (debug "make_objlocatedexp res=" res)
       (return res)
       )))
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; variadic function to make an objcompute out of a macrostring
 (defun make_objcompute (loc ctyp :rest)
   (debug "make_objcompute loc=" loc)
   (assert_msg "make_objcompute check loc" (or (null loc) (is_a loc discr_mixed_location)) loc)
   (assert_msg "make_objcompute check ctyp" (is_a ctyp class_ctype) ctyp)
   (let ( (arglist (make_list discr_list)) 
	  )
     (forever 
      argloop
      (variadic ( () 
		  (exit argloop))
		( (:long l)
		  (let ( (bl (make_integerbox discr_constant_integer l))
			 )
		    (list_append arglist bl)))
		( (:cstring s)
		  (let ( (bs (make_stringconst discr_verbatim_string s)) 
			 )
		    (list_append arglist bs)))
		( (:value v)
		  (cond ( (is_list v)
			  (list_append2list arglist v))
			( (is_multiple v)
			  (foreach_in_multiple
			   (v)
			   (curcomp :long ix)
			   (list_append arglist curcomp)))
			(:else
			 (list_append arglist v))))
		( :else
		  (debug "make_objcompute varargctype=" (variadic_ctype 0))
		  (assert_msg "unexpected variable argument for make_objcompute" () (variadic_ctype 0)))
		))
     (debug "make_objcompute arglist=" arglist)
     (let ( (res
	     (instance  class_objcompute
			:obdi_destlist (make_list discr_list)
			:obcpt_expr (list_to_multiple arglist discr_multiple)
			:obcpt_type ctyp
			:obi_loc loc))
	    )
       (debug "make_objcompute res=" res)
       (return res)
       )))


 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; variadic function to make an objexpandpureval out of a macrostring
 (defun make_objexpandpureval (loc ctyp comm :rest)
   (debug "make_objexpandpureval loc=" loc " ctyp=" ctyp " comm=" comm)
   (assert_msg "make_objexpandpureval check loc" (or (null loc) (is_a loc discr_mixed_location)) loc)
   (assert_msg "make_objexpandpureval check ctyp" (is_a ctyp class_ctype) ctyp)
   (assert_msg "make_objexpandpureval check comm" (or (null comm) (is_string comm)) comm)
   (when (== ctyp ctype_void)
       (warning_plain loc "bizarre :void ctype for pure expanded cvalue")
       (shortbacktrace_dbg "make_objexpandpureval void" 15))
   (let ( (arglist (make_list discr_list)) 
	  )
     (forever 
      argloop
      (variadic ( () 
		  (exit argloop))
		( (:long l)
		  (let ( (bl (make_integerbox discr_constant_integer l))
			 )
		    (list_append arglist bl)))
		( (:cstring s)
		  (let ( (bs (make_stringconst discr_verbatim_string s)) 
			 )
		    (list_append arglist bs)))
		( (:value v)
		  (cond ( (is_list v)
			  (list_append2list arglist v))
			( (is_multiple v)
			  (foreach_in_multiple
			   (v)
			   (curcomp :long ix)
			   (list_append arglist curcomp)))
			(:else
			 (list_append arglist v))))
		( :else
		  (debug "make_objexpandpureval varargctype=" (variadic_ctype 0))
		  (assert_msg "unexpected variable argument for make_objexpandpureval" ()))
		))
     (debug "make_objexpandpureval arglist=" arglist)
     (let ( (res
	     (instance  class_objexpandpureval
			:obv_type ctyp
			:oxpurval_loc loc
			:oxpurval_comm comm
			:oxpurval_cont (list_to_multiple arglist discr_multiple)))
	    )
       (debug "make_objexpandpureval res=" res)
       (return res)
       )))


 ;;;; selector to generate the declaration of an initial
 ;;; receiver some objinielem
 ;;; argument strbuf
 (defselector output_c_declinit class_selector
   :doc #{$OUTPUT_C_DECLINIT is the selector to generate the
 declaration of some initial element $RECV into the string-buffer
 $SBUF.}#
   :formals (recv sbuf)
   )
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;; selector to put a destination into an objcode
 ;;; receiver: the objcode
 ;;; argument: the destination value
 ;;; result: the (modified) receiving objcode or its replacement
 (defselector put_objdest class_selector
   )

 ;;; selector to generate the c code for an object
 ;;; receiver: the object to output
 ;;; arguments: 
 ;;;; * DECLBUF the stringbuffer for the declarations
 ;;;; * IMPLBUF the stringbuffer for implementations
 ;;;; * DEPTH an unboxed integer for indentation...
 ;;; result is not used

 (defselector output_c_code class_selector
   :doc #{$OUTPUT_C_CODE is the selector to generate C code. $RECV is
   the receiver, $DECLBUF is the string-buffer for declarations,
   $IMPLBUF is the string-buffer for implementations, $DEPTH is the raw
   integer depth.}#
   :formals (recv declbuf implbuf :long depth)
   )

 ;;;; selector to generate the initial fill of some objinit
 ;;; receiver some objinitelem
 ;;; argument a stringbuffer
 (defselector output_c_initial_fill class_selector
   :doc #{$OUTPUT_C_INITIAL_FILL is the selector to generate the filling of
   some initalized object $RECV. $IMPLBUF is the string-buffer for
   implementations, $PTRSTR is the string value of the pointer to fill,
   and $DEPTH is the raw integer depth.}#
   :formals (recv implbuf ptrstr :long depth)
 )

 ;;;; selector to generate the predef fill of some objinit
 ;;; receiver some objinitelem
 ;;; argument a stringbuffer
 (defselector output_c_initial_predef class_selector
   :formals (recv sbuf prtrstr :long depth)
   )

 (export_values
  make_objexpandpureval 
  output_c_code
  output_c_declinit
  output_c_initial_fill
  output_c_initial_predef 
  put_objdest
  )

 ;; a catchall method for nrep-s (normal representations) each should
 ;; be separately compiled with its own method so this should never be
 ;; called
 (defun compilobj_catchall_nrep (recv gcx)
   (debug "compilobj_catchall_nrep recv=" recv " gcx=" gcx)
   (let ( (discr (discrim recv)) 
	  (discrname  (unsafe_get_field :named_name discr))
	  )
     (debug "compilobj_catchall_nrep discr=" discr)
     (errormsg_strv "{Internal Error} COMPILE_OBJ sent to unexpected object of class" discrname)
     (assert_msg "@@compile_obj should be implemented in nrep-s subclasses" () recv)
 ))
 (install_method class_nrep compile_obj compilobj_catchall_nrep)

 (defun putobjdest_catchall_objcode (recv desto)
   (debug "putobjdest_catchall_objcode recv=" recv " desto=" desto)
   (let ( (discr (discrim recv)) 
	  (discrname  (unsafe_get_field :named_name discr))
	  )
     (error_at () "PUT_OBJDEST sent to unexpected C-generated object $1 of class $2 for destination $3." 
	       recv discrname desto)
     (assert_msg "@@put_objdest should be implemented in generated c code subclasses" () recv discr)
     ))
 (install_method class_generated_c_code put_objdest putobjdest_catchall_objcode)


(defun putobjdest_catch_objputmodvar (recv desto)
  (debug "putobjdest_catch_objputmodvar recv=" recv " desto=" desto)
  (assert_msg "check recv" (is_a recv class_objputmodvar) recv desto)
  (let ( (loc (get_field :obi_loc recv))
	 (obind (get_field :obputmodvar_bind recv))
	 (bindsymb (get_field :binder obind))
	 )
    (error_at loc "assignment of a module variable $1 don't have any result" bindsymb)
    (assert_msg "@@put_objdest on objputmodvar" () recv desto)
    (return)))
(install_method class_objputmodvar put_objdest putobjdest_catch_objputmodvar)

 (defun putobjdest_catchall_anydiscr (recv desto)
   (debug "putobjdest_catchall_anydiscr recv=" recv " desto=" desto)
   (outcstring_err "* putobjdest unimplemented receiver discriminant ")
   (let ( (discr (discrim recv)) 
	  (discrname  (unsafe_get_field :named_name discr))
	  )
     (error_at () "PUT_OBJDEST sent to unexpected reciever $1 of discriminant $2 for destination $3." 
	       recv discr desto)
   (assert_msg "@@ unexpected catchall putobjdest anydiscr" () recv)))
 (install_method discr_any_receiver put_objdest putobjdest_catchall_anydiscr)


 (defun getctype_objvalue (recv env)
   (assert_msg "check recv objvalue" (is_a recv class_objvalue) recv)
   (unsafe_get_field :obv_type recv))
 (install_method class_objvalue get_ctype getctype_objvalue)





 ;; nil are ctype_value
 (defun gectyp_objnil (recv env)  
   ctype_value)
 (install_method class_objnil get_ctype gectyp_objnil)


 ;; initstring-s are ctype_value
 (defun gectyp_objinitstring (recv env)
   (return ctype_value))
 (install_method class_objinitstring get_ctype gectyp_objinitstring)

 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;; in the debug output routineobj-s make huge output, so print the detail only when at toplevel
 (defun dbgout_routineobj (self dbgi :long depth)
   (if (<=i depth 0)
       (dbgout_namedobject_method self dbgi 0)
     (dbgout_namedobject_method self dbgi 30))
   )
 (install_method class_routineobj dbg_output dbgout_routineobj)

 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; common put destination of objdestinstr....
 (defun putobjdest_objdestinstr (recv desto)
   (assert_msg "putobjdest_objdestinstr check recv" (is_a recv class_objdestinstr) recv)
   (debug "putobjdest_objdestinstr recv=" recv " desto=" desto)
   (let ( (destl (unsafe_get_field :obdi_destlist recv)) )
     (if (not (is_list destl))
	 (progn 
	   (setq destl (make_list discr_list))
	   (unsafe_put_fields recv :obdi_destlist destl)))
     (let ( (firstd (pair_head (list_first destl))) )
       (if (== firstd desto)
	   (return recv)
	 (progn
	   (list_append destl desto)
	   (return recv)
	   )))))
 (install_method class_objdestinstr put_objdest putobjdest_objdestinstr)

 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;; notes about code generation
 ;;;
 ;;; in addition of the code structure generated by cold-melt we
 ;;; need to be able to import values (hence bindings) from a start
 ;;; environment which is the only argument given to the generated
 ;;; start routine of the module


 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;







 ;; for some reason, final returns are sometimes putobjdest-ed - a NOP here
 (defun putobjdest_objfinalreturn (recv desto)
   (assert_msg "check recv" (is_a recv class_objfinalreturn) recv)
   recv
   )
 (install_method class_objfinalreturn put_objdest putobjdest_objfinalreturn)

 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;; produce the verbatim string for of a variadic symbol with a given suffix
 (defun variadic_idstr (variadsym :cstring suffix)
   (match variadsym
	  (?(as_null)
	    (return ()))
	  (?(instance class_cloned_symbol
		      :named_name ?nvarnam
		      :csym_urank ?(integerbox_of ?nvarurank))
	    (assert_msg "check nvarnam" (is_string nvarnam) nvarnam)
	    (let ( (sbuf (make_strbuf discr_strbuf))
		   )
	      (add2sbuf_strconst sbuf "variad_")
	      (add2sbuf_cident sbuf nvarnam)
	      (add2sbuf_strconst sbuf "_c")
	      (add2sbuf_longdec sbuf nvarurank)
	      (add2sbuf_strconst sbuf suffix)
	      (strbuf2string discr_verbatim_string sbuf)
	      ))
	  (?(instance class_symbol
		      :named_name ?nvarnam)
	    (assert_msg "check nvarnam" (is_string nvarnam) nvarnam)
	    (let ( (sbuf (make_strbuf discr_strbuf))
		   )
	      (add2sbuf_strconst sbuf "variad_")
	      (add2sbuf_cident sbuf nvarnam)
	      (add2sbuf_strconst sbuf suffix)
	      (strbuf2string discr_verbatim_string sbuf)
	      ))
	  (?_
	   (debug "variadic_idstr bad variadsym=" variadsym)
	   (assert_msg "variadic_idstr bad variadsym" () variadsym)
	   ())))

 (defun variadic_index_idstr (variadsym)
   :doc #{Gives the verbatim string representing the index for variadic $VARIADSYM or else null.}# 
   (variadic_idstr variadsym "_ix"))

 (defun variadic_length_idstr (variadsym)
   :doc #{Gives the verbatim string representing the length for variadic $VARIADSYM or else null.}# 
   (variadic_idstr variadsym "_len"))




 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; compile a single hook
 (defun compile2obj_hook (nhook modctx compicache :long num)
   (debug "compile2obj_hook nhook=" nhook "\n.. modctx=" modctx
	  "\n.. compicache=" compicache "\n.. num=" num
	  "\n.. class_hookroutineobj=" class_hookroutineobj)
   (assert_msg "check nhook" (is_a nhook class_nrep_hookproc) nhook)
   (assert_msg "check compicache" (is_mapobject compicache) compicache)
   (assert_msg "check modctx" (is_a modctx class_any_module_context) modctx)
   (let (
	 (loc (get_field :nrep_loc nhook))
	 (nbody (get_field :nproc_body nhook))
	 (nhookname (get_field :nrclop_name nhook))
	 (hookroutname (let (
			     (namsbuf (make_strbuf discr_strbuf)) 
			     )
			 (add2sbuf_strconst namsbuf "melthook_")
			 (add2sbuf_cident namsbuf nhookname)
			 (strbuf2string discr_verbatim_string namsbuf)
			 ))
	 (ninbinds (get_field :nrclop_argbindtuple nhook))
	 (noutbinds (get_field :nrhook_outb nhook))
	 (resctype (get_field :nrhook_ctype nhook))
	 (ndatahook (get_field :nrhook_datahook nhook))
	 (nclosvtup (get_field :ndhook_closv ndatahook))
	 (obodylist (make_list discr_list))
	 (oepiloglist (make_list discr_list))
	 (oinargs (make_multiple discr_multiple (multiple_length ninbinds)))
	 (ooutargs (make_multiple discr_multiple (multiple_length noutbinds)))
	 (odatarg (instance class_objcformal
			    :obv_type ctype_value
			    :oformal_name '"melthookdatap"
			    :oformal_proc nhook
			    :oformal_bind ()
			    :oformal_locv ()
			    ))
	 (hookrout (instance class_hookroutineobj
			     :named_name hookroutname
			     :obrout_proc nhook
			     :obrout_body obodylist
			     :obrout_nbval (make_integerbox discr_integer 0)
			     :obrout_nblong (make_integerbox discr_integer 0)
			     :obrout_others (make_list discr_list)
			     :obrout_cntciter (make_integerbox discr_integer 0)
			     :obrout_cntletrec (make_integerbox discr_integer 0)
			     :ohookrout_datarg odatarg
			     :ohookrout_inargs oinargs
			     :ohookrout_outargs ooutargs
			     :ohookrout_epilog oepiloglist
			     ))
	 (locmap (make_mapobject discr_map_objects 
				 (+i 30 (*i 3 (+i (multiple_length ninbinds)
						  (multiple_length noutbinds))))))
	 (gcx (instance class_c_generation_context
			:gncx_objrout hookrout
			:gncx_locmap locmap
			:gncx_freeptrlist (make_list discr_list)
			:gncx_freelonglist (make_list discr_list)
			:gncx_freeothermaps (make_mapobject discr_map_objects 20)
			:gncx_compicache compicache
			:gncx_modulcontext modctx
			:gncx_matchmap (make_mapobject discr_map_objects 40)
			))
	 )
     (debug "compile2obj_hook " nhookname " empty hookrout=" hookrout 
	    "\n nclosvtup=" nclosvtup)
     (debug "compile2obj_hook " nhookname " resctype=" resctype "\n.. gcx=" gcx)
     (assert_msg "check resctype" (is_a resctype class_ctype) resctype)
     (let ( (retloc (get_free_objloctyped gcx '_reshook_ resctype))
	    (hdataloc (get_free_objloctyped gcx '_hookdata_ ctype_value))
	    (ogetdata (make_objcompute loc ctype_value 
				       ##{/*hookgetdata*/ $ODATARG}#))
	    )
       (put_fields gcx :gncx_retloc retloc)
       (put_fields odatarg :oformal_locv hdataloc)
       (put_objdest ogetdata hdataloc)
       (list_append obodylist ogetdata)
       ;; handle the input arguments
       (debug "compile2obj_hook " nhookname " ninbinds=" ninbinds)
       (foreach_in_multiple
	(ninbinds)
	(curinbnd :long inix)
	(debug "compile2obj_hook " nhookname " curinbnd=" curinbnd "\n .. inix=" inix)
	(assert_msg "check curinbnd" (is_a curinbnd class_formal_binding) curinbnd)
	(let ( (syminb (get_field :binder curinbnd))
	       (ctypinb (get_field :fbind_type curinbnd))
	       (locinb (get_free_objloctyped gcx syminb ctypinb))
	       (incname (let ( (sbuf (make_strbuf discr_strbuf))
			       )
			  (add2out sbuf "meltinp" inix "_" (symbol_cname syminb))
			  (strbuf2string discr_verbatim_string sbuf)))
	       (incformal (instance class_objcformal
				    :obv_type ctypinb
				    :oformal_name incname
				    :oformal_proc nhook
				    :oformal_bind curinbnd
				    :oformal_locv locinb))
	       (ogetfarg (make_objcompute loc ctypinb
					  ##{/*gethookinput*/ $INCFORMAL}#))
	       )
	  (put_int incformal inix)
	  (put_objdest ogetfarg locinb)
	  (list_append obodylist ogetfarg)
	  (debug "compile2obj_hook " nhookname " incformal=" incformal "\n.. ogetfarg=" ogetfarg)
	  (multiple_put_nth oinargs inix incformal)
	  (mapobject_put locmap curinbnd locinb)
	  ))
       (debug "compile2obj_hook " nhookname " oinargs=" oinargs "\n.. locmap=" locmap)
       ;;
       ;; handle the output arguments
       (debug "compile2obj_hook " nhookname " noutbinds=" noutbinds)
       (foreach_in_multiple
	(noutbinds)
	(curoutbnd :long outix)
	(debug "compile2obj_hook " nhookname " curoutbnd=" curoutbnd "\n .. outix=" outix)
	(assert_msg "check curoutbnd" (is_a curoutbnd class_formal_binding) curoutbnd)
	(let ( (symoutb (get_field :binder curoutbnd))
	       (ctypoutb (get_field :fbind_type curoutbnd))
	       (locoutb (get_free_objloctyped gcx symoutb ctypoutb))
	       (outcname (let ( (sbuf (make_strbuf discr_strbuf))
				)
			   (add2out sbuf "meltoutp" outix "_" (symbol_cname symoutb))
			   (strbuf2string discr_verbatim_string sbuf)))
	       (outcformal (instance class_objcformal
				     :obv_type ctypoutb
				     :oformal_name outcname
				     :oformal_proc nhook
				     :oformal_bind curoutbnd
				     :oformal_locv locoutb))
	       )
	  (put_int outcformal outix)
	  (debug "compile2obj_hook " nhookname " outcformal=" outcformal)
	  (multiple_put_nth ooutargs outix outcformal)
	  (mapobject_put locmap curoutbnd locoutb)
	  )
	)
       ;;
       (debug "compile2obj_hook " nhookname " here obodylist=" obodylist)
       (debug "compile2obj_hook " nhookname " ooutargs=" ooutargs 
	      "\n.. nbody=" nbody "\n..locmap=" locmap)
       ;; associate the hook with its routine in the compiler cache
       (mapobject_put compicache nhook hookrout)
       (debug "compile2obj_hook " nhookname " updated compicache=" compicache
	      "\n.. for nhook=" nhook "\n.. hookrout=" hookrout)
       (shortbacktrace_dbg "compile2obj_hook updated compicache" 15)
       ;;
       ;; associate each closedvalue with its retrieval in the compicache
       (debug "compile2obj_hook " nhookname " handling closvtup=" nclosvtup "\n")
       (foreach_in_multiple
	(nclosvtup)
	(nclosv :long clix)
	(debug "compile2obj_hook " nhookname " clix#" clix " nclosv=" nclosv)
	(let ( (ofetchcdata (instance class_objhooknth
				      :obv_type ctype_value
				      :ohknth_hook hdataloc
				      :ohknth_off (constant_box clix)))
	       )
	  (debug "compile2obj_hook " nhookname " ofetchcdata=" ofetchcdata "\n.. for nclosv=" nclosv)
	  (mapobject_put compicache nclosv ofetchcdata)
	  (debug "compile2obj_hook" " updated compicache=" compicache
		 "\n.. for nclosv=" nclosv
		 "\n.. with ofetchcdata=" ofetchcdata)
	  )
	)
       (debug "compile2obj_hook " nhookname " again updated compicache=" compicache
	      "\n.. obodylist=" obodylist "\n")
	 )
       ;;
       ;; compile the body
       (debug "compile2obj_hook " nhookname " beforebody obodylist=" obodylist)
       (debug "compile2obj_hook " nhookname " gcx=" gcx "\n.. nbody=" nbody)
       (let ( (obody (compile_obj nbody gcx))
	      )
	 (debug "compile2obj_hook " nhookname " obody=" obody)
	 (list_append obodylist obody)
	 ;; forget the closed data
       (foreach_in_multiple
	(nclosvtup)
	(closv :long clix)
	(debug "compile2obj_hook " nhookname " forgetting closv=" closv)
	(mapobject_remove compicache closv)
	 )
	 (debug "compile2obj_hook " nhookname " after forgethookdata compicache=" compicache)
	 (debug "compile2obj_hook " nhookname " final obodylist=" obodylist "\n")
	 ;;
	 ;; set the output parameters in the epilog
	 (foreach_in_multiple
	  (ooutargs)
	  (curout :long outix)
	  (debug "compile2obj_hook " nhookname " curout=" curout "\n... outix=" outix)
	  (let (
		(outloc (get_field :oformal_locv curout))
		(ctypoutb (get_field :obv_type curout))
		(ofargout (instance class_objputoutarg
				    :obi_loc loc
				    :oboutarg_formal curout))
		)
	    (debug "compile2obj_hook " nhookname " ofargout=" ofargout)
	    (list_append oepiloglist ofargout)
	    ))
	 ;;
	 (debug "compile2obj_hook " nhookname "oepiloglist=" oepiloglist)
	 (debug "compile2obj_hook " nhookname " return hookrout=" hookrout)
	 (return hookrout))))



 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; compile a single procedure
 (defun compile2obj_procedure (pro modctx compicache :long num)
   (debug "compile2obj_procedure pro=" pro "\n.. num=" num
	  "\n..start compicache=" compicache
	  "\n\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n")
   (assert_msg "check pro" (is_a pro class_nrep_routproc) pro)
   (assert_msg "check compicache" (is_mapobject compicache) compicache)
   (assert_msg "check modctx" (is_a modctx class_any_module_context) modctx)
   (shortbacktrace_dbg "compile2obj_procedure" 14)
   (let ( (namsbuf (make_strbuf discr_strbuf)) 
	  (routfunam ())
	  (restnam ())
	  (mofuncount  (get_field :mocx_funcount modctx))
	  (mofiles (get_field :mocx_filetuple modctx))
	  (:long funum (+i 1 (get_int mofuncount)))
	  )
     (if (is_a pro class_nrep_defunroutproc)
	 (put_int mofuncount funum))
     (add2sbuf_strconst namsbuf "meltrout_")
     (add2sbuf_longdec namsbuf num)
     (add2sbuf_strconst namsbuf "_")
     (add2sbuf_cident namsbuf (get_field :mocx_modulename modctx))
     (if (is_a pro class_nrep_routproc)
	 (let ( (pronam (get_field :nrclop_name pro)) 
		(nvariadic (unsafe_get_field :nrpro_variadic pro))
		)
	   (cond ( (is_a pronam class_symbol)
		   (setq routfunam (symbol_cname pronam))
		   (add2out namsbuf "_" routfunam))
		 ( (is_a pronam class_named)
		   (let ( (nambuf (make_strbuf discr_strbuf))
			  )
		     (add2sbuf_strconst nambuf "_")
		     (add2sbuf_cident nambuf
				      (unsafe_get_field :named_name pronam))
		     (setq routfunam (strbuf2string discr_verbatim_string
						    nambuf))
		     (add2out namsbuf "_nm" routfunam)))
		 ( (is_string pronam)
		   (add2sbuf_cident namsbuf pronam)))	  
	   (if nvariadic 
	       (setq restnam nvariadic))
	   ))
     (let ( 
	   (nbody (unsafe_get_field :nproc_body pro))
	   (nloc (unsafe_get_field :nrep_loc pro))
	   (nargb (if (is_a pro class_nrep_routproc) (get_field :nrclop_argbindtuple pro)))
	   (obodylist (make_list discr_list))
	   ;; the number 20 below is the ratio of number of functions
	   ;; per secondary generated C file. Change it carefully!  the
	   ;; offset 12 helps to make the first file less big, since it
	   ;; already contains the huge initialization functions. 
	   (:long filenum (/iraw (+i funum 12) 20))
	   (:long nbfiles (multiple_length mofiles))
	   (obrout (instance class_procroutineobj
			     :named_name (strbuf2string discr_string namsbuf)
			     :obrout_proc pro
			     :obrout_body obodylist
			     :obrout_nbval (make_integerbox discr_integer 0)
			     :obrout_nblong (make_integerbox discr_integer 0)
			     :obrout_others (make_list discr_list)
			     :obrout_cntciter (make_integerbox discr_integer 0)
			     :obrout_cntletrec (make_integerbox discr_integer 0)
			     :oprout_loc nloc
			     :oprout_funam routfunam
			     :oprout_filenum (make_integerbox discr_constant_integer filenum)
			     :oprout_restnam restnam
			     )) 
	   (locmap (make_mapobject discr_map_objects (+i 20 (*i 3 (multiple_length nargb)))))
	   (gcx (let ( (gx (instance class_c_generation_context
				     :gncx_objrout obrout
				     :gncx_locmap locmap
				     :gncx_freeptrlist (make_list discr_list)
				     :gncx_freelonglist (make_list discr_list)
				     :gncx_freeothermaps (make_mapobject discr_map_objects 20)
				     :gncx_compicache compicache
				     :gncx_modulcontext modctx
				     :gncx_matchmap (make_mapobject discr_map_objects 40)
				     ))
		       )
		  (debug "compile2obj_procedure gcx=" gx "\n.. pro=" pro)
		  gx))
	   (retloc 
	    (let ( (retl (get_free_objlocptr gcx '_retval_)) )
	      (unsafe_put_fields gcx :gncx_retloc retl)
	      retl))
	   (gtatup 
	    (multiple_map 
	     nargb
	     (lambda (bnd :long ix)
	       (assert_msg "check bnd" (is_a bnd class_formal_binding) bnd)
	       (let ( (bctyp (unsafe_get_field :fbind_type bnd)) 
		      (bnam (unsafe_get_field :binder bnd))
		      (oloc 
		       (cond ( (== bctyp ctype_value)
			       (get_free_objlocptr gcx bnam) )
			     ( (== bctyp ctype_long)
			       (get_free_objloclong gcx bnam) )
			     (:else
			      (get_free_objloctyped gcx bnam bctyp)))
		       ) 
		      (ogarg
		       (if restnam
			   (instance class_objgetargrest
				     :obi_loc nloc
				     :obarg_obloc oloc
				     :obarg_bind bnd
				     :obarg_rest restnam)
			 (instance class_objgetarg
				   :obi_loc nloc
				   :obarg_obloc oloc
				   :obarg_bind bnd)))
		      )
		 (if (and (<=i ix 0) (!= bctyp ctype_value))
		     (error_plain nloc "first argument of function should be a value"))
		 (debug "compile2obj_procedure formal bnd=" bnd " oloc=" oloc)
		 (mapobject_put locmap bnd oloc)
		 ogarg
		 ))
	     ))
	   )
 ;;; grow the file tuple if needed
       (if (>=i filenum nbfiles)
	   (let ( (:long newnbfiles (+i nbfiles (+i 2 (/iraw filenum 4))))
		  (newfiletup (make_multiple discr_multiple newnbfiles))
		  )
	     (put_fields modctx :mocx_filetuple newfiletup)
	     (foreach_in_multiple 
	      (mofiles)
	      (curfile :long curix)
	      (multiple_put_nth newfiletup curix curfile))
	     ))
       ;; associate the procedure with its objroutine in the compiler cache
       (mapobject_put compicache pro obrout)
       (put_fields obrout :oprout_getargs gtatup)
       (debug "compile2obj_procedure updated compicache=" compicache
	      "\n.. pro=" pro
	      "\n.. obrout=" obrout ".. nbody=" nbody)
       (shortbacktrace_dbg "compile2obj_procedure updated compicache" 15)
       (assert_msg "check nbody" (is_a nbody class_nrep) nbody)
       (if (is_a pro class_nrep_routproc)
	   (let ( (pthuls (unsafe_get_field :nrpro_thunklist pro)) )
	     (debug "compile2obj_procedure pthuls=" pthuls)
	     (foreach_pair_component_in_list
	      (pthuls)
	      (pthupair pthu) 
	      (debug "compile2obj_procedure pthu=" pthu)
	      (assert_msg "compile2obj_procedure check pthu" (is_closure pthu) pthu)
	      (pthu gcx)
	      (debug "compile2obj_procedure after pthu=" pthu "\n.. compicache=" compicache)
	      )
	     ))
       (let ( (obody (compile_obj nbody gcx)) 
	      )
	 (debug "compile2obj_procedure obody=" obody)
	 (list_append obodylist obody)
	 )
       (debug "compile2obj_procedure return obrout=" obrout)
       (return obrout)
       )))



 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;  the initial routine uses the initial system data ...
 (definstance initialsystemdata_objpredef class_objpredef
   :obv_type ctype_value
   :obpredef 'INITIAL_SYSTEM_DATA
   )

 (defun append_comment (ilist comstr iloc)
   (list_append ilist (instance class_objcommentinstr :obi_loc iloc :obci_comment comstr)))
 (defun append_commentconst (ilist :cstring comment :value iloc)
   (list_append ilist (instance class_objcommentinstr :obi_loc iloc :obci_comment (make_stringconst discr_string comment))))



 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;; compile the initial procedure into an object
(defun compile2obj_initproc (ipro modctx idata compicache procurmodenvlist)
   (debug "compile2obj_initproc ipro=" ipro 
	  "\n* modctx=" modctx "\n* compicache=" compicache
	  "\n* procurmodenvlist=" procurmodenvlist 
	  "\n\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n"
	  )
   (shortbacktrace_dbg "compile2obj_initproc" 15)
   (assert_msg "check ipro" (is_a ipro class_nrep_initproc) ipro)
   (assert_msg "check idata" (is_list idata) idata)
   (assert_msg "check modctx" (is_a modctx class_any_module_context) modctx)
   (assert_msg "check compicache" (is_mapobject compicache) compicache)
   (let ((locmap (make_mapobject discr_map_objects 50))
	 (importvalues (get_field :ninit_imports ipro))
	 (importexprs (get_field :ninit_importexprs ipro))
	 (oiniprolog (make_list discr_list))
	 (oinibody (make_list discr_list))
	 (modinienv (get_field :mocx_initialenv modctx))
	 (modnam  (get_field :mocx_modulename modctx))
	 (rawmodnam (clone_with_discriminant modnam discr_verbatim_string))
	 (listrestrout (make_list discr_list))
	 (oinitrout
	  (let ( (oi
		  (instance class_initial_module_routineobj
			    ;; Change the "melt_start_this_module" name with
			    ;; great care, it is known by the MELT runtime, and
			    ;; some functions of warmelt-outobj.melt are
			    ;; hardwiring it, e.g. thru emission of struct
			    ;; frame_melt_start_this_module_st or elsewhere.
			    :named_name '"melt_start_this_module"
			    :obrout_proc ipro
			    :obrout_body oinibody
			    :obrout_nbval (make_integerbox discr_integer 0)
			    :obrout_nblong (make_integerbox discr_integer 0)
			    :obrout_others (make_list discr_list)
			    :obrout_cntciter (make_integerbox discr_integer 0)
			    :obrout_cntletrec (make_integerbox discr_integer 0)
			    :oirout_fill (make_list discr_list)
			    :oirout_prolog oiniprolog
			    :oirout_modctx modctx
			    )) )
	    (debug "compile2obj_initproc oinitrout=" oi)
	    oi))
	 (importmap (make_mapobject discr_map_objects 50))
	 (gcx
	  (let ( (gx (instance 
		      class_initial_generation_context
		      :gncx_objrout oinitrout
		      :gncx_locmap locmap
		      :gncx_freeptrlist (make_list discr_list)
		      :gncx_freelonglist (make_list discr_list)
		      :gncx_freeothermaps (make_mapobject discr_map_objects 20)
		      :gncx_compicache compicache
		      :gncx_modulcontext modctx
		      :gncx_matchmap (make_mapobject discr_map_objects 60)
		      :igncx_procurmodenvlist
		      (list_map 
		       procurmodenvlist
		       (lambda (curpro)
			 (debug "compile2obj_initproc procurmodenvlist curpro=" curpro)
			 (let ( (curou (mapobject_get compicache curpro)) )
			   (debug "compile2obj_initproc procurmodenvlist curou=" curou)
			   (assert_msg "check curou" (is_object curou) curou)
			   curou)))
		      ;; perhaps we should store not a list of procedures, but their matching routines
		      :igncx_importmap importmap
		      ))
		 )
	    (debug "compile2obj_initproc gcx=" gx)
	    gx))
	 (retinit 
	  (let ( (reti (get_free_objlocptr gcx '_retinit_)) )
	    (unsafe_put_fields gcx :gncx_retloc reti)
	    (unsafe_put_fields oinitrout :obrout_retval reti)
	    reti))
	 (boxloc
	  (let ( (boxl (get_free_objlocptr gcx '_contenv_)) )
	    (put_fields gcx :igncx_contenvloc boxl)
	    boxl))
	 (ofreshenv  (get_free_objlocptr gcx '_freshenv_))
	 (oprevenv  (let ( (preve (get_free_objlocptr gcx '_prevenv_))
			   )
		      (put_fields gcx :igncx_prevenvloc preve)
		      preve))
	 (inidefbinds (get_field :ninit_defbinds ipro))
	 )
     (append_commentconst oinibody "start of oinibody")
     (debug boxloc "compile2obj_initproc boxloc=" boxloc " inidefbinds=" inidefbinds)
;;; reserve location for defined values
     (foreach_pair_component_in_list
      (inidefbinds)
      (curpair curdefbind)
      (debug "compile2obj_initproc curdefbind=" curdefbind
	     " of discrim=" (discrim curdefbind))
      (let ( (inidefsymb (get_field :binder curdefbind))
	     (oinisym (get_field :fixbind_data curdefbind))
	     (oinidefloc (get_free_objlocptr gcx inidefsymb))
	     )
	(debug "compile2obj_initproc oinidefloc=" oinidefloc " oinisym=" oinisym
	       " of discrim:" (discrim oinisym)
	       " curdefbind=" curdefbind)
	;;oinisym is often a class_nrep_locsymocc but can be a
	;;class_nrep_defined_constant
	(assert_msg "check oinisym" (is_a oinisym class_nrep_simple) oinisym)
	(mapobject_put locmap curdefbind oinidefloc)
	))
     (debug "compile2obj_initproc" " importvalues=" importvalues)
     ;; create a commentedblock to compute the new environemnt box in boxloc if it is null 
     (let (
	   ;; cond to test boxloc & call the hook_fresh_environment_reference_maker if it if null

	   (otestcomputboxloc 
	    (instance
	     class_objcond
	     :obcond_test boxloc
	     :obcond_then ()
	     :obcond_else
	     (make_objcompute
	      ()
	      ctype_void
	      ##{ /* compile2obj_initproc emitted initialization of environment reference for $RAWMODNAM */
	      if ($OPREVENV) 
	        {
	          $BOXLOC = melthookproc_HOOK_FRESH_ENVIRONMENT_REFERENCE_MAKER 
	                         ((melt_ptr_t) $OPREVENV, "$RAWMODNAM") ;
	        }
	      else /* no prevenv */
	        {
#if MELT_HAS_INITIAL_ENVIRONMENT>0
	      if (!melt_flag_bootstrapping)
	        warning(0, "MELT is not creating a fresh environment reference for $RAWMODNAM without parent env.") ;
#endif /* MELT_HAS_INITIAL_ENVIRONMENT>0 */
	      }
	      }#
	      )))
	   ;;
	   (limplocv
	    (list_map 
	     importvalues
	     (lambda (ival)
	       (debug "compile2obj_initproc imported ival=" ival)
	       (assert_msg "check ival" (is_a ival class_nrep_importedval) ival)
	       (let ( (isym (unsafe_get_field :nimport_symb ival)) 
		      (ilocv (get_free_objlocptr gcx isym))
		      )
		 (debug "compile2obj_initproc imported ilocv=" ilocv)
		 (mapobject_put importmap isym ilocv)
		 ilocv
		 ))))
	   )
       (debug "compile2obj_initproc otestcomputboxloc=" otestcomputboxloc 
	      "\n.. importvalues=" importvalues
	      "\n.. limplocv=" limplocv)
       ;; the prologue starts by getting the previous environment from the
       ;; modargp_ unique argument
       (let ( (lisdest (make_list discr_list)) )
	 (list_append lisdest oprevenv)
	 (append_commentconst oiniprolog "get previous environment")
	 (list_append oiniprolog
		      (instance class_objcompute
				:obdi_destlist lisdest
				:obcpt_type ctype_value
				:obcpt_expr (make_stringconst discr_verbatim_string "/*getprevenv*/ (melt_ptr_t) modargp_"))
		      )
	 )
       (append_commentconst oiniprolog "compute boxloc")
       ;; we compute the boxloc at first
       (list_append oiniprolog otestcomputboxloc)
       ;; the tuple to compile the body
       (debug "compile2obj_initproc" " idata=" idata)
       (let (
	     (odatatup 
	      (list_to_multiple
	       idata discr_multiple
	       (lambda (curdat)
		 (debug "compile2obj_initproc:lambdabody" " curdat=" curdat)
		 (assert_msg "check curdat" (is_a curdat class_nrep_bound_data) curdat)
		 (let ( (curobd (compile_obj curdat gcx)) )
		   (debug "compile2obj_initproc:lambdabody" " curobd=" curobd)
		   curobd))))
	     (toplis (unsafe_get_field :ninit_topl ipro)) 
	     )
	 (unsafe_put_fields oinitrout
			    :oirout_data odatatup)
	 (assert_msg "check toplis" (is_list_or_null toplis) toplis)
	 ;; compile the toplevels
	 (let ( (objtoplis 
		 (list_map
		  toplis
		  (lambda (curtop)
		    (let ( (otop (compile_obj curtop gcx)) )
		      (debug "compile2obj_initproc otop=" otop)
		      otop)))) 
		)
	   (debug "compile2obj_initproc objtoplis=" objtoplis "\n modinienv=" modinienv)
	   (cond 
	    ( (is_object modinienv)
	      ;; generate the getting of symbols & keywords
	      (append_commentconst oiniprolog "get symbols & keywords for initial procedure")
	      (foreach_in_multiple
	       (odatatup)
	       (curpdat :long curk) 
	       (if (is_a curpdat class_objinitobject)
		   (let ( (odat (unsafe_get_field :oie_data curpdat))
			  )
		     (debug "compile2obj_initproc getting curpdat=" curpdat)
		     (cond 
		      ;; first  check for keywords, since they are also symbols (so order is important)
		      ( (is_a odat class_nrep_datakeyword)
			(let ( (ogkw (instance class_objgetnamedkeyword
					       :obgnamed_iobj curpdat))
			       )
			  (list_append oiniprolog ogkw)
			  (debug "compile2obj_initproc added keyword getting ogkw=" ogkw)
			  ))
		      ( (is_a odat class_nrep_datasymbol)
			(let ( (ogsy (instance class_objgetnamedsymbol
					       :obgnamed_iobj curpdat))
			       )
			  (list_append oiniprolog ogsy)
			  (debug "compile2obj_initproc added symbol getting ogsy=" ogsy)
			  ))
		      ))))
	      ;;
	      ;; get the value importer if needed
	      (when (>i (list_length importvalues) 0)
		;; 
		(debug "compile2obj_initproc importexprs=" importexprs)
		(append_commentconst oiniprolog "before getting imported values thru hook")
		(let ( (:long nbimportexprs (multiple_length importexprs))
		       (oimportup (make_multiple discr_multiple nbimportexprs))
		       )
		  (foreach_in_multiple
		   (importexprs)
		   (curimpexp :long impix)
		   (debug "compile2obj_initproc curimpexp=" curimpexp " impix#" impix)
		   (let ( (ocurimp (compile_obj curimpexp gcx))
			  )
		     (debug "compile2obj_initproc ocurimp=" ocurimp)
		     (list_append oiniprolog ocurimp)
		  )))

		(append_commentconst oiniprolog "after getting imported values")
		)
	      )				;end if modinienv
	    ( (null modinienv)
	      ;; initial module, don't need to generate importer or
	      ;; symbol or keyword getter, but need to emit the check
	      ;; that the parent environment is null
	      (let ( 
		    (modulverbstr (clone_with_discriminant
				   (get_field :mocx_modulename modctx) 
				   discr_verbatim_string))
		    (ochecknopar
		     (make_objcompute
		      ()
		      ctype_void
		      ##{ /* initialization of initial module $MODULVERBSTR */
		      melt_assertmsg("initial module $MODULVERBSTR should have no parent",
				     modargp_ == NULL) ;
		      }#
		      ))
		    )
		(debug "compile2obj_initproc ochecknopar=" ochecknopar)
		(list_append oiniprolog ochecknopar)
		))
	    (:else
	     (debug "compile2obj_initproc unexpected modinienv=" modinienv)
	     (assert_msg "compile2obj_initproc impossible modinienv" () modinienv)
	     )
	    ) ;; end cond
	   ;;
	   ;; append the compiled toplevel
	   (append_commentconst oinibody "before toplevel body")
	   (each_component_in_list
	    objtoplis
	    curobjt
	    (list_append oinibody curobjt))
	   (append_commentconst oinibody "after toplevel body")
	   ;; we compute the boxloc again
	   (append_commentconst oinibody "compute boxloc again")
	   (list_append oinibody otestcomputboxloc)
	   (append_commentconst oinibody "intern symbols")
	   ;; generate interning of symbols & keywords
	   (multiple_every
	    odatatup
	    (lambda (curpdat :long curk) 
	      (if (is_a curpdat class_objinitobject)
		  (let ( (odat (unsafe_get_field :oie_data curpdat))
			 )
		    (debug "compile2obj_initproc interning curpdat=" curpdat)
		    (cond 
		     ;; first  check for keywords, since they are also symbols (so order is important)
		     ( (is_a odat class_nrep_datakeyword)
		       (let ( (oikw (instance class_objinternkeyword
					      :obintern_iobj curpdat))
			      )
			 (list_append oinibody oikw)
			 (debug "compile2obj_initproc added keyword interning oikw=" oikw)
			 ))
		     ( (is_a odat class_nrep_datasymbol)
		       (let ( (oisy (instance class_objinternsymbol
					      :obintern_iobj curpdat))
			      )
			 (list_append oinibody oisy)
			 (debug "compile2obj_initproc added symbol interning oisy=" oisy)
			 ))
		     )))))
	   )				;end of toplevels
	 (append_commentconst oinibody "set retinit from boxloc")
	 ;; emit setting the retinit from the boxloc
	 (let ( (osetretinit
		 (make_objcompute () ctype_value
				  ##{/* finalsetretinit */ melt_reference_value((melt_ptr_t)($BOXLOC))}#))
		)
	   (put_objdest osetretinit retinit)
	   (debug "compile2obj_initproc adding osetretinit=" osetretinit)
	   (list_append oinibody osetretinit))
;;; ending
	 (append_commentconst oinibody "end the initproc")
	 (debug "compile2obj_initproc" " final oinibody=" oinibody " gcx=" gcx " oinitrout=" oinitrout
		"\n.. listrestrout=" listrestrout)
	 (return oinitrout listrestrout)
	 ))))




 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; this function is similar to compile2obj_initproc but they are some differences
 ;; it compiles the initial routine for runtime evaluation
 (defun compile2obj_initextendproc (ipro modctx idata compicache procurmodenvlist)
   (debug "compile2obj_initextendproc ipro=" ipro 
	  "\n* modctx=" modctx "\n* idata=" idata "\n* compicache=" compicache
	  "\n* procurmodenvlist=" procurmodenvlist 
	  "\n\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n"
	  )
   (shortbacktrace_dbg "compile2obj_initextendproc" 12)
   (assert_msg "check ipro" (is_a ipro class_nrep_initextendproc) ipro)
   (assert_msg "check idata" (is_list idata) idata)
   (assert_msg "check modctx" (is_a modctx class_running_extension_module_context) modctx)
   (assert_msg "check compicache" (is_mapobject compicache) compicache)
   (let ( (locmap (make_mapobject discr_map_objects 50))
	  (importvalues (get_field :ninit_imports ipro))
	  (importexprs (get_field :ninit_importexprs ipro))
	  (oiniprolog (make_list discr_list))
	  (oinibody (make_list discr_list))
	  (modenv (get_field :ninitextend_modenv ipro))
	  (nbody (let ( (nb (get_field :nproc_body ipro))
			)
		   (debug "compile2obj_initextendproc nbody=" nb)
		   nb))
	  (modname (get_field :mocx_modulename modctx))
	  (litvalist (get_field :morcx_litervalist modctx))
	  (oinitxrout 
	   (let ( (oi
		   (instance class_initial_extension_routineobj
			     ;; change carefully the name, since the runtime
			     ;; should know it, notably its
			     ;; meltgc_run_cc_extension function
			     :named_name '"melt_start_run_extension"
			     :obrout_proc ipro
			     :obrout_body oinibody
			     :obrout_nbval (make_integerbox discr_integer 0)
			     :obrout_nblong (make_integerbox discr_integer 0)
			     :obrout_others (make_list discr_list)
			     :obrout_cntciter (make_integerbox discr_integer 0)
			     :obrout_cntletrec (make_integerbox discr_integer 0)
			     :oirout_fill (make_list discr_list)
			     :oirout_prolog oiniprolog
			     :oirout_modctx modctx
			     ))
		  )
	     (debug "compile2obj_initextendproc oinitxrout=" oi)
	     oi))
	  (importmap (make_mapobject discr_map_objects 30))
	  (valoclist (make_list discr_list))
	  ;; running expressions are usually smaller
	  (gcx (instance 
		class_extension_generation_context
		:gncx_objrout oinitxrout
		:gncx_locmap locmap
		:gncx_freeptrlist (make_list discr_list)
		:gncx_freelonglist (make_list discr_list)
		:gncx_freeothermaps (make_mapobject discr_map_objects 10)
		:gncx_compicache compicache
		:gncx_modulcontext modctx
		:gncx_matchmap (make_mapobject discr_map_objects 20)
		:igncx_procurmodenvlist
		(list_map 
		 procurmodenvlist
		 (lambda (curpro)
		   (debug "compile2obj_initextendproc procurmodenvlist curpro=" curpro)
		   (let ( (curou (mapobject_get compicache curpro)) )
		     (debug "compile2obj_initextendproc procurmodenvlist curou=" curou)
		     (assert_msg "check curou" (is_object curou) curou)
		     curou)))
		;; perhaps we should store not a list of procedures, but their matching routines
		:igncx_importmap importmap
		:egncx_valoclist valoclist
		))
	  ;; reserve stack location for the return value
	  (retinit 
	   (let ( (reti (get_free_objlocptr gcx '_retruninit_)) )
	     (put_fields gcx :gncx_retloc reti)
	     (put_fields oinitxrout :obrout_retval reti)
	     (debug "compile2obj_initextendproc retinit=" reti)
	     reti))
	  ;; reserve stack location for the current environment box container
	  (ocurenvboxloc
	   (let ( (boxl (get_free_objlocptr gcx '_ocurenvboxloc_)) )
	     (put_fields gcx :igncx_contenvloc boxl)
	     (debug "compile2obj_initextendproc ocurenvboxloc=" boxl)
	     boxl))
	  ;; reserve stack location for the current environment
	  (ocurenvloc
	   (let ( (locl (get_free_objlocptr gcx '_ocurenvloc_)) )
	     (debug "compile2obj_initextendproc ocurenvloc=" locl)
	     locl))
	  ;; reserve stack location for the previous environment
	  (oprevenvloc
	   (let ( (boxl (get_free_objlocptr gcx '_prevenvloc_)) )
	     (put_fields gcx :igncx_prevenvloc boxl)
	     (debug "compile2obj_initextendproc oprevenvloc=" boxl)
	     boxl))
	  ;; reserve stack location for the tuple of literal values
	  (olitvaluetuploc
	   (let ( (boxl (get_free_objlocptr gcx '_olitvaluetuploc_)) )
	     (put_fields gcx :egncx_litvaltuploc boxl)
	     (debug "compile2obj_initextendproc olitvaluetuploc=" boxl)
	     boxl))
	  ;; We don't have any exporter, because all values stay
	  ;; defined in the current environment so are implicitly
	  ;; exported.
	  ;;
	  ;; We don't have any importer, because we use the value
	  ;; literal tuple instead.
	  ;;
	  ;; initial defined bindings
	  (inidefbinds (get_field :ninit_defbinds ipro))
	  )
     (append_commentconst oinibody "start of oinibody")
     (debug "compile2obj_initextendproc ocurenvboxloc=" ocurenvboxloc
	    "\n inidefbinds=" inidefbinds
	    "\n modenv=" modenv)
     (debug "compile2obj_initextendproc importvalues=" importvalues 
	    "\n.. importexprs=" importexprs)
     ;; we actually could import literal named values.
     ;;
     ;; reserve location for defined values
     (debug "compile2obj_initextendproc inidefbinds=" inidefbinds)
     (assert_msg "check inidefbinds=" (is_list_or_null inidefbinds) inidefbinds)
     (foreach_pair_component_in_list
      (inidefbinds)
      (curpair curdefbind)
      (debug "compile2obj_initextendproc curdefbind=" curdefbind
	     " of discrim=" (discrim curdefbind))
      (let ( (inidefsymb (get_field :binder curdefbind))
	     (oinisym (get_field :fixbind_data curdefbind))
	     (oinidefloc (get_free_objlocptr gcx inidefsymb))
	     )
	(debug "compile2obj_initextendproc oinidefloc=" oinidefloc " oinisym=" oinisym
	       " of discrim:" (discrim oinisym)
	       " curdefbind=" curdefbind)
	;;oinisym is often a class_nrep_locsymocc but can be a
	;;class_nrep_defined_constant
	(assert_msg "check oinisym" (is_a oinisym class_nrep_simple) oinisym)
	(mapobject_put locmap curdefbind oinidefloc)
	))
     (debug "compile2obj_initextendproc updated locmap=" locmap "\n.. importvalues=" importvalues)
     ;;
     (let (
	   (limplocv
	    (list_map 
	     importvalues
	     (lambda (ival)
	       (debug "compile2obj_initextendproc imported ival=" ival)
	       (assert_msg "check ival" (is_a ival class_nrep_literalnamedvalue) ival)
	       (let ( (isym (get_field :nlitval_symbol ival)) 
		      (regval (get_field :nlitval_regval ival))
		      (litloc (get_field :litv_loc regval))
		      (ilocv (or litloc 
				 (let ( (nloc (get_free_objlocptr gcx isym))
					)
				   (debug "compile2obj_initextendproc nloc=" nloc " for ival=" ival)
				   (mapobject_put importmap isym nloc)
				   (put_fields litloc :litv_loc nloc)
				   nloc)))
		      )
		 (debug "compile2obj_initextendproc imported ilocv=" ilocv " for isym=" isym)
		 ilocv
		 )))))
       (debug "compile2obj_initextendproc limplocv=" limplocv)
       (void)
       )
     ;;
     ;; the prologue start by getting the the current environment
     ;; reference and the raw value tuple
     (list_append oiniprolog
		  (make_objlocatedexp 
		   () ctype_void
		   ##{/*initextendproc get boxcurenv*/ $OCURENVBOXLOC
		   = meltarg_curenvbox_p ;}#
		   ))
     (debug "compile2obj_initextendproc litvalist=" litvalist)
     (let ( (:long nblitval (list_length litvalist))
	    (toplis (unsafe_get_field :ninit_topl ipro)) 
	    )
       (debug "compile2obj_initextendproc toplis=" toplis)
       (list_append oiniprolog
		    (make_objlocatedexp 
		     () ctype_void
		     ##{/*initextendproc get litvaluetup*/ $OLITVALUETUPLOC 
		     = meltarg_tuplitval_p ;
		     if (melt_multiple_length((melt_ptr_t) $OLITVALUETUPLOC) !=
					     $NBLITVAL)
		     melt_fatal_error ("bad runtime extension literal value tuple@%p in " 
				       $MODNAME ", wants $NBLITVAL components", 
				       (void*) $OLITVALUETUPLOC) ;
		     }#
		     ))
       (list_append oiniprolog
		    (instance class_objgetslot
			      :obdi_destlist (list ocurenvloc)
			      :ogetsl_obj ocurenvboxloc
			      :ogetsl_field referenced_value
			      ))
       (list_append oiniprolog
		    (instance class_objgetslot
			      :obdi_destlist (list oprevenvloc)
			      :ogetsl_obj ocurenvloc
			      :ogetsl_field env_prev
			      ))
       (debug "compile2obj_initextendproc before body oiniprolog=" oiniprolog
	      "\n idata=" idata)
       (debug "compile2obj_initextendproc again toplis=" toplis
	      "\n.. gcx=" debug_less gcx)
       (assert_msg "check toplis" (is_list_or_null toplis) toplis)
       ;; compile the toplevels
       (let ( (objtoplis 
	       (list_map
		toplis
		(lambda (curtop)
		  (debug "compile2obj_initextendproc curtop=" curtop)
		  (let ( (otop (compile_obj curtop gcx)) )
		    (debug "compile2obj_initextendproc otop=" otop)
		    otop)))) 
	      )
	 (debug "compile2obj_initextendproc objtoplis=" objtoplis)
	 ;; now handle the body
	 ;; the tuple to compile the body
	 (let (
	       (odatatup 
		(list_to_multiple
		 idata discr_multiple
		 (lambda (curdat)
		   (debug "compile2obj_initextendproc/lambdabody curdat=" curdat)
		   (assert_msg "check curdat" (is_a curdat class_nrep_bound_data) curdat)
		   (let ( (curobd (compile_obj curdat gcx)) )
		     (debug "compile2obj_initextendproc/lambdabody curobd=" curobd)		   
		     curobd))))
	       )
	   (debug "compile2obj_initextendproc odatatup=" odatatup "\n.. toplis=" toplis)
	   (put_fields oinitxrout
		       :oirout_data odatatup)
	   ;; generate the getting of symbols & keywords
	   (append_commentconst oiniprolog "get symbols & keywords for extension")
	   (assert_msg "check odatatup" (is_multiple_or_null odatatup) odatatup)
	   (foreach_in_multiple
	    (odatatup)
	    (curpdat :long curk) 
	    (if (is_a curpdat class_objinitobject)
		(let ( (odat (unsafe_get_field :oie_data curpdat))
		       )
		  (debug "compile2obj_initextendproc getting curpdat=" curpdat)
		  (cond 
		   ;; first  check for keywords, since they are also symbols (so order is important)
		   ( (is_a odat class_nrep_datakeyword)
		     (let ( (ogkw (instance class_objgetnamedkeyword
					    :obgnamed_iobj curpdat))
			    )
		       (list_append oiniprolog ogkw)
		       (debug "compile2obj_initextendproc added keyword getting ogkw=" ogkw)
		       ))
		   ( (is_a odat class_nrep_datasymbol)
		     (let ( (ogsy (instance class_objgetnamedsymbol
					    :obgnamed_iobj curpdat))
			    )
		       (list_append oiniprolog ogsy)
		       (debug "compile2obj_initextendproc added symbol getting ogsy=" ogsy)
		       ))
		   ))))
	   (debug "compile2obj_initextendproc before imports oiniprolog=" oiniprolog)
	   ;;
	   (when (>i (list_length importvalues) 0)
	     (append_commentconst oiniprolog "before getting imported values")
	     ;; generate the getting of imported values
	     (foreach_pair_component_in_list
	      (importvalues)
	      (curpairimp curimport)
	      (debug "compile2obj_initextendproc curimport=" curimport)
	      (assert_msg "check curimport" (is_a curimport  class_nrep_literalnamedvalue) curimport)
	      (compile_warning "the generated import should have a cstring")
	      (let ( (impsym (get_field :nlitval_symbol curimport)) 
		     (regval (get_field :nlitval_regval curimport))
		     (val (get_field :litv_value regval))
		     (modulstr (get_field :mocx_modulename modctx)) 
		     (oimplocv (mapobject_get importmap impsym))
		     )
		(debug "compile2obj_initextendproc impsym=" impsym "\n regval=" regval "\n oimplocv=" oimplocv)
		(let ( 
		      (:long litrank (get_int (get_field :litv_rank regval)))
		      (ogetlit (make_objcompute
				()
				ctype_value
				##{/* retrieve runtime literal value #$LITRANK */
				((melt_ptr_t) (((meltmultiple_ptr_t)$OLITVALUETUPLOC)->tabval[$LITRANK]))
				}#))
		      )
		  (put_objdest ogetlit oimplocv)
		  (debug "compile2obj_initextendproc/import val=" val
			 " regval=" regval
			 " ogetlit=" ogetlit)
		  (list_append oiniprolog ogetlit)
		  )))
	     (append_commentconst oiniprolog "after getting imported values")
	     )
	   ;; append the compiled toplevel
	   (append_commentconst oinibody "before toplevel body")
	   (debug "compile2obj_initextendproc objtoplis=" objtoplis)
	   (foreach_pair_component_in_list
	    (objtoplis)
	    (curpair curobjt)
	    (debug "compile2obj_initextendproc appendinf curobjt=" curobjt)
	    (list_append oinibody curobjt))
	   (debug "compile2obj_initextendproc updated oinibody=" oinibody)
	   (debug "compile2obj_initextendproc nbody=" nbody)
	   (foreach_pair_component_in_list 
	    (nbody)
	    (curnpair curninst)
	    (debug "compile2obj_initextendproc curninst=" curninst)
	    (if (is_not_a curninst class_nrep_routproc)
		(let ( (curobjb (compile_obj curninst gcx))
		       )
		  (debug "compile2obj_initextendproc curobjb=" curobjb)
		  (cond ( (null curobjb)
			  (debug "compile2obj_initextendproc skipping null curobjb=" curobjb)
			  (void)
			  )
			( (is_a curobjb class_objpurevalue)
			  (debug "compile2obj_initextendproc skipping pure curobjb=" curobjb)
			  (void)
			  )
			(:else
			 (debug "compile2obj_initextendproc appending curobjb=" curobjb)
			 (list_append oinibody curobjb)
			 (void)))
		  )))
	   ;;
	   (append_commentconst oinibody "after toplevel body")
	   (debug "compile2obj_initextendproc final oinibody=" oinibody)
	   ;;
	   (debug "compile2obj_initextendproc gives oinitxrout=" oinitxrout "\n")
	   (return oinitxrout)
	   )))))



 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 (export_values 
  compile2obj_hook
  compile2obj_initproc
  compile2obj_initextendproc
  compile2obj_procedure
  variadic_index_idstr
  variadic_length_idstr
  )

 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;function to get a free local value pointer for some name
 ;; any free ptr is only reused for its offset. the objlocv is not reused...
 (defun get_free_objlocptr (gcx nam)
   (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
   (debug "get_free_objlocptr start nam=" nam)
   (shortbacktrace_dbg "get_free_objlocptr" 7)
   (let ( (orout (unsafe_get_field :gncx_objrout gcx))
	  (freeli (unsafe_get_field :gncx_freeptrlist gcx)) 
	  (pfree (list_pop_first freeli))
	  (:long off -1)
	  )
     (if (not (is_a orout class_routineobj))
	 (debug "get_free_objlocptr bad orout=" orout))
     (assert_msg "check orout" (is_a orout class_routineobj) orout)
     (if (is_a pfree  class_objlocv)
	 (let ( (offpfree (unsafe_get_field :obl_off pfree)) )
	   (debug "get_free_objlocptr pfree=" pfree)
	   (assert_msg "get_free_objlocptr check offpfree" (is_integerbox offpfree) offpfree)
	   ;; check that pfree has no objnum so was unused 
	   (assert_msg "check pfree not used" (not (get_int pfree)) pfree)
	   (setq off (get_int offpfree)))
       (let ( (nbvalorout (unsafe_get_field :obrout_nbval orout)) )
	 (setq off (get_int nbvalorout))
	 ))
     (assert_msg "check off" (>=i off 0) off)
     (let ( (nbvalbox (unsafe_get_field :obrout_nbval orout)) 
	    (:long nbval (get_int nbvalbox))  
	    (nambuf (make_strbuf discr_strbuf))
	    )
       (cond ( (is_a nam class_named)
	       (let ( (namstr (unsafe_get_field :named_name nam)) )
		 (add2sbuf_cident nambuf namstr)))
	     ( (is_string nam)
	       (add2sbuf_cident nambuf nam)))
       (add2sbuf_strconst nambuf "__V")
       (add2sbuf_longdec nambuf (+i nbval 1))
       (put_int nbvalbox (+i nbval 1))
       (let ( (namstr (strbuf2string discr_string nambuf))
	      (oldnbvalbox (make_integerbox discr_integer nbval))
	      (nloc (instance class_objlocv
			      :obv_type ctype_value
			      :obl_off (make_integerbox discr_integer off)
			      :obl_proc orout
			      :obl_cname namstr)) 
	      )
	 (debug "get_free_objlocptr" " new nloc" nloc "\n.. for nam=" nam)
	 (return nloc)
	 ))))



 ;;; function to get a free local long for some name
 (defun get_free_objloclong (gcx nam)
   (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
   (debug "get_free_objloclong start nam=" nam)
   ;(shortbacktrace_dbg "get_free_objloclong start" 12)
   (let ( (orout (unsafe_get_field :gncx_objrout gcx))
	  (freeli (unsafe_get_field :gncx_freelonglist gcx)) 
	  (pfree (list_pop_first freeli))
	  (:long off -1)
	  )
     (assert_msg "check orout" (is_a orout class_routineobj) orout)
     (if (is_a pfree  class_objlocv)
	 (let ( (offpfree (unsafe_get_field :obl_off pfree)) )
	   (debug "get_free_objloclong pfree" pfree)
	   (assert_msg "check offpfree" (is_integerbox offpfree) offpfree)
	   ;; check that pfree has no objnum so was unused 
	   (assert_msg "check pfree not used" (not (get_int pfree)) pfree)
	   (setq off (get_int offpfree)))
       (let ( (nblongorout (unsafe_get_field :obrout_nblong orout)) )
	 (assert_msg "check nblongorout" (is_integerbox nblongorout) nblongorout)
	 (setq off (get_int nblongorout))))
     (assert_msg "check off" (>=i off 0) off)
     (let ( (nblongbox (unsafe_get_field :obrout_nblong orout)) 
	    (:long nblong (get_int nblongbox))  
	    (nambuf (make_strbuf discr_strbuf))
	    )
       (cond ( (is_a nam class_named)
	       (add2sbuf_cident nambuf (unsafe_get_field :named_name nam)))
	     ( (is_string nam)
	       (add2sbuf_cident nambuf nam))
	     )
       (add2sbuf_strconst nambuf "__L")
       (add2sbuf_longdec nambuf (+i nblong 1))
       (put_int nblongbox (+i nblong 1))
       (let ( (nloc (instance class_objlocv
			      :obv_type ctype_long
			      :obl_off (make_integerbox discr_integer off)
			      :obl_proc orout
			      :obl_cname (strbuf2string discr_string nambuf))) )
	 (debug "get_free_objloclong new nloc=" nloc)
	 (return nloc)
	 ))))

 ;;; function to get a free local otherstuff for some name and ctype
 (defun get_free_objloctyped (gcx nam ctyp)
   (debug "get_free_objloctyped nam=" nam " ctyp=" ctyp)
   (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
   (assert_msg "check ctyp" (is_a ctyp class_ctype) ctyp)
   (cond ( (== ctyp ctype_long)
	   (return (get_free_objloclong gcx nam)))
	 ( (== ctyp ctype_value)
	   (return (get_free_objlocptr gcx nam)))
	 ;; return null for the void ctype
	 ( (== ctyp ctype_void)
	   (return ()))
	 (:else 
	  (debug "get_free_objloctyped otherctyp nam=" nam " ctyp=" ctyp)
	  ;(shortbacktrace_dbg "get_free_objloctyped otherctyp" 15)
	  (let ( (freemap (unsafe_get_field :gncx_freeothermaps gcx)) 
		 (orout (unsafe_get_field :gncx_objrout gcx))
		 (:long off -1)
		 )
	    (assert_msg "check freemap" (is_mapobject freemap) freemap)
	    (assert_msg "check orout" (is_a orout class_routineobj) orout)
	    (let ( (freeli (mapobject_get freemap ctyp)) )
	      (if (null freeli) 
		  (progn
		    (setq freeli (make_list discr_list))
		    (mapobject_put freemap ctyp freeli)))
	      (let ( (pfree (list_pop_first freeli)) )
		(if (is_a pfree  class_objlocv)
		    (progn 
		      (debug  "get_free_objloctyped pfree=" pfree)
		      (assert_msg "check pfree was unused" (not (get_int pfree)) pfree)
		      (setq off (get_int (unsafe_get_field :obl_off pfree)))
		      )
		  (setq off  (list_length (unsafe_get_field :obrout_others orout))))
		(let ( 
		      (nambuf (make_strbuf discr_strbuf)) 
		      (others (unsafe_get_field :obrout_others orout))
		      (:long nbothers (list_length others))
		      )
		  (assert_msg "check others" (is_list others) others)
		  (add2sbuf_strconst nambuf "loc_")
		  (add2sbuf_cident nambuf 
				   (get_field :named_name 
					      (get_field :ctype_keyword ctyp)))
		  (add2sbuf_strconst nambuf "__o")
		  (add2sbuf_longdec nambuf nbothers)
		  (let ( (nloc (instance class_objlocv
					 :obv_type ctyp
					 :obl_proc orout
					 :obl_off (make_integerbox discr_integer off)
					 :obl_cname (strbuf2string discr_string nambuf))) )
		    (debug  "get_free_objloctyped new nloc" nloc)
		    (list_append others nloc)
		    (return nloc)
		    )
		  )))))))




 ;; function to dispose, i.e. mark as free and reusable, an  objlocation
 (defun dispose_objloc (oldloc gcx)
   (debug "dispose_objloc start disposing oldloc=" oldloc)
   (shortbacktrace_dbg "dispose_objloc" 9)
   (assert_msg "check oldloc" (is_a oldloc class_objlocv) oldloc)
   (assert_msg "check gcx" (is_a gcx class_c_generation_context))
   ;; the obl_proc iff it has already been freed
   (assert_msg "check used oldloc" (unsafe_get_field :obl_proc oldloc) oldloc)
   (let ( (oldcty (unsafe_get_field :obv_type oldloc)) )
     (assert_msg "check oldcty not void" (!= oldcty ctype_void) oldcty)
     (assert_msg "check oldcty is ctype" (is_a oldcty class_ctype) oldcty)
     (put_fields oldloc :obl_proc ())			;mark the objlocation as freed
     (debug "dispose_objloc freeing oldloc=" oldloc)
     (cond ( (== oldcty ctype_value)
	     (let  ( (freepl (unsafe_get_field :gncx_freeptrlist gcx)) )
	       (list_append freepl oldloc)))
	   ( (== oldcty ctype_long)
	     (let  ( (freenl (unsafe_get_field :gncx_freelonglist gcx)) )
	       (list_append freenl oldloc)))
	   (:else
	    (let ( (freemap (unsafe_get_field :gncx_freeothermaps gcx)) 
		   (orout (unsafe_get_field :gncx_objrout gcx))
		   )
	      (assert_msg "check freemap" (is_mapobject freemap) freemap)
	      (assert_msg "check orout" (is_a orout class_routineobj) orout)
	      (let ( (freeli (mapobject_get freemap oldcty)) )
		;; since we are freeing, freeli should exist
		(assert_msg "check freeli" (is_list freeli) freeli)
		(list_append freeli oldloc)))))
     (debug "dispose_objloc freed oldloc=" oldloc)
     ))

 ;; function to dispose, i.e. mark as free, a binding 
 (defun dispose_bnd_obj (bnd gcx)
   (debug "dispose_bnd_obj start bnd=" bnd)
   (assert_msg "check bnd" (is_a bnd class_any_binding) bnd)
   (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
   (let ( (locmap (unsafe_get_field :gncx_locmap gcx))
	  (oldloc (mapobject_get locmap bnd)) 
	  )
     (debug "dispose_bnd_obj oldloc=" oldloc)
     (when (null oldloc)
	   ;; special hack to dispose a void let binding - return immediately in that case
	   (and (is_a bnd class_let_binding)
		(== (unsafe_get_field :letbind_type bnd) ctype_void)
		(return))
	   (debug "dispose_bnd_obj nulloldloc bnd=" bnd)
	   )
     (assert_msg "check oldloc" (is_a oldloc class_objlocv) oldloc)
     (dispose_objloc oldloc gcx)
     (mapobject_remove locmap bnd)
     (debug "dispose_bnd_obj end bnd=" bnd)
     ))

 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 (defun compilobj_nrep_chunk (nchk gcx)
   (debug "compilobj_nrep_chunk nchk=" nchk)
   (assert_msg "check nchk" (is_a nchk class_nrep_chunk) nchk)
   (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
   (let ( (loc (unsafe_get_field :nrep_loc nchk))
	  (nexp (unsafe_get_field :nchunk_expansion nchk))
	  (noper (unsafe_get_field :nchunk_oper nchk))
	  (ntyp (unsafe_get_field :nexpr_ctyp nchk))
	  )
     (debug "compilobj_nrep_chunk nexp=" nexp)
     (assert_msg "check noper" (is_a noper class_named) noper)
     (assert_msg "check nexp" (is_multiple nexp) nexp)
     (assert_msg "check ntyp" (is_a ntyp class_ctype) ntyp)
     (let (  (otup (multiple_map
		    nexp
		    (lambda (comp :long ix)
		      (debug "compilobj_nrep_chunk comp=" comp " ix#" ix)
		      (if (== (discrim comp) discr_verbatim_string)
			  (progn
			    (debug "compilobj_nrep_chunk verbstring comp=" comp 
				   " ix#" ix)
			    (return comp)
			    )			   
			(let ( (ocomp (compile_obj comp gcx)) 
			       )
			  (debug "compilobj_nrep_chunk ocomp=" ocomp
				 " ix#" ix)
			  (return ocomp))))
		    ))
	     (oexp (if loc
		       (instance class_objlocatedexpv
				 :obv_type ntyp
				 :obx_cont otup
				 :obcx_loc loc
				 )
		     (instance class_objexpv
			       :obv_type ntyp
			       :obx_cont otup)
		     ))      
	     )
       (debug "compilobj_nrep_chunk otup=" otup)
       (assert_msg "check ntyp" (is_a ntyp class_ctype) ntyp)
       (debug "compilobj_nrep_chunk result oexp=" oexp)
       oexp)
     ))
 (install_method class_nrep_chunk compile_obj compilobj_nrep_chunk)


 ;;;;;;;;;;;;;;;;
 (defun getctype_typexpr (recv env)
   (assert_msg "check recv" (is_a recv class_nrep_typed_expression) recv)
    (unsafe_get_field :nexpr_ctyp recv))
 (install_method class_nrep_typed_expression get_ctype getctype_typexpr)

 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 (defun compilobj_nrep_nil (nilo gcx)
   (assert_msg "check nilo" (is_a nilo class_nrep_nil) nilo)
   (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
   (let ( (obnil (instance class_objnil
			   :obv_type ctype_value)) )
     (return obnil))
   )

 (install_method class_nrep_nil compile_obj compilobj_nrep_nil)

 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 (defun compilobj_nrep_comment (ncomm gcx)
   (debug "compilobj_nrep_comment start ncomm=" ncomm)
   (assert_msg "check ncomm" (is_a ncomm class_nrep_comment) ncomm)
   (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
   (let ( (coms (unsafe_get_field :ncomm_string ncomm))
	  (nloc (unsafe_get_field :nrep_loc ncomm))
	  (sbuf (make_strbuf discr_strbuf)) )
     (add2sbuf_strconst sbuf "/**!* ")
     (add2sbuf_ccomstring sbuf coms)
     (add2sbuf_strconst sbuf " *!**/")
     (let ( (ostr (strbuf2string discr_verbatim_string sbuf)) 
	    (res  (instance class_objcompute
			    :obi_loc nloc
			    :obdi_destlist ()
			    :obcpt_type ctype_void
			    :obcpt_expr ostr))
	    )  
       (debug "compilobj_nrep_comment ostr=" ostr " res=" res)
       (return res)
       )))
 (install_method class_nrep_comment compile_obj compilobj_nrep_comment)


 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 (defun compilobj_nrep_locsymocc (lsyo gcx)
   (debug "compilobj_nrep_locsymocc begin lsyo=" lsyo)
   (assert_msg "check nchk" (is_a lsyo class_nrep_locsymocc) lsyo)
   (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
   (let ( (loc (unsafe_get_field :nrep_loc lsyo))
	  (locmap (unsafe_get_field :gncx_locmap gcx))
	  (sym (unsafe_get_field :nocc_symb lsyo))
	  (oty (unsafe_get_field :nocc_ctyp lsyo))
	  (sbnd (unsafe_get_field :nocc_bind lsyo))
	  (ovar (mapobject_get locmap sbnd))
	  )
     (debug "compilobj_nrep_locsymocc sbnd=" sbnd " ovar=" ovar)
     (when (null sbnd)
       (debug "compilobj_nrep_locsymocc null sbnd lsyo=" lsyo " sym=" sym)
       (error_at loc "bad mistyped MELT symbol occurrence $1 of type $2" sym oty)
       (assert_msg "locsymocc without binding" () lsyo)
	   )
     (if (null ovar) 
	 (progn
	   (debug "compilobj locsymocc null ovar sbnd=" sbnd 
		  "\n.. locmap=" locmap 
		  "\n.. lsyo=" lsyo 
		  "\n.. gcx=" debug_less gcx)
	   (when (!= oty ctype_void)
	     (error_at loc "bad MELT symbol occurrence $1 of type $2" sym oty)
	     (assert_msg "compilobj_nrep_locsymocc null ovar without ctype_void" (== oty ctype_void) oty lsyo locmap))
	   )
       (assert_msg "compilobj_nrep_locsymocc check ovar"  (is_a ovar class_objlocv) ovar))
     (debug "compilobj_nrep_locsymocc end lsyo=" lsyo " gives ovar=" ovar)
     (return ovar)
     ))
 (install_method class_nrep_locsymocc compile_obj compilobj_nrep_locsymocc)

 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 (defun compilobj_nrep_closedocc (nclo gcx)
   (debug "compilobj_nrep_closedocc nclo=" nclo)
   (assert_msg "check nclo" (is_a nclo class_nrep_closedocc) nclo)
   (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
   (let ( 
	 (orout (unsafe_get_field :gncx_objrout gcx))
	 (osym (unsafe_get_field :nocc_symb nclo))
	 (obind (unsafe_get_field :nocc_bind nclo))
	 (cprocs (unsafe_get_field :ncloc_procs nclo))
	 (lastcproc (pair_head (list_last cprocs)))
	 (nloc (unsafe_get_field :nrep_loc nclo))
	 )
     (assert_msg "check lastcproc" (is_a lastcproc class_nrep_routproc) lastcproc)
     (let ( (cloblis (get_field :nrclop_clobindlist lastcproc)) 
	    (:long clorank -1)
	    )
       (assert_msg "check cloblis" (is_list cloblis) cloblis)
       (let ( (curpair (list_first cloblis)) 
	      (:long curank 0)
	      )
	 (forever 
	  looplis
	  (if (not (is_pair curpair)) (exit looplis))
	  (let ( (curbind (pair_head curpair)) )
	    (if (== curbind obind)
		(progn
		  (setq clorank curank)
		  (exit looplis)))
	    (setq curpair (pair_tail curpair))
	    (setq curank (+i curank 1))
	    ))
	 (assert_msg "check good closed rank" (>=i clorank 0) clorank)
	 (let ( 
	       (nclotyp (unsafe_get_field :nocc_ctyp nclo))
	       (ocloccv 
		(instance class_objcloccv
			  :obv_type nclotyp
			  :obc_off (make_integerbox discr_integer
						    clorank)
			  :obc_proc lastcproc
			  :obc_name (unsafe_get_field :named_name osym)))
	       )
	   (assert_msg "check nclotyp" (is_a nclotyp class_ctype) nclotyp)
	   (debug "compilobj closedocc result ocloccv=" ocloccv)
	   ocloccv
	   )))))

 (install_method class_nrep_closedocc compile_obj compilobj_nrep_closedocc)

 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 (defun compilobj_nrep_constocc (ncnst gcx)
   (debug "compilobj_nrep_constocc ncnst=" ncnst)
   (assert_msg "check ncnst" (is_a ncnst class_nrep_constocc) ncnst)
   (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
   (let ( 
	 (orout (unsafe_get_field :gncx_objrout gcx))
	 (osym (unsafe_get_field :nocc_symb ncnst))
	 (cprocs (unsafe_get_field :ncloc_procs ncnst))
	 (lastcproc (pair_head (list_last cprocs)))
	 (nloc (unsafe_get_field :nrep_loc ncnst))
	 (cnstyp (unsafe_get_field :nocc_ctyp ncnst))
	 (nbind (unsafe_get_field :nocc_bind ncnst))
	 )
     (debug "compilobj_nrep_constocc lastcproc=" lastcproc "\n..cprocs=" cprocs "\n..nbind=" nbind 
	    "\n.. gcx=" debug_less gcx)
     (shortbacktrace_dbg "compilobj_nrep_constocc" 8)
     (assert_msg "check lastcproc" (is_a lastcproc class_nrep_anyproc) lastcproc ncnst)
     (assert_msg "check cnstyp" (== cnstyp ctype_value) cnstyp ncnst)
     (cond 
      ;; handle routine procedures
      ( (is_a lastcproc class_nrep_routproc)
	(let ( (cnstlis (get_field :nrclop_constlist lastcproc)) 
	       (:long cnstrank -1)
	       )
	  (assert_msg "check cnstlis" (is_list cnstlis) cnstlis)
	  (let ( (curpair (list_first cnstlis)) 
		 (:long curank 0)
		 )
	    (forever 
	     looplis
	     (if (not (is_pair curpair)) (exit looplis))
	     (let ( (curelem (pair_head curpair)) )
	       (if (== curelem ncnst)
		   (progn
		     (setq cnstrank curank)
		     (exit looplis)))
	       (setq curpair (pair_tail curpair))
	       (setq curank (+i curank 1))
	       ))
	    (assert_msg "check good const rank" (>=i cnstrank 0) cnstrank)
	    (let ( 
		  (oconstv 
		   (instance class_objconstv
			     :obv_type cnstyp
			     :obc_off (constant_box cnstrank)
			     :obc_proc lastcproc
			     :obc_name (unsafe_get_field :named_name osym))) )
	      (debug "compilobj_nrep_constocc result oconstv=" oconstv ";\n.. from ncnst=" ncnst)
	      (return oconstv)
	      ))))
      ;; handle hook routines
      ( (is_a lastcproc class_nrep_hookproc)
	(let ( (:long offhk -1)
	       (:long count 0)
	       (hclobindlist (get_field :nrclop_clobindlist lastcproc))
	       )
	  (debug "compilobj_nrep_constocc hook hclobindlist=" hclobindlist)
	  (foreach_pair_component_in_list
	   (hclobindlist)
	   (curpair curbind)
	   (assert_msg "check curbind" (is_a curbind class_any_binding) curbind)
	   (let ( (cursym (get_field :binder curbind))
		  )
	     (when (== cursym osym)
	       (setq curpair ())
	       (setq offhk count))
	     (setq count (+i count 1))
	     ))
	  (debug "compilobj_nrep_constocc offhk=" offhk)
	  (assert_msg "check offhk" (>=i offhk 0) offhk)
	  (let ( (ohkconstv (instance class_objclohookv
				      :obv_type cnstyp
				      :obc_off (constant_box offhk)
				      :obc_proc lastcproc
				      :obc_name (unsafe_get_field :named_name osym))) 
		 )
	    (debug "compilobj_nrep_constocc result ohkconstv=" ohkconstv ";\n.. from ncnst=" ncnst)
	    (return ohkconstv)
	    )))
      (:else
       (debug "compilobj_nrep_constocc invalid lastcproc=" lastcproc "\n.. for ncnst=" ncnst)
       (assert_msg "compilobj_nrep_constocc unexpected lastcproc" () lastcproc ncnst)
       ))))

 (install_method class_nrep_constocc compile_obj compilobj_nrep_constocc)



 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 (defun compilobj_nrep_importedval (nsva gcx)
   (debug "compilobj_nrep_importedval nsva=" nsva " gcx=" gcx)
   (assert_msg "check gcx" (is_a gcx class_initial_generation_context) gcx)
   (assert_msg "check nsva" (is_a nsva class_nrep_importedval) nsva)
   (let ( (var (unsafe_get_field :nimport_symb nsva))
	  (olocv (mapobject_get (unsafe_get_field :igncx_importmap gcx) var))
	  )
     (debug "compilobj_nrep_importedval result olocv=" olocv)
     (assert_msg "check var" (is_a var class_symbol) var)
     (assert_msg "check olocv" (is_a olocv class_objlocv) olocv)
     (return olocv)
     ))
 (install_method class_nrep_importedval compile_obj compilobj_nrep_importedval)


 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 (defun compilobj_nrep_literalvalue (nlitv gcx)
   (debug "compilobj_nrep_literalvalue nlitv=" nlitv 
	  "\n of discrim=" (discrim nlitv)
	  "\n gcx=" gcx)
   (let ( (litregval (get_field  :nlitval_regval nlitv))
	  (litvrank (get_field :litv_rank litregval))
	  (olitup (get_field :egncx_litvaltuploc gcx))
	  (nloc (get_field :nrep_loc nlitv))
	  )
     (debug "compilobj_nrep_literalvalue litregval=" litregval
	    "\n litvrank=" litvrank
	    "\n olitup=" olitup)
     (assert_msg "check litregval" (is_a litregval class_literal_value) litregval)
     (assert_msg "check litvrank" (is_integerbox litvrank) litvrank)
     (assert_msg "check gcx" (is_a gcx class_extension_generation_context) gcx)
     (let ( (res (make_objexpandpureval 
		  nloc ctype_value
		  (string4out discr_verbatim_string ##{literal-value #$LITVRANK}#)
		  ##{/*comp.literalvalue*/ (melt_ptr_t) (((meltmultiple_ptr_t)$OLITUP)->tabval[$LITVRANK])}#))
	    )
       (debug "compilobj_nrep_literalvalue res=" res)
       (return res)
       )))

 (install_method class_nrep_literalvalue compile_obj compilobj_nrep_literalvalue)

 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 (defun compilobj_nrep_definedconstant (ndconst gcx)
   (debug "compilobj definedconstant ndconst=" ndconst " gcx=" gcx)
   (assert_msg "check gcx" (is_a gcx class_initial_generation_context) gcx)
   (assert_msg "check ndconst" (is_a ndconst class_nrep_defined_constant) ndconst)
   (let ( (nsval (unsafe_get_field :nconst_sval ndconst))
	  (nloc (unsafe_get_field :nrep_loc ndconst))
	  (locmap (unsafe_get_field :gncx_locmap gcx))
	  (ndefbnd (unsafe_get_field :nconst_defbind ndconst))
	  (ovloc (mapobject_get locmap ndefbnd))
	  (nproc (unsafe_get_field :nconst_proc ndconst))
	  )
     (debug "compilobj definedconstant ndefbnd=" ndefbnd " nloc=" nloc " ovloc=" ovloc " nproc=" nproc)
     (assert_msg "compilobj definedconstant check ovloc" ovloc)
     (return ovloc)
     ))
 (install_method class_nrep_defined_constant compile_obj compilobj_nrep_definedconstant)

 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;; compile a quasiconstant
 (defun compilobj_nrep_quasiconstant (nconst gcx)
   (debug "compilobj quasiconstant nconst=" nconst)
   (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
   (assert_msg "check nconst" (is_a nconst class_nrep_quasiconstant) nconst)
   (let ( (nloc (unsafe_get_field :nrep_loc nconst))
	  (sval (unsafe_get_field :nconst_sval nconst))
	  (data (unsafe_get_field :nconst_data nconst))
	  (proc (unsafe_get_field :nconst_proc nconst))
	  )
     (if (is_a proc class_nrep_routproc)
	 (let ( (constlist (get_field :nrclop_constlist proc)) 
		(curpair (list_first constlist))
		(:long coff -1)
		(:long curank 0)
		(nambuf (make_strbuf discr_strbuf))
		)
	   (forever 
	    constloop
	    (if (is_pair curpair)
		(let ((curconst (pair_head curpair)))
		  (if (== curconst data)
		      (progn
			(setq coff curank)
			(exit constloop)))
		  )
	      (exit constloop))
	    (setq curpair (pair_tail curpair))
	    (setq curank (+i curank 1))
	    )
	   (assert_msg "check coff" (>=i coff 0) coff)
	   (add2sbuf_strconst nambuf "konst_")
	   (add2sbuf_longdec nambuf coff)
	   (if (is_a sval class_named)
	       (progn
		 (add2sbuf_strconst nambuf "_")
		 (add2sbuf_cident nambuf (unsafe_get_field :named_name sval))
		 )
	     )
	   (let ( (constv 
		   (instance class_objconstv
			     :obv_type ctype_value
			     :obc_off (make_integerbox discr_integer coff)
			     :obc_proc proc
			     :obc_name (strbuf2string discr_string nambuf)
			     )) )
	     (debug "compilobj quasiconstant constv=" constv)
	     (return constv)
	     )
	   )
       (let ( (odata (compile_obj data gcx)) )
	 ;; not inside a proc, just return the compiled data
	 (debug "compilobj quasiconstant odata=" odata)
	 (return odata)
	 )
       )
     )
   )
 (install_method class_nrep_quasiconstant compile_obj compilobj_nrep_quasiconstant)

 (defun compilobj_nrep_quasiconst_current_module_environment_reference (nqcme gcx)
   (debug "compilobj_nrep_quasiconst_current_module_environment_reference start nqcme=" nqcme)
   (assert_msg "check nqme" (is_a nqcme class_nrep_quasiconst_current_module_environment_reference) nqcme)
   (let ( (onres (compilobj_nrep_quasiconstant nqcme gcx))
	  (scomm (unsafe_get_field :nqcmec_comment nqcme))
	  (str (let ( (sbuf (make_strbuf discr_strbuf)) )
		 (add2sbuf_strconst sbuf "/*quasi.cur.mod.env.ref ")
		 (add2sbuf_ccomstring sbuf scomm)
		 (add2sbuf_strconst sbuf "*/\n")
		 (strbuf2string discr_verbatim_string sbuf)
		 )
	       )
	  (olres (make_objlocatedexp 
		  (unsafe_get_field :nrep_loc nqcme)
		  ctype_value
		  str 
		  ##{ /* check quasi.cur.mod.env.ref $(obj_hash nqcme) */ 
                  ($ONRES)
		  }#))
	  )
     (debug "compilobj_nrep_quasiconstant_current_module_environment_reference result olres=" olres)
     (return olres)
     ))
 (install_method class_nrep_quasiconst_current_module_environment_reference compile_obj
		 compilobj_nrep_quasiconst_current_module_environment_reference)
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;; compile a forever
 (defun compilobj_nrep_forever (nfor gcx)
   (debug "compilobj_nrep_forever nfor=" nfor)
   (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
   (assert_msg "check nfor" (is_a nfor class_nrep_forever) nfor)
   (let ( (nloc (unsafe_get_field :nrep_loc nfor))
	  (nbind (unsafe_get_field :nforever_bind nfor))
	  (nbody (unsafe_get_field :nforever_body nfor))
	  (nres (unsafe_get_field :nforever_result nfor)) 
	  (oresv (get_free_objlocptr gcx nres))
	  )
     (assert_msg "check nbind" (is_a nbind class_label_binding) nbind)
     (debug "compilobj_nrep_forever oresv=" oresv)
     (assert_msg "check oresv" (is_a oresv class_objlocv) oresv)
     (unsafe_put_fields nbind :labind_res oresv)
     (assert_msg "check again nbind" (is_object nbind) nbind)
     (debug "compilobj_nrep_forever updated nbind=" nbind)
     (let ( (closy (unsafe_get_field :labind_clonsy nbind)) 
	    (bodyl (make_list discr_list))
	    (epilogl (make_list discr_list))
	    (oloop (instance class_objloop
			     :obi_loc nloc
			     :oblo_bodyl bodyl
			     :oblo_epil epilogl
			     :obloop_label closy
			     :obloop_resv oresv))
	    )
       (assert_msg "check closy" (is_a closy class_cloned_symbol) closy)
       (multiple_every
	nbody
	(lambda (ncomp :long ix)
	  (list_append bodyl (compile_obj ncomp gcx))))
       (debug "compilobj forever result oloop=" oloop)
       oloop
       )
     )  
   )
 (install_method class_nrep_forever compile_obj compilobj_nrep_forever)

 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;; compile an exit
 (defun compilobj_nrep_exit (nexi gcx)
   (debug "compilobj_nrep_exit nexi=" nexi)
   (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
   (assert_msg "check nexi" (is_a nexi class_nrep_exit) nexi)
   (let ( 
	 (nloc (unsafe_get_field :nrep_loc nexi))
	 (nbindx (unsafe_get_field :nexit_bind nexi))
	 (nval (unsafe_get_field :nexit_val nexi)) 
	 )
     (assert_msg "check nbindx" (is_a nbindx class_label_binding) nbindx)
     (let ( 
	   (inslist (make_list discr_list)) 
	   (epilist (make_list discr_list)) 
	   (destlist (make_list discr_list))
	   (oval (compile_obj nval gcx))
	   (bxres (unsafe_get_field :labind_res nbindx))
	   (obloc (instance class_objplainblock
			    :obi_loc nloc
			    :oblo_bodyl inslist
			    :oblo_epil epilist
			    ))
	   (obex (instance class_objexit
			   :obi_loc nloc
			   :obexit_label (unsafe_get_field :labind_clonsy nbindx)
			   )) 
	   (obcom (instance class_objcompute
			    :obi_loc nloc
			    :obdi_destlist destlist
			    :obcpt_type ctype_value
			    :obcpt_expr oval))
	   )
       (list_append inslist obcom)
       (list_append epilist obex)
       (list_append destlist bxres)
       (debug "compilobj_nrep_exit return obloc=" obloc)
       (return obloc)
       )))
 (install_method class_nrep_exit compile_obj compilobj_nrep_exit)

 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;; compile an again
 (defun compilobj_nrep_again (nag gcx)
   (debug "compilobj_nrep_again nag=" nag)
   (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
   (assert_msg "check nag" (is_a nag class_nrep_again) nag)
   (let ( 
	 (nloc (unsafe_get_field :nrep_loc nag))
	 (nlabind (unsafe_get_field :nagain_bind nag))
	 (oagain (instance class_objagain
			   :obi_loc nloc 
			   :obagain_label (get_field :labind_clonsy nlabind)
			   ))
	 )
     (assert_msg "check nlabind" (is_a nlabind class_label_binding) nlabind)
     (debug "compilobj_nrep_again return oagain=" oagain)
     (return oagain)
 ))
 (install_method class_nrep_again compile_obj compilobj_nrep_again)



 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 (defun compilobj_discrany (anyv gcx)
   (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
   anyv
   )
 (install_method discr_any_receiver compile_obj compilobj_discrany)



 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 (defun compilobj_nrep_let (rlet gcx)
   (debug "compilobj_nrep_let initial rlet=" rlet)
   (assert_msg "check rlet" (is_a rlet class_nrep_let) rlet)
   (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
   (let ( (loc (unsafe_get_field :nrep_loc rlet))
	  (bnds (unsafe_get_field :nlet_bindings rlet))
	  (bdy (unsafe_get_field :nlet_body rlet))
	  (locmap (unsafe_get_field :gncx_locmap gcx))
	  (obodl (make_list discr_list))
	  (oepil (make_list discr_list))
	  (oblock (instance class_objplainblock
			    :obi_loc loc
			    :oblo_bodyl obodl
			    :oblo_epil oepil))
	  )
     (debug "compilobj_nrep_let initial loc=" loc "\n.. bnds=" bnds 
	    "\n.. bdy=" bdy
	    "\n.. locmap=" locmap)
     (shortbacktrace_dbg "compilobj_nrep_let" 9)
     ;; for each normalexp in the bnds tuple
     ;; add the binding and the setting in the body and the clear in the epilogue
     (assert_msg "compilobj_nrep_let check bnds multiple" (is_multiple_or_null bnds) bnds)
     ;; iterate on normal bindings
     (foreach_in_multiple
      (bnds)
      (nlbnd :long bndix)
      (debug "compilobj_nrep_let current normbinding loc=" loc " nlbnd=" nlbnd " locmap=" locmap)
      (assert_msg "check nlbnd in compilobj_nrep_let" (is_a nlbnd class_normal_let_binding) nlbnd)
      (let ( (bder (unsafe_get_field :binder nlbnd))
	     (cty (unsafe_get_field :letbind_type nlbnd))
	     (nexp (unsafe_get_field :letbind_expr nlbnd))
	     (obva (get_free_objloctyped gcx bder cty))
	     )
	(debug "compilobj_nrep_let current normbinding obva=" obva "\n nexp=" nexp)
	(let ( (obnx (compile_obj nexp gcx)) )
	  (debug "compilobj_nrep_let current normbinding obnx=" obnx
		 "\n.. for nexp=" nexp "\n.. with obva=" obva)
	  (if (is_a nexp class_sexpr) 
	      (when (not (is_object obnx))
		    (debug "compilobj_nrep_let current normbinding faulty nexp=" nexp " obnx=" obnx)
		    (assert_msg "compilobj_nrep_let check obnx" (is_object obnx) obnx nexp)))
	  (cond
	   ( obva
	     ;; non void cty
	     (mapobject_put locmap nlbnd obva)
	     (debug "compilobj_nrep_let obnx=" obnx 
		    "\n nlbnd=" nlbnd 
		    "\n obva=" obva)
	     (let ( (obpd (put_objdest obnx obva)) 
		    (obmy (or obpd obnx))
		    )
	       (debug "compilobj_nrep_let current obpd=" obpd " obmy=" obmy)
	       (list_append obodl obmy)
	       ))
	    (:else
	      ;; obva is nil when cty is void type 
	      (debug "compilobj_nrep_let append obnx=" obnx)
	      (list_append obodl obnx)
	      ))
	  ;; add clearing of obva to epilogue part of oblock
	  (if obva 
	      (let ( (obcl (instance class_objclear
				     :obi_loc loc
				     :oclr_vloc obva)) 
		     )
		(list_append oepil obcl)
		)))))
     (debug "compilobj_nrep_let after iterate normbind loc=" loc 
	    "\n.. locmap=" locmap "\n.. oepil=" oepil)
     ;;
     ;; compile each body component
     (assert_msg "check bdy" (is_multiple_or_null bdy) bdy)
     (foreach_in_multiple
      (bdy)
      (bdycomp :long bdyix)
      (debug "compilobj_nrep_let body loc=" loc 
	     " bdycomp=" bdycomp " bdyix=" bdyix)
      (let ( (objcomp  (compile_obj bdycomp gcx)) 
	     )
	(debug "compilobj_nrep_let body objcomp=" objcomp)
	;; objcomp is null when compiling a locvar of ctype_void;
	;; this happens with primitive of :void type
	(if (null objcomp) 
	    (void)
	  (list_append obodl objcomp))))
     (debug "compilobj_nrep_let after iterate body loc=" loc)
     ;;
     ;; dispose each binding
     (debug "compilobj_nrep_let disposing bnds=" bnds "\n.. with bdy=" bdy
	    "\n.. obodl=" obodl "\n.. locmap=" locmap "\n... loc=" loc)
     ;; @@@??? perhaps we should avoid disposing the binding of the
     ;; last component of tuple bdy, if it is its locsymocc...
     (foreach_in_multiple
      (bnds)
      (obnd :long ix)
      (debug "compilobj_nrep_let dispose loc=" loc " obnd=" obnd " ix=" ix)
      (dispose_bnd_obj obnd gcx))
     (debug "compilobj_nrep_let done disposal bnds=" bnds "\n.. locmap=" locmap "\n... loc=" loc)
     (debug "compilobj_nrep_let final loc=" loc " locmap=" locmap " oblock=" oblock)
     (return oblock)			;return it
     ))

 (install_method class_nrep_let compile_obj compilobj_nrep_let)

 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;; selector to compile the fill inside a letrec
 ;;; receiver: the normalized constructrive binding
 ;;; arguments: 
 ;;;; * GCX the code generation context
 ;;; result = the obj instruction or value

 (defselector compile_letrec_fill class_selector
   :doc #{The selector $COMPILE_LETREC_FILL is used to compile the fill
   for a $LETREC. The $RECV is usually a constructive binding. $OBVA is
   the object variable, and $OBODL is the list for the body, $GCX being
   the generation context. $SLOC is the source location.}#
   :formals (recv obva obodl gcx sloc)
   )
 (export_values compile_letrec_fill)

 (defun fail_compiletrecfill (recv obva obodl gcx sloc)
   (debug "fail_compiletrecfill recv=" recv " obva=" obva)
   (let ( (d (discrim recv)) )
     (error_strv sloc "unimplemented discriminant for compile_letrec_fill"
		 (get_field :named_name d))
     (assert_msg "fail_compiletrecfill unexpected" () recv)
 ))
 (install_method discr_any_receiver compile_letrec_fill fail_compiletrecfill)

 ;;;;;;;;;;;;;;;;
 ;; generate inside the body list the code for filling lambda in letrecs
 (defun compiletrec_lambda (recv obva obodl gcx sloc)
   (debug "compiletrec_lambda recv=" recv " obva=" obva)
   (assert_msg "check recv" (is_a recv class_normal_constructed_lambda_binding) recv)
   (assert_msg "check obva" (is_a obva class_objlocv) obva)
   (assert_msg "check obodl" (is_list obodl) obodl)
   (let ( (loc (or (get_field :nconsb_loc recv) sloc))
	  (nclosed (get_field :nlambdab_nclosed recv))
	  (nconstrout (get_field :nlambdab_constrout recv))
	  (otouch (instance class_objtouch
			    :obi_loc loc
			    :otouch_val obva
			    ))
	  (ocrout (compile_obj nconstrout gcx))
	  (oputrout (instance class_objputclosurout
			      :obi_loc loc
			      :opclor_clos obva
			      :opclor_rout ocrout
			      ))
	  )
     (debug "compiletrec_lambda oputrout=" oputrout)
     (list_append obodl oputrout)
     ;;
     (debug "compiletrec_lambda nclosed=" nclosed)
     (foreach_in_multiple 
      (nclosed) 
      (curclosed :long curix)
      (debug "compiletrec_lambda curclosed=" curclosed " curix=" curix)
      (let ( (oclosed (compile_obj curclosed gcx)) 
	     )
	(debug "compiletrec_lambda oclosed=" oclosed)
	(cond ( (or (is_not_a oclosed class_objpurevalue)
		    (is_a oclosed class_objinstr))
		(if (>i curix 0)
		    (list_append obodl otouch))
		(list_append obodl oclosed) 
		)
	      (:else
	       (debug "compiletrec_lambda ignored generated code oclosed=" oclosed))
	      )
	(let ( 	    
	      (oputclo (instance class_objputclosedv
				 :obi_loc loc
				 :opclov_clos obva
				 :opclov_off (make_integerbox discr_integer curix)
				 :opclov_cval oclosed
				 )) 
	      )
	  (debug "compiletrec_lambda oputclo=" oputclo)
	  (list_append obodl oputclo)
	  ))
      )
     (list_append obodl otouch)
     (debug "compiletrec_lambda final obodl=" obodl)
     ))
 (install_method class_normal_constructed_lambda_binding compile_letrec_fill compiletrec_lambda)



 ;; generate inside the body list the code for filling tuple in letrecs
 (defun compiletrec_tuple (recv obva obodl gcx sloc)
   (debug "compiletrec_tuple recv=" recv " obva=" obva)
   (assert_msg "check recv" (is_a recv class_normal_constructed_tuple_binding) recv)
   (assert_msg "check obva" (is_a obva class_objlocv) obva)
   (assert_msg "check obodl" (is_list obodl) obodl)
   (let ( (loc (or (get_field :nconsb_loc recv) sloc))
	  (ncomptup (get_field :ntupb_comp recv))
	  (otouch (instance class_objtouch
			    :obi_loc loc
			    :otouch_val obva
			    ))
	  )
     (debug "compiletrec_tuple ncomptup=" ncomptup)
     (foreach_in_multiple
      (ncomptup)
      (ncurcomp :long ix)
      (debug "compiletrec_tuple ncurcomp=" ncurcomp " ix=" ix)
      (let ( (ocomp (compile_obj ncurcomp gcx)) 
	     (oputn (instance class_objputuple
			      :obi_loc loc
			      :oputu_tupled obva
			      :oputu_offset (make_integerbox discr_integer ix)
			      :oputu_value ocomp
			      ))
	     )
	(debug "compiletrec_tuple ocomp=" ocomp)
	(cond ( (or (is_not_a ocomp class_objpurevalue)
		    (is_a ocomp class_objinstr))
		(list_append obodl otouch)
		(list_append obodl ocomp)
		)
	      (:else 
	       (debug "compiletrec_tuple ignored generated code ocomp=" ocomp))
	      )
	(list_append obodl oputn)
	))
     (list_append obodl otouch)
     (debug "compiletrec_tuple final obodl=" obodl)
     ))
 (install_method class_normal_constructed_tuple_binding compile_letrec_fill compiletrec_tuple)


 ;; generate inside the body list the code for filling pair in letrecs
 (defun compiletrec_pair (recv obva obodl gcx sloc)
   (debug "compiletrec_pair recv=" recv " obva=" obva)
   (assert_msg "check recv" (is_a recv class_normal_constructed_pair_binding) recv)
   (assert_msg "check obva" (is_a obva class_objlocv) obva)
   (assert_msg "check obodl" (is_list obodl) obodl)
   (let ( (loc (or (get_field :nconsb_loc recv) sloc))
	  (nhead (get_field :npairb_head recv))
	  (ntail (get_field :npairb_tail recv))
	  (ohead (compile_obj nhead gcx))
	  (otail (if ntail (compile_obj ntail gcx)))
	  (oputhead (instance class_objputpairhead
			      :obi_loc loc
			      :oputp_pair obva
			      :oputp_head ohead))
	  (oputtail (if otail (instance class_objputpairtail
					:obi_loc loc
					:oputp_pair obva
					:oputp_tail otail)))
	  (otouch (instance class_objtouch
			    :obi_loc loc
			    :otouch_val obva
			    ))
	  )
     (debug "compiletrec_pair nhead=" nhead " ohead=" ohead
	    " ntail=" ntail " otail=" otail)
     (if (or (is_not_a ohead class_objpurevalue) 
	     (is_a ohead class_objinstr))
	 (list_append obodl ohead)
       (debug "compiletrec_pair ohead ignored generated code ohead=" ohead))
     (if (and otail (or (is_not_a otail class_objpurevalue) 
			(is_a otail class_objinstr)))
	 (list_append obodl otail)
       (debug "compiletrec_pair otail ignored generated code otail=" otail))
     (list_append obodl oputhead)
     (if oputtail (list_append obodl oputtail))
     (list_append obodl otouch)
     ))
 (install_method class_normal_constructed_pair_binding compile_letrec_fill compiletrec_pair)

 ;; generate inside the body list the code for filling pair in letrecs
 (defun compiletrec_list (recv obva obodl gcx sloc)
   (debug "compiletrec_list recv=" recv " obva=" obva)
   (assert_msg "check recv" (is_a recv class_normal_constructed_list_binding) recv)
   (assert_msg "check obva" (is_a obva class_objlocv) obva)
   (assert_msg "check obodl" (is_list obodl) obodl)
   (let ( (loc (or (get_field :nconsb_loc recv) sloc))
	  (nfirst (get_field :nlistb_first recv))
	  (nlast (get_field :nlistb_last recv))
	  (ofirst (if nfirst (compile_obj nfirst gcx)))
	  (olast (if nlast (compile_obj nlast gcx)))
	  (oputl (if (or ofirst olast)
		     (instance class_objputlist
			       :obi_loc loc
			       :oputl_list obva
			       :oputl_first ofirst
			       :oputl_last olast
			       )))
	  (otouch (instance class_objtouch
			    :obi_loc loc
			    :otouch_val obva
			    ))
	  )
     (if (and ofirst (or (is_not_a ofirst class_objpurevalue) (is_a ofirst class_objinstr)))
	 (list_append obodl ofirst)
       (debug "compiletrec_list ignored generated code ofirst=" ofirst)
       )
     (if (and olast (or  (is_not_a olast class_objpurevalue)
			 (is_a olast class_objinstr)))
	 (list_append obodl olast)
       (debug "compiletrec_list olast ignored generated code olast=" olast)
       )
     (if oputl 
	 (progn 
	   (list_append obodl oputl)
	   (list_append obodl otouch)
	   ))
     ))
 (install_method class_normal_constructed_list_binding compile_letrec_fill compiletrec_list)


 ;; generate inside the body list the code for filling instance in letrecs
 (defun compiletrec_instance (recv obva obodl gcx sloc)
   (debug recv "compiletrec_instance recv=" recv " obva=" obva " obodl=" obodl)
   (assert_msg "check recv" (is_a recv class_normal_constructed_instance_binding) recv)
   (assert_msg "check obva" (is_a obva class_objlocv) obva)
   (assert_msg "check obodl" (is_list obodl) obodl)
   (let ( (loc (or (get_field :nconsb_loc recv) sloc))
	  (nslots (get_field :ninstb_slots recv))
	  (nclabind (get_field :ninstb_clabind recv))
	  (otouch (instance class_objtouch
			    :obi_loc loc
			    :otouch_val obva
			    ))
	  (clas (cond ( (is_a nclabind class_value_binding)
			(unsafe_get_field :vbind_value nclabind))
		      ( (is_a nclabind class_class_binding)
			(unsafe_get_field :cbind_class nclabind))
		      (:else
		       (debug "compiletrec_instance bad nclabind=" nclabind)
		       (assert_msg "unexpected class binding" () nclabind))))
	  (flds (get_field :class_fields clas))
	  )
     (debug "compiletrec_instance clas=" clas " nslots=" nslots)
     (assert_msg "check clas" (is_a clas class_class) clas)
     (foreach_in_multiple
      (nslots)
      (curnslot :long slix)
      (debug "compiletrec_instance curnslot=" curnslot " slix=" slix)
      (if curnslot
	  (let ( (curfld (multiple_nth flds slix)) 
		 (oslot (compile_obj curnslot gcx))
		 )
	    (debug "compiletrec_instance curfld=" curfld " oslot=" oslot)
	    (if (or (is_not_a oslot class_objpurevalue)
		    (is_a oslot class_objinstr))
		(progn
		  (if (>i slix 0) (list_append obodl otouch))
		  (list_append obodl oslot))
	      (debug "compiletrec_instance ignored generated code oslot=" oslot))
	    (let ( (oputs (instance class_objputslot
				    :obi_loc loc
				    :oslot_odata obva
				    :oslot_offset (make_integerbox discr_integer slix)
				    :oslot_field curfld
				    :oslot_value oslot))
		   )
	      (debug "compiletrec_instance oputs=" oputs)
	      (list_append obodl oputs)
	      )))) 
     (list_append obodl otouch)
     (debug "compiletrec_instance final obodl=" obodl)
     ))
 (install_method class_normal_constructed_instance_binding compile_letrec_fill compiletrec_instance)

 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;; compile of LETREC
 (defun compilobj_nrep_letrec (rlet gcx)
   (debug "compilobj_nrep_letrec initial rlet=" rlet)
   (assert_msg "check rlet" (is_a rlet class_nrep_letrec) rlet)
   (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
   (let ( (loc (unsafe_get_field :nrep_loc rlet))
	  (bnds (unsafe_get_field :nlet_bindings rlet))
	  (fillbnds (unsafe_get_field :nletrec_fill_bindings rlet))
	  (bodybnds (unsafe_get_field :nletrec_body_bindings rlet))
	  (:long nbbnds (multiple_length bnds))
	  (nlocsyms (unsafe_get_field :nletrec_locsyms rlet))
	  (:long nblocsym (multiple_length nlocsyms))
	  (tuploc (make_multiple discr_multiple nblocsym))
	  (nbdy (unsafe_get_field :nlet_body rlet))
	  (locmap (unsafe_get_field :gncx_locmap gcx))
	  (obodl (make_list discr_list))
	  (oepil (make_list discr_list))
	  (ofreelocs (make_list discr_list))
	  (obrout (get_field :gncx_objrout gcx))
	  (obcntletrec (get_field :obrout_cntletrec obrout))
	  (:long cntletrec (+i 1 (get_int obcntletrec)))
	  (oallstruct (make_multiple discr_multiple nbbnds))
	  (namstr 
	   (let ( (nambuf (make_strbuf discr_strbuf)) )
	     (add2sbuf_strconst nambuf "meltletrec_")
	     (add2sbuf_longdec nambuf cntletrec)
	     (strbuf2string discr_verbatim_string nambuf)
	     ))
	  (oblock (instance class_objmultiallocblock
			    :obi_loc loc
			    :oblo_bodyl obodl
			    :oblo_epil oepil
			    :omalblo_allstruct oallstruct
			    :omalblo_name namstr
			    ))
	  )
     (debug "compilobj_nrep_letrec initial loc=" loc "\n.. nlocsyms=" nlocsyms 
	    "\n.. fillbnds=" fillbnds "\n.. bodybnds=" bodybnds "\n locmap=" locmap)
     (assert_msg "check fillbnds is list" (is_list_or_null fillbnds) fillbnds)
     (assert_msg "check bodybnds is list" (is_list_or_null bodybnds) bodybnds)
     (put_int obcntletrec cntletrec)
     (debug "compilobj_nrep_letrec updated obcntletrec=" obcntletrec)
     (foreach_in_multiple
      (nlocsyms)
      (curlocsym :long symix)
      (debug "compilobj_nrep_letrec curlocsym=" curlocsym " symix=" symix)
      (assert_msg "check curlocsym" (is_a curlocsym class_nrep_locsymocc) curlocsym)
      (let ( (curobva (get_free_objloctyped gcx (get_field :nocc_symb curlocsym) ctype_value))
	     (ocurclear (instance class_objclear
				  :obi_loc loc
				  :oclr_vloc curobva))
	     (cursbnd (multiple_nth bnds symix))
	     )
	(debug "compilobj_nrep_letrec again curlocsym=" curlocsym 
	       " curobva=" curobva " cursbnd=" cursbnd " ocurclear=" ocurclear " symix=" symix)
	(multiple_put_nth tuploc symix curobva)
	(mapobject_put locmap cursbnd curobva)
	(list_append oepil ocurclear)
	(list_append ofreelocs curobva)
	)
      )
     ;;
     (debug "compilobj_nrep_letrec locmap=" locmap " oblock=" oblock " ofreelocs=" ofreelocs " bnds=" bnds)
     (foreach_in_multiple
      (bnds)
      (curbnd :long bndix)
      (debug "compilobj_nrep_letrec curbnd=" curbnd " bndix=" bndix)
      (let ( (obnd (compile_obj curbnd gcx)) 
	     )
	(debug "compilobj_nrep_letrec obnd=" obnd)
	(multiple_put_nth oallstruct bndix obnd)
	(list_append obodl obnd)
	(debug "compilobj_nrep_letrec updated obodl=" obodl)
	)
      )
     ;; 
     ;; maybe we should reserve the recobva before compiling nrecexp
     (debug "compilobj_nrep_letrec fillbnds" fillbnds)
     (assert_msg "check fillbnds" (is_list_or_null fillbnds) fillbnds)
     ;; first loop to reserve the recobva
     (foreach_pair_component_in_list
      (fillbnds)
      (curecpair curecbnd)
      (debug "compilobj_nrep_letrec  get_free_objloc curecbnd=" curecbnd)
      (assert_msg "check curecbnd" (is_a curecbnd class_normal_let_binding) curecbnd)
      (let ( (rbder (unsafe_get_field :binder curecbnd))
	     (rcty (unsafe_get_field :letbind_type curecbnd))
	     (rloc (unsafe_get_field :letbind_loc curecbnd))
	     (recobva (get_free_objloctyped gcx rbder rcty))
	     )
	(debug "compilobj_nrep_letrec current normbinding recobva=" recobva)
	;; recobva can be nil when rcty is :void
	(if recobva
	    (let (
		  (oreclear (instance class_objclear
				      :obi_loc (or rloc loc)
				      :oclr_vloc recobva
				      ))
		  )
	      (assert_msg "check recobva" (is_a recobva class_objlocv) recobva)
	      (mapobject_put locmap curecbnd recobva)
	      (debug "compilobj_nrep_letrec oreclear=" oreclear)
	      (list_append oepil oreclear)
	      (list_append ofreelocs recobva)
	      ))))
     (debug "compilobj_nrep_letrec again locmap=" locmap " ofreelocs=" ofreelocs " fillbnds=" fillbnds)
     ;;
     ;; loop to compile the fillbindings
     (foreach_pair_component_in_list
      (fillbnds)
      (curecpair curfilbnd)
      (debug "compilobj_nrep_letrec compil curfilbnd=" curfilbnd)
      (assert_msg "check curfilbnd" (is_a curfilbnd class_normal_let_binding) curfilbnd)
      (let ( (rbder (unsafe_get_field :binder curfilbnd))
	     (rcty (unsafe_get_field :letbind_type curfilbnd))
	     (nrecexp (unsafe_get_field :letbind_expr curfilbnd))
	     (recobva (mapobject_get locmap curfilbnd))
	     )
	(debug "compilobj_nrep_letrec current recbinding nrecexp=" nrecexp)
	(let ( (robnx (compile_obj nrecexp gcx)) 
	       (rnewob ())
	       )
	  (debug "compilobj_nrep_letrec robnx=" robnx)
	  (if recobva
	      (setq rnewob (put_objdest robnx recobva))
	    (setq rnewob robnx))
	  (debug "compilobj_nrep_letrec rnewob=" rnewob)
	  (if (or (is_not_a rnewob class_objpurevalue)
		  (is_a rnewob class_objinstr))
	      (list_append obodl rnewob)
	    (debug "compilobj_nrep_letrec ignored generated code rnewob=" rnewob)
	    )
	  ))
      )
 ;;;
      (debug "compilobj_nrep_letrec after fillbinding obodl=" obodl)
 ;;;
 ;;; generate the fill of the letrec-ed constructions
     (foreach_in_multiple
      (bnds)
      (curbnd :long bndix)
      (let ( (obva (multiple_nth tuploc bndix))
	     )
	(debug "compilobj_nrep_letrec again obva=" obva " curbnd=" curbnd " bndix=" bndix)
	(compile_letrec_fill curbnd obva obodl gcx loc)
	(debug "compilobj_nrep_letrec letrecfilled obodl=" obodl)
	))
     ;;
     (debug "compilobj_nrep_letrec oallstruct=" oallstruct " obodl=" obodl)
     ;; loop to compile the bodybindings
     (foreach_pair_component_in_list
      (bodybnds)
      (cubdypair curbdybnd)
      (debug "compilobj_nrep_letrec compil curbdybnd=" curbdybnd)
      (assert_msg "check curbdybnd" (is_a curbdybnd class_normal_let_binding) curbdybnd)
      (let ( (rbder (unsafe_get_field :binder curbdybnd))
	     (rcty (unsafe_get_field :letbind_type curbdybnd))
	     (nbdyexp (unsafe_get_field :letbind_expr curbdybnd))
	     (bdyobva (get_free_objloctyped gcx rbder rcty))
	     (rloc (unsafe_get_field :letbind_loc curbdybnd))
	     )
	(debug "compilobj_nrep_letrec body bdyobva="bdyobva " nbdyexp=" nbdyexp)
	(mapobject_put locmap curbdybnd bdyobva)
	(let ( (robnx (compile_obj nbdyexp gcx)) 
	       (rnewob ())
	       )
	  (if (and bdyobva rcty (!= rcty ctype_void))
	      (progn
		(list_append ofreelocs bdyobva)
		(setq rnewob (put_objdest robnx bdyobva))
		)
	    (setq rnewob robnx))
	  (debug "compilobj_nrep_letrec rnewob=" rnewob)
	  (if (or (is_not_a rnewob class_objpurevalue)
		  (is_a rnewob class_objinstr))
	      (list_append obodl rnewob)
	    (debug "compilobj_nrep_letrec ignored generated code rnewob=" rnewob)
	    )
	  ))
      )
     ;;
     ;; compile the body
     (debug  "compilobj_nrep_letrec nbdy=" nbdy)
     (assert_msg "check nbdy" (is_multiple_or_null nbdy) nbdy)
     (foreach_in_multiple
      (nbdy)
      (curbdy :long bdix)
      (debug "compilobj_nrep_letrec curbdy=" curbdy " bdix=" bdix)
      (let ( (ocurb (compile_obj curbdy gcx)) )
	(debug "compilobj_nrep_letrec ocurb=" ocurb)
	(list_append obodl ocurb)))
     (debug "compilobj_nrep_letrec final obodl=" obodl "\n.. ofreelocs=" ofreelocs)
     ;; should clear and free our objlocs...
     (foreach_pair_component_in_list
      (ofreelocs)
      (curlpair curlocva)
      (debug "compilobj_nrep_letrec disposing curlocva=" curlocva)
      (assert_msg "check curlocva" (is_a curlocva class_objlocv) curlocva)
      (let ( (oclear (instance class_objclear
			       :obi_loc loc
			       :oclr_vloc curlocva))
	     )
	(list_append oepil oclear)
	(debug "compilobj_nrep_letrec oclear=" oclear " \n..disposing curlocva=" curlocva)
	(dispose_objloc curlocva gcx)
	(debug "compilobj_nrep_letrec final oclear=" oclear)
	))
     ;;
     (debug "compilobj_nrep_letrec final oblock=" oblock "\n.. oallstruct= "oallstruct
	    "\n.. gcx=" gcx "\n")
     oblock
     ))
 (install_method class_nrep_letrec compile_obj compilobj_nrep_letrec)

 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

 (defun compilobj_nrep_citeration (nciter gcx)
   (assert_msg "check nciter" (is_a nciter class_nrep_citeration) nciter)
   (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
   (debug "compilobj_nrep_citeration nciter=" nciter)
   (let ( (loc (unsafe_get_field :nrep_loc nciter))
	  (obrout (unsafe_get_field :gncx_objrout gcx))
	  (citer (unsafe_get_field :nciter_citerator nciter))
	  (nlocbind (unsafe_get_field :nciter_locbindings nciter))
	  (nchkbef (unsafe_get_field :nciter_chunkbefore nciter))
	  (nstatocc (let ( (ns (unsafe_get_field :nciter_statocc nciter)) ) 
		      (debug "compilobj_nrep_citeration nstatocc=" ns)
		      (assert_msg "check nstatocc" (is_a ns class_nrep_locsymocc) ns)
		      ns))
	  (nbody (unsafe_get_field :nciter_body nciter))
	  (nbodbind (unsafe_get_field :nciter_bodbindings nciter))
	  (nchkaft (unsafe_get_field :nciter_chunkafter nciter))
	  (nstatbind (let ( (bi (unsafe_get_field :nocc_bind nstatocc)) )
		       (assert_msg "check nstatbind" (is_a bi class_normal_let_binding) bi)
		       bi))
	  (nstatsy (unsafe_get_field :binder nstatbind))
	  (ostat (get_free_objloctyped gcx nstatsy (unsafe_get_field :nocc_ctyp nstatocc)))
	  (obodl (make_list discr_list))
	  (oepil (make_list discr_list))
	  (ocblock (instance class_objciterblock
			     :obi_loc loc
			     :oblo_bodyl obodl
			     :oblo_epil oepil
			     :obciter_citer citer
			     :obciter_before ()
			     :obciter_after ()
			     ))
	  (locmap  (unsafe_get_field  :gncx_locmap gcx))
	  )
     (debug "compilobj_nrep_citeration ostat=" ostat " nlocbind=" nlocbind)
     (assert_msg "check citer" (is_a citer class_citerator) citer)
     (assert_msg "check locmap" (is_mapobject locmap) locmap)
     (assert_msg "check nlocbind" (is_multiple_or_null nlocbind) nlocbind)
     (multiple_every
      nlocbind
      (lambda (nlbnd :long ix)
	(debug "compilobj_nrep_citeration current nlocbinding nlbnd=" nlbnd " ix=" ix)
	(assert_msg "check nlbnd in compilobj_nrep_citeration" (is_a nlbnd class_normal_let_binding) nlbnd)
	(let ( (bder (unsafe_get_field :binder nlbnd))
	       (cty (unsafe_get_field :letbind_type nlbnd))
	       (nexp (unsafe_get_field :letbind_expr nlbnd))
	       (oblva (get_free_objloctyped gcx bder cty))
	       )
	  (debug "compilobj_nrep_citeration current local bder=" bder " oblva=" oblva)
	  (if (!= cty ctype_void)
	      (let ( (oclr (instance class_objclear
				     :obi_loc loc
				     :oclr_vloc oblva) ) )
		(list_append oepil oclr)
		(mapobject_put locmap nlbnd oblva)
		(debug "compilobj_nrep_citeration added clear for nlbnd=" nlbnd)
		))
	  )))
     (debug "compilobj_nrep_citeration start ocblock=" ocblock)
     (let ( (boxcntciter (unsafe_get_field :obrout_cntciter obrout))
	    (:long cnt (+i 1 (get_int boxcntciter)))
	    (statstr 
	     (let ( (sbu (make_strbuf discr_strbuf)) )
	       (put_int boxcntciter cnt)
	       (add2sbuf_strconst sbu "meltcit")
	       (add2sbuf_longdec sbu cnt)
	       (add2sbuf_strconst sbu "__")
	       (add2sbuf_cident sbu (unsafe_get_field :named_name nstatsy))
	       (strbuf2string discr_verbatim_string sbu)
	       ))
	    )
       (unsafe_put_fields 
	ocblock
	:obciter_before (multiple_map 
			 nchkbef 
			 (lambda (cbef :long ix)
			   (cond 
			    ((is_string cbef) cbef)
			    ((== cbef nstatocc) statstr)
			    (:else
			     (let ( (obef (compile_obj cbef gcx)) )
			       obef
			       )))))
	:obciter_after (multiple_map
			nchkaft 
			(lambda (caft :long ix)
			  (cond 
			   ((is_string caft) caft)
			   ((== caft nstatocc) statstr)
			   (:else
			    (let ( (oaft (compile_obj caft gcx)) )
			      oaft
			      )))))
	)
       )
     (debug "compilobj_nrep_citeration filled before&after chunks ocblock=" ocblock)
     (assert_msg "check nbodbind" (is_list_or_null nbodbind) nbodbind)
     (list_every
      nbodbind
      (lambda (nbbnd :long ix)
	(assert_msg "check nbbnd in compilobj_nrep_citeration" (is_a nbbnd class_normal_let_binding) nbbnd)
	(let ( (bder (unsafe_get_field :binder nbbnd))
	       (cty (unsafe_get_field :letbind_type nbbnd))
	       (nexp (unsafe_get_field :letbind_expr nbbnd))
	       (obbva (get_free_objloctyped gcx bder cty))
	       )
	  (if (!= cty ctype_void)
	      (let ( (oclr (instance class_objclear
				     :obi_loc loc
				     :oclr_vloc obbva)) 
		     )
		(list_append oepil oclr)
		(mapobject_put locmap nbbnd obbva)
		)
	    )
	  (let ( (ocur (compile_obj nexp gcx)) )
	    (if (!= cty ctype_void)
		(progn
		  (let ( (newocur (put_objdest ocur obbva)) )
		    (if newocur 
			(list_append obodl newocur)
		      (list_append obodl ocur))
		    ))
	      (progn
		(list_append obodl ocur)
		)))
	  )))
     (debug "compilobj_nrep_citeration nbody=" nbody)
     (multiple_every
      nbody
      (lambda (ncurbod :long ix)
	(let ( (ocbod (compile_obj ncurbod gcx)) )
	  (list_append obodl ocbod)
	  )))
     (debug "compilobj_nrep_citeration final ocblock=" ocblock)
     (return ocblock) 
     )
   )

 (install_method class_nrep_citeration compile_obj compilobj_nrep_citeration)

 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;; compile a setq
 (defun compilobj_nrep_setq (nsq gcx)
   (assert_msg "check nsq" (is_a nsq class_nrep_setq) nsq)
   (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
   (debug "compilobj_nrep_setq nsq=" nsq)
   (let ( (loc (unsafe_get_field :nrep_loc nsq))
	  (var (unsafe_get_field :nstq_var nsq))
	  (exp (unsafe_get_field :nstq_exp nsq))
	  )
     (debug "compilobj_nrep_setq loc=" loc " var=" var " exp=" exp)
     (let (
	  (cexp (compile_obj exp gcx))
	  (cvar (compile_obj var gcx))
	  (cres (put_objdest cexp cvar))
	  )
     (debug "compilobj_nrep_setq loc=" loc " left var=" var " cvar=" cvar
	    "\n right exp=" exp " cexp=" cexp " cres=" cres)
     (and (is_a cres class_objinstr)
	  (null (unsafe_get_field :obi_loc cres))
	  (unsafe_put_fields cres :obi_loc loc))
     (debug "compilobj_nrep_setq cres=" cres)
     cres
     )))
 (install_method class_nrep_setq compile_obj compilobj_nrep_setq)


 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;; compile a progn
 (defun compilobj_nrep_progn (npro gcx)
   (debug "compilobj_nrep_progn npro=" npro)
   (assert_msg "check npro" (is_a npro class_nrep_progn) npro)
   (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
   (let ( (loc (unsafe_get_field :nrep_loc npro))
	  (nseq (unsafe_get_field :nprogn_seq npro))
	  (nlast (unsafe_get_field :nprogn_last npro))
	  (bodyl (make_list discr_list))
	  (oblock (instance class_objplainblock
			    :obi_loc loc
			    :oblo_bodyl bodyl
			    ;; :oblo_epil is left null
			    ))
	  )
     (debug "compilobj_nrep_progn nseq=" nseq)
     (foreach_in_multiple
      (nseq)
      (ncomp :long ix)
      (debug "compilobj_nrep_progn ncomp=" ncomp "\n ix#" ix "\n in npro=" npro)
      (let ( (ocomp (compile_obj ncomp gcx)) )
	(debug "compilobj_nrep_progn ocomp=" ocomp "\n ix#" ix)
	(list_append bodyl ocomp)
	))
     (debug "compilobj_nrep_progn nlast=" nlast)
     (let ( (olast (compile_obj nlast gcx)) )
	(debug "compilobj_nrep_progn olast=" olast)
       (list_append bodyl olast))
     ;;
     (debug "compilobj_nrep_progn return oblock=" oblock "\n from npro=" npro)
     (return oblock)
     ))
 (install_method class_nrep_progn compile_obj compilobj_nrep_progn)

 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;; compile a multacc [data multiple accessor]
 (defun compilobj_nrep_multacc (nma gcx)
   (assert_msg "check nma" (is_a nma class_nrep_multacc) nma)
   (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
   (debug "compilobj_nrep_multacc nma=" nma)
   (let ( (loc (unsafe_get_field :nrep_loc nma))
	  (mul (unsafe_get_field :naccm_mul nma))
	  (ix (unsafe_get_field :naccm_ix nma))
	  (cmul (compile_obj mul gcx))
	  ;; we factor the case when the tuple access cannot be done at
	  ;; compile time
	  (makecompute 
	   (lambda ()
	     (let (
		   (tcont 
		    (tuple
		     (make_stringconst discr_verbatim_string "/*multacc*/(melt_multiple_nth((")
		     cmul
		     (make_stringconst discr_verbatim_string "), (")
		     ix
		     (make_stringconst discr_verbatim_string ")))")
		     ))
		   (res 
		    (instance class_objexpv
			      :obv_type ctype_value
			      :obx_cont tcont))
		   )
	       (debug "compilobj_nrep_multacc makecompute res=" res)
	       res
	       ))
	   )
	  )
     (debug "compilobj_nrep_multacc cmul=" cmul " nma=" nma)
     (if (and
	  (is_a cmul class_objinitmultiple)
	  (is_integerbox ix))
	 (let ( (comptup (unsafe_get_field :oim_tupval cmul)) )
	   (if (is_multiple comptup)
	       (let (
		     (curval (multiple_nth comptup (get_int ix))) 
		     )
		 (debug "compilobj_nrep_multacc returning curval=" curval)
		 (return curval)
		 )
	     (makecompute)
	     ))
       (makecompute)
       )))
 (install_method class_nrep_multacc compile_obj compilobj_nrep_multacc)

 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;; compile a fieldacc [data field accessor]
 (defun compilobj_nrep_fieldacc (nfa gcx)
   (assert_msg "check nfa" (is_a nfa class_nrep_fieldacc) nfa)
   (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
   (debug "compilobj_nrep_fieldacc nfa=" nfa)
   (let ( (loc (unsafe_get_field :nrep_loc nfa))
	  (obj (unsafe_get_field :naccf_obj nfa))
	  (fld (unsafe_get_field :naccf_fld nfa))
	  (:long fldoff (get_int fld))
	  (boxfldoff (make_integerbox discr_integer fldoff))
	  (cobj (compile_obj obj gcx))
	  ;; we factor the case when the field access cannot be done at
	  ;; compile time
	  (makecompute 
	   (lambda ()
	     (let ( 
		   (tcont 
		    (tuple  
		     (make_stringconst discr_verbatim_string "/*fieldacc*/(melt_field_object((melt_ptr_t)(")
		     cobj
		     (make_stringconst discr_verbatim_string "),")
		     boxfldoff
		     (make_stringconst discr_verbatim_string "))")
		     )) 
		   (res 
		    (instance class_objexpv
			      :obv_type ctype_value
			      :obx_cont tcont))
		   )
	       (debug "compilobj_nrep_fieldacc makecompute res=" res)
	       res
	       )))
	  )
     (assert_msg "compilobj_nrep_fieldacc check fld" (is_a fld class_field) fld)
     (debug "compilobj_nrep_fieldacc cobj=" cobj " fld=" fld)
     (if (is_a cobj class_objinitobject)
	 (let ( (cdata (unsafe_get_field :oie_data cobj)) 
		)
	   (if (is_a cdata class_nrep_datainstance)
	       (let ( (slotup (unsafe_get_field :ninst_slots cdata)) 
		      (ourslot (multiple_nth slotup fldoff)) 
		      )
		 (if (is_a ourslot class_nrep_bound_data)
		     (let ( (cslot (compile_obj ourslot gcx)) )
		       (debug "compilobj_nrep_fieldacc returning cslot=" cslot)
		       (return cslot))
		   (return (makecompute))))
	     (return (makecompute)))
	   )
       (return (makecompute))
       )))
 (install_method class_nrep_fieldacc compile_obj compilobj_nrep_fieldacc)

 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;; compile an unsafe get field access
 (defun compilobj_nrep_unsafe_get_field (nugf gcx)
   (assert_msg "check nugf" (is_a nugf class_nrep_unsafe_get_field) nugf)
   (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
   (debug "compilobj_nrep_unsafe_get_field nugf=" nugf)
   (let ( (loc (unsafe_get_field :nrep_loc nugf)) 
	  (nobj (unsafe_get_field :nuget_obj nugf))
	  (nfield (unsafe_get_field :nuget_field nugf))
	  (dlist (make_list discr_list))
	  (oobj (compile_obj nobj gcx))
	  (ogetslot (instance class_objgetslot
			      :obi_loc loc
			      :obdi_destlist dlist
			      :ogetsl_obj oobj
			      :ogetsl_field nfield))
	  )
     (return ogetslot)
     ))
 (install_method class_nrep_unsafe_get_field compile_obj compilobj_nrep_unsafe_get_field)


 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;; compile an unsafe put fields
 (defun compilobj_nrep_unsafe_put_fields (nupf gcx)
   (assert_msg "check nupf" (is_a nupf class_nrep_unsafe_put_fields) nupf)
   (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
   (debug "compilobj_nrep_unsafe_put_fields nupf=" nupf)
   (let ( (loc (unsafe_get_field :nrep_loc nupf)) 
	  (nobj (unsafe_get_field :nuput_obj nupf))
	  (nfldass (unsafe_get_field :nuput_fields nupf))
	  (obodl (make_list discr_list))
	  (oepil (make_list discr_list))
	  (oblock (instance class_objplainblock
			    :obi_loc loc
			    :oblo_bodyl obodl
			    :oblo_epil oepil))
	  (oobj (compile_obj nobj gcx))
	  )
     (foreach_in_multiple 
      (nfldass)
      (nfa :long ix)
      (assert_msg "check nfa" (is_a nfa class_nrep_fieldassign) nfa)
      (let ( (aloc (unsafe_get_field :nrep_loc nfa)) 
	     (afield (unsafe_get_field :nfla_field nfa))
	     (aval (unsafe_get_field :nfla_val nfa))
	     (:long aoff (get_int afield))
	     )
	(assert_msg "check afield" (is_a afield class_field) afield)
	(let ( 
	      (oval (compile_obj aval gcx)) 
	      (opuf (instance class_objputslot
			      :obi_loc (if aloc aloc loc)
			      :oslot_odata oobj
			      :oslot_field afield
			      :oslot_offset (make_integerbox discr_integer aoff)
			      :oslot_value oval)) 
	      )
	  (debug "compilobj_nrep_unsafe_put_fields opuf=" opuf)
	  (assert_msg "compilobj_nrep_unsafe_put_fields check oval not nrep" (is_not_a oval class_nrep) oval)
	  (list_append obodl opuf))
	))

     (list_append obodl (instance class_objtouch
				  :obi_loc loc
				  :otouch_val oobj))
     ;; emit debugtrace of written object
     (list_append obodl (instance class_objdbgtracewriteobj
				  :obi_loc loc
				  :obdtw_writtenobj oobj
				  :obdtw_message '"put-fields"))
     ;; add the updated obj to the block
     (list_append obodl oobj)
     (return oblock)
     ))
 (install_method class_nrep_unsafe_put_fields compile_obj compilobj_nrep_unsafe_put_fields)



 ;;;;
 (defun compilobj_nrep_modulevarocc (nsvar gcx)
   (debug "compilobj_nrep_modulevarocc nsvar=" nsvar)
   (assert_msg "check nsvar" (is_a nsvar class_nrep_modulevarocc) nsvar)
   (let  ( (nvbind (get_field :nmodvar_bind nsvar))
	  )
     (assert_msg "check nvbind" (is_a nvbind class_normal_module_variable_binding) nvbind)
       (let ( (ofetch (instance class_objfetchmodvar
				:obv_type ctype_value
				:obfetchmodvar_bind nvbind))
	      )
	 (debug "compilobj_nrep_modulevarocc ofetch=" ofetch)
	 (return ofetch)
 )))
 (install_method class_nrep_modulevarocc compile_obj compilobj_nrep_modulevarocc)



 ;;;;
 (defun compilobj_nrep_putmodulevar (npvar gcx)
   (debug "compilobj_nrep_putmodulevar npvar=" npvar)
   (assert_msg "check npvar" (is_a npvar class_nrep_putmodulevar) npvar)
   (let ( (loc (unsafe_get_field :nrep_loc npvar)) 
	  (destvar (unsafe_get_field :nputmod_destvar npvar))
	  (nval (unsafe_get_field :nputmod_value npvar))
	  )
     (debug "compilobj_nrep_putmodulevar destvar=" destvar " nval=" nval)
     (assert_msg "check destvar" (is_a destvar class_nrep_modulevarocc) destvar)
     (let ( (modvarbind (get_field :nmodvar_bind destvar))
	    (oval (compile_obj nval gcx))
	    )
       (assert_msg "check modvarbind" (is_a modvarbind class_normal_module_variable_binding) modvarbind)
       (let ( (oput (instance class_objputmodvar
			      :obi_loc loc
			      :obputmodvar_bind modvarbind
			      :obputmodvar_val oval))
	      )
	 (debug "compilobj_nrep_putmodulevar result oput=" oput)
	 (return oput)
	 ))))
 (install_method class_nrep_putmodulevar compile_obj compilobj_nrep_putmodulevar)

 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 (defun compilobj_nrep_checksignal (nchint gcx)
   (debug "compilobj_nrep_checksignal nchint=" nchint)
   (assert_msg "check nchint" (is_a nchint class_nrep_checksignal) nchint)
   (let (
	 (nloc (unsafe_get_field :nrep_loc nchint))
	 (ochint (instance class_objchecksignal
			   :obi_loc nloc))
	 )
     (debug "compilobj_nrep_checksignal ochint=" ochint)
     (return ochint)
     ))

 (install_method class_nrep_checksignal compile_obj compilobj_nrep_checksignal)

 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;; compile an unsafe nth component
 (defun compilobj_nrep_unsafe_nth_component (nunc gcx)
   (assert_msg "check nunc" (is_a nunc class_nrep_unsafe_nth_component) nunc)
   (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
   (debug "compilobj_nrep_unsafe_nth_component nunc=" nunc)
   (let ( (nloc (unsafe_get_field :nrep_loc nunc))
	  (ntup (unsafe_get_field :nunth_tuple nunc))
	  (nidx (unsafe_get_field :nunth_index nunc))
	  (otup (compile_obj ntup gcx))
	  (oidx (compile_obj nidx gcx))
	  (ounc (make_objcompute nloc ctype_value ##{/*unsafenthcomp*/((meltmultiple_ptr_t)($OTUP))->tabval[$OIDX]}#
				 ))
	 )
     (debug "compilobj_nrep_unsafe_nth_component otup=" otup " oidx=" oidx " ounc=" ounc)
     (return ounc)
   ))
 (install_method class_nrep_unsafe_nth_component compile_obj compilobj_nrep_unsafe_nth_component)

 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;; compile a simple application
 (defun compilobj_nrep_apply (napp gcx)
   (debug "compilobj_nrep_apply napp=" napp)
   (assert_msg "check napp" (is_a napp class_nrep_apply) napp)
   (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
   (let ( (loc (unsafe_get_field :nrep_loc napp))
	  (fun (unsafe_get_field :napp_fun napp))
	  (args (unsafe_get_field :nexpr_args napp))
	  )
     (let ( (oclos (compile_obj fun gcx)) 
	    (oargs (multiple_map
		    args
		    (lambda (comp :long ix)
		      (let ( (ocomp (compile_obj comp gcx)) )
			(assert_msg "compilobj_nrep_apply check ocomp not objinstr"
				    (is_not_a ocomp class_objinstr) ocomp)
			ocomp))))
	    (dlist (make_list discr_list))
	    (oapp 
	     (instance 
	      class_objapply
	      :obi_loc loc
	      :obdi_destlist dlist
	      :obapp_clos oclos
	      :obapp_args oargs))
	    )
       (debug "compilobj_nrep_apply return oapp=" oapp)
       oapp
       )))
 (install_method class_nrep_apply compile_obj compilobj_nrep_apply)


 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;; compile a hook call
(defun compilobj_nrep_hook_call (nhkcall gcx)
  (debug "compilobj_nrep_hook_call nhkcall=" nhkcall)
  (assert_msg "check nhkcall" (is_a nhkcall class_nrep_hook_call) nhkcall)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (let ( (loc (unsafe_get_field :nrep_loc nhkcall))
	 (nhkname (unsafe_get_field :nhook_name nhkcall))
	 (nhkctype (unsafe_get_field :nexpr_ctyp nhkcall))
	 (nhook (unsafe_get_field :nhook_called nhkcall))
	 (nargs (unsafe_get_field :nexpr_args nhkcall))
	 (nouts (unsafe_get_field :nhook_outs nhkcall))
	 (nhkdescr (unsafe_get_field :nhook_descr nhkcall))
	 (modctx (unsafe_get_field :gncx_modulcontext gcx))
	 (mhookdict (get_field :mocx_hookdict modctx))
	 )
    (debug "compilobj_nrep_hook_call nhook=" nhook "\n.. nargs=" nargs 
	   "\n.. nouts=" nouts "\n.. nhkname=" nhkname "\n.. nhkdescr=" nhkdescr
	   "\n.. mhookdict=" mhookdict)
    (let ( (ohook (let ( (oh (compile_obj nhook gcx)) )
		    (debug "compilobj_nrep_hook_call ohook=" oh)
		    oh))
	   (oargs (multiple_map
		   nargs
		   (lambda (ncomp :long ix)
		     (debug "compilobj_nrep_hook_call ncomp=" ncomp " ix#" ix)
		     (let ( (ocomp (compile_obj ncomp gcx)) )
		       (debug "compilobj_nrep_hook_call ocomp=" ocomp)
		       (assert_msg "compilobj_nrep_hook_call check ocomp not objinstr"
				   (is_not_a ocomp class_objinstr) ocomp)
		       ocomp))))
	   (oouts (multiple_map
		   nouts 
		   (lambda (nvar :long oix)
		     (debug "compilobj_nrep_hook_call nvar=" nvar " oix#" oix)
		     (let ( (ovar (compile_obj nvar gcx))
			    )
		       (debug "compilobj_nrep_hook_call ovar=" ovar)
		       ovar))))
	   )
      (debug "compilobj_nrep_hook_call ohook=" ohook " oargs=" oargs " oouts=" oouts)
      (let ( 
	    (commastr (make_stringconst discr_verbatim_string ", "))
	    (commampstr (make_stringconst discr_verbatim_string ", &"))
	    (rhkname (clone_with_discriminant nhkname discr_verbatim_string))
	    (addins (lambda (alist)
		      (foreach_in_multiple
		       (oargs)
		       (curarg :long argix)
		       (list_append alist commastr)
		       (list_append alist curarg)
		       )
		      ))
	    (addouts (lambda (alist)
		       (foreach_in_multiple
			(oouts)
			(curout :long outix)
			(list_append alist commampstr)
			(list_append alist curout)
			)
		       ))
	    (ohkcall
	     (make_objlocatedexp 
	      loc nhkctype
	      ##{ /*hookcall*/ melthook_$RHKNAME ((melt_ptr_t) $OHOOK$ADDINS$ADDOUTS) }#
	      ))
	    )
	(when nhkdescr
	  (debug "compilobj_nrep_hook_call nhkdescr=" nhkdescr "\n.. nhkname=" nhkname
		 "\n.. mhookdict=" mhookdict)
	  (assert_msg "check nhkdescr" (is_a nhkdescr class_hook_descriptor) nhkdescr)
	  (let ( (oldescr (mapstring_getstr mhookdict nhkname))
		 )
	    (debug "compilobj_nrep_hook_call nhkdescr=" nhkdescr " oldescr=" oldescr)
	    (if oldescr
		(assert_msg "check oldescr" (== oldescr nhkdescr) oldescr)
	      (progn
		(mapstring_putstr mhookdict nhkname nhkdescr)
		(debug "compilobj_nrep_hook_call updated mhookdict=" mhookdict)
		))))
	(debug "compilobj_nrep_hook_call ohkcall=" ohkcall)
	(return ohkcall)
	))))
(install_method class_nrep_hook_call compile_obj compilobj_nrep_hook_call)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun compilobj_nrep_multiapply (nmapp gcx)
  (assert_msg "check napp" (is_a nmapp class_nrep_multiapply) nmapp)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (debug "compilobj_nrep_multiapply nmapp=" nmapp)
  (let ( (loc (unsafe_get_field :nrep_loc nmapp))
	 (rbinds (unsafe_get_field :nmulapp_bindings nmapp))
	 (fun (unsafe_get_field :napp_fun nmapp))
	 (args (unsafe_get_field :nexpr_args nmapp))
	 (nbody (unsafe_get_field :nmulapp_body nmapp))
	 (locmap (unsafe_get_field :gncx_locmap gcx))
	 (:long nbres (multiple_length rbinds))
	 (reslocs 
	  (multiple_map
	   rbinds
	   (lambda (bind :long ix)
	     (assert_msg "compilobj_nrep_multiapply check bind" 
			 (is_a bind class_formal_binding) bind)
	     (let ( (bder (unsafe_get_field :binder bind))
		    (cty (unsafe_get_field :fbind_type bind)) 
		    (obva (get_free_objloctyped gcx bder cty))
		    )
	       (assert_msg "compilobj_nrep_multiapply check cty" 
			   (is_a cty class_ctype) cty)
	       ;; link nlbnd to obva in locmap
	       (if obva (mapobject_put locmap bind obva))
	       obva
	       ))))
	 (obodl (make_list discr_list))
	 (oepil (make_list discr_list))
	 (oblock (instance class_objplainblock
			   :obi_loc loc
			   :oblo_bodyl obodl
			   :oblo_epil oepil))
	 (oxres (if (>i nbres 1) (make_multiple discr_multiple (-i nbres 1)) ()))
	 (firstres (multiple_nth reslocs 0))
	 (ofun (compile_obj fun gcx))
	 (reslist (make_list discr_list))
	 (oargs (multiple_map args
			      (lambda (comp :long ix)
				(compile_obj comp gcx))))
	 (obody (compile_obj nbody gcx))
	 (omapp (instance class_objmultiapply
			  :obi_loc loc
			  :obdi_destlist reslist
			  :obapp_clos (compile_obj fun gcx)
			  :obapp_args oargs
			  :obmultapp_xres oxres))
	 )
    (if firstres (list_append reslist firstres))
    ;; add every compiled argument to the resulting block unless it is a pure value
    (foreach_in_multiple 
     (oargs)
     (ocurarg :long ix)
       (if 
	   (and ocurarg 
		(or (is_not_a ocurarg class_objpurevalue) 
		    (is_a ocurarg class_objinstr)))
	   (list_append obodl ocurarg)))
    ;; add the multiapply to the block
    (list_append obodl omapp)
    ;; add the compiled body to the block
    (list_append obodl obody)
    ;; add the clearing of each result to epilog
    (foreach_in_multiple 
     (reslocs)
     (rloc :long ix)
     (if (>i ix 0) 
	 (let ( (oclear (instance class_objclear 
				  :obi_loc loc
				  :oclr_vloc rloc)) )
	   (list_append oepil oclear)
	   (multiple_put_nth oxres (-i ix 1) rloc)
	   )))
    ;; dispose the local bindings
    (foreach_in_multiple
     (rbinds)
     (bind :long ix) (dispose_bnd_obj bind gcx))
    (debug "compilobj_nrep_multiapply final oblock=" oblock)
    oblock
    ))
(install_method class_nrep_multiapply compile_obj compilobj_nrep_multiapply)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; compile a simple message send
(defun compilobj_nrep_msend (nsnd gcx)
  (assert_msg "check nsnd" (is_a nsnd class_nrep_msend) nsnd)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (let ( (loc (unsafe_get_field :nrep_loc nsnd))
	 (nsel (unsafe_get_field :nsend_sel nsnd))
	 (nrecv (unsafe_get_field :nsend_recv nsnd))
	 (nargs (unsafe_get_field :nexpr_args nsnd))
	 )
    (debug "compilobj_nrep_msend nsnd=" nsnd)
    (assert_msg "check nrecv" (is_object nrecv) nrecv)
    (let ( (osel (compile_obj nsel gcx))
	   (orecv (compile_obj nrecv gcx))
	   (oargs (multiple_map 
		   nargs
		   (lambda (ncurarg :long ix)
		     (debug "compilobj_nrep_msend ncurarg=" ncurarg " ix=" ix)
		     (let ( (ocurarg (compile_obj ncurarg gcx)) 
			    )
		       (debug "compilobj_nrep_msend ocurarg=" ocurarg)
		       (assert_msg "check ocurarg not tuple" (not (is_multiple ocurarg)) ocurarg)
		       ocurarg
		       ))))
	   (osend
	    (instance 
	     class_objmsend
	     :obi_loc loc
	     :obdi_destlist (make_list discr_list)
	     :obmsnd_sel osel
	     :obmsnd_recv orecv
	     :obmsnd_args oargs
	     ))
	   )
      (debug "compilobj_nrep_msend osend=" osend)
      (assert_msg "check orecv" (is_object orecv) orecv)
      osend
      )))
(install_method class_nrep_msend compile_obj compilobj_nrep_msend)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; compile a multiresult message send
(defun compilobj_nrep_multimsend (nmsnd gcx)
  (assert_msg "check nmsnd" (is_a nmsnd class_nrep_multimsend) nmsnd)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (debug "compilobj_nrep_multimsend nmsnd=" nmsnd)
  (let ( (loc (unsafe_get_field :nrep_loc nmsnd)) 
	 (rbinds (unsafe_get_field :nmulsend_bindings nmsnd))
	 (nbody (unsafe_get_field :nmulsend_body nmsnd)) ; a single normalized expression
	 (nsel (unsafe_get_field :nsend_sel nmsnd))
	 (nrecv (unsafe_get_field :nsend_recv nmsnd))
	 (nargs (unsafe_get_field :nexpr_args nmsnd))
	 (locmap (unsafe_get_field :gncx_locmap gcx))
	 (:long nbres (multiple_length rbinds))
	 (reslocs 
	  (multiple_map
	   rbinds
	   (lambda (bind :long ix)
	     (assert_msg "compilobj_nrep_multimsend check bind" 
			 (is_a bind class_formal_binding) bind)
	     (let ( (bder (unsafe_get_field :binder bind))
		    (cty (unsafe_get_field :fbind_type bind)) 
		    (obva (get_free_objloctyped gcx bder cty))
		    )
	       (assert_msg "compilobj_nrep_multimsend check cty" 
			   (is_a cty class_ctype) cty)
	       ;; link nlbnd to obva in locmap
	       (if obva (mapobject_put locmap bind obva))
	       obva
	       ))))
	 (oxres (if (>i nbres 1) 
		    (make_multiple discr_multiple  (-i nbres 1))))
	 (firstres (multiple_nth reslocs 0))
	 (osel (compile_obj nsel gcx))
	 (reslist (make_list discr_list))
	 (orecv (compile_obj nrecv gcx))
	 (oargs (multiple_map nargs
			      (lambda (comp :long ix)
				(compile_obj comp gcx))))
	 (obody (compile_obj nbody gcx))
	 (obodl (make_list discr_list))
	 (oepil (make_list discr_list))
	 (oblock (instance class_objplainblock
			   :obi_loc loc
			   :oblo_bodyl obodl
			   :oblo_epil oepil))
	 (omsend (instance class_objmultimsend
			   :obi_loc loc
			   :obdi_destlist reslist
			   :obmsnd_sel osel
			   :obmsnd_recv orecv
			   :obmsnd_args oargs
			   :obmultsnd_xres oxres))
	 )
    (assert_msg "check orecv" (is_object orecv) orecv)
    (if firstres (list_append reslist firstres))
    ;; add every compiled argument to the resulting block unless it is a pure value
    (foreach_in_multiple 
     (oargs)
     (ocurarg :long ix)
     (if (and ocurarg (or (is_not_a ocurarg class_objpurevalue) (is_a ocurarg class_objinstr)))
	 (list_append obodl ocurarg)))
    ;; add the multisend to the block
    (list_append obodl omsend)
    ;; add the compiled body to the block
    (list_append obodl obody)
    ;; add the clearing of each result to epilog
    (multiple_every 
     reslocs
     (lambda (rloc :long ix)
       (if (>i ix 0)
	   (let ( (oclear (instance class_objclear 
				    :obi_loc loc
				    :oclr_vloc rloc)) )
	     (list_append oepil oclear)
	     (multiple_put_nth oxres (-i ix 1) rloc)))))
    ;; dispose the local bindings
    (multiple_every 
     rbinds
     (lambda (bind :long ix) (dispose_bnd_obj bind gcx)))
    (debug  "compilobj_nrep_multimsend final oblock=" oblock)
    oblock
    ))

(install_method class_nrep_multimsend compile_obj compilobj_nrep_multimsend)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; compile bindings
(defun compilobj_any_binding  (bind gcx)
  (assert_msg "check bind" (is_a bind class_any_binding) bind)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (debug "compilobj_any_binding bind=" bind)
  (outcstring_err "* compilobj unimplemented receiver binding class ")
  (let ( (discr (discrim bind)) ) (outstr_err (unsafe_get_field :named_name discr)))
  (outnewline_err)
  (assert_msg "@@compile_obj should be implemented in anybinding-s subclasses" () bind))
  
(install_method class_any_binding compile_obj compilobj_any_binding)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; compile value bindings
(defun compilobj_value_binding  (bind gcx)
  (assert_msg "check bind" (is_a bind class_value_binding) bind)
  (assert_msg "check gcx" (is_a gcx class_initial_generation_context) gcx)
  (debug "compilobj_value_binding bind=" bind)
  (let ( (sym (get_field :binder bind))
	 (importmap (get_field :igncx_importmap gcx))
	 (olocv (mapobject_get importmap sym))
	 )
    (debug "compilobj_value_binding olocv=" olocv " importmap=" importmap)
    (assert_msg "check olocv" (is_a olocv class_objlocv) olocv)
    (return olocv)
    )
  )
(install_method class_value_binding compile_obj compilobj_value_binding)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun compilobj_fixed_binding (bind gcx)
  (assert_msg "check bind" (is_a bind class_fixed_binding) bind)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (debug "compilobj_fixed_binding bind=" bind)
  (let ( (sbdata (unsafe_get_field :fixbind_data bind)) 
	 (osdata (compile_obj sbdata gcx)) )
    (debug "compilobj_fixed_binding sbdata=" sbdata " osdata=" osdata)
    (return osdata)
    )
  )
(install_method class_fixed_binding compile_obj compilobj_fixed_binding)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun compilobj_normal_let_binding (bind gcx)
  (assert_msg "check bind" (is_a bind class_normal_let_binding) bind)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (debug "compilobj_normal_let_binding bind=" bind)
  (let ( (nexpr (unsafe_get_field :letbind_expr bind)) 
	 (ctyp (unsafe_get_field :letbind_type bind))
	 (bnder (unsafe_get_field :binder bind))
	 (oexpr (compile_obj nexpr gcx)) )
    (debug "compilobj_normal_let_binding oexpr=" oexpr)
    (assert_msg "compilobj_normal_let_binding got here" () bind oexpr)
    (return oexpr)
    )
  )
(install_method class_normal_let_binding compile_obj compilobj_normal_let_binding)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun compilobj_conslambdabind (bind gcx)
  (assert_msg "check bind" (is_a bind class_normal_constructed_lambda_binding) bind)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (debug "compilobj_conslambdabind bind=" bind)
  (let ( (symb (unsafe_get_field :binder bind))
	 (loc (unsafe_get_field :nconsb_loc bind))
	 (ndiscr (unsafe_get_field :nconsb_discr bind))
	 (nclosed (unsafe_get_field :nlambdab_nclosed bind))
	 (ndatarout (unsafe_get_field :nlambdab_datarout bind))
	 (nconstrout (unsafe_get_field :nlambdab_constrout bind))
	 (nletrec (unsafe_get_field :nconsb_nletrec bind))
	 (odiscr (compile_obj ndiscr gcx))
	 (nambuf (make_strbuf discr_strbuf))
	 (nlocsyms (get_field :nletrec_locsyms nletrec))
	 (:long bindnum (get_int bind))
	 (:long nbclosed (multiple_length nclosed))
	 (locsymocc (multiple_nth nlocsyms bindnum))
	 )
    (let ( 
	  (orout (compile_obj nconstrout gcx))
	  (oloc (compile_obj locsymocc gcx))
	  )
      (add2sbuf_strconst nambuf "rclo_")
      (add2sbuf_longdec nambuf bindnum)
      (add2sbuf_strconst nambuf "__")
      (add2sbuf_cident nambuf (unsafe_get_field :named_name symb))
      (if (is_a symb class_cloned_symbol)
	  (progn
	    (add2sbuf_strconst nambuf "_x")
	    (add2sbuf_longdec nambuf (get_int (get_field :csym_urank symb)))))
      (let ( (iniclos (instance class_objinitclosure
				:obv_type ctype_value
				:oie_discr odiscr
				:oie_locvar oloc
				:oie_cname (strbuf2string discr_string nambuf)
				:oiclo_rout orout
				))
	     )
	(put_int iniclos nbclosed)
	(debug "compilobj_conslambdabind returning iniclos=" iniclos)
	iniclos
	))))
(install_method class_normal_constructed_lambda_binding compile_obj compilobj_conslambdabind)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun compilobj_constuplebind (bind gcx)
  (debug "compilobj_constuplebind bind=" bind)
  (assert_msg "check bind" (is_a bind class_normal_constructed_tuple_binding) bind)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (let ( (symb (unsafe_get_field :binder bind))
	 (nloc (unsafe_get_field :nconsb_loc bind))
	 (ndiscr (unsafe_get_field :nconsb_discr bind))
	 (nletrec (unsafe_get_field :nconsb_nletrec bind))
	 (ntupb (unsafe_get_field :ntupb_comp bind))
	 (odiscr (compile_obj ndiscr gcx))
	 (nambuf (make_strbuf discr_strbuf))
	 (nletrec (unsafe_get_field :nconsb_nletrec bind))
	 (nlocsyms (get_field :nletrec_locsyms nletrec))
	 (:long bindnum (get_int bind))
	 (:long lentup (multiple_length ntupb))
	 (locsymocc (multiple_nth nlocsyms bindnum))
	 )
      (add2sbuf_strconst nambuf "rtup_")
      (add2sbuf_longdec nambuf bindnum)
      (add2sbuf_strconst nambuf "__")
      (add2sbuf_cident nambuf (unsafe_get_field :named_name symb))
      (if (is_a symb class_cloned_symbol)
	  (progn
	    (add2sbuf_strconst nambuf "_x")
	    (add2sbuf_longdec nambuf (get_int (get_field :csym_urank symb)))))
      (let ( 
	    (oloc (compile_obj locsymocc gcx))
	    (tupval (make_multiple discr_multiple lentup))
	    (initup (instance class_objinitmultiple
			       :obv_type ctype_value
			       :oie_discr odiscr
			       :oie_locvar oloc
			       :oie_cname (strbuf2string discr_string nambuf)
			       :oim_tupval tupval
			       ))
	    )
	(put_int initup lentup)
	(debug "compilobj_constuplebind result initup=" initup)
	initup
	)
    ))
(install_method class_normal_constructed_tuple_binding compile_obj compilobj_constuplebind)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun compilobj_conspairbind (bind gcx)
  (debug "compilobj_conspairbind bind=" bind)
  (assert_msg "check bind" (is_a bind class_normal_constructed_pair_binding) bind)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (let ( (symb (unsafe_get_field :binder bind))
	 (nloc (unsafe_get_field :nconsb_loc bind))
	 (ndiscr (unsafe_get_field :nconsb_discr bind))
	 (nletrec (unsafe_get_field :nconsb_nletrec bind))
	 (nhead (unsafe_get_field :npairb_head bind))
	 (ntail (unsafe_get_field :npairb_tail bind))
	 (nlocsyms (get_field :nletrec_locsyms nletrec))
	 (odiscr (compile_obj ndiscr gcx))
	 (nambuf (make_strbuf discr_strbuf))
	 (:long bindnum (get_int bind))
	 (locsymocc (multiple_nth nlocsyms bindnum))
	 )
    (assert_msg "check nletrec" nletrec)
    (add2sbuf_strconst nambuf "rpair_")
    (add2sbuf_longdec nambuf bindnum)
    (add2sbuf_strconst nambuf "__")
    (add2sbuf_cident nambuf (unsafe_get_field :named_name symb))
    (if (is_a symb class_cloned_symbol)
	(progn
	  (add2sbuf_strconst nambuf "_x")
	  (add2sbuf_longdec nambuf (get_int (get_field :csym_urank symb)))))
    (let ( 
	  (oloc (compile_obj locsymocc gcx))
	  (inipair (instance class_objinitpair
			     :obv_type ctype_value
			     :oie_discr odiscr
			     :oie_locvar oloc
			     :oie_cname (strbuf2string discr_string nambuf)))
	  )
      (debug "compilobj_conspairbind return inipair=" inipair)
      (return inipair)
      )))
(install_method class_normal_constructed_pair_binding compile_obj compilobj_conspairbind)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun compilobj_conslistbind (bind gcx)
  (debug "compilobj_conslistbind bind=" bind)
  (assert_msg "check bind" (is_a bind class_normal_constructed_list_binding) bind)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (let ( (symb (unsafe_get_field :binder bind))
	 (nloc (unsafe_get_field :nconsb_loc bind))
	 (ndiscr (unsafe_get_field :nconsb_discr bind))
	 (nletrec (unsafe_get_field :nconsb_nletrec bind))
	 (nfirst (unsafe_get_field :nlistb_first bind))
	 (nlast (unsafe_get_field :nlistb_last bind))
	 (nlocsyms (get_field :nletrec_locsyms nletrec))
	 (odiscr (compile_obj ndiscr gcx))
	 (nambuf (make_strbuf discr_strbuf))
	 (:long bindnum (get_int bind))
	 (locsymocc (multiple_nth nlocsyms bindnum))
	 )
    (add2sbuf_strconst nambuf "rlist_")
    (add2sbuf_longdec nambuf bindnum)
    (add2sbuf_strconst nambuf "__")
    (add2sbuf_cident nambuf (unsafe_get_field :named_name symb))
    (let ( 
	  (oloc (compile_obj locsymocc gcx))
	  (inilist (instance class_objinitlist
			     :obv_type ctype_value
			     :oie_discr odiscr
			     :oie_locvar oloc
			     :oie_cname (strbuf2string discr_string nambuf)
			     ))
	  )
      (debug "compilobj_conslistbind return inilist=" inilist)
      (return inilist)
      )))
(install_method class_normal_constructed_list_binding compile_obj compilobj_conslistbind)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun compilobj_consinstancebind (bind gcx)
  (debug  "compilobj_consinstancebind bind=" bind)
  (assert_msg "check bind" (is_a bind class_normal_constructed_instance_binding) bind)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (let ( (symb (unsafe_get_field :binder bind))
	 (nloc (unsafe_get_field :nconsb_loc bind))
	 (ndiscr (unsafe_get_field :nconsb_discr bind))
	 (nletrec (unsafe_get_field :nconsb_nletrec bind))
	 (nslots (unsafe_get_field :ninstb_slots bind))
	 (nambuf (make_strbuf discr_strbuf))
	 (odiscr (compile_obj ndiscr gcx))
	 (nlocsyms (get_field :nletrec_locsyms nletrec))
	 (:long bindnum (get_int bind))
	 (locsymocc (multiple_nth nlocsyms bindnum))
	 (nclabind (get_field :ninstb_clabind bind))
	 )
    (add2sbuf_strconst nambuf "rinst_")
    (add2sbuf_longdec nambuf bindnum)
    (add2sbuf_strconst nambuf "__")
    (add2sbuf_cident nambuf (unsafe_get_field :named_name symb))
    (let ( 
	  (oloc (compile_obj locsymocc gcx))
	  (clas (cond ( (is_a nclabind class_value_binding)
		       (unsafe_get_field :vbind_value nclabind))
		     ( (is_a nclabind class_class_binding)
		       (unsafe_get_field :cbind_class nclabind))
		     (:else
		      (debug "compilobj_consinstancebind bad nclabind=" nclabind)
		      (assert_msg "unexpected class binding" () nclabind))))
	  (ininst (instance class_objinitobject
			    :obv_type ctype_value
			    :oie_discr odiscr
			    :oie_locvar oloc
			    :oie_cname (strbuf2string discr_string nambuf)
			    :oio_class clas
			    ))
	  )
      ;; set the length of the instance
      (put_int ininst (multiple_length (get_field :class_fields clas)))
      (debug "compilobj_consinstancebind return ininst=" ininst)
      (return ininst)
      )))
(install_method class_normal_constructed_instance_binding compile_obj compilobj_consinstancebind)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun putobjdest_objvalue (recv desto)
  (assert_msg "check recv" (is_a recv class_objvalue) recv)
  (assert_msg "check desto" (is_a desto class_objpurevalue) desto)
  (let ( (typrecv (unsafe_get_field :obv_type recv))
	 (typdesto (get_field :obv_type desto)) 
	 )
    (cond
     ;; special case when receiver is void
     ( (== typrecv ctype_void)
       (if (== typdesto ctype_void)
	   (return recv)
	 ;; if recv is void we just create a block with recv and the
	 ;; clear of desto
	 (let ( 
	       (obodl (make_list discr_list))
	       (oblk (instance class_objplainblock
			       ;; dont fill :obi_loc
			       :oblo_bodyl obodl
			       :oblo_epil ()
			       )
		     )
	       (oclr (instance class_objclear
			       ;; dont fill :obi_loc
			       :oclr_vloc desto
			       ))
	       )
	   (list_append obodl recv)
	   (list_append obodl oclr)
	   ;; the last of the block is the destination location, to
	   ;; avoid latter putobjdest-s on the objclear
	   (list_append obodl desto)
	   (return oblk)
	   )))
     ;; common case when desto & recv have same type
     ( (== typrecv typdesto)
       (assert_msg "check same typrecv&rtpdesto" (is_a typrecv class_ctype) typrecv)
       (let ( (destlis (make_list discr_list))
	      (explis (make_list discr_list))
	      (obc (instance class_objcompute
			     ;; dont fill :obi_loc
			     :obdi_destlist destlis
			     :obcpt_expr explis
			     :obcpt_type typrecv
			     )) 
	      )
	 (list_append destlis desto)
	 (list_append explis recv)
	 (return obc)))
     ;; error case: type mismatch
     (:else
      (debug "putobjdest_objvalue mismatching recv=" recv " typrecv=" typrecv " desto=" desto " typdesto=" typdesto)
      (outcstring_err "putobjdest_objvalue type mismatch : recv <")
      (let ( (discr (discrim recv)) ) (outstr_err (unsafe_get_field :named_name discr)))
      (outcstring_err "> & desto<") 
      (let ( (discr (discrim desto)) ) (outstr_err (unsafe_get_field :named_name discr)))
      (outcstring_err ">")
      (outnewline_err)
      (assert_msg "putobjdest_objvalue type mismatch" () recv desto)
      (return recv)))
    ))

(install_method class_objvalue  put_objdest  putobjdest_objvalue)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun putobjdest_integer (recv desto)
  (debug "putobjdest_integer recv=" recv "\n* desto=" desto
	 "\n* of discrim:" (discrim desto) "\n* class_objlocv=" class_objlocv)
  (assert_msg "check recv" (is_integerbox recv) recv)
  (assert_msg "check desto" (is_a desto class_objpurevalue) desto)
  (let ( (destlis (make_list discr_list))
	 (explis (make_list discr_list))
	 (typdesto (get_field :obv_type desto))
	 (obc (instance class_objcompute
			;; dont fill :obi_loc
			:obdi_destlist destlis
			:obcpt_expr explis
			:obcpt_type ctype_long
			)) 
	 )
    (assert_msg "check typdesto" (== typdesto ctype_long) typdesto)
    (list_append destlis desto)
    (list_append explis recv)
    (debug "putobjdest_integer return obc=" obc)
    obc
    ))
(install_method discr_integer put_objdest putobjdest_integer)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;; put obj destination inside a string
;;; useful to compile (let ( (:cstring foo "abc") ) ...)
(defun putobjdest_string (recv desto)
  (assert_msg "check recv" (is_string recv) recv)
  (assert_msg "check desto" (is_a desto class_objpurevalue) desto)
  (debug "putobjdest_string recv=" recv " desto=" desto)
  (let ( (destlis (make_list discr_list))
	 (explis (make_list discr_list))
	 (typdesto (unsafe_get_field :obv_type desto))
	 (obc (instance class_objcompute
			;; dont fill :obi_loc
			:obdi_destlist destlis
			:obcpt_expr explis
			:obcpt_type ctype_cstring
			)) 
	 )
    (assert_msg "check typdesto" (== typdesto ctype_cstring) typdesto)
    (list_append destlis desto)
    (list_append explis recv)
    (debug "putobjdest_string return obc=" obc)
    obc
    ))
(install_method discr_string put_objdest putobjdest_string)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun putobjdest_null (recv desto)
  (assert_msg "check recv" (null recv))
  (assert_msg "check desto" (is_a desto class_objpurevalue) desto)
  (debug "putobjdest_null recv=" recv " desto=" desto)
  (if (melt_need_dbg 0) (shortbacktrace_dbg "putobjdest_null" 15))
  (let ( (destlis (make_list discr_list))
	 (explis (make_list discr_list))
	 (typdesto (unsafe_get_field :obv_type desto))
	 (obc (instance class_objcompute
			;; dont fill :obi_loc
			:obdi_destlist destlis
			:obcpt_expr explis
			:obcpt_type typdesto
			)) 
	 )
    (list_append destlis desto)
    (if (== typdesto ctype_long)
	(list_append explis (make_integerbox discr_integer 0))
      (list_append explis recv))
    (debug "putobjdest_null return obc=" obc)
    obc
    ))
(install_method discr_null_receiver put_objdest putobjdest_null)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun putobjdest_objanyblock (recv desto)
  (assert_msg "check recv" (is_a recv class_objanyblock) recv)
  (assert_msg "check desto" (is_a desto class_objpurevalue) desto)
  (let ( (obl (unsafe_get_field :oblo_bodyl recv))
	 (oep (unsafe_get_field :oblo_epil recv))
	 )
    (assert_msg "check obl" (is_list_or_null obl) obl)
    (assert_msg "check oep" (is_list_or_null oep) oep)
    ;; maybe we should remove in the epilogue any clear of same ctype & offset
    (let ( (lpby (list_last obl))
	   (lasbp (pair_head lpby))
	   )
      (if lasbp 
	  (let ( (uplasb (put_objdest lasbp desto)) )
	    (pair_set_head lpby uplasb)
	    )
	)
      )
    recv
    ))

(install_method class_objanyblock  put_objdest  putobjdest_objanyblock)


;;;;;;;;;;
(defun putobjdest_objmultiblock (recv desto)
  (assert_msg "check recv" (is_a recv class_objmultiblock) recv)
  (debug "putobjdest_objmultiblock recv=" recv " desto=" desto)
  (let ( (osubcomp (unsafe_get_field :omulblo_subcomp recv)) )
    (assert_msg "check osubcomp" (is_multiple_or_null osubcomp) osubcomp)
    (foreach_in_multiple
     (osubcomp)
     (cursubcomp :long curix)
     (put_objdest cursubcomp desto))
    (debug  "putobjdest_objmultiblock done recv=" recv)
))
(install_method class_objmultiblock put_objdest putobjdest_objmultiblock)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun putobjdest_objloop (recv desto)
  (assert_msg "check recv" (is_a recv class_objloop) recv)
  (assert_msg "check desto" (is_a desto class_objpurevalue) desto)
  (let ( (epil (unsafe_get_field :oblo_epil recv)) 
	 (resv (unsafe_get_field :obloop_resv recv))
	 (destlist (make_list discr_list))
	 (obc (instance class_objcompute
			;; dont fill :obi_loc
			:obdi_destlist destlist
			:obcpt_expr resv
			:obcpt_type ctype_value
			))
	 )
    (list_append destlist desto)
    (assert_msg "check epil" (is_list epil) epil)
    (assert_msg "check resv" (is_a resv class_objlocv) resv)
    (list_append epil obc)
    )
  (debug "putobjdest loop updated recv=" recv)
  recv
  )
(install_method class_objloop  put_objdest  putobjdest_objloop)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; do nothing when puting a destination into an objexit
(defun putobjdest_objexit (recv desto)
  (assert_msg "check recv" (is_a recv class_objexit) recv)
  (assert_msg "check desto" (is_a desto class_objpurevalue) desto)
  recv
  )
(install_method class_objexit put_objdest putobjdest_objexit)



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun compilobj_nrep_if (rif gcx)
  (assert_msg "check rif" (is_a rif class_nrep_if) rif)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (debug "compilobj_nrep_if rif=" rif)
  (let ( (loc (unsafe_get_field :nrep_loc rif))
	 (ntest (unsafe_get_field :nif_test rif))
	 (nthen (unsafe_get_field :nif_then rif))
	 (nelse (unsafe_get_field :nif_else rif))
	 (nctyp (unsafe_get_field :nexpr_ctyp rif))
	 )
    (assert_msg "check nctyp" (is_a nctyp class_ctype) nctyp)
    (let ( (otest (compile_obj ntest gcx))
	   (othen (compile_obj nthen gcx))
	   (oelse (if (is_not_a nelse class_nrep_nil) 
		      (compile_obj nelse gcx)))
	   (obif (instance class_objcond
			   :obi_loc loc
			   :obcond_test otest
			   :obcond_then othen
			   :obcond_else oelse))
	   )
      (debug "compilobj_nrep_if ntest=" ntest " otest=" otest)
      (debug "compilobj_nrep_if nthen=" nthen " otest=" othen)
      (debug "compilobj_nrep_if nthen=" nelse " otest=" oelse)
      (debug "compilobj_nrep_if obif=" obif)
      (assert_msg "check otest" (notnull otest) otest)
      obif
      )))
(install_method class_nrep_if compile_obj compilobj_nrep_if)


;;;;;;;;;;;;;;;;
(defun compilobj_nrep_ifisa (rif gcx)
  (debug "compilobj_nrep_ifisa rif=" rif)
  (assert_msg "check rif" (is_a rif class_nrep_ifisa) rif)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (let ( (loc (unsafe_get_field :nrep_loc rif))
	 (nthen (unsafe_get_field :nif_then rif))
	 (nelse (unsafe_get_field :nif_else rif))
	 (nctyp (unsafe_get_field :nexpr_ctyp rif))
	 (nval (get_field :nif_testval rif))
	 (ncla (unsafe_get_field :nifa_class rif))
	 )
    (assert_msg "check nctyp" (is_a nctyp class_ctype) nctyp)
    (let ( (othen (compile_obj nthen gcx))
	   (oval (compile_obj nval gcx))
	   (ocla (compile_obj ncla gcx))
	   (oelse (if (is_not_a nelse class_nrep_nil) 
		      (compile_obj nelse gcx)))
	   (otest (make_objlocatedexp loc ctype_long
				      ##{/*ifisa*/ melt_is_instance_of((melt_ptr_t)($OVAL), 
                                                                       (melt_ptr_t)($OCLA))
				      }#))
	   (obif (instance class_objcond
			   :obi_loc loc
			   :obcond_test otest
			   :obcond_then othen
			   :obcond_else oelse))
	   )
      (debug "compilobj_nrep_ifisa obif=" obif)
      obif
      )))
(install_method class_nrep_ifisa compile_obj compilobj_nrep_ifisa)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun compilobj_nrep_ifsame (rif gcx)
  (debug "compilobj_nrep_ifsame rif=" rif "\n gcx=" gcx)
  (assert_msg "check rif" (is_a rif class_nrep_ifsame) rif)
  (let ( (nloc (get_field :nrep_loc rif))
	 (nleft (get_field :nifs_left rif))
	 (nright (get_field :nifs_right rif))
	 (nthen (get_field :nif_then rif))
	 (nelse (get_field :nif_else rif))
	 )
    (let ( (othen (compile_obj nthen gcx))
	   (oleft (compile_obj nleft gcx))
	   (oright (compile_obj nright gcx))
	   (oelse (if (is_not_a nelse class_nrep_nil) 
		      (compile_obj nelse gcx)))
	   (otest (make_objlocatedexp nloc ctype_long
				      ##{/*ifsame*/ ($OLEFT) == ($ORIGHT)}#))
	   (obif (instance class_objcond
			   :obi_loc nloc
			   :obcond_test otest
			   :obcond_then othen
			   :obcond_else oelse))
	   )
      (debug "compilobj_nrep_ifsame result obif=" obif)
      (return obif)
      )))
(install_method class_nrep_ifsame compile_obj compilobj_nrep_ifsame)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun compilobj_nrep_iftuplesized (rif gcx)
  (debug "compilobj_nrep_ifisa rif=" rif)
  (assert_msg "check rif" (is_a rif class_nrep_iftuplesized) rif)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (let ( (loc (unsafe_get_field :nrep_loc rif))
	 (nthen (unsafe_get_field :nif_then rif))
	 (nelse (unsafe_get_field :nif_else rif))
	 (nval (get_field :nif_testval rif))
	 (ntsz (get_field :nif_tupsiz rif))
	 )
    (debug "compilobj_nrep_iftuplesized nval=" nval " ntsz=" ntsz)
    (let (  (othen (compile_obj nthen gcx))
	    (oval (compile_obj nval gcx))
	    (oelse (compile_obj nelse gcx))
	    (oval (compile_obj nval gcx))
	    (otsz (compile_obj ntsz gcx))
	    (otest
	     (make_objlocatedexp loc ctype_long
				 ##{/*iftuplesized*/ melt_magic_discr((melt_ptr_t)($OVAL)) == MELTOBMAG_MULTIPLE
				 && ((meltmultiple_ptr_t)($OVAL))->nbval == (int)($OTSZ)}#))
	   (obif (instance class_objcond
			   :obi_loc loc
			   :obcond_test otest
			   :obcond_then othen
			   :obcond_else oelse))
	  )
      (debug "compilobj_nrep_iftuplesized obif=" obif)
      obif
)))
(install_method class_nrep_iftuplesized compile_obj compilobj_nrep_iftuplesized)

;;;;;;;;;;;;;;;;
(defun compilobj_nrep_ifvariadic (rif gcx)
  (assert_msg "check rif" (is_a rif class_nrep_ifvariadic) rif)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (debug  "compilobj_nrep_ifvariadic rif=" rif)
  (let ( (loc (unsafe_get_field :nrep_loc rif))
	 (nthen (unsafe_get_field :nif_then rif))
	 (nelse (unsafe_get_field :nif_else rif))
	 (nvariadic (unsafe_get_field :nifv_variadic rif))
	 (nvctypes (unsafe_get_field :nifv_ctypes rif))
	 (:long nbvararg (multiple_length nvctypes))
	 )
    (assert_msg "check nvctypes" (is_multiple_or_null nvctypes) nvctypes)
    (assert_msg "check nvariadic" (is_a nvariadic class_symbol) nvariadic)
    (debug "compilobj_nrep_ifvariadic nthen=" nthen "\n.. nelse=" nelse
	   "\n.. nvariadic=" nvariadic " loc=" loc)
    (let ( 
	  (ovariadicindex (variadic_index_idstr nvariadic))
	  (ovariadiclength (variadic_length_idstr nvariadic))
	  (otestchklist 
	   (if (<=i nbvararg 0) 
	       (list
		(make_stringconst discr_verbatim_string "/*ifvariadic nomore*/ ")
		ovariadicindex
		(make_stringconst discr_verbatim_string " == ")
		ovariadiclength
		)
	     (let ( (ovlist
		     (list
		      (make_stringconst discr_verbatim_string "/*ifvariadic arg#")
		      (make_integerbox discr_constant_integer nbvararg)
		      (make_stringconst discr_verbatim_string "*/ ")
		       ovariadicindex
		      (make_stringconst discr_verbatim_string ">=0 && ")
		      ovariadicindex
		      (make_stringconst discr_verbatim_string " + ")
		      (make_integerbox discr_constant_integer nbvararg)
		      (make_stringconst discr_verbatim_string " <= ")
		      ovariadiclength
		      ))
		    )
	       (foreach_in_multiple
		(nvctypes)
		(curctyp :long ix)
		(debug "compilobj_nrep_ifvariadic curctyp" curctyp " ix=" ix
		       "; loc=" loc)
		(assert_msg "check curctyp" (is_a curctyp class_ctype) curctyp)
		(list_append ovlist (make_stringconst discr_verbatim_string " && meltxargdescr_["))
		(list_append ovlist ovariadicindex)
		(if ix
		    (progn
		      (list_append ovlist (make_stringconst discr_verbatim_string " + "))
		      (list_append ovlist (make_integerbox discr_constant_integer ix))))
		(list_append ovlist (make_stringconst discr_verbatim_string "]== "))
		(list_append ovlist 
			     (make_string discr_verbatim_string 
					  (get_field :ctype_parchar curctyp)))
		)
	       (debug "compilobj_nrep_ifvariadic ovlist=" ovlist"; loc=" loc)
	       ovlist))
	   )
	  (otest (instance  class_objexpv
			    :obx_cont (list_to_multiple otestchklist discr_multiple)))
	  (othen 
	   (progn 
	     (debug "compilobj_nrep_ifvariadic before compiling nthen=" nthen"; loc=" loc)
	     (let ( (objthen (compile_obj nthen gcx))
		    )
	       (debug "compilobj_nrep_ifvariadic after compiling nthen=" nthen 
		      " objthen=" objthen"; loc=" loc)
	       objthen)))
	  (oelse 
	   (progn 
	     (debug "compilobj_nrep_ifvariadic before compiling nelse=" nelse "; loc=" loc)
	     (let ( (objelse (compile_obj nelse gcx))
		    )
	       (debug "compilobj_nrep_ifvariadic after compiling nelse=" nelse
		      " objelse=" objelse"; loc=" loc)
	       objelse)))
	  (ocond (instance class_objcond
			   :obi_loc loc
			   :obcond_test otest
			   :obcond_then othen
			   :obcond_else oelse))
	  )
      (debug "compilobj_nrep_ifvariadic ocond=" ocond"; loc=" loc)
      (return ocond))))
(install_method class_nrep_ifvariadic compile_obj compilobj_nrep_ifvariadic)

(defun getctype_ifvariadic (rif env)
  (assert_msg "check ifvariadic" (is_a rif class_nrep_ifvariadic) rif)
  ctype_void)
(install_method class_nrep_ifvariadic get_ctype getctype_ifvariadic)


;;;;;;;;;;;;;;;;

(defun compilobj_nrep_variadic_argument (nvarg gcx)
  (debug "compilobj_nrep_variadic_argument nvarg=" nvarg)
  (assert_msg "check nvarg" (is_a nvarg class_nrep_variadic_argument) nvarg)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (let ( (nloc (unsafe_get_field :nrep_loc nvarg))
	 (nvariadic (unsafe_get_field :nvarg_variadic nvarg))
	 (nctyp (unsafe_get_field :nvarg_ctyp nvarg))
	 (noffset (unsafe_get_field :nvarg_offset nvarg))
	 (ovariadicindex (variadic_index_idstr nvariadic))
	 (ovariadiclength (variadic_length_idstr nvariadic))
	 )
    (assert_msg "check nctyp" (is_a nctyp class_ctype) nctyp)
    (assert_msg "check noffset" (is_integerbox noffset) noffset)
    (let (
	  (otuple 
	   (if (== nctyp ctype_value)
	       (tuple
		(make_stringconst discr_verbatim_string "/*variadic argument value*/ ((meltxargtab_[")
		ovariadicindex
		(make_stringconst discr_verbatim_string " + ")
		noffset
		(make_stringconst discr_verbatim_string "].meltbp_aptr) ? (*(meltxargtab_[")
		ovariadicindex
		(make_stringconst discr_verbatim_string " + ")
		noffset
		(make_stringconst discr_verbatim_string "].meltbp_aptr)) : NULL)")
		)
	     (tuple
	      (make_stringconst discr_verbatim_string "/*variadic argument stuff*/ meltxargtab_[")
	      ovariadicindex
	      (make_stringconst discr_verbatim_string " + ")
	      noffset
	      (make_stringconst discr_verbatim_string "].")
	      (make_string discr_verbatim_string (get_field :ctype_argfield nctyp))
	      )))
	  (ocomp (instance 
		  class_objcompute
		  :obi_loc nloc
		  :obcpt_type nctyp
		  :obcpt_expr otuple))
	  )
      (debug "compilobj_nrep_variadic_argument ocomp=" ocomp)
      (return ocomp)
      )))
(install_method class_nrep_variadic_argument compile_obj compilobj_nrep_variadic_argument)


;;;;;;;;;;;;;;;;
(defun compilobj_nrep_consumevariadic (rcv gcx)
  (assert_msg "check rcv" (is_a rcv class_nrep_consume_variadic) rcv)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (debug "compilobj_nrep_consumevariadic rcv=" rcv)
  (let ( (nloc (unsafe_get_field :nrep_loc rcv))
	 (nvariadic (unsafe_get_field :nconsva_variadic rcv))
	 (nctypes (unsafe_get_field :nconsva_ctypes rcv))
	 (olist (make_list discr_list))
	 (ovariadicindex (variadic_index_idstr nvariadic))
	 (ovariadiclength (variadic_length_idstr nvariadic))
	 )
    (assert_msg "check nctypes" (is_multiple_or_null nctypes) nctypes)
    (list_append olist (make_stringconst discr_verbatim_string "/*consume variadic "))
    (foreach_in_multiple 
     (nctypes)
     (curctyp :long typix)
     (assert_msg "check curctyp" (is_a curctyp class_ctype) curctyp)
     (if (== curctyp ctype_value)
	 (list_append olist (make_stringconst discr_verbatim_string "Value"))
       (list_append olist (make_string discr_verbatim_string (get_field :named_name (get_field :ctype_keyword curctyp))))))
    (list_append olist (make_stringconst discr_verbatim_string " !*/ "))
    (list_append olist ovariadicindex)
    (list_append olist (make_stringconst discr_verbatim_string " += "))
    (list_append olist (make_integerbox discr_integer (multiple_length nctypes)))
    (let (
	  (otuple (list_to_multiple olist))
	  (ocomp (instance 
		  class_objcompute
		  :obi_loc nloc
		  :obcpt_type ctype_void
		  :obcpt_expr otuple))
	  )
      (debug "compilobj_nrep_consumevariadic ocomp=" ocomp)
      (return ocomp)
      )))
(install_method class_nrep_consume_variadic compile_obj compilobj_nrep_consumevariadic)

;;;;;;;;;;;;;
(defun putobjdest_objcond (recv desto)
  (assert_msg "check recv" (is_a recv class_objcond) recv)
  (assert_msg "check desto" (is_a desto class_objpurevalue) desto)
  (let ( (othen (unsafe_get_field :obcond_then recv))
	 (oelse (unsafe_get_field :obcond_else recv)) 
	 )
    (let ( (dthen (put_objdest othen desto))
	   (delse (put_objdest oelse desto)) )
      (unsafe_put_fields recv
			 :obcond_then dthen
			 :obcond_else delse)
      recv
      )))

(install_method class_objcond  put_objdest  putobjdest_objcond)
;;;;;;;;;;;;;;;;

(defun compilobj_nrep_cppif (pif gcx)
  (assert_msg "check pif" (is_a pif class_nrep_cppif) pif)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (let ( (loc (unsafe_get_field :nrep_loc pif))
	 (ncond (unsafe_get_field :nifp_cond pif))
	 (nthen (unsafe_get_field :nifp_then pif))
	 (nelse (unsafe_get_field :nifp_else pif))
	 (ctyp (unsafe_get_field :nifp_ctyp pif))
	 (scond (cond
		 ( (is_a ncond class_symbol) (unsafe_get_field :named_name ncond))
		 ( (is_string ncond) ncond)
		 (:else (assert_msg "invalid ncond in nrep_cppif" () ncond))))
	 (othen (compile_obj nthen gcx))
	 (oelse (compile_obj nelse gcx))
	 (res (instance class_objcppif
			:obi_loc loc
			:obifp_cond scond
			:obifp_then othen
			:obifp_else oelse))
	 )
    (return res)
    ))
(install_method class_nrep_cppif compile_obj compilobj_nrep_cppif)


;;;;;;;;;;;;;
(defun putobjdest_objcppif (recv desto)
  (assert_msg "check recv" (is_a recv class_objcppif) recv)
  (assert_msg "check desto" (is_a desto class_objpurevalue) desto)
  (let ( (othen (unsafe_get_field :obifp_then recv))
	 (oelse (unsafe_get_field :obifp_else recv)) 
	 )
    (let ( (dthen (put_objdest othen desto))
	   (delse (put_objdest oelse desto)) )
      (unsafe_put_fields recv
			 :obifp_then dthen
			 :obifp_else delse)
      recv
      )))

(install_method class_objcppif  put_objdest  putobjdest_objcppif)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;
(defun compilobj_nrep_return (nret gcx)
  (assert_msg "check nret" (is_a nret class_nrep_return) nret)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (debug "compilobj_nrep_return nret=" nret "\n gcx=" gcx)
  (let ( (rloc (unsafe_get_field :nrep_loc nret))
	 (rmain (unsafe_get_field :nret_main nret))
	 (rrest (unsafe_get_field :nret_rest nret)) ;; a tuple or nil
	 (retloc (unsafe_get_field :gncx_retloc gcx))
	 (orout (unsafe_get_field :gncx_objrout gcx))
	 (olis (make_list discr_list))
	 (oblock (instance class_objplainblock
			   :obi_loc rloc
			   :oblo_bodyl olis))
	 (omainv (progn (debug "compilobj_nrep_return rmain=" rmain)
			(compile_obj rmain gcx)))
	 )
    (debug "compilobj_nrep_return omainv=" omainv)
    (assert_msg "check orout" (is_a orout class_routineobj) orout)
    (assert_msg "check rrest" (is_multiple_or_null rrest) rrest)
    (if (null (get_field :obrout_retval orout))
	(put_fields orout :obrout_retval retloc))
    (debug "compilobj_nrep_return omainv=" omainv " retloc=" retloc)
    (if retloc 
	(list_append olis (put_objdest omainv retloc)))
    (when (and (is_a orout class_initialroutineobj)
	       (>i (multiple_length rrest) 0))
      (debug "compilobj_nrep_return bad initial orout=" orout " with secondary results rrest=" rrest)
      (error_plain rloc "(RETURN ...) with secondary results outside of function")
      (return)
      )
    (debug "compilobj_nrep_return rrest=" rrest)
    (foreach_in_multiple
     (rrest)
     (rxtra :long ix)
     (debug "compilobj_nrep_return rxtra=" rxtra " ix=" ix)
     (let ( (oxres 
	     (instance class_objputxtraresult
		       :obi_loc rloc
		       :obxres_rank (make_integerbox discr_integer ix)
		       :obxres_obloc (compile_obj rxtra gcx))) 
	    )
       (debug "compilobj_nrep_return oxres=" oxres)
       ;; maybe we need to compute the ctype of the extra result....
       (list_append olis oxres)))
    ;; if no secondary results are returned, emit a check that no
    ;; secondary actual results are expected
    (if (is_a orout class_procroutineobj)
	(if (==i (multiple_length rrest) 0)
	    (let ( (ochecknores 
		    ;; I should be ashamed of this, we really should a
		    ;; special class subclass of class_objinstr for
		    ;; that check.
		    (make_objlocatedexp 
		     rloc ctype_void		
		     "/*ochecknores compilobj_nrep_return*/\n"
		     "#if MELT_HAVE_DEBUG\n"
		     " if (meltxresdescr_ && meltxresdescr_[0] && meltxrestab_)\n"
		     "    melt_warn_for_no_expected_secondary_results();\n"
		     "/* we warned when secondary results are expected but not returned. */\n"
		     "#endif /*MELT_HAVE_DEBUG*/\n"
		     ))
		   )
	      (debug "compilobj_nrep_return ochecknores=" ochecknores)
	      (list_append olis ochecknores)
	      )))
    (list_append olis 
		 (instance class_objfinalreturn
			   :obi_loc rloc))
    (debug "compilobj_nrep_return final oblock=" oblock)
    oblock
    ))
 
(install_method class_nrep_return compile_obj compilobj_nrep_return)

(install_method class_nrep_return get_ctype 
		(lambda (recv env) ctype_value))
;; all the closures generated by lambda share the same ...
(definstance discrclosure_objpredef class_objpredef
  :obv_type ctype_value
  :obpredef 'DISCR_CLOSURE
  )

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun compilobj_nrep_lambda (nlam gcx)
  (debug "compilobj_nrep_lambda nlam=" nlam "\n.. gcx=" gcx)
  (assert_msg "check nlam" (is_a nlam class_nrep_lambda) nlam)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (shortbacktrace_dbg "compilobj_nrep_lambda" 12)
  (let ( (nloc (unsafe_get_field :nrep_loc nlam))
	 (npro (let 
		   ( (checkpro (unsafe_get_field :nlambda_proc nlam)) )
		 (debug "compilobj_nrep_lambda npro=" checkpro)
		 (assert_msg "check checkpro" (is_a checkpro class_nrep_routproc) checkpro)
		 checkpro))
	 (nam (get_field :nrclop_name npro))
	 (nclovtup (unsafe_get_field :nlambda_closedv nlam))
	 (:long nbclosed (multiple_length nclovtup))
	 (locv (get_free_objlocptr gcx nam))
	 (nrou (unsafe_get_field :nlambda_constrout nlam))
	 (orout (unsafe_get_field :gncx_objrout gcx))
	 (olis (make_list discr_list))
	 (oblock (instance class_objplainblock
			   :obi_loc nloc
			   :oblo_bodyl olis))
	 (destlist (make_list discr_list))
	 )
    (debug "compilobj_nrep_lambda nrou=" nrou "\n.. npro=" npro "\n.. orout=" orout)
    (list_append destlist locv)
    (list_append olis 
		 (instance 
		  class_objnewclosure
		  :obi_loc nloc
		  :obnclo_discr discrclosure_objpredef
		  :obnclo_rout 
		  (progn 
		    (let ( (crou (compile_obj nrou gcx)) )
		      (debug "compilobj_nrep_lambda crou=" crou)
		      crou)
		    )
		  :obnclo_len (make_integerbox discr_integer nbclosed)
		  :obdi_destlist destlist))
    (foreach_in_multiple
     (nclovtup)
     (clov :long ix)
     (list_append 
      olis
      (instance class_objputclosedv
		:obi_loc nloc
		:opclov_clos locv
		:opclov_off (make_integerbox discr_integer ix)
		:opclov_cval (compile_obj clov gcx))))
    ;; we don't need to add any objtouch because the nlam was normalized!
    (list_append olis locv) ;;; last instruction is just the value, which can be set to some dest
    (debug "compilobj_nrep_lambda result oblock=" oblock)
    oblock
    ))
(install_method class_nrep_lambda compile_obj compilobj_nrep_lambda)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun compilobj_nrep_makeinst (nmki gcx)
  (debug "compilobj_nrep_makeinst nmki=" nmki)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (assert_msg "check nmki" (is_a nmki class_nrep_instance) nmki)
  (let ( (nloc (unsafe_get_field :nrep_loc nmki))
	 (ncla (unsafe_get_field :nmins_class nmki))
	 (ncladat (unsafe_get_field :nmins_cladata nmki))
	 (nfields (unsafe_get_field :nmins_fields nmki)) 
	 )
    (assert_msg "check ncla" (is_a ncla class_class) ncla)
    (let ( (:long nbfld (multiple_length (unsafe_get_field :class_fields ncla)))
	   (destlist (make_list discr_list))
	   (locv (get_free_objlocptr gcx 'inst))
	   (olis (make_list discr_list))
	   (ocladat (compile_obj ncladat gcx))
	   (oblock (instance class_objplainblock
			     :obi_loc nloc
			     :oblo_bodyl olis))
	   (orallobj (instance class_objrawallocobj
			       :obi_loc nloc
			       :obrallobj_class ocladat
			       :obrallobj_len (make_integerbox discr_integer nbfld)
			       :obrallobj_classname (unsafe_get_field :named_name  ncla)
			       :obdi_destlist destlist))
	   )
      (list_append destlist locv)
      (list_append olis orallobj)
      ;; handle each field assign
      (foreach_in_multiple
       (nfields)
       (cfla :long ix)
       (assert_msg "compilobj_nrep_makeinst check cfla" (is_a cfla class_nrep_fieldassign) cfla)
       (let ( (cfloc (unsafe_get_field :nrep_loc cfla))
	      (cfield (unsafe_get_field :nfla_field cfla))
	      (cval (unsafe_get_field :nfla_val cfla)) )
	 (assert_msg "compilobj_nrep_makeinst check cfield" (is_a cfield class_field) cfield)
	 (let ( (oval (compile_obj cval gcx)) 
		(oputs (instance class_objputslot 
				 :obi_loc (if cfloc cfloc nloc)
				 :oslot_odata locv
				 :oslot_field cfield
				 :oslot_offset (make_integerbox discr_integer (get_int cfield))
				 :oslot_value oval))
		)
	   (debug "compilobj_nrep_makeinst cval=" cval "\n.. oputs=" oputs)
	   (assert_msg "compilobj_nrep_makeinst check oval not nrep" (not (is_a oval class_nrep)) oval)
	   (list_append olis oputs)
	   )))
      ;; since nmki was normalized, the new object was allocated in
      ;; the birth zone so don't need to be touched.  
      ;; 
      ;; add the debugtracing
      (let ( (odbgtr (instance class_objdbgtracewriteobj
			       :obi_loc nloc
			       :obdtw_writtenobj locv
			       :obdtw_message '"newly made instance"
			       ))
	     )
	(list_append olis odbgtr)
	)
      (list_append olis locv) ;;; last instruction is just the value, which can be set to some dest
      (debug "compilobj_nrep_makeinst result oblock=" oblock)
      oblock
      )))
  
(install_method class_nrep_instance compile_obj compilobj_nrep_makeinst)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; compile a procedure should not be called
(defun compilobj_routproc (npro gcx)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (assert_msg "check npro" (is_a npro class_nrep_routproc) npro)
  (debug "compilobj_routproc npro=" npro "\n... gcx=" gcx)
  (assert_msg "UNEXPECTED CALL TO compilobj_routproc" () npro)
  )
(install_method class_nrep_routproc compile_obj compilobj_routproc)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;
(defun compilobj_predef (npr gcx)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (assert_msg "check npr" (is_a npr class_nrep_predef) npr)
  (let ((obpred (get_field :nrpredef npr))
	(opr (instance class_objpredef
			:obv_type ctype_value
			:obpredef obpred)) 
	)
    (assert_msg "check obpred" obpred npr)
    opr)
  )

(install_method class_nrep_predef compile_obj compilobj_predef)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;; common code to compilobj_datasymbol & compilobj_datainstance
;;; to add the initial data fill and the slots filling
;;; return a tuple of bindings to be disposed
(defun compil_data_and_slots_fill (ndat obj odiscr irout gcx)
  (debug "compil_data_and_slots_fill start ndat=" ndat 
	 "\n.. obj=" obj 
	 "\n.. odiscr=" odiscr 
	 "\n.. irout=" irout "\n")
  (shortbacktrace_dbg "compil_data_and_slots_fill" 25)
  (assert_msg "compil_data_and_slots_fill check ndat" (is_a ndat class_nrep_bound_data) ndat)
  (assert_msg "compil_data_and_slots_fill check obj" (is_a obj class_objinitobject) obj)
  (assert_msg "compil_data_and_slots_fill check odiscr" (is_a odiscr class_objvalue) odiscr)
  (assert_msg "compil_data_and_slots_fill check irout" (is_a irout class_any_start_routineobj) irout)
  (assert_msg "compil_data_and_slots_fill check gcx" (is_a gcx class_c_generation_context) gcx)
  (let (
	(ipredef 
	 (cond
	   ( (is_a ndat class_nrep_datainstance) 
	     (unsafe_get_field :ninst_predef ndat))
	   ( (is_a ndat class_nrep_datahook)
	     (unsafe_get_field :ndhook_predef ndat))))
	(ibodylis (get_field :obrout_body irout))
	(locvar (get_free_objlocptr gcx '_valdata_))
	(comm (unsafe_get_field :named_name '_valuedata_))
	(nloc (unsafe_get_field :nrep_loc ndat))
	(dlocbind (unsafe_get_field :ndata_locbind ndat))
	(locmap (unsafe_get_field :gncx_locmap gcx))
	(istmtlis ibodylis) ;the statement list to which the putslots are appended
	;; a tuple to store the objvar for localbinds to be able to clear them later
	(tupvar (make_multiple discr_multiple (multiple_length locmap)))
	)
    (assert_msg "compil_data_and_slots_fill check ibodylis" (is_list ibodylis) ibodylis)
    (assert_msg "compil_data_and_slots_fill check fresh obj" (null (unsafe_get_field :oie_locvar obj)) obj)
    (unsafe_put_fields obj :oie_locvar locvar)
    (debug "compil_data_and_slots_fill updated obj=" obj)
    ;; if the data is predefined, we fill it conditionally on !meltpredefinited[..]
    (if ipredef
	(let ( 
	      (otestpredef 
	       (cond 
		( (is_a ipredef class_symbol)
		  (instance 
		   class_objexpv
		   :obx_cont (tuple
			      (make_stringconst discr_verbatim_string 
						"MELTPREDEFIX(meltpredefinited,")
			      (make_string discr_verbatim_string 
					   (unsafe_get_field :named_name ipredef))
			      (make_stringconst discr_verbatim_string 
						")")
			      ))
		  )
		( (is_integerbox ipredef)
		  (instance
		   class_objexpv
		   :obx_cont (tuple
			      (make_stringconst discr_verbatim_string 
						"predefinited[")
			      ipredef
			      (make_stringconst discr_verbatim_string 
						"]")
			      ))
		  )
		))
	      (initlis (make_list discr_list))
	      (oblockpredef (instance 
			     class_objcommentedblock
			     :oblo_bodyl initlis
			     :ocomblo_comment '"fill predef slots"))
	      (ocondpredef (instance
			    class_objcond
			    :obi_loc nloc
			    :obcond_test otestpredef
			    :obcond_then ()
			    :obcond_else oblockpredef))
	      )
	  (setq istmtlis initlis)
	  (list_append ibodylis ocondpredef)
	  ))
    (debug "compil_data_and_slots_fill dlocbind=" dlocbind)
    (foreach_in_multiple
     (dlocbind)
     (lbind :long bindrk)
     (debug "compil_data_and_slots_fill lbind=" lbind)
     (assert_msg "compil_data_and_slots_fill check lbind" (is_a lbind class_normal_let_binding) lbind)
     (let ( (bder (unsafe_get_field :binder lbind))
	    (cty (unsafe_get_field :letbind_type lbind))
	    (nexp (unsafe_get_field :letbind_expr lbind))
	    (obva (get_free_objloctyped gcx bder cty))
	    (obnx (compile_obj nexp gcx)) 
	    )
       (debug "compil_data_and_slots_fill obnx=" obnx "\n.. obva=" obva)
       (if obva (mapobject_put locmap lbind obva))
       (let ( (obmy (if obva (put_objdest obnx obva) obnx)) )
	 ;; add the modified obmy in the ibodylis
	 (list_append istmtlis obmy)
	 )
       (if obva (multiple_put_nth tupvar bindrk obva))
       ))
    (shortbacktrace_dbg "compil_data_and_slots_fill [slo]" 21)
    (debug "compil_data_and_slots_fill ndats slots="
	   (get_field :ninst_slots ndat))
    ;; for every non nil slot, append its initialization to istmtlis
    (foreach_in_multiple
     ((unsafe_get_field :ninst_slots ndat))
     (sloval :long slork)
     (if sloval
;;; add to list inifill the filling in dai of slot#slork by slobj
	 (let ( (slobj (compile_obj sloval gcx)) 
		)
	   (debug "compil_data_and_slots_fill slobj=" slobj "\n.. sloval=" sloval "\n slork#" slork)
	   (assert_msg "compil_data_and_slots_fill check slobj not nrep" (is_not_a slobj class_nrep) slobj)
	   (let (
		 (ooff (make_integerbox discr_integer slork))
		 (oput (instance class_objputslot
				 :obi_loc  nloc
				 :oslot_odata obj
				 :oslot_offset ooff
				 :oslot_value slobj
				 )) 
		 )
	     (debug "compil_data_and_slots_fill oput=" oput "\n for sloval=" sloval)
	     (shortbacktrace_dbg "compil_data_and_slots_fill oput" 18)
	     (list_append istmtlis oput)
	     ))))
    ;; touch the object
    (list_append istmtlis 
		 (instance class_objtouch
			   :obi_loc (if nloc nloc (unsafe_get_field :nrep_loc ndat))
			   :otouch_comment comm
			   :otouch_val obj))
    ;; debugwrite the object		;
    (list_append istmtlis
    (instance class_objdbgtracewriteobj
    :obi_loc (if nloc nloc (unsafe_get_field :nrep_loc ndat))
    :obdtw_writtenobj obj
    :obdtw_message '"new static instance"))
    ;; for every non nil local obvar, clear it
    (multiple_every
     tupvar
     (lambda (obva :long ix)
       (if obva
	   (progn
	     (list_append ibodylis
			  (instance class_objclear 
				    :obi_loc nloc
				    :oclr_vloc obva))
	     ))))
;;; add the obj as the last instr of the block
    (list_append ibodylis obj)
    ;;
    (debug "compil_data_and_slots_fill final dlocbind=" dlocbind)
    ;; the caller is supposed to do
    ;; dispose_dlocbind_after_data_and_slots_fill with the result if
    ;; needed but in practice this is never needed
    (return dlocbind)
    )
  (return)				;force a nil return
  )


;; probably useless function
(defun dispose_dlocbind_after_data_and_slots_fill (dlocbind gcx)
  (debug "dispose_dlocbind_after_data_and_slots_fill dlocbind=" dlocbind)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (multiple_every
   dlocbind
   (lambda (bnd :long ix) (dispose_bnd_obj bnd gcx)))
  )
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun compilobj_datasymbol (syv gcx)
  (debug "compilobj_datasymbol syv=" syv)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (assert_msg "check syv" (is_a syv class_nrep_datasymbol) syv)
  (let ( (compicache (unsafe_get_field :gncx_compicache gcx)) 
	 (chobj (mapobject_get compicache syv))
	 (inirout (unsafe_get_field :gncx_objrout gcx))
	 )
    (debug "compilobj_datasymbol inirout=" inirout 
	   "\n compicache=" compicache "\n chobj=" chobj)
    ;; datasymbol compiled only in start routines
    (assert_msg "check inirout" (is_a inirout class_any_start_routineobj) inirout)
    (when chobj
      (debug "compilobj_datasymbol found chobj=" chobj)
      (return chobj))
    (let (
	  (odiscr  (compile_obj (unsafe_get_field :ndata_discrx syv) gcx))
	  (obsym 
	   ;;; symbols should be unique objects, to avoir recreating
	   ;;; them when they already exist.
	   (instance class_objinituniqueobject
		     :obv_type ctype_value
		     :oie_data syv
		     :oie_discr odiscr
		     :oie_cname ()
		     :oio_class ()
		     )) 
	  )
      (mapobject_put compicache syv obsym)
      (debug "compilobj_datasymbol obsym=" obsym  "\n.. syv=" syv 
	     "\n.. updated compicache=" compicache "\n")
      ;; make a cname
      (let ( (nambuf (make_strbuf discr_strbuf))
	     (:long syrk (get_int (unsafe_get_field :ndata_rank syv)))
	     )
	(add2sbuf_strconst nambuf "dsym_")
	(add2sbuf_longdec nambuf syrk)
	(add2sbuf_strconst nambuf "__")
	(add2sbuf_cident nambuf (unsafe_get_field :ndsy_namestr syv))
	(unsafe_put_fields obsym
			   :oie_cname (strbuf2string discr_string nambuf)))
      (shortbacktrace_dbg "compilobj_datasymbol" 6)
      (debug "compilobj_datasymbol obsym=" obsym "\n.. for syv=" syv)
      ;; put the length as obj_num of obsym
      (put_int obsym (multiple_length (unsafe_get_field :ninst_slots syv)))
      (let ( (dlocbind (compil_data_and_slots_fill syv obsym odiscr inirout gcx)) ) 
	(debug "compilobj_datasymbol dlocbind=" dlocbind)
	;;(dispose_dlocbind_after_data_and_slots_fill dlocbind gcx)
	)
      (shortbacktrace_dbg "compilobj_datasymbol" 9)
      (debug "compilobj_datasymbol final obsym=" obsym)
      (return obsym)
      )))
(install_method class_nrep_datasymbol compile_obj compilobj_datasymbol)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;; compilobj of datainstance
(defun compilobj_datainstance (dai gcx)
  (debug "compilobj_datainstance dai=" dai)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (let ( (compicache (unsafe_get_field :gncx_compicache gcx)) 
	 (chobj (mapobject_get compicache dai))
	 (inirout (unsafe_get_field :gncx_objrout gcx))
	 )
    ;; datainstance compiled only in start routine
    (assert_msg "check inirout" (is_a inirout class_any_start_routineobj) inirout)
    (when chobj
      (debug "compilobj_datainstance return found chobj=" chobj)
      (return chobj))
    (let ( (loc (unsafe_get_field :nrep_loc dai))
	   (nam (unsafe_get_field :ndata_name dai))
	   ;; nam is a symbol, not a string
	   (disx (unsafe_get_field :ndata_discrx dai))
	   (drank (unsafe_get_field :ndata_rank dai))
	   (dhash (unsafe_get_field :ninst_hash dai))
	   (dpredef (unsafe_get_field :ninst_predef dai))
	   (dslots (unsafe_get_field :ninst_slots dai)) 
	   )
      ;; if the drank is invalid or nil, the data has never been added
      ;; with add_nctx_data (should not happen)
      (assert_msg "compilobj_datainstance check drank" (is_integerbox drank) drank)
      (let ( (cdisx (compile_obj disx gcx)) 
	     )
	(debug "compilobj_datainstance cdisx=" cdisx)
	(let (
	      ;; make a cname
	      (oini (if dpredef ;; if predefined, make it unique!
			(instance class_objinituniqueobject
			      :obv_type ctype_value
			      :oie_data dai
			      :oie_discr cdisx
			      :oio_predef dpredef
			      :oio_class ()
			      )
		      ;; othewise, don't bother make it unique
			(instance class_objinitobject
			      :obv_type ctype_value
			      :oie_data dai
			      :oie_discr cdisx
			      :oio_predef dpredef
			      :oio_class ()
			      )
		      ))
	      (nambuf (make_strbuf discr_strbuf))
	      (:long drk (get_int drank))
	      )
	  (debug "compilobj_datainstance oini=" oini)
	  (shortbacktrace_dbg "compilobj_datainstance" 14)
	  (mapobject_put compicache dai oini)
	  (debug "compilobj_datainstance updated compicache=" compicache 
		 "\n.. dai=" dai "\n.. oini=" oini)
	  (add2sbuf_strconst nambuf "dobj_")
	  (add2sbuf_longdec nambuf drk)
	  (if nam (progn
		    (add2sbuf_strconst nambuf "__")
		    (add2sbuf_cident nambuf (get_field :named_name nam))))
	  (let ( (cnam (strbuf2string discr_string nambuf)) )
	    (unsafe_put_fields oini :oie_cname cnam)
	    )
	  (put_int oini (multiple_length dslots))
	  (let ( (dlocbind (compil_data_and_slots_fill dai oini cdisx inirout gcx)) )
	    (debug "compil_data_and_slots_fill dlocbind=" dlocbind)
	    ;;(dispose_dlocbind_after_data_and_slots_fill dlocbind gcx)
	    )
	  (debug "compilobj_datainstance final oini=" oini)
	  (return oini)
	  )  
	)
      )
    )
  )
(install_method class_nrep_datainstance compile_obj compilobj_datainstance)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;; compile a data tuple
(defun compilobj_datatuple (nti gcx)
  (debug "compilobj_datatuple nti=" nti)
  (assert_msg "check nti" (is_a nti class_nrep_datatuple) nti)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (let ( (compicache (unsafe_get_field :gncx_compicache gcx)) 
	 (chobj (mapobject_get compicache nti))
	 (inirout (unsafe_get_field :gncx_objrout gcx))
	 )
    ;; datatuples compiled only in start routine
    (debug "compilobj_datatuple inirout=" inirout)
    (assert_msg "check inirout" (is_a inirout class_any_start_routineobj) inirout)
    (when chobj
      (debug "compilobj_datatuple found chobj=" chobj)
      (return chobj))
    (let ( (ncompi (unsafe_get_field :ntup_comp nti))
	   (ocompi (multiple_map 
		    ncompi
		    (lambda (c :long ix) (if c (compile_obj c gcx)))))
	   (disx (unsafe_get_field :ndata_discrx nti))
	   (drank (unsafe_get_field :ndata_rank nti))
	   (odiscr (compile_obj disx gcx)) 
	   (nam (unsafe_get_field :ndata_name nti))
	   (nambuf (make_strbuf discr_strbuf))
	   (locvar (get_free_objlocptr gcx '_valtup_))
	   (:long drk (get_int drank))
	   (inibody (get_field :obrout_body inirout))
	   (comm (unsafe_get_field :named_name '_initup_))
	   )
      (add2sbuf_strconst nambuf "dtup_")
      (add2sbuf_longdec nambuf drk)
      (cond 
       ((is_a nam class_symbol)
	(add2out nambuf "_sy" (symbol_cname nam)))
       ((is_a nam class_named)
	(add2sbuf_strconst nambuf "__")
	(add2sbuf_cident nambuf (get_field :named_name nam)))
       ((is_string nam)
	(add2out nambuf "___") (add2sbuf_cident nambuf nam)))
      (let ( (otup (instance class_objinitmultiple
			     :obv_type ctype_value
			     :oie_discr odiscr
			     :oie_locvar locvar
			     :oie_cname (strbuf2string discr_verbatim_string nambuf)
			     :oim_tupval ocompi
			     ))
	     )
	(mapobject_put compicache nti otup)
	(debug "compilobj_datatuple updated compicache=" compicache
	       "\n.. nti=" nti "\n.. otup=" otup)
	(put_int otup (multiple_length ncompi))
	(multiple_every
	 ncompi
	 (lambda (scomp :long srk)
	   (if scomp 
	       (let ( (ocomp (multiple_nth ocompi srk)) )
		 (list_append inibody
			      (instance class_objputuple
					:oputu_tupled otup
					:oputu_offset (make_integerbox discr_integer srk)
					:oputu_value ocomp)))
	     )))
	(list_append inibody
		     (instance class_objtouch
			       :otouch_val otup
			       :otouch_comment comm))
	(debug "compilobj_datatuple otup=" otup)
	(return otup)
	)
      )
    )
  )

(install_method class_nrep_datatuple compile_obj compilobj_datatuple)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;; compile a data string
(defun compilobj_datastring (nds gcx)
  (assert_msg "check nds" (is_a nds class_nrep_datastring) nds)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (let ( (compicache (unsafe_get_field :gncx_compicache gcx)) 
	 (inirout (unsafe_get_field :gncx_objrout gcx))
	 (chobj (mapobject_get compicache nds))
	 )
    ;; datastring compiled only in initial routines
    (assert_msg "check inirout" (is_a inirout class_any_start_routineobj) inirout)
    (if chobj
	(progn
	  (return chobj)))
    (let (
	  (nambuf (make_strbuf discr_strbuf))
	  (ndisx (unsafe_get_field :ndata_discrx nds))
	  (odiscr (compile_obj ndisx gcx))
	  (odata (unsafe_get_field :nstr_string nds))
	  (drank (unsafe_get_field :ndata_rank nds))
	  (nam (unsafe_get_field :ndata_name nds))
	  (locvar (get_free_objlocptr gcx '_valstr_))
	  (:long drk (get_int drank))
	  (ostr (instance class_objinitstring
			  :obv_type ctype_value
			  :oie_data odata
			  :oie_discr odiscr
			  :oie_locvar locvar
			  )) 
	  )
      (mapobject_put compicache nds ostr)
      (debug "compilobj_datastring updated compicache=" compicache
	     "\n.. nds=" nds "\n.. ostr=" ostr)
      (add2sbuf_strconst nambuf "dstr_")
      (add2sbuf_longdec nambuf drk)
      (add2sbuf_strconst nambuf "__")
      (add2sbuf_cidentprefix nambuf odata 24)
      (put_int ostr (string_length odata))
      (if nam 
	  (progn
	    (add2sbuf_strconst nambuf "__")
	    (add2sbuf_cident nambuf (unsafe_get_field :named_name nam))))
      (unsafe_put_fields ostr :oie_cname (strbuf2string discr_string nambuf))
      ostr
      )
    ))
(install_method class_nrep_datastring compile_obj compilobj_datastring)

;;;;;;;;;;;;;;;; compile a data boxed integer
(defun compilobj_databoxedinteger (ndi gcx)
  (debug "compilobj_databoxedinteger ndi=" ndi)
  (assert_msg "check ndi" (is_a ndi class_nrep_databoxedinteger) ndi)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (let ( (compicache (unsafe_get_field :gncx_compicache gcx)) 
	 (inirout (unsafe_get_field :gncx_objrout gcx))
	 (chobj (mapobject_get compicache ndi))
	 )
    ;; datastring compiled only in initial routines
    (assert_msg "check inirout" (is_a inirout class_any_start_routineobj) inirout)
    (when chobj
      (debug "compilobj_databoxedinteger found chobj=" chobj)
      (return chobj))
    (let (
	  (nambuf (make_strbuf discr_strbuf))
	  (ndisx (unsafe_get_field :ndata_discrx ndi))
	  (odiscr (compile_obj ndisx gcx))
	  (odata (unsafe_get_field :nboxint_num ndi))
	  (drank (unsafe_get_field :ndata_rank ndi))
	  (nam (unsafe_get_field :ndata_name ndi))
	  (locvar (get_free_objlocptr gcx '_valbxint_))
	  (:long drk (get_int drank))
	  (oint (instance class_objinitboxinteger
			  :obv_type ctype_value
			  :oie_data odata
			  :oie_discr odiscr
			  :oie_locvar locvar
			  )) 
	  )
      (mapobject_put compicache ndi oint)
      (debug "compilobj_databoxedinteger updated compicache=" compicache "\n ndi=" ndi "\n.. oint=" oint)
      (add2sbuf_strconst nambuf "dint_")
      (add2sbuf_longdec nambuf drk)
      (add2sbuf_strconst nambuf "__")
      (add2sbuf_cidentprefix nambuf odata 16)
      (if nam 
	  (progn
	    (add2sbuf_strconst nambuf "__")
	    (add2sbuf_cident nambuf (unsafe_get_field :named_name nam))))
      (unsafe_put_fields oint :oie_cname (strbuf2string discr_string nambuf))
      oint
      )
    ))
(install_method class_nrep_databoxedinteger compile_obj compilobj_databoxedinteger)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;; compile a data closure
(defun compilobj_dataclosure (ncl gcx)
  (debug "compilobj_dataclosure ncl=" ncl)
  (assert_msg "check ncl" (is_a ncl class_nrep_dataclosure) ncl)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (let ( (compicache (unsafe_get_field :gncx_compicache gcx)) 
	 (inirout (unsafe_get_field :gncx_objrout gcx))
	 (inibody (unsafe_get_field :obrout_body inirout))
	 (chobj (mapobject_get compicache ncl))
	 )
    (assert_msg  "check inirout" (is_a inirout class_any_start_routineobj) inirout)
    (when chobj
      (debug  "compilobj_dataclosure found chobj=" chobj)
      (return chobj))
    (let ( 
	  (nam (unsafe_get_field :ndata_name ncl))
	  (discx (unsafe_get_field :ndata_discrx ncl))
	  (nrank (unsafe_get_field :ndata_rank ncl))
	  (nloc (unsafe_get_field :nrep_loc ncl))
	  (npro (unsafe_get_field :ndclo_proc ncl))
	  (nclov (unsafe_get_field :ndclo_closv ncl))
	  (:long nbclos (multiple_length nclov))
	  (nambuf (make_strbuf discr_strbuf))
	  (odiscr (compile_obj discx gcx))
	  (locvar (get_free_objlocptr gcx '_valclo_))
	  (comm (unsafe_get_field :named_name '_dataclosure_))
	  )
      (assert_msg "check npro" (is_a npro class_nrep_routproc) npro)
      (add2sbuf_strconst nambuf "dclo_")
      (add2sbuf_longdec nambuf (get_int nrank))
      (when nam
	(add2sbuf_strconst nambuf "__")
	(add2sbuf_cident nambuf (unsafe_get_field :named_name nam)))
      (let (
	    (ndatarou (unsafe_get_field :nrpro_datarout npro))
	    (oiclo
	     (instance class_objinitclosure
		       :obv_type ctype_value
		       :oie_discr odiscr
		       :oie_data ncl
		       :oie_locvar locvar
		       :oie_cname (strbuf2string discr_string nambuf)
		       )) 
	    )
	(put_int oiclo nbclos)
	(mapobject_put compicache ncl oiclo)
	(debug  "compilobj_dataclosure updated compicache=" compicache
		"\n.. ncl=" ncl "\n.. oiclo=" oiclo)
	(assert_msg "check ndatarou" (is_a ndatarou class_nrep_dataroutine) ndatarou)
	(let (
	      ;; npro should already have been compiled, so should be in the compiler cache
	      (ocrout (mapobject_get compicache npro))
	      (odatrout (compile_obj ndatarou gcx))
	      (ocputrout (instance  class_objputclosurout
				    :obi_loc nloc
				    :opclor_clos oiclo
				    :opclor_rout odatrout
				    ;;@@OLDBUGGY :opclor_rout (mapobject_get compicache ndatarou)
				    ))
	      (bxoff (make_integerbox discr_integer 0))
	      )
	  (assert_msg "check ocrout" (is_a ocrout class_procroutineobj) ocrout)
	  (list_append inibody ocputrout)
	  (multiple_every
	   nclov
	   (lambda (clov :long ix)
	     (let ( (cloval (compile_obj clov gcx)) 
		    (ocputclos (instance class_objputclosedv
					 :obi_loc nloc
					 :opclov_clos oiclo
					 :opclov_off (make_integerbox discr_integer (get_int bxoff))
					 :opclov_cval cloval))
		    )
	       (list_append inibody ocputclos)
	       )
	     (put_int bxoff (+i (get_int bxoff) 1))))
	  (list_append inibody (instance class_objtouch
					 :obi_loc nloc
					 :otouch_comment comm
					 :otouch_val oiclo))
	  oiclo
	  ))
      ))
  )
(install_method class_nrep_dataclosure compile_obj compilobj_dataclosure)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;; compile a data routine
(defun compilobj_dataroutine (ndrou gcx)
  (debug "compilobj_dataroutine ndrou=" ndrou "\n.. gcx=" gcx)
  (shortbacktrace_dbg "compilobj_dataroutine" 16)
  (assert_msg "check ndrou" (is_a ndrou class_nrep_dataroutine) ndrou)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (let ( (compicache (unsafe_get_field :gncx_compicache gcx)) 
	 (inirout (unsafe_get_field :gncx_objrout gcx))
	 (chobj (mapobject_get compicache ndrou))
	 )
    ;; dataroutine compiled only in initial routines
    (debug "compilobj_dataroutine" " inirout=" inirout)
    (shortbacktrace_dbg "compilobj_dataroutine" 10)
    (assert_msg "check inirout" (is_a inirout class_any_start_routineobj) inirout)
    (when chobj
      (debug "compilobj_dataroutine return chobj=" chobj)
      (return chobj))
    (let ( (nam (unsafe_get_field :ndata_name ndrou))
	   (disx (unsafe_get_field :ndata_discrx ndrou))
	   (nloc (unsafe_get_field :nrep_loc ndrou))
	   (drank (unsafe_get_field :ndata_rank ndrou))
	   (nam (unsafe_get_field :ndata_name ndrou))
	   (npro (get_field :ndrou_proc ndrou))
	   (inibody (get_field :obrout_body inirout))
	   (locvar (get_free_objlocptr gcx '_valrout_))
	   )
      (debug "compilobj_dataroutine" " npro=" npro "\n.. ndrou=" ndrou)
      (if (null nloc)
	  (if (is_a npro class_nrep)
	      (setq nloc (unsafe_get_field :nrep_loc npro))))
      (debug "compilobj_dataroutine compicache=" compicache)
      (assert_msg "check compicache" (is_mapobject compicache) compicache)
      (let (
	    (nambuf (make_strbuf discr_strbuf))
	    (:long drk (get_int drank))
	    (odiscr (compile_obj disx gcx))
	    )
	(add2sbuf_strconst nambuf "drout_")
	(add2sbuf_longdec nambuf drk)
	(when nam
	  (add2sbuf_strconst nambuf "__")
	  (add2sbuf_cident nambuf (unsafe_get_field :named_name nam)))
	(let (
	      (oinipro (mapobject_get compicache npro))
	      (oirout 
	       (instance class_objinitroutine
			 :obv_type ctype_value
			 :oie_discr odiscr
			 :oie_data ndrou
			 :oie_locvar locvar
			 :oie_cname (strbuf2string discr_string nambuf)
			 :oir_procroutine oinipro
			 )) 
	      )
	  (debug "compilobj_dataroutine oirout=" oirout "\n .. oinipro=" oinipro
		 "\n.. npro=" npro "\n.. compicache=" compicache
		 "\n.. ndrou=" debug_less ndrou)
	  (assert_msg "check oinipro" (is_object oinipro) oinipro npro compicache ndrou)
	  (mapobject_put compicache ndrou oirout)
	  (debug "compilobj_dataroutine updated compicache=" compicache 
		 "\n.. ndrou=" ndrou "\n.. oirout=" oirout)
	  (if (is_a npro class_nrep_routproc)
	      (let ( (pconstl (get_field :nrclop_constlist npro)) 
		     (:long nbconst (list_length pconstl))
		     (bxoff (make_integerbox discr_integer 0))
		     (comm (unsafe_get_field :named_name '_iroutval_))
		     )
		(debug "compilobj_dataroutine pconstl=" pconstl)
		(put_int oirout nbconst)
		(foreach_pair_component_in_list
		 (pconstl)
		 (constpair constx)
		 (debug "compilobj_dataroutine constx=" constx)
		 (cond
		  ( (is_a constx class_nrep_constocc)
		    (let ( (cnstbind (unsafe_get_field :nocc_bind constx)) )
		      (assert_msg "compilobj_dataroutine check cnstbind" (is_a cnstbind class_any_binding) cnstbind)
		      (let ( 
			    (oconstx (compile_obj cnstbind gcx)) 
			    (:long off (get_int bxoff))
			    ) 
			(debug "compilobj_dataroutine oconstx=" oconstx "\n.. off=" off)
			(if oconstx 
			    (let (
				  (iput
				   (if (is_a cnstbind class_fixed_binding)
				       (instance class_objputroutconstnotnull
						 :obi_loc nloc
						 :oprconst_rout oirout
						 :oprconst_off (make_integerbox discr_integer off)
						 :oprconst_cval oconstx)
				     (instance class_objputroutconst
					       :obi_loc nloc
					       :oprconst_rout oirout
					       :oprconst_off (make_integerbox discr_integer off)
					       :oprconst_cval oconstx)
				     )) 
				  ) 
			      (list_append inibody iput)
			      (put_int bxoff (+i off 1))))))
		    )
		  ( (is_a constx class_nrep_quasidata)
		    (let ( 
			  (oconstx (compile_obj constx gcx)) 
			  (:long off (get_int bxoff))
			  ) 
		      (if oconstx 
			  (let ( (iput (instance class_objputroutconst
						 :obi_loc nloc
						 :oprconst_rout oirout
						 :oprconst_off (make_integerbox discr_integer off)
						 :oprconst_cval oconstx)) ) 
			    (list_append inibody iput)
			    (put_int bxoff (+i off 1))))))
		  (:else
		   (assert_msg "compilobj_dataroutine uneppected constx" () constx)
		   )
		  )
		 ) 			;end foreach_pair_component_in_list pconstl
		(if (>i (get_int bxoff) 0)
		    (list_append inibody (instance class_objtouch
						   :obi_loc nloc
						   :otouch_val oirout
						   :otouch_comment comm
						   )))
		(debug "compilobj_dataroutine final oirout=" oirout)
		oirout)
	    ))))
    )
  )
(install_method class_nrep_dataroutine compile_obj compilobj_dataroutine)




;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun compilobj_datahook (ndhook gcx)
  (debug "compilobj_datahook ndhook=" ndhook "\n.. gcx=" gcx "\n")
  (shortbacktrace_dbg "compilobj_datahook" 16)
  (assert_msg "check ndhook" (is_a ndhook class_nrep_datahook) ndhook)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (let ( (compicache (unsafe_get_field :gncx_compicache gcx)) 
	 (inirout (unsafe_get_field :gncx_objrout gcx))
	 (chobj (mapobject_get compicache ndhook))
	 (nloc (get_field :nrep_loc ndhook))
	 )
    (debug "compilobj_datahook compicache=" compicache)
    (assert_msg "check compicache" (is_mapobject compicache) compicache)
    (when chobj
      (debug "compilobj_datahook return chobj=" chobj)
      (return chobj))
    (debug "compilobj_datahook inirout=" inirout)
    (assert_msg "check inirout" (is_a inirout class_any_start_routineobj) inirout)
    (let ( 
	  (nclotup (let ( (nct (get_field :ndhook_closv ndhook)) )
		     (debug "compilobj_datahook nclotup=" nct)
		     nct))
	  (inibody (get_field :obrout_body inirout))
	  (:long nbclo (multiple_length nclotup))
	  (nhpro (get_field :ndhook_proc ndhook))
	  (hname (get_field :ndata_name ndhook))      ;a string
	  (nrank (get_field :ndata_rank ndhook))      ;a boxed int
	  (npredef (get_field :ndhook_predef ndhook)) ;a symbol or nil
	  (nmodvarbind (get_field :ndhook_modvarbind ndhook)) 
					;a normal module variable binding or nil
	  (nlocbind (get_field :ndata_locbind ndhook))
	  (ndisx (get_field :ndata_discrx ndhook))
	  (ndhdata (get_field :ndhook_data ndhook))
	  (odiscr (let ( (odi (compile_obj ndisx gcx)) )
		    (debug "compilobj_datahook odiscr=" odi)
		    odi))
	  (onam (string4out discr_verbatim_string
			    ##{dhook__$NRANK#__$HNAME}#))
	  (locvar (get_free_objlocptr gcx '_valhook_))
	  (oclo (make_multiple discr_multiple nbclo))
	  (ohkdata (let ( (o (compile_obj ndhdata gcx))
			  )
		     (debug "compilobj_datahook ohkdata=" o)
		     o))
	  (oihook 
	   (instance class_objinithook
		     :obv_type ctype_value
		     :oie_locvar locvar
		     :oie_cname onam
		     :oie_data ndhook
		     :oie_discr odiscr
		     :oihk_data ohkdata
		     :oihk_prochook nhpro
		     :oihk_cloval oclo
		     :oihk_predef npredef
		     :oihk_modvarbind nmodvarbind
		     ))
	  )
      (debug "compilobj_datahook before compiling nclotup=" nclotup)
      (foreach_in_multiple
       (nclotup)
       (ncurclo :long clix)
       (debug "compilobj_datahook clix#" clix " ncurclo=" ncurclo)
       (let ( (ocurclo (compile_obj ncurclo gcx))
	      )
	 (debug "compilobj_datahook clix#" clix " ocurclo=" ocurclo)
	 (multiple_put_nth oclo clix ocurclo)
	 ))
      (debug "compilobj_datahook oclo=" oclo)
      (mapobject_put compicache ndhook oihook)
      (put_int oihook (multiple_length oclo))
      (debug "compilobj_datahook updated compicache=" compicache 
	     "\n.. nclotup=" nclotup "\n.. nhpro=" nhpro
	     "\n.. oihook=" oihook
	     "\n.. oclo=" oclo "\n.. inibody=" inibody)
      (when nmodvarbind
	(assert_msg "check nmodvarbind" (is_a nmodvarbind class_normal_module_variable_binding) nmodvarbind)
	(let ( (opmv (instance class_objputmodvar
			       :obi_loc nloc
			       :obputmodvar_bind nmodvarbind
			       :obputmodvar_val oihook
			       ))
	       )
	  (list_append inibody opmv)
	  (debug "compilobj_datahook opmv=" opmv)
	  ))
      ;; set the data
      (let ( (ophd (instance class_objputhookdata
			     :obi_loc nloc
			     :ophkdata_hook oihook
			     :ophkdata_data ohkdata))
	     )
	(list_append inibody ophd)
	(debug "compilobj_datahook ophd=" ophd))
      ;; set the components
      (debug "compilobj_datahook oclo=" oclo)
      (foreach_in_multiple
       (oclo)
       (curobc :long obix)
       (debug "compilobj_datahook curobc=" curobc "   obix#" obix)
       (let ( 
	     (iput (instance class_objputhookconst
			     :obi_loc nloc
			     :ophconst_hook oihook
			     :ophconst_off (constant_box obix)
			     :ophconst_cval curobc
			     ))
	     )
	 (debug "compilobj_datahook obix=" obix ".. curobc=" curobc
		"\n.. iput=" iput)
	 (list_append inibody iput)
	 ))
      (when (multiple_length oclo)
	(list_append inibody (instance class_objtouch
				       :obi_loc nloc
				       :otouch_val oihook
				       :otouch_comment hname
				       )))
      (debug "compilobj_datahook updated inibody=" inibody "\n.. final oihook=" oihook "\n")
      (return oihook)
      )))

(install_method class_nrep_datahook compile_obj compilobj_datahook)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun compilobj_quasidata_current_module_environment_reference (qdcm gcx)
  (assert_msg "check qdcm" (is_a qdcm class_nrep_quasidata_current_module_environment_reference) qdcm)
  ;; the get_field below will fail if gcx is not a  class_initial_generation_context
  (let ( (locbox (get_field :igncx_contenvloc gcx)) 
	 )
    (return locbox)))
(install_method class_nrep_quasidata_current_module_environment_reference compile_obj compilobj_quasidata_current_module_environment_reference)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun compilobj_quasidata_parent_module_environment (qdpm gcx)
  (debug "compilobj_quasidata_parent_module_environment qdpm=" qdpm " gcx=" gcx)
  (assert_msg "check qdpm" (is_a qdpm class_nrep_quasidata_parent_module_environment) qdpm)
  ;; the get_field below will fail if gcx is not a  class_initial_generation_context
  (let ( (prevenvloc (get_field :igncx_prevenvloc gcx)) 
	 )
    (return prevenvloc)))
(install_method class_nrep_quasidata_parent_module_environment compile_obj compilobj_quasidata_parent_module_environment)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun compilobj_nrep_store_predefined (nspr gcx)
  (assert_msg "check nspr" (is_a nspr class_nrep_store_predefined) nspr)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (debug "compilobj_nrep_store_predefined start nspr=" nspr)
  (let ( (nloc (unsafe_get_field :nrep_loc nspr))
	 (npred (unsafe_get_field :nstpd_predef nspr))
	 (nval (unsafe_get_field :nstpd_value nspr))
	 (oval (compile_obj nval gcx)) 
	 (res ())
	 )
    (cond 
     ( (is_a npred class_symbol)
       (let ( (namepred (make_string discr_verbatim_string (get_field :named_name npred))) )
	 (setq res 
	       (make_objcompute 
		nloc
		ctype_void
		##{MELT_STORE_PREDEF($NAMEPRED, (melt_ptr_t) ($OVAL))}#)))
       )
     ( (is_integerbox npred)
       (setq res 
	     (make_objcompute
	      nloc
	      ctype_void
	      ##{melt_store_predefined($NPRED, (melt_ptr_t) ($OVAL))}#))
       )
     (:else
      (debug "compilobj_nrep_store_predefined bad npred=" npred)
      (assert_msg "compilobj_nrep_store_predefined invalid npred" () npred)
      (return))
     )
    (debug "compilobj_nrep_store_predefined result res=" res)
    res
    ))
(install_method class_nrep_store_predefined compile_obj compilobj_nrep_store_predefined)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(defun compilobj_nrep_update_current_module_environment_reference (nucmeb gcx)
  (assert_msg "check nucmeb" (is_a nucmeb class_nrep_update_current_module_environment_reference) nucmeb)
  (assert_msg "check gcx" (is_a gcx class_initial_generation_context) gcx)
  (debug "compilobj_nrep_update_current_module_environment_reference nucmeb=" nucmeb)
  (let ( (nloc (unsafe_get_field :nrep_loc nucmeb))
	 (ncomm (unsafe_get_field :ncumeb_comment nucmeb))
	 (nex (unsafe_get_field :nucmeb_expr nucmeb))
	 (pcml (unsafe_get_field :igncx_procurmodenvlist gcx))
	 (ocontenvloc (get_field :igncx_contenvloc gcx))
	 (csbuf (let ( (sb (make_strbuf discr_strbuf)) 
		       )
		  (add2sbuf_strconst sb "upd.cur.mod.env.cont")
		  (if (is_string ncomm)
		      (progn
			(add2sbuf_strconst sb " : ")
			(add2sbuf_string sb ncomm)))
		  sb
		  ))
	 (obodl (make_list discr_list))
	 (ocblo (instance class_objcommentedblock
			  :obi_loc nloc
			  :oblo_bodyl obodl
			  :ocomblo_comment 
			  (strbuf2string discr_string csbuf)))
	 (oex (compile_obj nex gcx))
	 )
    ;; get the igncx_procurmodenvlist from gcx
    ;; for each routine of class_procroutineobj  get its nrpro_const list and
    ;; for each CLASS_NREP_QUASIDATA_CURRENT_MODULE_ENVIRONMENT_REFERENCE there do ....
    (foreach_pair_component_in_list
     (pcml)
     (curpair curout)
     (debug "compilobj_nrep_update_current_module_environment_reference curout=" curout)
     (if (is_a curout class_procroutineobj)
	 (let (
	       (curproc (unsafe_get_field :obrout_proc curout))
	       (cnslis (get_field :nrclop_constlist curproc)) 
	       (datarout (unsafe_get_field :nrpro_datarout curproc))
	       (odatarout (compile_obj datarout gcx))
	       (boxcount (make_integerbox discr_integer 0))
	       (oroutlocvar (unsafe_get_field :oie_locvar odatarout))
	       )
	   (assert_msg "check odatarout" (is_a odatarout class_objinitroutine) odatarout)
	   (list_every 
	    cnslis
	    (lambda (curconst)
	      (let (
		    (:long curcount (get_int boxcount))
		    )
		(if (is_a curconst class_nrep_quasidata_current_module_environment_reference)
		    ;; set into oroutlocvar  the constant ranked curcount to oex
		    ;; and touch it
		    (let (
			  (oputrout (instance class_objputroutconst
					      :obi_loc nloc
					      :oprconst_rout oroutlocvar
					      :oprconst_off  (make_integerbox discr_integer curcount)
					      :oprconst_cval oex
					      ))
			  (otouchrout (instance class_objtouch
						:obi_loc nloc
						:otouch_val oroutlocvar
						:otouch_comment '"compobj.upd.mod.env.box"
						))
			  (ocopy (instance class_objcompute
					   :obi_loc nloc
					   :obdi_destlist (list ocontenvloc)
					   :obcpt_expr oex
					   :obcpt_type ctype_value
					   ))
			  )
		      (list_append obodl oputrout)
		      (list_append obodl otouchrout)
		      (list_append obodl ocopy)
		      )
		  )
		)
	      ))
	   (put_int boxcount (+i (get_int boxcount) 1))
	   )))
    (debug "compobj.upd.mod.env.box result ocblo=" ocblo)
    (return ocblo)
    ))
(install_method class_nrep_update_current_module_environment_reference compile_obj compilobj_nrep_update_current_module_environment_reference)





;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun compilobj_nrep_check_running_module_environment_container (nchmeb gcx)
  (debug "compilobj_nrep_check_running_module_environment_container nchmeb=" nchmeb "\n gcx=" gcx)
  (assert_msg "check nucmeb" (is_a nchmeb class_nrep_check_running_module_environment_container) nchmeb)
  (assert_msg "check gcx" (is_a gcx class_extension_generation_context) gcx)
  (let (
	(nchcomm (get_field :nchrumod_comment nchmeb))
	(nloc (get_field :nrep_loc nchmeb))
	(ocontenvloc (get_field :igncx_contenvloc gcx))
	(pcml (get_field :igncx_procurmodenvlist gcx))
	(obodl (make_list discr_list))
	(csbuf (make_strbuf discr_strbuf))
	(locenv (get_free_objlocptr gcx '_curmodenv_)) ;stack location
					;for the
					;current
					;environment
	(ocblo (instance class_objcommentedblock
			 :obi_loc nloc
			 :oblo_bodyl obodl
			 :ocomblo_comment 
			 (progn
			   (add2out csbuf "check.run.mod.env:" nchcomm)
			   (strbuf2string discr_string csbuf))))
	(ochkcont (make_objlocatedexp 
		   nloc ctype_void
		   ##{ /*check running module environment reference*/
		   if (!melt_is_instance_of ((melt_ptr_t)$OCONTENVLOC,
					     (melt_ptr_t) MELT_PREDEF(CLASS_REFERENCE)))
		   melt_fatal_error ("MELT running extension with bad module environment reference @%p", (void*) $OCONTENVLOC) ;
		   }#))
	(ogetenv (make_objlocatedexp
		  nloc ctype_void
		  ##{ /*retrieve then check running module environment*/
		  $LOCENV = melt_reference_value ((melt_ptr_t)$OCONTENVLOC) ;
		  if (!melt_is_instance_of ((melt_ptr_t) $LOCENV,
					    (melt_ptr_t) MELT_PREDEF(CLASS_ENVIRONMENT)))
		  melt_fatal_error ("MELT running extension with bad environment @%p in its reference @%p",
				    (void*) $LOCENV, (void*) $OCONTENVLOC) ;
		  }#))
	)
    (debug "compilobj_nrep_check_running_module_environment_container ocblo=" ocblo "\n ocontenvloc=" ocontenvloc)
    (debug "compilobj_nrep_check_running_module_environment_container ochkcont=" ochkcont
	   "\n ogetenv=" ogetenv)
    (list_append obodl ochkcont)
    (list_append obodl ogetenv)
    (foreach_pair_component_in_list
     (pcml)
     (curpair curout)
     (debug "compilobj_nrep_update_current_module_environment_reference curout=" curout)
     (if (is_a curout class_procroutineobj)
	 (let (
	       (curproc (unsafe_get_field :obrout_proc curout))
	       (cnslis (get_field :nrclop_constlist curproc)) 
	       (datarout (unsafe_get_field :nrpro_datarout curproc))
	       (odatarout (compile_obj datarout gcx))
	       (boxcount (make_integerbox discr_integer 0))
	       (oroutlocvar (unsafe_get_field :oie_locvar odatarout))
	       )
	   (assert_msg "check odatarout" (is_a odatarout class_objinitroutine) odatarout)
	   (list_every 
	    cnslis
	    (lambda (curconst)
	      (let (
		    (:long curcount (get_int boxcount))
		    )
		(if (is_a curconst class_nrep_quasidata_current_module_environment_reference)
		    ;; set into oroutlocvar  the constant ranked curcount to oex
		    ;; and touch it
		    (let (
			  (oputrout (instance class_objputroutconst
					      :obi_loc nloc
					      :oprconst_rout oroutlocvar
					      :oprconst_off  (make_integerbox discr_integer curcount)
					      :oprconst_cval ocontenvloc
					      ))
			  (otouchrout (instance class_objtouch
						:obi_loc nloc
						:otouch_val oroutlocvar
						:otouch_comment '"updat.cur.running.mod.env"
						))
			  )
		      (list_append obodl oputrout)
		      (list_append obodl otouchrout)
		      )
		  )
		)
	      ))
	   (put_int boxcount (+i (get_int boxcount) 1))
	   ))) 
    (list_append obodl (instance class_objclear :obi_loc nloc
				 :oclr_vloc locenv))
    (dispose_objloc locenv gcx)
    (debug "compilobj_nrep_check_running_module_environment_container gives ocblo=" ocblo)
    (return ocblo)    
    ))
(install_method class_nrep_check_running_module_environment_container compile_obj compilobj_nrep_check_running_module_environment_container)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; selector to compile a matcher
;; receiver: some indirect instance of class_any_matcher
;; arguments:
;;; * the match compilation context
;;; * the generation context
;;;   
(defselector compile_matcher class_selector
)

(export_values compile_matcher)
(defclass class_matchcompilcontext 
  :super class_proped
  :fields (mcx_loc			;the location of the matcher
	   mcx_normtester		;the normtester
	   mcx_gotothen			;the goto then part
	   mcx_gotoelse 		;the goto else part
	   mcx_olist			;the objcode list to be filled
	   mcx_suffix			;the suffix for state expansion
	   mcx_statecounter		;boxed counter for state expansion
	   ))
(export_class class_matchcompilcontext)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; selector to compile a tester
;;;; receiver: the tester
;;;; first argument: the generator context gcx
;;;; second argument: the tester context tcx
;;;; return values: primary, the objcode or lists; secondary the destination objcode
(defselector compile_tester class_selector
  :doc #{Compile a tester $RECV for matching with generator context
  $GCX and tester context $TCX. Return the compiled tester and
  secondarily the destination.}#
  :formals (recv gcx tcx)
 )
(export_values compile_tester)
(defclass class_testercompilcontext
  :super class_proped
  :fields (tcx_nrmatch			;the nrep_matcher
	   tcx_freelist			;the list of free objloc
	   tcx_nextest			;the next test
))
(export_class class_testercompilcontext)


;;;; catch all
(defun compiltst_anytester (ntester gcx tcx)
  (assert_msg "check ntester" (is_a ntester class_normtester_any) ntester)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (assert_msg "check tcx" (is_a tcx class_testercompilcontext) tcx)
  (debug ntester "compiltst_anytester ntester=" ntester)
  (outcstring_err "* compiltst unimplemented receiver class ")
  (let ( (discr (discrim ntester)) ) (outstr_err (unsafe_get_field :named_name discr)))
  (outnewline_err)
  (assert_msg "@@compile_tester should be implemented in normtesters-s subclasses" () ntester)
)
(install_method class_normtester_any compile_tester compiltst_anytester)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; compilation of old matches
(defun compilobj_nrep_match (nmat gcx)
  (assert_msg "check nmat" (is_a nmat class_nrep_match) nmat)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (debug  "compilobj_nrep_match nmat=" nmat)
  (let ( 
	(nloc (unsafe_get_field :nrep_loc nmat))
	(nctyp (unsafe_get_field :nexpr_ctyp nmat))
	(ntests (unsafe_get_field :nmatch_tests nmat))
	(stuffmap (unsafe_get_field :nmatch_stuffmap nmat))
	(nmatched (get_field :nmatch_matched nmat))
	(matmap (unsafe_get_field :gncx_matchmap gcx))
	(matlabel (let ( (:long nbmat (mapobject_count matmap))
			 (labuf (make_strbuf discr_strbuf))
			 )
		    (add2sbuf_strconst labuf "mtch")
		    (add2sbuf_longdec labuf (+i nbmat 1))
		    (add2sbuf_strconst labuf "_")
		    (let ( (labstr (strbuf2string discr_verbatim_string labuf)) )
		      (mapobject_put matmap  nmat labstr)
		      (debug "compilobj_nrep_match matlabel labstr=" labstr)
		      labstr
		      )))
	(endlabel (let (
			(labuf (make_strbuf discr_strbuf))
			)
		    (add2sbuf_string labuf matlabel)
		    (add2sbuf_strconst labuf "_end")
		    (strbuf2string discr_verbatim_string labuf)))
	;; the list of suborders for putobjdest dispatch...
	;; should be the *last* of each sequence added...
	(subcomplist (make_list discr_list))
	(obodyl (make_list discr_list))
	(ombloc (instance class_objmultiblock
			  :obi_loc nloc
			  :oblo_bodyl obodyl
			  :omulblo_subcomp ()
			  ))
	(ofirstgoto (instance class_objgotoinstr
			      :obi_loc nloc
			      :obgoto_prefix matlabel
			      :obgoto_rank (make_integerbox discr_integer 0)
			      ))
	(oendlabel (instance class_objlabelinstr
			     :obi_loc nloc
			     :oblab_prefix endlabel
			     :oblab_rank ()))
	(tcx (instance class_testercompilcontext
		       :tcx_nrmatch nmat
		       :tcx_freelist (make_list discr_list)
		       :tcx_nextest ()	;updated below
		       ))
	(donetests (make_list discr_list))
	(omatched 
	 (progn 
	   (debug "compilobj_nrep_match nmatched=" nmatched)
	   (compile_obj nmatched gcx)))
	)
    (list_append obodyl ofirstgoto)
    (debug "compilobj_nrep_match ntests=" ntests " omatched=" omatched " oendlabel=" oendlabel)
    (foreach_in_multiple
     (ntests)
     (curotest :long testix)
     (debug "compilobj_nrep_match curotest=" curotest " testix=" testix)
     (assert_msg "check curotest" (is_a curotest class_normtester_any) curotest)
     (assert_msg "check curotest rank" (==i (get_int curotest) testix) testix)
     ;; do we have both then & else?
     (compile_warning 
      ;; we probably don't need to test the curnthen & curntest; they
      ;; probably are set...
      "probably useless tests - the then & else parts are here!" ())
     (if (is_a curotest class_normtester_anytester)
	 (let ( (curnthen (get_field :ntest_then curotest))
		(curnelse (get_field :ntest_else curotest))
		)
	   (cond 
	    ( (null curnthen)
	      (debug "compilobj_nrep_match  with null then curotest=" curotest)
	      (shortbacktrace_dbg "compilobj_nrep_match curotest has null then" 14)
	      )
	    ( (null curnelse)
	      (debug "compilobj_nrep_match with null else curotest=" curotest)
	      (shortbacktrace_dbg "compilobj_nrep_match curotest has null else" 14)
	      )
	   )))
     (let (
	   (labins (normtester_labelinstr curotest gcx))
	   (curnmatched (get_field :ntest_matched curotest))
	   )
       (debug "compilobj_nrep_match labins=" labins)
       (let ( (nextest (multiple_nth ntests (+i testix 1))) )
	 (put_fields tcx :tcx_nextest nextest)
	 (debug "compilobj_nrep_match nextest=" nextest " tcx=" tcx))
       (multicall
	(curcomp curobdest) 
	(compile_tester curotest gcx tcx)
	(debug "compilobj_nrep_match curcomp=" curcomp "curobdest=" curobdest)
	(assert_msg "check curcomp" curcomp)
	;; always add the labins and the curcomp or its element into obodyl
	(list_append obodyl labins)
	(cond 
	 ( (is_list curcomp)
	   (let ( (lastlicomp (pair_head (list_last curcomp))) )
	     (debug "compilobj_nrep_match lastlicomp=" lastlicomp)
	     (list_append2list obodyl curcomp)
	     ))
	 ( (is_multiple curcomp)
	   (let ( (lastupcomp (multiple_nth curcomp -1)) )
	     (debug "compilobj_nrep_match lastupcomp=" lastupcomp)
	     (foreach_in_multiple
	      (curcomp)
	      (subtest :long subix)
	      (list_append obodyl subtest))
	     ))
	 ( (is_object curcomp)
	   (debug "compilobj_nrep_match obj curcomp=" curcomp)
	   (list_append obodyl curcomp)
	   )
	 (:else
	  (assert_msg "unexpected curcomp" () curcomp)
	  ))
	;; add into subcomplist the curobdest if not null
	(if curobdest (list_append subcomplist curobdest))
	;; 
	(list_append donetests curotest)
	;; dispose some stuff
	(let ( (disposablist (make_list discr_list)) )
	  (debug "compilobj_nrep_match disposing curotest=" curotest)
	  (cond
	   ;; if the current test is a success, we can dispose all the
	   ;; stuff which has already been tested
	   ( (is_a curotest class_normtester_success)
	     (mapobject_every 
	      stuffmap
	      (lambda (stuff stutests)
		(if (!= stuff omatched)
		(let ( (remstuff stuff) )
		  (foreach_pair_component_in_list 
		   (stutests)
		   (testpair curtest)
		   (if (list_find donetests curtest)
		       (setq testpair ())
		     (setq remstuff ()))
		   )
		  (if remstuff 
		      (list_append disposablist remstuff))
		)))))
	   ;; if the curnmatched is the nmatched, we do nothing
	   ;; because we cannot dispose it
	   ( (== curnmatched nmatched)
	     (debug "compilobj_nrep_match curnmatched == nmatched=" nmatched)
	     )
	   ;; if the current test is not a success and the curnmatched
	   ;; is an object, we can dispose it if all its stuff has been
	   ;; tested
	   ( (is_object curnmatched)
	     (debug curnmatched
		    "compilobj_nrep_match disposing curnmatched=" curnmatched " omatched=" omatched)
	     (let ( (stutests (mapobject_get stuffmap curnmatched)) )
	       (let ( (remstuff curnmatched) )
		 (foreach_pair_component_in_list 
		  (stutests)
		  (testpair curtest)
		  (if (list_find donetests curtest)
		      (setq testpair ())
		    (setq remstuff ()))
		  )
		 (if remstuff 
		     (list_append disposablist remstuff))
		 )))) 
;;; dispose all the stuff in the disposablist 
	  (debug "compilobj_nrep_match disposablist=" disposablist)
	  (foreach_pair_component_in_list
	   (disposablist)
	   (dispair dispstuff)
	   (mapobject_remove stuffmap dispstuff)
	   (debug "compilobj_nrep_match dispstuff=" dispstuff)
	   (let ( (dispobj (compile_obj dispstuff gcx)) )
	     (debug "compilobj_nrep_match dispobj=" dispobj)
	     (assert_msg "check dispobj" (is_a dispobj class_objlocv) dispobj)
	     ;; but never dispose omatched itself
	     (if (!= dispobj omatched)
		 (dispose_objloc dispobj gcx)
	       (debug  "compilobj_nrep_match dont dispose omatched=" omatched))
	     ))))))
    (list_append obodyl oendlabel)
    (put_fields ombloc 
		:omulblo_subcomp (list_to_multiple subcomplist discr_multiple))
    (debug "compilobj_nrep_match return ombloc=" ombloc)
    (return ombloc ())
    ))
(install_method class_nrep_match compile_obj compilobj_nrep_match)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;





;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defclass class_alternate_match_nrep_data 
  :super class_root
  :fields (altmatchn_prev		;the previous
	   altmatchn_number		;unique number
	   altmatchn_nrep		;the current nrep_matchalt
	   altmatchn_flagmap		;mapping from match flags to objflags
	   altmatchn_datamap		;mapping from nrep matched data to objvalues
	   altmatchn_stepmap 		;mapping from match steps to their unique number
	   altmatchn_labprefix		;string prefix for labels
	   )
  )
(export_class class_alternate_match_nrep_data)


;;;; compilation of alternate matches
(defun compilobj_nrep_matchalt (nmat gcx)
  (debug "compilobj_nrep_matchalt nmat=" nmat "\n** gcx=" gcx 
	 "\n** class_objmatchflagblock=" class_objmatchflagblock "\n")
  (assert_msg "check nmat" (is_a nmat class_nrep_matchalt) nmat)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (let ( 
	(nloc (unsafe_get_field :nrep_loc nmat))
	(nctyp (unsafe_get_field :nexpr_ctyp nmat))
	(nmatched (unsafe_get_field :namatch_matched nmat))
	(nres (unsafe_get_field :namatch_result nmat))
	(nbody (unsafe_get_field :namatch_body nmat))
	(nflags (unsafe_get_field :namatch_flags nmat))
	(nmdatas (unsafe_get_field :namatch_mdatas nmat))
	(nstartlab (get_field :namatch_startlabel nmat))
	(obodyl (make_list discr_list))
	(oldaltmatch (get_field :gncx_altmatch gcx))
	(oldmatchnum (or (get_field :altmatchn_number oldaltmatch) '0))
	(matchnum (+ivi oldmatchnum 1))
	(oflagmap (make_mapobject discr_map_objects 
				  (+i 5 (*i 2 (multiple_length nflags)))))
	(odatamap (make_mapobject discr_map_objects
				  (+i 7 (*i 2 (multiple_length nmdatas)))))
	(ostepmap (make_mapobject discr_map_objects
				  (+i 13 (*i 3 (multiple_length nmdatas)))))
	(labprefix (string4out discr_verbatim_string "_meltmatchaltlab" matchnum "_"))
	(altmatch (instance class_alternate_match_nrep_data 
			    :altmatchn_prev oldaltmatch
			    :altmatchn_number matchnum
			    :altmatchn_nrep nmat
			    :altmatchn_flagmap oflagmap
			    :altmatchn_datamap odatamap
			    :altmatchn_stepmap ostepmap
			    :altmatchn_labprefix labprefix
			    )))
							      
    (debug "compilobj_nrep_matchalt nmatched=" nmatched "\n nres=" nres 
	   "\n nflags=" nflags "\n nctyp=" nctyp
	   "\n nbody=" nbody "\n oldaltmatch=" oldaltmatch
	   "\n new altmatch=" altmatch)
    (put_fields gcx :gncx_altmatch altmatch)
    (let (
	  (nsymbres (get_field :nocc_symb nres))
	  (obvares (get_free_objloctyped gcx nsymbres nctyp))
	  (ocleares (instance class_objclear
			      :obi_loc nloc
			      :oclr_vloc obvares))
	  )
      (list_append obodyl ocleares)
      ;;
      (debug "compilobj_nrep_matchalt nflags=" nflags)
      (let ( (oflags 
	      (multiple_map
	       nflags
	       (lambda (curnflag :long fix)
		 (debug "compilobj_nrep_matchalt/lambda curnflag=" curnflag " fix=" fix)
		 (let ( (curoflag (compile_obj curnflag gcx))
			)
		   (debug "compilobj_nrep_matchalt/lambda curoflag=" curoflag)
		   (return curoflag))))
	      )
	     (oblock (instance class_objmatchflagblock
			       :obi_loc nloc
			       :omchflgblo_flags oflags
			       :oblo_bodyl obodyl))
	     )
	(debug "compilobj_nrep_matchalt oflags=" oflags "\n oblock=" oblock
	       "\n nbody=" nbody "\n nstartlab=" nstartlab)
	;;
	;; fill the stepmap from class_nrep_match_label occurrences
	(foreach_in_multiple
	 (nbody)
	 (curncomp :long bodix)
	 (debug "compilobj_nrep_matchalt stepmap bodix#" bodix " curncomp=" curncomp)
	 (if (is_a curncomp class_nrep_match_label)
	     (let ( (labstep (get_field :nmlab_step curncomp))
		    (:long stepcount (mapobject_count ostepmap))
		    (stepnum (constant_box (+i stepcount 1)))
		   )
	       (debug "compilobj_nrep_matchalt labstep=" labstep "\n stepnum=" stepnum)
	       (assert_msg "check labstep" (or (is_a curncomp class_nrep_match_label_end) 
					       (is_a labstep class_match_step))
			   labstep)
	       (assert_msg "check unknown labstep" (null (mapobject_get ostepmap labstep)) labstep ostepmap)
	       (if labstep 
		   (mapobject_put ostepmap labstep stepnum))
	       ))
	 )
	(debug "compilobj_nrep_matchalt ostepmap=" ostepmap "\n.. nbody=" nbody)
	;;
	(foreach_in_multiple
	 (nbody)
	 (curncomp :long bodix)
	 (debug  "compilobj_nrep_matchalt curncomp=" curncomp " bodix=" bodix)
	 (let ( (curocomp (compile_obj curncomp gcx))
		)
	   (debug "compilobj_nrep_matchalt curocomp=" curocomp)
	   (assert_msg "check curocomp object" (is_object curocomp) curocomp)
	   (if (and (== curncomp nstartlab) 
		    (is_a curncomp class_nrep_match_label))
	       ;; we forcibly add a goto to the first label step, to
	       ;; avoid a label without goto warning from gcc
	       ;; compiling the generated code
	     (let ( (startstep (get_field :nmlab_step nstartlab))
		   (ostartjump
		     (instance class_objgotoinstr
			       :obgoto_prefix labprefix
			       :obgoto_rank (mapobject_get ostepmap startstep)))
		    )
	       (debug "compilobj_nrep_matchalt ostartjump=" ostartjump 
		      "\n startstep=" startstep
		      "\n ostepmap=" ostepmap)
	       (list_append obodyl ostartjump)
	     ))
	   (list_append obodyl curocomp)
	   ))
	;; we need to append the result at end of body
	(list_append obodyl obvares)
	;;
	(debug "compilobj_nrep_matchalt obodyl=" obodyl)
	(dispose_objloc obvares gcx)
	(put_fields gcx :gncx_altmatch oldaltmatch)
	;;
	(debug "compilobj_nrep_matchalt restored gcx=" gcx 
	       "\n* obodyl=" obodyl
	       "\n* result oblock=" oblock
	       "\n*****\n")
	(return oblock)
	))))
(install_method class_nrep_matchalt compile_obj compilobj_nrep_matchalt)


;;;;;;;;;;;;;;;;
(defun compilobj_nrep_matchlabel (nmlab gcx)
  (debug "compilobj_nrep_matchlabel nmlab=" nmlab " gcx=" gcx)
  (assert_msg "check nmlab" (is_a nmlab class_nrep_match_label) nmlab)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (let (
	(nloc (get_field :nrep_loc nmlab))
	(nstep (get_field :nmlab_step nmlab))
	(altmatchdata (get_field :gncx_altmatch gcx))
	(labprefix (get_field :altmatchn_labprefix altmatchdata))
	(ostepmap (get_field :altmatchn_stepmap altmatchdata))
	(stepnum (mapobject_get ostepmap nstep))
	)
    (debug "compilobj_nrep_matchlabel nstep=" nstep
	   "\n stepnum=" stepnum "\n labprefix=" labprefix)
    (assert_msg "check altmatchdata" (is_a altmatchdata class_alternate_match_nrep_data) altmatchdata)
    (assert_msg "check nstep" (is_a nstep class_match_step) nstep)
    (assert_msg "check stepnum" (is_integerbox stepnum) stepnum)
    (assert_msg "check labprefix" (is_string labprefix) labprefix)
    (shortbacktrace_dbg "compilobj_nrep_matchlabel" 12)
    (let ( (olabinstr (instance class_objlabelinstr
				:obi_loc nloc
				:oblab_prefix labprefix
				:oblab_rank stepnum))
	   )
      (debug "compilobj_nrep_matchlabel result olabinstr=" olabinstr)
      (return olabinstr)
      )))

(install_method class_nrep_match_label compile_obj compilobj_nrep_matchlabel)


;;;;;;;;;;;;;;;;
(defun compilobj_nrep_matchlabelend (nmlab gcx)
  (debug "compilobj_nrep_matchlabelend nmlab=" nmlab " gcx=" gcx)
  (assert_msg "check nmlab" (is_a nmlab class_nrep_match_label_end) nmlab)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (let (
	(nloc (get_field :nrep_loc nmlab))
	(altmatchdata (get_field :gncx_altmatch gcx))
	(labprefix (get_field :altmatchn_labprefix altmatchdata))
	)
    (debug "compilobj_nrep_matchlabel labprefix=" labprefix)
    (assert_msg "check labprefix" (is_string labprefix) labprefix)
    (shortbacktrace_dbg "compilobj_nrep_matchlabel" 12)
    (let ( (olabinstr (instance class_objlabelinstr
				:obi_loc nloc
				:oblab_prefix (string4out discr_verbatim_string labprefix "_end")
				)
		      )
	   )
      (debug "compilobj_nrep_matchlabel resultend olabinstr=" olabinstr)
      (return olabinstr)
      )))

(install_method class_nrep_match_label_end compile_obj compilobj_nrep_matchlabelend)


;;;;;;;;;;;;;;;;
;; the compilation of a match flag should give a 
(defun compilobj_nrep_matchflag (nmflag gcx)
  (debug "compilobj_nrep_matchflag nmflag=" nmflag "\n of discrim=" (discrim nmflag)
	 "\n** gcx=" gcx)
  (assert_msg "check nmflag" (is_a nmflag class_nrep_match_flag) nmflag)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (let ( (nloc (unsafe_get_field :nrep_loc nmflag))
	 (nrfla (unsafe_get_field :nrpfla_flag nmflag))
	 (nrmatch (unsafe_get_field :nrpfla_nmatch nmflag))
	 (altmatchdata (get_field :gncx_altmatch gcx))
	 (oflagmap (get_field :altmatchn_flagmap altmatchdata))
	 )
    (debug "compilobj_nrep_matchflag nrfla=" nrfla " nrmatch=" nrmatch " oflagmap=" oflagmap)
    (assert_msg "check oflagmap" (is_mapobject oflagmap) oflagmap)
    (let ( (objmf (mapobject_get oflagmap nmflag))
	   )
      (if objmf
	  (progn
	    (debug "compilobj_nrep_matchflag found & returning objmf=" objmf)
	    (assert_msg "check ojbmf" (is_a objmf class_objflag) objmf)
	    (return objmf)))
      (setq objmf (instance class_objflag
			    :obv_type ctype_long
			    :obflag_matchflag nmflag
			    :obflag_name (get_field :mflag_string nrfla)
			    :obflag_rank (get_field :mflag_rank nrfla)))
      (mapobject_put oflagmap nmflag objmf)
      (debug "compilobj_nrep_matchflag new objmf=" objmf " in updated oflagmap=" oflagmap)
      (shortbacktrace_dbg "compilobj_nrep_matchflag" 15)
      (return objmf)
      )))

(install_method class_nrep_match_flag compile_obj compilobj_nrep_matchflag)

;;;;;;;;;;;;;;;;
(defun compilobj_nrep_matchdatainit (nmdat gcx)
  (debug "compilobj_nrep_matchdatainit nmdat=" nmdat 
	 "\n of discr=" (discrim nmdat) "\n gcx=" gcx)
  (assert_msg "check nmdat" (is_a nmdat class_nrep_match_data_initializer) nmdat)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (let (
	(nloc (unsafe_get_field :nrep_loc nmdat))
	(ndata (get_field :nmdac_data nmdat))
	(ndatatype (get_field :nrmatd_ctype ndata))
	(ndatarank (get_field :nrmatd_rank ndata))
	(matdata (get_field :nrmatd_mdata ndata))
	(altmatch (get_field :gncx_altmatch gcx))
	(symb (or (get_field :mdata_symb matdata) (clone_symbol 'matchdata)))
	)
    (shortbacktrace_dbg "compilobj_nrep_matchdatainit" 10)
    (debug "compilobj_nrep_matchdatainit ndata=" ndata "\n* ndatatype=" ndatatype
	   "\n* ndatarank=" ndatarank 
	   "\n* matdata=" matdata "\n* altmatch=" altmatch
	   "\n* symb=" symb)
    (let (
	  (obvloc (get_free_objloctyped gcx symb ndatatype))
	  (aldatamap (get_field :altmatchn_datamap altmatch))
	  (obcl (instance class_objclear
			  :obi_loc nloc
			  :oclr_vloc obvloc))
	  )
      (debug "compilobj_nrep_matchdatainit obvloc=" obvloc
	     "\n* obcl=" obcl
	     "\n* aldatamap=" aldatamap)
      (assert_msg "unknown ndata in aldatamap" (null (mapobject_get aldatamap ndata)) ndata aldatamap)
      (mapobject_put aldatamap ndata obvloc)
      (debug "compilobj_nrep_matchdatainit updated aldatamap=" aldatamap 
	     "\n*return obcl=" obcl)
      (return obcl)
      )))

(install_method class_nrep_match_data_initializer compile_obj compilobj_nrep_matchdatainit)

;;;;;;;;;;;;;;;;
(defun compilobj_nrep_matchdataclear (nmc gcx)
  (debug "compilobj_nrep_matchdataclear nmc=" nmc "\n gcx=" gcx)
  (assert_msg "check nmc" (is_a nmc class_nrep_match_data_clear) nmc)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (let (
	(nloc (get_field :nrep_loc nmc))
	(ndata (get_field :nmdac_data nmc))
	(odata (compile_obj ndata gcx))
	(oclear (instance class_objclear
			  :obi_loc nloc
			  :oclr_vloc odata))
	)
    (debug "compilobj_nrep_matchdataclear odata=" odata "\n result oclear=" oclear)
    (return oclear)
  ))
(install_method class_nrep_match_data_clear compile_obj compilobj_nrep_matchdataclear)


;;;;;;;;;;;;;;;;
(defun compilobj_nrep_matchdatafinal (nmdatf gcx)
  (debug "compilobj_nrep_matchdatafinal nmdatf=" nmdatf 
	 "\n of discr=" (discrim nmdatf) "\n gcx=" gcx)
  (assert_msg "check nmdatf" (is_a nmdatf class_nrep_match_data_finalizer) nmdatf)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (shortbacktrace_dbg "compilobj_nrep_matchdatafinal" 10)
  (let (
	(nloc (unsafe_get_field :nrep_loc nmdatf))
	(ndata (unsafe_get_field :nmdac_data nmdatf))
	(odata (compile_obj ndata gcx))
	;; no need to clear odata, it is already cleared before
	)
    (debug "compilobj_nrep_matchdatafinal ndata=" ndata "\n disposing odata=" odata 
	   "\n nmdatf=" nmdatf)
    (dispose_objloc odata gcx)
    (debug "compilobj_nrep_matchdatafinal end nmdatf=" nmdatf)
    (return)
    ))
(install_method class_nrep_match_data_finalizer compile_obj compilobj_nrep_matchdatafinal)


;;;;;;;;;;;;;;;;
(defun compilobj_nrep_matchedata (nmdat gcx)
  (debug "compilobj_nrep_matchedata nmdat=" nmdat 
	 "\n of discr=" (discrim nmdat) "\n gcx=" gcx)
  (assert_msg "check nmdat" (is_a nmdat class_nrep_matched_data) nmdat)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (let (
	(nloc (unsafe_get_field :nrep_loc nmdat))
	(nctype (unsafe_get_field :nrmatd_ctype nmdat))
	(nrmdata (get_field :nrmatd_mdata nmdat))
	(nrmrank (get_field :nrmatd_rank nmdat))
	(altmatch (get_field :gncx_altmatch gcx))
	(aldatamap (get_field :altmatchn_datamap altmatch))
	(obmdat (mapobject_get aldatamap nmdat))
	)
    (shortbacktrace_dbg "compilobj_nrep_matcheddata" 10)
    (debug "compilobj_nrep_matchedata  altmatch=" altmatch "\n aldatamap=" aldatamap 
	   "\n obmdat=" obmdat "\n.. of discrim=" (discrim obmdat))
    (assert_msg "check obmdat" (is_a obmdat class_objvalue) obmdat)
    (return obmdat)
    ))
(install_method class_nrep_matched_data compile_obj compilobj_nrep_matchedata)




;;;;;;;;;;;;;;;;
(defun compilobj_nrep_matchjump (nmjump gcx)
  (debug "compilobj_nrep_matchjump nmjump=" nmjump 
	 "\n of discr=" (discrim nmjump) "\n gcx=" gcx)
  (assert_msg "check nmjump" (is_a nmjump class_nrep_match_jump) nmjump)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (let (
	(nloc (unsafe_get_field :nrep_loc nmjump))
	(altmatchdata (get_field :gncx_altmatch gcx))
	(nmlab (get_field :nmjmp_label nmjump))
	(labprefix (get_field :altmatchn_labprefix altmatchdata))
	)
    (debug "compilobj_nrep_matchjump  altmatchdata=" altmatchdata
	   "\n *nmlab=" nmlab)
    (assert_msg "check altmatchdata" (is_a altmatchdata class_alternate_match_nrep_data) altmatchdata)
    (let ( (objgotomins
	    (cond ((is_a nmlab class_nrep_match_label_end)
		   (debug "compilobj_nrep_matchjump ending nmlab=" nmlab)
		   (instance class_objgotoinstr
			     :obi_loc nloc
			     :obgoto_prefix (string4out discr_verbatim_string 
							labprefix "_end")
			     ))
		  ((is_a nmlab class_nrep_match_label)
		   (let 
		       (
			(nstep (get_field :nmlab_step nmlab))
			(ostepmap (get_field :altmatchn_stepmap altmatchdata))
			(stepnum (mapobject_get ostepmap nstep))
			)
		     (debug "compilobj_nrep_matchjump nstep=" nstep "\n *stepnum=" stepnum)
		     
		     (instance class_objgotoinstr
			       :obi_loc nloc
			       :obgoto_prefix labprefix
			       :obgoto_rank stepnum)))
		  (:else
		   (assert_msg "unexpected nmlab" () nmlab))))
	   )
      (debug "compilobj_nrep_matchjump result objgotomins=" objgotomins)
      (return objgotomins)
      )))

(install_method class_nrep_match_jump compile_obj compilobj_nrep_matchjump)







;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; utility function to return the label instr of a tester
(defun normtester_labelinstr (nt gcx)
  (debug "normtester_labelinstr start nt=" nt)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (if (is_not_a nt class_normtester_any)
      (progn
	(debug "normtester_labelinstr return nil")
	(return)))
  (let ( 
	(nloc (unsafe_get_field :nrep_loc nt))
	(:long ntestix (get_int nt))
	(normatch (unsafe_get_field :ntest_normatch nt))
	(matchmap (unsafe_get_field :gncx_matchmap gcx))
	)
    (assert_msg "check normatch" (is_a normatch class_nrep_match) normatch)
    (assert_msg "check valid normatch" 
		(== (multiple_nth (get_field :nmatch_tests normatch) 
				  ntestix) 
		    nt) normatch ntestix)
    (let (
	  (prefix (mapobject_get matchmap normatch))
	  (labins (instance class_objlabelinstr
			    :obi_loc nloc
			    :oblab_prefix prefix
			    :oblab_rank nt)) 
	  )
      (debug "normtester_labelinstr result labins=" labins)
      (assert_msg "check prefix" (is_string prefix) prefix)
      (return labins)
      )))


;; utility function to return the goto instr into a tester
(defun normtester_gotoinstr (nt gcx)
  (debug  "normtester_gotoinstr start nt=" nt)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (if (is_not_a nt class_normtester_any)
      (progn
	(debug "normtester_gotoinstr return nil")
	(return)))
  (let ( 
	(nloc (unsafe_get_field :nrep_loc nt))
	(:long ntestix (get_int nt))
	(normatch (unsafe_get_field :ntest_normatch nt))
	(matchmap (unsafe_get_field :gncx_matchmap gcx))
	)
    (debug "normtester_gotoinstr normatch=" normatch)
    (assert_msg "check normatch" (is_a normatch class_nrep_match) normatch)
    (assert_msg "check valid normatch" 
		(== (multiple_nth (get_field :nmatch_tests normatch) 
				  ntestix) 
		    nt) normatch ntestix)
    (let (
	  (prefix (mapobject_get matchmap normatch))
	  (goins (instance class_objgotoinstr
			    :obi_loc nloc
			    :obgoto_prefix prefix
			    :obgoto_rank nt)) 
	  )
      (debug "normtester_gotoinstr result goins=" goins)
      (assert_msg "check prefix" (is_string prefix) prefix)
      (return goins)
)))


;;; utility function to return the goto instr at end of matcher
(defun endmatch_gotoinstr (nma gcx nloc)
  (assert_msg "check nma" (is_a nma class_nrep_match) nma)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (debug "endmatch_gotoinstr nma=" nma)
  (shortbacktrace_dbg "endmatch_gotoinstr" 15)
  (let ( 
	(matchmap (unsafe_get_field :gncx_matchmap gcx))
	(prefix (mapobject_get matchmap nma))
	(labuf (make_strbuf discr_strbuf))
	)
    (add2sbuf_string labuf prefix)
    (add2sbuf_strconst labuf "_end /*endmatch*/")
    (let (
	  (goins (instance 
		  class_objgotoinstr
		  :obi_loc nloc
		  :obgoto_prefix (strbuf2string discr_verbatim_string labuf)
		  :obgoto_rank ()))
	  )
      (debug "endmatch_gotoinstr goins=" goins)
      (return goins)
)))

;; utility function to return the goto instr to a given tester
(defun testmatch_gotoinstr (ntest nma gcx nloc)
  (debug "testmatch_gotoinstr ntest=" ntest)
  (assert_msg "check ntest" (is_a ntest class_normtester_any) ntest)
  (assert_msg "check nma" (is_a nma class_nrep_match) nma)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (shortbacktrace_dbg "testmatch_gotoinstr" 15)
  (let ( 
	(matchmap (unsafe_get_field :gncx_matchmap gcx))
	(prefix (mapobject_get matchmap nma))
	(labuf (make_strbuf discr_strbuf))
	)
    (add2sbuf_string labuf prefix)
    (add2sbuf_longdec labuf (get_int ntest))
    (add2sbuf_strconst labuf " /*testmatch*/")
    (let (
	  (goins (instance 
		  class_objgotoinstr
		  :obi_loc nloc
		  :obgoto_prefix (strbuf2string discr_verbatim_string labuf)
		  :obgoto_rank ()))
	  )
      (debug "testmatch_gotoinstr goins=" goins)
      (return goins)
      )))

;;; utility function to get free objloc for the local occurrences of a tester
(defun normtester_free_objloc_list (nt gcx tcx)
  (debug "normtester_free_objloc_list nt=" nt)
  (assert_msg "check nt" (is_a nt class_normtester_any) nt)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (assert_msg "check tcx" (is_a tcx class_testercompilcontext) tcx)
  (let ( 
	(nloclist (unsafe_get_field :ntest_locclist nt))
	(locmap (unsafe_get_field :gncx_locmap gcx))
	)
    (debug "normtester_free_objloc_list nloclist=" nloclist)
    (shortbacktrace_dbg "normtester_free_objloc_list" 15)
    (let ( (freelist
	    (list_map 
	     nloclist 
	     (lambda (nloc) 
	       (assert_msg "check nloc" (is_a nloc class_nrep_locsymocc) nloc)
	       (let ( (oblo
		       (get_free_objloctyped gcx 
				     (get_field :nocc_symb nloc)
				     (get_field :nocc_ctyp nloc)
				     )) )
		 (mapobject_put locmap (get_field :nocc_bind nloc) oblo)
		 oblo
	       )))) 
	   )
      (list_append2list (get_field :tcx_freelist tcx) freelist)
      (debug "normtester_free_objloc_list result freelist=" freelist)
      (return freelist)
      )))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;; catch-all for unimplemented normtester
(defun compiltst_normtester_any (nta gcx tcx)
  (debug "compiltst_normtester_any nta=" nta 
	 "\n of discrim " (discrim nta)
	 "\n gcx=" gcx " tcx=" tcx)
  (error_strv (get_field :nrep_loc nta) 
	      "**UNIMPLEMENTED normal tester compilation "
	      (get_field :named_name (discrim nta)))
  (assert_msg "@$@UNIMPLEMENTED normal tester compilation" () nta gcx tcx)
)
(install_method class_normtester_any compile_tester compiltst_normtester_any)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun compiltst_normtester_matcher (ntma gcx tcx)
  (debug "compiltst_normtester_matcher ntma=" ntma)
  (assert_msg "check ntma" (is_a ntma class_normtester_matcher) ntma)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (assert_msg "check tcx" (is_a tcx class_testercompilcontext) tcx)
  (let ( 
	(nloc (unsafe_get_field :nrep_loc ntma))
	(nmatched (unsafe_get_field :ntest_matched ntma))
	(nthen (unsafe_get_field :ntest_then ntma))
	(nelse (unsafe_get_field :ntest_else ntma))
	(nmatcher (unsafe_get_field :ntmatch_matcher ntma))
	(nins (unsafe_get_field :ntmatch_inargs ntma))
	(nouts (unsafe_get_field :ntmatch_outlocs ntma))
	(normatch (unsafe_get_field :ntest_normatch ntma))
	(gotothen (normtester_gotoinstr nthen gcx))
	(gotoelse (normtester_gotoinstr nelse gcx))
	(olist (make_list discr_list))
	(matchmap (unsafe_get_field :gncx_matchmap gcx))
	(prefix (mapobject_get matchmap normatch))
	(freelist (normtester_free_objloc_list ntma gcx tcx))
	(nextest (get_field :tcx_nextest tcx))
	)
    (debug "compiltst_normtester_matcher matchmap=" matchmap " nextest=" nextest
	   " gotothen=" gotothen)
    (cond ( (null gotothen)
	    (shortbacktrace_dbg "compiltst_normtester_matcher null gotothen" 14)
	    (setq gotothen 
		  (if nextest 
		      (testmatch_gotoinstr nextest normatch gcx nloc)
		    (endmatch_gotoinstr normatch gcx nloc)))
	    (debug "compiltst_normtester_matcher fixed gotothen=" gotothen)
	    ))
    (debug "compiltst_normtester_matcher unfixed gotoelse=" gotoelse)
    (cond ( (null gotoelse)
	    (shortbacktrace_dbg "compiltst_normtester_matcher null gotoelse" 14)
	    (setq gotoelse 
		  (if nextest
		      (testmatch_gotoinstr nextest normatch gcx nloc)
		    (endmatch_gotoinstr normatch gcx nloc)))
	    (debug "compiltst_normtester_matcher fixed gotoelse=" gotoelse)
	    ))
    (debug "compiltst_normtester_matcher freelist=" freelist " prefix=" prefix)
    (assert_msg "check prefix" (is_string prefix) prefix)
    ;; clear the freelist
    (foreach_pair_component_in_list
     (freelist)
     (locpair obloc)
     (assert_msg "check obloc" (is_a obloc class_objlocv) obloc)
     (let ( (oclearob (instance class_objclear
				:obi_loc nloc
				:oclr_vloc obloc
				)) )
       (list_append olist oclearob)
       ))
    (debug "compiltst_normtester_matcher before nmatcher=" nmatcher)
    (let ( (matcx (instance class_matchcompilcontext
			    :mcx_loc nloc
			    :mcx_normtester ntma
			    :mcx_gotothen gotothen
			    :mcx_gotoelse gotoelse
			    :mcx_olist olist
			    :mcx_suffix prefix
			    :mcx_statecounter (make_integerbox discr_integer 0)
			    )) )
      (debug "compiltst_normtester_matcher matcx=" matcx)
      (compile_matcher nmatcher matcx gcx)
      (debug "compiltst_normtester_matcher return olist=" olist)
      (return olist ())
      )
    ))
(install_method class_normtester_matcher compile_tester compiltst_normtester_matcher)

;;;;;;;;;;;;;;;;
(defun compiltst_normtester_instance (ntmi gcx tcx)
  (debug "compiltst_normtester_instance ntmi=" ntmi)
  (assert_msg "check ntmi" (is_a ntmi class_normtester_instance) ntmi)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (assert_msg "check tcx" (is_a tcx class_testercompilcontext) tcx)
  (let ( 
	(nloc (unsafe_get_field :nrep_loc ntmi))
	(nmatched (unsafe_get_field :ntest_matched ntmi))
	(nthen (unsafe_get_field :ntest_then ntmi))
	(nelse (unsafe_get_field :ntest_else ntmi))
	(normatch (unsafe_get_field :ntest_normatch ntmi))
	(nlocclist (unsafe_get_field :ntest_locclist ntmi))
	(olist (make_list discr_list))
	(:long ntestix (get_int ntmi))	
	(ntclass (unsafe_get_field :ntinst_class ntmi))
	(ntflds (unsafe_get_field :ntinst_fieldlocs ntmi))
	(gotothen (or (normtester_gotoinstr nthen gcx)
		      (endmatch_gotoinstr normatch gcx nloc)))
	(gotoelse (or (normtester_gotoinstr nelse gcx)
		      (endmatch_gotoinstr normatch gcx nloc)))
	(oclass (compile_obj ntclass gcx))
	(omatched (compile_obj nmatched gcx))
	(freelist (normtester_free_objloc_list ntmi gcx tcx))
	(othenlist (make_list discr_list))
	(oelselist (make_list discr_list))
	(othenblock (instance class_objplainblock
			      :obi_loc nloc
			      :oblo_bodyl othenlist
			      ))
	(oelseblock (instance class_objplainblock
			      :obi_loc nloc
			      :oblo_bodyl oelselist))
	(otest 
	 (make_objlocatedexp 
	  nloc ctype_long
	  ##{/*normtesterinst*/ (melt_is_instance_of((melt_ptr_t)($OMATCHED),
						     (melt_ptr_t)($OCLASS)))}#))	     
	(ocond (instance class_objcond
			 :obi_loc nloc
			 :obcond_test otest
			 :obcond_then othenblock
			 :obcond_else oelseblock))
	)
    (debug "compiltst_normtester_instance otest=" otest
	   " gotothen=" gotothen " gotoelse=" gotoelse
	   " ocond=" ocond)
    (assert_msg "check oclass" (is_object oclass) oclass)
    ;; clear the freelist
    (foreach_pair_component_in_list
     (freelist)
     (locpair obloc)
     (debug "compiltst_normtester_instance obloc=" obloc)
     (assert_msg "check obloc" (is_a obloc class_objlocv) obloc)
     (let ( (oclearob (instance class_objclear
				 :obi_loc nloc
				 :oclr_vloc obloc
				 )) )
       (list_append olist oclearob)
     ))
    ;; add the cond
    (list_append olist ocond)
    ;; we have to add into the othenlist the fetch of each field and
    ;; the gotothen
    (debug "compiltst_normtester_instance ntflds=" ntflds " nlocclist=" nlocclist)
    (foreach_in_multiple
     (ntflds)
     (fldoc :long fldix)
     (if fldoc
	 (progn
	   (debug "compiltst_normtester_instance fldoc=" fldoc " fldix=" fldix)
	   (assert_msg "check fldoc" (is_a fldoc class_nrep_locsymocc) fldoc)
	   (let ( (flovar (compile_obj fldoc gcx))
		  (flbind (unsafe_get_field :nocc_bind fldoc))
		  (fldget (unsafe_get_field :letbind_expr flbind))
		  (ofget (compile_obj fldget gcx))
		  )
	     (assert_msg "check flbind" (is_a flbind class_normal_let_binding) flbind)
	     (assert_msg "check fldget" (is_a fldget class_nrep_unsafe_get_field) fldget)
	     (put_objdest ofget flovar)
	     (debug "compiltst_normtester_instance ofget=" ofget)
	     (assert_msg "check ofget" (is_object ofget) ofget)
	     (list_append othenlist ofget)
     ))))
    ;; also add the gotothen
    (assert_msg "check gotothen" (is_object gotothen) gotothen)
    (list_append othenlist gotothen)
    ;;
    ;; add into the oelselist the gotoelse
    (assert_msg "check gotoelse" (is_object gotoelse) gotoelse)
    (list_append oelselist gotoelse)
    (debug  "compiltst_normtester_instance final olist=" olist)
    (return olist ())
    )
  )
(install_method class_normtester_instance compile_tester compiltst_normtester_instance)




;;;;;;;;;;;;;;;;
(defun compiltst_normtester_tuple (ntup gcx tcx)
  (debug "compiltst_normtester_tuple ntup=" ntup " of discrim=" (discrim ntup))
  (assert_msg "check ntup" (is_a ntup class_normtester_tuple) ntup)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (assert_msg "check tcx" (is_a tcx class_testercompilcontext) tcx)
  (let ( (nloc (unsafe_get_field :nrep_loc ntup))
	 (nmatched (unsafe_get_field :ntest_matched ntup))
	 (nthen (unsafe_get_field :ntest_then ntup))
	 (nelse (unsafe_get_field :ntest_else ntup))
	 (normatch (unsafe_get_field :ntest_normatch ntup))
	 (nlocclist (unsafe_get_field :ntest_locclist ntup))
	 (ntupcomp (unsafe_get_field :nttuple_components ntup))
	 (:long nbcomp (multiple_length ntupcomp))
	 (olist (make_list discr_list))
	 (:long ntestix (get_int ntup))	
	 (gotothen (or (normtester_gotoinstr nthen gcx)
		       (endmatch_gotoinstr normatch gcx nloc)))
	 (gotoelse (or (normtester_gotoinstr nelse gcx)
		       (endmatch_gotoinstr normatch gcx nloc)))
	 (omatched (compile_obj nmatched gcx))
	 (freelist (normtester_free_objloc_list ntup gcx tcx))
	 (othenlist (make_list discr_list))
	 (oelselist (make_list discr_list))
	 (othenblock (instance class_objplainblock
			       :obi_loc nloc
			       :oblo_bodyl othenlist
			       ))
	 (oelseblock (instance class_objplainblock
			       :obi_loc nloc
			       :oblo_bodyl oelselist))
	 (otest 
	  (make_objlocatedexp
	   nloc ctype_long
	   ##{/*normtestertuple*/ (melt_magic_discr((melt_ptr_t)($OMATCHED)) == MELTOBMAG_MULTIPLE
		&& ((meltmultiple_ptr_t)($OMATCHED))->nbval == $NBCOMP)}#)				   )
	 (ocond (instance class_objcond
			  :obi_loc nloc
			  :obcond_test otest
			  :obcond_then othenblock
			  :obcond_else oelseblock))
	 )
    (debug "compiltst_normtester_tuple omatched=" omatched " freelist=" freelist 
	   "\n otest=" otest
	   "\n ocond=" ocond)
    ;; clear the freelist
    (foreach_pair_component_in_list
     (freelist)
     (locpair obloc)
     (debug "compiltst_normtester_tuple obloc=" obloc)
     (assert_msg "check obloc" (is_a obloc class_objlocv) obloc)
     (let ( (oclearob (instance class_objclear
				:obi_loc nloc
				:oclr_vloc obloc
				)) )
       (list_append olist oclearob)
       ))
    ;; add the cond
    (list_append olist ocond)
    ;; we have to add into the othenlist the fetch of each component and
    ;; the gotothen
    (debug "compiltst_normtester_tuple ntupcomp=" ntupcomp)
    (foreach_in_multiple
     (ntupcomp)
     (curntup :long tupix)
     (debug "compiltst_normtester_tuple curntup=" curntup " tupix=" tupix)
     (if curntup
	 (let ( (curovar (compile_obj curntup gcx))
		(cnbind (get_field :nocc_bind curntup))
		(curbexp (get_field :letbind_expr cnbind))
		(curoexp (compile_obj curbexp gcx))
	     )
	   (debug "compiltst_normtester_tuple curovar=" curovar 
		  "  cnbind=" cnbind "  curbexp=" curbexp "  curoexp=" curoexp
		  " tupix=" tupix)
	   (assert_msg "check curovar" (is_a curovar class_objlocv) curovar)
	   (assert_msg "check cnbind" (is_a cnbind class_normal_let_binding) cnbind)
	   (assert_msg "check curbexp" (is_a curbexp class_nrep_unsafe_nth_component) curbexp)
	   (assert_msg "check nthrnk" (==i (get_int (get_field :nunth_index curbexp)) tupix) curbexp)
	   (put_objdest curoexp curovar)
	   (debug "compiltst_normtester_tuple updated curoexp=" curoexp)
	   (list_append othenlist curoexp)
	   ))
     );; end foreach ntupcomp
    ;; also add the gotothen
    (assert_msg "check gotothen" (is_object gotothen) gotothen)
    (list_append othenlist gotothen)
    ;;
    ;; add into the oelselist the gotoelse
    (assert_msg "check gotoelse" (is_object gotoelse) gotoelse)
    (list_append oelselist gotoelse)
    (debug "compiltst_normtester_tuple final olist=" olist)
    (return olist ())
    ))
(install_method class_normtester_tuple compile_tester compiltst_normtester_tuple)




;;;;;;;;;;;;;;;;
(defun compiltst_normtester_same (ntsa gcx tcx)
  (debug "compiltst_normtester_same ntsa=" ntsa)
  (assert_msg "check ntsa" (is_a ntsa class_normtester_same) ntsa)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (assert_msg "check tcx" (is_a tcx class_testercompilcontext) tcx)
  (let ( 
	(nloc (unsafe_get_field :nrep_loc ntsa))
	(nmatched (unsafe_get_field :ntest_matched ntsa))
	(nthen (unsafe_get_field :ntest_then ntsa))
	(nelse (unsafe_get_field :ntest_else ntsa))
	(normatch (unsafe_get_field :ntest_normatch ntsa))
	(nidentical (unsafe_get_field :ntsame_identical ntsa))
	(:long ntestix (get_int ntsa))	
	(omatched (compile_obj nmatched gcx))
	(oidentical (compile_obj nidentical gcx))
	(gotothen (or (normtester_gotoinstr nthen gcx)
		      (endmatch_gotoinstr normatch gcx nloc)))
	(gotoelse (or (normtester_gotoinstr nelse gcx)
		      (endmatch_gotoinstr normatch gcx nloc)))
	(freelist (normtester_free_objloc_list ntsa gcx tcx))
	(othenlist (make_list discr_list))
	(oelselist (make_list discr_list))
	(othenblock (instance class_objplainblock
			      :obi_loc nloc
			      :oblo_bodyl othenlist
			      ))
	(oelseblock (instance class_objplainblock
			      :obi_loc nloc
			      :oblo_bodyl oelselist))
	(otest
	 (make_objlocatedexp 
	  nloc ctype_long
	  ##{/*testersame*/ ($OMATCHED == $OIDENTICAL)}#))
	(ocond (instance class_objcond
			 :obi_loc nloc
			 :obcond_test otest
			 :obcond_then othenblock
			 :obcond_else oelseblock))
	(olist (make_list discr_list))
	)
    (debug "compiltst_normtester_same ocond=" ocond)
    ;; clear the freelist
    (foreach_pair_component_in_list
     (freelist)
     (locpair obloc)
     (assert_msg "check obloc" (is_a obloc class_objlocv) obloc)
     (let ( (oclearob (instance class_objclear
				 :obi_loc nloc
				 :oclr_vloc obloc
				 )) )
       (list_append olist oclearob)
     ))
    ;; add the cond
    (list_append olist ocond)
    ;; also add the gotothen
    (assert_msg "check gotothen" (is_object gotothen) gotothen)
    (list_append othenlist gotothen)
    ;; add into the oelselist the gotoelse
    (assert_msg "check gotoelse" (is_object gotoelse) gotoelse)
    (list_append oelselist gotoelse)
    (debug "compiltst_normtester_same return olist=" olist)
    (return olist ())
    )
)
(install_method class_normtester_same compile_tester compiltst_normtester_same)


;;;;;;;;;;;;;;;;
(defun compiltst_normtester_success (ntsu gcx tcx)
  (debug "compiltst_normtester_success ntsu=" ntsu " tcx=" tcx)
  (assert_msg "check ntsu" (is_a ntsu class_normtester_success) ntsu)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (assert_msg "check tcx" (is_a tcx class_testercompilcontext) tcx)
  (let ( 
	(nloc (unsafe_get_field :nrep_loc ntsu))
	(nmatched (unsafe_get_field :ntest_matched ntsu))
	(nthen (unsafe_get_field :ntest_then ntsu))
	(nelse (unsafe_get_field :ntest_else ntsu))
	(nloclis (unsafe_get_field :ntest_locclist ntsu))
	(normatch (unsafe_get_field :ntest_normatch ntsu))
	(nsucdo (unsafe_get_field :ntsuccess_do ntsu))
	(:long ntestix (get_int ntsu))	
	(gotoend (endmatch_gotoinstr normatch gcx nloc))
	)
    (assert_msg "check nil nloclis" (null nloclis) nloclis)
    (assert_msg "check nil nthen" (null nthen) nthen)
    (assert_msg "check nil nelse" (null nelse) nelse)
    (let ( (osucc (compile_obj nsucdo gcx)) 
	   )
      ;; maybe we have to free all the location allocated for this test
      (if (is_list osucc)
	  (progn
	    (list_append osucc gotoend)
	    (return osucc (list_last osucc)))
	(return (list osucc gotoend) osucc))
      )))
(install_method class_normtester_success compile_tester compiltst_normtester_success)

;;;;;;;;;;;;;;;;
(defun compiltst_normtester_orclear (ntoc gcx tcx)
  (debug "compiltst_normtester_orclear ntoc=" ntoc)
  (assert_msg "check ntoc" (is_a ntoc class_normtester_or_clear) ntoc)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (assert_msg "check tcx" (is_a tcx class_testercompilcontext) tcx)
  (let ( 
	(nloc (unsafe_get_field :nrep_loc ntoc))
	(nmatched (unsafe_get_field :ntest_matched ntoc))
	(normatch (unsafe_get_field :ntest_normatch ntoc))
	(nthen (unsafe_get_field :ntest_then ntoc))
	(nelse (unsafe_get_field :ntest_else ntoc))
	(nclear (unsafe_get_field :ntorclear_locsym ntoc))
	(locmap (unsafe_get_field :gncx_locmap gcx))
	(olist (make_list discr_list))
	(gotothen (or (normtester_gotoinstr nthen gcx)
		      (endmatch_gotoinstr normatch gcx nloc)))
;;;	(gotoelse (or (normtester_gotoinstr nelse gcx)
;;;		      (endmatch_gotoinstr normatch gcx nloc)))
	)
    (debug "compiltst_normtester_orclear nclear=" nclear
	   " nthen=" nthen " nelse=" nelse)
    (assert_msg "check nclear" (is_multiple nclear) nclear)
    (foreach_in_multiple
     (nclear)
     (curlocs :long cix)
     (debug "compiltst_normtester_orclear curlocs=" curlocs " cix=" cix)
     (shortbacktrace_dbg "compiltst_normtester_orclear curlocs" 14)
     (let ( 
	   ;; TODO: perhaps we should not allocate a new obva but just
	   ;; compile the curlocs
	   (ocurl (let ( (oc (compile_obj curlocs gcx)) 
			 )
		    (debug "compiltst_normtester_orclear ocurl=" oc)
		    oc))
	   (oclrloc (instance class_objclear
			      :obi_loc nloc
			      :oclr_vloc ocurl
			      ))
	   )
       (debug "compiltst_normtester_orclear oclrloc=" oclrloc)
       (list_append olist oclrloc)
       )
     )
    (list_append olist gotothen)
    (debug "compiltst_normtester_orclear final olist=" olist)
    (return olist ())
    ))
(install_method class_normtester_or_clear compile_tester compiltst_normtester_orclear)
;;;;;;;;;;;;;;;;

(defun compiltst_normtester_ortransmit (ntot gcx tcx)
  (debug "compiltst_normtester_ortransmit ntot=" ntot)
  (assert_msg "check ntot" (is_a ntot class_normtester_or_transmit) ntot)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (assert_msg "check tcx" (is_a tcx class_testercompilcontext) tcx)
  (let ( 
	(nloc (unsafe_get_field :nrep_loc ntot))
	(nmatched (unsafe_get_field :ntest_matched ntot))
	(normatch (unsafe_get_field :ntest_normatch ntot))
	(ntupdst (unsafe_get_field :ntortransmit_dst ntot))
	(ntupsrc (unsafe_get_field :ntortransmit_src ntot))
	(nthen (unsafe_get_field :ntest_then ntot))
	(nelse (unsafe_get_field :ntest_else ntot))
	(olist (make_list discr_list))
	(gotothen (or (normtester_gotoinstr nthen gcx)
		      (endmatch_gotoinstr normatch gcx nloc)))
	)
    (assert_msg "check null nelse" (null nelse) nelse)
    (assert_msg "check same size ntupsc ntupdst" 
		(==i (multiple_length ntupdst) (multiple_length ntupsrc)) ntupsrc ntupdst)
    (foreach_in_multiple
     (ntupdst)
     (ncurdst :long nix)
     (let ( (ncursrc (multiple_nth ntupsrc nix)) 
	    )
       (debug "compiltst_normtester_ortransmit ncursrc=" ncursrc " ncurdst=" ncurdst " nix=" nix)
       (let ( 
	     (osrc (compile_obj ncursrc gcx))
	     (dstype (get_field :nocc_ctyp ncurdst))
	     (odst (compile_obj ncurdst gcx))
	     (dstlist (make_list discr_list))
	     (ocomp (instance class_objcompute
		     :obi_loc nloc
		     :obdi_destlist dstlist
		     :obcpt_type dstype
		     :obcpt_expr osrc))
	     )
	 (list_append dstlist odst)
	 (debug "compiltst_normtester_ortransmit osrc=" osrc " odst=" odst " ocomp=" ocomp)
	 (list_append olist ocomp)
       )))
    (list_append olist gotothen)
    (debug "compiltst_normtester_ortransmit final olist=" olist)
    (return olist ())
    ))
(install_method class_normtester_or_transmit compile_tester compiltst_normtester_ortransmit)

;;;;;;;;;;;;;;;;
;; to compile a disjunction, just goto the then case, because the
;; disjunction is only here to redistribute the then case inside the
;; disjuncts.
(defun compiltst_normtester_disjunction (ntdj gcx tcx)
  (debug "compiltst_normtester_disjunction ntdj=" ntdj)
  (assert_msg "check ntdj" (is_a ntdj class_normtester_disjunction) ntdj)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (assert_msg "check tcx" (is_a tcx class_testercompilcontext) tcx)
  (let (
	(locmap (unsafe_get_field :gncx_locmap gcx))
	(nloc (unsafe_get_field :nrep_loc ntdj))
	(nthen (unsafe_get_field :ntest_then ntdj))
	(normatch (unsafe_get_field :ntest_normatch ntdj))
	(ndisjlocsy (unsafe_get_field :ntdisj_freshorvar ntdj))
	(gotothen (or (normtester_gotoinstr nthen gcx)
		      (endmatch_gotoinstr normatch gcx nloc)))
	;; not sure that freelist is needed!
	(freelist (normtester_free_objloc_list ntdj gcx tcx))
	)
    (debug "compiltst_normtester_disjunction ndisjlocsy=" ndisjlocsy " gotothen=" gotothen " freelist=" freelist)
    (compile_warning "do we need the freelist in compiltst_normtester_disjunction?")
    (foreach_in_multiple
     (ndisjlocsy)
     (curdisjloc :long lix)
     (debug  "compiltst_normtester_disjunction curdisjloc=" curdisjloc " lix=" lix)
     (assert_msg "check curdisjloc" (is_a curdisjloc class_nrep_locsymocc) curdisjloc)
     (let ( (dbind (unsafe_get_field :nocc_bind curdisjloc))
	    (dsymb (unsafe_get_field :nocc_symb curdisjloc))
	    (dctyp (unsafe_get_field :nocc_ctyp curdisjloc))
	    (dobva (get_free_objloctyped gcx
					 dsymb
					 dctyp))
	   )
       (debug "compiltst_normtester_disjunction dobva=" dobva)
       (mapobject_put locmap dbind dobva)
       )
     )
    (return gotothen ())
    )
  )
(install_method class_normtester_disjunction compile_tester compiltst_normtester_disjunction)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun compilmatcher_cmatcher (cmat mcx gcx)
  (debug "compilmatcher_cmatcher cmat=" cmat " mcx=" mcx)
  (assert_msg "check cmat" (is_a cmat class_cmatcher) cmat)
  (assert_msg "check mcx" (is_a mcx class_matchcompilcontext) mcx)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (let (
	(cmins (unsafe_get_field :amatch_in cmat))
	(cmbind (unsafe_get_field :amatch_matchbind cmat))
	(cmouts (unsafe_get_field :amatch_out cmat))
	(cmstate (unsafe_get_field :cmatch_state cmat))
	(cmexptest (unsafe_get_field :cmatch_exptest cmat))
	(cmexpfill (unsafe_get_field :cmatch_expfill cmat))
	;; the normtester
	(normtester (unsafe_get_field :mcx_normtester mcx))
	;; the subsitution map
	(substmap (make_mapobject discr_map_objects 
				  (+i 5
				      (*i 2 (+i (multiple_length cmins)
						(multiple_length cmouts))))))
	(:long mcxcount
	       (let ( (boxcnt (get_field :mcx_statecounter mcx))
		      (:long cnt (+i 1 (get_int boxcnt)) ) )
		 (put_int boxcnt cnt)
		 cnt))
	;; generate a unique state string
	(uniqstate (let ( (sbuf (make_strbuf discr_strbuf)) )
		     (add2sbuf_cident sbuf (get_field :named_name cmstate))
		     (add2sbuf_strconst sbuf "_")
		     (add2sbuf_string sbuf (get_field :mcx_suffix mcx))
		     (add2sbuf_strconst sbuf "_")
		     (add2sbuf_longdec sbuf mcxcount)
		     (strbuf2string discr_verbatim_string sbuf)))
	;; fetch the olist to add instructions into
	(olist (get_field :mcx_olist mcx))
	)
    ;; map the state to the unique string 
    (mapobject_put substmap cmstate uniqstate)
    ;; map the matched thing 
    (let ( (nmatched (get_field :ntest_matched normtester)) )
      (debug "compilmatcher_cmatcher nmatched=" nmatched)
      (let ( (obmatched (compile_obj nmatched gcx)) )
	(debug "compilmatcher_cmatcher obmatched=" obmatched)
	(mapobject_put substmap
		       (get_field :binder cmbind)
		       obmatched
		       )))
    ;;
    (debug "compilmatcher_cmatcher normtester=" normtester)
    ;; map each input arguments
    (multiple_every_both 
     (get_field :ntmatch_inargs normtester)
     cmins
     (lambda (curin formin :long ix)
       (debug "compilmatcher_cmatcher curin=" curin " formin=" formin " ix=" ix)
       (assert_msg "check formin" (is_a formin class_formal_binding) formin)
       (let ( (oin (compile_obj curin gcx)) )
	 (debug "compilmatcher_cmatcher oin=" oin)
	 (mapobject_put substmap
			(get_field :binder formin)
			oin)
	 )))
    ;; map each output arguments
    (multiple_every_both
     (get_field :ntmatch_outlocs normtester)
     cmouts
     (lambda (curout formout :long ix)
       (debug "compilmatcher_cmatcher curout=" curout " formout=" formout " ix=" ix)
       (assert_msg "check formout" (is_a formout class_formal_binding) formout)
       (let ( (oout (compile_obj curout gcx)) )
	 (debug "compilmatcher_cmatcher oout=" oout " ix=" ix)
	 (mapobject_put substmap
			(get_field :binder formout)
			oout))
       ))
    (debug "compilmatcher_cmatcher substmap=" substmap)
    ;; expand
    (let (
	  (mcxloc (get_field :mcx_loc mcx))
	  (expander 
	   (lambda (tup)
	     (multiple_map
	      tup
	      (lambda (c)
		(cond 
		 ( (is_a c class_symbol)
		   (let ( (r (mapobject_get substmap c)) )
		     (if (null r)
			 (error_at mcx_loc
				   "invalid symbol $1 to expand for cmatcher" c))
		     r))
		 ( (is_object c)
		   (error_at mcxloc
			     "invalid object of $1 to expand for cmatcher"
			     (get_field :named_name (discrim c))))
		 ( (is_integerbox c)
		   (constant_box (get_int c)))
		 ( (is_string c)
		   (make_string discr_verbatim_string c))
		 (:else
		  (error_at mcxloc
			    "invalid stuff $1 of $2 to expand for cmatcher"
			    c
			    (get_field :named_name (discrim c))
			    )))))))
	  (exptest (expander cmexptest))
	  (expfill (expander cmexpfill))
	  (mloc (get_field :mcx_loc mcx))
	  (testchunk (instance class_objlocatedexpv
			       :obv_type ctype_long
			       :obx_cont exptest
			       :obcx_loc mloc))
	  (fillchunk (instance class_objlocatedexpv
			       :obv_type ctype_void
			       :obx_cont expfill
			       :obcx_loc mloc))
	  )
      (debug  "compilmatcher_cmatcher exptest=" exptest " expfill=" expfill
	      " testchunk=" testchunk " fillchunk=" fillchunk)
      (assert_msg "compilmatcher_cmatcher check exptest" exptest)
      (let ( 
	    (othenlist (make_list discr_list))
	    (othenbody (instance class_objplainblock
				 :obi_loc mloc
				 :oblo_bodyl othenlist
				 ))
	    (oelselist (make_list discr_list))
	    (oelsebody (instance class_objplainblock
				 :obi_loc mloc
				 :oblo_bodyl oelselist
				 ))
	    (ocond (instance class_objcond
			     :obi_loc mloc
			     :obcond_test testchunk
			     :obcond_then othenbody
			     :obcond_else oelsebody
			     ))
	    )
	(debug "compilmatcher_cmatcher ocond=" ocond)
	(list_append olist ocond)
	(foreach_in_multiple
	 (cmouts)
	 (curout :long outix)
	 (debug "compilmatcher_cmatcher curout=" curout " outix=" outix)
	 (assert_msg "check curout" (is_a curout class_formal_binding) curout)
	 (let ( (locout
		 (mapobject_get substmap 
				(unsafe_get_field :binder curout)))
		(oclearout (instance class_objclear
				     :obi_loc mloc
				     :oclr_vloc locout)) )
	   (debug "compilmatcher_cmatcher oclearout=" oclearout)
	   (assert_msg "check locout" (is_object locout) locout)
	   (list_append othenlist oclearout)
	   )
	 )
	(list_append othenlist fillchunk)
	(list_append othenlist (get_field :mcx_gotothen mcx))
	(list_append oelselist (get_field :mcx_gotoelse mcx))
	(debug "compilmatcher_cmatcher final ocond=" ocond)
	)
      )))
(install_method class_cmatcher compile_matcher compilmatcher_cmatcher)






;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun compilmatcher_funmatcher (fmat mcx gcx)
  (debug "compilmatcher_funmatcher fmat=" fmat " mcx=" mcx)
  (assert_msg "check fmat" (is_a fmat class_funmatcher) fmat)
  (assert_msg "check mcx" (is_a mcx class_matchcompilcontext) mcx)
  (assert_msg "check gcx" (is_a gcx class_c_generation_context) gcx)
  (let (
	(fmins (unsafe_get_field :amatch_in fmat))
	(fmbind (unsafe_get_field :amatch_matchbind fmat))
	(fmouts (unsafe_get_field :amatch_out fmat))
	(ntma (get_field :mcx_normtester mcx))
	;; fetch the olist to add instructions into
	(olist (get_field :mcx_olist mcx)) 
	(mloc (get_field :mcx_loc mcx))
	)
    (debug "compilmatcher_funmatcher ntma=" ntma)
    (assert_msg "check ntma" (is_a ntma class_normtester_matcher) ntma)
    (let ( (matndata (get_field :ntmatch_matndata ntma)) 
	   (omatdata (compile_obj matndata gcx))
	   (nmatched (get_field :ntest_matched ntma))
	   (omatched (compile_obj nmatched gcx))
	   (nins (get_field :ntmatch_inargs ntma))
	   (nouts (get_field :ntmatch_outlocs ntma))
	   (oins (multiple_map 
		  nins 
		  (lambda (thein)
		    (compile_obj thein gcx)
		    )))
	   (oouts (multiple_map 
		  nouts 
		  (lambda (theout)
		    (compile_obj theout gcx)
		    )))
	   (otestres (get_free_objlocptr gcx fmat))
	   (otestclos (get_free_objlocptr gcx '_closfunmatch))
	   )
      (debug "compilmatcher_funmatcher matndata=" matndata " omatdata=" omatdata
	     " fmins=" fmins " fmbind=" fmbind " fmouts=" fmouts
	     " nins=" nins " nouts=" nouts
	     " nmatched=" nmatched " omatched=" omatched
	     " oins=" oins " oouts=" oouts " ntma=" ntma 
	     " otestres=" otestres " otestclos=" otestclos)
      ;; should generate a multiapplication etc...
      (let (
	    (oargs (make_multiple discr_multiple (+i 2 (multiple_length oins))))
	    (ogetclos (instance class_objgetslot
				:obi_loc mloc
				:obdi_destlist (list otestclos)
				:ogetsl_obj omatdata
				:ogetsl_field fmatch_matchf
				))
	    (omapp (instance class_objmultiapply
			      :obi_loc mloc
			      :obdi_destlist (list otestres)
			      :obapp_clos otestclos
			      :obapp_args oargs
			      :obmultapp_xres oouts
			      ))
	    (othenlist (make_list discr_list))
	    (othenbody (instance class_objplainblock
				 :obi_loc mloc
				 :oblo_bodyl othenlist
				 ))
	    (oelselist (make_list discr_list))
	    (oelsebody (instance class_objplainblock
				 :obi_loc mloc
				 :oblo_bodyl oelselist
				 ))
	    (ocond (instance class_objcond
			     :obi_loc mloc
			     :obcond_test otestres
			     :obcond_then othenbody
			     :obcond_else oelsebody
			     ))
	     )
	(multiple_put_nth oargs 0 omatdata)
	(multiple_put_nth oargs 1 omatched)
	(foreach_in_multiple
	 (oins)
	 (curins :long inix)
	 (multiple_put_nth oargs (+i inix 2) curins)
	 )
	;; add the clear of all the outs in the else branch
	(foreach_in_multiple
	 (oouts)
	 (curouts :long outix)
	 (let ( (obcl (instance class_objclear
				:obi_loc mloc
				:oclr_vloc curouts)) )
	   (debug "compilmatcher_funmatcher obcl=" obcl)
	   (list_append oelselist obcl)
	 ))
	;; dispose the temporary variables
	(dispose_objloc otestres gcx)
	(dispose_objloc otestclos gcx)
	;; add the final gotos
	(list_append othenlist (get_field :mcx_gotothen mcx))
	(list_append oelselist (get_field :mcx_gotoelse mcx))
	(debug "compilmatcher_funmatcher ogetclos=" ogetclos 
	       " omapp=" omapp " ocond=" ocond)
	(list_append olist ogetclos)
	(list_append olist omapp)
	(list_append olist ocond)
	)
      )
    ))
(install_method class_funmatcher compile_matcher compilmatcher_funmatcher)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;; eof warmelt-genobj.melt