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
|
;; file warmelt-outobj.melt -*- Lisp -*-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(comment "***
Copyright (C) 2008 - 2012 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-outobj.melt and
;; to the generated file warmelt-outobj*.c
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 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])
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; the limit for our [generated C code] implementation and declaration
;; buffer length. The biggest file is often one of
;; melt-stage2/warmelt*c or one of melt-sources/xtramelt*c. 9Mbytes is
;; not enough!
(definstance buffer_limit_cont class_reference
:referenced_value '33554432) ;; 2^25
(defun get_code_buffer_limit ()
:doc #{Function to retrieve the generated code buffer limit.
See also $PUT_CODE_BUFFER_LIMIT}#
!buffer_limit_cont)
(defun put_code_buffer_limit (lim)
:doc #{Function to verbosely change the generated code buffer limit
between 2Mb and 64Mb. See also $GET_CODE_BUFFER_LIMIT.}#
(let ( (:long l (get_int lim))
)
(debug "put_buffer_limit l=" l)
(if (and (>=i l 2097152) ;; 2097152 == 2^21 = 2Mbytes
(<=i l 134217728) ;; 134217728 = 2^27 = 128Mbytes
)
(let ( (vlim (make_integerbox discr_constant_integer l))
)
(code_chunk informbuflimchk
#{ /*$INFORMBUFLIMCHK*/ inform (UNKNOWN_LOCATION,
"MELT code buffer limit set to %ld Kb = %ld Mb",
($L) >>10, ($L) >> 20);
}#)
(set_ref buffer_limit_cont vlim)
)
)))
;;;;;;;;;;;;;;;;
(defun code_buffer_limit_optset (optsymb :cstring csopt)
(let ( (:long lim 0) )
(code_chunk getlimchk
#{/*$GETLIMCHK*/ $LIM = atoi($CSOPT);
}#)
(if (>i lim 0)
(put_code_buffer_limit (make_integerbox discr_constant_integer
(*i lim 1024))))))
(register_option 'code_buffer_limit
'"set limit in kilobytes for the generated code buffer size"
code_buffer_limit_optset)
(defun outdeclinit_root (recv sbuf)
(debug "outdeclinit_root recv=" recv)
(assert_msg "outdeclinit_root unimplemented catchall" ())
)
(install_method class_root output_c_declinit outdeclinit_root)
(defun outpucod_objinielem (obielem declbuf implbuf :long depth)
(assert_msg "check obelem" (is_a obielem class_objinitelem))
(let ( (olocvar (unsafe_get_field :oie_locvar obielem))
(cnam (unsafe_get_field :oie_cname obielem)) )
(assert_msg "check cnam" (is_string cnam))
(assert_msg "check olocvar" olocvar)
(output_c_code olocvar declbuf implbuf depth)
;;
(cond ( (>i (strbuf_usedlength declbuf) (/iraw (get_int !buffer_limit_cont) 2))
(shortbacktrace_dbg "outpucod_objinielem huge declbuf" 10)
(debug "outpucod_objinielem huge declbuf=" declbuf)
(assert_msg "check limited declbuf"
(<i (strbuf_usedlength declbuf) (get_int !buffer_limit_cont)))))
;;
(cond ( (>i (strbuf_usedlength implbuf) (/iraw (get_int !buffer_limit_cont) 2))
(shortbacktrace_dbg "outpucod_objinielem huge implbuf" 10)
(debug "outpucod_objinielem huge implbuf=" implbuf)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))))
)
)
(install_method class_objinitelem output_c_code outpucod_objinielem)
(defun outcinitfill_root (recv implbuf ptrstr :long depth)
(debug "outcinitfill_root recv=" recv)
(assert_msg "outcinitfill_root unimplemented catchall" ())
)
(install_method class_root output_c_initial_fill outcinitfill_root)
(defun outcinitpredef_root (recv sbuf ptrstr :long depth)
(debug "outcinitfill_root recv=" recv)
(return)
)
(install_method class_root output_c_initial_predef outcinitpredef_root)
;;; output a predef
(defun output_predef (obpr implbuf :long depth)
(cond
( (is_integerbox obpr)
(add2sbuf_strconst implbuf "melt_fetch_predefined(")
(add2sbuf_longdec implbuf (get_int obpr))
(add2sbuf_strconst implbuf ")")
)
( (is_a obpr class_symbol)
(add2sbuf_strconst implbuf "((melt_ptr_t)(MELT_PREDEF(")
(add2sbuf_string implbuf (unsafe_get_field :named_name obpr))
(add2sbuf_strconst implbuf ")))")
)
( :else
(debug obpredef " output_predef bad obpredef=" obpredef)
(assert_msg "invalid obpredef" ())
)
)
;;
(cond ( (>i (strbuf_usedlength implbuf) (/iraw (get_int !buffer_limit_cont) 2))
(shortbacktrace_dbg "output_predef huge implbuf" 10)
(debug "output_predef huge implbuf=" implbuf)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))))
)
;;; output code for a predef
(defun outpucod_predef (obpred declbuf implbuf :long depth)
(assert_msg "check obpredef" (is_a obpred class_objpredef))
(let ( (obpr (unsafe_get_field :obpredef obpred)) )
(output_predef obpr implbuf depth)))
(install_method class_objpredef output_c_code outpucod_predef)
;;;; output a nil
(defun outpucod_nil (obnil declbuf implbuf :long depth)
(assert_msg "check obnil" (is_a obnil class_objnil))
(add2sbuf_strconst implbuf "(/*nil*/NULL)"))
(install_method class_objnil output_c_code outpucod_nil)
(defun outdeclinit_objinitobject (recv sbuf)
(add2sbuf_strconst sbuf " struct MELT_OBJECT_STRUCT(")
(add2sbuf_longdec sbuf (get_int recv))
(add2sbuf_strconst sbuf ") ")
(add2sbuf_string sbuf (unsafe_get_field :named_name recv))
(add2sbuf_strconst sbuf ";") ;
)
(install_method class_objinitobject output_c_declinit outdeclinit_objinitobject)
;; initial fill for both objinitobject & its objinituniqueobject subclass
(defun outcinitfill_objinitobject (recv sbuf ptrstr :long depth)
(assert_msg "outcinitfill_objinitobject check recv" (is_a recv class_objinitobject))
(debug "outcinitfill_objinitobject recv=" recv " ptrstr=" ptrstr)
(assert_msg "outcinitfill_objinitobject check ptrstr" (is_string ptrstr))
(let ( (odata (unsafe_get_field :oie_data recv))
(odiscr (unsafe_get_field :oie_discr recv))
(oname (unsafe_get_field :oie_cname recv))
(olocvar (unsafe_get_field :oie_locvar recv))
(oiopredef (unsafe_get_field :oio_predef recv))
(oclass (get_field :oio_class recv))
(:long depthp1 (+i depth 1))
)
(debug "outcinitfill_objinitobject odata=" odata)
(if odata (assert_msg "check odata" (is_a odata class_nrep_datainstance)))
(let ( (odloc (if odata (unsafe_get_field :nrep_loc odata)))
(odhash (if odata (unsafe_get_field :ninst_hash odata)))
(odslots (if odata (unsafe_get_field :ninst_slots odata)))
(odobnum (if odata (unsafe_get_field :ninst_objnum odata)))
(:long nbslots
(cond ( (is_multiple odslots)
(multiple_length odslots))
( (is_a oclass class_class)
(multiple_length (get_field :class_fields oclass)))
(:else
(assert_msg "outcinitfill_objinitobject cannot compute nbslots" ())
0)))
)
(if odloc (output_location odloc sbuf depthp1 "iniobj"))
(add2sbuf_indentnl sbuf depth)
(add2sbuf_strconst sbuf "/*iniobj ")
(add2sbuf_string sbuf oname)
(add2sbuf_strconst sbuf "*/")
(add2sbuf_indentnl sbuf depth)
(if oiopredef
(progn
(add2sbuf_strconst sbuf "if (")
(output_predef oiopredef sbuf depth)
(add2sbuf_strconst sbuf " != (melt_ptr_t)&")
(add2sbuf_string sbuf ptrstr)
(add2sbuf_strconst sbuf "->")
(add2sbuf_string sbuf oname)
(add2sbuf_strconst sbuf ") {")
(add2sbuf_indentnl sbuf depthp1)
(if nbslots
(progn
(add2sbuf_strconst sbuf "melt_assertmsg(\"check.predef length ")
(output_predef oiopredef sbuf depthp1)
(add2sbuf_strconst sbuf "\", melt_object_length((melt_ptr_t)(")
(output_predef oiopredef sbuf depthp1)
(add2sbuf_strconst sbuf ")) >= ")
(add2sbuf_longdec sbuf nbslots)
(add2sbuf_strconst sbuf ");")
(add2sbuf_indentnl sbuf depthp1)))
(add2sbuf_strconst sbuf "};")
(add2sbuf_indentnl sbuf depth)
(output_c_code olocvar () sbuf depth)
(add2sbuf_strconst sbuf " = ")
(output_predef oiopredef sbuf depth)
(add2sbuf_strconst sbuf ";")
(add2sbuf_indentnl sbuf depth)
)
(progn
;; for unique objects, only set locvar if it was not set;
;; hence already existing symbols are not recreated
(if (is_a recv class_objinituniqueobject)
(progn
(add2sbuf_strconst sbuf "/*uniqueobj*/ if (!")
(output_c_code olocvar () sbuf depth)
(add2sbuf_strconst sbuf ") ")
(add2sbuf_indentnl sbuf depth)
))
(output_c_code olocvar () sbuf (+i depth 1))
(add2sbuf_strconst sbuf " = (melt_ptr_t )&")
(add2sbuf_string sbuf ptrstr)
(add2sbuf_strconst sbuf "->")
(add2sbuf_string sbuf oname)
(add2sbuf_strconst sbuf ";")
(add2sbuf_indentnl sbuf depth)
))
;; Generate the check that odiscr is an object. We generate a
;; test for melt_prohibit_garbcoll because code generated for
;; warmelt-first.melt temporarily violate the check, since all
;; major classes are not initialized at that time.
(add2sbuf_strconst sbuf " if (MELT_LIKELY(!melt_prohibit_garbcoll)) melt_assertmsg(\"iniobj check.discr isobj ")
(add2sbuf_string sbuf oname)
(add2sbuf_strconst sbuf "\", melt_magic_discr ((melt_ptr_t) (")
(output_c_code odiscr () sbuf depth)
(add2sbuf_strconst sbuf ")) == MELTOBMAG_OBJECT);")
(add2sbuf_indentnl sbuf (+i depth 1))
;; generate the check of the objnum of odiscr
(add2sbuf_strconst sbuf " if (MELT_LIKELY(!melt_prohibit_garbcoll)) melt_assertmsg(\"iniobj check.discr objmagic ")
(add2sbuf_string sbuf oname)
(add2sbuf_strconst sbuf "\", ((meltobject_ptr_t) (")
(output_c_code odiscr () sbuf depth)
(add2sbuf_strconst sbuf "))->meltobj_magic == MELTOBMAG_OBJECT);")
(add2sbuf_indentnl sbuf (+i depth 1))
;; generate the initialization of the class
(add2sbuf_string sbuf ptrstr)
(add2sbuf_strconst sbuf "->")
(add2sbuf_string sbuf oname)
(add2sbuf_strconst sbuf ".meltobj_class = (meltobject_ptr_t)(")
(output_c_code odiscr () sbuf depth)
(add2sbuf_strconst sbuf ");")
(add2sbuf_indentnl sbuf depth)
(if odobnum
(progn
(add2sbuf_strconst sbuf " ")
(add2sbuf_string sbuf ptrstr)
(add2sbuf_strconst sbuf "->")
(add2sbuf_string sbuf oname)
(add2sbuf_strconst sbuf ".obj_num = ")
(cond ( (is_integerbox odobnum)
(add2sbuf_longdec sbuf (get_int odobnum)))
( (is_a odobnum class_symbol)
(add2sbuf_string sbuf (unsafe_get_field :named_name odobnum)))
(:else
(debug "outcinitfill_objinitobject unexpected odobnum=" odobnum)
(assert_msg "outcinitfill_objinitobject unexpected odobnum" ())
))
(add2sbuf_strconst sbuf ";")
(add2sbuf_indentnl sbuf depth)
))
(add2sbuf_strconst sbuf " ")
(add2sbuf_string sbuf ptrstr)
(add2sbuf_strconst sbuf "->")
(add2sbuf_string sbuf oname)
(add2sbuf_strconst sbuf ".obj_hash = ")
(if odhash
(add2sbuf_longdec sbuf (get_int odhash))
(add2sbuf_strconst sbuf "melt_nonzerohash ()"))
(add2sbuf_strconst sbuf ";")
(add2sbuf_indentnl sbuf depth)
(add2sbuf_strconst sbuf " ")
(add2sbuf_string sbuf ptrstr)
(add2sbuf_strconst sbuf "->")
(add2sbuf_string sbuf oname)
(add2sbuf_strconst sbuf ".obj_len = ")
(add2sbuf_longdec sbuf nbslots)
(add2sbuf_strconst sbuf ";")
(add2sbuf_indentnl sbuf depth)
;; output the fill
)
(cond ( (>i (strbuf_usedlength sbuf) (/iraw (get_int !buffer_limit_cont) 2))
(debug "outcinitfill_objinitobject huge sbuf=" sbuf)
(assert_msg "check limited sbuf"
(<i (strbuf_usedlength sbuf) (get_int !buffer_limit_cont)))))
)
)
(install_method class_objinitobject output_c_initial_fill outcinitfill_objinitobject)
(defun outcinitpredef_objinitobject (recv sbuf ptrstr :long depth)
(assert_msg "outcinitpredef_objinitobject check recv" (is_a recv class_objinitobject))
(debug recv "outcinitpredef_objinitobject recv=" recv " ptrstr=" ptrstr)
(assert_msg "outcinitpredef_objinitobject check sbuf" (is_strbuf sbuf))
(assert_msg "outcinitpredef_objinitobject check ptrstr" (is_string ptrstr))
(let ( (odata (unsafe_get_field :oie_data recv))
(odiscr (unsafe_get_field :oie_discr recv))
(oname (unsafe_get_field :oie_cname recv))
(olocvar (unsafe_get_field :oie_locvar recv))
(oiopredef (unsafe_get_field :oio_predef recv))
)
(assert_msg "check odata" (is_a odata class_nrep_datainstance))
(debug "outcinitpredef_objinitobject oiopredef=" oiopredef)
(if (null oiopredef) (return ()))
(if (is_a oiopredef class_nrep_nil) (return ()))
(let ( (odloc (unsafe_get_field :nrep_loc odata))
)
(output_location odloc sbuf depth "inipredef")
(add2sbuf_strconst sbuf "/*inipredef ")
(add2sbuf_string sbuf oname)
(add2sbuf_strconst sbuf "*/")
(add2sbuf_indentnl sbuf depth)
;;
(cond ( (>i (strbuf_usedlength sbuf) (/iraw (get_int !buffer_limit_cont) 2))
(debug "outcinitpredef_objinitobject huge implbuf=" sbuf)
(assert_msg "check limited sbuf"
(<i (strbuf_usedlength sbuf) (get_int !buffer_limit_cont)))))
;; we really initialize the predefined only if it was not initialized
(cond
( (is_a oiopredef class_symbol)
(add2sbuf_strconst sbuf "if (!MELT_PREDEF(")
(add2sbuf_string sbuf (unsafe_get_field :named_name oiopredef))
(add2sbuf_strconst sbuf ")) MELT_STORE_PREDEF(")
(add2sbuf_string sbuf (unsafe_get_field :named_name oiopredef))
(add2sbuf_strconst sbuf ", (melt_ptr_t)&")
(add2sbuf_string sbuf ptrstr)
(add2sbuf_strconst sbuf "->")
(add2sbuf_string sbuf oname)
(add2sbuf_strconst sbuf ");")
(add2sbuf_indentnl sbuf 1)
(add2sbuf_strconst sbuf "else {")
(add2sbuf_indentnl sbuf 2)
(add2sbuf_strconst sbuf "MELTPREDEFIX(meltpredefinited,")
(add2sbuf_string sbuf (unsafe_get_field :named_name oiopredef))
(add2sbuf_strconst sbuf ") = 1;")
(add2sbuf_indentnl sbuf 2)
(add2sbuf_strconst sbuf "fnotice(stderr, \"MELT: predefined %s already defined <%s:%d>\\n\", \"")
(add2sbuf_string sbuf (unsafe_get_field :named_name oiopredef))
(add2sbuf_strconst sbuf "\", __FILE__, __LINE__);")
(add2sbuf_indentnl sbuf 2)
(add2sbuf_strconst sbuf "};")
(add2sbuf_indentnl sbuf 1)
)
( (is_integerbox oiopredef)
(add2sbuf_strconst sbuf "if (!melt_fetch_predefined(")
(add2sbuf_longdec sbuf (get_int oiopredef))
(add2sbuf_strconst sbuf ")) melt_store_predefined(")
(add2sbuf_longdec sbuf (get_int oiopredef))
(add2sbuf_strconst sbuf ", (melt_ptr_t)&")
(add2sbuf_string sbuf ptrstr)
(add2sbuf_strconst sbuf "->")
(add2sbuf_string sbuf oname)
(add2sbuf_strconst sbuf ");")
(add2sbuf_indentnl sbuf 1)
(add2sbuf_strconst sbuf "else {")
(add2sbuf_indentnl sbuf 2)
(add2sbuf_strconst sbuf "meltpredefinited[")
(add2sbuf_longdec sbuf (get_int oiopredef))
(add2sbuf_strconst sbuf "] = 1;")
(add2sbuf_indentnl sbuf 2)
(add2sbuf_strconst sbuf "fnotice(\"MELT: predefined #%d already defined <%s:%d>\\n\", ")
(add2sbuf_longdec sbuf (get_int oiopredef))
(add2sbuf_strconst sbuf ", __FILE__, __LINE__);")
(add2sbuf_indentnl sbuf 2)
(add2sbuf_strconst sbuf "};")
(add2sbuf_indentnl sbuf 1)
;;;
)
( (null oiopredef)
(return ()))
( :else
(debug "outcinitpredef_objinitobject unexpected oiopredef=" oiopredef)
(assert_msg "outcinitpredef_objinitobject unexpected oiopredef" ())
)))
)
)
(install_method class_objinitobject output_c_initial_predef outcinitpredef_objinitobject)
(defun outdeclinit_objinitmultiple (recv sbuf)
(add2sbuf_strconst sbuf " struct MELT_MULTIPLE_STRUCT(")
(add2sbuf_longdec sbuf (get_int recv))
(add2sbuf_strconst sbuf ") ")
(add2sbuf_string sbuf (unsafe_get_field :named_name recv))
(add2sbuf_strconst sbuf ";")
)
(install_method class_objinitmultiple output_c_declinit outdeclinit_objinitmultiple)
(defun outcinitfill_objinitmultiple (recv sbuf ptrstr :long depth)
(assert_msg "outcinitfill_objinitmultiple check recv" (is_a recv class_objinitmultiple))
(debug "outcinitfill_objinitmultiple recv=" recv " ptrstr=" ptrstr)
(assert_msg "outcinitfill_objinitmultiple check ptrstr" (is_string ptrstr))
(let ( (cnam (unsafe_get_field :oie_cname recv))
(olocvar (unsafe_get_field :oie_locvar recv))
)
(add2sbuf_strconst sbuf "/*inimult ")
(add2sbuf_string sbuf cnam)
(add2sbuf_strconst sbuf "*/")
(add2sbuf_indentnl sbuf 1)
(if olocvar
(progn
(output_c_code olocvar () sbuf 1)
(add2sbuf_strconst sbuf " = (melt_ptr_t) &")
(add2sbuf_string sbuf ptrstr)
(add2sbuf_strconst sbuf "->")
(add2sbuf_string sbuf cnam)
(add2sbuf_strconst sbuf ";")
(add2sbuf_indentnl sbuf 1)
))
(add2sbuf_strconst sbuf " ")
(add2sbuf_string sbuf ptrstr)
(add2sbuf_strconst sbuf "->")
(add2sbuf_string sbuf cnam)
(add2sbuf_strconst sbuf ".discr = (meltobject_ptr_t)(")
(output_c_code (unsafe_get_field :oie_discr recv) () sbuf 1)
(add2sbuf_strconst sbuf ");")
(add2sbuf_indentnl sbuf 1)
(add2sbuf_strconst sbuf " ")
(add2sbuf_string sbuf ptrstr)
(add2sbuf_strconst sbuf "->")
(add2sbuf_string sbuf cnam)
(add2sbuf_strconst sbuf ".nbval = ")
(add2sbuf_longdec sbuf (get_int recv))
(add2sbuf_strconst sbuf ";")
;;
(cond ( (>i (strbuf_usedlength sbuf) (/iraw (get_int !buffer_limit_cont) 2))
(shortbacktrace_dbg "outcinitfill_objinitmultiple huge sbuf" 15)
(debug "outcinitfill_objinitmultiple huge sbuf=" sbuf)
(assert_msg "check limited sbuf"
(<i (strbuf_usedlength sbuf) (get_int !buffer_limit_cont)))))
))
(install_method class_objinitmultiple output_c_initial_fill outcinitfill_objinitmultiple)
(defun outdeclinit_objinitclosure (recv sbuf)
(add2sbuf_strconst sbuf " struct MELT_CLOSURE_STRUCT(")
(add2sbuf_longdec sbuf (get_int recv))
(add2sbuf_strconst sbuf ") ")
(add2sbuf_string sbuf (unsafe_get_field :oie_cname recv))
(add2sbuf_strconst sbuf ";")
)
(install_method class_objinitclosure output_c_declinit outdeclinit_objinitclosure)
(defun outcinitfill_objinitclosure (recv sbuf ptrstr :long depth)
(assert_msg "outcinitfill_objinitclosure check recv" (is_a recv class_objinitclosure))
(debug "outcinitfill_objinitclosure recv=" recv " ptrstr=" ptrstr)
(assert_msg "outcinitfill_objinitclosure check ptrstr" (is_string ptrstr))
(let ( (cnam (unsafe_get_field :oie_cname recv))
(olocvar (unsafe_get_field :oie_locvar recv))
(orout (unsafe_get_field :oiclo_rout recv))
(:long depthp1 (+i 1 depth))
)
(add2sbuf_strconst sbuf "/*iniclos ")
(add2sbuf_string sbuf cnam)
(add2sbuf_strconst sbuf "*/")
(add2sbuf_indentnl sbuf depthp1)
(if olocvar
(progn
; (add2sbuf_strconst sbuf "/*inicloslocvar*/ ")
(output_c_code olocvar () sbuf depthp1)
(add2sbuf_strconst sbuf " = (melt_ptr_t) &")
(add2sbuf_string sbuf ptrstr)
(add2sbuf_strconst sbuf "->")
(add2sbuf_string sbuf cnam)
(add2sbuf_strconst sbuf ";")
(add2sbuf_indentnl sbuf depthp1)
))
(add2sbuf_strconst sbuf " ")
(add2sbuf_string sbuf ptrstr)
(add2sbuf_strconst sbuf "->")
(add2sbuf_string sbuf cnam)
(add2sbuf_strconst sbuf ".discr = (meltobject_ptr_t)(")
(output_c_code (unsafe_get_field :oie_discr recv) () sbuf depthp1)
(add2sbuf_strconst sbuf ");")
(add2sbuf_indentnl sbuf depthp1)
(add2sbuf_strconst sbuf " ")
(add2sbuf_string sbuf ptrstr)
(add2sbuf_strconst sbuf "->")
(add2sbuf_string sbuf cnam)
(add2sbuf_strconst sbuf ".nbval = ")
(add2sbuf_longdec sbuf (get_int recv))
(add2sbuf_strconst sbuf ";")
(add2sbuf_indentnl sbuf depthp1)
(if orout
(progn
(add2sbuf_strconst sbuf " ")
(add2sbuf_string sbuf ptrstr)
(add2sbuf_strconst sbuf "->")
(add2sbuf_string sbuf cnam)
(add2sbuf_strconst sbuf ".rout = (meltroutine_ptr_t) (")
(output_c_code orout () sbuf depthp1)
(add2sbuf_strconst sbuf ");")
(add2sbuf_indentnl sbuf depthp1)
))
;;
(cond ( (>i (strbuf_usedlength sbuf) (/iraw (get_int !buffer_limit_cont) 2))
(debug "outcinitfill_objinitclosure huge sbuf=" sbuf)
(shortbacktrace_dbg "outcinitfill_objinitclosure huge sbuf" 15)
(assert_msg "check limited sbuf"
(<i (strbuf_usedlength sbuf) (get_int !buffer_limit_cont)))))
))
(install_method class_objinitclosure output_c_initial_fill outcinitfill_objinitclosure)
(defun outdeclinit_objinitroutine (recv sbuf)
(add2sbuf_strconst sbuf " struct MELT_ROUTINE_STRUCT(")
(add2sbuf_longdec sbuf (get_int recv))
(add2sbuf_strconst sbuf ") ")
(add2sbuf_string sbuf (unsafe_get_field :oie_cname recv))
(add2sbuf_strconst sbuf ";")
)
(install_method class_objinitroutine output_c_declinit outdeclinit_objinitroutine)
(defun outcinitfill_objinitroutine (recv sbuf ptrstr :long depth)
(assert_msg "outcinitfill_objinitroutine check recv" (is_a recv class_objinitroutine))
(debug recv "outcinitfill_objinitroutine recv=" recv " ptrstr=" ptrstr)
(assert_msg "outcinitfill_objinitroutine check ptrstr" (is_string ptrstr))
(let ( (cnam (unsafe_get_field :oie_cname recv))
(ipro (unsafe_get_field :oir_procroutine recv))
(olocvar (unsafe_get_field :oie_locvar recv))
(ndatr (unsafe_get_field :oie_data recv))
)
(add2sbuf_strconst sbuf "/*inirout ")
(add2sbuf_string sbuf cnam)
(add2sbuf_strconst sbuf "*/")
(add2sbuf_indentnl sbuf 1)
(if olocvar
(progn
; (add2sbuf_strconst sbuf "/*iniroutlocvar*/ ")
(output_c_code olocvar () sbuf 1)
(add2sbuf_strconst sbuf " = (melt_ptr_t) &")
(add2sbuf_string sbuf ptrstr)
(add2sbuf_strconst sbuf "->")
(add2sbuf_string sbuf cnam)
(add2sbuf_strconst sbuf ";")
(add2sbuf_indentnl sbuf 1)
))
(add2sbuf_strconst sbuf " ")
(add2sbuf_string sbuf ptrstr)
(add2sbuf_strconst sbuf "->")
(add2sbuf_string sbuf cnam)
(add2sbuf_strconst sbuf ".discr = (meltobject_ptr_t)(")
(output_c_code (unsafe_get_field :oie_discr recv) () sbuf 1)
(add2sbuf_strconst sbuf ");")
(add2sbuf_indentnl sbuf 1)
(add2sbuf_strconst sbuf " strncpy (")
(add2sbuf_string sbuf ptrstr)
(add2sbuf_strconst sbuf "->")
(add2sbuf_string sbuf cnam)
(add2sbuf_strconst sbuf ".routdescr, \"")
(if (is_a ndatr class_nrep_dataroutine)
(let ( (dnam (unsafe_get_field :ndata_name ndatr))
(dpro (unsafe_get_field :ndrou_proc ndatr))
)
(debug ndatr "outcinitfill_objinitroutine ndatr=" ndatr " dpro=" dpro)
(if (is_a dnam class_named)
(add2sbuf_cencstring sbuf (unsafe_get_field :named_name dnam)))
(if (is_a dpro class_nrep_routproc)
(let ( (dloc (unsafe_get_field :nrep_loc dpro))
(locfil (or (mixint_val dloc) (mixloc_val dloc)))
)
(add2sbuf_strconst sbuf " @")
(add2sbuf_cencstring sbuf locfil)
(add2sbuf_strconst sbuf ":")
(add2sbuf_longdec sbuf (get_int dloc))
)
)
)
(add2sbuf_cencstring sbuf cnam))
(add2sbuf_strconst sbuf "\", MELT_ROUTDESCR_LEN - 1);")
(add2sbuf_indentnl sbuf 1)
(add2sbuf_strconst sbuf " ")
(add2sbuf_string sbuf ptrstr)
(add2sbuf_strconst sbuf "->")
(add2sbuf_string sbuf cnam)
(add2sbuf_strconst sbuf ".nbval = ")
(add2sbuf_longdec sbuf (get_int recv))
(add2sbuf_strconst sbuf ";")
(add2sbuf_indentnl sbuf 1)
(if ipro
(progn
(debug "outcinitfill_objinitroutine ipro=" ipro)
(assert_msg "check ipro" (is_a ipro class_named))
(add2sbuf_strconst sbuf "MELT_ROUTINE_SET_ROUTCODE(&")
(add2sbuf_string sbuf ptrstr)
(add2sbuf_strconst sbuf "->")
(add2sbuf_string sbuf cnam)
(add2sbuf_strconst sbuf ", ")
(add2sbuf_string sbuf (unsafe_get_field :named_name ipro))
(add2sbuf_strconst sbuf ");")
(add2sbuf_indentnl sbuf 1)
)
(progn
(debug "outcinitfill_objinitroutine (noipro) recv=" recv)
(add2sbuf_strconst sbuf "#warning no procedure in objinitroutine ")
(add2sbuf_string sbuf cnam)
(add2sbuf_indentnl sbuf 1)
)
)
)
;;
(cond ( (>i (strbuf_usedlength sbuf) (/iraw (get_int !buffer_limit_cont) 2))
(debug "outcinitfill_objinitroutine huge sbuf=" sbuf)
(shortbacktrace_dbg "outcinitfill_objinitroutine huge sbuf" 12)
(assert_msg "check limited sbuf"
(<i (strbuf_usedlength sbuf) (get_int !buffer_limit_cont)))))
)
(install_method class_objinitroutine output_c_initial_fill outcinitfill_objinitroutine)
;;;; strings
(defun outdeclinit_objinitstring (recv sbuf)
(add2sbuf_strconst sbuf " struct MELT_STRING_STRUCT(")
(add2sbuf_longdec sbuf (get_int recv))
(add2sbuf_strconst sbuf ") ")
(add2sbuf_string sbuf (unsafe_get_field :named_name recv))
(add2sbuf_strconst sbuf ";")
)
(install_method class_objinitstring output_c_declinit outdeclinit_objinitstring)
(defun outcinitfill_objinitstring (recv sbuf ptrstr :long depth)
(assert_msg "outcinitfill_objinitstring check recv" (is_a recv class_objinitstring))
(debug "outcinitfill_objinitstring recv=" recv " ptrstr=" ptrstr)
(assert_msg "outcinitfill_objinitstring check ptrstr" (is_string ptrstr))
(let ( (cnam (unsafe_get_field :oie_cname recv))
(olocvar (unsafe_get_field :oie_locvar recv))
(strdata (unsafe_get_field :oie_data recv))
(:long datalen (string_length strdata))
)
(add2sbuf_indentnl sbuf depth)
(add2sbuf_strconst sbuf "/*inistring ")
(add2sbuf_string sbuf cnam)
(add2sbuf_strconst sbuf "*/")
(add2sbuf_indentnl sbuf (+i depth 1))
(if olocvar
(progn
(output_c_code olocvar () sbuf 1)
(add2sbuf_strconst sbuf " = (melt_ptr_t) &")
(add2sbuf_string sbuf ptrstr)
(add2sbuf_strconst sbuf "->")
(add2sbuf_string sbuf cnam)
(add2sbuf_strconst sbuf ";")
(add2sbuf_indentnl sbuf 1)
))
(add2sbuf_strconst sbuf " ")
(add2sbuf_string sbuf ptrstr)
(add2sbuf_strconst sbuf "->")
(add2sbuf_string sbuf cnam)
(add2sbuf_strconst sbuf ".discr = (meltobject_ptr_t)(")
(output_c_code (unsafe_get_field :oie_discr recv) () sbuf 1)
(add2sbuf_strconst sbuf ");")
(add2sbuf_indentnl sbuf 1)
;; we handle big enough strings specially
(if (<i datalen 256)
(progn
(add2sbuf_strconst sbuf "/*small inistring*/ strncpy(")
(add2sbuf_string sbuf ptrstr)
(add2sbuf_strconst sbuf "->")
(add2sbuf_string sbuf cnam)
(add2sbuf_strconst sbuf ".val, \"")
(add2sbuf_cencstring sbuf strdata)
(add2sbuf_strconst sbuf "\", sizeof (")
(add2sbuf_string sbuf ptrstr)
(add2sbuf_strconst sbuf "->")
(add2sbuf_string sbuf cnam)
(add2sbuf_strconst sbuf ".val)-1);")
)
;; else datalen > 256
;;;;;;;;;;;;;;;;
;; the C standard gives some limitation on constant strings. We
;; avoid generating a huge constant string as single source to a
;; strcpy. We break that in a sequence of memcpy on big chunks
;; ended by a smaller strcpy.
(let ( (:long ix 0)
)
(debug "outcinitfill_objinitstring big datalen=" datalen)
(add2sbuf_strconst sbuf "/*big inistring*/")
(add2sbuf_indentnl sbuf 1)
(forever
inistrloop
(debug "outcinitfill_objinitstring ix=" ix " sbuflen=" (strbuf_usedlength sbuf))
;;
(cond ( (>i (strbuf_usedlength sbuf) (/iraw (get_int !buffer_limit_cont) 2))
(shortbacktrace_dbg "outcinitfill_objinitstring huge sbuf" 10)
(debug "outcinitfill_objinitstring huge sbuf=" sbuf)
(assert_msg "check limited sbuf"
(<i (strbuf_usedlength sbuf) (get_int !buffer_limit_cont)))))
;;
(cond
;; end reached
((>=i ix datalen)
(exit inistrloop))
;; end nearly reached
((>i (+i ix 72) datalen)
(add2sbuf_strconst sbuf "/*end big inistring*/ strncpy(")
(add2sbuf_string sbuf ptrstr)
(add2sbuf_strconst sbuf "->")
(add2sbuf_string sbuf cnam)
(add2sbuf_strconst sbuf ".val + ")
(add2sbuf_longdec sbuf ix)
(add2sbuf_strconst sbuf ", \"")
(add2out_cencsubstring sbuf strdata ix (-i datalen ix))
(add2sbuf_strconst sbuf "\", sizeof (")
(add2sbuf_string sbuf ptrstr)
(add2sbuf_strconst sbuf "->")
(add2sbuf_string sbuf cnam)
(add2sbuf_strconst sbuf ".val) - ")
(add2sbuf_longdec sbuf (+i ix 1))
(add2sbuf_strconst sbuf ");")
(add2sbuf_indentnl sbuf 1)
(exit inistrloop)
)
;; very big remaining
((<i ix (-i datalen 256))
(add2sbuf_strconst sbuf "/*really big chunk inistring*/")
(add2sbuf_indentnl sbuf 1)
(add2sbuf_strconst sbuf "memcpy (")
(add2sbuf_string sbuf ptrstr)
(add2sbuf_strconst sbuf "->")
(add2sbuf_string sbuf cnam)
(add2sbuf_strconst sbuf ".val + ")
(add2sbuf_longdec sbuf ix)
(add2sbuf_strconst sbuf ",")
;; compile time catanation of constant string
(add2sbuf_indentnl sbuf 8)
(add2sbuf_strconst sbuf "\"")
(add2out_cencsubstring sbuf strdata ix 64)
(add2sbuf_strconst sbuf "\"")
(add2sbuf_indentnl sbuf 8)
(add2sbuf_strconst sbuf "\"")
(add2out_cencsubstring sbuf strdata (+i 64 ix) 64)
(add2sbuf_strconst sbuf "\"")
(add2sbuf_indentnl sbuf 8)
(add2sbuf_strconst sbuf "\"")
(add2out_cencsubstring sbuf strdata (+i 128 ix) 64)
(add2sbuf_strconst sbuf "\"")
(add2sbuf_indentnl sbuf 8)
(add2sbuf_strconst sbuf "\"")
(add2out_cencsubstring sbuf strdata (+i 192 ix) 64)
(add2sbuf_strconst sbuf "\",")
(add2sbuf_indentnl sbuf 8)
(add2sbuf_strconst sbuf " /*big*/ 256);")
(add2sbuf_indentnl sbuf 1)
;;(setq ix (+i ix 256))
(increment ix 256)
(void)
)
;; less big remaining
((<i ix (-i datalen 128))
(add2sbuf_strconst sbuf "/*quite big chunk inistring*/")
(add2sbuf_indentnl sbuf 1)
(add2sbuf_strconst sbuf "memcpy (")
(add2sbuf_string sbuf ptrstr)
(add2sbuf_strconst sbuf "->")
(add2sbuf_string sbuf cnam)
(add2sbuf_strconst sbuf ".val + ")
(add2sbuf_longdec sbuf ix)
(add2sbuf_strconst sbuf ",")
;; compile time catanation of constant string
(add2sbuf_indentnl sbuf 8)
(add2sbuf_strconst sbuf "\"")
(add2out_cencsubstring sbuf strdata ix 64)
(add2sbuf_strconst sbuf "\"")
(add2sbuf_indentnl sbuf 8)
(add2sbuf_strconst sbuf "\"")
(add2out_cencsubstring sbuf strdata (+i 64 ix) 64)
(add2sbuf_strconst sbuf "\",")
(add2sbuf_indentnl sbuf 8)
(add2sbuf_strconst sbuf " /*lessbig*/ 128);")
(add2sbuf_indentnl sbuf 1)
(increment ix 128)
;;(setq ix (+i ix 128))
(void)
)
;; even less big remaining
((<i ix (-i datalen 64))
(add2sbuf_strconst sbuf "/*almost big chunk inistring*/")
(add2sbuf_indentnl sbuf 1)
(add2sbuf_strconst sbuf "memcpy (")
(add2sbuf_string sbuf ptrstr)
(add2sbuf_strconst sbuf "->")
(add2sbuf_string sbuf cnam)
(add2sbuf_strconst sbuf ".val + ")
(add2sbuf_longdec sbuf ix)
(add2sbuf_strconst sbuf ",")
(add2sbuf_indentnl sbuf 8)
(add2sbuf_strconst sbuf "\"")
(add2out_cencsubstring sbuf strdata ix 64)
(add2sbuf_strconst sbuf "\",")
(add2sbuf_indentnl sbuf 8)
(add2sbuf_strconst sbuf " /*evenlessbig*/ 64);")
(add2sbuf_indentnl sbuf 1)
(increment ix 64)
;;(setq ix (+i ix 64))
(void)
)
)
(void)
)
;;
;;
;;
(cond ( (>i (strbuf_usedlength sbuf) (/iraw (get_int !buffer_limit_cont) 2))
(shortbacktrace_dbg "outcinitfill_objinitstring huge sbuf" 10)
(debug "outcinitfill_objinitstring huge declbuf=" sbuf)
(assert_msg "check limited sbuf"
(<i (strbuf_usedlength sbuf) (get_int !buffer_limit_cont)))))
))
(add2sbuf_indentnl sbuf 1)
(add2out sbuf ##{$PTRSTR->$CNAM.val[$DATALEN] = (char)0; }#
)
(add2sbuf_indentnl sbuf 1)
(add2out sbuf ##{$PTRSTR->$CNAM.slen = $DATALEN; }#
)
(add2sbuf_indentnl sbuf 1)
))
(install_method class_objinitstring output_c_initial_fill outcinitfill_objinitstring)
;;;; boxed integers
(defun outdeclinit_objinitboxedinteger (recv sbuf)
(add2sbuf_strconst sbuf " struct meltint_st ")
(add2sbuf_string sbuf (unsafe_get_field :named_name recv))
(add2sbuf_strconst sbuf ";")
)
(install_method class_objinitboxinteger output_c_declinit outdeclinit_objinitboxedinteger)
(defun outcinitfill_objinitboxedinteger (recv sbuf ptrstr :long depth)
(assert_msg "outcinitfill_objinitboxedinteger check recv" (is_a recv class_objinitboxinteger))
(debug "outcinitfill_objinitboxedinteger recv=" recv " ptrstr=" ptrstr)
(assert_msg "outcinitfill_objinitboxedinteger check ptrstr" (is_string ptrstr))
(let ( (cnam (unsafe_get_field :oie_cname recv))
(olocvar (unsafe_get_field :oie_locvar recv))
(odata (unsafe_get_field :oie_data recv))
(:long depthp1 (+i 1 depth))
)
(add2sbuf_strconst sbuf "/*iniboxint ")
(add2sbuf_string sbuf cnam)
(add2sbuf_strconst sbuf "*/")
(add2sbuf_indentnl sbuf depthp1)
(if olocvar
(progn
(output_c_code olocvar () sbuf depthp1)
(add2sbuf_strconst sbuf " = (melt_ptr_t) &")
(add2sbuf_string sbuf ptrstr)
(add2sbuf_strconst sbuf "->")
(add2sbuf_string sbuf cnam)
(add2sbuf_strconst sbuf ";")
(add2sbuf_indentnl sbuf depthp1)
))
(add2sbuf_strconst sbuf " ")
(add2sbuf_string sbuf ptrstr)
(add2sbuf_strconst sbuf "->")
(add2sbuf_string sbuf cnam)
(add2sbuf_strconst sbuf ".discr = (meltobject_ptr_t)(")
(output_c_code (unsafe_get_field :oie_discr recv) () sbuf depthp1)
(add2sbuf_strconst sbuf ");")
(add2sbuf_indentnl sbuf depthp1)
(add2sbuf_strconst sbuf " ")
(add2sbuf_string sbuf ptrstr)
(add2sbuf_strconst sbuf "->")
(add2sbuf_string sbuf cnam)
(add2sbuf_strconst sbuf ".val = ")
(add2sbuf_longdec sbuf (get_int odata))
(add2sbuf_strconst sbuf ";")
(add2sbuf_indentnl sbuf depthp1)
;;
(cond ( (>i (strbuf_usedlength sbuf) (/iraw (get_int !buffer_limit_cont) 2))
(shortbacktrace_dbg "outcinitfill_objinitboxedinteger huge sbuf" 10)
(debug "outcinitfill_objinitboxedinteger huge sbuf=" sbuf)
(assert_msg "check limited sbuf"
(<i (strbuf_usedlength sbuf) (get_int !buffer_limit_cont)))))
))
(install_method class_objinitboxinteger output_c_initial_fill outcinitfill_objinitboxedinteger)
;;;; pairs
(defun outdeclinit_objinitpair (recv sbuf)
(add2sbuf_strconst sbuf " struct meltpair_st ")
(add2sbuf_string sbuf (unsafe_get_field :named_name recv))
(add2sbuf_strconst sbuf ";")
)
(install_method class_objinitpair output_c_declinit outdeclinit_objinitpair)
(defun outcinitfill_objinitpair (recv sbuf ptrstr :long depth)
(assert_msg "outcinitfill_objinitpair check recv" (is_a recv class_objinitpair))
(debug "outcinitfill_objinitpair recv=" recv " ptrstr=" ptrstr)
(assert_msg "outcinitfill_objinitpair check ptrstr" (is_string ptrstr))
(let ( (cnam (unsafe_get_field :oie_cname recv))
(olocvar (unsafe_get_field :oie_locvar recv))
(odata (unsafe_get_field :oie_data recv))
(:long depthp1 (+i 1 depth))
)
(add2sbuf_strconst sbuf "/*inipair ")
(add2sbuf_string sbuf cnam)
(add2sbuf_strconst sbuf "*/")
(add2sbuf_indentnl sbuf depthp1)
(if olocvar
(progn
(output_c_code olocvar () sbuf depthp1)
(add2sbuf_strconst sbuf " = (melt_ptr_t) &")
(add2sbuf_string sbuf ptrstr)
(add2sbuf_strconst sbuf "->")
(add2sbuf_string sbuf cnam)
(add2sbuf_strconst sbuf ";")
(add2sbuf_indentnl sbuf depthp1)
))
(add2sbuf_strconst sbuf " ")
(add2sbuf_string sbuf ptrstr)
(add2sbuf_strconst sbuf "->")
(add2sbuf_string sbuf cnam)
(add2sbuf_strconst sbuf ".discr = (meltobject_ptr_t)(")
(output_c_code (unsafe_get_field :oie_discr recv) () sbuf depthp1)
(add2sbuf_strconst sbuf ");")
(add2sbuf_indentnl sbuf depth)
;;
(cond ( (>i (strbuf_usedlength sbuf) (/iraw (get_int !buffer_limit_cont) 2))
(shortbacktrace_dbg "outcinitfill_objinitpair huge sbuf" 10)
(debug "outcinitfill_objinitpair huge sbuf=" sbuf)
(assert_msg "check limited sbuf"
(<i (strbuf_usedlength sbuf) (get_int !buffer_limit_cont)))))
))
(install_method class_objinitpair output_c_initial_fill outcinitfill_objinitpair)
;;;;;;;;;;;;;;;;
;;;; lists
(defun outdeclinit_objinitlist (recv sbuf)
(add2sbuf_strconst sbuf " struct meltlist_st ")
(add2sbuf_string sbuf (unsafe_get_field :named_name recv))
(add2sbuf_strconst sbuf ";")
)
(install_method class_objinitlist output_c_declinit outdeclinit_objinitlist)
(defun outcinitfill_objinitlist (recv sbuf ptrstr :long depth)
(assert_msg "outcinitfill_objinitlist check recv" (is_a recv class_objinitlist))
(debug "outcinitfill_objinitlist recv=" recv " ptrstr=" ptrstr)
(assert_msg "outcinitfill_objinitlist check ptrstr" (is_string ptrstr))
(let ( (cnam (unsafe_get_field :oie_cname recv))
(olocvar (unsafe_get_field :oie_locvar recv))
(odata (unsafe_get_field :oie_data recv))
(:long depthp1 (+i 1 depth))
)
(add2sbuf_strconst sbuf "/*inilist ")
(add2sbuf_string sbuf cnam)
(add2sbuf_strconst sbuf "*/")
(add2sbuf_indentnl sbuf depthp1)
(if olocvar
(progn
(output_c_code olocvar () sbuf depthp1)
(add2sbuf_strconst sbuf " = (melt_ptr_t) &")
(add2sbuf_string sbuf ptrstr)
(add2sbuf_strconst sbuf "->")
(add2sbuf_string sbuf cnam)
(add2sbuf_strconst sbuf ";")
(add2sbuf_indentnl sbuf depthp1)
))
(add2sbuf_strconst sbuf " ")
(add2sbuf_string sbuf ptrstr)
(add2sbuf_strconst sbuf "->")
(add2sbuf_string sbuf cnam)
(add2sbuf_strconst sbuf ".discr = (meltobject_ptr_t)(")
(output_c_code (unsafe_get_field :oie_discr recv) () sbuf depthp1)
(add2sbuf_strconst sbuf ");")
(add2sbuf_indentnl sbuf depth)
;;
(cond ( (>i (strbuf_usedlength sbuf) (/iraw (get_int !buffer_limit_cont) 2))
(shortbacktrace_dbg "outcinitfill_objinitlist huge sbuf" 10)
(debug "outcinitfill_objinitlist huge sbuf=" sbuf)
(assert_msg "check limited sbuf"
(<i (strbuf_usedlength sbuf) (get_int !buffer_limit_cont)))))
)
)
(install_method class_objinitlist output_c_initial_fill outcinitfill_objinitlist)
;;;;;;;;;;;;;;;;
(defun outpucod_anydiscr (any declbuf implbuf :long depth)
(debug "outpucod_anydiscr any=" any)
(outcstring_err "* output_c_code unimplemented receiver discriminator ")
(let ( (discr (discrim any)) )
(outstr_err (unsafe_get_field :named_name discr))
(outnewline_err)
(debug "outpucod_anydiscr discr=" discr))
(assert_msg "@@ outpucod_anydiscr not able to output" ())
)
(install_method discr_any_receiver output_c_code outpucod_anydiscr)
(defun outpucod_null (nul declbuf implbuf :long depth)
(add2sbuf_strconst implbuf "NULL")
)
(install_method discr_null_receiver output_c_code outpucod_null)
;;; catchall for outputting any stuff
(defun outpucod_catchall_root (anyr declbuf implbuf :long depth)
(debug anyr "outpucod_catchall_root anyr=" anyr)
(display_debug_message anyr "outpucod_catchall_root anyr")
(outcstring_err "* output_c_code unimplemented receiver class ")
(let ( (discr (discrim anyr)) ) (outstr_err (unsafe_get_field :named_name discr)))
(outnewline_err)
(assert_msg "@@ outpucod_catchall_root not able to output" ())
)
(install_method class_root output_c_code outpucod_catchall_root)
;;; common code to output a location
;;; just output the #line directive
(defun output_raw_location (loc implbuf :long depth :cstring msg)
(if loc
(progn
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "#ifndef MELTGCC_NOLINENUMBERING")
(add2sbuf_indentnl implbuf 0)
(cond ( (is_mixint loc)
;;; we don't output #line in a single draw to make
;;; grep -v '#line' work better even without the
;;; start-of-line caret...
(add2sbuf_strconst implbuf "#")
(add2sbuf_strconst implbuf "line ")
(add2sbuf_longdec implbuf (get_int loc))
(add2sbuf_strconst implbuf " \"")
(add2sbuf_string implbuf (mixint_val loc))
(add2sbuf_strconst implbuf "\""))
( (is_mixloc loc)
(add2sbuf_strconst implbuf "#")
(add2sbuf_strconst implbuf "line ")
(add2sbuf_longdec implbuf (mixloc_locline loc))
(add2sbuf_strconst implbuf " \"")
(add2sbuf_strconst implbuf (mixloc_locbasefile loc))
(add2sbuf_strconst implbuf "\""))
)
(if msg
(progn
(add2sbuf_strconst implbuf " /**::")
(add2sbuf_ccomconst implbuf msg)
(add2sbuf_strconst implbuf "::**/")
))
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "#endif /*MELTGCC_NOLINENUMBERING*/")
(add2sbuf_indentnl implbuf depth)
;;
(cond ( (>i (strbuf_usedlength implbuf) (/iraw (get_int !buffer_limit_cont) 2))
(shortbacktrace_dbg "output_raw_location huge implbuf" 12)
(debug "output_raw_location huge implbuf=" implbuf)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))))
)))
;; we really want to avoid outputint the same location twice, so we
;; keep the previous location and implbuf
(definstance prevloc_container class_reference)
(definstance previmplbuf_container class_reference)
;; return the line number and file name of a location
(defun line_and_file_of_location (loc)
(cond
( (is_mixint loc)
(return (make_integerbox discr_integer (get_int loc))
(mixint_val loc))
)
( (is_mixloc loc)
(return (make_integerbox discr_integer (mixloc_locline loc))
(make_string_mixloc_file discr_string loc)))
( :else
(return () ()))
)
)
;; output the location & set the frame's location
(defun output_location (loc implbuf :long depth :cstring msg)
(let ( (prevloc (unsafe_get_field :referenced_value prevloc_container))
(prevbuf (unsafe_get_field :referenced_value previmplbuf_container))
)
(if (== prevbuf implbuf)
(if (or (== prevloc loc)
(and (==i (get_int loc) (get_int prevloc))
(== (mixloc_val loc) (mixloc_val prevloc))))
(progn
(if msg (progn
(add2sbuf_strconst implbuf "/*^")
(add2sbuf_ccomconst implbuf msg)
(add2sbuf_strconst implbuf "*/")
))
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "#ifndef MELTGCC_NOLINENUMBERING")
(add2sbuf_indentnl implbuf 0)
(cond ( (is_mixint loc)
;;; we don't output #line in a single draw to make
;;; grep -v '#line' work better even without the
;;; start-of-line caret...
(add2sbuf_strconst implbuf "#")
(add2sbuf_strconst implbuf "line ")
(add2sbuf_longdec implbuf (get_int loc))
)
( (is_mixloc loc)
(add2sbuf_strconst implbuf "#")
(add2sbuf_strconst implbuf "line ")
(add2sbuf_longdec implbuf (mixloc_locline loc))
)
)
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "#endif")
(add2sbuf_indentnl implbuf depth)
;;
(cond ( (>i (strbuf_usedlength implbuf) (/iraw (get_int !buffer_limit_cont) 2))
(shortbacktrace_dbg "output_location huge implbuf" 12)
(debug "output_location huge implbuf=" implbuf)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))))
(return)
)
)
)
(unsafe_put_fields prevloc_container :referenced_value loc)
(unsafe_put_fields previmplbuf_container :referenced_value implbuf)
;;
(cond
( (is_mixint loc)
(add2sbuf_strconst implbuf "MELT_LOCATION(\"")
(add2sbuf_string implbuf (mixint_val loc))
(add2sbuf_strconst implbuf ":")
(add2sbuf_longdec implbuf (get_int loc))
(if msg (progn
(add2sbuf_strconst implbuf ":/ ")
(add2sbuf_strconst implbuf msg)
))
(add2sbuf_strconst implbuf "\");")
)
( (is_mixloc loc)
(add2sbuf_strconst implbuf "MELT_LOCATION(\"")
(add2sbuf_string implbuf (mixloc_val loc))
(add2sbuf_strconst implbuf ":")
(add2sbuf_longdec implbuf (get_int loc))
(if msg (progn
(add2sbuf_strconst implbuf ":/ ")
(add2sbuf_strconst implbuf msg)
))
(add2sbuf_strconst implbuf "\");")
)
)
(output_raw_location loc implbuf depth msg)
))
;;; output the code for declaring the current frame struct
(defun output_curframe_declstruct (rou dsbuf)
(let (
(obody (unsafe_get_field :obrout_body rou))
(onbval (unsafe_get_field :obrout_nbval rou))
(onblong (unsafe_get_field :obrout_nblong rou))
(:long nbval (get_int onbval))
(:long nblong (get_int onblong))
(:long isinitial (is_a rou class_initialroutineobj))
(others (unsafe_get_field :obrout_others rou))
)
;; output the current frame
(add2sbuf_indentnl dsbuf 0)
(add2sbuf_strconst dsbuf " struct ")
(if (is_a rou class_named)
(progn
(add2sbuf_strconst dsbuf "frame_")
(add2sbuf_string dsbuf (unsafe_get_field :named_name rou))
(add2sbuf_strconst dsbuf "_st ")))
(add2sbuf_strconst dsbuf "{")
(add2sbuf_indentnl dsbuf 0)
(add2sbuf_strconst dsbuf " int mcfr_nbvar;")
(add2sbuf_indentnl dsbuf 0)
(add2sbuf_strconst dsbuf "#if MELT_HAVE_DEBUG")
(add2sbuf_indentnl dsbuf 0)
(add2sbuf_strconst dsbuf " const char* mcfr_flocs;")
(add2sbuf_indentnl dsbuf 0)
(add2sbuf_strconst dsbuf "#else /*!MELT_HAVE_DEBUG*/")
(add2sbuf_indentnl dsbuf 0)
(add2sbuf_strconst dsbuf " const char* mcfr_unusedflocs;")
(add2sbuf_indentnl dsbuf 0)
(add2sbuf_strconst dsbuf "#endif /*MELT_HAVE_DEBUG*/")
(add2sbuf_indentnl dsbuf 0)
;; we declare a mcfr_initforwmarkrout to be sure to never use clos in the
;; generated code; if we do, the generated code is invalid C
(if isinitial
(add2sbuf_strconst dsbuf
" void (*mcfr_initforwmarkrout) ( struct melt_callframe_st*, int);")
(add2sbuf_strconst dsbuf " struct meltclosure_st *mcfr_clos;"))
(add2sbuf_indentnl dsbuf 0)
(add2sbuf_strconst dsbuf " struct excepth_melt_st *mcfr_exh;")
(add2sbuf_indentnl dsbuf 0)
(add2sbuf_strconst dsbuf " struct melt_callframe_st *mcfr_prev;")
(add2sbuf_indentnl dsbuf 0)
(if (>i nbval 0)
(progn
(add2sbuf_strconst dsbuf "#define MELTFRAM_NBVARPTR ")
(add2sbuf_longdec dsbuf nbval)
(add2sbuf_indentnl dsbuf 0)
(add2sbuf_strconst dsbuf " melt_ptr_t mcfr_varptr[")
(add2sbuf_longdec dsbuf nbval)
(add2sbuf_strconst dsbuf "];")
(add2sbuf_indentnl dsbuf 0))
(progn
(add2sbuf_strconst dsbuf "/*no varptr*/")
(add2sbuf_indentnl dsbuf 0)
(add2sbuf_strconst dsbuf "#define MELTFRAM_NBVARPTR /*none*/0")
(add2sbuf_indentnl dsbuf 0)))
(if (>i nblong 0)
(progn
(add2sbuf_strconst dsbuf "#define MELTFRAM_NBVARNUM ")
(add2sbuf_longdec dsbuf nblong)
(add2sbuf_indentnl dsbuf 0)
(add2sbuf_strconst dsbuf " long mcfr_varnum[")
(add2sbuf_longdec dsbuf nblong)
(add2sbuf_strconst dsbuf "];")
(add2sbuf_indentnl dsbuf 0))
(progn
(add2sbuf_strconst dsbuf "/*no varnum*/")
(add2sbuf_indentnl dsbuf 0)
(add2sbuf_strconst dsbuf "#define MELTFRAM_NBVARNUM /*none*/0")
(add2sbuf_indentnl dsbuf 0)))
(if others
(progn
(add2sbuf_strconst dsbuf "/*others*/")
(add2sbuf_indentnl dsbuf 0)
(list_every
others
(lambda (oloc)
(assert_msg "check other oloc" (is_a oloc class_objlocv))
(let ( (octyp (unsafe_get_field :obv_type oloc))
(oname (unsafe_get_field :obl_cname oloc))
)
(assert_msg "check octyp" (is_a octyp class_ctype))
(add2sbuf_string dsbuf (unsafe_get_field :ctype_cname octyp))
(add2sbuf_strconst dsbuf " ")
(add2sbuf_string dsbuf oname)
(add2sbuf_strconst dsbuf ";")
(add2sbuf_indentnl dsbuf 0))
(cond ( (>i (strbuf_usedlength dsbuf) (/iraw (get_int !buffer_limit_cont) 2))
(shortbacktrace_dbg "output_curframe_declstruct huge dsbuf" 10)
(debug "output_curframe_declstruct huge dsbuf=" dsbuf)
(assert_msg "check limited dsbuf"
(<i (strbuf_usedlength dsbuf) (get_int !buffer_limit_cont)))))
))
)
(progn
(add2sbuf_strconst dsbuf "/*no others*/")
(add2sbuf_indentnl dsbuf 0))
)
(add2sbuf_strconst dsbuf " long _spare_; }")
(add2sbuf_indentnl dsbuf 0)
;; end of curframe
))
;;; output code for marking the frame pointed by meltframptr_
(defun outpucod_marker (rou implbuf)
(assert_msg "check rou" (is_a rou class_routineobj))
(let ( (others (get_field :obrout_others rou))
(:long nbval (get_int (get_field :obrout_nbval rou)))
)
(if (is_not_a rou class_initialroutineobj)
(progn
(add2sbuf_string implbuf (get_field :ctype_marker ctype_value))
(add2sbuf_strconst implbuf " (meltframptr_->mcfr_clos);")
(add2sbuf_indentnl implbuf 3)))
(add2sbuf_strconst implbuf "for(ix=0; ix<")
(add2sbuf_longdec implbuf nbval)
(add2sbuf_strconst implbuf "; ix++)")
(add2sbuf_indentnl implbuf 4)
(add2sbuf_strconst implbuf "if (meltframptr_->mcfr_varptr[ix])")
(add2sbuf_indentnl implbuf 5)
(add2sbuf_string implbuf (get_field :ctype_marker ctype_value))
(add2sbuf_strconst implbuf " (meltframptr_->mcfr_varptr[ix]);")
(add2sbuf_indentnl implbuf 3)
(list_every
others
(lambda (oloc)
(assert_msg "check other oloc" (is_a oloc class_objlocv))
(let ( (octyp (get_field :obv_type oloc))
(oname (get_field :obl_cname oloc))
(omarker (get_field :ctype_marker octyp))
)
(assert_msg "check octyp" (is_a octyp class_ctype))
(cond
((is_string omarker)
(add2sbuf_strconst implbuf "if (meltframptr_->")
(add2sbuf_string implbuf oname)
(add2sbuf_strconst implbuf ") ")
(add2sbuf_string implbuf omarker)
(add2sbuf_strconst implbuf " (meltframptr_->")
(add2sbuf_string implbuf oname)
(add2sbuf_strconst implbuf ");")
(add2sbuf_indentnl implbuf 3)
)
((is_a omarker class_named)
(add2sbuf_strconst implbuf "if (meltframptr_->")
(add2sbuf_string implbuf oname)
(add2sbuf_strconst implbuf ") ")
(add2sbuf_string implbuf (get_field :named_name omarker))
(add2sbuf_strconst implbuf " (meltframptr_->")
(add2sbuf_string implbuf oname)
(add2sbuf_strconst implbuf ");")
(add2sbuf_indentnl implbuf 3)
)
))
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
))
;; (add2sbuf_indentnl implbuf 1)
))
;;; output the code for declaring and initializing the current frame
(defun output_curframe_declstruct_init (declstruct rou implbuf)
(let (
(obody (unsafe_get_field :obrout_body rou))
(onbval (unsafe_get_field :obrout_nbval rou))
(onblong (unsafe_get_field :obrout_nblong rou))
(:long nbval (get_int onbval))
(:long nblong (get_int onblong))
(:long isinitial (is_a rou class_initialroutineobj))
(others (unsafe_get_field :obrout_others rou))
(rouname (get_field :named_name rou))
)
;; output call counter for debugging
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "#if MELT_HAVE_DEBUG")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf " static long call_counter__;")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf " long thiscallcounter__ ATTRIBUTE_UNUSED = ++ call_counter__;")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "#undef meltcallcount")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "#define meltcallcount thiscallcounter__")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "#else")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "#undef meltcallcount")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "#define meltcallcount 0L")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "#endif")
(add2sbuf_indentnl implbuf 0)
(declstruct rou implbuf)
(if (not isinitial)
(add2sbuf_strconst implbuf " *meltframptr_=0,"))
(add2sbuf_strconst implbuf " meltfram__;")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "#define meltframe meltfram__")
(if (not isinitial)
(progn
(add2sbuf_indentnl implbuf 2)
(add2sbuf_strconst implbuf "if (MELT_UNLIKELY(meltxargdescr_ == MELTPAR_MARKGGC)) { /*mark for ggc*/")
(add2sbuf_indentnl implbuf 3)
(add2sbuf_strconst implbuf "int ix=0;")
(add2sbuf_indentnl implbuf 3)
(if rouname
(add2out implbuf "meltframptr_ = (struct frame_" rouname "_st*) meltfirstargp_;")
(add2sbuf_strconst implbuf "meltframptr_ = (void*)meltfirstargp_;"))
(add2sbuf_indentnl implbuf 3)
(add2out implbuf ##{ /* use arguments output_curframe_declstruct_init */
(void) meltclosp_;
(void) meltfirstargp_;
(void) meltxargdescr_;
(void) meltxargtab_;
(void) meltxresdescr_;
(void) meltxrestab_;
}#)
(outpucod_marker rou implbuf)
(add2sbuf_strconst implbuf "return NULL;")
(add2sbuf_indentnl implbuf 2)
(add2sbuf_strconst implbuf "}/*end markggc*/;")
)
)
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf " memset(&meltfram__, 0, sizeof(meltfram__));")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf " meltfram__.mcfr_nbvar = ")
(add2sbuf_longdec implbuf nbval)
(add2sbuf_strconst implbuf ";")
(add2sbuf_indentnl implbuf 0)
(if (not isinitial)
(progn
(add2sbuf_strconst implbuf " meltfram__.mcfr_clos = meltclosp_;")
(add2sbuf_indentnl implbuf 0)))
(add2sbuf_strconst implbuf " meltfram__.mcfr_prev = (struct melt_callframe_st *) melt_topframe;")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf " melt_topframe = (struct melt_callframe_st *) &meltfram__;")
(add2sbuf_indentnl implbuf 0)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
))
;;; output code for a procroutine
(defun outpucod_procroutine (prou declbuf implbuf :long depth)
(assert_msg "check prou" (is_a prou class_procroutineobj))
(let ( (onam (unsafe_get_field :named_name prou))
(obody (unsafe_get_field :obrout_body prou))
(onbval (unsafe_get_field :obrout_nbval prou))
(onblong (unsafe_get_field :obrout_nblong prou))
(:long nbval (get_int onbval))
(:long nblong (get_int onblong))
(others (unsafe_get_field :obrout_others prou))
(ogargs (unsafe_get_field :oprout_getargs prou))
(oretval (unsafe_get_field :obrout_retval prou))
(orloc (unsafe_get_field :oprout_loc prou))
(ofunam (unsafe_get_field :oprout_funam prou))
(orestnam (unsafe_get_field :oprout_restnam prou))
)
(if (not (is_string ofunam))
(setq ofunam '"**"))
;; output the declaration
(add2sbuf_indentnl declbuf 0)
(add2sbuf_indentnl declbuf 0)
(output_raw_location orloc implbuf 0 "proc")
(add2sbuf_indentnl declbuf 0)
(if (or (is_mixint orloc) (is_mixloc orloc))
(output_raw_location orloc declbuf 0 "procdecl")
)
(add2sbuf_strconst declbuf "melt_ptr_t MELT_MODULE_VISIBILITY ")
(add2sbuf_string declbuf onam)
(add2sbuf_strconst declbuf "(meltclosure_ptr_t meltclosp_,")
(add2sbuf_strconst declbuf " melt_ptr_t meltfirstargp_,")
(add2sbuf_strconst declbuf " const melt_argdescr_cell_t meltxargdescr_[],")
(add2sbuf_strconst declbuf " union meltparam_un *meltxargtab_,")
(add2sbuf_strconst declbuf " const melt_argdescr_cell_t meltxresdescr_[],")
(add2sbuf_strconst declbuf " union meltparam_un *meltxrestab_);")
(add2sbuf_indentnl declbuf 0)
;; output the implementation
(add2sbuf_indentnl implbuf 0)
(add2sbuf_indentnl implbuf 0)
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "melt_ptr_t MELT_MODULE_VISIBILITY ")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_string implbuf onam)
(add2sbuf_strconst implbuf "(meltclosure_ptr_t meltclosp_,")
(add2sbuf_strconst implbuf " melt_ptr_t meltfirstargp_,")
(add2sbuf_strconst implbuf " const melt_argdescr_cell_t meltxargdescr_[],")
(add2sbuf_strconst implbuf " union meltparam_un *meltxargtab_,")
(add2sbuf_indentnl implbuf 5)
(add2sbuf_strconst implbuf " const melt_argdescr_cell_t meltxresdescr_[],")
(add2sbuf_strconst implbuf " union meltparam_un *meltxrestab_)")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "{")
(if orestnam
(let ( (ovariadicindex (variadic_index_idstr orestnam))
(ovariadiclength (variadic_length_idstr orestnam))
)
(add2sbuf_indentnl implbuf 1)
(add2sbuf_strconst implbuf "/*variadic*/ int ")
(add2sbuf_string implbuf ovariadicindex)
(add2sbuf_strconst implbuf " = 0, ")
(add2sbuf_string implbuf ovariadiclength)
(add2sbuf_strconst implbuf " = melt_argdescr_length (meltxargdescr_);")
(add2sbuf_indentnl implbuf 0)
;; we generate (0+$ORESTNAM_len) to ensure that it cannot be
;; set.
;;
;; The melt_variadic_length & melt_variadic_index are used
;; by primitives from warmelt-base.melt like variadic_index,
;; variadic_length, ...
(add2sbuf_strconst implbuf "#define melt_variadic_length (0+")
(add2sbuf_string implbuf ovariadiclength)
(add2sbuf_strconst implbuf ")")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "#define melt_variadic_index ")
(add2sbuf_string implbuf ovariadicindex)
(add2sbuf_indentnl implbuf 0)
))
(add2sbuf_indentnl implbuf 2)
(add2out implbuf "long current_blocklevel_signals_" onam "_melt = melt_blocklevel_signals;")
(add2sbuf_indentnl implbuf 1)
(output_curframe_declstruct_init output_curframe_declstruct prou implbuf)
(add2sbuf_strconst implbuf "melt_trace_start(\"")
(add2sbuf_string implbuf ofunam)
(add2sbuf_strconst implbuf "\", meltcallcount);")
(add2sbuf_indentnl implbuf 0)
;; output the argument getting
(add2sbuf_strconst implbuf "/*getargs*/")
(add2sbuf_indentnl implbuf 0)
(assert_msg "check ogargs" (is_multiple_or_null ogargs))
(foreach_in_multiple
(ogargs)
(curget :long curank)
(add2sbuf_indentnl implbuf 1)
(add2sbuf_strconst implbuf "/*getarg#")
(add2sbuf_longdec implbuf curank)
(add2sbuf_strconst implbuf "*/")
(add2sbuf_indentnl implbuf 1)
(output_c_code curget declbuf implbuf 1)
;;
(cond ( (>i (strbuf_usedlength implbuf) (/iraw (get_int !buffer_limit_cont) 2))
(shortbacktrace_dbg "outpucod_procroutine huge implbuf" 10)
(debug "outpucod_procroutine huge implbuf=" implbuf)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))))
) ;end foreach ogargs
(add2sbuf_strconst implbuf ";")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf " goto lab_endgetargs;")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "lab_endgetargs:;")
(add2sbuf_indentnl implbuf 0)
;; output the body
(assert_msg "check obody" (is_list obody))
(add2sbuf_strconst implbuf "/*body*/")
(add2sbuf_indentnl implbuf 0)
(list_every
obody
(lambda (curbody)
(if (and curbody (not (is_a curbody class_objpurevalue)))
(progn
(output_c_code curbody declbuf implbuf 0)
(add2sbuf_indentnl implbuf 0)))
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
))
;; end of implementation
(add2sbuf_strconst implbuf ";")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf " goto labend_rout;")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "labend_rout:")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "melt_trace_end(\"")
(add2sbuf_string implbuf ofunam)
(add2sbuf_strconst implbuf "\", meltcallcount);")
(add2sbuf_indentnl implbuf 1)
(add2out implbuf " melt_blocklevel_signals = current_blocklevel_signals_" onam "_melt;")
(add2sbuf_indentnl implbuf 1)
(add2sbuf_strconst implbuf " melt_topframe = (struct melt_callframe_st*) meltfram__.mcfr_prev;")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf " return (melt_ptr_t)(")
(if oretval
(output_c_code oretval declbuf implbuf 1)
(add2sbuf_strconst implbuf "/*noretval*/ NULL"))
(add2sbuf_strconst implbuf ");")
(if orestnam
(progn
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "#undef melt_variadic_length")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "#undef melt_variadic_index")
(add2sbuf_indentnl implbuf 0)))
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "#undef meltcallcount")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "#undef meltfram__")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "#undef MELTFRAM_NBVARNUM")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "#undef MELTFRAM_NBVARPTR")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "} /*end ")
(add2sbuf_string implbuf onam)
(add2sbuf_strconst implbuf "*/")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_indentnl implbuf 0)
;;
(cond ( (>i (strbuf_usedlength declbuf) (/iraw (get_int !buffer_limit_cont) 2))
(shortbacktrace_dbg "outpucod_procroutine huge declbuf" 10)
(debug "outpucod_procroutine huge declbuf=" declbuf)
(assert_msg "check limited declbuf"
(<i (strbuf_usedlength declbuf) (get_int !buffer_limit_cont)))))
;;
(cond ( (>i (strbuf_usedlength implbuf) (/iraw (get_int !buffer_limit_cont) 2))
(shortbacktrace_dbg "outpucod_procroutine huge implbuf" 10)
(debug "outpucod_procroutine huge implbuf=" implbuf)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))))
))
(install_method class_procroutineobj output_c_code outpucod_procroutine)
;;; output the cdata structure
(defun output_curframe_cdat_struct (idatup implbuf)
(add2sbuf_indentnl implbuf 1)
(add2sbuf_strconst implbuf "struct cdata_st {")
(foreach_in_multiple
(idatup)
(curdat :long curk)
(add2sbuf_indentnl implbuf 1)
(output_c_declinit curdat implbuf))
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf " long spare_;")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "}")
(cond ( (>i (strbuf_usedlength implbuf) (/iraw (get_int !buffer_limit_cont) 2))
(shortbacktrace_dbg "output_curframe_cdat_struct huge implbuf" 10)
(debug "output_curframe_cdat_struct huge implbuf=" implbuf)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))))
)
;;; output the cdata structure fill
(defun output_curframe_cdat_fill (idatup implbuf)
;; generate the allocation of cdat
(add2sbuf_strconst implbuf " cdat = (struct cdata_st*) meltgc_allocate(sizeof(*cdat),0);")
(add2sbuf_indentnl implbuf 1)
(add2sbuf_strconst implbuf " melt_prohibit_garbcoll = TRUE;")
(add2sbuf_indentnl implbuf 1)
;;;
;;; generate the initial predef of cdat
(add2sbuf_strconst implbuf "/*initial routine predef*/")
(add2sbuf_indentnl implbuf 1)
(foreach_in_multiple
(idatup)
(curpdat :long curk)
(output_c_initial_predef curpdat implbuf '"cdat" 1))
;;;
;;; generate the initial filling of cdat
(add2sbuf_strconst implbuf "/*initial routine fill*/")
(add2sbuf_indentnl implbuf 1)
(foreach_in_multiple
(idatup)
(curfil :long curk)
(add2sbuf_indentnl implbuf 1)
(output_c_initial_fill curfil implbuf '"cdat" 0))
;;;;;;;
;;; initialize the variables
;;;
;;; clear the cdat for safety and renable GC
(add2sbuf_strconst implbuf " cdat = NULL;")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf " melt_prohibit_garbcoll = FALSE;")
(add2sbuf_indentnl implbuf 0)
;;;
(cond ( (>i (strbuf_usedlength implbuf) (/iraw (get_int !buffer_limit_cont) 2))
(shortbacktrace_dbg "output_curframe_cdat_fill implbuf" 10)
(debug "output_curframe_cdat_fill huge implbuf=" implbuf)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))))
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; output code for the initial module routine
(defun outpucod_initialmoduleroutine (pini declbuf implbuf :long depth)
(debug "outpucod_initialmoduleroutine start pini=" pini
"\n of discrim=" (discrim pini))
(assert_msg "check pini" (is_a pini class_initial_module_routineobj))
(let (
(idatup (unsafe_get_field :oirout_data pini))
(irfill (unsafe_get_field :oirout_fill pini))
(iprolog (unsafe_get_field :oirout_prolog pini))
(oretval (unsafe_get_field :obrout_retval pini))
(omodnam (unsafe_get_field :oirout_modulename pini))
(onbval (get_field :obrout_nbval pini))
(:long nbval (get_int onbval))
(:long minihash (+i 1 (%iraw (obj_hash pini) 4096)))
)
(add2sbuf_indentnl declbuf 0)
(add2sbuf_indentnl declbuf 0)
(add2out declbuf ##{
MELT_EXTERN void* melt_start_this_module (void*);
}#)
(add2sbuf_indentnl declbuf 0)
(add2sbuf_indentnl implbuf 0)
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "typedef ")
(output_curframe_declstruct pini implbuf)
(add2sbuf_strconst implbuf " initial_frame_st;")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_indentnl implbuf 0)
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "static void initialize_module_meltdata_")
(add2sbuf_cident implbuf omodnam)
(add2sbuf_strconst implbuf " (initial_frame_st *iniframp__, char meltpredefinited[])")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "{")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "#define meltfram__ (*iniframp__)")
(add2sbuf_indentnl implbuf 1)
(output_curframe_cdat_struct idatup implbuf)
(add2sbuf_strconst implbuf " *cdat = NULL;")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf " dbgprintf (\"start initialize_module_meltdata_")
(add2sbuf_cident implbuf omodnam)
(add2sbuf_strconst implbuf " iniframp__=%p\", (void*) iniframp__);")
(add2sbuf_indentnl implbuf 1)
(add2sbuf_strconst implbuf "(void) meltpredefinited; /* avoid warning if non-used. */")
(add2sbuf_indentnl implbuf 1)
(add2sbuf_strconst implbuf " melt_assertmsg (\"check module initial frame\", iniframp__->mcfr_nbvar == /*minihash*/ -")
(add2sbuf_longdec implbuf minihash)
(add2sbuf_strconst implbuf ");")
(add2sbuf_indentnl implbuf 1)
;;; fill the cdat
(output_curframe_cdat_fill idatup implbuf)
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "#undef meltfram__")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "} /*end initialize_module_meltdata_")
(add2sbuf_cident implbuf omodnam)
(add2sbuf_strconst implbuf "*/")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_indentnl implbuf 0)
;; emit code to tell if we have debug
(progn
(add2sbuf_indentnl declbuf 0)
(add2sbuf_strconst declbuf
"/* define different names when debugging or not */")
(add2sbuf_indentnl declbuf 0)
(add2sbuf_strconst declbuf "#if MELT_HAVE_DEBUG")
(add2sbuf_indentnl declbuf 0)
(add2sbuf_strconst declbuf "MELT_EXTERN ")
(add2sbuf_strconst declbuf "const char meltmodule_")
(add2sbuf_cident declbuf omodnam)
(add2sbuf_strconst declbuf "__melt_have_debug_enabled[];")
(add2sbuf_indentnl declbuf 0)
(add2sbuf_strconst declbuf "#define melt_have_debug_string meltmodule_")
(add2sbuf_cident declbuf omodnam)
(add2sbuf_strconst declbuf "__melt_have_debug_enabled")
(add2sbuf_indentnl declbuf 0)
(add2sbuf_strconst declbuf "#else /*!MELT_HAVE_DEBUG*/")
(add2sbuf_indentnl declbuf 0)
(add2sbuf_strconst declbuf "MELT_EXTERN const char meltmodule_")
(add2sbuf_cident declbuf omodnam)
(add2sbuf_strconst declbuf "__melt_have_debug_disabled[];")
(add2sbuf_indentnl declbuf 0)
(add2sbuf_strconst declbuf "#define melt_have_debug_string meltmodule_")
(add2sbuf_cident declbuf omodnam)
(add2sbuf_strconst declbuf "__melt_have_debug_disabled")
(add2sbuf_indentnl declbuf 0)
(add2sbuf_strconst declbuf "#endif /*!MELT_HAVE_DEBUG*/")
(add2sbuf_indentnl declbuf 0)
(add2sbuf_indentnl declbuf 0)
;;
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "#if MELT_HAVE_DEBUG")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "const char meltmodule_")
(add2sbuf_cident implbuf omodnam)
(add2sbuf_strconst implbuf "__melt_have_debug_enabled[] = \"MELT module ")
(add2sbuf_cencstring implbuf omodnam)
(add2sbuf_strconst implbuf " have debug enabled\";")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "#else /*!MELT_HAVE_DEBUG*/")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "const char meltmodule_")
(add2sbuf_cident implbuf omodnam)
(add2sbuf_strconst implbuf "__melt_have_debug_disabled[] = \"MELT module ")
(add2sbuf_cencstring implbuf omodnam)
(add2sbuf_strconst implbuf " have debug disabled\";")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "#endif /*MELT_HAVE_DEBUG*/")
(add2sbuf_indentnl implbuf 0)
)
;;
(add2sbuf_indentnl implbuf 0)
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "void* melt_start_this_module (void* modargp_) {")
(add2sbuf_indentnl implbuf 0)
;; generate the initial data structure
(add2sbuf_indentnl implbuf 1)
(add2sbuf_strconst implbuf "char meltpredefinited[MELTGLOB__LASTGLOB+8];")
(add2sbuf_indentnl implbuf 1)
;; generate the initial frame
(output_curframe_declstruct_init
(lambda (rou dsbuf)
(add2sbuf_indentnl dsbuf 0)
(add2sbuf_strconst dsbuf "initial_frame_st ")
)
pini implbuf)
;;; output the prologue
;;;
(add2sbuf_strconst implbuf "/**initial routine prologue**/")
(add2sbuf_indentnl implbuf 1)
(add2sbuf_strconst implbuf "/* set initial frame marking */")
(add2sbuf_indentnl implbuf 1)
(add2sbuf_strconst implbuf "((struct melt_callframe_st*)&meltfram__)->mcfr_nbvar = /*minihash*/ -")
(add2sbuf_longdec implbuf minihash)
(add2sbuf_strconst implbuf ";")
(add2sbuf_indentnl implbuf 1)
(add2sbuf_strconst implbuf "((struct melt_callframe_st*)&meltfram__)->mcfr_forwmarkrout = meltmod__")
(add2sbuf_cident implbuf omodnam)
(add2sbuf_strconst implbuf "__forward_or_mark_module_start_frame;")
(add2sbuf_indentnl implbuf 1)
(foreach_in_list
(iprolog)
(curpair curprol)
(if (and curprol (not (is_a curprol class_objpurevalue)))
(progn
(output_c_code curprol declbuf implbuf 1)
(add2sbuf_indentnl implbuf 1))
))
(add2sbuf_strconst implbuf "/**initial routine cdata initializer**/")
(add2sbuf_indentnl implbuf 0)
;;; output call cdata initializer
(add2sbuf_indentnl implbuf 1)
(add2sbuf_strconst implbuf "memset(meltpredefinited, 0, sizeof(meltpredefinited));")
(add2sbuf_indentnl implbuf 1)
(add2sbuf_strconst implbuf "initialize_module_meltdata_")
(add2sbuf_cident implbuf omodnam)
(add2sbuf_strconst implbuf " (&meltfram__, meltpredefinited);")
(add2sbuf_indentnl implbuf 1)
;;; output the body
;;;
(add2sbuf_strconst implbuf "/**initial routine body**/")
(add2sbuf_indentnl implbuf 0)
;; filter out the pure values from the body
(let ( (rawbody (unsafe_get_field :obrout_body pini))
(bodylist (make_list discr_list))
(chunkbuflist (make_list discr_list))
)
(foreach_in_list
(rawbody)
(curpair curbody)
(if (and curbody (not (is_a curbody class_objpurevalue)))
(list_append bodylist curbody)))
(let ( (bodtup (list_to_multiple bodylist discr_multiple))
(chunkbuf ())
(:long nbbody (multiple_length bodtup))
(:long chunkcount 0)
)
(foreach_in_multiple
(bodtup)
(curbody :long bodix)
;; the 128 is the size of each chunk...
(if (==i (%iraw bodix 128) 0)
(let ( (:long chunkix (+i chunkcount 1))
(newchunkbuf (make_strbuf discr_strbuf))
)
;;(setq chunkcount (+i chunkcount 1))
(increment chunkcount 1)
(list_append chunkbuflist newchunkbuf)
(setq chunkbuf newchunkbuf)))
;; clear the previous location memoization
(unsafe_put_fields prevloc_container :referenced_value ())
(unsafe_put_fields previmplbuf_container :referenced_value ())
(let ( (curloc (get_field :obi_loc curbody))
)
(if curloc
(output_location curloc chunkbuf 1 "initchunk"))
)
(output_c_code curbody declbuf chunkbuf 1)
(add2sbuf_indentnl chunkbuf 1)
(cond ( (>i (strbuf_usedlength chunkbuf) (/iraw (get_int !buffer_limit_cont) 2))
(shortbacktrace_dbg "outpucod_initialroutine huge chunkbuf" 10)
(debug "outpucod_initialroutine huge chunkbuf=" chunkbuf)
(assert_msg "check limited chunkbuf"
(<i (strbuf_usedlength chunkbuf) (get_int !buffer_limit_cont)))))
))
;; clear the previous location memoization
(unsafe_put_fields prevloc_container :referenced_value ())
(unsafe_put_fields previmplbuf_container :referenced_value ())
(let ( (chunktup (list_to_multiple chunkbuflist discr_multiple))
)
;; declare each chunk and call it notice that the name
;; frame_melt_start_this_module_st is constructed from name
;; melt_start_this_module which is built inside our MELT function
;; compile2obj_initproc.
(add2sbuf_indentnl declbuf 0)
(add2sbuf_strconst declbuf "struct frame_melt_start_this_module_st;")
(foreach_in_multiple
(chunktup)
(curchunk :long chunkix)
(add2sbuf_indentnl declbuf 0)
(add2sbuf_strconst declbuf "void MELT_MODULE_VISIBILITY meltmod__")
(add2sbuf_cident declbuf omodnam)
(add2sbuf_strconst declbuf "__initialmeltchunk_")
(add2sbuf_longdec declbuf chunkix)
(add2sbuf_strconst declbuf " (struct frame_melt_start_this_module_st*, char*);")
(add2sbuf_indentnl implbuf 1)
(add2sbuf_strconst implbuf "meltmod__")
(add2sbuf_cident implbuf omodnam)
(add2sbuf_strconst implbuf "__initialmeltchunk_")
(add2sbuf_longdec implbuf chunkix)
(add2sbuf_strconst implbuf " (&meltfram__, meltpredefinited);")
)
(add2sbuf_indentnl declbuf 0)
;;; end of implementation
;;;
(add2sbuf_strconst implbuf ";")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf " goto labend_rout;")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "labend_rout:;")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf " melt_topframe = (struct melt_callframe_st *) meltfram__.mcfr_prev;")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "/* popped initial frame */")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "{ /* clear initial frame & return */")
(add2sbuf_strconst implbuf " melt_ptr_t retval = ")
(if oretval
(output_c_code oretval declbuf implbuf 1)
(add2sbuf_strconst implbuf "/*noretval*/ NULL"))
(add2sbuf_strconst implbuf ";")
(add2sbuf_indentnl implbuf 1)
(add2sbuf_strconst implbuf " memset((void*) &meltfram__, 0, sizeof(meltfram__));")
(add2sbuf_indentnl implbuf 1)
(add2sbuf_strconst implbuf " return retval;}")
(add2sbuf_indentnl implbuf 1)
(add2sbuf_strconst implbuf "#undef meltcallcount")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "#undef meltfram__")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "#undef MELTFRAM_NBVARNUM")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "#undef MELTFRAM_NBVARPTR")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "} /* end */")
(add2sbuf_indentnl implbuf 0)
;; output the implementation of each chunk
(foreach_in_multiple
(chunktup)
(curchunk :long chunkix)
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "void meltmod__")
(add2sbuf_cident implbuf omodnam)
(add2sbuf_strconst implbuf "__initialmeltchunk_")
(add2sbuf_longdec implbuf chunkix)
(add2sbuf_strconst implbuf " (struct frame_melt_start_this_module_st* meltmeltframptr__, char meltpredefinited[]) {")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "#define meltfram__ (*meltmeltframptr__)")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "#undef meltcallcount")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "#define meltcallcount 0L")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "(void) meltpredefinited;")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_sbuf implbuf curchunk)
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "#undef meltfram__")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "} /*end of meltmod__")
(add2sbuf_cident implbuf omodnam)
(add2sbuf_strconst implbuf "__initialmeltchunk_")
(add2sbuf_longdec implbuf chunkix)
(add2sbuf_strconst implbuf "*/")
(add2sbuf_indentnl implbuf 0)
;;
(cond ( (>i (strbuf_usedlength implbuf) (/iraw (get_int !buffer_limit_cont) 2))
(shortbacktrace_dbg "outpucod_initialroutine huge implbuf" 10)
(debug "outpucod_initialroutine huge implbuf=" implbuf)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))))
)
)
)
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst declbuf "void MELT_MODULE_VISIBILITY meltmod__")
(add2sbuf_cident declbuf omodnam)
(add2sbuf_strconst declbuf "__forward_or_mark_module_start_frame (struct melt_callframe_st* fp, int marking);")
(add2sbuf_indentnl declbuf 0)
(add2sbuf_strconst implbuf "void meltmod__")
(add2sbuf_cident implbuf omodnam)
(add2sbuf_strconst implbuf "__forward_or_mark_module_start_frame (struct melt_callframe_st* fp, int marking)")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "{")
(add2sbuf_indentnl implbuf 1)
(add2sbuf_strconst implbuf "int ix=0;")
(add2sbuf_indentnl implbuf 1)
(add2sbuf_strconst implbuf "initial_frame_st* meltframptr_= (initial_frame_st*)fp;")
(add2sbuf_indentnl implbuf 1)
(add2sbuf_strconst implbuf " melt_assertmsg (\"check module frame\", meltframptr_->mcfr_nbvar == /*minihash*/ -")
(add2sbuf_longdec implbuf minihash)
(add2sbuf_strconst implbuf ");")
(add2sbuf_indentnl implbuf 0)
;; output the forwarding
(add2sbuf_strconst implbuf "if (!marking && melt_is_forwarding) {")
(add2sbuf_indentnl implbuf 1)
(add2sbuf_strconst implbuf "dbgprintf (\"forward_or_mark_module_start_frame_")
(add2sbuf_cident implbuf omodnam)
(add2sbuf_strconst implbuf " forwarding %d pointers in frame %p\", ")
(add2sbuf_longdec implbuf nbval)
(add2sbuf_strconst implbuf ", (void*) meltframptr_);")
(add2sbuf_indentnl implbuf 1)
(add2sbuf_strconst implbuf "for (ix = 0; ix < ")
(add2sbuf_longdec implbuf nbval)
(add2sbuf_strconst implbuf "; ix++) MELT_FORWARDED(meltframptr_->mcfr_varptr[ix]);")
(add2sbuf_indentnl implbuf 1)
(add2sbuf_strconst implbuf " return;")
(add2sbuf_indentnl implbuf 1)
(add2sbuf_strconst implbuf "} /*end forwarding*/")
(add2sbuf_indentnl implbuf 0)
;; output the marking
(add2sbuf_strconst implbuf "dbgprintf (\"forward_or_mark_module_start_frame_")
(add2sbuf_cident implbuf omodnam)
(add2sbuf_strconst implbuf " marking in frame %p\", (void*) meltframptr_);")
(add2sbuf_indentnl implbuf 0)
(outpucod_marker pini implbuf)
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "} /* end meltmod__")
(add2sbuf_cident implbuf omodnam)
(add2sbuf_strconst implbuf "__forward_or_mark_module_start_frame */")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_indentnl implbuf 0)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
(assert_msg "check limited declbuf"
(<i (strbuf_usedlength declbuf) (get_int !buffer_limit_cont)))
))
(install_method class_initial_module_routineobj output_c_code outpucod_initialmoduleroutine)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; output extension initial routine
(defun outpucod_initialextensionroutine (pini declbuf implbuf :long depth)
(assert_msg "check pini" (is_a pini class_initial_extension_routineobj))
(debug "outpucod_initialextensionroutine start pini=" pini
"\n of discrim " (discrim pini))
(shortbacktrace_dbg "outpucod_initialextensionroutine" 20)
(let (
(oname (get_field :named_name pini))
(odatup (get_field :oirout_data pini))
(orfill (get_field :oirout_fill pini))
(oprolog (get_field :oirout_prolog pini))
(omodnam (unsafe_get_field :oirout_modulename pini))
(obody (get_field :obrout_body pini))
(onbval (get_field :obrout_nbval pini))
(:long nbval (get_int onbval))
(:long minihash (+i 1 (%iraw (obj_hash pini) 4096)))
(oretval (get_field :obrout_retval pini))
)
(add2sbuf_indentnl declbuf 0)
(add2sbuf_indentnl declbuf 0)
(add2out
declbuf
##{ /** declare initial extension running routine $ONAME
* of $OMODNAM [outpucod_initialextensionroutine] **/
MELT_EXTERN melt_ptr_t $ONAME (melt_ptr_t meltarg_curenv_p, meltarg_tuplitval_p) ;
struct meltextend_$OMODNAM#_initial_frame_st ;
void MELT_MODULE_VISIBILITY
meltrun_$OMODNAM#_mark_or_forward (struct meltextend_$OMODNAM#_initial_frame_st*, int) ;
#ifdef MELT_HAVE_DEBUG
MELT_EXTERN const char meltextend_$OMODNAM#_have_debug_enabled[] ;
#define melt_have_debug_string meltextend_$OMODNAM#_have_debug_enabled
#else
MELT_EXTERN const char meltextend_$OMODNAM#_have_debug_disabled[] ;
#define melt_have_debug_string meltextend_$OMODNAM#_have_debug_disabled
#endif /* MELT_HAVE_DEBUG */
}#)
(add2sbuf_indentnl declbuf 0)
(add2out
implbuf
##{ /* implement extension running routine $ONAME
of $OMODNAM [outpucod_initialextensionroutine] **/
#ifdef MELT_HAVE_DEBUG
const char meltextend_$OMODNAM#_have_debug_enabled[]
= "MELT running extension $OMODNAM has debug enabled" ;
#else
const char meltextend_$OMODNAM#_have_debug_disabled[]
= "MELT running extension $OMODNAM has debug disabled" ;
#endif /* MELT_HAVE_DEBUG */
}#)
(add2sbuf_indentnl implbuf 0)
(add2sbuf_indentnl implbuf 0)
(add2out implbuf ##{
/** implement initial extension routine $ONAME
* of $OMODNAM [outpucod_initialextensionroutine] **/
melt_ptr_t $ONAME (melt_ptr_t meltarg_curenv_p, meltarg_tuplitval_p) {}#)
(add2sbuf_strconst implbuf "/* extension routine frame */ typedef ")
(output_curframe_declstruct pini implbuf)
(add2out implbuf ##{meltrun_$OMODNAM#_initial_frame_st ;}#
)
(add2sbuf_indentnl implbuf 1)
(output_curframe_cdat_struct odatup implbuf)
(add2sbuf_strconst implbuf " *cdat = NULL;")
(add2sbuf_indentnl implbuf 1)
;; generate the initial frame declaration
(add2out declbuf ##{ /* extension $OMODNAM initial frame */}#)
(add2sbuf_indentnl implbuf 1)
(output_curframe_declstruct_init
(lambda (rou dsbuf)
(add2sbuf_indentnl dsbuf 0)
(add2out dsbuf ##{ meltrun_$OMODNAM#_initial_frame_st}#))
pini declbuf)
;; generate the prologue
(debug "outpucod_initialextensionroutine oprolog=" oprolog)
(add2sbuf_indentnl implbuf 1)
(add2out implbuf ##{ /* extension $OMODNAM prologue */}#)
(foreach_in_list
(oprolog)
(curpair curprol)
(when (and curprol (not (is_a curprol class_objpurevalue)))
(add2sbuf_indentnl implbuf 1)
(output_c_code curprol declbuf implbuf 1)))
;; generate the fill of the cdata
(add2sbuf_indentnl implbuf 1)
(add2out implbuf ##{ /* extension $OMODNAM cdata fill */}#)
(output_curframe_cdat_fill odatup implbuf)
;; generate the body
(debug "outpucod_initialextensionroutine obody=" obody)
(add2sbuf_indentnl implbuf 1)
(let ( (bodtup
(cond
((is_list obody) (list_to_multiple obody discr_multiple))
((is_multiple obody) obody)
(:else
(assert_msg "unexpected body"))))
(:long nbbody (multiple_length bodtup))
)
(debug "outpucod_initialextensionroutine bodtup=" bodtup)
(add2out implbuf ##{ /* extension $OMODNAM body of $NBBODY instructions */}#)
(foreach_in_multiple
(bodtup)
(curbody :long bodix)
(debug "outpucod_initialextensionroutine curbody=" curbody)
(when (and curbody (not (is_a curbody class_objpurevalue)))
(add2sbuf_indentnl implbuf 1)
(add2out implbuf ##{ /*sideffecting $OMODNAM extension body #$BODIX */}#)
(let ( (curloc (get_field :obi_loc curbody))
)
(if curloc
(output_location curloc implbuf 1 "curbody")))
(output_c_code curbody declbuf implbuf 1)
)
)
(add2sbuf_indentnl implbuf 1)
(add2out implbuf ##{ /* ending run extension $OMODNAM */}#)
(add2out implbuf ##{
#error run extension $OMODNAM is incomplete
} /* end $ONAME */}#)
(compile_warning "outpucod_initialextensionroutine is incomplete since generating incomplete code")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_indentnl implbuf 0)
)))
(install_method class_initial_extension_routineobj output_c_code outpucod_initialextensionroutine)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; output code for argument getter
(defun outpucod_getarg (garg declbuf implbuf :long depth)
(assert_msg "check garg" (is_a garg class_objgetarg))
(let ( (oloc (unsafe_get_field :obarg_obloc garg))
(nloc (unsafe_get_field :obi_loc garg))
(obind (unsafe_get_field :obarg_bind garg))
(:long rkbind (get_int obind))
(ctybind (unsafe_get_field :fbind_type obind))
)
(assert_msg "check obind" (is_a obind class_formal_binding))
(output_location nloc implbuf depth "getarg")
(assert_msg "check oloc" (is_a oloc class_objlocv))
(assert_msg "check ctybind" (is_a ctybind class_ctype))
(if (==i rkbind 0)
(progn
(assert_msg "check ctybind first" (== ctybind ctype_value))
(output_c_code oloc declbuf implbuf depth)
(add2sbuf_strconst implbuf " = (melt_ptr_t) meltfirstargp_;")
(add2sbuf_indentnl implbuf depth)
)
(let (
;; use the ctype_parchar ctype_argfield
(parc (unsafe_get_field :ctype_parchar ctybind))
(argf (unsafe_get_field :ctype_argfield ctybind))
)
(if (not (is_string parc))
(error_strv oloc "impossible argument ctype"
(unsafe_get_field :named_name ctybind)))
(add2sbuf_strconst implbuf "if (meltxargdescr_[")
(add2sbuf_longdec implbuf (-i rkbind 1))
(add2sbuf_strconst implbuf "] != ")
(add2sbuf_string implbuf parc)
(add2sbuf_strconst implbuf ") goto lab_endgetargs;")
(add2sbuf_indentnl implbuf depth)
(if (== ctybind ctype_value)
(progn
(output_c_code oloc declbuf implbuf depth)
(add2sbuf_strconst implbuf " = (meltxargtab_[")
(add2sbuf_longdec implbuf (-i rkbind 1))
(add2sbuf_strconst implbuf "].meltbp_aptr) ? (*(meltxargtab_[")
(add2sbuf_longdec implbuf (-i rkbind 1))
(add2sbuf_strconst implbuf "].meltbp_aptr)) : NULL;")
(add2sbuf_indentnl implbuf depth)
(add2sbuf_strconst implbuf "gcc_assert(melt_discr((melt_ptr_t)(")
(output_c_code oloc declbuf implbuf depth)
(add2sbuf_strconst implbuf ")) != NULL);")
(add2sbuf_indentnl implbuf depth)
)
(progn
(output_c_code oloc declbuf implbuf depth)
(add2sbuf_strconst implbuf " = meltxargtab_[")
(add2sbuf_longdec implbuf (-i rkbind 1))
(add2sbuf_strconst implbuf "].")
(add2sbuf_string implbuf argf)
(add2sbuf_strconst implbuf ";")
)
)
(add2sbuf_indentnl implbuf depth)
))
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
))
(install_method class_objgetarg output_c_code outpucod_getarg)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; output code for argument getter
(defun outpucod_getargrest (garg declbuf implbuf :long depth)
(assert_msg "check garg" (is_a garg class_objgetargrest))
(let ( (oloc (unsafe_get_field :obarg_obloc garg))
(nloc (unsafe_get_field :obi_loc garg))
(obind (unsafe_get_field :obarg_bind garg))
(orest (get_field :obarg_rest garg))
(:long rkbind (get_int obind))
(ctybind (unsafe_get_field :fbind_type obind))
(ovariadicindex (variadic_index_idstr orest))
(ovariadiclength (variadic_length_idstr orest))
)
(assert_msg "check obind" (is_a obind class_formal_binding))
(output_location nloc implbuf depth "getarg")
(assert_msg "check oloc" (is_a oloc class_objlocv))
(assert_msg "check ctybind" (is_a ctybind class_ctype))
(if (==i rkbind 0)
(progn
(assert_msg "check ctybind first" (== ctybind ctype_value))
(output_c_code oloc declbuf implbuf depth)
(add2sbuf_strconst implbuf " = (melt_ptr_t) meltfirstargp_;")
(add2sbuf_indentnl implbuf depth)
)
(let (
;; use the ctype_parchar ctype_argfield
(parc (unsafe_get_field :ctype_parchar ctybind))
(argf (unsafe_get_field :ctype_argfield ctybind))
)
(if (not (is_string parc))
(error_strv oloc "impossible argument ctype"
(unsafe_get_field :named_name ctybind)))
(add2sbuf_strconst implbuf "if (meltxargdescr_[")
(add2sbuf_longdec implbuf (-i rkbind 1))
(add2sbuf_strconst implbuf "] != ")
(add2sbuf_string implbuf parc)
(add2sbuf_strconst implbuf ") { /*getargrest*/")
(add2sbuf_indentnl implbuf (+i 1 depth))
(add2sbuf_string implbuf ovariadicindex)
(add2sbuf_strconst implbuf " = ")
(add2sbuf_string implbuf ovariadiclength)
(add2sbuf_strconst implbuf ";")
(add2sbuf_indentnl implbuf (+i 1 depth))
(add2sbuf_strconst implbuf "goto lab_endgetargs;")
(add2sbuf_indentnl implbuf depth)
(add2sbuf_strconst implbuf "}")
(add2sbuf_indentnl implbuf depth)
(add2sbuf_string implbuf ovariadicindex)
(add2sbuf_strconst implbuf " = ")
(add2sbuf_longdec implbuf rkbind)
(add2sbuf_strconst implbuf ";")
(add2sbuf_indentnl implbuf depth)
(if (== ctybind ctype_value)
(progn
(output_c_code oloc declbuf implbuf depth)
(add2sbuf_strconst implbuf " = (meltxargtab_[")
(add2sbuf_longdec implbuf (-i rkbind 1))
(add2sbuf_strconst implbuf "].meltbp_aptr) ? (*(meltxargtab_[")
(add2sbuf_longdec implbuf (-i rkbind 1))
(add2sbuf_strconst implbuf "].meltbp_aptr)) : NULL;")
(add2sbuf_indentnl implbuf depth)
(add2sbuf_strconst implbuf "gcc_assert(melt_discr((melt_ptr_t)(")
(output_c_code oloc declbuf implbuf depth)
(add2sbuf_strconst implbuf ")) != NULL);")
(add2sbuf_indentnl implbuf depth)
)
(progn
(output_c_code oloc declbuf implbuf depth)
(add2sbuf_strconst implbuf " = meltxargtab_[")
(add2sbuf_longdec implbuf (-i rkbind 1))
(add2sbuf_strconst implbuf "].")
(add2sbuf_string implbuf argf)
(add2sbuf_strconst implbuf ";")
)
)
(add2sbuf_indentnl implbuf depth)
))
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
))
(install_method class_objgetargrest output_c_code outpucod_getargrest)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; output code for objlocv
(defun outpucod_objlocv (locv declbuf implbuf :long depth)
(assert_msg "check locv" (is_a locv class_objlocv))
(let (
(ltyp (unsafe_get_field :obv_type locv))
(loff (unsafe_get_field :obl_off locv))
(lcnam (unsafe_get_field :obl_cname locv))
)
(cond
( (== ltyp ctype_value)
(add2sbuf_strconst implbuf "/*_.")
(add2sbuf_string implbuf lcnam)
(add2sbuf_strconst implbuf "*/ meltfptr[")
(add2sbuf_longdec implbuf (get_int loff))
(add2sbuf_strconst implbuf "]") )
( (== ltyp ctype_long)
(add2sbuf_strconst implbuf "/*_#")
(add2sbuf_string implbuf lcnam)
(add2sbuf_strconst implbuf "*/ meltfnum[")
(add2sbuf_longdec implbuf (get_int loff))
(add2sbuf_strconst implbuf "]") )
(:else
(add2sbuf_strconst implbuf "/*_?*/ meltfram__.")
(add2sbuf_string implbuf lcnam)))
)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
)
(install_method class_objlocv output_c_code outpucod_objlocv)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; output code for object closed occurrence
(defun outpucod_objcloccv (occv declbuf implbuf :long depth)
(assert_msg "check occv" (is_a occv class_objcloccv))
(let ( (ooff (unsafe_get_field :obc_off occv))
(onam (unsafe_get_field :obc_name occv)) )
(assert_msg "check valueness of closed occurrence"
(== (unsafe_get_field :obv_type occv) ctype_value))
(add2sbuf_strconst implbuf "(/*~")
(add2sbuf_string implbuf onam)
(add2sbuf_strconst implbuf "*/ meltfclos->tabval[")
(add2sbuf_longdec implbuf (get_int ooff))
(add2sbuf_strconst implbuf "])")
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
))
(install_method class_objcloccv output_c_code outpucod_objcloccv)
;;;;;;;;;;;;;;;;
;; output code for object const [closed] occurrence
(defun outpucod_objconstv (ocnstv declbuf implbuf :long depth)
(assert_msg "check ocnstv" (is_a ocnstv class_objconstv))
(let ( (ooff (unsafe_get_field :obc_off ocnstv))
(onam (unsafe_get_field :obc_name ocnstv)) )
(assert_msg "check valueness of const occurrence"
(== (unsafe_get_field :obv_type ocnstv) ctype_value))
(add2sbuf_strconst implbuf "(/*!")
(add2sbuf_string implbuf onam)
;; was for debug
(add2sbuf_strconst implbuf "*/ meltfrout->tabval[")
(add2sbuf_longdec implbuf (get_int ooff))
(add2sbuf_strconst implbuf "])")
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
))
(install_method class_objconstv output_c_code outpucod_objconstv)
;; output the code of an instructions list, skipping any pure value
(defun output_code_instructions_list (lis declbuf implbuf boxeddepth)
(assert_msg "check lis" (is_list_or_null lis))
(assert_msg "check boxeddepth" (is_integerbox boxeddepth))
(let ( (:long depth (get_int boxeddepth)) )
(add2sbuf_indentnl implbuf depth)
(foreach_in_list
(lis)
(pair cur)
(cond
( (is_a cur class_objplainblock)
(add2sbuf_indentnl implbuf depth)
(let ( (bloc (unsafe_get_field :obi_loc cur))
(bodyl (unsafe_get_field :oblo_bodyl cur))
(epil (unsafe_get_field :oblo_epil cur))
)
(if bloc (output_location bloc implbuf depth "quasiblock"))
(if bodyl (output_code_instructions_list bodyl declbuf implbuf boxeddepth))
(if epil (output_code_instructions_list epil declbuf implbuf boxeddepth))
)
)
( (and cur (is_not_a cur class_objpurevalue))
(add2sbuf_indentnl implbuf depth)
(output_c_code cur declbuf implbuf depth)
(add2sbuf_strconst implbuf ";"))
) ;end cond
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
(assert_msg "check limited declbuf"
(<i (strbuf_usedlength declbuf) (get_int !buffer_limit_cont)))
))
)
;;;;;;;;;;;;;;;;
(defun outpucod_objchecksignal (obchi declbuf implbuf :long depth)
(assert_msg "check ochi" (is_a obchi class_objchecksignal))
(let ( (oloc (unsafe_get_field :obi_loc obchi))
)
(if oloc (output_location oloc implbuf depth "checksignal"))
(add2out implbuf " MELT_CHECK_SIGNAL();")
(add2sbuf_indentnl implbuf depth)
))
(install_method class_objchecksignal output_c_code outpucod_objchecksignal)
;; output code for objanyblock
(defun outpucod_objanyblock (oblo declbuf implbuf :long depth)
(assert_msg "check oblo" (is_a oblo class_objanyblock))
(output_location (unsafe_get_field :obi_loc oblo) implbuf depth "block")
(let ( (bodyl (unsafe_get_field :oblo_bodyl oblo))
(epil (unsafe_get_field :oblo_epil oblo))
(boxdepthp1 (make_integerbox discr_integer (+i depth 1)))
)
(add2sbuf_strconst implbuf "/*anyblock*/{")
(if (is_list bodyl)
(output_code_instructions_list bodyl declbuf implbuf boxdepthp1))
(if (is_list epil)
(progn
(add2sbuf_indentnl implbuf (get_int boxdepthp1))
(add2sbuf_strconst implbuf "/*epilog*/")
(output_code_instructions_list epil declbuf implbuf boxdepthp1)))
(add2sbuf_strconst implbuf "}")
(add2sbuf_indentnl implbuf depth)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
)
)
(install_method class_objanyblock output_c_code outpucod_objanyblock)
;; output code for objmultiallocblock
(defun outpucod_objmultiallocblock (oblo declbuf implbuf :long depth)
(assert_msg "check oblo" (is_a oblo class_objmultiallocblock))
(let ( (oloc (unsafe_get_field :obi_loc oblo))
(oallstruct (unsafe_get_field :omalblo_allstruct oblo))
(oname (unsafe_get_field :omalblo_name oblo))
(epil (unsafe_get_field :oblo_epil oblo))
(bodyl (unsafe_get_field :oblo_bodyl oblo))
(:long depthp1 (+i depth 1))
(boxdepthp1 (make_integerbox discr_integer depthp1))
(onameptr (let ( (ptrbuf (make_strbuf discr_strbuf)) )
(add2sbuf_string ptrbuf oname)
(add2sbuf_strconst ptrbuf "_ptr")
(strbuf2string discr_verbatim_string ptrbuf)))
)
(output_location oloc implbuf depth "blockmultialloc")
(assert_msg "check oallstruct" (is_multiple_or_null oallstruct))
(add2sbuf_strconst implbuf "/*multiallocblock*/{")
(add2sbuf_indentnl implbuf depthp1)
(add2sbuf_strconst implbuf "struct ")
(add2sbuf_string implbuf oname)
(add2sbuf_strconst implbuf "_st {")
(foreach_in_multiple
(oallstruct)
(curstru :long strix)
(assert_msg "check curstru" (is_a curstru class_objinitelem))
(add2sbuf_indentnl implbuf depthp1)
(output_c_declinit curstru implbuf)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
)
(add2sbuf_strconst implbuf " long ")
(add2sbuf_string implbuf oname)
(add2sbuf_strconst implbuf "_endgap; } *")
(add2sbuf_string implbuf oname)
(add2sbuf_strconst implbuf "_ptr = 0;")
(add2sbuf_indentnl implbuf depthp1)
(add2sbuf_string implbuf oname)
(add2sbuf_strconst implbuf "_ptr = (struct ")
(add2sbuf_string implbuf oname)
(add2sbuf_strconst implbuf "_st *) meltgc_allocate (sizeof (struct ")
(add2sbuf_string implbuf oname)
(add2sbuf_strconst implbuf "_st), 0);")
(add2sbuf_indentnl implbuf depthp1)
;;
(output_location oloc implbuf depth "blockmultialloc.initfill")
(foreach_in_multiple
(oallstruct)
(curstru :long strix)
(output_c_initial_fill curstru implbuf onameptr depthp1)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
(add2sbuf_indentnl implbuf depthp1)
)
;;
(if (is_list bodyl)
(output_code_instructions_list bodyl declbuf implbuf boxdepthp1))
;;
(if (is_list epil)
(progn
(add2sbuf_indentnl implbuf (get_int boxdepthp1))
(add2sbuf_strconst implbuf "/*epilog*/")
(output_code_instructions_list epil declbuf implbuf boxdepthp1)))
;(assert_msg "@$@unimplemented outpucod_objmultiallocblock" ())
(add2sbuf_strconst implbuf "} /*end multiallocblock*/")
(add2sbuf_indentnl implbuf depth)
)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
)
(install_method class_objmultiallocblock output_c_code outpucod_objmultiallocblock)
;; output code for objciterblock
(defun outpucod_objciterblock (obcit declbuf implbuf :long depth)
(assert_msg "check obcit" (is_a obcit class_objciterblock))
(let ( (oloc (unsafe_get_field :obi_loc obcit))
(bodyl (unsafe_get_field :oblo_bodyl obcit))
(epil (unsafe_get_field :oblo_epil obcit))
(boxdepthp1 (make_integerbox discr_integer (+i depth 1)))
(obefore (unsafe_get_field :obciter_before obcit))
(oafter (unsafe_get_field :obciter_after obcit))
(citer (unsafe_get_field :obciter_citer obcit))
)
(assert_msg "check citer" (is_a citer class_citerator))
(output_location oloc "citerblock")
(add2sbuf_strconst implbuf "/*citerblock ")
(add2sbuf_ccomstring implbuf (unsafe_get_field :named_name citer))
(add2sbuf_strconst implbuf "*/ {")
(add2sbuf_indentnl implbuf depth)
(output_location oloc "citerbefore")
(foreach_in_multiple
(obefore)
(obef :long ix)
(output_c_code obef declbuf implbuf (get_int boxdepthp1))
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
)
(add2sbuf_indentnl implbuf depth)
(output_location oloc "citerbody")
(if (is_list bodyl)
(output_code_instructions_list bodyl declbuf implbuf boxdepthp1))
(add2sbuf_indentnl implbuf depth)
(output_location oloc "citerafter")
(foreach_in_multiple
(oafter)
(oaft :long ix)
(output_c_code oaft declbuf implbuf (get_int boxdepthp1))
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
)
(add2sbuf_indentnl implbuf depth)
(output_location oloc "citerepil")
(if (is_list epil)
(progn
(add2sbuf_indentnl implbuf (get_int boxdepthp1))
(add2sbuf_strconst implbuf "/*citerepilog*/")
(output_code_instructions_list epil declbuf implbuf boxdepthp1)))
(add2sbuf_strconst implbuf "} /*endciterblock ")
(add2sbuf_ccomstring implbuf (unsafe_get_field :named_name citer))
(add2sbuf_strconst implbuf "*/")
(add2sbuf_indentnl implbuf depth)
)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
)
(install_method class_objciterblock output_c_code outpucod_objciterblock)
;;;;;;;;;;;;;;;;
(defun outpucod_objcommentinstr (obci declbuf implbuf :long depth)
(assert_msg "check obci" (is_a obci class_objcommentinstr))
(let ( (oloc (unsafe_get_field :obi_loc obci))
(coms (unsafe_get_field :obci_comment obci))
(comstr (let ( (sbu (make_strbuf discr_strbuf)) )
(add2sbuf_ccomstring sbu coms)
(strbuf2string discr_string sbu)
))
)
(output_location oloc implbuf depth "comment")
(add2sbuf_strconst implbuf "/**COMMENT: ")
(add2sbuf_string implbuf comstr)
(add2sbuf_strconst implbuf " **/;")
(add2sbuf_indentnl implbuf depth)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
))
(install_method class_objcommentinstr output_c_code outpucod_objcommentinstr)
;;;;;;;;;;;;;;;;
;; output code for objcommentedblock
(defun outpucod_objcommentedblock (oblo declbuf implbuf :long depth)
(assert_msg "check oblo" (is_a oblo class_objcommentedblock))
(output_location (unsafe_get_field :obi_loc oblo) implbuf depth "block")
(let ( (bodyl (unsafe_get_field :oblo_bodyl oblo))
(epil (unsafe_get_field :oblo_epil oblo))
(boxdepthp1 (make_integerbox discr_integer (+i depth 1)))
(coms (unsafe_get_field :ocomblo_comment oblo))
(comstr (let ( (sbu (make_strbuf discr_strbuf)) )
(add2sbuf_ccomstring sbu coms)
(strbuf2string discr_string sbu)
))
)
(add2sbuf_strconst implbuf "/*com.block:")
(add2sbuf_string implbuf comstr)
(add2sbuf_strconst implbuf "*/{")
(if (is_list bodyl)
(output_code_instructions_list bodyl declbuf implbuf boxdepthp1))
(if (is_list epil)
(progn
(add2sbuf_indentnl implbuf (get_int boxdepthp1))
(add2sbuf_strconst implbuf "/*comp.epilog:")
(add2sbuf_string implbuf comstr)
(add2sbuf_strconst implbuf "*/")
(output_code_instructions_list epil declbuf implbuf boxdepthp1)))
(add2sbuf_strconst implbuf "}")
(add2sbuf_strconst implbuf "/*com.end block:")
(add2sbuf_string implbuf comstr)
(add2sbuf_strconst implbuf "*/")
(add2sbuf_indentnl implbuf depth)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
)
)
(install_method class_objcommentedblock output_c_code outpucod_objcommentedblock)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; output code for label instr
(defun outpucod_objlabelinstr (oblab declbuf implbuf :long depth)
(assert_msg "check oblab" (is_a oblab class_objlabelinstr))
(add2sbuf_indentnl implbuf depth)
(add2sbuf_strconst implbuf "/*objlabel*/ ")
(add2sbuf_string implbuf (unsafe_get_field :oblab_prefix oblab))
(let ( (obrank (unsafe_get_field :oblab_rank oblab)) )
(if obrank
(add2sbuf_longdec implbuf (get_int (unsafe_get_field :oblab_rank oblab)))))
(add2sbuf_strconst implbuf ": ;")
(add2sbuf_indentnl implbuf depth)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
(output_location (unsafe_get_field :obi_loc oblab) implbuf depth "objlabel")
)
(install_method class_objlabelinstr output_c_code outpucod_objlabelinstr)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; output code for goto instr
(defun outpucod_objgotoinstr (obgoto declbuf implbuf :long depth)
(assert_msg "check obgoto" (is_a obgoto class_objgotoinstr))
(output_location (unsafe_get_field :obi_loc obgoto) implbuf depth "objgoto")
(add2sbuf_strconst implbuf "/*objgoto*/ goto ")
(add2sbuf_string implbuf (unsafe_get_field :obgoto_prefix obgoto))
(let ( (obrank (unsafe_get_field :obgoto_rank obgoto)) )
(if obrank
(add2sbuf_longdec implbuf (get_int obrank))))
(add2sbuf_strconst implbuf ";")
(add2sbuf_indentnl implbuf depth)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
)
(install_method class_objgotoinstr output_c_code outpucod_objgotoinstr)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; add a cname for a cloned identifier into a buffer
(defun add2sbuf_clonsym (sbuf csy)
(assert_msg "check sbuf" (is_strbuf sbuf))
(assert_msg "check csy" (is_a csy class_cloned_symbol))
(let ( (cnam (unsafe_get_field :named_name csy))
(:long rk (get_int (unsafe_get_field :csym_urank csy))) )
(add2sbuf_cident sbuf cnam)
(add2sbuf_strconst sbuf "_")
(add2sbuf_longdec sbuf rk)
(assert_msg "check limited sbuf"
(<i (strbuf_usedlength sbuf) (get_int !buffer_limit_cont)))
))
;;; output code for objloop
(defun outpucod_objloop (oblo declbuf implbuf :long depth)
(assert_msg "check oblo" (is_a oblo class_objloop))
(let ( (bodyl (unsafe_get_field :oblo_bodyl oblo))
(epil (unsafe_get_field :oblo_epil oblo))
(lab (unsafe_get_field :obloop_label oblo))
(oloc (unsafe_get_field :obi_loc oblo))
(boxdepthp1 (make_integerbox discr_integer (+i depth 1)))
)
(assert_msg "check lab" (is_a lab class_cloned_symbol))
(output_location oloc implbuf depth "loop")
(add2sbuf_strconst implbuf "/*loop*/{ labloop_")
(add2sbuf_clonsym implbuf lab)
(add2sbuf_strconst implbuf ":;")
(if (is_list bodyl)
(progn
(output_location oloc implbuf depth "loopbody")
(add2sbuf_indentnl implbuf (+i depth 1))
(list_every
bodyl
(lambda (curbody)
(let ( (:long depthp1 (get_int boxdepthp1)) )
(if (and curbody (not (is_a curbody class_objpurevalue)))
(output_c_code curbody declbuf implbuf depthp1))
(add2sbuf_strconst implbuf ";")
(add2sbuf_indentnl implbuf depthp1))))))
(add2sbuf_strconst implbuf ";")
(add2sbuf_indentnl implbuf (+i depth 1))
(add2sbuf_strconst implbuf " goto labloop_")
(add2sbuf_clonsym implbuf lab)
(add2sbuf_strconst implbuf ";")
(add2sbuf_indentnl implbuf (+i depth 1))
(add2sbuf_strconst implbuf " labexit_")
(add2sbuf_clonsym implbuf lab)
(add2sbuf_strconst implbuf ":;")
(if (is_list epil)
(progn
(output_location oloc implbuf depth "loopepilog")
(add2sbuf_strconst implbuf "/*loopepilog*/")
(add2sbuf_indentnl implbuf (+i depth 1))
(list_every
epil
(lambda (curepil)
(let ( (:long depthp1 (get_int boxdepthp1)) )
(if (and curepil (not (is_a curepil class_objpurevalue)))
(output_c_code curepil declbuf implbuf depthp1))
(add2sbuf_strconst implbuf ";")
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
(add2sbuf_indentnl implbuf depthp1))))))
(add2sbuf_strconst implbuf "}")
(add2sbuf_indentnl implbuf depth)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
)
)
(install_method class_objloop output_c_code outpucod_objloop)
;;; output code for objexit
(defun outpucod_objexit (obxi declbuf implbuf :long depth)
(assert_msg "check obxi" (is_a obxi class_objexit))
(let ( (olab (unsafe_get_field :obexit_label obxi))
(loc (unsafe_get_field :obi_loc obxi))
)
(assert_msg "check olab" (is_a olab class_cloned_symbol))
(output_location loc implbuf depth "exit")
(add2sbuf_strconst implbuf "/*exit*/{")
(add2sbuf_indentnl implbuf depth)
(add2sbuf_strconst implbuf " goto labexit_")
(add2sbuf_clonsym implbuf olab)
(add2sbuf_strconst implbuf ";}")
(add2sbuf_indentnl implbuf depth)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
))
(install_method class_objexit output_c_code outpucod_objexit)
;;; output code for objagain
(defun outpucod_objagain (obag declbuf implbuf :long depth)
(assert_msg "check obag" (is_a obag class_objagain))
(let ( (olab (unsafe_get_field :obagain_label obag))
(loc (unsafe_get_field :obi_loc obag))
)
(assert_msg "check olab" (is_a olab class_cloned_symbol))
(output_location loc implbuf depth "again")
(add2sbuf_strconst implbuf "/*again*/{")
(add2sbuf_indentnl implbuf depth)
(add2sbuf_strconst implbuf " goto labloop_")
(add2sbuf_clonsym implbuf olab)
(add2sbuf_strconst implbuf ";}")
(add2sbuf_indentnl implbuf depth)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
))
(install_method class_objagain output_c_code outpucod_objagain)
;;; output code for objcompute
(defun outpucod_objcompute (obcomp declbuf implbuf :long depth)
(assert_msg "check obcomp" (is_a obcomp class_objcompute))
(let ( (cdest (unsafe_get_field :obdi_destlist obcomp)) ; destination list
(cloc (unsafe_get_field :obi_loc obcomp))
(cexp (unsafe_get_field :obcpt_expr obcomp))
(boxdepthp1 (make_integerbox discr_integer (+i depth 1)))
)
(output_location cloc implbuf depth "compute")
(if (is_list cdest)
(list_every
cdest
(lambda (destcur)
(output_c_code destcur declbuf implbuf (get_int boxdepthp1))
(add2sbuf_strconst implbuf " = ")
())))
(cond ((is_list cexp)
(if (>i (list_length cexp) 2)
(add2sbuf_indentnl implbuf (+i 1 depth)))
(list_every
cexp
(lambda (expcur)
(output_c_code expcur declbuf implbuf (get_int boxdepthp1))
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
)))
((is_multiple cexp)
(if (>i (multiple_length cexp) 2)
(add2sbuf_indentnl implbuf (+i 1 depth)))
(multiple_every
cexp
(lambda (expcur)
(output_c_code expcur declbuf implbuf (get_int boxdepthp1))
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
)))
(:else
(output_c_code cexp declbuf implbuf (+i depth 1))
))
(add2sbuf_strconst implbuf ";")
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
))
(install_method class_objcompute output_c_code outpucod_objcompute)
;; output a conditional
(defun outpucod_objcond (ocond declbuf implbuf :long depth)
(assert_msg "check ocond" (is_a ocond class_objcond))
(let ( (cloc (unsafe_get_field :obi_loc ocond))
(ctest (unsafe_get_field :obcond_test ocond))
(cthen (unsafe_get_field :obcond_then ocond))
(celse (unsafe_get_field :obcond_else ocond))
)
(assert_msg "check ctest" (notnull ctest))
(output_location cloc implbuf depth "cond")
(add2sbuf_strconst implbuf "/*cond*/ if (")
(output_c_code ctest declbuf implbuf (+i depth 1))
(add2sbuf_strconst implbuf ") /*then*/ {")
(add2sbuf_indentnl implbuf depth)
(if (and cthen (not (is_a cthen class_objpurevalue)))
(progn
(output_location cloc implbuf depth "cond.then")
(output_c_code cthen declbuf implbuf (+i depth 1))
(add2sbuf_strconst implbuf ";")
(add2sbuf_indentnl implbuf depth)
)
)
(if (and celse (not (is_a celse class_objpurevalue)))
(progn
(add2sbuf_strconst implbuf "} else {")
(output_location cloc implbuf depth "cond.else")
(add2sbuf_indentnl implbuf (+i depth 1))
(output_c_code celse declbuf implbuf (+i depth 1))
(add2sbuf_strconst implbuf ";")
(add2sbuf_indentnl implbuf (+i depth 1))
(add2sbuf_strconst implbuf "}") ;
)
(add2sbuf_strconst implbuf "} /*noelse*/")
)
(add2sbuf_indentnl implbuf depth)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
)
)
(install_method class_objcond output_c_code outpucod_objcond)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; output a cppif
(defun outpucod_objcppif (opif declbuf implbuf :long depth)
(assert_msg "check opif" (is_a opif class_objcppif))
(let ( (cloc (unsafe_get_field :obi_loc opif))
(ccond (unsafe_get_field :obifp_cond opif))
(cthen (unsafe_get_field :obifp_then opif))
(celse (unsafe_get_field :obifp_else opif))
(:long depthp1 (+i 1 depth))
)
(assert_msg "check ccond" (is_string ccond))
(output_raw_location cloc implbuf depth "cppif")
(add2sbuf_strconst implbuf "#if ")
(add2sbuf_string implbuf ccond)
(add2sbuf_indentnl implbuf depthp1)
(output_location cloc implbuf depth "cppif.then")
(output_c_code cthen declbuf implbuf depthp1)
(add2sbuf_indentnl implbuf depthp1)
(add2sbuf_strconst implbuf "#else /*")
(add2sbuf_string implbuf ccond)
(add2sbuf_strconst implbuf "*/")
(add2sbuf_indentnl implbuf depthp1)
(output_location cloc implbuf depth "cppif.else")
(output_c_code celse declbuf implbuf depthp1)
(add2sbuf_indentnl implbuf depthp1)
(add2sbuf_strconst implbuf "#endif /*")
(add2sbuf_string implbuf ccond)
(add2sbuf_strconst implbuf "*/")
(add2sbuf_indentnl implbuf depthp1)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
))
(install_method class_objcppif output_c_code outpucod_objcppif)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun outpucod_objinternsymbol (oisy declbuf implbuf :long depth)
(assert_msg "check oisy" (is_a oisy class_objinternsymbol))
(let ( (cloc (unsafe_get_field :obi_loc oisy))
(oiobj (unsafe_get_field :obintern_iobj oisy))
(oidat (unsafe_get_field :oie_data oiobj))
(oilocv (unsafe_get_field :oie_locvar oiobj))
)
(assert_msg "check oiobj" (is_a oiobj class_objinitobject))
(assert_msg "check oidat" (is_a oidat class_nrep_datasymbol))
(let ( (nsy (unsafe_get_field :ndsy_namestr oidat)) )
(output_location (if cloc cloc (unsafe_get_field :nrep_loc oidat)) implbuf 1 "internsymbol")
(add2sbuf_strconst implbuf "/*internsym:")
(add2sbuf_string implbuf nsy)
(add2sbuf_strconst implbuf "*/")
(add2sbuf_indentnl implbuf depth)
(add2sbuf_strconst implbuf "(void) meltgc_intern_symbol((melt_ptr_t)(")
(output_c_code oilocv declbuf implbuf depth)
(add2sbuf_strconst implbuf "));")
(add2sbuf_indentnl implbuf depth))
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
))
(install_method class_objinternsymbol output_c_code outpucod_objinternsymbol)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun outpucod_objinternkeyword (oikw declbuf implbuf :long depth)
(assert_msg "check oikw" (is_a oikw class_objinternkeyword))
(let ( (cloc (unsafe_get_field :obi_loc oikw))
(oiobj (unsafe_get_field :obintern_iobj oikw))
(oidat (unsafe_get_field :oie_data oiobj))
(oilocv (unsafe_get_field :oie_locvar oiobj))
)
(assert_msg "check oidat" (is_a oidat class_nrep_datakeyword))
(let ( (nsy (unsafe_get_field :ndsy_namestr oidat)) )
(output_location (if cloc cloc (unsafe_get_field :nrep_loc oidat)) implbuf depth "internkeyword")
(add2sbuf_strconst implbuf "/*internkeyw:")
(add2sbuf_string implbuf nsy)
(add2sbuf_strconst implbuf "*/")
(add2sbuf_indentnl implbuf depth)
(add2sbuf_strconst implbuf "(void) meltgc_intern_keyword((melt_ptr_t)(")
(output_c_code oilocv declbuf implbuf depth)
(add2sbuf_strconst implbuf "));")
(add2sbuf_indentnl implbuf depth))
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
))
(install_method class_objinternkeyword output_c_code outpucod_objinternkeyword)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun outpucod_objgetnamedsymbol (ogsy declbuf implbuf :long depth)
(assert_msg "check ogsy" (is_a ogsy class_objgetnamedsymbol))
(let ( (cloc (unsafe_get_field :obi_loc ogsy))
(oiobj (unsafe_get_field :obgnamed_iobj ogsy))
(ogdat (unsafe_get_field :oie_data oiobj))
(oilocv (unsafe_get_field :oie_locvar oiobj))
)
(assert_msg "check oiobj" (is_a oiobj class_objinitobject))
(assert_msg "check ogdat" (is_a ogdat class_nrep_datasymbol))
(let ( (nsy (unsafe_get_field :ndsy_namestr ogdat))
)
(output_location (if cloc cloc (unsafe_get_field :nrep_loc ogdat)) implbuf depth "getnamedsymbol")
(add2sbuf_strconst implbuf "/*getnamedsym:")
(add2sbuf_string implbuf nsy)
(add2sbuf_strconst implbuf "*/")
(add2sbuf_indentnl implbuf depth)
(add2sbuf_strconst implbuf "{ melt_ptr_t sy_")
(add2sbuf_cident implbuf nsy)
(add2sbuf_strconst implbuf " = meltgc_named_symbol(\"")
(add2sbuf_string implbuf nsy)
(add2sbuf_strconst implbuf "\", MELT_GET);")
(add2sbuf_indentnl implbuf (+i depth 1))
(add2sbuf_strconst implbuf "if (sy_")
(add2sbuf_cident implbuf nsy)
(add2sbuf_strconst implbuf " && NULL == ")
(output_c_code oilocv declbuf implbuf (+i depth 1))
(add2sbuf_strconst implbuf ")")
(add2sbuf_indentnl implbuf (+i depth 1))
(output_c_code oilocv declbuf implbuf (+i depth 1))
(add2sbuf_strconst implbuf " = (melt_ptr_t) sy_")
(add2sbuf_cident implbuf nsy)
(add2sbuf_strconst implbuf "; }")
(add2sbuf_indentnl implbuf depth)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
)))
(install_method class_objgetnamedsymbol output_c_code outpucod_objgetnamedsymbol)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun outpucod_objgetnamedkeyword (ogkw declbuf implbuf :long depth)
(assert_msg "check ogkw" (is_a ogkw class_objgetnamedkeyword))
(let ( (cloc (unsafe_get_field :obi_loc ogkw))
(oiobj (unsafe_get_field :obgnamed_iobj ogkw))
(ogdat (unsafe_get_field :oie_data oiobj))
(oilocv (unsafe_get_field :oie_locvar oiobj))
)
(assert_msg "check oiobj" (is_a oiobj class_objinitobject))
(assert_msg "check ogdat" (is_a ogdat class_nrep_datakeyword))
(let ( (nkw (unsafe_get_field :ndsy_namestr ogdat)) )
(output_location (if cloc cloc (unsafe_get_field :nrep_loc ogdat)) implbuf depth "getnamedkeyword")
(add2sbuf_strconst implbuf "/*getnamedkeyw:")
(add2sbuf_string implbuf nkw)
(add2sbuf_strconst implbuf "*/")
(add2sbuf_indentnl implbuf depth)
(add2sbuf_strconst implbuf "{ melt_ptr_t kw_")
(add2sbuf_cident implbuf nkw)
(add2sbuf_strconst implbuf " = meltgc_named_keyword(\"")
(add2sbuf_string implbuf nkw)
(add2sbuf_strconst implbuf "\", MELT_GET);")
(add2sbuf_indentnl implbuf (+i depth 1))
(add2sbuf_strconst implbuf "if (kw_")
(add2sbuf_cident implbuf nkw)
(add2sbuf_strconst implbuf ") ")
(output_c_code oilocv declbuf implbuf (+i depth 1))
(add2sbuf_strconst implbuf " = (melt_ptr_t) kw_")
(add2sbuf_cident implbuf nkw)
(add2sbuf_strconst implbuf "; }")
(add2sbuf_indentnl implbuf depth)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
)))
(install_method class_objgetnamedkeyword output_c_code outpucod_objgetnamedkeyword)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; output an application
(defun outpucod_objapply (oapp declbuf implbuf :long depth)
(assert_msg "check oapp" (is_a oapp class_objapply))
(let (
(aloc (unsafe_get_field :obi_loc oapp))
(adest (unsafe_get_field :obdi_destlist oapp))
(oclos (unsafe_get_field :obapp_clos oapp))
(oargs (unsafe_get_field :obapp_args oapp))
(:long nbarg (multiple_length oargs))
(paramdesclist (make_list discr_list))
(boxdepthp1 (make_integerbox discr_integer (+i 1 depth)))
)
(output_location aloc implbuf depth "apply")
(add2sbuf_strconst implbuf "/*apply*/{")
(add2sbuf_indentnl implbuf (+i 1 depth))
(if (>i nbarg 1)
(progn
(add2sbuf_strconst implbuf "union meltparam_un argtab[")
(add2sbuf_longdec implbuf (-i nbarg 1))
(add2sbuf_strconst implbuf "];")
(add2sbuf_indentnl implbuf (+i 1 depth))
(add2sbuf_strconst implbuf "memset(&argtab, 0, sizeof(argtab));")
(add2sbuf_indentnl implbuf (+i 1 depth))
;; output the initialization of argtab and fill the paramdesclist
(foreach_in_multiple
(oargs)
(curarg :long curank)
(assert_msg "outputcod_objapply check curarg not objinstr" (not (is_a curarg class_objinstr)))
(if (>i curank 0)
(let ( (curctyp (get_ctype curarg ())) )
(assert_msg "check curctyp" (is_a curctyp class_ctype))
(output_location aloc implbuf (get_int boxdepthp1) "apply.arg")
(add2sbuf_strconst implbuf "argtab[")
(add2sbuf_longdec implbuf (-i curank 1))
(add2sbuf_strconst implbuf "].")
(list_append paramdesclist (unsafe_get_field :ctype_parstring curctyp))
(cond ( (null curarg)
(add2sbuf_strconst implbuf "meltbp_aptr = (melt_ptr_t*)NULL"))
( (is_a curarg class_objnil)
(add2sbuf_strconst implbuf "meltbp_aptr = /*nil*/(melt_ptr_t*)NULL"))
( (== curctyp ctype_value)
(add2sbuf_strconst implbuf "meltbp_aptr = (melt_ptr_t*) &")
(output_c_code curarg declbuf implbuf (get_int boxdepthp1))
)
(:else
(add2sbuf_string implbuf (unsafe_get_field :ctype_argfield curctyp))
(add2sbuf_strconst implbuf " = ")
(output_c_code curarg declbuf implbuf (get_int boxdepthp1))
))
(add2sbuf_strconst implbuf ";")
(add2sbuf_indentnl implbuf (get_int boxdepthp1))
))
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
)
))
;;; output the destination(s)
(list_every
adest
(lambda (curdest)
(output_c_code curdest declbuf implbuf (get_int boxdepthp1))
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
(add2sbuf_strconst implbuf " = ")))
;; output the apply and the closure
(add2sbuf_strconst implbuf " melt_apply ((meltclosure_ptr_t)(")
(output_c_code oclos declbuf implbuf (+i 1 depth))
(add2sbuf_strconst implbuf "), (melt_ptr_t)(")
;; output the first argument
(let ( (firstarg (multiple_nth oargs 0)) )
(output_c_code firstarg declbuf implbuf (+i 1 depth))
)
(add2sbuf_strconst implbuf "), (")
;; output the argdescr string
(list_every
paramdesclist
(lambda (pard)
(add2sbuf_string implbuf pard)
(add2sbuf_strconst implbuf " ")))
(add2sbuf_strconst implbuf "\"\"), ")
;; output the argtab (or null if none)
(if (>i nbarg 1)
(add2sbuf_strconst implbuf "argtab,")
(add2sbuf_strconst implbuf "(union meltparam_un*)0,"))
;; no extra results
(add2sbuf_strconst implbuf " \"\", (union meltparam_un*)0")
(add2sbuf_strconst implbuf ");")
(add2sbuf_indentnl implbuf (+i 1 depth))
(add2sbuf_strconst implbuf "}")
(add2sbuf_indentnl implbuf depth)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
)
)
(install_method class_objapply output_c_code outpucod_objapply)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; output a message send
(defun outpucod_objmsend (omsend declbuf implbuf :long depth)
(assert_msg "check omsend" (is_a omsend class_objmsend))
(let ( (oloc (unsafe_get_field :obi_loc omsend))
(odest (unsafe_get_field :obdi_destlist omsend))
(osel (unsafe_get_field :obmsnd_sel omsend))
(orecv (unsafe_get_field :obmsnd_recv omsend))
(oargs (unsafe_get_field :obmsnd_args omsend))
(:long nbarg (multiple_length oargs))
(paramdesclist (make_list discr_list))
(boxdepthp1 (make_integerbox discr_integer (+i 1 depth)))
)
(output_location oloc implbuf depth "msend")
(add2sbuf_strconst implbuf "/*msend*/{")
(add2sbuf_indentnl implbuf (+i 1 depth))
(if (>i nbarg 0)
;; the code below is very similar to code inside
;; outpucod_objapply except that we do not shift arguments by
;; one
(progn
(add2sbuf_strconst implbuf "union meltparam_un argtab[")
(add2sbuf_longdec implbuf nbarg)
(add2sbuf_strconst implbuf "];")
(add2sbuf_indentnl implbuf (+i 1 depth))
(add2sbuf_strconst implbuf "memset(&argtab, 0, sizeof(argtab));")
(add2sbuf_indentnl implbuf (+i 1 depth))
;; output the initialization of argtab and fill the paramdesclist
(foreach_in_multiple
(oargs)
(curarg :long curank)
(let ( (curctyp (get_ctype curarg ())) )
(assert_msg "check curctyp" (is_a curctyp class_ctype))
(output_location oloc implbuf (get_int boxdepthp1) "ojbmsend.arg")
(add2sbuf_strconst implbuf "argtab[")
(add2sbuf_longdec implbuf curank)
(add2sbuf_strconst implbuf "].")
(list_append paramdesclist (unsafe_get_field :ctype_parstring curctyp))
(cond ( (null curarg)
(add2sbuf_strconst implbuf "meltbp_aptr = (melt_ptr_t*)NULL")
)
( (is_a curarg class_objnil)
(add2sbuf_strconst implbuf "meltbp_aptr = /*nil*/(melt_ptr_t*)NULL")
)
( (== curctyp ctype_value)
(add2sbuf_strconst implbuf "meltbp_aptr = (melt_ptr_t*) &")
(output_c_code curarg declbuf implbuf (get_int boxdepthp1))
)
(:else
(assert_msg "check curarg is not multiple" (not (is_multiple curarg)))
(add2sbuf_string implbuf (unsafe_get_field :ctype_argfield curctyp))
(add2sbuf_strconst implbuf " = ")
(output_c_code curarg declbuf implbuf (get_int boxdepthp1))
))
(add2sbuf_strconst implbuf ";")
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
(add2sbuf_indentnl implbuf (get_int boxdepthp1))
))
))
;;; output the destination(s)
(foreach_in_list
(odest)
(curpair curdest)
(output_c_code curdest declbuf implbuf (get_int boxdepthp1))
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
(add2sbuf_strconst implbuf " = "))
;;
(assert_msg "check orecv object" (is_object orecv))
;;
(add2sbuf_strconst implbuf "meltgc_send((melt_ptr_t)(")
(output_c_code orecv declbuf implbuf (+i depth 1))
(add2sbuf_strconst implbuf "), (melt_ptr_t)(")
(output_c_code osel declbuf implbuf (+i depth 1))
(add2sbuf_strconst implbuf "), (")
;; output the argdescr string
(list_every
paramdesclist
(lambda (pard)
(add2sbuf_string implbuf pard)
(add2sbuf_strconst implbuf " ")))
(add2sbuf_strconst implbuf "\"\"), ")
(if (>i nbarg 0)
(add2sbuf_strconst implbuf "argtab,")
(add2sbuf_strconst implbuf "(union meltparam_un*)0,"))
;; no extra results
(add2sbuf_strconst implbuf " \"\", (union meltparam_un*)0")
(add2sbuf_strconst implbuf ");")
(add2sbuf_indentnl implbuf (+i 1 depth))
(add2sbuf_strconst implbuf "}")
(add2sbuf_indentnl implbuf depth)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
))
(install_method class_objmsend output_c_code outpucod_objmsend)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; output a multiresult application
(defun outpucod_objmultiapply (oapp declbuf implbuf :long depth)
(assert_msg "check oapp" (is_a oapp class_objmultiapply))
(let (
(aloc (unsafe_get_field :obi_loc oapp))
(adest (unsafe_get_field :obdi_destlist oapp))
(oclos (unsafe_get_field :obapp_clos oapp))
(oargs (unsafe_get_field :obapp_args oapp))
(oxres (unsafe_get_field :obmultapp_xres oapp))
(:long nbarg (multiple_length oargs))
(:long nbxres (multiple_length oxres))
(paramdesclist (make_list discr_list))
(resdesclist (make_list discr_list))
(boxdepthp1 (make_integerbox discr_integer (+i 1 depth)))
)
(assert_msg "check oargs" (is_multiple_or_null oargs))
(assert_msg "check oxres" (is_multiple_or_null oxres))
(output_location aloc implbuf depth "multiapply")
(add2sbuf_strconst implbuf "/*multiapply ")
(add2sbuf_longdec implbuf nbarg)
(add2sbuf_strconst implbuf "args, ")
(add2sbuf_longdec implbuf nbxres)
(add2sbuf_strconst implbuf "x.res*/ ")
(add2sbuf_strconst implbuf "{")
(add2sbuf_indentnl implbuf (+i 1 depth))
(if (>i nbarg 1)
(progn
(add2sbuf_strconst implbuf "union meltparam_un argtab[")
(add2sbuf_longdec implbuf (-i nbarg 1))
(add2sbuf_strconst implbuf "];")
(add2sbuf_indentnl implbuf (+i 1 depth))
))
(if (>i nbxres 0)
(progn
(add2sbuf_indentnl implbuf (+i 1 depth))
(add2sbuf_strconst implbuf "union meltparam_un restab[")
(add2sbuf_longdec implbuf nbxres)
(add2sbuf_strconst implbuf "];")
(add2sbuf_indentnl implbuf (+i 1 depth))
))
(if (>i nbxres 0)
(progn
(add2sbuf_strconst implbuf "memset(&restab, 0, sizeof(restab));")
(add2sbuf_indentnl implbuf (+i 1 depth))
;; fill the resdesclist
(multiple_every
oxres
(lambda (cures :long curank)
(let ( (curctyp (get_ctype cures ())) )
(list_append resdesclist (unsafe_get_field :ctype_parstring curctyp)))))))
(if (>i nbarg 1)
(progn
(add2sbuf_strconst implbuf "memset(&argtab, 0, sizeof(argtab));")
(add2sbuf_indentnl implbuf (+i 1 depth))
;; output the initialization of argtab and fill the paramdesclist
(foreach_in_multiple
(oargs)
(curarg :long curank)
(if (>i curank 0)
(let ( (curctyp (get_ctype curarg ())) )
(assert_msg "check curctyp" (is_a curctyp class_ctype))
(output_location aloc implbuf (get_int boxdepthp1) "multiapply.arg")
(add2sbuf_strconst implbuf "argtab[")
(add2sbuf_longdec implbuf (-i curank 1))
(add2sbuf_strconst implbuf "].")
(list_append paramdesclist (unsafe_get_field :ctype_parstring curctyp))
(cond
( (null curarg)
(add2sbuf_strconst implbuf "meltbp_aptr = (melt_ptr_t*)NULL"))
( (== curctyp ctype_value)
(add2sbuf_strconst implbuf "meltbp_aptr = (melt_ptr_t*) &")
(output_c_code curarg declbuf implbuf (get_int boxdepthp1))
)
(:else
(add2sbuf_string implbuf (unsafe_get_field :ctype_argfield curctyp))
(add2sbuf_strconst implbuf " = ")
(output_c_code curarg declbuf implbuf (get_int boxdepthp1))
))
(add2sbuf_strconst implbuf ";")
))
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
)
(add2sbuf_indentnl implbuf (get_int boxdepthp1))
))
;; output the initialization of restab
(if (>i nbxres 0)
(progn
(multiple_every
oxres
(lambda (cures :long curank)
(let ( (curestyp (get_ctype cures ())) )
(assert_msg "check curestyp" (is_a curestyp class_ctype))
(output_location aloc implbuf (get_int boxdepthp1) "multiapply.xres")
(add2sbuf_strconst implbuf "restab[")
(add2sbuf_longdec implbuf curank)
(add2sbuf_strconst implbuf "].")
(cond
( (null cures)
(add2sbuf_strconst implbuf "meltbp_aptr = (melt_ptr_t*)NULL"))
( (== curestyp ctype_value)
(add2sbuf_strconst implbuf "meltbp_aptr = (melt_ptr_t*) &")
(output_c_code cures declbuf implbuf (get_int boxdepthp1))
)
(:else
(add2sbuf_string implbuf (unsafe_get_field :ctype_resfield curestyp))
(add2sbuf_strconst implbuf " = & ")
(output_c_code cures declbuf implbuf (get_int boxdepthp1))
))
(add2sbuf_strconst implbuf ";")
(add2sbuf_indentnl implbuf (get_int boxdepthp1))
)
))
))
(output_location aloc implbuf (get_int boxdepthp1) "multiapply.appl")
;;; output the destination(s)
(list_every
adest
(lambda (curdest)
(output_c_code curdest declbuf implbuf (get_int boxdepthp1))
(add2sbuf_strconst implbuf " = ")))
;; output the apply and the closure
(add2sbuf_strconst implbuf " melt_apply ((meltclosure_ptr_t)(")
(output_c_code oclos declbuf implbuf (+i 1 depth))
(add2sbuf_strconst implbuf "), (melt_ptr_t)(")
;; output the first argument
(let ( (firstarg (multiple_nth oargs 0)) )
(output_c_code firstarg declbuf implbuf (+i 1 depth))
)
(add2sbuf_strconst implbuf "), (")
;; output the argdescr string
(list_every
paramdesclist
(lambda (pard)
(add2sbuf_string implbuf pard)
(add2sbuf_strconst implbuf " ")))
(add2sbuf_strconst implbuf "\"\"), ")
;; output the argtab (or null if none)
(if (>i nbarg 1)
(add2sbuf_strconst implbuf "argtab, (")
(add2sbuf_strconst implbuf "(union meltparam_un*)0, ("))
;; output the resdescr string
(list_every
resdesclist
(lambda (resd)
(add2sbuf_string implbuf resd)
(add2sbuf_strconst implbuf " ")))
(add2sbuf_strconst implbuf "\"\"), ")
;; output the extra results
(if (>i nbxres 0)
(add2sbuf_strconst implbuf "restab")
(add2sbuf_strconst implbuf "(union meltparam_un*)0"))
(add2sbuf_strconst implbuf ");")
(add2sbuf_indentnl implbuf (+i 1 depth))
(add2sbuf_strconst implbuf "}")
(add2sbuf_indentnl implbuf depth)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
))
(install_method class_objmultiapply output_c_code outpucod_objmultiapply)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; output a multiresult message send
(defun outpucod_objmultimsend (omsnd declbuf implbuf :long depth)
(assert_msg "check omsnd" (is_a omsnd class_objmultimsend))
(let ( (oloc (unsafe_get_field :obi_loc omsnd))
(odest (unsafe_get_field :obdi_destlist omsnd))
(osel (unsafe_get_field :obmsnd_sel omsnd))
(orecv (unsafe_get_field :obmsnd_recv omsnd))
(oargs (unsafe_get_field :obmsnd_args omsnd))
(oxres (unsafe_get_field :obmultsnd_xres omsnd))
(:long nbarg (multiple_length oargs))
(:long nbxres (multiple_length oxres))
(paramdesclist (make_list discr_list))
(resdesclist (make_list discr_list))
(boxdepthp1 (make_integerbox discr_integer (+i 1 depth)))
)
(output_location oloc implbuf depth "multimsend")
(add2sbuf_strconst implbuf "/*multimsend*/{")
(add2sbuf_indentnl implbuf (+i 1 depth))
(if (>i nbarg 0)
(progn
(add2sbuf_strconst implbuf "union meltparam_un argtab[")
(add2sbuf_longdec implbuf nbarg)
(add2sbuf_strconst implbuf "];")
(add2sbuf_indentnl implbuf (+i 1 depth))
))
(if (>i nbxres 0)
(progn
(add2sbuf_strconst implbuf "union meltparam_un restab[")
(add2sbuf_longdec implbuf nbxres)
(add2sbuf_strconst implbuf "];")
(add2sbuf_indentnl implbuf (+i 1 depth))
;; fill the resdesclist
(multiple_every
oxres
(lambda (cures :long curank)
(let ( (curestyp (get_ctype cures ())) )
(list_append resdesclist (unsafe_get_field :ctype_parstring curestyp)))))
))
(if (>i nbarg 0)
(progn
(add2sbuf_strconst implbuf "memset(&argtab, 0, sizeof(argtab));")
(add2sbuf_indentnl implbuf (+i 1 depth))))
(if (>i nbxres 0)
(progn
(add2sbuf_strconst implbuf "memset(&restab, 0, sizeof(restab));")
(add2sbuf_indentnl implbuf (+i 1 depth))))
;; output the initialization of argtab and fill paramdesclist
(if (>i nbarg 0)
(progn
;; output the initialization of argtab and fill the paramdesclist
(foreach_in_multiple
(oargs)
(curarg :long curank)
(let ( (curctyp (get_ctype curarg ())) )
(assert_msg "check curctyp" (is_a curctyp class_ctype))
(output_location oloc implbuf (get_int boxdepthp1) "multimsend.arg")
(add2sbuf_strconst implbuf "argtab[")
(add2sbuf_longdec implbuf curank)
(add2sbuf_strconst implbuf "].")
(list_append paramdesclist (unsafe_get_field :ctype_parstring curctyp))
(cond
( (null curarg)
(add2sbuf_strconst implbuf "meltbp_aptr = (melt_ptr_t*)NULL"))
( (== curctyp ctype_value)
(add2sbuf_strconst implbuf "meltbp_aptr = (melt_ptr_t*) &")
(output_c_code curarg declbuf implbuf (get_int boxdepthp1))
)
(:else
(add2sbuf_string implbuf (unsafe_get_field :ctype_argfield curctyp))
(add2sbuf_strconst implbuf " = ")
(output_c_code curarg declbuf implbuf (get_int boxdepthp1))
))
(add2sbuf_strconst implbuf ";")
)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
)
(add2sbuf_indentnl implbuf (get_int boxdepthp1))
))
;; output the initialization of restab
(if (>i nbxres 0)
(progn
(multiple_every
oxres
(lambda (cures :long curank)
(let ( (curestyp (get_ctype cures ())) )
(assert_msg "check curestyp" (is_a curestyp class_ctype))
(output_location oloc implbuf (get_int boxdepthp1) "multimsend.xres")
(add2sbuf_strconst implbuf "restab[")
(add2sbuf_longdec implbuf curank)
(add2sbuf_strconst implbuf "].")
(cond
( (null cures)
(add2sbuf_strconst implbuf "meltbp_aptr = (melt_ptr_t*)NULL")
)
( (== curestyp ctype_value)
(add2sbuf_strconst implbuf "meltbp_aptr = (melt_ptr_t*) &")
(output_c_code cures declbuf implbuf (get_int boxdepthp1))
)
(:else
(add2sbuf_string implbuf (unsafe_get_field :ctype_resfield curestyp))
(add2sbuf_strconst implbuf " = ")
(output_c_code cures declbuf implbuf (get_int boxdepthp1))
))
(add2sbuf_strconst implbuf ";")
)
))
))
(output_location oloc implbuf (get_int boxdepthp1) "multimsend.send")
;;; output the destination(s)
(list_every
odest
(lambda (curdest)
(output_c_code curdest declbuf implbuf (get_int boxdepthp1))
(add2sbuf_strconst implbuf " = ")))
;; output the send and the receiver
(add2sbuf_strconst implbuf " meltgc_send ((melt_ptr_t)(")
(output_c_code orecv declbuf implbuf (+i 1 depth))
(add2sbuf_strconst implbuf "), ((melt_ptr_t)(")
;; output the selector
(output_c_code osel declbuf implbuf (+i 1 depth))
(add2sbuf_strconst implbuf ")), (")
;; output the argdescr string
(list_every
paramdesclist
(lambda (pard)
(add2sbuf_string implbuf pard)
(add2sbuf_strconst implbuf " ")))
(add2sbuf_strconst implbuf "\"\"), ")
;; output the argtab (or null if none)
(if (>i nbarg 0)
(add2sbuf_strconst implbuf "argtab, (")
(add2sbuf_strconst implbuf "(union meltparam_un*)0, ("))
;; output the resdescr string
(list_every
resdesclist
(lambda (resd)
(add2sbuf_string implbuf resd)
(add2sbuf_strconst implbuf " ")))
(add2sbuf_strconst implbuf "\"\"), ")
;; output the extra results
(if (>i nbxres 0)
(add2sbuf_strconst implbuf "restab")
(add2sbuf_strconst implbuf "(union meltparam_un*)0"))
(add2sbuf_strconst implbuf ");")
(add2sbuf_indentnl implbuf (+i 1 depth))
(add2sbuf_strconst implbuf "}")
(add2sbuf_indentnl implbuf depth)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
))
(install_method class_objmultimsend output_c_code outpucod_objmultimsend)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; output a clear
(defun outpucod_objclear (oclear declbuf implbuf :long depth)
(assert_msg "check oclear" (is_a oclear class_objclear))
(let ( (cloc (unsafe_get_field :obi_loc oclear))
(cvl (unsafe_get_field :oclr_vloc oclear))
)
(output_location cloc implbuf depth "clear")
(add2sbuf_strconst implbuf "/*clear*/ ")
(output_c_code cvl declbuf implbuf (+i depth 1))
(add2sbuf_strconst implbuf " = 0 ")
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
)
)
(install_method class_objclear output_c_code outpucod_objclear)
;; output a raw object allocation
(defun outpucod_objrawallocobj (oralob declbuf implbuf :long depth)
(assert_msg "check oralob" (is_a oralob class_objrawallocobj))
(let ( (iloc (unsafe_get_field :obi_loc oralob))
(iclass (unsafe_get_field :obrallobj_class oralob))
(iclaname (unsafe_get_field :obrallobj_classname oralob))
(ilen (unsafe_get_field :obrallobj_len oralob))
(destlist (unsafe_get_field :obdi_destlist oralob))
(boxdepthp1 (make_integerbox discr_integer (+i depth 1)))
)
(assert_msg "outpucod_objrawallocobj check iclass" (is_a iclass class_objvalue))
(output_location iloc implbuf depth "rawallocobj")
(add2sbuf_strconst implbuf "/*rawallocobj*/ { melt_ptr_t newobj = 0;")
(add2sbuf_indentnl implbuf (+i depth 1))
(add2sbuf_strconst implbuf "melt_raw_object_create(newobj,(melt_ptr_t)(")
(output_c_code iclass declbuf implbuf (get_int boxdepthp1))
(add2sbuf_strconst implbuf "), (")
(output_c_code ilen declbuf implbuf (get_int boxdepthp1))
(add2sbuf_strconst implbuf "), \"")
(add2sbuf_cencstring implbuf iclaname)
(add2sbuf_strconst implbuf "\");")
(foreach_in_list
destlist
(dstpair dst)
(add2sbuf_indentnl implbuf (+i depth 1))
(output_c_code dst declbuf implbuf (get_int boxdepthp1))
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
(add2sbuf_strconst implbuf " =")))
(add2sbuf_indentnl implbuf (+i depth 1))
(add2sbuf_strconst implbuf "newobj; };")
(add2sbuf_indentnl implbuf depth)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
)
(install_method class_objrawallocobj output_c_code outpucod_objrawallocobj)
;; output a closure allocation
(defun outpucod_objnewclosure (obnclo declbuf implbuf :long depth)
(assert_msg "check oralob" (is_a obnclo class_objnewclosure))
(let ( (iloc (unsafe_get_field :obi_loc obnclo))
(odiscr (unsafe_get_field :obnclo_discr obnclo))
(orout (unsafe_get_field :obnclo_rout obnclo))
(olen (unsafe_get_field :obnclo_len obnclo))
(destlist (unsafe_get_field :obdi_destlist obnclo))
(boxdepthp1 (make_integerbox discr_integer (+i depth 1)))
)
(output_location iloc implbuf depth "newclosure")
(add2sbuf_strconst implbuf " /*newclosure*/ ")
(list_every
destlist
(lambda (dst)
(output_c_code dst declbuf implbuf (get_int boxdepthp1))
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
(add2sbuf_strconst implbuf " =")))
(add2sbuf_indentnl implbuf (+i depth 1))
(add2sbuf_strconst implbuf "(melt_ptr_t) meltgc_new_closure((meltobject_ptr_t)(")
(output_c_code odiscr declbuf implbuf (get_int boxdepthp1))
(add2sbuf_strconst implbuf "), (meltroutine_ptr_t)(")
(output_c_code orout declbuf implbuf (get_int boxdepthp1))
(add2sbuf_strconst implbuf "), (")
(output_c_code olen declbuf implbuf (get_int boxdepthp1))
(add2sbuf_strconst implbuf "));")
(add2sbuf_indentnl implbuf depth)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
))
(install_method class_objnewclosure output_c_code outpucod_objnewclosure)
;; output a touch
(defun outpucod_objtouch (otouch declbuf implbuf :long depth)
(assert_msg "check otouch" (is_a otouch class_objtouch))
(let ( (iloc (unsafe_get_field :obi_loc otouch))
(touched (unsafe_get_field :otouch_val otouch))
(comm (unsafe_get_field :otouch_comment otouch))
)
(output_location iloc implbuf depth "touch")
(if comm
(progn
(add2sbuf_strconst implbuf "/*touch:")
(add2sbuf_cident implbuf comm)
(add2sbuf_strconst implbuf "*/")
(add2sbuf_indentnl implbuf depth)
))
(add2sbuf_strconst implbuf "meltgc_touch(")
(output_c_code touched declbuf implbuf depth)
(add2sbuf_strconst implbuf ");")
(add2sbuf_indentnl implbuf depth)
)
)
(install_method class_objtouch output_c_code outpucod_objtouch)
;; output a debug tracing of written object
(defun outpucod_dbgtracewriteobj (otwro declbuf implbuf :long depth)
(assert_msg "check otwro" (is_a otwro class_objdbgtracewriteobj))
(let ( (iloc (unsafe_get_field :obi_loc otwro))
(owritten (unsafe_get_field :obdtw_writtenobj otwro))
(msg (unsafe_get_field :obdtw_message otwro))
)
(output_location iloc implbuf depth "touchobj")
(add2sbuf_indentnl implbuf depth)
(add2sbuf_strconst implbuf "melt_dbgtrace_written_object (")
(output_c_code owritten declbuf implbuf depth)
(add2sbuf_strconst implbuf ", \"")
(if (is_string msg)
(add2sbuf_cencstring implbuf msg)
(add2sbuf_strconst implbuf "*written object*"))
(add2sbuf_strconst implbuf "\");")
(add2sbuf_indentnl implbuf depth)))
(install_method class_objdbgtracewriteobj output_c_code outpucod_dbgtracewriteobj)
;;; output a put tuple (mostly used in initial data content filling)
(defun outpucod_objputuple (optup declbuf implbuf :long depth)
(assert_msg "check optyp" (is_a optup class_objputuple))
(let ( (iloc (unsafe_get_field :obi_loc optup))
(otup (unsafe_get_field :oputu_tupled optup))
(ooff (unsafe_get_field :oputu_offset optup))
(:long uniqrank 0)
(oval (unsafe_get_field :oputu_value optup))
)
(code_chunk uniqrankset
#{ { /* outpucod_objputuple $UNIQRANKSET */
static long $UNIQRANKSET#_cnt ;
$UNIQRANKSET#_cnt++ ;
$UNIQRANK = $UNIQRANKSET#_cnt ;
} /* end outpucod_objputuple $UNIQRANKSET */ }#)
(multicall
(linev filev)
(line_and_file_of_location iloc)
(output_location iloc implbuf depth "putuple")
(add2sbuf_strconst implbuf "/*putupl")
(add2sbuf_strconst implbuf "#")
(add2sbuf_longdec implbuf uniqrank)
(add2sbuf_strconst implbuf "*/")
(add2sbuf_indentnl implbuf depth)
(add2sbuf_strconst implbuf "melt_assertmsg(\"putupl ")
(if (>i (get_int linev) 0)
(progn
(add2sbuf_strconst implbuf "[")
(add2sbuf_string implbuf filev)
(add2sbuf_strconst implbuf ":")
(add2sbuf_longdec implbuf (get_int linev))
(add2sbuf_strconst implbuf "] ")
))
(add2sbuf_strconst implbuf "#")
(add2sbuf_longdec implbuf uniqrank)
(add2sbuf_strconst implbuf " checktup\", melt_magic_discr((melt_ptr_t)(")
(output_c_code otup declbuf implbuf depth)
(add2sbuf_strconst implbuf "))== MELTOBMAG_MULTIPLE);")
(add2sbuf_indentnl implbuf depth)
(add2sbuf_strconst implbuf "melt_assertmsg(\"putupl ")
(if (>i (get_int linev) 0)
(progn
(add2sbuf_strconst implbuf "[")
(add2sbuf_string implbuf filev)
(add2sbuf_strconst implbuf ":")
(add2sbuf_longdec implbuf (get_int linev))
(add2sbuf_strconst implbuf "] ")
))
(add2sbuf_strconst implbuf "#")
(add2sbuf_longdec implbuf uniqrank)
(add2sbuf_strconst implbuf " checkoff\", (")
(output_c_code ooff declbuf implbuf depth)
(add2sbuf_strconst implbuf ">=0 && ")
(output_c_code ooff declbuf implbuf depth)
(add2sbuf_strconst implbuf "< melt_multiple_length((melt_ptr_t)(")
(output_c_code otup declbuf implbuf depth)
(add2sbuf_strconst implbuf "))));")
(add2sbuf_indentnl implbuf depth)
(add2sbuf_strconst implbuf "((meltmultiple_ptr_t)(")
(output_c_code otup declbuf implbuf depth)
(add2sbuf_strconst implbuf "))->tabval[")
(output_c_code ooff declbuf implbuf depth)
(add2sbuf_strconst implbuf "] = (melt_ptr_t)(")
(output_c_code oval declbuf implbuf depth)
(add2sbuf_strconst implbuf ");")
(add2sbuf_indentnl implbuf depth)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
)
)
)
(install_method class_objputuple output_c_code outpucod_objputuple)
;;;;
(definstance objputpairhead_counter class_reference :referenced_value '0)
(defun outpucod_objputpairhead (oput declbuf implbuf :long depth)
(let ( (oloc (unsafe_get_field :obi_loc oput))
(opair (get_field :oputp_pair oput))
(ohead (get_field :oputp_head oput))
(oldcount !objputpairhead_counter)
(newcount (+ivi oldcount 1))
)
(output_location oloc implbuf depth "putpairhead")
(add2sbuf_strconst implbuf "/*putpairhead*/")
(add2sbuf_indentnl implbuf depth)
(set_ref objputpairhead_counter newcount)
(add2sbuf_strconst implbuf "melt_assertmsg(\"putpairhead /")
(add2sbuf_longhex implbuf (get_int newcount))
(add2sbuf_strconst implbuf " checkpair\", melt_magic_discr((melt_ptr_t)(")
(output_c_code opair declbuf implbuf depth)
(add2sbuf_strconst implbuf "))== MELTOBMAG_PAIR);")
(add2sbuf_indentnl implbuf depth)
(add2sbuf_strconst implbuf "((meltpair_ptr_t)(")
(output_c_code opair declbuf implbuf depth)
(add2sbuf_strconst implbuf "))->hd = (melt_ptr_t) (")
(output_c_code ohead declbuf implbuf depth)
(add2sbuf_strconst implbuf ");")
(add2sbuf_indentnl implbuf depth)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
))
(install_method class_objputpairhead output_c_code outpucod_objputpairhead)
;;;;
(defun outpucod_objputpairtail (oput declbuf implbuf :long depth)
(let ( (oloc (unsafe_get_field :obi_loc oput))
(opair (get_field :oputp_pair oput))
(otail (get_field :oputp_tail oput))
)
(output_location oloc implbuf depth "putpairtail")
(add2sbuf_strconst implbuf "/*putpairtail*/")
(add2sbuf_indentnl implbuf depth)
(add2sbuf_strconst implbuf "melt_assertmsg(\"putpairtail /")
(add2sbuf_longhex implbuf (obj_hash oput))
(add2sbuf_strconst implbuf " checkpair\", melt_magic_discr((melt_ptr_t)(")
(output_c_code opair declbuf implbuf depth)
(add2sbuf_strconst implbuf "))== MELTOBMAG_PAIR);")
(add2sbuf_indentnl implbuf depth)
(add2sbuf_strconst implbuf "((meltpair_ptr_t)(")
(output_c_code opair declbuf implbuf depth)
(add2sbuf_strconst implbuf "))->tl = (meltpair_ptr_t) (")
(output_c_code otail declbuf implbuf depth)
(add2sbuf_strconst implbuf ");")
(add2sbuf_indentnl implbuf depth)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
))
(install_method class_objputpairtail output_c_code outpucod_objputpairtail)
;;;;
(defun outpucod_objputlist (oput declbuf implbuf :long depth)
(let ( (oloc (unsafe_get_field :obi_loc oput))
(olist (get_field :oputl_list oput))
(ofirst (get_field :oputl_first oput))
(olast (get_field :oputl_last oput))
)
(output_location oloc implbuf depth "putlist")
(add2sbuf_strconst implbuf "/*putlist*/")
(add2sbuf_indentnl implbuf depth)
(add2sbuf_strconst implbuf "melt_assertmsg(\"putlist checklist\", melt_magic_discr((melt_ptr_t)(")
(output_c_code olist declbuf implbuf depth)
(add2sbuf_strconst implbuf "))== MELTOBMAG_LIST);")
(add2sbuf_indentnl implbuf depth)
(add2sbuf_strconst implbuf "((meltlist_ptr_t)(")
(output_c_code olist declbuf implbuf depth)
(add2sbuf_strconst implbuf "))->first = (meltpair_ptr_t) (")
(output_c_code ofirst declbuf implbuf depth)
(add2sbuf_strconst implbuf ");")
(add2sbuf_indentnl implbuf depth)
(add2sbuf_strconst implbuf "((meltlist_ptr_t)(")
(output_c_code olist declbuf implbuf depth)
(add2sbuf_strconst implbuf "))->last = (meltpair_ptr_t) (")
(output_c_code olast declbuf implbuf depth)
(add2sbuf_strconst implbuf ");")
(add2sbuf_indentnl implbuf depth)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
))
(install_method class_objputlist output_c_code outpucod_objputlist)
;;;;
(defun outpucod_objgetslot (ogsl declbuf implbuf :long depth)
(assert_msg "check ogsl" (is_a ogsl class_objgetslot))
(let ( (oloc (unsafe_get_field :obi_loc ogsl))
(destlist (unsafe_get_field :obdi_destlist ogsl))
(oobj (unsafe_get_field :ogetsl_obj ogsl))
(ofield (unsafe_get_field :ogetsl_field ogsl))
(boxdepthp1 (make_integerbox discr_integer (+i depth 1)))
)
(assert_msg "check ofield" (is_a ofield class_field))
(output_location oloc implbuf depth "getslot")
(add2sbuf_strconst implbuf "{ melt_ptr_t slot=NULL, obj=NULL;")
(add2sbuf_indentnl implbuf (+i 1 depth))
(add2sbuf_strconst implbuf "obj = (melt_ptr_t)(");
(output_c_code oobj declbuf implbuf depth)
(add2sbuf_strconst implbuf ") /*=obj*/;");
(add2sbuf_indentnl implbuf (+i 1 depth))
(add2sbuf_strconst implbuf "melt_object_get_field(slot,obj, ")
(add2sbuf_longdec implbuf (get_int ofield))
(add2sbuf_strconst implbuf ", \"")
(add2sbuf_string implbuf (unsafe_get_field :named_name ofield))
(add2sbuf_strconst implbuf "\");")
(add2sbuf_indentnl implbuf (+i 1 depth))
(list_every
destlist
(lambda (dst)
(output_c_code dst declbuf implbuf (get_int boxdepthp1))
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
(add2sbuf_strconst implbuf " = ")))
(add2sbuf_strconst implbuf "slot; };")
(add2sbuf_indentnl implbuf depth)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
))
(install_method class_objgetslot output_c_code outpucod_objgetslot)
;;; output a put slot (mostly used in initial data content filling)
(defun outpucod_objputslot (opslo declbuf implbuf :long depth)
(assert_msg "check opslo" (is_a opslo class_objputslot))
(let ( (iloc (unsafe_get_field :obi_loc opslo))
(odata (unsafe_get_field :oslot_odata opslo))
(ooff (unsafe_get_field :oslot_offset opslo))
(ofield (unsafe_get_field :oslot_field opslo))
(oval (unsafe_get_field :oslot_value opslo))
)
(assert_msg "outpucod_objputslot check oval not nrep" (not (is_a oval class_nrep)))
(output_location iloc implbuf depth "putslot")
(add2sbuf_strconst implbuf "/*putslot*/")
(add2sbuf_indentnl implbuf depth)
(add2sbuf_strconst implbuf "melt_assertmsg(\"putslot checkobj")
(if (is_a odata class_named)
(progn
(add2sbuf_strconst implbuf " ")
(add2sbuf_string implbuf (unsafe_get_field :named_name odata))))
(if (is_a ofield class_named)
(progn
(add2sbuf_strconst implbuf " @")
(add2sbuf_string implbuf (unsafe_get_field :named_name ofield))))
(add2sbuf_strconst implbuf "\", melt_magic_discr((melt_ptr_t)(")
(output_c_code odata declbuf implbuf depth)
(add2sbuf_strconst implbuf ")) == MELTOBMAG_OBJECT);")
(add2sbuf_indentnl implbuf depth)
(if (is_a ofield class_field)
(progn
(add2sbuf_strconst implbuf "melt_putfield_object((")
(output_c_code odata declbuf implbuf depth)
(add2sbuf_strconst implbuf "), (")
(output_c_code ooff declbuf implbuf depth)
(add2sbuf_strconst implbuf "), (")
(output_c_code oval declbuf implbuf (+i 1 depth))
(add2sbuf_strconst implbuf "), \"")
(add2sbuf_cident implbuf (unsafe_get_field :named_name ofield))
(add2sbuf_strconst implbuf "\");")
)
(progn
;;; this only happens for initialization of instances
(add2sbuf_indentnl implbuf depth)
(add2sbuf_strconst implbuf "melt_assertmsg(\"putslot checkoff")
(if (is_a odata class_named)
(progn
(add2sbuf_strconst implbuf " ")
(add2sbuf_string implbuf (unsafe_get_field :named_name odata))))
(if (is_a ofield class_named)
(progn
(add2sbuf_strconst implbuf " @")
(add2sbuf_string implbuf (unsafe_get_field :named_name ofield))))
(add2sbuf_strconst implbuf "\", (")
(output_c_code ooff declbuf implbuf depth)
(add2sbuf_strconst implbuf ">=0 && ")
(output_c_code ooff declbuf implbuf depth)
(add2sbuf_strconst implbuf "< melt_object_length((melt_ptr_t)(")
(output_c_code odata declbuf implbuf depth)
(add2sbuf_strconst implbuf "))));")
(add2sbuf_indentnl implbuf depth)
(add2sbuf_strconst implbuf "((meltobject_ptr_t)(")
(output_c_code odata declbuf implbuf depth)
(add2sbuf_strconst implbuf "))->obj_vartab[")
(output_c_code ooff declbuf implbuf depth)
(add2sbuf_strconst implbuf "] = (melt_ptr_t)(")
(add2sbuf_indentnl implbuf (+i 1 depth))
(output_c_code oval declbuf implbuf (+i 1 depth))
(add2sbuf_strconst implbuf ");")
)
)
(add2sbuf_indentnl implbuf depth)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
))
(install_method class_objputslot output_c_code outpucod_objputslot)
;;; output the putting of the routine in a closure
(defun outpucod_objputclosurout (opclor declbuf implbuf :long depth)
(assert_msg "check opclor" (is_a opclor class_objputclosurout))
(let ( (oloc (unsafe_get_field :obi_loc opclor))
(oclos (unsafe_get_field :opclor_clos opclor))
(orout (unsafe_get_field :opclor_rout opclor))
(:long cnt 0)
)
(code_chunk
getcntchk
#{ /* $GETCNTCHK in outpucod_objputclosurout */ {
static long $GETCNTCHK#_cnt;
$GETCNTCHK#_cnt++;
$CNT = $GETCNTCHK#_cnt;
} }#)
(output_location oloc implbuf depth "putclosurout")
(add2sbuf_strconst implbuf "/*putclosurout#")
(add2sbuf_longdec implbuf cnt)
(add2sbuf_strconst implbuf "*/")
(add2sbuf_indentnl implbuf depth)
(add2sbuf_strconst implbuf "melt_assertmsg(\"putclosrout#")
(add2sbuf_longdec implbuf cnt)
(add2sbuf_strconst implbuf " checkclo\", melt_magic_discr((melt_ptr_t)(")
(output_c_code oclos declbuf implbuf depth)
(add2sbuf_strconst implbuf ")) == MELTOBMAG_CLOSURE);")
(add2sbuf_indentnl implbuf depth)
(add2sbuf_strconst implbuf "melt_assertmsg(\"putclosrout#")
(add2sbuf_longdec implbuf cnt)
(add2sbuf_strconst implbuf " checkrout\", melt_magic_discr((melt_ptr_t)(")
(output_c_code orout declbuf implbuf depth)
(add2sbuf_strconst implbuf ")) == MELTOBMAG_ROUTINE);")
(add2sbuf_indentnl implbuf depth)
(add2sbuf_strconst implbuf "((meltclosure_ptr_t)")
(output_c_code oclos declbuf implbuf depth)
(add2sbuf_strconst implbuf ")->rout = (meltroutine_ptr_t) (")
(output_c_code orout declbuf implbuf depth)
(add2sbuf_strconst implbuf ");")
(add2sbuf_indentnl implbuf depth)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
)
)
(install_method class_objputclosurout output_c_code outpucod_objputclosurout)
;;; output the putting of a closed value
(defun outpucod_objputclosedv (opclov declbuf implbuf :long depth)
(assert_msg "check opclor" (is_a opclov class_objputclosedv))
(let ( (oloc (unsafe_get_field :obi_loc opclov))
(oclos (unsafe_get_field :opclov_clos opclov))
(ooff (unsafe_get_field :opclov_off opclov))
(ocval (unsafe_get_field :opclov_cval opclov)) )
(output_location oloc implbuf depth "putclosedv")
(add2sbuf_strconst implbuf "/*putclosv*/")
(add2sbuf_indentnl implbuf depth)
(add2sbuf_strconst implbuf "melt_assertmsg(\"putclosv checkclo\", melt_magic_discr((melt_ptr_t)(")
(output_c_code oclos declbuf implbuf depth)
(add2sbuf_strconst implbuf ")) == MELTOBMAG_CLOSURE);")
(add2sbuf_indentnl implbuf depth)
(add2sbuf_strconst implbuf "melt_assertmsg(\"putclosv checkoff\", ")
(output_c_code ooff declbuf implbuf depth)
(add2sbuf_strconst implbuf ">= 0 && ")
(output_c_code ooff declbuf implbuf depth)
(add2sbuf_strconst implbuf "< melt_closure_size((melt_ptr_t) (")
(output_c_code oclos declbuf implbuf depth)
(add2sbuf_strconst implbuf ")));")
(add2sbuf_indentnl implbuf depth)
(add2sbuf_strconst implbuf "((meltclosure_ptr_t)")
(output_c_code oclos declbuf implbuf depth)
(add2sbuf_strconst implbuf ")->tabval[")
(output_c_code ooff declbuf implbuf depth)
(add2sbuf_strconst implbuf "] = (melt_ptr_t)(")
(output_c_code ocval declbuf implbuf depth)
(add2sbuf_strconst implbuf ");")
(add2sbuf_indentnl implbuf depth)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
))
(install_method class_objputclosedv output_c_code outpucod_objputclosedv)
;;; output the putting of a nonull closed value
(defun outpucod_objputclosednotnullv (opclov declbuf implbuf :long depth)
(assert_msg "check opclor" (is_a opclov class_objputclosednotnullv))
(let ( (oloc (unsafe_get_field :obi_loc opclov))
(oclos (unsafe_get_field :opclov_clos opclov))
(ooff (unsafe_get_field :opclov_off opclov))
(ocval (unsafe_get_field :opclov_cval opclov)) )
(output_location oloc implbuf depth "putclosednotnullv")
(add2sbuf_strconst implbuf "/*putclosvnotnull*/")
(add2sbuf_indentnl implbuf depth)
(add2sbuf_strconst implbuf "melt_assertmsg(\"putclosvnotnull checkclo\", melt_magic_discr((melt_ptr_t)(")
(output_c_code oclos declbuf implbuf depth)
(add2sbuf_strconst implbuf ")) == MELTOBMAG_CLOSURE);")
(add2sbuf_indentnl implbuf depth)
(add2sbuf_strconst implbuf "melt_assertmsg(\"putclosvnotnull checknotnullval\", NULL != ")
(output_c_code ocval declbuf implbuf depth)
(add2sbuf_strconst implbuf ");")
(add2sbuf_indentnl implbuf depth)
(add2sbuf_strconst implbuf "melt_assertmsg(\"putclosvnotnull checkoff\", ")
(output_c_code ooff declbuf implbuf depth)
(add2sbuf_strconst implbuf ">= 0 && ")
(output_c_code ooff declbuf implbuf depth)
(add2sbuf_strconst implbuf "< melt_closure_size((melt_ptr_t) (")
(output_c_code oclos declbuf implbuf depth)
(add2sbuf_strconst implbuf ")));")
(add2sbuf_indentnl implbuf depth)
(add2sbuf_strconst implbuf "((meltclosure_ptr_t)")
(output_c_code oclos declbuf implbuf depth)
(add2sbuf_strconst implbuf ")->tabval[")
(output_c_code ooff declbuf implbuf depth)
(add2sbuf_strconst implbuf "] = (melt_ptr_t)(")
(output_c_code ocval declbuf implbuf depth)
(add2sbuf_strconst implbuf ");")
(add2sbuf_indentnl implbuf depth)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
))
(install_method class_objputclosednotnullv output_c_code outpucod_objputclosednotnullv)
;; output the putting of a constant value inside a routine
(defun outpucod_objputroutconst (oprconst declbuf implbuf :long depth)
(assert_msg "check oprconst" (is_a oprconst class_objputroutconst))
(let ( (oloc (unsafe_get_field :obi_loc oprconst))
(orout (unsafe_get_field :oprconst_rout oprconst))
(oroutnam (if (is_a orout class_objinitroutine) (unsafe_get_field :oie_cname orout)))
(ooff (unsafe_get_field :oprconst_off oprconst))
(ocval (unsafe_get_field :oprconst_cval oprconst)) )
(output_location oloc implbuf depth "putroutconst")
(add2sbuf_strconst implbuf "/*putroutconst*/")
(add2sbuf_indentnl implbuf depth)
(add2sbuf_strconst implbuf "if (MELT_HAS_INITIAL_ENVIRONMENT) melt_assertmsg(\"putroutconst checkrout\", melt_magic_discr((melt_ptr_t)(")
(output_c_code orout declbuf implbuf depth)
(add2sbuf_strconst implbuf ")) == MELTOBMAG_ROUTINE);")
(add2sbuf_indentnl implbuf depth)
;;
(add2sbuf_strconst implbuf "if (MELT_HAS_INITIAL_ENVIRONMENT) melt_checkmsg(\"putroutconst constnull.")
(if (is_string oroutnam) (add2sbuf_string implbuf oroutnam))
(add2sbuf_strconst implbuf "#")
(output_c_code ooff declbuf implbuf depth)
(add2sbuf_strconst implbuf "\", NULL != (")
(output_c_code ocval declbuf implbuf depth)
(add2sbuf_strconst implbuf "));")
(add2sbuf_indentnl implbuf depth)
;;
(add2sbuf_strconst implbuf "((meltroutine_ptr_t)")
(output_c_code orout declbuf implbuf depth)
(add2sbuf_strconst implbuf ")->tabval[")
(output_c_code ooff declbuf implbuf depth)
(add2sbuf_strconst implbuf "] = (melt_ptr_t)(")
(output_c_code ocval declbuf implbuf depth)
(add2sbuf_strconst implbuf ");")
(add2sbuf_indentnl implbuf depth)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
)
)
(install_method class_objputroutconst output_c_code outpucod_objputroutconst)
;; output the putting of a nonnull constant value inside a routine
(defun outpucod_objputroutconstnotnull (oprconst declbuf implbuf :long depth)
(assert_msg "check oprconst" (is_a oprconst class_objputroutconstnotnull))
(let ( (oloc (unsafe_get_field :obi_loc oprconst))
(orout (unsafe_get_field :oprconst_rout oprconst))
(ooff (unsafe_get_field :oprconst_off oprconst))
(ocval (unsafe_get_field :oprconst_cval oprconst)) )
(assert_msg "check notnull ocval" (notnull ocval))
(output_location oloc implbuf depth "putroutconstnotnull")
(add2sbuf_strconst implbuf "/*putroutconstnotnull*/")
(add2sbuf_indentnl implbuf depth)
(add2sbuf_strconst implbuf "melt_assertmsg(\"putroutconstnotnull checkrout\", melt_magic_discr((melt_ptr_t)(")
(output_c_code orout declbuf implbuf depth)
(add2sbuf_strconst implbuf ")) == MELTOBMAG_ROUTINE);")
(add2sbuf_indentnl implbuf depth)
(add2sbuf_strconst implbuf "melt_assertmsg(\"putroutconstnotnull notnullconst\", NULL != ")
(output_c_code ocval declbuf implbuf depth)
(add2sbuf_strconst implbuf ");")
(add2sbuf_indentnl implbuf depth)
(add2sbuf_strconst implbuf "((meltroutine_ptr_t)")
(output_c_code orout declbuf implbuf depth)
(add2sbuf_strconst implbuf ")->tabval[")
(output_c_code ooff declbuf implbuf depth)
(add2sbuf_strconst implbuf "] = (melt_ptr_t)(")
(output_c_code ocval declbuf implbuf depth)
(add2sbuf_strconst implbuf ");")
(add2sbuf_indentnl implbuf depth)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
)
)
(install_method class_objputroutconstnotnull output_c_code outpucod_objputroutconstnotnull)
;;; output the put of an extra returned result
(defun outpucod_objputxtraresult (oputx declbuf implbuf :long depth)
(assert_msg "check oputx" (is_a oputx class_objputxtraresult))
(let ( (oloc (unsafe_get_field :obi_loc oputx))
(orank (unsafe_get_field :obxres_rank oputx))
(ovloc (unsafe_get_field :obxres_obloc oputx))
(octyp (get_ctype ovloc ()))
)
(output_location oloc implbuf depth "putxtraresult")
(assert_msg "check octyp" (is_a octyp class_ctype))
(assert_msg "check orank" (is_integerbox orank))
(add2sbuf_strconst implbuf "if (!meltxrestab_ || !meltxresdescr_) goto labend_rout;")
(add2sbuf_indentnl implbuf depth)
(add2sbuf_strconst implbuf "if (meltxresdescr_[")
(add2sbuf_longdec implbuf (get_int orank))
(add2sbuf_strconst implbuf "] != ")
(add2sbuf_string implbuf (unsafe_get_field :ctype_parchar octyp))
(add2sbuf_strconst implbuf ") goto labend_rout;")
(add2sbuf_indentnl implbuf depth)
(add2sbuf_strconst implbuf "if (meltxrestab_[")
(add2sbuf_longdec implbuf (get_int orank))
(add2sbuf_strconst implbuf "].")
(unless (is_string (get_field :ctype_resfield octyp))
(debug "outpucod_objputxtraresult bad octyp" octyp " oputx=" oputx)
(error_strv oloc "impossible secondary result type" (get_field :named_name octyp))
)
(add2sbuf_string implbuf (unsafe_get_field :ctype_resfield octyp))
(add2sbuf_strconst implbuf ") *(meltxrestab_[")
(add2sbuf_longdec implbuf (get_int orank))
(add2sbuf_strconst implbuf "].")
(add2sbuf_string implbuf (unsafe_get_field :ctype_resfield octyp))
(add2sbuf_strconst implbuf ") = (")
(if (== octyp ctype_value) (add2sbuf_strconst implbuf "melt_ptr_t) ("))
(output_c_code ovloc declbuf implbuf depth)
(add2sbuf_strconst implbuf ");")
(add2sbuf_indentnl implbuf depth)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
))
(install_method class_objputxtraresult output_c_code outpucod_objputxtraresult)
;;; output an expression
(defun outpucod_objexpv (oexp declbuf implbuf :long depth)
(assert_msg "check oexp" (is_a oexp class_objexpv))
(let ( (cont (unsafe_get_field :obx_cont oexp))
(boxdepthp1 (make_integerbox discr_integer (+i depth 1)))
)
(assert_msg "check cont" (is_multiple cont))
(foreach_in_multiple
(cont)
(comp :long ix)
(output_c_code comp declbuf implbuf (get_int boxdepthp1))
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
)))
(install_method class_objexpv output_c_code outpucod_objexpv)
;;; output a located expression
(defun outpucod_objlocatedexpv (oexp declbuf implbuf :long depth)
(assert_msg "check oexp" (is_a oexp class_objlocatedexpv))
(let ( (cont (unsafe_get_field :obx_cont oexp))
(oloc (unsafe_get_field :obcx_loc oexp))
(boxdepthp1 (make_integerbox discr_integer (+i depth 1)))
(otyp (unsafe_get_field :obv_type oexp))
)
;; the cont may be null
(assert_msg "check cont" (is_multiple_or_null cont))
(if (== otyp ctype_void)
(progn
(add2sbuf_indentnl implbuf depth)
(add2sbuf_strconst implbuf "{")
(add2sbuf_indentnl implbuf depth)
(output_location oloc implbuf depth "locexp")
)
(if oloc
(output_raw_location oloc implbuf depth "expr")
)
)
;;
(foreach_in_multiple
(cont)
(comp :long ix)
(output_c_code comp declbuf implbuf (get_int boxdepthp1))
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
)
(if (== otyp ctype_void)
(progn
(add2sbuf_strconst implbuf ";}")
(add2sbuf_indentnl implbuf depth)))
)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
)
(install_method class_objlocatedexpv output_c_code outpucod_objlocatedexpv)
;;; output a verbatim string
(defun outpucod_verbatimstring (vstr declbuf implbuf :long depth)
(assert_msg "check vstr" (== (discrim vstr) discr_verbatim_string))
(add2sbuf_string implbuf vstr)
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
)
(install_method discr_verbatim_string output_c_code outpucod_verbatimstring)
;; output a string (cstring constant)
(defun outpucod_string (vstr declbuf implbuf :long depth)
(assert_msg "check vstr" (== (discrim vstr) discr_string))
(add2sbuf_strconst implbuf " \"")
(add2sbuf_cencstring implbuf vstr)
(add2sbuf_strconst implbuf "\"")
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
)
(install_method discr_string output_c_code outpucod_string)
;;; output an integer
(defun outpucod_integer (vint declbuf implbuf :long depth)
(assert_msg "check vint" (is_integerbox vint))
(add2sbuf_longdec implbuf (get_int vint))
)
(install_method discr_integer output_c_code outpucod_integer)
;;; output a finalreturn
(defun outpucod_finalreturn (fret declbuf implbuf :long depth)
(assert_msg "check fret" (is_a fret class_objfinalreturn))
(output_location (unsafe_get_field :obi_loc fret) implbuf depth "finalreturn")
(add2sbuf_strconst implbuf ";")
(add2sbuf_indentnl implbuf depth)
(add2sbuf_strconst implbuf "/*finalret*/ goto labend_rout ")
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
)
(install_method class_objfinalreturn output_c_code outpucod_finalreturn)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun sorted_named_dict_tuple (dic)
(let ( (:long dicnt (mapstring_count dic))
(entlist (make_list discr_list))
)
(foreach_in_mapstring
(dic)
(nam ent)
(assert_msg "check ent named" (is_a ent class_named))
(list_append entlist ent))
(let ( (rawtup (list_to_multiple entlist))
)
(assert_msg "sorted_named_dict_tuple check tuple length is dict count"
(==i dicnt (multiple_length rawtup)))
(multiple_sort rawtup compare_named_alpha discr_multiple)
)
))
(defun output_exported_offsets (modctx declbuf implbuf)
(assert_msg "check modctx" (is_a modctx class_module_context))
(let (
(rawdictfields (unsafe_get_field :mocx_expfieldict modctx))
(sortedfields (sorted_named_dict_tuple rawdictfields))
(rawdictclasses (unsafe_get_field :mocx_expclassdict modctx))
(sortedclasses (sorted_named_dict_tuple rawdictclasses))
)
(add2sbuf_indentnl implbuf 0)
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "/* exported ")
(add2sbuf_longdec implbuf (mapstring_count rawdictfields))
(add2sbuf_strconst implbuf " field offsets */")
(foreach_in_multiple
(sortedfields)
(fld :long ix)
(assert_msg "check fld" (is_a fld class_field))
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "MELT_EXTERN const int meltfieldoff__")
(add2sbuf_cident implbuf (unsafe_get_field :named_name fld))
(add2sbuf_strconst implbuf ";")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "const int meltfieldoff__")
(add2sbuf_cident implbuf (unsafe_get_field :named_name fld))
(add2sbuf_strconst implbuf " = ")
(add2sbuf_longdec implbuf (get_int fld))
(add2sbuf_strconst implbuf ";")
(add2sbuf_strconst implbuf " /* in ")
(add2sbuf_string implbuf (get_field :named_name (get_field :fld_ownclass fld)))
(add2sbuf_strconst implbuf " */")
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
)
(add2sbuf_indentnl implbuf 0)
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "/* exported ")
(add2sbuf_longdec implbuf (mapstring_count rawdictclasses))
(add2sbuf_strconst implbuf " class lengths */")
(foreach_in_multiple
(sortedclasses)
(cla :long ix)
(assert_msg "check cla" (is_a cla class_class))
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "MELT_EXTERN const int meltclasslen__")
(add2sbuf_cident implbuf (unsafe_get_field :named_name cla))
(add2sbuf_strconst implbuf ";")
(add2sbuf_indentnl implbuf 0)
(add2sbuf_strconst implbuf "const int meltclasslen__")
(add2sbuf_cident implbuf (unsafe_get_field :named_name cla))
(add2sbuf_strconst implbuf " = ")
(add2sbuf_longdec implbuf
(multiple_length (unsafe_get_field :class_fields cla)))
(add2sbuf_strconst implbuf ";")
(assert_msg "check limited implbuf"
(<i (strbuf_usedlength implbuf) (get_int !buffer_limit_cont)))
)
(add2sbuf_indentnl implbuf 0)
(add2sbuf_indentnl implbuf 0)
))
;;; the internal class for secondary generated C files
(defclass class_secondary_c_file
:super class_root
:fields (secfil_modnam ;the module name
secfil_path ;the file path
secfil_declbuf ;the declaration buffer
secfil_implbuf ;the implementation buffer
))
;; internal primitive to generate a C name
(defprimitive generated_c_filename (discr base dir :long num) :value
#{meltgc_new_string_generated_c_filename /* generated_c_filename */
((meltobject_ptr_t) ($DISCR),
melt_string_str((melt_ptr_t) ($BASE)), melt_string_str((melt_ptr_t) ($DIR)),
($NUM))}#)
;;; retrieve or create the nth secondary file in a module
(defun nth_secundary_file (modctx modnamstr declbuf :long ix)
(assert_msg "check modctx" (is_a modctx class_module_context))
(assert_msg "check modnamstr" (is_string modnamstr))
(assert_msg "check declbuf" (is_strbuf declbuf))
(let ( (mofiles (get_field :mocx_filetuple modctx))
(:long nbfiles (multiple_length mofiles))
(nthfile (multiple_nth mofiles ix))
)
(if nthfile (return nthfile))
(if (<=i ix 0) (return))
(if (>=i ix nbfiles) (return))
(compile_warning "nth_secundary_file incomplete")
(let (
(path (generated_c_filename discr_string
modnamstr
()
ix))
(implbuf (make_strbuf discr_strbuf))
(newfile (instance class_secondary_c_file
:secfil_modnam modnamstr
:secfil_path path
:secfil_declbuf declbuf
:secfil_implbuf implbuf))
)
(put_int newfile ix)
(multiple_put_nth mofiles ix newfile)
(return newfile)
)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; utility to output the melt descriptor FOO+meltdesc.c and melt
;; timestamp FOO+melttime.h [#include-d by FOO+meltdesc.c] from files
(defun output_melt_descriptor (modnamstr secfiles modctx)
(debug "output_melt_descriptor modnamstr=" modnamstr " secfiles=" secfiles " modctx=" modctx)
(assert_msg "check modnamstr" (is_string modnamstr))
(assert_msg "check modctx" (is_a modctx class_module_context))
(let (
(:long nbsecfiles (multiple_length secfiles))
(:long lastsecfileix 0)
(debuf (make_strbuf discr_strbuf))
(tibuf (make_strbuf discr_strbuf))
(mkbuf (make_strbuf discr_strbuf))
(pathlist (make_list discr_list))
(md5list (make_list discr_list))
(modbuildstr (make_string_nakedbasename discr_string modnamstr))
(modcident (let ( (buf (make_strbuf discr_strbuf))
)
(add2out_cident buf modnamstr)
(strbuf2string discr_string buf)))
(modbuildcident (let ( (buf (make_strbuf discr_strbuf))
)
(add2out_cident buf modbuildstr)
(strbuf2string discr_string buf)))
(modprefstr (string4out discr_string "$(GCCMELTGEN_BUILD)" modbuildstr))
(packagepclist (get_field :mocx_packagepclist modctx))
(flavortuple
(tuple '"quicklybuilt" '"optimized" '"dynamic" '"debugnoline"))
)
(add2sbuf_strconst debuf "/** GENERATED MELT DESCRIPTOR FILE ")
(add2sbuf_ccomstring debuf modnamstr)
(add2sbuf_strconst debuf "+meltdesc.c \n** NEVER EDIT OR MOVE THIS, IT IS GENERATED & PARSED! **/")
(add2sbuf_indentnl debuf 0)
(add2sbuf_strconst debuf "/* These identifiers are generated in warmelt-outobj.melt \n & handled in melt-runtime.c carefully. */")
(add2sbuf_indentnl debuf 0)
(add2out mkbuf "## GENERATED MELT MAKE FRAGMENT FILE " modnamstr "+meltbuild.mk\n")
(add2out mkbuf "## NEVER EDIT THIS FILE, generated from warmelt-outobj.melt by output_melt_descriptor\n")
(add2out debuf ##{
#ifdef __cplusplus
/* explicitly declare as extern "C" our dlsym-ed symbols */
extern "C" const char melt_versionmeltstr[] ;
extern "C" const char melt_genversionstr[] ;
extern "C" const char melt_modulename[] ;
extern "C" const char melt_modulerealpath[] ;
extern "C" const char melt_prepromd5meltrun[] ;
extern "C" const char melt_primaryhexmd5[] ;
extern "C" const char* const melt_secondaryhexmd5tab[] ;
extern "C" const int melt_lastsecfileindex ;
extern "C" const char melt_cumulated_hexmd5[] ;
extern "C" {
#endif /*__cplusplus */
}#)
(add2sbuf_indentnl debuf 0)
(add2sbuf_strconst debuf "/* version of the GCC compiler & MELT runtime generating this */")
(add2sbuf_indentnl debuf 0)
(add2sbuf_strconst debuf "const char melt_genversionstr[]=\"")
(code_chunk
genversch
#{ /* output_melt_descriptor $GENVERSCH + */
meltgc_add_strbuf_cstr ((melt_ptr_t) $DEBUF, melt_gccversionstr) ;
}#)
(add2sbuf_strconst debuf "\"")
(add2sbuf_indentnl debuf 0)
(add2out debuf ##{
#ifdef __cplusplus
" (in C++)"
#else
" (in C)"
#endif
;
}#)
(add2sbuf_indentnl debuf 0)
(add2sbuf_strconst debuf "const char melt_versionmeltstr[]=\"")
(add2out mkbuf "## generated by MELT version ")
(code_chunk
genvmeltch
#{ /* output_melt_descriptor $GENVMELTCH + */
meltgc_add_strbuf_cstr ((melt_ptr_t) $DEBUF, melt_version_str ()) ;
meltgc_add_strbuf_cstr ((melt_ptr_t) $MKBUF, melt_version_str ()) ;
}#)
(add2sbuf_strconst debuf "\";")
(add2sbuf_indentnl debuf 0)
(add2sbuf_indentnl mkbuf 0)
;;
(add2sbuf_indentnl debuf 0)
(add2sbuf_strconst debuf "/* source name & real path of the module */")
(add2sbuf_indentnl debuf 0)
(add2sbuf_strconst debuf "/*MELTMODULENAME ")
(add2sbuf_ccomstring debuf modnamstr)
(add2sbuf_strconst debuf " */")
(add2sbuf_indentnl debuf 0)
(add2out mkbuf "#module name and identifier\n")
(add2out mkbuf "MELTGEN_MODULENAME=" modnamstr)
(add2sbuf_indentnl mkbuf 0)
(add2out mkbuf "MELTGEN_MODULEIDENT=" modcident)
(add2sbuf_indentnl mkbuf 0)
(add2sbuf_strconst debuf "const char melt_modulename[]=\"")
(code_chunk
genmodnamstr
#{ /* output_melt_descriptor $GENMODNAMSTR + */
meltgc_add_strbuf_cstr ((melt_ptr_t) $DEBUF, lbasename (melt_string_str((melt_ptr_t) $MODNAMSTR))) ;
}#
)
;;
(add2sbuf_strconst debuf "\";")
(add2sbuf_indentnl debuf 0)
(add2sbuf_strconst debuf "const char melt_modulerealpath[]=\"")
(code_chunk
genrpathch
#{ /* output_melt_descriptor $GENRPATHCH + */ {
char* lrp = lrealpath (melt_string_str ((melt_ptr_t) $MODNAMSTR)) ;
if (!melt_flag_bootstrapping && !IS_ABSOLUTE_PATH(lrp)) {
meltgc_add_strbuf_cstr ((melt_ptr_t) $DEBUF, getpwd()) ;
meltgc_add_strbuf ((melt_ptr_t) $DEBUF, "/") ;
meltgc_add_strbuf_cstr ((melt_ptr_t) $DEBUF, lrp) ;
}
else if (melt_flag_bootstrapping) {
meltgc_add_strbuf_cstr ((melt_ptr_t) $DEBUF, melt_module_dir) ;
meltgc_add_strbuf ((melt_ptr_t) $DEBUF, "/") ;
meltgc_add_strbuf_cstr ((melt_ptr_t) $DEBUF, lbasename (lrp)) ;
}
else
meltgc_add_strbuf_cstr ((melt_ptr_t) $DEBUF, lrp) ;
free (lrp) ;
} /* end output_melt_descriptor $GENRPATHCH */}#)
(add2sbuf_strconst debuf "\";")
(add2sbuf_indentnl debuf 0)
(add2sbuf_indentnl debuf 0)
(add2sbuf_strconst debuf "/* hash of preprocessed melt-run.h generating this */")
(add2sbuf_indentnl debuf 0)
(add2sbuf_strconst debuf "const char melt_prepromd5meltrun[]=\"")
(code_chunk
genversch
#{ /* output_melt_descriptor $GENVERSCH */
meltgc_add_strbuf_cstr ((melt_ptr_t) $DEBUF, MELT_RUN_HASHMD5) ;
}#)
(add2sbuf_strconst debuf "\";")
(add2sbuf_indentnl debuf 0)
;;
(add2sbuf_strconst debuf "/* hexmd5checksum of primary C file */")
(add2sbuf_indentnl debuf 0)
(add2sbuf_strconst debuf "const char melt_primaryhexmd5[]=\"")
(let (
(primpath (string4out discr_string modnamstr ".c"))
(primmd5s (string_hex_md5sum_pathstrv primpath))
(mkrulebuf (make_strbuf discr_strbuf))
(secmd5buf (make_strbuf discr_strbuf))
(secpathbuf (make_strbuf discr_strbuf))
)
(debug "output_melt_descriptor primpath=" primpath)
(list_append pathlist primpath)
(list_append md5list primmd5s)
(add2sbuf_cencstring debuf primmd5s)
(add2out mkbuf "#primary path and checksum\n")
(add2out mkbuf "MELTGENMOD_PRIMPATH_" modcident "=" primpath)
(add2sbuf_indentnl mkbuf 0)
(add2out mkbuf "MELTGENMOD_MD5PRIM_" modcident "=" primmd5s)
(add2sbuf_indentnl mkbuf 0)
;; emit pkg-config information in make fragment
(let ( (packagepctup (list_to_multiple packagepclist discr_multiple))
(:long nbpackagepc (multiple_length packagepctup))
)
(debug "output_melt_descriptor packagepctup=" packagepctup)
(when nbpackagepc
(add2out mkbuf "# " nbpackagepc " packages for pkg-config utility\n")
(add2out mkbuf "MELTGENMOD_PACKAGELIST_PKGCONFIG_" modcident "=")
(foreach_in_multiple
(packagepctup)
(curpack :long pkix)
(add2out mkbuf " " curpack))
(add2out mkbuf "\n# global name for these pkg-config packages:\n")
(add2out mkbuf "MELTGENMOD_PACKAGELIST=$(MELTGENMOD_PACKAGELIST_PKGCONFIG_" modcident ")\n")
)
(unless nbpackagepc
(add2out mkbuf "# no packages needed thru pkg-config\n"))
)
(add2out mkrulebuf "### generated dependencies for " modnamstr "\n\n")
(add2out mkrulebuf "# dependency for primary of " modcident "\n")
(foreach_in_multiple
(flavortuple)
(curflav :long flavix)
(add2out mkrulebuf modprefstr "." primmd5s "." curflav ".meltpic.o: " primpath "\n")
)
(add2sbuf_strconst debuf "\";")
(add2sbuf_indentnl debuf 0)
;;
(add2sbuf_indentnl debuf 0)
(add2sbuf_strconst debuf "/* hexmd5checksum of secondary C files */")
(add2sbuf_indentnl debuf 0)
(add2sbuf_strconst debuf "const char* const melt_secondaryhexmd5tab[]={")
;;
(debug "output_melt_descriptor secfiles=" secfiles)
(foreach_in_multiple
(secfiles)
(curfil :long filix)
(debug "output_melt_descriptor curfil=" curfil " filix=" filix)
(add2sbuf_indentnl debuf 1)
(if curfil
(progn
(assert_msg "output_melt_descriptor check curfil"
(is_a curfil class_secondary_c_file))
(setq lastsecfileix filix)
(let ( (secpath (get_field :secfil_path curfil))
(secmd5s (string_hex_md5sum_pathstrv secpath))
)
(list_append pathlist secpath)
(list_append md5list secmd5s)
(add2sbuf_strconst debuf "/*sechexmd5checksum ")
(add2sbuf_ccomstring debuf secpath)
(add2sbuf_strconst debuf " #")
(add2sbuf_longdec debuf (get_int curfil))
(add2sbuf_strconst debuf " */ \"")
(add2sbuf_cencstring debuf secmd5s)
(add2sbuf_strconst debuf "\",")
(add2out secpathbuf " " secpath)
(add2out secmd5buf " " secmd5s)
;; make secondary dependencies
(add2out mkrulebuf "# dependencies for secondary " filix " of " modcident "\n")
(foreach_in_multiple
(flavortuple)
(curflav :long flavix)
(add2out mkrulebuf modprefstr "+"
(if (<i filix 10) "0" "")
filix "." secmd5s "." curflav ".meltpic.o: " modnamstr "+"
(if (<i filix 10) "0" "")
filix ".c" "\n")
)
))
(add2sbuf_strconst debuf "/*nosecfile*/ (const char*)0,")
)) ;end foreach secondary file
(add2sbuf_indentnl debuf 1)
(add2sbuf_strconst debuf "(const char*)0 };")
(add2sbuf_indentnl debuf 0)
;;
(add2sbuf_indentnl debuf 0)
(add2sbuf_strconst debuf "/* last index of secondary files */")
(add2sbuf_indentnl debuf 0)
(add2sbuf_strconst debuf "const int melt_lastsecfileindex=")
(add2sbuf_longdec debuf lastsecfileix)
(add2sbuf_strconst debuf ";")
(add2sbuf_indentnl debuf 0)
(add2out mkbuf "#secondary paths and checksums\n")
(add2out mkbuf "MELTGENMOD_SECONDARY_FILES_" modcident "=" (strbuf2string discr_string secpathbuf) "\n")
(add2sbuf_indentnl mkbuf 0)
(add2out mkbuf "MELTGENMOD_SECONDARY_MD5SUMS_" modcident "=" (strbuf2string discr_string secmd5buf) "\n")
(add2sbuf_indentnl mkbuf 0)
;;
(let ( (cumpathmds (string_hex_md5sum_path_sequence
(list_to_multiple pathlist)))
(midstr (make_string_nakedbasename
discr_string modnamstr))
(modidnam (let ( (mout (make_strbuf discr_strbuf))
)
(add2out mout "meltmod_")
(add2sbuf_cident mout midstr)
(add2out mout "_mds__")
(add2sbuf_cident mout cumpathmds)
(strbuf2string discr_string mout))
)
)
(assert_msg "check cumpathmds" (is_string cumpathmds))
;;
(add2out mkrulebuf "## dependency for descriptor object of " modnamstr "\n")
(add2out mkrulebuf modprefstr "." cumpathmds ".descriptor.meltpic.o: " modnamstr "+meltdesc.c "
modnamstr "+melttime.h\n")
;;
(add2out mkrulebuf "## dependency for modules " modnamstr "\n")
(foreach_in_multiple
(flavortuple)
(curflav :long flavix)
(add2out mkrulebuf "\n#### dependencies for flavor " curflav " of module " modnamstr "\n\n")
;; old flavored dependencies; the .meltmod is at end
(add2out mkrulebuf "\n## old fashion dependency for flavor " curflav " of module " modnamstr "\n")
(add2out mkrulebuf modprefstr "." cumpathmds "." curflav ".meltmod.so: \\\n"
" " modprefstr "." cumpathmds ".descriptor.meltpic.o "
)
(let ( (pathtup (list_to_multiple pathlist discr_multiple))
(md5tup (list_to_multiple md5list discr_multiple))
)
(assert_msg "check same length pathtup md5tup" (==i (multiple_length pathtup) (multiple_length md5tup)))
(foreach_in_multiple
(pathtup)
(curpath :long ix)
(let ( (curmd5 (multiple_nth md5tup ix))
)
(debug "output_melt_descriptor curpath=" curpath " ix=" ix " curmd5=" curmd5)
(add2out mkrulebuf " \\\n " "$(GCCMELTGEN_BUILD)" (make_string_nakedbasename discr_string curpath)
"." curmd5 "." curflav ".meltpic.o")
)
)
)
;; new flavored dependencies; the .meltmod- is before the md5sum
(add2out mkrulebuf "\n\n## new dependency for flavor " curflav " of module " modnamstr "\n")
(add2out mkrulebuf modprefstr ".meltmod-" cumpathmds "." curflav ".so: \\\n"
" " modprefstr "." cumpathmds ".descriptor.meltpic.o "
)
(let ( (pathtup (list_to_multiple pathlist discr_multiple))
(md5tup (list_to_multiple md5list discr_multiple))
)
(assert_msg "check same length pathtup md5tup" (==i (multiple_length pathtup) (multiple_length md5tup)))
(foreach_in_multiple
(pathtup)
(curpath :long ix)
(let ( (curmd5 (multiple_nth md5tup ix))
)
(debug "output_melt_descriptor curpath=" curpath " ix=" ix " curmd5=" curmd5)
(add2out mkrulebuf " \\\n " "$(GCCMELTGEN_BUILD)" (make_string_nakedbasename discr_string curpath)
"." curmd5 "." curflav ".meltpic.o")
)
)
)
(add2out mkrulebuf "\n\n")
) ;; end foreach flavortuple
;;
(add2out mkrulebuf "\n#end of generated dependencies for " modnamstr "\n\n")
(add2out mkbuf mkrulebuf)
(setq mkrulebuf ())
(add2out mkbuf "## cumulated checksum and naked name\n")
(add2out mkbuf "MELTGENMOD_CUMULATED_MD5SUM_" modcident "=" cumpathmds "\n")
(add2out mkbuf "MELTGENMOD_NAKED_NAME_" modcident "=" midstr "\n")
(add2sbuf_indentnl debuf 0)
(add2out
debuf
##{/* cumulated checksum of primary & secondary files */
const char melt_cumulated_hexmd5[]="$CUMPATHMDS" ;
/* include the timestamp file */
#define $MODIDNAM 1
#include "$MIDSTR+melttime.h"
}#
)
;;
;;
(add2sbuf_strconst tibuf "/** GENERATED MELT TIMESTAMP FILE ")
(add2sbuf_ccomstring tibuf modnamstr)
(add2sbuf_strconst tibuf "+melttime.h \n** NEVER EDIT OR MOVE THIS, IT IS GENERATED & PARSED! **/")
(add2sbuf_indentnl tibuf 0)
(add2sbuf_strconst tibuf "/* These identifiers are generated in warmelt-outobj.melt \n & handled in melt-runtime.c carefully. */")
(add2sbuf_indentnl tibuf 0)
(add2sbuf_indentnl tibuf 0)
(add2out tibuf ##{
/* This $MIDSTR+melttime.h is included from $MIDSTR+meltdesc.c only. */
#if $MODIDNAM
/* MELT generation timestamp for $MODNAMSTR */
#ifdef __cplusplus
/* these symbols are extern "C" since dlsym-ed */
extern "C" const char melt_gen_timestamp[] ;
extern "C" const long long melt_gen_timenum ;
extern "C" const char melt_build_timestamp[] ;
extern "C" {
#endif /*__cplusplus */
}#
)
(add2sbuf_indentnl tibuf 0)
(code_chunk
gentimch
#{ /* output_melt_descriptor $GENTIMCH + */ {
time_t now = 0 ;
char nowbuf[64] ;
time (&now) ;
memset (nowbuf, 0, sizeof(nowbuf)) ;
strftime (nowbuf, sizeof(nowbuf)-1, "%c %Z", localtime(&now)) ;
if (melt_flag_bootstrapping)
meltgc_add_strbuf ((melt_ptr_t) $TIBUF, "/*MELT BOOTSTRAP*/\n") ;
meltgc_add_strbuf ((melt_ptr_t) $TIBUF,
"const char melt_gen_timestamp[]=\"") ;
meltgc_add_strbuf_cstr ((melt_ptr_t) $TIBUF, nowbuf) ;
meltgc_add_strbuf ((melt_ptr_t) $TIBUF, "\";\n") ;
/* $GENTIMCH don't use time_t, it is not a predefined C type! */
meltgc_strbuf_printf ((melt_ptr_t) $TIBUF,
"const long long melt_gen_timenum=%lld;",
(long long) now) ;
} /* output_melt_descriptor $GENTIMCH - */}#)
(add2sbuf_indentnl tibuf 0)
(add2out tibuf ##{
const char melt_build_timestamp[]= __DATE__ "@" __TIME__
#ifdef __cplusplus
" (in C++)"
#else
" (in C)"
#endif /*__cplusplus*/
;
}#)
(add2sbuf_indentnl tibuf 0)
(add2out tibuf ##{
#ifdef __cplusplus
} /* end extern C timestamp */
#endif /*__cplusplus */
#else /* ! $MODIDNAM */
#error invalid timestamp file for $MODNAMSTR
#endif /* $MODIDNAM */
}#)
(add2sbuf_indentnl tibuf 0)
;;
(add2sbuf_indentnl debuf 0)
(add2out debuf ##{
#ifdef __cplusplus
} /* end extern C descriptor */
#endif /*__cplusplus */
}#)
(add2sbuf_indentnl debuf 0)
(add2sbuf_strconst debuf "/* end of melt descriptor file */")
(add2sbuf_indentnl debuf 0)
(add2out mkbuf "\n## eof of generated " modnamstr "+meltbuild.mk\n")
)
(let (
(meltdescpath (string4out discr_string modnamstr "+meltdesc.c"))
(melttimepath (string4out discr_string modnamstr "+melttime.h"))
(meltmakepath (string4out discr_string modnamstr "+meltbuild.mk"))
)
(debug "output_melt_descriptor meltdescpath=" meltdescpath
"\n* debuf=" debuf)
(debug "output_melt_descriptor melttimepath=" melttimepath
"\n* tibuf=" tibuf)
(debug "output_melt_descriptor meltmakepath=" meltmakepath
"\n* mkbuf=" mkbuf)
(output_sbuf_no_overwrite_strval debuf meltdescpath)
(output_sbuf_no_overwrite_strval tibuf melttimepath)
(output_sbuf_no_overwrite_strval mkbuf meltmakepath)
(debug "output_melt_descriptor final modctx=" modctx)
)
)
)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
(defselector syntax_test_generator
class_selector
:doc #{Selector to emit C syntax for testing purposes of a generator
device. Reciever is the representation -e.g. $CLASS_PRIMITIVE,
... $GENDEV is the generator device, $SBUF is the string buffer,
$MODCTX is the module context, and $IX is the index.}#
:formals (recv gendev sbuf modctx :long ix)
)
(defun syntestgen_any (recv gendev sbuf modctx :long ix)
(let ( (dis (discrim recv))
(disname (get_field :named_name dis))
(dloc (get_field :loca_location gendev))
)
(debug "syntestgen_any recv=" recv "\n* dis=" dis
"\n* gendev=" gendev
"\n* sbuf=" sbuf
"\n* modctx=" modctx
"\n* ix=" ix)
(error_strv dloc "unimplemented SYNTAX_TEST_GENERATOR method for " disname)
(assert_msg "check gendev" (is_a gendev class_source_generator_device))
(assert_msg "check sbuf" (is_strbuf sbuf))
(assert_msg "check modctx" (is_a modctx class_module_context))
(assert_msg "@$@unimplemented syntax_test_generator")
))
(install_method discr_any_receiver syntax_test_generator syntestgen_any)
(defun substitute_formals_for_syntest (sbuf replmap formals :cstring prefix)
(debug "substitute_formals_for_syntest sbuf=" sbuf "\n replmap=" replmap "\n* formals=" formals "\n prefix=" prefix)
(assert_msg "check sbuf" (is_strbuf sbuf))
(assert_msg "check replmap" (is_mapobject replmap))
(assert_msg "check formals" (is_multiple_or_null formals))
(foreach_in_multiple
(formals)
(curformal :long ix)
(debug "substitute_formals_for_syntest curformal=" curformal " ix=" ix)
(assert_msg "check curformal" (is_a curformal class_formal_binding))
(let ( (fsymb (get_field :binder curformal))
(ftype (get_field :fbind_type curformal))
(gensy (let ( (nambuf (make_strbuf discr_strbuf))
)
(add2out nambuf prefix ix "_")
(add2sbuf_cident nambuf (get_field :named_name fsymb))
(strbuf2string discr_verbatim_string nambuf)))
)
(mapobject_put replmap fsymb gensy)
(debug "substitute_formals_for_syntest updated replmap=" replmap "\n with fsymb=" fsymb "\n with gensy=" gensy)
(add2out sbuf (get_field :ctype_cname ftype) " " gensy " =0;")
(add2sbuf_indentnl sbuf 1)
))
)
(defun expand_tuple_for_syntest (sbuf replmap tup loc)
(debug "expand_tuple_for_syntest sbuf=" sbuf "\n replmap=" replmap "\n tup=" tup)
(foreach_in_multiple
(tup)
(curexpan :long pix)
(debug "expand_tuple_for_syntest curexpan=" curexpan)
(if (is_object curexpan)
(let ( (curepl (mapobject_get replmap curexpan))
)
(debug "expand_tuple_for_syntest curepl=" curepl)
(if curepl
(add2out sbuf curepl)
(let ( (curexpnam (get_field :named_name curexpan))
)
(debug "expand_tuple_for_syntest no curepl for curexpan=" curexpan " replmap=" replmap)
(warning_strv
loc "unexpected symbol in expansion [syntax check]" curexpnam)
)))
(add2out sbuf curexpan))
) ;;end foreach tup
(debug "expand_tuple_for_syntest done sbuf=" sbuf)
)
;;;;;;;;;;;;;;;;
(defun syntestgen_primitive (recv gendev sbuf modctx :long ix)
(debug "syntestgen_primitive recv=" recv " gendev=" gendev)
(assert_msg "check recv" (is_a recv class_primitive))
(assert_msg "check gendev" (is_a gendev class_source_generator_device))
(assert_msg "check sbuf" (is_strbuf sbuf))
(assert_msg "check modctx" (is_a modctx class_module_context))
(let ( (dloc (get_field :loca_location gendev))
(pridef (get_field :srcgen_defin gendev))
(prirep (get_field :srcgen_repr gendev))
(prinam (get_field :named_name recv))
(priformals (get_field :prim_formals recv))
(exploc (or (get_field :sprim_exploc pridef) dloc))
(pritype (get_field :prim_type recv))
(primexpan (get_field :prim_expansion recv))
(replmap (make_mapobject discr_map_objects
(+i 5 (*i 2 (multiple_length priformals)))))
)
(assert_msg "check pridef" (is_a pridef class_source_defprimitive))
(assert_msg "check prirep" (== prirep recv))
(add2out sbuf "/*primitive-syntax ")
(add2sbuf_ccomstring sbuf prinam)
(add2out sbuf "*/ {")
(add2sbuf_indentnl sbuf 1)
(substitute_formals_for_syntest sbuf replmap priformals "primf_")
;;
(if (!= pritype ctype_void)
(let ( (pritynam (get_field :ctype_cname pritype))
)
(add2out sbuf ##{$PRITYNAM primres_$IX = }#)
))
;;;
(if exploc (output_raw_location exploc sbuf 0 "primitive-syntax"))
(if (!= pritype ctype_void)
(add2out sbuf " "))
(debug "syntestgen_primitive primexpan=" primexpan)
(expand_tuple_for_syntest sbuf replmap primexpan exploc)
;;
(if (!= pritype ctype_void)
(let ( (pritynam (get_field :ctype_cname pritype))
)
(add2out sbuf ";")
(add2sbuf_indentnl sbuf 2)
(add2out sbuf ##{if (primres_$IX) return}#
)
))
(add2out sbuf ";")
(add2sbuf_indentnl sbuf 1)
(add2out sbuf "} /*end primitive-syntax ")
(add2sbuf_ccomstring sbuf prinam)
(add2out sbuf "*/")
(add2sbuf_indentnl sbuf 0)
))
(install_method class_primitive syntax_test_generator syntestgen_primitive)
;;;
;;;;;;;;;;;;;;;;
(defun syntestgen_citerator (recv gendev sbuf modctx :long ix)
(debug "syntestgen_citerator recv=" recv " gendev=" gendev)
(assert_msg "check recv" (is_a recv class_citerator))
(assert_msg "check gendev" (is_a gendev class_source_generator_device))
(assert_msg "check sbuf" (is_strbuf sbuf))
(assert_msg "check modctx" (is_a modctx class_module_context))
(let ( (dloc (get_field :loca_location gendev))
(citdef (get_field :srcgen_defin gendev))
(citrep (get_field :srcgen_repr gendev))
(citnam (get_field :named_name recv))
(citstaformals (get_field :citer_start_formals recv))
(citstate (get_field :citer_state recv))
(citbodformals (get_field :citer_body_formals recv))
(citexpbefo (get_field :citer_expbefore recv))
(citexpafte (get_field :citer_expafter recv))
(replmap (make_mapobject discr_map_objects (*i 2 (+i 3 (multiple_length citstaformals)))))
(repstatnam (let ( (nbuf (make_strbuf discr_strbuf))
)
(add2out nbuf "meltcitstate_" ix "_")
(add2sbuf_cident nbuf (get_field :named_name citstate))
(strbuf2string discr_verbatim_string nbuf)))
(befloc (or (get_field :sciterdef_beforeloc citdef) dloc))
(aftloc (or (get_field :sciterdef_afterloc citdef) dloc))
)
(assert_msg "check citdef" (is_a citdef class_source_defciterator))
(assert_msg "check citrep" (== citrep recv))
(add2out sbuf "/*citerator-syntax ")
(add2sbuf_ccomstring sbuf citnam)
(add2out sbuf "*/ {")
(add2sbuf_indentnl sbuf 1)
(if dloc (output_raw_location dloc sbuf 0 "citerator-syntax"))
(mapobject_put replmap citstate repstatnam)
(debug "syntestgen_citerator replmap=" replmap)
(substitute_formals_for_syntest sbuf replmap citstaformals "citstart_")
(substitute_formals_for_syntest sbuf replmap citbodformals "citbody_")
(if befloc (output_raw_location befloc sbuf 0 "citerator-syntax-before"))
(expand_tuple_for_syntest sbuf replmap citexpbefo befloc)
(debug "syntestgen_citerator after start formals replmap=" replmap)
(add2sbuf_indentnl sbuf 0)
(add2out sbuf "/**fictive body of citerator " repstatnam " **/")
(add2sbuf_indentnl sbuf 0)
(debug "syntestgen_citerator citbodformals=" citbodformals)
(foreach_in_multiple
(citbodformals)
(curbodformbind :long bodformix)
(debug "syntestgen_citerator curbodformbind=" curbodformbind)
(let (
(curbodformal (get_field :binder curbodformbind))
(nambodformal (mapobject_get replmap curbodformal))
)
(debug "syntestgen_citerator nambodformal=" nambodformal)
(assert_msg "check nambodformal" nambodformal)
(add2out sbuf "if (" NAMBODFORMAL ") return;")
(add2sbuf_indentnl sbuf 0)
))
(if aftloc (output_raw_location aftloc sbuf 0 "citerator-syntax-after"))
(expand_tuple_for_syntest sbuf replmap citexpafte aftloc)
(add2sbuf_indentnl sbuf 0)
(add2out sbuf "} /*end citerator-syntax ")
(add2sbuf_ccomstring sbuf citnam)
(add2out sbuf "*/")
(add2sbuf_indentnl sbuf 0)
))
(install_method class_citerator syntax_test_generator syntestgen_citerator)
;;;;;;;;;;;;;;;;
(defun syntestgen_cmatcher (recv gendev sbuf modctx :long ix)
(debug "syntestgen_cmatcher recv=" recv " gendev=" gendev)
(assert_msg "check recv" (is_a recv class_cmatcher))
(assert_msg "check gendev" (is_a gendev class_source_generator_device))
(assert_msg "check sbuf" (is_strbuf sbuf))
(assert_msg "check modctx" (is_a modctx class_module_context))
(let ( (dloc (get_field :loca_location gendev))
(cmatdef (get_field :srcgen_defin gendev))
(cmatrep (get_field :srcgen_repr gendev))
(cmatnam (get_field :named_name recv))
(cmatins (get_field :amatch_in recv))
(cmatbind (get_field :amatch_matchbind recv))
(cmatout (get_field :amatch_out recv))
(cmatstate (get_field :cmatch_state recv))
(cmattest (get_field :cmatch_exptest recv))
(cmatfill (get_field :cmatch_expfill recv))
(cmatoper (get_field :cmatch_expoper recv))
(testloc (or (get_field :scmatdef_testloc cmatdef) dloc))
(fillloc (or (get_field :scmatdef_fillloc cmatdef) dloc))
(operloc (or (get_field :scmatdef_operloc cmatdef) dloc))
(replmap (make_mapobject discr_map_objects
(+i 5 (*i 2 (+i (multiple_length cmatins)
(multiple_length cmatout))))))
(repstatnam (let ( (nbuf (make_strbuf discr_strbuf))
)
(add2out nbuf "cmatstate_" ix "_")
(add2sbuf_cident nbuf (get_field :named_name cmatstate))
(strbuf2string discr_verbatim_string nbuf)))
)
(add2out sbuf "/*cmatcher-syntax ")
(add2sbuf_ccomstring sbuf cmatnam)
(add2out sbuf "**/ {")
(add2sbuf_indentnl sbuf 1)
(mapobject_put replmap cmatstate repstatnam)
(substitute_formals_for_syntest sbuf replmap (tuple cmatbind) "cmatched_")
(substitute_formals_for_syntest sbuf replmap cmatins "cmatinput_")
(substitute_formals_for_syntest sbuf replmap cmatout "cmatoutput_")
(add2sbuf_indentnl sbuf 1)
(if testloc (output_raw_location testloc sbuf 0 "cmatcher-syntax-test"))
(add2out sbuf "if (/*cmatcher-test " cmatnam ":*/")
(expand_tuple_for_syntest sbuf replmap cmattest testloc)
(add2out sbuf "/*cmatcher-endtest*/) {")
(add2sbuf_indentnl sbuf 2)
(if fillloc (output_raw_location fillloc sbuf 0 "cmatcher-syntax-fill"))
(add2out sbuf "/*cmatcher-fill " cmatnam ":*/")
(add2sbuf_indentnl sbuf 2)
(expand_tuple_for_syntest sbuf replmap cmatfill fillloc)
(add2out sbuf ";")
(add2sbuf_indentnl sbuf 2)
(foreach_in_multiple
(cmatout)
(curmatoutbind :long outix)
(debug "syntestgen_cmatcher curmatoutbind=" curmatoutbind)
(let (
(curoutformal (get_field :binder curmatoutbind))
(namoutformal (mapobject_get replmap curoutformal))
)
(debug "syntestgen_cmatcher curmatoutbind=" curmatoutbind
" namoutformal=" namoutformal)
(assert_msg "check namoutformal " namoutformal)
(add2out sbuf "if (" NAMOUTFORMAL ") return;")
(add2sbuf_indentnl sbuf 2)
)
)
(add2out sbuf "} /*cmatcher-endfill " cmatnam " */ else return;")
(add2sbuf_indentnl sbuf 1)
(if cmatoper
(progn
(if operloc (output_raw_location operloc sbuf 0 "cmatcher-syntax-oper"))
(expand_tuple_for_syntest sbuf replmap
(tuple '"/*cmatcher-oper*/" (get_field :binder cmatbind) '" = ")
operloc)
(expand_tuple_for_syntest sbuf replmap cmatoper operloc)
(add2out sbuf ";")
(add2sbuf_indentnl sbuf 2)
))
(add2out sbuf "} /*end cmatcher-syntax ")
(add2sbuf_ccomstring sbuf cmatnam)
(add2out sbuf "**/")
(add2sbuf_indentnl sbuf 0)
))
(install_method class_cmatcher syntax_test_generator syntestgen_cmatcher)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun emit_syntax_testing_routine (gendevtup modctx sbuf)
(debug "emit_syntax_testing_routine gendevtup=" gendevtup
" sbuf=" sbuf)
(assert_msg "check gendevtup" (is_multiple gendevtup))
(assert_msg "check modctx" (is_a modctx class_module_context))
(assert_msg "check sbuf" (is_strbuf sbuf))
(let (
(:long nbgendev (multiple_length gendevtup))
(modnam (get_field :mocx_modulename modctx))
(syntestname
(let ( (nabuf (make_strbuf discr_strbuf)) )
(add2out nabuf "melt_syntax_tester_")
(add2sbuf_cident nabuf modnam)
(strbuf2string discr_verbatim_string nabuf)))
)
(debug "emit_syntax_testing_routine syntestname=" syntestname)
(assert_msg "check syntestname" (is_string syntestname))
(add2sbuf_indentnl sbuf 0)
(add2sbuf_indentnl sbuf 0)
(add2sbuf_indentnl sbuf 0)
(add2out sbuf "/****** emitted syntax checking for C generating devices *****/")
(add2sbuf_indentnl sbuf 0)
(add2out sbuf "#if MELT_HAVE_DEBUG")
(add2sbuf_indentnl sbuf 0)
(add2out
sbuf ##{
/* generated syntax checking routine for $NBGENDEV C generating devices */
MELT_EXTERN void MELT_MODULE_VISIBILITY $SYNTESTNAME (void);
void
$SYNTESTNAME (void) {
if (1) return;
}#)
(foreach_in_multiple
(gendevtup)
(curgendev :long gix)
(add2sbuf_indentnl sbuf 1)
(debug "emit_syntax_testing_routine curgendev=" curgendev "\n gix#" gix)
(assert_msg "check curgendev" (is_a curgendev class_source_generator_device))
(let ( (:long sucgix (+i gix 1))
(repr (get_field :srcgen_repr curgendev))
)
(add2sbuf_indentnl sbuf 0)
(add2out sbuf ##{/* generating device #$SUCGIX */}#)
(add2sbuf_indentnl sbuf 0)
(debug "emit_syntax_testing_routine before syntax_test_generator repr=" repr)
(syntax_test_generator repr curgendev sbuf modctx gix)
(debug "emit_syntax_testing_routine after syntax_test_generator repr=" repr "\n gix#" gix "\n")
)
(add2sbuf_indentnl sbuf 0)
) ;; end foreach gendevtup
(add2sbuf_indentnl sbuf 0)
(add2out
sbuf
##{} /* end generated $SYNTESTNAME */}#)
(add2sbuf_indentnl sbuf 0)
(add2out sbuf "#endif /*MELT_HAVE_DEBUG syntaxcheck*/")
(add2sbuf_indentnl sbuf 0)
(add2sbuf_indentnl sbuf 0)
))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; internal utility function to normalize & declare a macroexpanded list
;; return the normalized list, the declaration buffer, the start clock
(defun normadeclb_macroexpanded_list (xlist modnamstr modctx ncx inienv)
(debug "normadeclb_macroexpanded_list start xlist= " xlist
"\n* modnamstr=" modnamstr
"\n* modctx=" modctx
"\n* ncx=" ncx
"\n* inienv=" inienv)
(assert_msg "check xlist" (is_list xlist))
(assert_msg "check modnamstr" (is_string modnamstr))
(assert_msg "check modctx" (is_a modctx class_module_context))
(assert_msg "check ncx" (is_a ncx class_normalization_context))
(assert_msg "check inienv" (is_a inienv class_environment))
(debug "normadeclb_macroexpanded_list modctx=" modctx)
(let (
(:long startclock 0)
(normlist (list))
(declbuf (make_strbuf discr_strbuf))
(firstx (pair_head (list_first xlist)))
(firstloc (if (is_a firstx class_source) (get_field :loca_location firstx)))
(errorhdlr (get_field :mocx_errorhandler modctx))
(modinienv (get_field :mocx_initialenv modctx))
(iniproc (get_field :nctx_initproc ncx))
(cheadlist (get_field :mocx_cheaderlist modctx))
;; make an update_current_module_environment at the very beginning
(ucmeb1 (instance class_source_update_current_module_environment_container
:loca_location firstloc
:sucme_comment '"at very start"
))
)
(debug "normadeclb_macroexpanded_list modctx=" modctx)
(debug "normadeclb_macroexpanded_list @@cheadlist=" cheadlist)
(code_chunk startmodnam
#{ /* normadeclb_macroexpanded_list $STARTMODNAM */
#if HAVE_CLOCK
$STARTCLOCK = (long) clock () ;
#endif /*HAVE_CLOCK */
#if MELT_HAVE_DEBUG
inform (UNKNOWN_LOCATION,
"MELT [#%ld] generating C code of module %s",
melt_dbgcounter, melt_string_str ((melt_ptr_t) $MODNAMSTR)) ;
#else
inform (UNKNOWN_LOCATION,
"MELT generating C code of module %s",
melt_string_str ((melt_ptr_t) $MODNAMSTR)) ;
#endif /* MELT_HAVE_DEBUG */
}#)
(add2sbuf_indentnl declbuf 0)
;; special hack to copy the first comment before anything else,
;; practically useful to make the copyright comment appear really
;; early in generated declaration buffer.
(when (is_a firstx class_source_comment)
(list_popfirst xlist)
(let ( (sloc (unsafe_get_field :loca_location firstx))
(scomm (unsafe_get_field :scomm_str firstx))
)
(add2sbuf_indentnl declbuf 0)
(add2sbuf_strconst
declbuf
"/***************************************************")
(add2sbuf_indentnl declbuf 0)
(add2sbuf_ccomstring declbuf scomm)
(add2sbuf_indentnl declbuf 0)
(add2sbuf_strconst
declbuf
"****************************************************/")
(add2sbuf_indentnl declbuf 0)
(add2sbuf_indentnl declbuf 0)
)
)
(debug "normadeclb_macroexpanded_list modctx=" modctx
"\n with @@cheadlist=" cheadlist)
;; only warmelt-first.melt gets a zeroed MELT_HAS_INITIAL_ENVIRONMENT
(if modinienv
(progn
(debug "normadeclb_macroexpanded_list usual modinienv=" modinienv)
(add2sbuf_strconst declbuf "/* ordinary MELT module */")
(add2sbuf_indentnl declbuf 0)
(add2sbuf_strconst declbuf "#define MELT_HAS_INITIAL_ENVIRONMENT 1 /*usual*/"))
(progn
(debug "normadeclb_macroexpanded_list initial modinienv=" modinienv)
(add2sbuf_strconst declbuf "/* initial MELT module */")
(add2sbuf_indentnl declbuf 0)
(code_chunk check_warmelt_first_bootstrapping_chunk #{
/* $CHECK_WARMELT_FIRST_BOOTSTRAPPING_CHUNK */
melt_checkmsg ("bootstrapping first file",
melt_flag_bootstrapping
&& melt_string_str((melt_ptr_t) $MODNAMSTR)
&& strstr(melt_string_str((melt_ptr_t) $MODNAMSTR), "first")) ;
}#)
;; lack of initial environment happens only in translateinit mode for warmelt-first.melt
(add2sbuf_strconst declbuf "#define MELT_HAS_INITIAL_ENVIRONMENT 0 /*initial*/")))
;;
(add2sbuf_indentnl declbuf 0)
(add2sbuf_indentnl declbuf 0)
(add2sbuf_strconst declbuf "struct melt_callframe_st; /*defined in melt-runtime.h*/")
(add2sbuf_indentnl declbuf 0)
(add2sbuf_indentnl declbuf 0)
(list_prepend xlist ucmeb1)
;;
;; we need to normalize now, because cheaders are handled by normalization
(list_every
xlist
(lambda (sexp :long ix)
(debug "normadeclb_macroexpanded_list sexp=" sexp " ix=" ix)
(let (
(psloc (if (is_a sexp class_located) (unsafe_get_field :loca_location sexp)))
)
;; special hack to handle toplevel comments specially; the generated comment goes into the declbuf
;; practically useful to copy a copyright notice into the generated C code
(if (is_a sexp class_source_comment)
(let ( (sloc (unsafe_get_field :loca_location sexp))
(scomm (unsafe_get_field :scomm_str sexp))
)
(add2sbuf_indentnl declbuf 0)
(add2sbuf_strconst declbuf "/**!!** ")
(add2sbuf_ccomstring declbuf scomm)
(add2sbuf_strconst declbuf "**!!**/")
(add2sbuf_indentnl declbuf 0)
)
;;; otherwise, normalize etc.
(multicall
(nexp nbind)
(normal_exp sexp inienv ncx psloc)
(debug "normadeclb_macroexpanded_list nexp=" nexp " nbind=" nbind)
(if (and (is_a nexp class_nrep)
(not (is_a nexp class_nrep_anyproc)))
(let ( (wnexp (wrap_normal_let1 nexp nbind psloc)) )
(debug "normadeclb_macroexpanded_list wnexp=" wnexp)
(list_append (unsafe_get_field :ninit_topl iniproc)
wnexp)
))
(list_append normlist nexp)
)))))
(debug "normadeclb_macroexpanded_list @@cheadlist=" cheadlist "\n modctx=" modctx)
;; handle cheaders, should be done after normalization which is filling cheadlist
(let (
(cheadtup (list_to_multiple cheadlist discr_multiple))
(:long nbchead (multiple_length cheadtup))
)
(debug "normadeclb_macroexpanded_list cheadtup=" cheadtup "\n nbchead=" nbchead
"\n @@cheadlist=" cheadlist)
(if (>i nbchead 0)
(progn
(add2sbuf_indentnl declbuf 0)
(add2sbuf_indentnl declbuf 0)
(add2out declbuf ##{/***** $NBCHEAD extra C headers *****/}#)
(add2sbuf_indentnl declbuf 0)
(add2sbuf_indentnl declbuf 0)
(foreach_in_multiple
(cheadtup)
(curchead :long hix)
(debug "normadeclb_macroexpanded_list curchead=" curchead " hix=" hix)
(assert_msg "check curchead" (is_a curchead class_source_cheader))
(add2sbuf_indentnl declbuf 0)
(add2out declbuf ##{/** header #$HIX: **/}#)
(add2sbuf_indentnl declbuf 0)
(let ( (hloc (get_field :loca_location curchead))
(chstr (get_field :scheader_codestring curchead))
)
(if hloc
(output_raw_location hloc declbuf 0 "cheader"))
(add2out declbuf chstr)
(add2sbuf_indentnl declbuf 0)
)
)
(add2sbuf_indentnl declbuf 0)
(add2sbuf_indentnl declbuf 0)
(add2out declbuf ##{/***** end of $NBCHEAD extra C headers *****/}#)
(add2sbuf_indentnl declbuf 0)
(add2sbuf_indentnl declbuf 0)
))
(debug "normadeclb_macroexpanded_list @@cheadlist=" cheadlist)
)
;;
(assert_msg "check iniproc" (is_a iniproc class_nrep_initproc))
(assert_msg "check xlist" (is_list xlist))
;;
(return normlist declbuf startclock)
))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; utility function to translate a macroexpanded list
(defun translate_macroexpanded_list (xlist modnamstr modctx ncx inienv normalisthandler iniproctransl)
;; XLIST is the list of macro-expanded things, usually instances of
;; subclasses of class_source
;;
;; MODNAMSTR is the name string of the module
;;
;; MODCTX is the module generation context of class_module_context
;;
;; NCX is the normalization context, of class_normalization_context
;;
;; INIENV is the initial environment, of class_environment
;;
;; NORMALISTHANDLER is null or a closure to post-process the
;; normalized list
;;
;; INIPROCTRANSL is the translator of the initial routine
;;
;;;;;;;;;;;;;;;;
(debug "translate_macroexpanded_list modnamstr=" modnamstr "\n* modctx=" modctx
"\n* inienv=" inienv
"\n* iniproctransl=" iniproctransl)
(assert_msg "check xlist" (is_list xlist))
(assert_msg "check modnamstr" (is_string modnamstr))
(assert_msg "check modctx" (is_a modctx class_module_context))
(assert_msg "check ncx" (is_a ncx class_normalization_context))
(assert_msg "check inienv" (is_a inienv class_environment))
(assert_msg "translate_macroexpanded_list modulename not ended with MELT_DYNLOADED_SUFFIX."
(not (string_dynloaded_suffixed modnamstr)))
(assert_msg "translate_macroexpanded_list modulename not ended with .melt"
(not (string_suffixed modnamstr ".melt")))
(assert_msg "translate_macroexpanded_list modulename not ended with .c"
(not (string_suffixed modnamstr ".c")))
(let (
(:long endclock 0)
(errorhdlr (get_field :mocx_errorhandler modctx))
(gendevlist (get_field :mocx_gendevlist modctx))
(modinienv (get_field :mocx_initialenv modctx))
(iniproc (get_field :nctx_initproc ncx))
(implbuf (make_strbuf discr_strbuf))
)
(debug "translate_macroexpanded_list modinienv=" modinienv " modnamstr=" modnamstr
" before normadeclb_macroexpanded_list modctx=" modctx)
(multicall
(normlist declbuf :long startclock)
(normadeclb_macroexpanded_list xlist modnamstr modctx ncx inienv)
(assert_msg "check normlist" (is_list normlist))
(assert_msg "check declbuf" (is_strbuf declbuf))
(debug "translate_macroexpanded_list after normadeclb_macroexpanded_list modctx=" modctx
"\n normalisthandler=" normalisthandler)
(when (is_closure normalisthandler)
(debug "translate_macroexpanded_list before calling normalisthandler normlist=" normlist)
(normalisthandler normlist modctx ncx inienv)
(debug "translate_macroexpanded_list after calling normalisthandler normlist=" normlist)
)
;;
;;
(when (melt_error_counter)
(if (is_closure errorhdlr)
(errorhdlr '"MELT translation failed after normalization"))
(code_chunk errorednormal_warnchk
#{ /* translate_macroexpanded_list $ERROREDNORMAL_WARNCHK */
warning (0, "MELT translation of %s got after normalization %ld MELT errors",
melt_string_str((melt_ptr_t) $MODNAMSTR), melt_error_counter) ;
}#)
(return))
;;
;;
(let ( (prolist (unsafe_get_field :nctx_proclist ncx))
(objlist (make_list discr_list))
(compicache (make_mapobject discr_map_objects (+i 10 (*i 20 (list_length xlist)))))
(countbox (make_integerbox discr_integer 0))
)
(debug "translate_macroexpanded_list prolist=" prolist)
;;
;; compile each procedure and check for errors
(assert_msg "check prolist" (is_list prolist))
(list_every
prolist
(lambda (pro)
(assert_msg "check pro" (is_a pro class_nrep_anyproc))
(put_int countbox (+i (get_int countbox) 1))
(let ( (objpro (compile2obj_procedure pro modctx compicache (get_int countbox))) )
(debug "translate_macroexpanded_list objpro=" objpro " pro=" pro)
(list_append objlist objpro)
)))
(when (melt_error_counter)
(if (is_closure errorhdlr)
(errorhdlr '"MELT translation failed after generation"))
(code_chunk erroredgener_warnchk
#{ /* translate_macroexpanded_list $ERROREDGENER_WARNCHK */
warning (0, "MELT translation of %s got after generation %ld MELT errors",
melt_string_str((melt_ptr_t) $MODNAMSTR), melt_error_counter) ;
}#)
(return))
;;
;; compile the initial procedure
(assert_msg "check objlist" (is_list objlist))
(let ( (inipro (unsafe_get_field :nctx_initproc ncx))
(inidata (unsafe_get_field :nctx_datalist ncx))
(importvalues (unsafe_get_field :nctx_valuelist ncx))
(procurmodenvlist (unsafe_get_field :nctx_procurmodenvlist ncx))
)
(debug "translate_macroexpanded_list before compiling initproc inipro=" inipro
"\n iniproctransl=" iniproctransl)
(assert_msg "check inipro" (is_a inipro class_nrep_initproc))
(assert_msg "check iniproctransl" (is_closure iniproctransl))
(let ( (iniobj
(iniproctransl inipro modctx inidata compicache procurmodenvlist importvalues))
)
;;
(foreach_in_list
(objlist)
(pairel obel)
(debug "translate_macroexpanded_list obel=" obel)
;; we do want to generate several C files...
(let ( (:long filnum
(if (is_a obel class_procroutineobj)
(get_int (get_field :oprout_filenum obel))))
(secfil
(if filnum (nth_secundary_file modctx modnamstr declbuf filnum)))
(outimplbuf
(if secfil (get_field :secfil_implbuf secfil) implbuf))
)
(output_c_code obel declbuf outimplbuf 0)))
;;;
(debug "translate_macroexpanded_list final modnamstr=" modnamstr " iniobj=" iniobj)
(add2sbuf_indentnl implbuf 0)
(add2sbuf_indentnl implbuf 0)
;;;;; emit the syntax generator
(let ( (gendevtup (list_to_multiple gendevlist discr_multiple))
(:long nbgendev (multiple_length gendevtup))
)
(debug "translate_macroexpanded_list before emit_syntax_testing_routine gendevtup=" gendevtup
" gendevlist=" gendevlist)
(if nbgendev
(emit_syntax_testing_routine gendevtup modctx implbuf)
(add2sbuf_strconst implbuf "/*no syntax testing generated*/")
))
;;
(add2sbuf_indentnl implbuf 0)
;;;; emit the initial routine
(output_c_code iniobj declbuf implbuf 0)
(output_exported_offsets modctx declbuf implbuf)
;; output warnings if the buffer are half the limit
(if (>i (strbuf_usedlength declbuf) (/iraw (get_int !buffer_limit_cont) 2))
(warningmsg_strv "very large declaration string buffer for module " modnamstr))
(if (>i (strbuf_usedlength implbuf) (/iraw (get_int !buffer_limit_cont) 2))
(warningmsg_strv "very large implementation string buffer module for " modnamstr))
;;
(code_chunk outputcfile
#{ /* translate_macroexpanded_list $OUTPUTCFILE: */
melt_output_cfile_decl_impl
((melt_ptr_t)($MODNAMSTR),
(melt_ptr_t)($DECLBUF),
(melt_ptr_t)($IMPLBUF)) ;
}#)
;;(informsg_strv "warmelt generated module C file" modnamstr)
(let ( (secfiles (get_field :mocx_filetuple modctx))
(:long nbsecfiles 0)
(:long lgsecfiles (multiple_length secfiles))
(:long hisecfilerk 0)
)
(debug "translate_macroexpanded_list secfiles=" secfiles)
(foreach_in_multiple
(secfiles)
(curfil :long filix)
(if curfil
(progn
(assert_msg "check curfil"
(is_a curfil class_secondary_c_file))
(assert_msg "check curfil index"
(==i (get_int curfil) filix))
(setq hisecfilerk filix)
(increment nbsecfiles 1)
;;(setq nbsecfiles (+i nbsecfiles 1))
(let ( (secfilpath (get_field :secfil_path curfil))
(secdeclbuf (get_field :secfil_declbuf curfil))
(secimplbuf (get_field :secfil_implbuf curfil))
)
;; output warnings if the buffer are half the limit
(if (>i (strbuf_usedlength secdeclbuf) (/iraw (get_int !buffer_limit_cont) 2))
(warningmsg_strv "very large declaration string buffer for secondary file " secfilpath))
(if (>i (strbuf_usedlength secimplbuf) (/iraw (get_int !buffer_limit_cont) 2))
(warningmsg_strv "very large implementation string buffer for secondary file " secfilpath))
;;
(code_chunk
secfilout
#{ /* translate_macroexpanded_list $SECFILOUT: */
melt_output_cfile_decl_impl_secondary
((melt_ptr_t)($SECFILPATH),
(melt_ptr_t)($SECDECLBUF),
(melt_ptr_t)($SECIMPLBUF),
$FILIX) ;
}#)
;;(informsg_strv "warmelt generated secondary C file" secfilpath)
))
))
;;
;; output the descriptive C file
(debug "translate_macroexpanded_list before output descrfil modctx=" modctx)
(output_melt_descriptor modnamstr secfiles modctx)
;; remove the old extra files
(foreach_long_upto
((+i hisecfilerk 1) (+i hisecfilerk 25))
(:long delfilix)
(if (>i delfilix 0)
(let ( (delfilnam (generated_c_filename discr_string modnamstr () delfilix))
(baksbuf (make_strbuf discr_strbuf))
)
(add2out baksbuf delfilnam "~")
(let ( (bakfilnam (strbuf2string discr_string baksbuf))
)
(debug "translate_macroexpanded_list delfilix=" delfilix)
(code_chunk
backupchk
#{ /*translate_macroexpanded_list $BACKUPCHK*/ {
const char* $BACKUPCHK#_delfilnamstr =
melt_string_str ((melt_ptr_t) $DELFILNAM) ;
const char* $BACKUPCHK#_bakfilnamstr =
melt_string_str ((melt_ptr_t) $BAKFILNAM) ;
if ($BACKUPCHK#_delfilnamstr && $BACKUPCHK#_bakfilnamstr
&& !access ($BACKUPCHK#_delfilnamstr, F_OK)) {
if (!rename ($BACKUPCHK#_delfilnamstr, $BACKUPCHK#_bakfilnamstr))
inform (UNKNOWN_LOCATION, "MELT backing up previous generated file %s as %s",
$BACKUPCHK#_delfilnamstr, $BACKUPCHK#_bakfilnamstr) ;
}
$BACKUPCHK#_delfilnamstr = NULL ;
$BACKUPCHK#_bakfilnamstr = NULL ;
} /*end translate_macroexpanded_list $BACKUPCHK*/ }#)
))))
;;
(debug "translate_macroexpanded_list before endmodnamchk modctx=" modctx)
(code_chunk
endmodnam
#{ /* translate_macroexpanded_list $ENDMODNAM */
#if HAVE_CLOCK && defined (CLOCKS_PER_SEC)
$ENDCLOCK = (long) clock () ;
if (melt_flag_bootstrapping)
inform (UNKNOWN_LOCATION,
"MELT generated C code of module %s with %ld secondary files in %ld CPU millisec [#%ld].",
melt_string_str ((melt_ptr_t) $MODNAMSTR), $NBSECFILES,
($ENDCLOCK - $STARTCLOCK) / (CLOCKS_PER_SEC/1000), melt_dbgcounter) ;
else
inform (UNKNOWN_LOCATION,
"MELT generated C code of module %s with %ld secondary files in %ld CPU millisec.",
melt_string_str ((melt_ptr_t) $MODNAMSTR), $NBSECFILES,
($ENDCLOCK - $STARTCLOCK) / (CLOCKS_PER_SEC/1000)) ;
#else /* no clock */
inform (UNKNOWN_LOCATION,
"MELT generated C code of module %s with %ld secondary files",
melt_string_str ((melt_ptr_t) $MODNAMSTR), $NBSECFILES) ;
#endif /* HAVE_CLOCK && CLOCKS_PER_SEC */
/* end translate_macroexpanded_list $ENDMODNAM */ }#)
(debug "translate_macroexpanded_list ending modctx=" modctx)
(shortbacktrace_dbg "translate_macroexpanded_list ended" 25)
(when (melt_error_counter)
(if (is_closure errorhdlr)
(errorhdlr '"MELT translation failed after C code emission"))
(code_chunk errorednormal_warnchk
#{ /* translate_macroexpanded_list $ERROREDNORMAL_WARNCHK */
warning (0, "MELT translation of %s got after emission %ld MELT errors",
melt_string_str((melt_ptr_t) $MODNAMSTR), melt_error_counter) ;
}#)
(return))
)))))))
;; utility to handle compilation errors as fatal ones
(defun fatal_compile_error (modnamstr v)
(if (is_string v)
(code_chunk
fatalerrormsg_chk
#{ /*fatal_compile_error $FATALERRORMSG_CHK */
melt_fatal_error ("MELT failed to compile module %s (%ld errors): %s",
melt_string_str ((melt_ptr_t) $MODNAMSTR),
melt_error_counter,
melt_string_str ((melt_ptr_t) $V)) ;
}#)
(code_chunk
fatalerror_chk
#{ /* fatal_compile_error $FATALERROR_CHK */
melt_fatal_error ("MELT failed to compile module %s (%ld errors)",
melt_string_str ((melt_ptr_t) $MODNAMSTR),
melt_error_counter) ;
}#))
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; compile a list of sexpressions as a module starting from a given environment
(defun compile_list_sexpr (lsexp inienv modnamstr)
(message_dbg "starting compile_list_sexpr")
(debug "@*@@@@ compile_list_sexpr lsexp=" lsexp "\n@ compile_list_sexpr inienv=" inienv
"\n@ compile_list_sexpr modnamstr=" modnamstr)
(assert_msg "check lsexp" (is_list lsexp))
(assert_msg "check modnamstr" (is_string modnamstr))
(assert_msg "check inienv" (or (null inienv) (is_a inienv class_environment)))
(assert_msg "compile_list_sexpr modulename not ended with MELT_DYNLOADED_SUFFIX."
(not (string_dynloaded_suffixed modnamstr)))
(assert_msg "compile_list_sexpr modulename not ended with .melt"
(not (string_suffixed modnamstr ".melt")))
(assert_msg "compile_list_sexpr modulename not ended with .c"
(not (string_suffixed modnamstr ".c")))
(let (
(modnakedname (make_string_nakedbasename discr_string modnamstr))
(modctx (instance class_module_context
:mocx_modulename modnakedname
:mocx_expfieldict (make_mapstring discr_map_strings 390)
:mocx_expclassdict (make_mapstring discr_map_strings 140)
:mocx_initialenv inienv
:mocx_funcount (make_integerbox discr_integer 0)
:mocx_filetuple ()
:mocx_cheaderlist (make_list discr_list)
;; :mocx_cflags (make_list discr_list)
;; :mocx_linkflags (make_list discr_list)
:mocx_packagepclist (make_list discr_list)
:mocx_gendevlist (make_list discr_list)
:mocx_errorhandler (lambda (v) (fatal_compile_error modnamstr v))
))
(ncx (create_normcontext modctx))
)
(debug "compile_list_sexpr modctx=" modctx
"\n of class " (discrim modctx))
;; is it very unusual that inienv is null, only happenning in
;; translateinit mode, when bootstrapping warmelt-first.melt
(when (null inienv)
(code_chunk
checkbootstrapping_chk
#{ /* $CHECKBOOTSTRAPPING_CHK */
if (!melt_flag_bootstrapping)
melt_fatal_error ("lack of initial environment can only happen during MELT bootstrapping in module %s",
melt_string_str ((melt_ptr_t) $MODNAKEDNAME)) ;
}#)
;; we set inienv to be able to macroexpand and translate the rest. However, mocx_initialenv is null.
(setq inienv initial_environment))
(debug "compile_list_sexpr initial ncx=" ncx)
(assert_msg "check ncx" (is_a ncx class_normalization_context))
(let ( (xlist (macroexpand_toplevel_list lsexp inienv macroexpand_1 modctx))
(:long lenxlist (list_length xlist))
)
(debug "compile_list_sexpr after macroexpansion modctx=" modctx)
;;
(if (<=i lenxlist 3)
(code_chunk warnshortchk
#{/* compile_list_sexpr $WARNSHORTCHK*/
warning (0, "MELT expanded few (%d) expressions", (int) $LENXLIST) ;
}#))
(debug "compile_list_sexpr before translation modctx=" modctx)
;;
(translate_macroexpanded_list xlist modnamstr modctx ncx inienv () compile2obj_initproc)
(debug "compile_list_sexpr after translation modctx=" modctx)
)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun translate_run_melt_expressions (exprs env)
:doc #{Translate and run the MELT s-expressions from $EXPRS in the
$ENV environment, which can be modified, e.g. by definitions inside
the $EXPRS. The last expression should preferably gives a value,
which is returned...}#
(debug "translate_run_melt_expressions start exprs=" exprs "\n*env=" env)
(when (null exprs)
(debug "translate_run_melt_expressions gets and gives null")
(return ()))
(assert_msg "check env" (is_a env class_environment))
(let ( (:long num 0)
(:long starterrcount (melt_error_counter))
(nakedbasnam ())
(referr (instance class_reference))
)
(code_chunk numchk #{/* translate_run_melt_expressions $NUMCHK */ static long num_$NUMCHK ;
char basbuf_$NUMCHK[64] ;
memset (basbuf_$NUMCHK, 0, sizeof(basbuf_$NUMCHK)) ;
num_$NUMCHK++ ;
$NUM = num_$NUMCHK ;
snprintf (basbuf_$NUMCHK, sizeof(basbuf_$NUMCHK),
"MELTrun%04lx", num_$NUMCHK) ;
$NAKEDBASNAM = meltgc_new_string_raw_len ((meltobject_ptr_t)MELT_PREDEF (DISCR_STRING),
basbuf_$NUMCHK, -1) ;
}#)
(debug "translate_run_melt_expressions nakedbasnam=" nakedbasnam " num=" num " starterrcount=" starterrcount)
(let (
(runerrorhdlr (lambda (v)
(debug "runerrorhdlr v=" v)
(cond
((is_string v)
(code_chunk warnrunstr_chk
#{ /* translate_run_melt_expressions $WARNRUNSTR_chk */
warning (0, "MELT running expression {%s} error - %s",
melt_string_str ((melt_ptr_t) $NAKEDBASNAM),
melt_string_str ((melt_ptr_t) $V)) ; }#
))
(:else
(code_chunk warnrun_chk
#{ /* translate_run_melt_expressions $WARNRUN_chk */
warning (0, "MELT running expression {%s} errored",
melt_string_str ((melt_ptr_t) $NAKEDBASNAM)) ; }#
))
)
(set_ref referr (or v :true))))
(modctx (instance class_running_extension_module_context
:mocx_modulename nakedbasnam
:mocx_expfieldict (make_mapstring discr_map_strings 71)
:mocx_expclassdict (make_mapstring discr_map_strings 19)
:mocx_initialenv env
:mocx_funcount (make_integerbox discr_integer 0)
:mocx_filetuple ()
:mocx_cheaderlist (make_list discr_list)
;; :mocx_cflags (make_list discr_list)
;; :mocx_linkflags (make_list discr_list)
:mocx_packagepclist (make_list discr_list)
:mocx_gendevlist (make_list discr_list)
:mocx_errorhandler runerrorhdlr
:morcx_litervalist (list ())
:morcx_countlitval (make_integerbox discr_integer 1)
:morcx_literobjmap (make_mapobject discr_map_objects 53)
))
(ncx (create_normal_extending_context modctx env))
(lsexp
(let
( (ls (make_list discr_list))
(addexp
(lambda (curexp :long ix)
(cond
((null curexp)
(void))
((is_a curexp class_sexpr)
(list_append ls curexp))
((is_a curexp class_symbol)
(list_append ls curexp))
((is_string curexp)
(list_append ls curexp))
((is_integerbox curexp)
(list_append ls curexp))
((is_closure curexp)
(debug "translate_run_melt_expressions closure curexp=" curexp " ix=" ix)
(curexp ls))
(:else
(debug "translate_run_melt_expressions bad curexp=" curexp " ix=" ix)
(let ( (curdis (discrim curexp))
(curdisname (get_field :named_name curdis))
)
(code_chunk badexp_chk
#{ /* translate_run_melt_expressions $BADEXP_CHK */
warning (0, "MELT run %s expression #%d has bad disciminant %s",
melt_string_str ((melt_ptr_t) $NAKEDBASNAM),
1+(int) $IX,
melt_string_str ((melt_ptr_t) $CURDISNAME)) ;
}#)
(runerrorhdlr '"Bad expression")))
)
))
)
(cond
((null exprs)
(void))
((is_multiple exprs)
(foreach_in_multiple
(exprs)
(curexp :long ix)
(addexp curexp ix)
))
((is_list exprs)
(let ((:long ix 0))
(foreach_in_list
(exprs)
(curpair curexp)
(setq ix (-i ix 1))
(addexp curexp ix))))
((is_a exprs class_sexpr)
(addexp exprs -999999))
(:else
(runerrorhdlr '"No expressions")))
ls))
)
;;macro expand
(debug "translate_run_melt_expressions modctx=" modctx "\n ncx=" ncx "\n lsexp=" lsexp)
(when !referr
(runerrorhdlr '"runtime invalid expressions")
(return () ()))
(let ( (xlist (macroexpand_toplevel_list lsexp env macroexpand_1 modctx))
(:long lenxlist (list_length xlist))
;; normalextend should ensure that the last normal gives a value
(normalextend
(lambda (normlist modctx ncx inienv)
(debug "translate_run_melt_expressions/normalextend normlist=" normlist)
(let ( (lastnorm (list_last_element normlist))
(lastctyp (get_ctype lastnorm inienv))
)
(debug "translate_run_melt_expressions/normalextend lastnorm=" lastnorm " lastctyp=" lastctyp)
;; we really should box the last stuff and return
;; the boxed value
(when (!= lastctyp ctype_value)
(warningmsg_strv
"runtime expressions don't end with a :value giving expression, appending () to them."
(get_field :named_name lastctyp))
(list_append normlist (instance class_nrep_nil))
(debug "translate_run_melt_expressions/normalextend updated normlist=" normlist)
)
)))
)
(debug "translate_run_melt_expressions xlist=" xlist)
(when (or (notnull !referr) (>i (melt_error_counter) starterrcount))
(runerrorhdlr '"runtime macroexpansion failed")
(return () ()))
(let ( (basename (make_string_tempname_suffixed discr_string nakedbasnam "_eXt"))
)
(debug "translate_run_melt_expressions basename=" basename)
;; translate to C code
(translate_macroexpanded_list xlist basename modctx ncx env
normalextend compile2obj_initextendproc)
(debug "translate_run_melt_expressions after translation to nakedbasnam=" nakedbasnam)
(when (or (notnull !referr) (>i (melt_error_counter) starterrcount))
(runerrorhdlr '"runtime translation to code failed")
(return () ()))
;; should now compile the generated C code
;; FIXME: we should have a runbuilt flavor.... (also in the
;; runtime and the melt-module.mk)
(debug "translate_run_melt_expressions before compiling quicklybuilt flavor of basename=" basename)
(generate_flavored_melt_module basename basename '"quicklybuilt")
(debug "translate_run_melt_expressions after compiling quicklybuilt flavor of basename=" basename)
(assert_msg "@$@translate_run_melt_expressions incomplete")
)))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; recursive internal utility to read melt expressions from files or lists or vectors or s-exprs
(defun read_melt_expressions (src rlist :long depth)
(debug "read_melt_expressions src=" src " depth=" depth " rlist.len=" (list_length rlist))
(assert_msg "check rlist" (is_list rlist))
(assert_msg "check depth" (<i depth 100))
(cond
((null src)
(return))
((is_string src)
(informsg_strv "reading from MELT file source" src)
(list_append2list rlist (read_file src)))
((is_list src)
(foreach_in_list
(src)
(curpair cursrc)
(read_melt_expressions cursrc rlist (+i depth 1))))
((is_multiple src)
(foreach_in_multiple
(src)
(cursrc :long six)
(read_melt_expressions cursrc rlist (+i depth 1))))
((is_object src)
(list_append rlist src))
((is_closure src)
(let ( (xsrc (src rlist (+i depth 1)))
)
(debug "read_melt_expressions xsrc=" xsrc " depth=" depth)
(if (null xsrc) (return))
(assert_msg "check xsrc" (or (is_a xsrc class_sexpr) (is_a xsrc class_symbol)))
(list_append rlist xsrc)))
(:else
(error_strv () "invalid MELT expression to read, with discriminant"
(get_field :named_name (discrim src))))
))
;;;;;;;;;;;;;;;;
;;;;; utility function to translate to C some MELT sources
;;; modsrcname is the string for the module source file path; its
;;; basename should not contains any dots
(defun translate_to_c_module_melt_sources (sources modsrcname curenv)
(debug "translate_to_c_module_melt_sources sources=" sources " modsrcname=" modsrcname)
(assert_msg "check curenv" (is_a curenv class_environment))
(assert_msg "check modsrcname" (is_string modsrcname))
(if (or (string_dynloaded_suffixed modsrcname)
(string_suffixed modsrcname ".melt")
(string_suffixed modsrcname ".c"))
(errormsg_strv "invalid MELT source name - should not be suffixed"
modsrcname))
(assert_msg "translate_to_c_module_melt_sources modsrcname not ended with MELT_DYNLOADED_SUFFIX"
(not (string_dynloaded_suffixed modsrcname)))
(assert_msg "translate_to_c_module_melt_sources modulename not ended with .melt"
(not (string_suffixed modsrcname ".melt")))
(assert_msg "translate_to_c_module_melt_sources modulename not ended with .c"
(not (string_suffixed modsrcname ".c")))
(let ( (:long isvalidmodsrc 0)
(rlist (make_list discr_list))
)
(code_chunk
setisvalidmodsrcch
#{ /* translate_to_c_module_melt_sources $SETISVALIDMODSRCCH */ {
const char* modsrcstr = melt_string_str ((melt_ptr_t) $MODSRCNAME);
const char* modsrcbase = modsrcstr ? (lbasename (modsrcstr)) : NULL;
if (modsrcbase)
$ISVALIDMODSRC =
(strchr(modsrcbase,'.') == NULL) && (strchr(modsrcbase,'+') == NULL);
} /* end translate_to_c_module_melt_sources $SETISVALIDMODSRCCH */
}#)
(if (not isvalidmodsrc)
(progn
(debug "translate_to_c_module_melt_sources bad generated modsrcname=" modsrcname)
(errormsg_strv
"invalid generated source name [basename should have no dot or plus]"
modsrcname)
(return)
))
(read_melt_expressions sources rlist 0)
(debug "after read translate_to_c_module_melt_sources rlist=" rlist)
(assert_msg "check non empty rlist" (>i (list_length rlist) 0))
(compile_list_sexpr rlist curenv modsrcname)
(debug "translate_to_c_module_melt_sources done modsrcname=" modsrcname "\n")
))
;;;;;;;;;;;;;;;;
(defun generate_gplv3plus_copyright_notice_c_comment (sbuf name)
:doc #{Generate into stringbuffer $SBUF a C comment with GPLv3+
notice for file named $NAME.}#
(assert_msg "check sbuf" (is_strbuf sbuf))
(add2sbuf_strconst sbuf "/** Copyright (C) ")
(let ( (:long year 0)
)
(code_chunk getyear
#{ /*+ generate_gplv3plus_copyright_notice_c_comment $GETYEAR*/ {
time_t $GETYEAR#_now = 0;
struct tm* $GETYEAR#_tm = NULL;
$YEAR = atol (__DATE__ + 7);
time (&$GETYEAR#_now);
if ($GETYEAR#_now > 0)
$GETYEAR#_tm = localtime (&$GETYEAR#_now);
if ($GETYEAR#_tm)
$YEAR = $GETYEAR#_tm->tm_year + 1900;
} /*- $GETYEAR*/}#)
(add2sbuf_longdec sbuf year)
)
(add2sbuf_strconst sbuf " Free Software Foundation, Inc.")
(add2sbuf_indentnl sbuf 0)
(add2sbuf_strconst sbuf " This generated file ")
(if (is_string name)
(code_chunk
addbasename
#{ /*$ADDBASENAME +*/
meltgc_add_strbuf( (melt_ptr_t)($SBUF),
lbasename (melt_string_str((melt_ptr_t)($NAME))));
/*$ADDBASENAME -*/ }#)
)
(add2sbuf_strconst sbuf " is part of GCC.")
(add2sbuf_indentnl sbuf 0)
(add2sbuf_indentnl sbuf 0)
(add2sbuf_strconst sbuf " [DON'T EDIT THIS GENERATED FILE]
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/>.
**/")
(add2sbuf_indentnl sbuf 0)
(add2sbuf_indentnl sbuf 0)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(export_values
syntax_test_generator
compile_list_sexpr
generate_gplv3plus_copyright_notice_c_comment
get_code_buffer_limit
put_code_buffer_limit
translate_to_c_module_melt_sources
translate_run_melt_expressions
)
(export_class class_secondary_c_file)
;;;;;;;;;;;;;;;;
;;; eof warmelt-outobj.melt
|