File: feh2.c

package info (click to toggle)
intercal 30:0.30-2
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 4,044 kB
  • sloc: ansic: 8,936; sh: 1,274; yacc: 1,073; lex: 518; lisp: 460; makefile: 435; perl: 295
file content (2786 lines) | stat: -rw-r--r-- 87,185 bytes parent folder | download | duplicates (2)
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
/****************************************************************************

Name
   feh2.c -- code-generator back-end for ick parser

DESCRIPTION
   This module provides storage manglement and code degeneration
   for the INTERCAL compiler. Optimizations (formerly in this file)
   were split into dekludge.c.

LICENSE TERMS
    Copyright (C) 1996 Eric S. Raymond

    This program 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 2 of the License, or
    (at your option) any later version.

    This program 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 this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

****************************************************************************/
/*LINTLIBRARY */
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "sizes.h"
#include "ick.h"
#include "parser.h"
#include "fiddle.h"
#include "ick_lose.h"
#include "feh.h"

/* AIS: Destaticed for dekludge.c */
int emitlineno;   /* line number for errors encountered during emit */

/*@-exportlocal@*/ /* the parser uses this */
bool mark112 = 0; /* AIS: Mark the ick_next generated tuple for W112 */
/*@=exportlocal@*/

/* AIS: From perpet.c */
extern bool pickcompile;
extern bool ick_clcsemantics;

/*************************************************************************
 *
 * Node allocation functions.
 *
 * Nodes are used to represent expression trees. The emit() function
 * deallocates them.
 *
 **************************************************************************/

/*@partial@*/ node *newnode(void)
/* allocate and zero out a new expression node */
{
  node* temp;
  temp=calloc(sizeof(node), 1);
  if(!temp) ick_lose(IE345, 0, (const char*) NULL);
  return temp;
}

/*@partial@*/ node *cons(int type, /*@null@*/ /*@keep@*/ node *car, /*@null@*/ /*@keep@*/ node *cdr)
{
    node *np = newnode();

    np->opcode = type;
    np->lval = car;
    np->rval = cdr;

    return(np);
}

/*************************************************************************
 *
 * Variable-name mapping
 *
 * This permits us to optimize use of variable storage at runtime
 *
 **************************************************************************/

unsigned long intern(int type, unsigned long index)
{
    atom	*x;

    /* AIS: Allow use of a modifiable constant 0 or >65535. */
    if ((index < 1LU || index > 65535LU) && type!=MESH)
	ick_lose(IE200, iyylineno, (const char *)NULL);

    /*@-branchstate@*/
    if (!oblist)
    {
	/* initialize oblist and obdex */
	oblist = malloc(ALLOC_CHUNK * sizeof(atom));
	if (!oblist)
	    ick_lose(IE345, iyylineno, (const char *)NULL);
	obdex = oblist;
	obcount = ALLOC_CHUNK;
    }
    else
    {
      /* if it's already on the oblist, return its intindex */
      for (x = oblist; x < obdex; x++)
	if (x->type == type && x->extindex == index)
	  return(x->intindex);
    }
    /*@=branchstate@*/
    assert(oblist != NULL);

    /* else we must intern a new symbol */
    /* AIS: Splint doesn't understand what's going on here at all. Disabling
       the warnings; I've checked this and think it's correct. */
    /*@-usedef@*/ /*@-usereleased@*/ /*@-branchstate@*/
    if (obdex >= oblist + obcount)
    {
	obcount += ALLOC_CHUNK;
	x = realloc(oblist, obcount * sizeof(atom));
	if (!x)
	    ick_lose(IE333, iyylineno, (const char *)NULL);
	obdex = x + (obdex - oblist);
	oblist = x;
    }
    /*@=branchstate@*/ /*@=usereleased@*/ /*@=usedef@*/
    obdex->type = type;
    obdex->extindex = index;
    obdex->memloc = 0; /* AIS: not placed in memory yet */
    if (type == ick_ONESPOT)
      obdex->intindex = (unsigned)nonespots++;
    if (type == ick_TWOSPOT)
      obdex->intindex = (unsigned)ntwospots++;
    if (type == ick_TAIL)
      obdex->intindex = (unsigned)ntails++;
    if (type == ick_HYBRID)
      obdex->intindex = (unsigned)nhybrids++;
    if (type == MESH) /* AIS: count meshes too */
      obdex->intindex = (unsigned)nmeshes++;
    ++obdex;

    /*@-usedef@*/
    return(obdex[-1].intindex);
    /*@=usedef@*/
}

/*************************************************************************
 *
 * This function insures a label is valid.
 *
 **************************************************************************/

/* AIS: I haven't modified this function, but I have repurposed it without
   changing the code; this function must not now have side effects (apart from
   an error exit), because some labels are initialised in the preprocessor
   without causing this. */
void checklabel(int label)
{
    if (label < 1 || label > 65535)
	ick_lose(IE197, iyylineno, (const char *)NULL);
}

/*************************************************************************
 *
 * AIS: Search for the indexth COME_FROM sucking in the given tuple.
 *      Return an int representing the COME_FROM's tn-tuples+1, or -1.
 *      index is based at 1, not 0 as is usual for C.
 *
 ***************************************************************************/

int comefromsearch(tuple* tn, unsigned int index)
{
  tuple* tp;
  for (tp = tuples; tp < tuples + ick_lineno; tp++)
  {
    if((tp->type == COME_FROM || tp->type == NEXTFROMLABEL)
	&& tp->u.target == (unsigned)(tn-tuples+1))
      index--;
    if(!index) return tp-tuples+1;
  }
  return -1;
}

/*************************************************************************
 *
 * Tuple allocation functions.
 *
 **************************************************************************/

void treset(void)
{
    tuplecount = 0;
    if (tuples)
    {
      /* AIS: Splint doesn't understand lazy allocation, which is why it
	 thinks I'm treating an unqualified as an only (I am, but a lazy
	 list doesn't fit any of Splint's storage classes); also, I am
	 completely destroying the tuples, because any nodes in them ought
	 to have been deallocated in prexpr. */
      /*@-unqualifiedtrans@*/ /*@-compdestroy@*/
      free(tuples);
      tuples = NULL;
      /*@=unqualifiedtrans@*/ /*@=compdestroy@*/
    }
    nmeshes = nonespots = ntwospots = ntails = nhybrids = 0;
    obdex = oblist;
    ick_lineno = 0;
    /* AIS: It's easier to mark tuples as 'always allocated', because
       it usually is, and just supress the warnings. Maybe the 'proper'
       way to do it would be to assert that tuples was non-null everywhere,
       but again this is just problems with Splint not understanding how
       lazy allocation works. So I tell Splint that it's allocated everywhere
       and just supress the warnings it produces when it isn't. */
    /*@-globstate@*/
}
/*@=globstate@*/

/*@out@*/ /*@dependent@*/ tuple *newtuple(void)
/* allocate and zero out a new expression tuple */
{
  /* Patch by Joris Huizer: must leave at least 1 tuple empty */
  if (ick_lineno >= tuplecount - 1 || tuples == NULL)
  {
    tuplecount += ALLOC_CHUNK;
    if (tuples)
	tuples = (tuple *)realloc(tuples, tuplecount * sizeof(tuple));
    else
	tuples = (tuple *)malloc(tuplecount * sizeof(tuple));
    if (!tuples)
      ick_lose(IE666, iyylineno, (const char *)NULL);
    memset(tuples + ick_lineno, 0, (tuplecount - ick_lineno) * sizeof(tuple));
  }
  if(mark112) tuples[ick_lineno].warn112 = true; mark112 = false; /* AIS */
  /* Yes, tuples is strictly speaking 'partial' at this point, but it's going
     to be filled in later, and isn't marked as partial due to it not being
     partial through most of the code, and you can't write out on a global.
     So instead I'm just suppressing the warning, because it doesn't lead to
     a problem long-term. */
  /*@-compdef@*/
  return(tuples + ick_lineno++);
  /*@=compdef@*/
}

void tupleswap(int distback1, int distback2)
{
  tuple temp;
  memcpy(&temp, &tuples[ick_lineno-distback1], sizeof(tuple));
  memcpy(&tuples[ick_lineno-distback1], &tuples[ick_lineno-distback2], sizeof(tuple));
  memcpy(&tuples[ick_lineno-distback2], &temp, sizeof(tuple));
  /* Splint doesn't understand memcpy, and so falsely things this is a memory leak. */
  /*@-compdestroy@*/
}
/*@=compdestroy@*/

void ppinit(int tuplecount)
{
  while(tuplecount)
  {
    /* 0 is an impossible exechance; make sure it's set for tuple elements. */
    if(!tuples[ick_lineno-tuplecount].exechance)
      tuples[ick_lineno-tuplecount].exechance=100;
    /* The onceagainflag also needs to be set. */
    tuples[ick_lineno-tuplecount].onceagainflag=onceagain_NORMAL;
    tuplecount--;
  }
}

/*************************************************************************
 *
 * The typecaster
 *
 * The theory here is that we associate a type with each node in order to
 * know what widths of unary-logical operator to use.
 *
 **************************************************************************/

void typecast(node *np)
{
    /* recurse so we typecast each node after all its subnodes */
    if (np == (node *)NULL)
	return;
    else if (np->lval != (node *)NULL)
	typecast(np->lval);
    if (np->rval != (node *)NULL)
	typecast(np->rval);

    /*
     * This is an entire set of type-deducing machinery right here.
     */
    /*@-nullderef@*/ /* AIS: because the opcode defines whether lval or rval are nonnull */
    if (np->opcode == MESH || np->opcode == ick_ONESPOT || np->opcode == ick_TAIL)
	np->width = 16;
    else if (np->opcode == ick_TWOSPOT || np->opcode == ick_HYBRID
	     || np->opcode == MINGLE || np->opcode == MESH32
	     || np->opcode == UNKNOWNOP /* AIS */)
	np->width = 32;
    else if (np->opcode == AND || np->opcode == OR || np->opcode == XOR ||
	     np->opcode == FIN ||
	     (np->opcode >= WHIRL && np->opcode <= WHIRL5))
	np->width = np->rval->width;
    else if (np->opcode == SELECT)
	np->width = np->rval->width;	/* n-bit select has an n-bit result */
    else if (np->opcode == INTERSECTION) /* AIS */
        np->width = (np->rval ?
		     np->lval ? np->rval->width == 16 ? np->lval->width : 32 :
		     np->rval->width : np->lval ? np->lval->width : 32);
    else if (np->opcode == BADCHAR) /* AIS */
        np->width = 16;
    else if (np->opcode == SUB)
	np->width = np->lval->width;	/* type of the array */
    else if (np->opcode == SLAT || np->opcode == BACKSLAT)
      np->width = np->lval->width; /* AIS: \ and / return their left arg */
    /*@=nullderef@*/
}

/*************************************************************************
 *
 * The codechecker
 *
 * This checks for nasties like mismatched types in assignments that
 * can be detected at compile time -- also for errors that could cause
 * the compilation of the generated C to fail, like generated gotos to
 * nonexistent labels or duplicate labels.
 *
 * AIS: codecheck has another important job, that of filling in information
 *      about COME FROM suckpoints and ABSTAIN/REINSTATE command numbers
 *      into the tuples.
 *
 **************************************************************************/

void codecheck(void)
{
    tuple	*tp, *up;
    int         notpast1900; /* AIS */

    /* check for assignment type mismatches */
    /* This check can't be done at compile time---RTFM.  [LHH] */
/*
    for (tp = tuples; tp < tuples + ick_lineno; tp++)
	if (tp->type == GETS)
	    if (tp->u.node->lval->width == 16 && tp->u.node->rval->width == 32)
		ick_lose(IE275, tp - tuples + 1, (const char *)NULL);
*/

    /* check for duplicate labels */
    for (tp = tuples; tp < tuples + ick_lineno; tp++)
	if (tp->label)
	    for (up = tuples; up < tuples + ick_lineno; up++)
		if (tp != up && tp->label == up->label)
		  ick_lose(IE182, tp - tuples + 1, (const char *)NULL);

    /*
     * Check that every NEXT, ABSTAIN, REINSTATE and COME_FROM actually has a
     * legitimate target label.
     */
    notpast1900 = 1;
    for (tp = tuples; tp < tuples + ick_lineno; tp++)
    {
      if (tp->label == 1900) notpast1900 = false; /* AIS */
        if (tp->type == NEXT
	    || tp->type == ABSTAIN || tp->type == REINSTATE
	    || tp->type == COME_FROM || tp->type == FROM
	    || tp->type == NEXTFROMLABEL) /* AIS: added FROM, NEXTFROMLABEL. */
	{
	    bool	foundit = false;

	    if (tp->u.target >= 1900 && tp->u.target <= 1998)
	    {
	      /* AIS: This program uses syslib.i's random number feature... or are
	         we in syslib already? */
	      if(notpast1900) coopt = 0;
	    }

	    if (tp->u.target > 65535 && !tp->preproc) /* AIS */
	      ick_lose(IE197, tp - tuples + 1, (const char*) NULL);

	    for (up = tuples; up < tuples + ick_lineno; up++)
		if (tp->u.target == up->label)
		{
		    foundit = true;
		    break;
		}

	    if (!foundit)
	    {
	      /* AIS: Added the pickcompile check. Syslib has to be optimized
		 for PICs, so syslib.i isn't imported and so none of the lables
		 in it will appear in the program. Also added the useickec
		 check, as that's another legitimate way for a NEXT to target
		 a nonexistent line label */
		if (tp->type == NEXT && !useickec &&
		    (!pickcompile||tp->u.target<1000||tp->u.target>1999))
		    ick_lose(IE129, tp - tuples + 1, (const char *)NULL);
		else if (tp->type == NEXT) /* AIS */
		{tp->nexttarget=0; continue;}
		else if (useickec) /* AIS */
		  continue;
		/* AIS: NEXTFROMLABEL's basically identical to COME_FROM */
		else if (tp->type == COME_FROM || tp->type == NEXTFROMLABEL)
		    ick_lose(IE444, tp - tuples + 1, (const char *)NULL);
		else
		    ick_lose(IE139, tp - tuples + 1, (const char *)NULL);
	    }
	    /* tell the other tuple if it is a COME FROM target */
	    /* AIS: NEXTFROMLABEL again */
	    else if (tp->type == COME_FROM || tp->type == NEXTFROMLABEL)
	    {
	        if (up->ncomefrom && !multithread) /* AIS: multithread check */
		    ick_lose(IE555, iyylineno, (const char *)NULL);
		else
                    up->ncomefrom++; /* AIS: to handle multiple COME FROMs */
	    }
	    /* this substitutes line numbers for label numbers
	       AIS: COME FROM now uses this too. This changes the logic
	       slightly so that an !foundit condition would fall through,
	       but as long as ick_lose doesn't return, it's not a problem.
	       (I removed the else before the if.) */
	    if (tp->type != NEXT)
	    {
	      /* AIS: added this useickec condition. */
	      if(!useickec || (tp->type!=NEXTFROMLABEL && tp->type!=COME_FROM))
		 tp->u.target = (unsigned)(up - tuples + 1);
	    }
	    else /* AIS */
	    {
	      tp->nexttarget = (unsigned)(up - tuples + 1);
	      up->nextable = true;
	    }
	}
    }
}

/* AIS: Added the third argument to prexpr and prvar. It specifies
   whether the node should be freed or not. I added the third
   argument in all calls of prexpr/prvar. This protoype has been moved
   up through the file so it can be used earlier. Destaticed so it can
   be referenced by dekludge.c. */
void prexpr(node *np, FILE *fp, int freenode);
/*************************************************************************
 *
 * Code degeneration
 *
 * The theory behind this crock is that we've been handed a pointer to
 * a tuple representing a single INTERCAL statement, possibly with an
 * expression tree hanging off it and twisting slowly, slowly in the wind.
 *
 * Our mission, should we choose to accept it, is to emit C code which,
 * when linked to the INTERCAL run-time support, will do something
 * resembling the right thing.
 *
 **************************************************************************/

/*
 * If the order of statement-token defines in parser.y ever changes,
 * this will need to be reordered.
 */
/*@observer@*/ const char *enablersm1[MAXTYPES+1] =
{
    "UNKNOWN", /* AIS: so comments can be ABSTAINED/REINSTATED */
    "GETS",
    "RESIZE",
    "NEXT",
    "GO_AHEAD", /* AIS: Added for backtracking */
    "GO_BACK",  /* AIS: Added for backtracking */
    "FORGET",
    "RESUME",
    "STASH",
    "RETRIEVE",
    "IGNORE",
    "REMEMBER",
    "ABSTAIN",
    "REINSTATE",
    "DISABLE",
    "ENABLE",
    "MANYFROM", /* AIS: Added ABSTAIN expr FROM gerunds */
    "GIVE_UP",
    "READ_OUT",
    "WRITE_IN",
    "PIN",
    "COME_FROM",
    "NEXTFROMLABEL", /* AIS */
    "NEXTFROMEXPR", /* AIS */
    "NEXTFROMGERUND", /* AIS */
    "COMPUCOME", /* AIS: Added COMPUCOME */
    "GERUCOME", /* AIS: This is COME FROM gerunds */
    "PREPROC", /* AIS: Nonexistent statement */
    "WHILE", /* AIS: statement WHILE statement */
    "TRY_AGAIN", /* AIS: Added TRY AGAIN */
    "CREATE", /* AIS */
    "COMPUCREATE", /* AIS */
    "FROM", /* AIS: ABSTAIN expr FROM LABEL */
};
const char** enablers = enablersm1+1;

const assoc vartypes[] =
{
    { ick_ONESPOT,	"ick_ONESPOT" },
    { ick_TWOSPOT,	"ick_TWOSPOT" },
    { ick_TAIL,	"ick_TAIL" },
    { ick_HYBRID,	"ick_HYBRID" },
    { 0,	(const char *)NULL }
};

static const assoc forgetbits[] =
{
    { ick_ONESPOT,	"ick_oneforget" },
    { ick_TWOSPOT,	"ick_twoforget" },
    { ick_TAIL,	"ick_tailforget" },
    { ick_HYBRID,	"ick_hyforget" },
    { 0,	(const char *)NULL }
};

/* AIS: Destatic. This is now needed in perpet.c. */
const assoc varstores[] =
{
    { ick_ONESPOT,	"ick_onespots" },
    { ick_TWOSPOT,	"ick_twospots" },
    { ick_TAIL,	"ick_tails" },
    { ick_HYBRID,	"ick_hybrids" },
    { 0,	(const char *)NULL }
};

/* AIS: A demangled version */
static const assoc varstoresdem[] =
{
    { ick_ONESPOT,	"onespots" },
    { ick_TWOSPOT,	"twospots" },
    { ick_TAIL,	"tails" },
    { ick_HYBRID,	"hybrids" },
    { 0,	(const char *)NULL }
};

static const assoc typedefs[] =
{
    { ick_ONESPOT,	"ick_type16" },
    { ick_TWOSPOT,	"ick_type32" },
    { ick_TAIL,	"ick_type16" },
    { ick_HYBRID,	"ick_type32" },
    { 0,	(const char *)NULL }
};

/*@observer@*/ /*@null@*/ const char *nameof(int value, const assoc table[])
/* return string corresponding to value in table */
{
    const assoc	*ap;

    for (ap = table; ap->name; ap++)
	if (ap->value == value)
	    return(ap->name);
    return((const char *)NULL);
}

/* AIS: Code for printing explanations (mixed C/INTERCAL code that lets
   the user know what the meaning of an expression is). This is paraphrased
   from the prexpr/prvar code lower down. It's passed to yuk so that the
   explain ('e') command works. It's also included in the degenerated C
   code when the option -c is used, so the person looking at the code can
   debug both the INTERCAL and ick itself more effectively, and used by
   -h to produce its optimizer-debug output, and used to produce the variable
   numbers used in ick_createdata. */

unsigned long varextern(unsigned long intern, int vartype)
{
  atom *x;
  if(!oblist) ick_lose(IE778, emitlineno, (const char*) NULL);
  for (x = oblist; x < obdex; x++)
    if (x->type == vartype && (unsigned long)x->intindex == intern)
      return(x->extindex);
  if(vartype==MESH) return 0; /* the mesh wasn't used after all */
  ick_lose(IE778, emitlineno, (const char*) NULL);
  /*@-unreachable@*/ return 0; /*@=unreachable@*/
}

static void explvar(node* np, FILE* fp)
{
  node *sp;
  switch(np->opcode)
  {
  case ick_ONESPOT:
    (void) fprintf(fp, ".%lu", varextern(np->constant,ick_ONESPOT));
    break;
  case ick_TWOSPOT:
    (void) fprintf(fp, ":%lu", varextern(np->constant,ick_TWOSPOT));
    break;
  case ick_TAIL:
    (void) fprintf(fp, ",%lu", varextern(np->constant,ick_TAIL));
    break;
  case ick_HYBRID:
    (void) fprintf(fp, ";%lu", varextern(np->constant,ick_HYBRID));
    break;
  case SUB:
    (void) fprintf(fp, "(");
    explvar(np->lval, fp);
    (void) fprintf(fp, " SUB ");
    for (sp = np->rval ; sp ; sp = sp->rval)
      explexpr(sp->lval, fp);
    (void) fprintf(fp, ")");
    break;
  default:
    ick_lose(IE778, emitlineno, (const char*) NULL);
  }
}

/* unlike prexpr, this doesn't free its operands */
void explexpr(node* np, FILE* fp)
{
  if(!np) return;
  switch (np->opcode)
  {
  case MINGLE:
    (void) fprintf(fp, "(");
    explexpr(np->lval, fp);
    (void) fprintf(fp, " $ ");
    explexpr(np->rval, fp);
    (void) fprintf(fp, ")");
    break;

  case SELECT:
    (void) fprintf(fp, "(");
    explexpr(np->lval, fp);
    (void) fprintf(fp, " ~ ");
    explexpr(np->rval, fp);
    (void) fprintf(fp, ")");
    break;

  case UNKNOWNOP:
    (void) fprintf(fp, "(");
    explexpr(np->rval->lval, fp);
    if(np->lval->constant < 256)
      (void) fprintf(fp, " %c ", (char)np->lval->constant);
    else
      (void) fprintf(fp, " %c^H%c ",
		     (char)(np->lval->constant / 256),
		     (char)(np->lval->constant % 256));
    explexpr(np->rval->rval, fp);
    (void) fprintf(fp, ")");
    break;

  case SLAT:
    (void) fprintf(fp, "(");
    explexpr(np->lval, fp);
    (void) fprintf(fp, " / ");
    explexpr(np->rval, fp);
    (void) fprintf(fp, ")");
    break;

  case BACKSLAT:
    (void) fprintf(fp, "(");
    explexpr(np->lval, fp);
    (void) fprintf(fp, " \\ ");
    explexpr(np->rval, fp);
    (void) fprintf(fp, ")");
    break;

  case AND:
    (void) fprintf(fp, "(&%d ", np->width);
    explexpr(np->rval, fp);
    (void) fprintf(fp, ")");
    break;

  case OR:
    (void) fprintf(fp, "(V%d ", np->width);
    explexpr(np->rval, fp);
    (void) fprintf(fp, ")");
    break;

  case XOR:
    (void) fprintf(fp, "(?%d ", np->width);
    explexpr(np->rval, fp);
    (void) fprintf(fp, ")");
    break;

  case FIN:
    if (ick_Base < 3)
      ick_lose(IE997, emitlineno, (const char *)NULL);
    (void) fprintf(fp, "(^%d ", np->width);
    explexpr(np->rval, fp);
    (void) fprintf(fp, ")");
    break;

  case WHIRL:
  case WHIRL2:
  case WHIRL3:
  case WHIRL4:
  case WHIRL5:
    if (np->opcode - WHIRL + 3 > ick_Base)
      ick_lose(IE997, emitlineno, (const char *)NULL);
    if(np->opcode == WHIRL)
      (void) fprintf(fp, "(@%d ", np->width);
    else
      (void) fprintf(fp, "(%d@%d ", np->opcode - WHIRL + 1, np->width);
    explexpr(np->rval, fp);
    (void) fprintf(fp, ")");
    break;

  case MESH:
    if(variableconstants) /* AIS */
      (void) fprintf(fp, "meshes[%lu]", np->constant);
    else
      (void) fprintf(fp, "0x%lx", np->constant);
    break;

  case MESH32:
    (void) fprintf(fp, "0x%lx", np->constant);
    break;

  case ick_ONESPOT:
  case ick_TWOSPOT:
  case ick_TAIL:
  case ick_HYBRID:
  case SUB:
    explvar(np, fp);
    break;

    /* cases from here down are generated by the optimizer */
  case C_AND:
    (void) fprintf(fp, "(");
    explexpr(np->lval, fp);
    (void) fprintf(fp, " & ");
    explexpr(np->rval, fp);
    (void) fprintf(fp, ")");
    break;

  case C_OR:
    (void) fprintf(fp, "(");
    explexpr(np->lval, fp);
    (void) fprintf(fp, " | ");
    explexpr(np->rval, fp);
    (void) fprintf(fp, ")");
    break;

  case C_XOR:
    (void) fprintf(fp, "(");
    explexpr(np->lval, fp);
    (void) fprintf(fp, " ^ ");
    explexpr(np->rval, fp);
    (void) fprintf(fp, ")");
    break;

  case C_NOT:
    (void) fprintf(fp, "(~%d ", np->width);
    explexpr(np->rval, fp);
    (void) fprintf(fp, ")");
    break;

  case C_NOTEQUAL:
    (void) fprintf(fp, "(");
    explexpr(np->lval, fp);
    (void) fprintf(fp, " != ");
    explexpr(np->rval, fp);
    (void) fprintf(fp, ")");
    break;

  case C_A:
    (void) fprintf(fp, "a");
    break;

  case C_RSHIFTBY:
    (void) fprintf(fp, "(");
    explexpr(np->lval, fp);
    (void) fprintf(fp, " >> ");
    explexpr(np->rval, fp);
    (void) fprintf(fp, ")");
    break;

  case C_LOGICALNOT:
    (void) fprintf(fp, "(! ");
    explexpr(np->rval, fp);
    (void) fprintf(fp, ")");
    break;

  case C_LSHIFTBY:
    (void) fprintf(fp, "(");
    explexpr(np->lval, fp);
    (void) fprintf(fp, " << ");
    explexpr(np->rval, fp);
    (void) fprintf(fp, ")");
    break;

  case C_PLUS:
    (void) fprintf(fp, "(");
    explexpr(np->lval, fp);
    (void) fprintf(fp, " + ");
    explexpr(np->rval, fp);
    (void) fprintf(fp, ")");
    break;

  case C_MINUS:
    (void) fprintf(fp, "(");
    explexpr(np->lval, fp);
    (void) fprintf(fp, " - ");
    explexpr(np->rval, fp);
    (void) fprintf(fp, ")");
    break;

  case C_TIMES:
    (void) fprintf(fp, "(");
    explexpr(np->lval, fp);
    (void) fprintf(fp, " * ");
    explexpr(np->rval, fp);
    (void) fprintf(fp, ")");
    break;

  case C_DIVIDEBY:
    (void) fprintf(fp, "(");
    explexpr(np->lval, fp);
    (void) fprintf(fp, " / ");
    explexpr(np->rval, fp);
    (void) fprintf(fp, ")");
    break;

  case C_MODULUS:
    (void) fprintf(fp, "(");
    explexpr(np->lval, fp);
    (void) fprintf(fp, " %% ");
    explexpr(np->rval, fp);
    (void) fprintf(fp, ")");
    break;

  case C_GREATER:
    (void) fprintf(fp, "(");
    explexpr(np->lval, fp);
    (void) fprintf(fp, " > ");
    explexpr(np->rval, fp);
    (void) fprintf(fp, ")");
    break;

  case C_LESS:
    (void) fprintf(fp, "(");
    explexpr(np->lval, fp);
    (void) fprintf(fp, " < ");
    explexpr(np->rval, fp);
    (void) fprintf(fp, ")");
    break;

  case C_ISEQUAL:
    (void) fprintf(fp, "(");
    explexpr(np->lval, fp);
    (void) fprintf(fp, " == ");
    explexpr(np->rval, fp);
    (void) fprintf(fp, ")");
    break;

  case C_LOGICALAND:
    (void) fprintf(fp, "(");
    explexpr(np->lval, fp);
    (void) fprintf(fp, " && ");
    explexpr(np->rval, fp);
    (void) fprintf(fp, ")");
    break;

  case C_LOGICALOR:
    (void) fprintf(fp, "(");
    explexpr(np->lval, fp);
    (void) fprintf(fp, " || ");
    explexpr(np->rval, fp);
    (void) fprintf(fp, ")");
    break;

  case INTERSECTION:
    explexpr(np->lval, fp);
    (void) fprintf(fp, " + ");
    explexpr(np->rval, fp);
    break;

  case GETS:
  case RESIZE:
    explexpr(np->lval, fp);
    (void) fprintf(fp, " <- ");
    explexpr(np->rval, fp);
    break;

  case BY:
    explexpr(np->lval, fp);
    (void) fprintf(fp, " BY ");
    explexpr(np->rval, fp);
    break;

  default:
    ick_lose(IE778, emitlineno, (const char*) NULL);
    /*@-unreachable@*/ break; /*@=unreachable@*/
  }
}

/* AIS: Added the third argument to prexpr and prvar. It specifies
   whether the node should be freed or not. I added the third
   argument in all calls of prexpr/prvar. */

/* AIS: I moved prexpr's prototype higher in the file.
   Destaticed so the optimizer can access it. */

static void prvar(node *np, FILE *fp, int freenode)
/* print out args to pass to storage manager for reference */
{
    node	*sp;
    int		dim;

    switch (np->opcode)
    {
    case ick_ONESPOT:
	(void) fprintf(fp, "ick_onespots[%lu]", np->constant);
	break;

    case ick_TWOSPOT:
	(void) fprintf(fp, "ick_twospots[%lu]", np->constant);
	break;

    case ick_TAIL:
	(void) fprintf(fp, "ick_TAIL, &ick_tails[%lu]", np->constant);
	break;

    case ick_HYBRID:
	(void) fprintf(fp, "ick_HYBRID, &ick_hybrids[%lu]", np->constant);
	break;

    case SUB:
	{
	  (void) fprintf(fp, "ick_aref(");
	  prvar(np->lval, fp, freenode);

	  dim = 0;
	  for (sp = np->rval ; sp ; sp = sp->rval)
	    dim++;
	  (void) fprintf(fp, ", %d", dim);

	  for (sp = np->rval ; sp ; sp = sp->rval) {
	    (void) fprintf(fp, ", ");
	    prexpr(sp->lval, fp, freenode);
	  }
	  (void) fprintf(fp, ")");
	}
	break;
    default: /* Added by AIS */
      ick_lose(IE778, emitlineno, (const char*) NULL);
      /*@-unreachable@*/ break; /*@=unreachable@*/
    }
}

static void ooprvar(node *np, FILE *fp, int freenode)
/* AIS: Print out the overloaded version */
{
    node	*sp;
    int		dim;

    switch (np->opcode)
    {
    case ick_ONESPOT:
	(void) fprintf(fp, "ick_oo_onespots[%lu]", np->constant);
	break;

    case ick_TWOSPOT:
	(void) fprintf(fp, "ick_oo_twospots[%lu]", np->constant);
	break;

    case ick_TAIL:
    case ick_HYBRID:
      /* This should never be reached */
      ick_lose(IE778, emitlineno, (const char*) NULL);
      /*@-unreachable@*/ break; /*@=unreachable@*/

    case SUB:
	{
	  (void) fprintf(fp, "ick_aref(");
	  prvar(np->lval, fp, freenode);

	  dim = 0;
	  for (sp = np->rval ; sp ; sp = sp->rval)
	    dim++;
	  (void) fprintf(fp, ", %d", dim);

	  for (sp = np->rval ; sp ; sp = sp->rval) {
	    (void) fprintf(fp, ", ");
	    prexpr(sp->lval, fp, freenode);
	  }
	  (void) fprintf(fp, ")");
	}
	break;
    default:
      ick_lose(IE778, emitlineno, (const char*) NULL);
      /*@-unreachable@*/ break; /*@=unreachable@*/
    }
}

/* AIS: Give us a mesh with value x */
static unsigned long meshval(unsigned long x)
{
  if(variableconstants)
    return intern(MESH, x);
  else
    return x;
}

/* AIS: This is the reverse of prexpr, in a way.
   It degenerates an expression that causes *np to become equal to *target.
   If this is impossible at any point, it degenerates code that causes
   error 277 (and itself causes error 278 if the situation is inevitable).
   As for the annotations; there quite possibly are memory allocation mistakes
   here, but just about every line is a false positive (because we're operating
   at the subobject level in terms of copy/free/allocate) for Splint, and so
   disabling the warnings doesn't make the output any less useful. (When there
   are so many false positives, disabling the true positives doesn't make them
   any harder to find by eye. */
/*@-temptrans@*/ /*@-kepttrans@*/ /*@-compdestroy@*/ /*@-branchstate@*/
 /*@-nullpass@*/
static void revprexpr(node *np, FILE *fp, node *target)
{
  node* temp;
  switch (np->opcode)
  {
  case MINGLE:
    /* We can use select to determine what np->lval and np->rval have
       to become equal to, as long as we're in base 2. */
    if(ick_Base!=2)
    {
      fprintf(fp, "  ick_lose(IE277, ick_lineno, (const char*) NULL);\n");
      ick_lwarn(W278, emitlineno, (const char*) NULL);
      break;
    }
    temp=cons(MESH,0,0);
    temp->constant=meshval(0xAAAAAAAALU);
    temp->width=32;
    temp=cons(SELECT,target,temp);
    temp->width=target->width;
    revprexpr(np->lval, fp, temp);
    free(temp->rval);
    free(temp);
    temp=cons(MESH,0,0);
    temp->constant=meshval(0x55555555LU);
    temp->width=32;
    temp=cons(SELECT,target,temp);
    temp->width=target->width;
    revprexpr(np->rval, fp, temp);
    free(temp->rval);
    free(temp);
    break;

  case SELECT:
    /* Set the left of the select to the target, and the right
       to 0xffffffff or 0xffff. This only works in base 2. */
    if(ick_Base!=2)
    {
      fprintf(fp, "  ick_lose(IE277, ick_lineno, (const char*) NULL);\n");
      ick_lwarn(W278, emitlineno, (const char*) NULL);
      break;
    }
    temp=cons(MESH,0,0);
    temp->constant=meshval(target->width==32?0xFFFFFFFFLU:0xFFFFLU);
    temp->width=target->width;
    revprexpr(np->lval, fp, target);
    revprexpr(np->rval, fp, temp);
    free(temp);
    break;

  case UNKNOWNOP: /* don't be silly */
    fprintf(fp, "  ick_lose(IE277, ick_lineno, (const char*) NULL);\n");
    ick_lwarn(W278, emitlineno, (const char*) NULL);
    break;

  case BACKSLAT:
    /* Unimplemented. This isn't even in the parser yet, so it's a
       ick_mystery how we got here. */
    ick_lose(IE778, emitlineno, (const char*) NULL);
    /*@-unreachable@*/ break; /*@=unreachable@*/

  case SLAT:
    /* We need to set the true value of the LHS... */

    /* Copied and modified from the GETS code */
    if(!pickcompile)
    {
      (void) fprintf(fp,"  (void) ick_assign((char*)&");
      prvar(np->lval, fp, 0);
      (void) fprintf(fp,", %s", nameof(np->lval->opcode, vartypes));
      (void) fprintf(fp,", %s[%lu], ", nameof(np->lval->opcode, forgetbits),
		     np->lval->constant);
      prexpr(target, fp, 0);
      (void) fprintf(fp,");  \n");
    }
    else /* AIS: Added this case for the simpler PIC assignment rules */
    {
      (void) fprintf(fp,"\t""if(ignore%s%lu) ",
		     nameof(np->lval->opcode,varstores),
		     np->lval->constant);
      prexpr(np->lval, fp, 0);
      (void) fprintf(fp, " = ");
      prexpr(target, fp, 0);
      (void) fprintf(fp, ";  \n");
    }

    /* ... and we need to cause overloading to happen. This is a copy
       of part of the code for SLAT, modified to work in this context. */
    ooprvar(np->lval, fp, 0);
    /* Do something highly non-portable with pointers that should work
       anyway. Each pointer needs to be given a unique code; so we use
       the hex representation of np casted to an unsigned long.
       Technically speaking, np->rval could be casted to anything; but
       all implementations I've ever seen cast unique pointers to unique
       numbers, which is good enough for our purposes. */
    (void) fprintf(fp, ".get=ick_og%lx;\n  ", (unsigned long)np->rval);
    ooprvar(np->lval, fp, 0);
    (void) fprintf(fp, ".set=ick_os%lx;\n", (unsigned long)np->rval);
    break;

  case AND:
  case OR:
  case XOR:
  case FIN:
  case WHIRL:
  case WHIRL2:
  case WHIRL3:
  case WHIRL4:
  case WHIRL5:
    temp=cons(np->opcode-AND+REV_AND,0,target);
    temp->width=temp->rval->width=np->width;
    revprexpr(np->rval, fp, temp);
    free(temp);
    break;

  case MESH:
    if(!variableconstants)
    {
      /* Can't set a mesh in this case */
      fprintf(fp, "  ick_lose(IE277, ick_lineno, (const char*) NULL);\n");
      ick_lwarn(W278, emitlineno, (const char*) NULL);
      break;
    }
    (void) fprintf(fp,"  meshes[%lu] = ",np->constant);
    prexpr(target, fp, 0);
    (void) fprintf(fp,";\n");
    break;

  case ick_ONESPOT:
  case ick_TWOSPOT:
  case ick_TAIL:
  case ick_HYBRID:
  case SUB:
    /* Copy the code for the GETS statement; this is almost the same
       thing. Modified because we're assigning target to np, not
       np->lval to np->rval, and to not free(). */
    if(opoverused&&
       (np->opcode==ick_ONESPOT||np->opcode==ick_TWOSPOT)) /* AIS */
    {
      (void) fprintf(fp,"  ");
      ooprvar(np, fp, 0);
      (void) fprintf(fp,".set(");
      prexpr(target, fp, 0);
      (void) fprintf(fp,",os%dspot%lu);\n",
		     ((np->opcode==ick_TWOSPOT)?1:0)+1, np->constant);
    }
    else if(!pickcompile)
    {
      node* sp;

      if (np->opcode != SUB) {
	sp = np;
	(void) fprintf(fp,"  (void) ick_assign((char*)&");
      }
      else {
	sp = np->lval;
	(void) fprintf(fp,"  (void) ick_assign(");
      }
      prvar(np, fp, 0);
      (void) fprintf(fp,", %s", nameof(sp->opcode, vartypes));
      (void) fprintf(fp,", %s[%lu], ", nameof(sp->opcode, forgetbits),
		     sp->constant);
      prexpr(target, fp, 0);
      (void) fprintf(fp,");\n");
    }
    else /* AIS: Added this case for the simpler PIC assignment rules */
    {
      (void) fprintf(fp,"  if(ignore%s%lu) ",
		     nameof(np->opcode,varstores),
		     np->constant);
      prexpr(np, fp, 0);
      (void) fprintf(fp, " = ");
      prexpr(target, fp, 0);
      (void) fprintf(fp, ";\n");
    }
    break;

    /* cases from here down are generated by the optimizer, and so
       should never come up here and are errors. The exception is
       C_A, which should only ever appear in a target expression,
       so is also an error. */
  case MESH32:
  case C_AND:
  case C_OR:
  case C_XOR:
  case C_NOT:
  case C_NOTEQUAL:
  case C_A:
  case C_RSHIFTBY:
  case C_LOGICALNOT:
  case C_LSHIFTBY:
  case C_PLUS:
  case C_MINUS:
  case C_TIMES:
  case C_DIVIDEBY:
  case C_MODULUS:
  case C_GREATER:
  case C_LESS:
  case C_ISEQUAL:
  case C_LOGICALAND:
  case C_LOGICALOR:
  case GETS: /* should never come up */
  default:
    ick_lose(IE778, emitlineno, (const char*) NULL);
    /*@-unreachable@*/ break; /*@=unreachable@*/
  }
}
/*@=temptrans@*/ /*@=kepttrans@*/ /*@=compdestroy@*/ /*@=branchstate@*/

/*@observer@*/ static char* E000string; /* AIS */

static int prunknownstr(node*, FILE*); /* AIS */

/* AIS: Destaticed */
/* Splint doesn't understand the concept of a function which might or might
   not free its argument. That's a pity, because its checking would come in
   useful here, but as it is we have to annotate memory checking off for this
   function. */
/*@-temptrans@*/ /*@-onlytrans@*/ /*@-compdestroy@*/ /*@-branchstate@*/
void prexpr(node *np, FILE *fp, int freenode)
/* print out C-function equivalent of an expression */
{
    int tempint;
    switch (np->opcode)
    {
    case MINGLE:
	(void) fprintf(fp, "ick_mingle(");
	prexpr(np->lval, fp, freenode);
	(void) fprintf(fp, ", ");
	prexpr(np->rval, fp, freenode);
	(void) fprintf(fp, ")");
	break;

    case SELECT:
	(void) fprintf(fp, "ick_iselect(");
	prexpr(np->lval, fp, freenode);
	(void) fprintf(fp, ", ");
	prexpr(np->rval, fp, freenode);
	(void) fprintf(fp, ")");
	break;

    case UNKNOWNOP: /* AIS */
      if(!useickec || !createsused)
      {
	/* CREATEd operators require -ea */
	(void) fprintf(fp, "(ick_lose(IE000, ick_lineno, \"%s\"),0)",
		       E000string);
	break;
      }
      /* We need to do the same as UNKNOWN statements, but as an expression.
	 This is achieved with the helper function ick_dounop in ick_ec.c. */
      (void) fprintf(fp, "ick_dounop(\"");
      (void) prunknownstr(np->lval, fp);
      if(freenode) free(np->lval);
      (void) fprintf(fp, "\", ");
      prexpr(np->rval->lval, fp, 0);
      (void) fprintf(fp, ", ");
      prexpr(np->rval->rval, fp, 0);
      (void) fprintf(fp,
		     ", ick_lineno, %luUL, %luUL, %luUL"
		     ", ick_og%lx, ick_og%lx, og2spot%lu"
		     ", ick_os%lx, ick_os%lx, os2spot%lu, \"%s\")",
		     intern(ick_TWOSPOT, 1601),
		     intern(ick_TWOSPOT, 1602),
		     intern(ick_TWOSPOT, 1603),
		     (unsigned long) np->rval->lval,
		     (unsigned long) np->rval->rval,
		     intern(ick_TWOSPOT, 1603),
		     (unsigned long) np->rval->lval,
		     (unsigned long) np->rval->rval,
		     intern(ick_TWOSPOT, 1603),
		     E000string);
      if(freenode) free(np->rval);
      break;

    case BACKSLAT: /* AIS */
      /* Unimplemented. This isn't even in the parser yet, so it's a
	 ick_mystery how we got here. */
      ick_lose(IE778, emitlineno, (const char*) NULL);
      /*@-unreachable@*/ break; /*@=unreachable@*/

    case SLAT: /* AIS */
      (void) fprintf(fp,"((");
      ooprvar(np->lval, fp, 0);
      /* Do something highly non-portable with pointers that should work
	 anyway. Each pointer needs to be given a unique code; so we use
	 the hex representation of np casted to an unsigned long.
	 Technically speaking, np->rval could be casted to anything; but
	 all implementations I've ever seen cast unique pointers to unique
	 numbers, which is good enough for our purposes. */
      (void) fprintf(fp, ".get=ick_og%lx),(", (unsigned long)np->rval);
      ooprvar(np->lval, fp, 0);
      (void) fprintf(fp, ".set=ick_os%lx),(", (unsigned long)np->rval);
      prvar(np->lval, fp, freenode);
      /* np->rval will be freed later, when its expression is printed */
      (void) fprintf(fp, "))");
      return; /* mustn't be freed */

    case AND:
	(void) fprintf(fp, "ick_and%d(", np->width);
	prexpr(np->rval, fp, freenode);
	(void) fprintf(fp, ")");
	break;

    case OR:
	(void) fprintf(fp, "ick_or%d(", np->width);
	prexpr(np->rval, fp, freenode);
	(void) fprintf(fp, ")");
	break;

    case XOR:
	(void) fprintf(fp, "ick_xor%d(", np->width);
	prexpr(np->rval, fp, freenode);
	(void) fprintf(fp, ")");
	break;

    case FIN:
	if (ick_Base < 3)
	  ick_lose(IE997, emitlineno, (const char *)NULL);
	(void) fprintf(fp, "ick_fin%d(", np->width);
	prexpr(np->rval, fp, freenode);
	(void) fprintf(fp, ")");
	break;

    case WHIRL:
    case WHIRL2:
    case WHIRL3:
    case WHIRL4:
    case WHIRL5:
	if (np->opcode - WHIRL + 3 > ick_Base)
	  ick_lose(IE997, emitlineno, (const char *)NULL);
	(void) fprintf(fp, "ick_whirl%d(%d, ", np->width, np->opcode - WHIRL + 1);
	prexpr(np->rval, fp, freenode);
	(void) fprintf(fp, ")");
	break;

    /* AIS: Reversed operations */
    case REV_AND:
	(void) fprintf(fp, "ick_rev_and%d(", np->width);
	prexpr(np->rval, fp, freenode);
	(void) fprintf(fp, ")");
	break;

    case REV_OR:
	(void) fprintf(fp, "ick_rev_or%d(", np->width);
	prexpr(np->rval, fp, freenode);
	(void) fprintf(fp, ")");
	break;

    case REV_XOR:
	(void) fprintf(fp, "ick_rev_xor%d(", np->width);
	prexpr(np->rval, fp, freenode);
	(void) fprintf(fp, ")");
	break;

    case REV_FIN:
	if (ick_Base < 3)
	  ick_lose(IE997, emitlineno, (const char *)NULL);
	(void) fprintf(fp, "rev_fin%d(", np->width);
	prexpr(np->rval, fp, freenode);
	(void) fprintf(fp, ")");
	break;

    case REV_WHIRL:
    case REV_WHIRL2:
    case REV_WHIRL3:
    case REV_WHIRL4:
    case REV_WHIRL5:
	if (np->opcode - WHIRL + 3 > ick_Base)
	  ick_lose(IE997, emitlineno, (const char *)NULL);
	(void) fprintf(fp,
		       "rev_whirl%d(%d, ", np->width, np->opcode - WHIRL + 1);
	prexpr(np->rval, fp, freenode);
	(void) fprintf(fp, ")");
	break;

    case MESH:
      if(variableconstants) /* AIS */
	(void) fprintf(fp, "meshes[%lu]", np->constant);
      else
	(void) fprintf(fp, "0x%lx", np->constant);
      break;

    case MESH32:
	(void) fprintf(fp, "0x%lx", np->constant);
	break;

    case ick_ONESPOT:
    case ick_TWOSPOT:
    case ick_TAIL:
    case ick_HYBRID:
	if(!opoverused||np->opcode==ick_TAIL||np->opcode==ick_HYBRID)
	  prvar(np, fp, freenode);
	else /* AIS */
	{
	  ooprvar(np, fp, freenode);
	  fprintf(fp, ".get(");
	  prvar(np, fp, freenode);
	  fprintf(fp,")");
	}
	break;

    case SUB:
	(void) fprintf(fp, "*(%s*)", nameof(np->lval->opcode, typedefs));
	prvar(np, fp, freenode);
	break;

	/* cases from here down are generated by the optimizer */
    case C_AND:
	(void) fprintf(fp, "(");
	prexpr(np->lval, fp, freenode);
	(void) fprintf(fp, " & ");
	prexpr(np->rval, fp, freenode);
	(void) fprintf(fp, ")");
	break;

    case C_OR:
	(void) fprintf(fp, "(");
	prexpr(np->lval, fp, freenode);
	(void) fprintf(fp, " | ");
	prexpr(np->rval, fp, freenode);
	(void) fprintf(fp, ")");
	break;

    case C_XOR:
	(void) fprintf(fp, "(");
	prexpr(np->lval, fp, freenode);
	(void) fprintf(fp, " ^ ");
	prexpr(np->rval, fp, freenode);
	(void) fprintf(fp, ")");
	break;

    case C_NOT:
	(void) fprintf(fp, "(~");
        tempint=np->width; /* AIS */
	prexpr(np->rval, fp, freenode);
	if (tempint == ick_Small_digits)
	    (void) fprintf(fp, " & ick_Max_small)");
	else
	    (void) fprintf(fp, " & ick_Max_large)");
	break;

	/* AIS: I added the rest of the cases */
    case C_NOTEQUAL:
      (void) fprintf(fp, "(");
      prexpr(np->lval, fp, freenode);
      (void) fprintf(fp, " != ");
      prexpr(np->rval, fp, freenode);
      (void) fprintf(fp, ")");
      break;

    case C_A:
      (void) fprintf(fp, "a");
      break;

    case C_RSHIFTBY:
      (void) fprintf(fp, "(");
      prexpr(np->lval, fp, freenode);
      (void) fprintf(fp, " >> ");
      prexpr(np->rval, fp, freenode);
      (void) fprintf(fp, ")");
      break;

    case C_LOGICALNOT:
      (void) fprintf(fp, "(!");
      prexpr(np->rval, fp, freenode);
      (void) fprintf(fp, ")");
      break;

    case C_LSHIFTBY:
      (void) fprintf(fp, "(");
      prexpr(np->lval, fp, freenode);
      (void) fprintf(fp, " << ");
      prexpr(np->rval, fp, freenode);
      (void) fprintf(fp, ")");
      break;

    case C_PLUS:
      (void) fprintf(fp, "(");
      prexpr(np->lval, fp, freenode);
      (void) fprintf(fp, " + ");
      prexpr(np->rval, fp, freenode);
      (void) fprintf(fp, ")");
      break;

    case C_MINUS:
      (void) fprintf(fp, "(");
      prexpr(np->lval, fp, freenode);
      (void) fprintf(fp, " - ");
      prexpr(np->rval, fp, freenode);
      (void) fprintf(fp, ")");
      break;

    case C_TIMES:
      (void) fprintf(fp, "(");
      prexpr(np->lval, fp, freenode);
      (void) fprintf(fp, " * ");
      prexpr(np->rval, fp, freenode);
      (void) fprintf(fp, ")");
      break;

    case C_DIVIDEBY:
      (void) fprintf(fp, "(");
      prexpr(np->lval, fp, freenode);
      (void) fprintf(fp, " / ");
      prexpr(np->rval, fp, freenode);
      (void) fprintf(fp, ")");
      break;

    case C_MODULUS:
      (void) fprintf(fp, "(");
      prexpr(np->lval, fp, freenode);
      (void) fprintf(fp, " %% ");
      prexpr(np->rval, fp, freenode);
      (void) fprintf(fp, ")");
      break;

    case C_GREATER:
      (void) fprintf(fp, "(");
      prexpr(np->lval, fp, freenode);
      (void) fprintf(fp, " > ");
      prexpr(np->rval, fp, freenode);
      (void) fprintf(fp, ")");
      break;

    case C_LESS:
      (void) fprintf(fp, "(");
      prexpr(np->lval, fp, freenode);
      (void) fprintf(fp, " < ");
      prexpr(np->rval, fp, freenode);
      (void) fprintf(fp, ")");
      break;

    case C_ISEQUAL:
      (void) fprintf(fp, "(");
      prexpr(np->lval, fp, freenode);
      (void) fprintf(fp, " == ");
      prexpr(np->rval, fp, freenode);
      (void) fprintf(fp, ")");
      break;

    case C_LOGICALAND:
      (void) fprintf(fp, "(");
      prexpr(np->lval, fp, freenode);
      (void) fprintf(fp, " && ");
      prexpr(np->rval, fp, freenode);
      (void) fprintf(fp, ")");
      break;

    case C_LOGICALOR:
      (void) fprintf(fp, "(");
      prexpr(np->lval, fp, freenode);
      (void) fprintf(fp, " || ");
      prexpr(np->rval, fp, freenode);
      (void) fprintf(fp, ")");
      break;

    case GETS: /* AIS: this is used only if freenode == 0 */
      if(freenode) ick_lose(IE778, emitlineno, (const char*) NULL);
      prexpr(np->lval, fp, freenode);
      (void) fprintf(fp, " = ");
      prexpr(np->rval, fp, freenode);
      break;

    default: /* Added by AIS */
      if(!freenode) break; /* Be less careful when not freeing, because
			      this is used by -hH to print out its
			      intermediate optimization stages */
      ick_lose(IE778, emitlineno, (const char*) NULL);
      /*@-unreachable@*/ break; /*@=unreachable@*/
    }

    if(freenode) (void) free(np);
}
/*@=temptrans@*/ /*@=onlytrans@*/ /*@=compdestroy@*/ /*@=branchstate@*/

/* By AIS: Helper function for prunknown */
static int prunknownstr(node *np, FILE* fp)
{
  int i;
  switch(np->opcode)
  {
  case INTERSECTION:
    i=prunknownstr(np->lval, fp);
    i+=prunknownstr(np->rval, fp);
    return i;
  case BADCHAR:
    if (np->constant > 256)
      (void) fprintf(fp, "o%xx%x",
		     (unsigned int)(np->constant / 256),
		     (unsigned int)(np->constant % 256));
    else
      (void) fprintf(fp, "u%x", (unsigned int)np->constant);
    return 2;
  case US_ID: (void) fputc((char)np->constant, fp); return 0;
  case US_ELEM: (void) fputc(';', fp); return 1;
  case US_SCALAR: (void) fputc('.', fp); return 1;
  case US_ARRVAR: (void) fputc(',', fp); return 1;
  case US_EXPR: (void) fputc('~', fp); return 1;
  default: ick_lose(IE778, emitlineno, (const char*) NULL);
  }
  /*@-unreachable@*/ return 0; /*@=unreachable@*/
}

/* By AIS: Helper function for prunknown */
static void prunknowncreatedata(node *np, FILE* fp)
{
  unsigned long ve;
  switch(np->opcode)
  {
  case INTERSECTION:
    prunknowncreatedata(np->lval, fp);
    prunknowncreatedata(np->rval, fp);
    return;
  case US_ID: return; /* nothing to do */
  case US_SCALAR:
    ve=varextern(np->rval->constant,np->rval->opcode);
    fprintf(fp,"\t\t{%d,0,%lu,",np->rval->width,ve);
    break;
  case US_ARRVAR: /* an array doesn't itself have a value */
    ve=varextern(np->rval->constant,np->rval->opcode);
    fprintf(fp,"\t\t{%d,1,%lu,{ick_ieg277,ick_ies277},0},\n",
	    np->rval->width,ve);
    return;
  case US_ELEM: /* these two cases are actually treated the same way, */
  case US_EXPR: /* because expressions can be assigned to */
    fprintf(fp,"\t\t{%d,0,0,",np->rval->width);
    break;
  default: ick_lose(IE778, emitlineno, (const char*) NULL);
  }
  if(createsused)
    fprintf(fp,"{ick_og%lx,ick_os%lx},",
	    (unsigned long)np->rval,(unsigned long)np->rval);
  else
    fprintf(fp,"{0,0},");
  prexpr(np->rval,fp,0);
  fprintf(fp,"},\n");
}

/* This function by AIS. Print a check to see if a just-in-case compiled
   statement actually has a meaning yet, or if we should error. */
static void prunknown(node *np, FILE* fp)
{
  static long negcounter=-65538;
  int i,j;
  fprintf(fp,"\tif((ick_skipto=ick_jicmatch(\"");
  i=prunknownstr(np, fp);
  fprintf(fp, "\")))\n\t{\n\t    ick_createdata icd[]={\n");
  prunknowncreatedata(np, fp);
  fprintf(fp, "\t    };\n");
  if(createsused)
  {
    j=i;
    while(j--)
      (void) fprintf(fp, "\t\t""ICKSTASH(ick_TWOSPOT, %lu, "
		     "ick_twospots, ick_oo_twospots);\n"
		     "\t\t""ick_oo_twospots[%lu]=icd[%d].accessors;\n",
		     intern(ick_TWOSPOT,(unsigned long)(1601+j)),
		     intern(ick_TWOSPOT,(unsigned long)(1601+j)),j);
  }
  if(useickec)
  {
    fprintf(fp,"\t\t""ick_global_createdata=icd;\n");
    fprintf(fp,"\t\t""ick_dogoto(ick_skipto,ick_lineno,1);\n");
  }
  else
  {
    fprintf(fp,"\t\t""ick_pushnext(%ld); ick_skipto=-ick_skipto; goto top; "
	    "case %ld:;\n",negcounter,negcounter);
    negcounter--;
  }
  if(createsused)
  {
    j=i;
    while(j--)
      (void) fprintf(fp, "\t\t""ICKRETRIEVE(ick_twospots, %lu, "
		     "ick_TWOSPOT, ick_twoforget, ick_oo_twospots);\n",
		     intern(ick_TWOSPOT,(unsigned long)(1601+j)));

  }
  fprintf(fp, "\t} else\n");
}

/*@dependent@*/ static char *nice_text(char *texts[], int lines)
{
#define MAXNICEBUF	512
  static char buf[MAXNICEBUF];
  char *cp, *text;
  int i;

  if (lines < 1)
    lines = 1;
  for (cp = buf, i = 0 ; i < lines ; ++i) {
    if (cp>buf+MAXNICEBUF-10)
    {
      (*cp++) = '.';
      (*cp++) = '.';
      (*cp++) = '.';
      *cp = '\0';
      return buf;
    }
    if (i) {
      (*cp++) = '\\';
      (*cp++) = 'n';
      (*cp++) = '\\';
      (*cp++) = '\n';
      (*cp++) = '\t';
    }
    for (text = texts[i] ; text != NULL && *text != '\0'; cp++, text++) {
      if (cp>buf+MAXNICEBUF-10)
      {
	(*cp++) = '.';
	(*cp++) = '.';
	(*cp++) = '.';
	*cp = '\0';
	return buf;
      }
      if(*text == '"' || *text == '\\') {
	(*cp++) = '\\';
      }
      if(*text == 'K') /* AIS: break the string so that the ick_ec
			  preprocessor doesn't trigger on the string
			  ICKNUMBERPAIR */
      {
	(*cp++) = '"';
	(*cp++) = '"';
      }
      *cp = *text;
    }
  }
  *cp = '\0';
  return buf;
}

static void emit_guard(tuple *tn, FILE *fp)
/* emit execution guard for giiven tuple (note the unbalanced trailing {!) */
{
  if(tn->maybe) /* AIS */
  {
    if(!multithread) ick_lose(IE405, emitlineno, (const char *)NULL);
    (void) fprintf(fp, "    gonebackto = setjmp(btjb); choicepoint();\n");
  }
  if(!flowoptimize || tn->abstainable) /* This condition by AIS */
  {
    (void) fprintf(fp, "    if (");
    if (tn->maybe) /* AIS */
      (void) fprintf(fp, "gonebackto == !(");
    if (tn->exechance < 100)
	(void) fprintf(fp, "ick_roll(%d) && ", tn->exechance);
    if ((tn->type != NEXT && tn->type != GO_BACK && tn->type != COME_FROM
	 && /* AIS */ tn->type != NEXTFROMLABEL && tn->type != UNKNOWN)
	|| tn->onceagainflag == onceagain_NORMAL)
      (void) fprintf(fp, "!ICKABSTAINED(%d))%s {\n", (int)(tn - tuples),
		     /* AIS */ tn->maybe?")":"");
    else /* AIS: [NEXT, GO_BACK, COME_FROM] ONCE needs specially
	    handled abstentions */
      (void) fprintf(fp, "!ick_oldabstain)%s {\n",
		     /* AIS */ tn->maybe?")":"");
  }
  else
  { /* AIS */
    if(tn->maybe) ick_lose(IE778, emitlineno, (const char*) NULL);
    if(!tn->initabstain)
    {
      if(tn->type != COMPUCOME && tn->type != GERUCOME
	 && tn->type != NEXTFROMEXPR && tn->type != NEXTFROMGERUND)
	(void) fprintf(fp, "    {\n");
      else (void) fprintf(fp, "    if(1) {\n"); /* COMPUCOME specifically needs
						   an if() so it can have
						   an else. */
    }
    else (void) fprintf(fp, "    if(0) {\n"); /* for exceptional cases like
						 DON'T COME FROM #1 where we
						 need a label or an else. */
  }
}

void emittextlines(FILE *fp)
{
  int i=0; /* The first textline is line 1 */
  (void) fprintf(fp, "\"\",\n");
  while(++i<iyylineno)
  {
    (void) fprintf(fp, "\"%s\",\n",nice_text(textlines + i, 0));
  }
  (void) fprintf(fp, "\"\"\n");
}

/*@-nestedextern@*/
void emit(tuple *tn, FILE *fp)
/* emit code for the given tuple */
{
    node *np, *sp;
    int	dim;
    int generatecfjump=0; /* AIS */
    static int pasttryagain=0; /* AIS */
    extern bool cdebug; /* AIS */

    /* grind out label and source dump */
    if (yydebug || cdebug || compile_only)
	(void) fprintf(fp, "    /* line %03d */\n", tn->ick_lineno);
    if (tn->label)
    {
      if(!useickec) /* AIS */
	(void) fprintf(fp, "case -%u: ; L%u:\n", tn->label, tn->label);
      else
	/* AIS: start one of ick_ec's labeled blocks. */
	(void) fprintf(fp, "ick_labeledblock(%uU,{",tn->label);
    }
    if (yydebug || cdebug || compile_only)
    {
      (void) fprintf(fp, "\t""/* %s */", textlines[tn->ick_lineno]);
      /* AIS: grind out an expression explanation */
      if (tn->type == GETS || tn->type == FORGET || tn->type == RESUME
	  || tn->type == FROM || tn->type == COMPUCOME
	  || tn->type == MANYFROM || tn->type == NEXTFROMEXPR)
      {
	(void) fprintf(fp, "\n\t/* Expression is ");
	explexpr(tn->type == MANYFROM ? tn->u.node->lval :
		 tn->type == GETS ? tn->u.node->rval : tn->u.node, fp);
	(void) fprintf(fp, " */");
      }
    }
    (void) fputc('\n', fp);

    /* set up the "next" lexical line number for error messages */
    if (tn->type == NEXT) {
	tuple *up;
	for (up = tuples; up < tuples + ick_lineno; up++)
	    if (tn->u.target == up->label) {
		emitlineno = up->ick_lineno;
		break;
	    }
    }
    else if (tn->ncomefrom)
    {
       /* AIS: For multithreading. Return the 1st if we're forking. */
      emitlineno = comefromsearch(tn,1);
      if(emitlineno != -1)
	emitlineno = tuples[emitlineno-1].ick_lineno;
    }
    else if (tn < tuples + ick_lineno - 1)
	emitlineno = tn[1].ick_lineno;
    else
	emitlineno = iyylineno;
    if(!pickcompile) /* AIS: PICs can't report errors,
			so don't bother with ick_lineno */
      (void) fprintf(fp, "    ick_lineno = %d;\n", emitlineno);

    /* AIS: figure out which line we're on, so E000 can be done correctly */
    if (tn < tuples + ick_lineno - 1)
      dim = tn[1].ick_lineno - tn->ick_lineno;
    else
      dim = iyylineno - tn->ick_lineno;
    if (tn->sharedline)
      ++dim;
    E000string=nice_text(textlines + tn->ick_lineno, dim);

    /* AIS: set weaving status if necessary */
    if(tn->setweave)
	(void) fprintf(fp, "    weaving = %d;\n", (tn->setweave>0)?1:0);

    /* AIS: print warnings on -l */
    if(ick_checkforbugs)
    {
      if(tn->warn112) ick_lwarn(W112, emitlineno, (const char*) NULL);
      if(tn->warn128) ick_lwarn(W128, emitlineno, (const char*) NULL);
      if(tn->warn534) ick_lwarn(W534, emitlineno, (const char*) NULL);
      if(tn->warn018) ick_lwarn(W018, emitlineno, (const char*) NULL);
      if(tn->warn016) ick_lwarn(W016, emitlineno, (const char*) NULL);
      if(tn->warn276) ick_lwarn(W276, emitlineno, (const char*) NULL);
      if(tn->warn239) ick_lwarn(W239, emitlineno, (const char*) NULL);
      if(tn->warn622) ick_lwarn(W622, emitlineno, (const char*) NULL);
    }

    /* AIS: emit debugging information */
    if (yukdebug||yukprofile)
    {
	(void) fprintf(fp, "    YUK(%d,%d);\n",
		       (int)(tn-tuples),emitlineno);
    }

    /* AIS: The +mystery option on degenerated code causes the code to
       unexpectedly terminate after 4 billion commands are run, thus
       preventing an infinite loop. Of course, it will enhance the fun
       if we don't tell the user that. (This is necessary for the
       constant-output optimizer to work properly.) */
    if(coopt) (void) fprintf(fp, "    ick_MYSTERYLINE;\n");

    /* AIS: If the tuple is ONCE/AGAIN flagged, we need a delayed-action
       set of its abstention status to the AGAIN-flagged status. The
       problem is that some statements, like COME FROM, need to set after
       the command has finished, and some, like NEXT, need it before the
       command has started. At the moment, only NEXT and GO_BACK have a
       ONCE/AGAIN before it, rather than after (because neither of them
       continue in the normal fashion). UNKNOWN is also handled this way,
       because CREATEd statements can be NEXT-like but not COME FROM-like. */
    if ((tn->type == NEXT || tn->type == GO_BACK || tn->type == UNKNOWN) &&
	tn->onceagainflag != onceagain_NORMAL)
    {
      /* ONCE/AGAIN has already been swapped by perpet.c in the case
	 of a preabstained statement ('DO NOT'...). So if we currently have
	 a ONCE, it means that being abstained is the attractive state,
	 and if we currently have an AGAIN, it means that being
         reinstated is the attractive state. Semantics with computed
	 ABSTAIN: Don't change the abstention count unless necessary, in
	 which case change it to 0 or 1. */
      fprintf(fp,"    ick_oldabstain = ICKABSTAINED(%d);\n", (int)(tn - tuples));
      fprintf(fp,"    ICKABSTAINED(%d) = %s;\n",
	      (int)(tn - tuples),
	      tn->onceagainflag==onceagain_ONCE ? "ick_oldabstain ? ick_oldabstain : 1"
	      : "0");
      /* This test-and-set must be atomic. As all statements are atomic anyway
         in the current version of ick, that isn't a problem, but if anyone
	 wants to try using POSIX's multithreading features, the above two
	 lines need to be a critical section. */
    }

    /* AIS: in the case of COMPUCOME, we need an extra guard unless useickec. */
    if ((!useickec && (tn->type == COMPUCOME || tn->type == NEXTFROMEXPR))
	 || tn->type == GERUCOME || tn->type == NEXTFROMGERUND)
    {
      fprintf(fp,"    if(0)\n    {\n");
      fprintf(fp,"CCF%d:\n",compucomecount++);
      if(tn->type == COMPUCOME || tn->type == NEXTFROMEXPR)
      {
	fprintf(fp,"    if(ick_skipto&&ick_skipto==");
	prexpr(tn->u.node, fp, 1);
      }
      else if(tn->type == GERUCOME || tn->type == NEXTFROMGERUND)
      {
	fprintf(fp,"    if(");
	for (np = tn->u.node; np; np = np->rval)
	{
	  if (np->constant == ABSTAIN) {
	    (void) fprintf(fp,
"linetype[truelineno] == %s || linetype[truelineno] == %s || "
"linetype[truelineno] == %s || linetype[truelineno] == %s || ",
			   enablers[np->constant-GETS],
			   enablers[np->constant-GETS+2],
			   enablers[FROM-GETS], enablers[MANYFROM-GETS]);
	  } else if (np->constant == REINSTATE) {
	    (void) fprintf(fp,
"linetype[truelineno] == %s || linetype[truelineno] == %s || ",
			   enablers[np->constant-GETS],
			   enablers[np->constant-GETS+2]);
	  } else if (np->constant == GETS) {
	    (void) fprintf(fp,
"linetype[truelineno] == %s || linetype[truelineno] == %s || ",
			   enablers[GETS-GETS],
			   enablers[RESIZE-GETS]);
	  } else if (np->constant == COME_FROM) {
	    (void) fprintf(fp,
"linetype[truelineno] == %s || linetype[truelineno] == %s || "
"linetype[truelineno] == %s || ",
			   enablers[COME_FROM-GETS],
			   enablers[COMPUCOME-GETS],
			   enablers[GERUCOME-GETS]);
	  } else if (np->constant == NEXTFROMLABEL) {
	    (void) fprintf(fp,
"linetype[truelineno] == %s || linetype[truelineno] == %s || "
"linetype[truelineno] == %s || ",
			   enablers[NEXTFROMLABEL-GETS],
			   enablers[NEXTFROMEXPR-GETS],
			   enablers[NEXTFROMGERUND-GETS]);
	  } else {
	    (void) fprintf(fp, "linetype[truelineno] == %s || ",
			   enablers[np->constant-GETS]);
	  }
	}
	fprintf(fp, "0");
      }
      fprintf(fp,") {\n");
    }

    /* AIS: With this block placed here, you can't even have a comment
       after a TRY AGAIN line. Move it below the next check if this seems
       to be undesirable behaviour. */
    if(pasttryagain) /* AIS */
    {
      ick_lose(IE993, emitlineno, (const char*)NULL);
    }

    if(flowoptimize && tn->initabstain && !tn->abstainable
       && tn->type != COMPUCOME && tn->type != COME_FROM &&
       tn->type != NEXT && tn->type != GERUCOME &&
       tn->type != NEXTFROMLABEL && tn->type != NEXTFROMEXPR &&
       tn->type != NEXTFROMGERUND) /* AIS */
      goto skipcomment; /* Look, a comment! We can completely skip all
			   degeneration of this statement (although with
			   -c, comments will appear in the degenerated
			   code in its place). The COMPUCOME condition is
			   because it is so weird. COME_FROM and NEXT are
			   exempted so labels are generated. */

    /* emit conditional-execution prefixes */
    /* AIS: added the useickec condition */
    if ((tn->type != COME_FROM && tn->type != NEXTFROMLABEL) || useickec)
	emit_guard(tn, fp);

    /* now emit the code for the statement body */
    switch(tn->type)
    {
    case GETS:
      /* AIS: variableconstants means GETS has been generalised */
      if(variableconstants)
      {
	revprexpr(tn->u.node->lval, fp, tn->u.node->rval);
	nodefree(tn->u.node);
	break;
      }

        /* Start of AIS optimization */
	np = tn->u.node;
	if(np->lval->opcode == SUB) np = np->lval;
	if(flowoptimize && ick_Base == 2 && !opoverused && !variableconstants &&
	   (np->lval->opcode == ick_TWOSPOT
	    || np->lval->opcode == ick_HYBRID
	    || !(tn->u.node->rval->optdata & ~0xffffLU)))
	{
	  atom* op;
	  int ignorable = 1;
	  assert(oblist != NULL);
	  for(op = oblist; op < obdex; op++)
	  {
	    if(op->type == np->lval->opcode &&
	       (unsigned long)op->intindex == np->lval->constant)
	    {
	      ignorable &= op->ignorable;
	    }
	  }
	  if(!ignorable)
	  { /* Variable can't be ignored, and expression must be in range */
	    (void) fprintf(fp,"\t""");
	    prexpr(tn->u.node->lval, fp, 1);
	    (void) fprintf(fp, " = ");
	    prexpr(tn->u.node->rval, fp, 1);
	    (void) fprintf(fp, ";\n");
	    break;
	  }
	}
	/* End of AIS optimization */
	if(opoverused&&
	   (tn->u.node->lval->opcode==ick_ONESPOT||
	    tn->u.node->lval->opcode==ick_TWOSPOT)) /* AIS */
	{
	  (void) fprintf(fp,"\t""");
	  ooprvar(tn->u.node->lval, fp, 1);
	  (void) fprintf(fp,".set(");
	  prexpr(tn->u.node->rval, fp, 1);
	  (void) fprintf(fp,",os%dspot%lu);\n",
			 ((tn->u.node->lval->opcode==ick_TWOSPOT)?1:0)+1,
			 tn->u.node->lval->constant);
	}
	else if(!pickcompile)
	{
	  np = tn->u.node;

	  if (np->lval->opcode != SUB) {
	    sp = np->lval;
	    (void) fprintf(fp,"\t""(void) ick_assign((char*)&");
	  }
	  else {
	    sp = np->lval->lval;
	    (void) fprintf(fp,"\t""(void) ick_assign(");
	  }
	  prvar(np->lval, fp, 1);
	  (void) fprintf(fp,", %s", nameof(sp->opcode, vartypes));
	  (void) fprintf(fp,", %s[%lu], ", nameof(sp->opcode, forgetbits),
			 sp->constant);
	  prexpr(np->rval, fp, 1);
	  (void) fprintf(fp,");\n");
	}
	else /* AIS: Added this case for the simpler PIC assignment rules */
	{
	  (void) fprintf(fp,"\t""if(ignore%s%lu) ",
			 nameof(tn->u.node->lval->opcode,varstores),
			 tn->u.node->lval->constant);
	  prexpr(tn->u.node->lval, fp, 1);
	  (void) fprintf(fp, " = ");
	  prexpr(tn->u.node->rval, fp, 1);
	  (void) fprintf(fp, ";\n");
	}
	break;

    case RESIZE:
      if(pickcompile) ick_lose(IE256, emitlineno, (const char*) NULL); /* AIS */
	np = tn->u.node;
	dim = 0;
	for (sp = np->rval; sp; sp = sp->rval)
	  dim++;
	(void) fprintf(fp, "\t""ick_resize(");
	prvar(np->lval, fp, 1);
#ifdef BOOL_VARARGS_BROKEN
	(void) fprintf(fp, ", (int)%s[%lu]", nameof(np->lval->opcode, forgetbits),
		       np->lval->constant);
#else
	(void) fprintf(fp, ", %s[%lu]", nameof(np->lval->opcode, forgetbits),
		       np->lval->constant);
#endif
	(void) fprintf(fp, ", %d", dim);
	for (sp = np->rval; sp; sp = sp->rval) {
	  (void) fprintf(fp, ", (size_t)");
	  prexpr(sp->lval, fp, 1);
        }
	(void) fprintf(fp, ");\n");
	break;

    case NEXT:
      /* AIS: if using ickec, use its features for the next */
      if(useickec)
      {
	(void) fprintf(fp,"\t""ick_dogoto(%uU,ick_lineno,1);\n",tn->u.target);
	break;
      }
      /* Start of AIS optimization */
      if(tn->u.target>=1000 && tn->u.target<=1999 && pickcompile)
      {
	/* optimize syslib call on a PIC */
	(void) fprintf(fp, "\t""syslibopt%u();\n", tn->u.target);
	break;
      }
      if(tn->optversion)
      { /* optimizef has checked that this is a valid optimization */
	(void) fprintf(fp, "\t""if(1 == ");
	prexpr(tn->u.node, fp, 1); /* frees optimizef's nodecopy */
	/* AIS: Everything now in one giant switch(), with some very strange
	   constructs (including ;{;} as a null statement; this makes
	   degenerating the code slightly easier) */
	(void) fprintf(fp, ") {ick_pushnext(%d); ick_skipto=%uU; goto top;}} case %d:;{;\n",
		       (int)(tn - tuples + 1), tn->nexttarget, (int)(tn - tuples + 1));
	break;
      }
      /* End of AIS optimization */
      (void) fprintf(fp, /* same change as above (case rather than a label) */
		     "\t""ick_pushnext(%d); goto L%u;} case %d:;{;\n",
		     (int)(tn - tuples + 1), tn->u.target, (int)(tn - tuples + 1));
      break;

    case GO_BACK: /* By AIS */
      if(!multithread) ick_lose(IE405, emitlineno, (const char*) NULL);
      (void) fprintf(fp, "\t""choiceback();\n");
      break;

    case GO_AHEAD: /* By AIS */
      if(!multithread) ick_lose(IE405, emitlineno, (const char*) NULL);
      (void) fprintf(fp, "\t""choiceahead();\n");
      break;

    case RESUME:
      if(useickec) /* AIS */
      {
	(void) fprintf(fp, "\t""ick_doresume(");
	prexpr(tn->u.node, fp, 1);
	(void) fprintf(fp, ", ick_lineno);\n");
	break;
      }
	(void) fprintf(fp, "\t""ick_skipto = ick_resume(");
	prexpr(tn->u.node, fp, 1);
	(void) fprintf(fp, "); goto top;\n");
	break;

    case FORGET:
      if(useickec) /* AIS */
      {
	(void) fprintf(fp, "\t""ick_forget(");
	prexpr(tn->u.node, fp, 1);
	(void) fprintf(fp, ");\n");
	break;
      }

	(void) fprintf(fp, "\t""ick_popnext(");
	prexpr(tn->u.node, fp, 1);
	(void) fprintf(fp, ");\n");
	break;

    case STASH:
	for (np = tn->u.node; np; np = np->rval)
	    (void) fprintf(fp, "\t""ICKSTASH(%s, %lu, %s, %s%s);\n",
			   nameof(np->opcode, vartypes),
			   np->constant,
			   nameof(np->opcode, varstores),
			   /* AIS */(opoverused&&(np->opcode==ick_ONESPOT||
						  np->opcode==ick_TWOSPOT)?
			   "ick_oo_":"0"),
			   /* AIS */(opoverused&&(np->opcode==ick_ONESPOT||
						  np->opcode==ick_TWOSPOT)?
			   nameof(np->opcode, varstoresdem):"0"));
	break;

    case RETRIEVE:
	for (np = tn->u.node; np; np = np->rval)
	    (void) fprintf(fp, "\t""ICKRETRIEVE(%s, %lu, %s, %s, %s%s);\n",
			   nameof(np->opcode, varstores), np->constant,
			   nameof(np->opcode, vartypes),
			   nameof(np->opcode, forgetbits),
			   /* AIS */(opoverused&&(np->opcode==ick_ONESPOT||
						  np->opcode==ick_TWOSPOT)?
			   "ick_oo_":"0"),
			   /* AIS */(opoverused&&(np->opcode==ick_ONESPOT||
						  np->opcode==ick_TWOSPOT)?
			   nameof(np->opcode, varstoresdem):"0"));

	break;

    case IGNORE:
	for (np = tn->u.node; np; np = np->rval)
	    (void) fprintf(fp,"\t""ICKIGNORE(%s,%lu,%s) = true;\n",
			   nameof(np->opcode, forgetbits),
			   np->constant,
			   nameof(np->opcode, varstores));
	break;

    case REMEMBER:
	for (np = tn->u.node; np; np = np->rval)
	    (void) fprintf(fp,"\t""ICKIGNORE(%s,%lu,%s) = false;\n",
			   nameof(np->opcode, forgetbits),
			   np->constant,
			   nameof(np->opcode, varstores));
	break;

	/* All abstention code has been edited by AIS to allow for the new
	   abstention rules */
    case ABSTAIN:
      /* AIS: In CLC-INTERCAL, you can't abstain a GIVE UP line, so I copied
         a modified version of Joris's REINSTATE patch here as well */
      if (!ick_clcsemantics || (tuples + tn->u.target - 1)->type != GIVE_UP)
      {
	if(!pickcompile)
	  (void) fprintf(fp, "\t""if(!ICKABSTAINED(%u)) ICKABSTAINED(%u) = 1;\n", tn->u.target - 1, tn->u.target-1);
	else
	  (void) fprintf(fp, "ICKABSTAINED(%u) = 1;\n", tn->u.target-1);
      }
      else
	(void) fprintf(fp, "\t""/* not abstaining from a GIVE UP line */\n");;
      break;

    case FROM:
      if(pickcompile) ick_lose(IE256, emitlineno, (const char*) NULL);
        (void) fprintf(fp, "\t""ICKABSTAINED(%u)+=", tn->u.target-1);
	tn->u.node->width = 32;
	prexpr(tn->u.node,fp, 1);
	(void) fprintf(fp, ";\n");
	break;

    case REINSTATE:
        /* (Joris Huizer) ensure it is not a GIVE UP statement */
        if ((tuples + tn->u.target - 1)->type != GIVE_UP)
        {
          if(!pickcompile)
            (void) fprintf(fp, "\t""if(ICKABSTAINED(%u)) ICKABSTAINED(%u)--;\n", tn->u.target - 1, tn->u.target-1);
          else
            (void) fprintf(fp, "\t""ICKABSTAINED(%u)=0;\n", tn->u.target - 1);
        }
        else
          (void) fprintf(fp, "\t""/* not reinstating a GIVE UP line */\n");
        break;

    case ENABLE:
    case DISABLE:
    case MANYFROM:
      /* AIS: This code has been rewritten to make use of the revlinetype array
	 (an optimisation that Joris Huizer came up with; however, I am not
	 using his code, but rewriting it, to make use of a single array and an
	 index to it, rather than one array for each command type, for
	 maintainability reasons. */
      if(pickcompile) ick_lose(IE256, emitlineno, (const char*) NULL);
      (void) fprintf(fp,"\tint i;\n");
      np=tn->u.node;
      if(tn->type==MANYFROM)
      {
	np=np->rval;
	fprintf(fp,"\tint j = ");
	prexpr(tn->u.node->lval, fp, 1);
	fprintf(fp,";\n");
      }
      for(; np; np = np->rval)
      {
	int npc = np->constant;
      anothertype:
	(void) fprintf(fp,"\n\tfor(i=revlineindex[%s];i<revlineindex[%s+1];i++)\n",
		       enablers[npc-GETS],enablers[npc-GETS]);
	switch(tn->type)
	{
	case ENABLE:  (void) fprintf(fp,"\t    if (ick_abstained[revlinetype[i]])"
				    "\t\tick_abstained[revlinetype[i]]--;\n"); break;
	case DISABLE: (void) fprintf(fp,"\t    if(!ick_abstained[revlinetype[i]])"
				    "\t\tick_abstained[revlinetype[i]]=1;\n"); break;
	case MANYFROM:(void) fprintf(fp,"\tick_abstained[revlinetype[i]]+=j;\n"); break;
	default:      ick_lose(IE994, emitlineno, (const char *)NULL);
	}
	switch(npc)
	{
	case GETS:          npc=RESIZE;         goto anothertype;
	case ABSTAIN:       npc=DISABLE;        goto anothertype;
	case DISABLE:       npc=FROM;           goto anothertype;
	case FROM:          npc=MANYFROM;       goto anothertype;
	case REINSTATE:     npc=ENABLE;         goto anothertype;
	case COME_FROM:     npc=COMPUCOME;      goto anothertype;
	case COMPUCOME:     npc=GERUCOME;       goto anothertype;
	case NEXTFROMLABEL: npc=NEXTFROMEXPR;   goto anothertype;
	case NEXTFROMEXPR:  npc=NEXTFROMGERUND; goto anothertype;
	default: break;
	}
      }
      break;

    case NEXTFROMEXPR:
    case NEXTFROMGERUND:
    case GERUCOME:
    case COMPUCOME: /* By AIS. Note that this doesn't even have balanced
		       braces; it's designed to work with COMPUCOME's
		       crazy guarding arrangements */
      if(pickcompile) ick_lose(IE256, emitlineno, (const char*) NULL); /* AIS */
      if(useickec) /* use ick_ec's features for next from and come from*/
      {
	if(tn->type == COMPUCOME)
	{
	  fprintf(fp,"\t""ick_docomefromif(");
	  prexpr(tn->u.node, fp, 1);
	  fprintf(fp,",ick_lineno,({int i=0;");
	  emit_guard(tn,fp); /* re-emit the guard */
	  fprintf(fp,"i=1;};i;}));\n");
	  break;
	}
	else if(tn->type == NEXTFROMEXPR)
	{
	  fprintf(fp,"\t""ick_donextfromif(");
	  prexpr(tn->u.node, fp, 1);
	  fprintf(fp,",ick_lineno,({int i=0;");
	  emit_guard(tn,fp); /* re-emit the guard */
	  fprintf(fp,"i=1;};i;}));\n");
	  break;
	}
      }
      fprintf(fp,"\t""%s;} else goto CCF%d;\n",
	      multithread?"NEXTTHREAD":useprintflow?
	      "if(ick_printflow) fprintf(stderr,\"[%d]\",ick_lineno)":"",
	      compucomecount);
      break;

    case GIVE_UP: /* AIS: Edited to allow for yuk */
      if(yukprofile||yukdebug) fprintf(fp, "\t""YUKTERM;\n");
      if(multithread) fprintf(fp, "\t""killthread();\n");
      else
      {
	if(nonespots||opoverused)
	  fprintf(fp,"\t""if(ick_onespots) free(ick_onespots);\n");
	if(ntwospots||opoverused)
	  fprintf(fp,"\t""if(ick_twospots) free(ick_twospots);\n");
	if(ntails) fprintf(fp,"\t""if(ick_tails) free(ick_tails);\n");
	if(nhybrids) fprintf(fp,"\t""if(ick_hybrids) free(ick_hybrids);\n");
	if(nonespots||opoverused)
	  fprintf(fp,"\t""if(ick_oneforget) free(ick_oneforget);\n");
	if(ntwospots||opoverused)
	  fprintf(fp,"\t""if(ick_twoforget) free(ick_twoforget);\n");
	if(ntails) fprintf(fp,"\t""if(ick_tailforget) free(ick_tailforget);\n");
	if(nhybrids) fprintf(fp,"\t""if(ick_hyforget) free(ick_hyforget);\n");
	if(opoverused)
	{
	  fprintf(fp,"\t""if(ick_oo_onespots) free(ick_oo_onespots);\n");
	  fprintf(fp,"\t""if(ick_oo_twospots) free(ick_oo_twospots);\n");
	}
	fprintf(fp,"\t""if(ick_next) free(ick_next);\n");
	if(useickec)
	  fprintf(fp,"\t""if(ick_next_jmpbufs) free(ick_next_jmpbufs);\n");
      }
      (void) fprintf(fp, "\t""exit(0);\n");
      break;

    case TRY_AGAIN: /* By AIS */
      (void) fprintf(fp, "\t""goto ick_restart;\n    }\n");
      if(yukprofile||yukdebug) fprintf(fp, "    if(yukloop) goto ick_restart;\n");
      if(yukprofile||yukdebug) fprintf(fp, "    YUKTERM;\n");
      if(multithread) fprintf(fp, "\t""killthread();\n");
      else
      {
	if(nonespots||opoverused)
	  fprintf(fp,"\t""if(ick_onespots) free(ick_onespots);\n");
	if(ntwospots||opoverused)
	  fprintf(fp,"\t""if(ick_twospots) free(ick_twospots);\n");
	if(ntails) fprintf(fp,"\t""if(ick_tails) free(ick_tails);\n");
	if(nhybrids) fprintf(fp,"\t""if(ick_hybrids) free(ick_hybrids);\n");
	if(nonespots||opoverused)
	  fprintf(fp,"\t""if(ick_oneforget) free(ick_oneforget);\n");
	if(ntwospots||opoverused)
	  fprintf(fp,"\t""if(ick_twoforget) free(ick_twoforget);\n");
	if(ntails) fprintf(fp,"\t""if(ick_tailforget) free(ick_tailforget);\n");
	if(nhybrids) fprintf(fp,"\t""if(ick_hyforget) free(ick_hyforget);\n");
	if(opoverused)
	{
	  fprintf(fp,"\t""if(ick_oo_onespots) free(ick_oo_onespots);\n");
	  fprintf(fp,"\t""if(ick_oo_twospots) free(ick_oo_twospots);\n");
	}
      }
      (void) fprintf(fp, "    {\n\treturn(0);\n");
      /* because if TRY AGAIN is the last line, falling off the end isn't an error */
      pasttryagain=1; /* flag an error if we try any more commands */
      break;

    case WRITE_IN:
      if(pickcompile) ick_lose(IE256, emitlineno, (const char*) NULL); /* AIS */
      for (np = tn->u.node; np; np = np->rval) {
	  if (np->lval->opcode == ick_TAIL || np->lval->opcode == ick_HYBRID) {
	    (void) fprintf(fp,"\t""ick_binin(");
	    prvar(np->lval, fp, 1);
	    (void) fprintf(fp, ", %s[%lu]",
			   nameof(np->lval->opcode, forgetbits),
			   np->lval->constant);
	    (void) fprintf(fp,");\n");
	  }
	  else {
	    if (np->lval->opcode != SUB) {
	      sp = np->lval;
	      (void) fprintf(fp,"\t""(void) ick_assign((char*)&");
	    }
	    else {
	      sp = np->lval->lval;
	      (void) fprintf(fp,"\t""(void) ick_assign(");
	    }
	    prvar(np->lval, fp, 1);
	    (void) fprintf(fp,", %s", nameof(sp->opcode, vartypes));
	    (void) fprintf(fp,", %s[%lu]", nameof(sp->opcode, forgetbits),
			   sp->constant);
	    (void) fprintf(fp,", ick_pin());\n");
	  }
	}
	break;

    case READ_OUT:
      if(pickcompile) ick_lose(IE256, emitlineno, (const char*) NULL); /* AIS */
	for (np = tn->u.node; np; np = np->rval)
	{
	  if (np->lval->opcode == ick_TAIL || np->lval->opcode == ick_HYBRID) {
	    (void) fprintf(fp,"\t""ick_binout(");
	    prvar(np->lval, fp, 1);
	    (void) fprintf(fp,");\n");
	  }
	  else {
	    (void) fprintf(fp, "\t""ick_pout(");
	    prexpr(np->lval, fp, 1);
	    (void) fprintf(fp, ");\n");
	  }
	}
	break;

    case PIN: /* AIS, with some code borrowed from the GETS code */
      np = tn->u.node;
      (void) fprintf(fp, "\t""TRISA = seq(~((");
      prexpr(np, fp, 0);
      (void) fprintf(fp, " >> 16) & 255));\n");
      (void) fprintf(fp, "\t""TRISB = seq(~(");
      prexpr(np, fp, 0);
      (void) fprintf(fp, " >> 24));\n");
      (void) fprintf(fp, "\t""PORTA = seq(~(");
      prexpr(np, fp, 0);
      (void) fprintf(fp, " & 255));\n");
      (void) fprintf(fp, "\t""PORTB = seq(~((");
      prexpr(np, fp, 0);
      (void) fprintf(fp, " >> 8) & 255));\n");
      {
	atom* op;
	int ignorable = 1;
	assert(oblist != NULL);
	for(op = oblist; op < obdex; op++)
	{
	  if(op->type == np->opcode &&
	     (unsigned long)op->intindex == np->constant)
	  {
	    ignorable &= op->ignorable;
	  }
	}
	if(!ignorable)
	{ /* Variable can't be ignored, and expression must be in range */
	  (void) fprintf(fp,"\t""");
	  prexpr(np, fp, 1);
	  (void) fprintf(fp, " = ");
	}
	else
	{
	  np = tn->u.node;
	  (void) fprintf(fp,"\t""if(ignore%s%lu) ",
			 nameof(np->opcode,varstores),
			 np->constant);
	  prexpr(np, fp, 1);
	  (void) fprintf(fp, " = ");
	}
      }
      (void) fprintf(fp,"(TRISB<<24) | (TRISA<<16) | (PORTB<<8) | PORTA;\n");
      break;

    case CREATE: /* By AIS */
      if(createsused == 0) goto splatme;
      (void) fprintf(fp,"\t""ick_registercreation(\"");
      (void) prunknownstr(tn->u.node, fp);
      (void) fprintf(fp,"\",%uU);\n",tn->u.target);
      break;

    case COMPUCREATE: /* By AIS */
      if(createsused == 0) goto splatme;
      (void) fprintf(fp,"\t""ick_registercreation(\"");
      (void) prunknownstr(tn->u.node->rval, fp);
      (void) fprintf(fp,"\",");
      prexpr(tn->u.node->lval, fp, 1);
      (void) fprintf(fp,");\n");
      free(tn->u.node); /* don't free the rval */
      break;

    case UNKNOWN: /* By AIS */
      /* We generate a check to see if the unknown statement has gained a
	 meaning since it was compiled, or otherwise continue to the splattered
	 case. Not for PIC-INTERCAL, though. */
      if(!pickcompile) prunknown(tn->u.node, fp);
      /*@fallthrough@*/
    case SPLATTERED:
      /* AIS: The code previously here could access unallocated memory due to
	 a bug if the comment was a COME FROM target. The problem is that
	 emitlineno (the line to show an error on) is usually the line after
	 this one, but not always, and in this case the line after this one is
	 always what we want, so I copied the relevant part of the emitlineno
	 logic here to fix the bug. */
    splatme:
      if (tn < tuples + ick_lineno - 1)
	dim = tn[1].ick_lineno - tn->ick_lineno;
      else
	dim = iyylineno - tn->ick_lineno;
      if (tn->sharedline)
	++dim;
      (void) fprintf(fp, "\t""ick_lose(IE000, %d, \"%s\");\n",
		     emitlineno, nice_text(textlines + tn->ick_lineno, dim));
      break;

    case PREPROC: /* AIS: 'DO NOTHING', but not enterable into a program. This
		     is generated by the preprocessor. */
      fprintf(fp,"\t""; /* do nothing */\n");
      break;

    case COME_FROM:
    case NEXTFROMLABEL: /* AIS */
      if(useickec) /* AIS */
      {
	if(tn->type == COME_FROM)
	{
	  fprintf(fp,"\t""ick_docomefromif(%uU,ick_lineno,({int i=0;",
		  tn->u.target);
	  emit_guard(tn,fp); /* re-emit the guard */
	  fprintf(fp,"i=1;};i;}));\n");
	  break;
	}
	else /* (tn->type == NEXTFROMLABEL) */
	{
	  fprintf(fp,"\t""ick_donextfromif(%uU,ick_lineno,({int i=0;",
		  tn->u.target);
	  emit_guard(tn,fp); /* re-emit the guard */
	  fprintf(fp,"i=1;};i;}));\n");
	  break;
	}
      }
	(void) fprintf(fp, "if(0) {C%ld: %s;%s}\n", (long)(tn-tuples+1),
		       tn->type==NEXTFROMLABEL ? "ick_pushnext(truelineno+1)":"",
		       multithread?" NEXTTHREAD;":!useprintflow?""
		       :" if(ick_printflow) "
		       "fprintf(stderr,\"[%d]\",ick_lineno);");
	/* AIS: Changed so all COME_FROMs have unique labels even if two
	   of them aim at the same line, and added the NEXT FROM case (which
	   involves hiding COME FROM labels in an unreachable if()). */
	break;

    case WHILE: /* AIS: fall through to the error, because this shouldn't
		   come up yet. */
    default:
	ick_lose(IE994, emitlineno, (const char *)NULL);
	/*@-unreachable@*/ break; /*@=unreachable@*/
    }

    if ((tn->type != COME_FROM && tn->type != NEXTFROMLABEL)
	|| /*AIS*/ useickec)
	(void) fprintf(fp, "    }\n");

 skipcomment:

    if ((!useickec && (tn->type == COMPUCOME || tn->type == NEXTFROMEXPR))
	|| tn->type == NEXTFROMGERUND  || tn->type == GERUCOME )
    { /* By AIS */
      (void) fprintf(fp,"    else goto CCF%d;\n",compucomecount);
      (void) fprintf(fp,"    ick_ccfc++;\n");
      /* Note that due to the semantics of setjmp, this has to be written as 2
	 separate ifs. The MULTICOME macro expands to a non-multithreaded or
         multithreaded function for handling a COME FROM clash. */
      (void) fprintf(fp,"    if(ick_ccfc==1||MULTICOME(%d,ick_cjb))\n"
		     "\t""if(setjmp(ick_cjb) == 0) goto CCF%d;\n",
		     emitlineno, compucomecount);
      /* Of course, emitlineno is unlikely to be helpful! */
      if(tn->type == NEXTFROMEXPR || tn->type == NEXTFROMGERUND)
      {
	/* Stack up the statement we've NEXTed from */
	(void) fprintf(fp,"    ick_pushnext(truelineno+1);\n");
      }
      (void) fprintf(fp,"    }\n");
    }

    /* AIS: Before any COMING FROM this line is done, we need to sort out
       ONCE and AGAIN situations, unless this line was a NEXT or GO_BACK.
       COME FROM is also excluded because it acts at the suckpoint, not
       at the place it's written in the program. */
    if (tn->onceagainflag != onceagain_NORMAL &&
	tn->type != NEXT && tn->type != GO_BACK && tn->type != UNKNOWN &&
	((tn->type != COME_FROM && tn->type != NEXTFROMLABEL) || useickec))
    {
      /* See my comments against the NEXT code for more information.
	 This code is placed here so COME FROM ... ONCE constructs work
	 properly (the line is ick_abstained if the COME FROM is reached in
	 execution, or its suckpoint is reached in execution). */
      fprintf(fp,"    ick_oldabstain = ICKABSTAINED(%d);\n", (int)(tn - tuples));
      fprintf(fp,"    ICKABSTAINED(%d) = %s;\n",
	      (int)(tn - tuples),
	      tn->onceagainflag==onceagain_ONCE ? "ick_oldabstain ? ick_oldabstain : 1"
	      : "0");
    }

    /* AIS: This is where we start the COME FROM suckpoint code. */

    /* AIS: The ickec version is very simple! We just finish the labeled
       block started at the start of the command. */
    if(tn->label && useickec)
      (void) fprintf(fp, "});\n");

    /* AIS: We need to keep track of how many COME FROMs are aiming here
       at runtime, if we don't have the very simple situation of no
       COMPUCOMEs and a single-thread program (in which case the check
       is done at compile-time by codecheck). Even without COMPUCOME,
       this can change in a multithread program due to abstentions. */
    if((tn->ncomefrom && multithread) || (tn->label && compucomesused)
       || gerucomesused)
      (void) fprintf(fp, "    ick_ccfc = 0;\n");
    /* AIS: For NEXTING FROM this line */
    if(nextfromsused && tn->ncomefrom)
    {
      (void) fprintf(fp, "    truelineno = %d;\n", (int)(tn-tuples));
    }
    /*
     * If the statement that was just degenerated was a COME FROM target,
     * emit the code for the jump to the COME FROM.
     * AIS: Changed most of this to allow for multithreading.
     */
    while(tn->ncomefrom && !useickec) /* acts as an if if singlethreading */
    {
      tuple* cf; /* local to this block */
      if(multithread || compucomesused) generatecfjump = 1;
      cf = tuples+comefromsearch(tn,tn->ncomefrom)-1;
      if (yydebug || compile_only)
	(void) fprintf(fp,
		       "    /* line %03d is a suck point for the COME FROM "
		       "at line %03d */\n", tn->ick_lineno, cf->ick_lineno);
      if (cf->onceagainflag != onceagain_NORMAL)
      { /* Calculate ONCE/AGAIN when the suckpoint is passed */
	fprintf(fp,"    ick_oldabstain = ICKABSTAINED(%d);\n", (int)(cf - tuples));
	fprintf(fp,"    ICKABSTAINED(%d) = %s;\n",
		(int)(cf - tuples),
		cf->onceagainflag==onceagain_ONCE ? "ick_oldabstain ? ick_oldabstain : 1"
		: "0");
      }
      emit_guard(cf, fp);
      if(multithread || compucomesused)
	(void) fprintf(fp,
		       "\t""ick_ccfc++;\tif(ick_ccfc==1||MULTICOME(%d,ick_cjb)) "
		       "if(setjmp(ick_cjb) == 1) goto C%ld;\n    }\n",
		       emitlineno, (long)(cf-tuples+1));
      else /* optimize for the simple case */
	(void) fprintf(fp, "\t""goto C%ld;\n    }\n", (long)(cf-tuples+1));
      tn->ncomefrom--;
    }

    /* AIS: If the statement has a label, it might be a
       computed COME FROM target. Also check the flag that says this
       code is needed in a multithread non-COMPUCOME program.
       If (at runtime) ick_ccfc is nonzero, we know ick_cjb has already been set;
       otherwise, set it now. In the case of a multithread non-COMPUCOME
       program, the goto will just jump to a longjmp, switching to the
       one and only one COME FROM that hasn't been given its own thread.
       However, skip all the compucomes and gerucomes if preproc is set,
       because COMING FROM a preproc should only ever be done by label. */
    if (((tn->label && compucomesused) || generatecfjump || gerucomesused) &&
        (!tn->preproc || generatecfjump) && (!useickec || gerucomesused))
    {
      if(compucomesused)
      {
	(void) fprintf(fp, "    ick_skipto = %u;\n", tn->label);
      }
      if(gerucomesused || nextfromsused)
      {
	(void) fprintf(fp, "    truelineno = %d;\n", (int)(tn-tuples));
      }
      if(generatecfjump) (void) fprintf(fp, "    if(ick_ccfc) goto CCF%s;\n",
					tn->preproc?"L":"0");
      if((compucomesused || gerucomesused) && !tn->preproc)
      { /* check all the COMPUCOMES */
	(void) fprintf(fp, "    %sif(setjmp(ick_cjb) == 0) goto CCF0;\n",
		       generatecfjump?"else ":"");
      }
      generatecfjump = 0;
      /* AIS: If NEXT FROM's used, this might be a NEXT return target.
	 Don't generate case labels for NEXT, as it has them already. */
      if(nextfromsused && tn->type != NEXT)
      {
	(void) fprintf(fp, "    case %u:;\n", (unsigned)(tn-tuples+1));
      }
    }

    /* AIS: Now we've finished the statement, let's switch to the next
       thread in a multithread program. */
    if(multithread) (void) fputs("    NEXTTHREAD;\n", fp);
    else if(useprintflow)
      (void) fputs("    if(ick_printflow) fprintf(stderr,"
		   "\"[%d]\",ick_lineno);\n",fp);
}
/*@=nestedextern@*/

/* AIS: Generate prototypes for slat expressions, args to UNKNOWN */
void emitslatproto(FILE* fp)
{
  node* np=firstslat;
  const char* t="ick_type32";
  while(np)
  {
    fprintf(fp,"%s ick_og%lx(%s);\nvoid ick_os%lx(%s, void(*)());\n",
	    t,(unsigned long)np,t,(unsigned long)np,t);
    np=np->nextslat;
  }
}

/* AIS: Generate bodies for slat expressions, args to UNKNOWN */
void emitslat(FILE* fp)
{
  node* np=firstslat;
  node* temp, *temp2;
  const char* t="ick_type32";
  while(np)
  {
    fprintf(fp,
	    "void ick_os%lx(%s a, void(*f)())\n{\n  static int l=0;\n"
	    "  if(l)\n  {\n    if(!f) ick_lose(IE994, ick_lineno, (const char *)NULL);\n"
	    "    f(a,0);\n    return;\n  }\n  l=1;\n",
	    (unsigned long)np,t);
    temp=cons(C_A, 0, 0);
    revprexpr(np, fp, temp); /* revprexpr can't free */
    fprintf(fp,"  l=0;\n}\n");
    fprintf(fp,"%s ick_og%lx(%s t)\n{\n  %s a;\n  static int l=0;\n"
	    "  if(l) return t;\n  l=1;\n  a=",
	    t,(unsigned long)np,t,t);
    prexpr(np, fp, 0);
    fprintf(fp,";\n  l=0;\n  return a;\n}\n");
    np=np->nextslat;
  }
  np=firstslat;
  /* Note that the order in which the parser assembles nodes means
     that we have to free the nodes in reverse order so we don't
     free child nodes twice. */
  temp2=0;
  while(np)
  {
    temp=np->nextslat;
    np->nextslat=temp2; /* reverse the chain */
    temp2=np;
    np=temp;
  }
  np=temp2;
  while(np)
  {
    temp=np->nextslat;
    nodefree(np);
    np=temp;
  }
  /* JH: clear firstslat */
  firstslat = 0;
}

/* feh.c ends here */