summaryrefslogtreecommitdiffstats
path: root/Lib/test/decimaltestdata/add.decTest
blob: 1461c45c3f3805f3296ac6e0209766ccad7357e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
------/cancell----------------------------------------------------------
-- add.decTest -- decimal addition                                    --
-- Copyright (c) IBM Corporation, 1981, 2008.  All rights reserved.   --
------------------------------------------------------------------------
-- Please see the document "General Decimal Arithmetic Testcases"     --
-- at http://www2.hursley.ibm.com/decimal for the description of      --
-- these testcases.                                                   --
--                                                                    --
-- These testcases are experimental ('beta' versions), and they       --
-- may contain errors.  They are offered on an as-is basis.  In       --
-- particular, achieving the same results as the tests here is not    --
-- a guarantee that an implementation complies with any Standard      --
-- or specification.  The tests are not exhaustive.                   --
--                                                                    --
-- Please send comments, suggestions, and corrections to the author:  --
--   Mike Cowlishaw, IBM Fellow                                       --
--   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         --
--   mfc@uk.ibm.com                                                   --
------------------------------------------------------------------------
version: 2.59

precision:   9
rounding:    half_up
maxExponent: 384
minexponent: -383
extended:    1

-- [first group are 'quick confidence check']
addx001 add 1       1       ->  2
addx002 add 2       3       ->  5
addx003 add '5.75'  '3.3'   ->  9.05
addx004 add '5'     '-3'    ->  2
addx005 add '-5'    '-3'    ->  -8
addx006 add '-7'    '2.5'   ->  -4.5
addx007 add '0.7'   '0.3'   ->  1.0
addx008 add '1.25'  '1.25'  ->  2.50
addx009 add '1.23456789'  '1.00000000' -> '2.23456789'
addx010 add '1.23456789'  '1.00000011' -> '2.23456800'

addx011 add '0.4444444444'  '0.5555555555' -> '1.00000000' Inexact Rounded
addx012 add '0.4444444440'  '0.5555555555' -> '1.00000000' Inexact Rounded
addx013 add '0.4444444444'  '0.5555555550' -> '0.999999999' Inexact Rounded
addx014 add '0.44444444449'    '0' -> '0.444444444' Inexact Rounded
addx015 add '0.444444444499'   '0' -> '0.444444444' Inexact Rounded
addx016 add '0.4444444444999'  '0' -> '0.444444444' Inexact Rounded
addx017 add '0.4444444445000'  '0' -> '0.444444445' Inexact Rounded
addx018 add '0.4444444445001'  '0' -> '0.444444445' Inexact Rounded
addx019 add '0.444444444501'   '0' -> '0.444444445' Inexact Rounded
addx020 add '0.44444444451'    '0' -> '0.444444445' Inexact Rounded

addx021 add 0 1 -> 1
addx022 add 1 1 -> 2
addx023 add 2 1 -> 3
addx024 add 3 1 -> 4
addx025 add 4 1 -> 5
addx026 add 5 1 -> 6
addx027 add 6 1 -> 7
addx028 add 7 1 -> 8
addx029 add 8 1 -> 9
addx030 add 9 1 -> 10

-- some carrying effects
addx031 add '0.9998'  '0.0000' -> '0.9998'
addx032 add '0.9998'  '0.0001' -> '0.9999'
addx033 add '0.9998'  '0.0002' -> '1.0000'
addx034 add '0.9998'  '0.0003' -> '1.0001'

addx035 add '70'  '10000e+9' -> '1.00000000E+13' Inexact Rounded
addx036 add '700'  '10000e+9' -> '1.00000000E+13' Inexact Rounded
addx037 add '7000'  '10000e+9' -> '1.00000000E+13' Inexact Rounded
addx038 add '70000'  '10000e+9' -> '1.00000001E+13' Inexact Rounded
addx039 add '700000'  '10000e+9' -> '1.00000007E+13' Rounded

-- symmetry:
addx040 add '10000e+9'  '70' -> '1.00000000E+13' Inexact Rounded
addx041 add '10000e+9'  '700' -> '1.00000000E+13' Inexact Rounded
addx042 add '10000e+9'  '7000' -> '1.00000000E+13' Inexact Rounded
addx044 add '10000e+9'  '70000' -> '1.00000001E+13' Inexact Rounded
addx045 add '10000e+9'  '700000' -> '1.00000007E+13' Rounded

-- same, higher precision
precision: 15
addx046 add '10000e+9'  '7' -> '10000000000007'
addx047 add '10000e+9'  '70' -> '10000000000070'
addx048 add '10000e+9'  '700' -> '10000000000700'
addx049 add '10000e+9'  '7000' -> '10000000007000'
addx050 add '10000e+9'  '70000' -> '10000000070000'
addx051 add '10000e+9'  '700000' -> '10000000700000'
addx052 add '10000e+9'  '7000000' -> '10000007000000'

-- examples from decarith
addx053 add '12' '7.00' -> '19.00'
addx054 add '1.3' '-1.07' -> '0.23'
addx055 add '1.3' '-1.30' -> '0.00'
addx056 add '1.3' '-2.07' -> '-0.77'
addx057 add '1E+2' '1E+4' -> '1.01E+4'

-- zero preservation
precision: 6
addx060 add '10000e+9'  '70000' -> '1.00000E+13' Inexact Rounded
addx061 add 1 '0.0001' -> '1.0001'
addx062 add 1 '0.00001' -> '1.00001'
addx063 add 1 '0.000001' -> '1.00000' Inexact Rounded
addx064 add 1 '0.0000001' -> '1.00000' Inexact Rounded
addx065 add 1 '0.00000001' -> '1.00000' Inexact Rounded

-- some funny zeros [in case of bad signum]
addx070 add 1  0    -> 1
addx071 add 1 0.    -> 1
addx072 add 1  .0   -> 1.0
addx073 add 1 0.0   -> 1.0
addx074 add 1 0.00  -> 1.00
addx075 add  0  1   -> 1
addx076 add 0.  1   -> 1
addx077 add  .0 1   -> 1.0
addx078 add 0.0 1   -> 1.0
addx079 add 0.00 1  -> 1.00

precision: 9

-- some carries
addx080 add 999999998 1  -> 999999999
addx081 add 999999999 1  -> 1.00000000E+9 Rounded
addx082 add  99999999 1  -> 100000000
addx083 add   9999999 1  -> 10000000
addx084 add    999999 1  -> 1000000
addx085 add     99999 1  -> 100000
addx086 add      9999 1  -> 10000
addx087 add       999 1  -> 1000
addx088 add        99 1  -> 100
addx089 add         9 1  -> 10


-- more LHS swaps
addx090 add '-56267E-10'   0 ->  '-0.0000056267'
addx091 add '-56267E-6'    0 ->  '-0.056267'
addx092 add '-56267E-5'    0 ->  '-0.56267'
addx093 add '-56267E-4'    0 ->  '-5.6267'
addx094 add '-56267E-3'    0 ->  '-56.267'
addx095 add '-56267E-2'    0 ->  '-562.67'
addx096 add '-56267E-1'    0 ->  '-5626.7'
addx097 add '-56267E-0'    0 ->  '-56267'
addx098 add '-5E-10'       0 ->  '-5E-10'
addx099 add '-5E-7'        0 ->  '-5E-7'
addx100 add '-5E-6'        0 ->  '-0.000005'
addx101 add '-5E-5'        0 ->  '-0.00005'
addx102 add '-5E-4'        0 ->  '-0.0005'
addx103 add '-5E-1'        0 ->  '-0.5'
addx104 add '-5E0'         0 ->  '-5'
addx105 add '-5E1'         0 ->  '-50'
addx106 add '-5E5'         0 ->  '-500000'
addx107 add '-5E8'         0 ->  '-500000000'
addx108 add '-5E9'         0 ->  '-5.00000000E+9'   Rounded
addx109 add '-5E10'        0 ->  '-5.00000000E+10'  Rounded
addx110 add '-5E11'        0 ->  '-5.00000000E+11'  Rounded
addx111 add '-5E100'       0 ->  '-5.00000000E+100' Rounded

-- more RHS swaps
addx113 add 0  '-56267E-10' ->  '-0.0000056267'
addx114 add 0  '-56267E-6'  ->  '-0.056267'
addx116 add 0  '-56267E-5'  ->  '-0.56267'
addx117 add 0  '-56267E-4'  ->  '-5.6267'
addx119 add 0  '-56267E-3'  ->  '-56.267'
addx120 add 0  '-56267E-2'  ->  '-562.67'
addx121 add 0  '-56267E-1'  ->  '-5626.7'
addx122 add 0  '-56267E-0'  ->  '-56267'
addx123 add 0  '-5E-10'     ->  '-5E-10'
addx124 add 0  '-5E-7'      ->  '-5E-7'
addx125 add 0  '-5E-6'      ->  '-0.000005'
addx126 add 0  '-5E-5'      ->  '-0.00005'
addx127 add 0  '-5E-4'      ->  '-0.0005'
addx128 add 0  '-5E-1'      ->  '-0.5'
addx129 add 0  '-5E0'       ->  '-5'
addx130 add 0  '-5E1'       ->  '-50'
addx131 add 0  '-5E5'       ->  '-500000'
addx132 add 0  '-5E8'       ->  '-500000000'
addx133 add 0  '-5E9'       ->  '-5.00000000E+9'    Rounded
addx134 add 0  '-5E10'      ->  '-5.00000000E+10'   Rounded
addx135 add 0  '-5E11'      ->  '-5.00000000E+11'   Rounded
addx136 add 0  '-5E100'     ->  '-5.00000000E+100'  Rounded

-- related
addx137 add  1  '0E-12'      ->  '1.00000000'  Rounded
addx138 add -1  '0E-12'      ->  '-1.00000000' Rounded
addx139 add '0E-12' 1        ->  '1.00000000'  Rounded
addx140 add '0E-12' -1       ->  '-1.00000000' Rounded
addx141 add 1E+4    0.0000   ->  '10000.0000'
addx142 add 1E+4    0.00000  ->  '10000.0000'  Rounded
addx143 add 0.000   1E+5     ->  '100000.000'
addx144 add 0.0000  1E+5     ->  '100000.000'  Rounded

-- [some of the next group are really constructor tests]
addx146 add '00.0'  0       ->  '0.0'
addx147 add '0.00'  0       ->  '0.00'
addx148 add  0      '0.00'  ->  '0.00'
addx149 add  0      '00.0'  ->  '0.0'
addx150 add '00.0'  '0.00'  ->  '0.00'
addx151 add '0.00'  '00.0'  ->  '0.00'
addx152 add '3'     '.3'    ->  '3.3'
addx153 add '3.'    '.3'    ->  '3.3'
addx154 add '3.0'   '.3'    ->  '3.3'
addx155 add '3.00'  '.3'    ->  '3.30'
addx156 add '3'     '3'     ->  '6'
addx157 add '3'     '+3'    ->  '6'
addx158 add '3'     '-3'    ->  '0'
addx159 add '0.3'   '-0.3'  ->  '0.0'
addx160 add '0.03'  '-0.03' ->  '0.00'

-- try borderline precision, with carries, etc.
precision: 15
addx161 add '1E+12' '-1'    -> '999999999999'
addx162 add '1E+12'  '1.11' -> '1000000000001.11'
addx163 add '1.11'  '1E+12' -> '1000000000001.11'
addx164 add '-1'    '1E+12' -> '999999999999'
addx165 add '7E+12' '-1'    -> '6999999999999'
addx166 add '7E+12'  '1.11' -> '7000000000001.11'
addx167 add '1.11'  '7E+12' -> '7000000000001.11'
addx168 add '-1'    '7E+12' -> '6999999999999'

--             123456789012345      123456789012345      1 23456789012345
addx170 add '0.444444444444444'  '0.555555555555563' -> '1.00000000000001' Inexact Rounded
addx171 add '0.444444444444444'  '0.555555555555562' -> '1.00000000000001' Inexact Rounded
addx172 add '0.444444444444444'  '0.555555555555561' -> '1.00000000000001' Inexact Rounded
addx173 add '0.444444444444444'  '0.555555555555560' -> '1.00000000000000' Inexact Rounded
addx174 add '0.444444444444444'  '0.555555555555559' -> '1.00000000000000' Inexact Rounded
addx175 add '0.444444444444444'  '0.555555555555558' -> '1.00000000000000' Inexact Rounded
addx176 add '0.444444444444444'  '0.555555555555557' -> '1.00000000000000' Inexact Rounded
addx177 add '0.444444444444444'  '0.555555555555556' -> '1.00000000000000' Rounded
addx178 add '0.444444444444444'  '0.555555555555555' -> '0.999999999999999'
addx179 add '0.444444444444444'  '0.555555555555554' -> '0.999999999999998'
addx180 add '0.444444444444444'  '0.555555555555553' -> '0.999999999999997'
addx181 add '0.444444444444444'  '0.555555555555552' -> '0.999999999999996'
addx182 add '0.444444444444444'  '0.555555555555551' -> '0.999999999999995'
addx183 add '0.444444444444444'  '0.555555555555550' -> '0.999999999999994'

-- and some more, including residue effects and different roundings
precision: 9
rounding: half_up
addx200 add '123456789' 0             -> '123456789'
addx201 add '123456789' 0.000000001   -> '123456789' Inexact Rounded
addx202 add '123456789' 0.000001      -> '123456789' Inexact Rounded
addx203 add '123456789' 0.1           -> '123456789' Inexact Rounded
addx204 add '123456789' 0.4           -> '123456789' Inexact Rounded
addx205 add '123456789' 0.49          -> '123456789' Inexact Rounded
addx206 add '123456789' 0.499999      -> '123456789' Inexact Rounded
addx207 add '123456789' 0.499999999   -> '123456789' Inexact Rounded
addx208 add '123456789' 0.5           -> '123456790' Inexact Rounded
addx209 add '123456789' 0.500000001   -> '123456790' Inexact Rounded
addx210 add '123456789' 0.500001      -> '123456790' Inexact Rounded
addx211 add '123456789' 0.51          -> '123456790' Inexact Rounded
addx212 add '123456789' 0.6           -> '123456790' Inexact Rounded
addx213 add '123456789' 0.9           -> '123456790' Inexact Rounded
addx214 add '123456789' 0.99999       -> '123456790' Inexact Rounded
addx215 add '123456789' 0.999999999   -> '123456790' Inexact Rounded
addx216 add '123456789' 1             -> '123456790'
addx217 add '123456789' 1.000000001   -> '123456790' Inexact Rounded
addx218 add '123456789' 1.00001       -> '123456790' Inexact Rounded
addx219 add '123456789' 1.1           -> '123456790' Inexact Rounded

rounding: half_even
addx220 add '123456789' 0             -> '123456789'
addx221 add '123456789' 0.000000001   -> '123456789' Inexact Rounded
addx222 add '123456789' 0.000001      -> '123456789' Inexact Rounded
addx223 add '123456789' 0.1           -> '123456789' Inexact Rounded
addx224 add '123456789' 0.4           -> '123456789' Inexact Rounded
addx225 add '123456789' 0.49          -> '123456789' Inexact Rounded
addx226 add '123456789' 0.499999      -> '123456789' Inexact Rounded
addx227 add '123456789' 0.499999999   -> '123456789' Inexact Rounded
addx228 add '123456789' 0.5           -> '123456790' Inexact Rounded
addx229 add '123456789' 0.500000001   -> '123456790' Inexact Rounded
addx230 add '123456789' 0.500001      -> '123456790' Inexact Rounded
addx231 add '123456789' 0.51          -> '123456790' Inexact Rounded
addx232 add '123456789' 0.6           -> '123456790' Inexact Rounded
addx233 add '123456789' 0.9           -> '123456790' Inexact Rounded
addx234 add '123456789' 0.99999       -> '123456790' Inexact Rounded
addx235 add '123456789' 0.999999999   -> '123456790' Inexact Rounded
addx236 add '123456789' 1             -> '123456790'
addx237 add '123456789' 1.00000001    -> '123456790' Inexact Rounded
addx238 add '123456789' 1.00001       -> '123456790' Inexact Rounded
addx239 add '123456789' 1.1           -> '123456790' Inexact Rounded
-- critical few with even bottom digit...
addx240 add '123456788' 0.499999999   -> '123456788' Inexact Rounded
addx241 add '123456788' 0.5           -> '123456788' Inexact Rounded
addx242 add '123456788' 0.500000001   -> '123456789' Inexact Rounded

rounding: down
addx250 add '123456789' 0             -> '123456789'
addx251 add '123456789' 0.000000001   -> '123456789' Inexact Rounded
addx252 add '123456789' 0.000001      -> '123456789' Inexact Rounded
addx253 add '123456789' 0.1           -> '123456789' Inexact Rounded
addx254 add '123456789' 0.4           -> '123456789' Inexact Rounded
addx255 add '123456789' 0.49          -> '123456789' Inexact Rounded
addx256 add '123456789' 0.499999      -> '123456789' Inexact Rounded
addx257 add '123456789' 0.499999999   -> '123456789' Inexact Rounded
addx258 add '123456789' 0.5           -> '123456789' Inexact Rounded
addx259 add '123456789' 0.500000001   -> '123456789' Inexact Rounded
addx260 add '123456789' 0.500001      -> '123456789' Inexact Rounded
addx261 add '123456789' 0.51          -> '123456789' Inexact Rounded
addx262 add '123456789' 0.6           -> '123456789' Inexact Rounded
addx263 add '123456789' 0.9           -> '123456789' Inexact Rounded
addx264 add '123456789' 0.99999       -> '123456789' Inexact Rounded
addx265 add '123456789' 0.999999999   -> '123456789' Inexact Rounded
addx266 add '123456789' 1             -> '123456790'
addx267 add '123456789' 1.00000001    -> '123456790' Inexact Rounded
addx268 add '123456789' 1.00001       -> '123456790' Inexact Rounded
addx269 add '123456789' 1.1           -> '123456790' Inexact Rounded

-- input preparation tests (operands should not be rounded)
precision: 3
rounding: half_up

addx270 add '12345678900000'  9999999999999 ->  '2.23E+13' Inexact Rounded
addx271 add  '9999999999999' 12345678900000 ->  '2.23E+13' Inexact Rounded

addx272 add '12E+3'  '3444'   ->  '1.54E+4' Inexact Rounded
addx273 add '12E+3'  '3446'   ->  '1.54E+4' Inexact Rounded
addx274 add '12E+3'  '3449.9' ->  '1.54E+4' Inexact Rounded
addx275 add '12E+3'  '3450.0' ->  '1.55E+4' Inexact Rounded
addx276 add '12E+3'  '3450.1' ->  '1.55E+4' Inexact Rounded
addx277 add '12E+3'  '3454'   ->  '1.55E+4' Inexact Rounded
addx278 add '12E+3'  '3456'   ->  '1.55E+4' Inexact Rounded

addx281 add '3444'   '12E+3'  ->  '1.54E+4' Inexact Rounded
addx282 add '3446'   '12E+3'  ->  '1.54E+4' Inexact Rounded
addx283 add '3449.9' '12E+3'  ->  '1.54E+4' Inexact Rounded
addx284 add '3450.0' '12E+3'  ->  '1.55E+4' Inexact Rounded
addx285 add '3450.1' '12E+3'  ->  '1.55E+4' Inexact Rounded
addx286 add '3454'   '12E+3'  ->  '1.55E+4' Inexact Rounded
addx287 add '3456'   '12E+3'  ->  '1.55E+4' Inexact Rounded

rounding: half_down
addx291 add '3444'   '12E+3'  ->  '1.54E+4' Inexact Rounded
addx292 add '3446'   '12E+3'  ->  '1.54E+4' Inexact Rounded
addx293 add '3449.9' '12E+3'  ->  '1.54E+4' Inexact Rounded
addx294 add '3450.0' '12E+3'  ->  '1.54E+4' Inexact Rounded
addx295 add '3450.1' '12E+3'  ->  '1.55E+4' Inexact Rounded
addx296 add '3454'   '12E+3'  ->  '1.55E+4' Inexact Rounded
addx297 add '3456'   '12E+3'  ->  '1.55E+4' Inexact Rounded

-- 1 in last place tests
rounding: half_up
addx301 add  -1   1      ->   0
addx302 add   0   1      ->   1
addx303 add   1   1      ->   2
addx304 add  12   1      ->  13
addx305 add  98   1      ->  99
addx306 add  99   1      -> 100
addx307 add 100   1      -> 101
addx308 add 101   1      -> 102
addx309 add  -1  -1      ->  -2
addx310 add   0  -1      ->  -1
addx311 add   1  -1      ->   0
addx312 add  12  -1      ->  11
addx313 add  98  -1      ->  97
addx314 add  99  -1      ->  98
addx315 add 100  -1      ->  99
addx316 add 101  -1      -> 100

addx321 add -0.01  0.01    ->  0.00
addx322 add  0.00  0.01    ->  0.01
addx323 add  0.01  0.01    ->  0.02
addx324 add  0.12  0.01    ->  0.13
addx325 add  0.98  0.01    ->  0.99
addx326 add  0.99  0.01    ->  1.00
addx327 add  1.00  0.01    ->  1.01
addx328 add  1.01  0.01    ->  1.02
addx329 add -0.01 -0.01    -> -0.02
addx330 add  0.00 -0.01    -> -0.01
addx331 add  0.01 -0.01    ->  0.00
addx332 add  0.12 -0.01    ->  0.11
addx333 add  0.98 -0.01    ->  0.97
addx334 add  0.99 -0.01    ->  0.98
addx335 add  1.00 -0.01    ->  0.99
addx336 add  1.01 -0.01    ->  1.00

-- some more cases where adding 0 affects the coefficient
precision: 9
addx340 add 1E+3    0    ->         1000
addx341 add 1E+8    0    ->    100000000
addx342 add 1E+9    0    ->   1.00000000E+9   Rounded
addx343 add 1E+10   0    ->   1.00000000E+10  Rounded
-- which simply follow from these cases ...
addx344 add 1E+3    1    ->         1001
addx345 add 1E+8    1    ->    100000001
addx346 add 1E+9    1    ->   1.00000000E+9   Inexact Rounded
addx347 add 1E+10   1    ->   1.00000000E+10  Inexact Rounded
addx348 add 1E+3    7    ->         1007
addx349 add 1E+8    7    ->    100000007
addx350 add 1E+9    7    ->   1.00000001E+9   Inexact Rounded
addx351 add 1E+10   7    ->   1.00000000E+10  Inexact Rounded

-- tryzeros cases
precision:   7
rounding:    half_up
maxExponent: 92
minexponent: -92
addx361  add 0E+50 10000E+1  -> 1.0000E+5
addx362  add 10000E+1 0E-50  -> 100000.0  Rounded
addx363  add 10000E+1 10000E-50  -> 100000.0  Rounded Inexact
addx364  add 9.999999E+92 -9.999999E+92 -> 0E+86

-- a curiosity from JSR 13 testing
rounding:    half_down
precision:   10
addx370 add 99999999 81512 -> 100081511
precision:      6
addx371 add 99999999 81512 -> 1.00082E+8 Rounded Inexact
rounding:    half_up
precision:   10
addx372 add 99999999 81512 -> 100081511
precision:      6
addx373 add 99999999 81512 -> 1.00082E+8 Rounded Inexact
rounding:    half_even
precision:   10
addx374 add 99999999 81512 -> 100081511
precision:      6
addx375 add 99999999 81512 -> 1.00082E+8 Rounded Inexact

-- ulp replacement tests
precision: 9
maxexponent: 999999999
minexponent: -999999999
addx400 add   1   77e-7       ->  1.0000077
addx401 add   1   77e-8       ->  1.00000077
addx402 add   1   77e-9       ->  1.00000008 Inexact Rounded
addx403 add   1   77e-10      ->  1.00000001 Inexact Rounded
addx404 add   1   77e-11      ->  1.00000000 Inexact Rounded
addx405 add   1   77e-12      ->  1.00000000 Inexact Rounded
addx406 add   1   77e-999     ->  1.00000000 Inexact Rounded
addx407 add   1   77e-9999999 ->  1.00000000 Inexact Rounded

addx410 add  10   77e-7       ->  10.0000077
addx411 add  10   77e-8       ->  10.0000008 Inexact Rounded
addx412 add  10   77e-9       ->  10.0000001 Inexact Rounded
addx413 add  10   77e-10      ->  10.0000000 Inexact Rounded
addx414 add  10   77e-11      ->  10.0000000 Inexact Rounded
addx415 add  10   77e-12      ->  10.0000000 Inexact Rounded
addx416 add  10   77e-999     ->  10.0000000 Inexact Rounded
addx417 add  10   77e-9999999 ->  10.0000000 Inexact Rounded

addx420 add  77e-7        1   ->  1.0000077
addx421 add  77e-8        1   ->  1.00000077
addx422 add  77e-9        1   ->  1.00000008 Inexact Rounded
addx423 add  77e-10       1   ->  1.00000001 Inexact Rounded
addx424 add  77e-11       1   ->  1.00000000 Inexact Rounded
addx425 add  77e-12       1   ->  1.00000000 Inexact Rounded
addx426 add  77e-999      1   ->  1.00000000 Inexact Rounded
addx427 add  77e-9999999  1   ->  1.00000000 Inexact Rounded

addx430 add  77e-7       10   ->  10.0000077
addx431 add  77e-8       10   ->  10.0000008 Inexact Rounded
addx432 add  77e-9       10   ->  10.0000001 Inexact Rounded
addx433 add  77e-10      10   ->  10.0000000 Inexact Rounded
addx434 add  77e-11      10   ->  10.0000000 Inexact Rounded
addx435 add  77e-12      10   ->  10.0000000 Inexact Rounded
addx436 add  77e-999     10   ->  10.0000000 Inexact Rounded
addx437 add  77e-9999999 10   ->  10.0000000 Inexact Rounded

-- negative ulps
addx440 add   1   -77e-7       ->  0.9999923
addx441 add   1   -77e-8       ->  0.99999923
addx442 add   1   -77e-9       ->  0.999999923
addx443 add   1   -77e-10      ->  0.999999992 Inexact Rounded
addx444 add   1   -77e-11      ->  0.999999999 Inexact Rounded
addx445 add   1   -77e-12      ->  1.00000000 Inexact Rounded
addx446 add   1   -77e-999     ->  1.00000000 Inexact Rounded
addx447 add   1   -77e-9999999 ->  1.00000000 Inexact Rounded

addx450 add  10   -77e-7       ->   9.9999923
addx451 add  10   -77e-8       ->   9.99999923
addx452 add  10   -77e-9       ->   9.99999992 Inexact Rounded
addx453 add  10   -77e-10      ->   9.99999999 Inexact Rounded
addx454 add  10   -77e-11      ->  10.0000000 Inexact Rounded
addx455 add  10   -77e-12      ->  10.0000000 Inexact Rounded
addx456 add  10   -77e-999     ->  10.0000000 Inexact Rounded
addx457 add  10   -77e-9999999 ->  10.0000000 Inexact Rounded

addx460 add  -77e-7        1   ->  0.9999923
addx461 add  -77e-8        1   ->  0.99999923
addx462 add  -77e-9        1   ->  0.999999923
addx463 add  -77e-10       1   ->  0.999999992 Inexact Rounded
addx464 add  -77e-11       1   ->  0.999999999 Inexact Rounded
addx465 add  -77e-12       1   ->  1.00000000 Inexact Rounded
addx466 add  -77e-999      1   ->  1.00000000 Inexact Rounded
addx467 add  -77e-9999999  1   ->  1.00000000 Inexact Rounded

addx470 add  -77e-7       10   ->   9.9999923
addx471 add  -77e-8       10   ->   9.99999923
addx472 add  -77e-9       10   ->   9.99999992 Inexact Rounded
addx473 add  -77e-10      10   ->   9.99999999 Inexact Rounded
addx474 add  -77e-11      10   ->  10.0000000 Inexact Rounded
addx475 add  -77e-12      10   ->  10.0000000 Inexact Rounded
addx476 add  -77e-999     10   ->  10.0000000 Inexact Rounded
addx477 add  -77e-9999999 10   ->  10.0000000 Inexact Rounded

-- negative ulps
addx480 add  -1    77e-7       ->  -0.9999923
addx481 add  -1    77e-8       ->  -0.99999923
addx482 add  -1    77e-9       ->  -0.999999923
addx483 add  -1    77e-10      ->  -0.999999992 Inexact Rounded
addx484 add  -1    77e-11      ->  -0.999999999 Inexact Rounded
addx485 add  -1    77e-12      ->  -1.00000000 Inexact Rounded
addx486 add  -1    77e-999     ->  -1.00000000 Inexact Rounded
addx487 add  -1    77e-9999999 ->  -1.00000000 Inexact Rounded

addx490 add -10    77e-7       ->   -9.9999923
addx491 add -10    77e-8       ->   -9.99999923
addx492 add -10    77e-9       ->   -9.99999992 Inexact Rounded
addx493 add -10    77e-10      ->   -9.99999999 Inexact Rounded
addx494 add -10    77e-11      ->  -10.0000000 Inexact Rounded
addx495 add -10    77e-12      ->  -10.0000000 Inexact Rounded
addx496 add -10    77e-999     ->  -10.0000000 Inexact Rounded
addx497 add -10    77e-9999999 ->  -10.0000000 Inexact Rounded

addx500 add   77e-7       -1   ->  -0.9999923
addx501 add   77e-8       -1   ->  -0.99999923
addx502 add   77e-9       -1   ->  -0.999999923
addx503 add   77e-10      -1   ->  -0.999999992 Inexact Rounded
addx504 add   77e-11      -1   ->  -0.999999999 Inexact Rounded
addx505 add   77e-12      -1   ->  -1.00000000 Inexact Rounded
addx506 add   77e-999     -1   ->  -1.00000000 Inexact Rounded
addx507 add   77e-9999999 -1   ->  -1.00000000 Inexact Rounded

addx510 add   77e-7       -10  ->   -9.9999923
addx511 add   77e-8       -10  ->   -9.99999923
addx512 add   77e-9       -10  ->   -9.99999992 Inexact Rounded
addx513 add   77e-10      -10  ->   -9.99999999 Inexact Rounded
addx514 add   77e-11      -10  ->  -10.0000000 Inexact Rounded
addx515 add   77e-12      -10  ->  -10.0000000 Inexact Rounded
addx516 add   77e-999     -10  ->  -10.0000000 Inexact Rounded
addx517 add   77e-9999999 -10  ->  -10.0000000 Inexact Rounded


-- long operands
maxexponent: 999
minexponent: -999
precision: 9
addx521 add 12345678000 0 -> 1.23456780E+10 Rounded
addx522 add 0 12345678000 -> 1.23456780E+10 Rounded
addx523 add 1234567800  0 -> 1.23456780E+9 Rounded
addx524 add 0 1234567800  -> 1.23456780E+9 Rounded
addx525 add 1234567890  0 -> 1.23456789E+9 Rounded
addx526 add 0 1234567890  -> 1.23456789E+9 Rounded
addx527 add 1234567891  0 -> 1.23456789E+9 Inexact Rounded
addx528 add 0 1234567891  -> 1.23456789E+9 Inexact Rounded
addx529 add 12345678901 0 -> 1.23456789E+10 Inexact Rounded
addx530 add 0 12345678901 -> 1.23456789E+10 Inexact Rounded
addx531 add 1234567896  0 -> 1.23456790E+9 Inexact Rounded
addx532 add 0 1234567896  -> 1.23456790E+9 Inexact Rounded

precision: 15
-- still checking
addx541 add 12345678000 0 -> 12345678000
addx542 add 0 12345678000 -> 12345678000
addx543 add 1234567800  0 -> 1234567800
addx544 add 0 1234567800  -> 1234567800
addx545 add 1234567890  0 -> 1234567890
addx546 add 0 1234567890  -> 1234567890
addx547 add 1234567891  0 -> 1234567891
addx548 add 0 1234567891  -> 1234567891
addx549 add 12345678901 0 -> 12345678901
addx550 add 0 12345678901 -> 12345678901
addx551 add 1234567896  0 -> 1234567896
addx552 add 0 1234567896  -> 1234567896

-- verify a query
precision:    16
maxExponent: +394
minExponent: -393
rounding:     down
addx561 add 1e-398 9.000000000000000E+384 -> 9.000000000000000E+384 Inexact Rounded
addx562 add      0 9.000000000000000E+384 -> 9.000000000000000E+384 Rounded
-- and using decimal64 bounds (see also ddadd.decTest)
precision:    16
maxExponent: +384
minExponent: -383
rounding:     down
addx563 add 1e-388 9.000000000000000E+374 -> 9.000000000000000E+374 Inexact Rounded
addx564 add      0 9.000000000000000E+374 -> 9.000000000000000E+374 Rounded


-- some more residue effects with extreme rounding
precision:   9
rounding: half_up
addx601 add 123456789  0.000001 -> 123456789 Inexact Rounded
rounding: half_even
addx602 add 123456789  0.000001 -> 123456789 Inexact Rounded
rounding: half_down
addx603 add 123456789  0.000001 -> 123456789 Inexact Rounded
rounding: floor
addx604 add 123456789  0.000001 -> 123456789 Inexact Rounded
rounding: ceiling
addx605 add 123456789  0.000001 -> 123456790 Inexact Rounded
rounding: up
addx606 add 123456789  0.000001 -> 123456790 Inexact Rounded
rounding: down
addx607 add 123456789  0.000001 -> 123456789 Inexact Rounded

rounding: half_up
addx611 add 123456789 -0.000001 -> 123456789 Inexact Rounded
rounding: half_even
addx612 add 123456789 -0.000001 -> 123456789 Inexact Rounded
rounding: half_down
addx613 add 123456789 -0.000001 -> 123456789 Inexact Rounded
rounding: floor
addx614 add 123456789 -0.000001 -> 123456788 Inexact Rounded
rounding: ceiling
addx615 add 123456789 -0.000001 -> 123456789 Inexact Rounded
rounding: up
addx616 add 123456789 -0.000001 -> 123456789 Inexact Rounded
rounding: down
addx617 add 123456789 -0.000001 -> 123456788 Inexact Rounded

rounding: half_up
addx621 add 123456789  0.499999 -> 123456789 Inexact Rounded
rounding: half_even
addx622 add 123456789  0.499999 -> 123456789 Inexact Rounded
rounding: half_down
addx623 add 123456789  0.499999 -> 123456789 Inexact Rounded
rounding: floor
addx624 add 123456789  0.499999 -> 123456789 Inexact Rounded
rounding: ceiling
addx625 add 123456789  0.499999 -> 123456790 Inexact Rounded
rounding: up
addx626 add 123456789  0.499999 -> 123456790 Inexact Rounded
rounding: down
addx627 add 123456789  0.499999 -> 123456789 Inexact Rounded

rounding: half_up
addx631 add 123456789 -0.499999 -> 123456789 Inexact Rounded
rounding: half_even
addx632 add 123456789 -0.499999 -> 123456789 Inexact Rounded
rounding: half_down
addx633 add 123456789 -0.499999 -> 123456789 Inexact Rounded
rounding: floor
addx634 add 123456789 -0.499999 -> 123456788 Inexact Rounded
rounding: ceiling
addx635 add 123456789 -0.499999 -> 123456789 Inexact Rounded
rounding: up
addx636 add 123456789 -0.499999 -> 123456789 Inexact Rounded
rounding: down
addx637 add 123456789 -0.499999 -> 123456788 Inexact Rounded

rounding: half_up
addx641 add 123456789  0.500001 -> 123456790 Inexact Rounded
rounding: half_even
addx642 add 123456789  0.500001 -> 123456790 Inexact Rounded
rounding: half_down
addx643 add 123456789  0.500001 -> 123456790 Inexact Rounded
rounding: floor
addx644 add 123456789  0.500001 -> 123456789 Inexact Rounded
rounding: ceiling
addx645 add 123456789  0.500001 -> 123456790 Inexact Rounded
rounding: up
addx646 add 123456789  0.500001 -> 123456790 Inexact Rounded
rounding: down
addx647 add 123456789  0.500001 -> 123456789 Inexact Rounded

rounding: half_up
addx651 add 123456789 -0.500001 -> 123456788 Inexact Rounded
rounding: half_even
addx652 add 123456789 -0.500001 -> 123456788 Inexact Rounded
rounding: half_down
addx653 add 123456789 -0.500001 -> 123456788 Inexact Rounded
rounding: floor
addx654 add 123456789 -0.500001 -> 123456788 Inexact Rounded
rounding: ceiling
addx655 add 123456789 -0.500001 -> 123456789 Inexact Rounded
rounding: up
addx656 add 123456789 -0.500001 -> 123456789 Inexact Rounded
rounding: down
addx657 add 123456789 -0.500001 -> 123456788 Inexact Rounded

-- long operand triangle
rounding: half_up
precision:  37
addx660 add 98471198160.56524417578665886060 -23994.14313393939743548945165462 -> 98471174166.42211023638922337114834538
precision:  36
addx661 add 98471198160.56524417578665886060 -23994.14313393939743548945165462 -> 98471174166.4221102363892233711483454  Inexact Rounded
precision:  35
addx662 add 98471198160.56524417578665886060 -23994.14313393939743548945165462 -> 98471174166.422110236389223371148345   Inexact Rounded
precision:  34
addx663 add 98471198160.56524417578665886060 -23994.14313393939743548945165462 -> 98471174166.42211023638922337114835    Inexact Rounded
precision:  33
addx664 add 98471198160.56524417578665886060 -23994.14313393939743548945165462 -> 98471174166.4221102363892233711483     Inexact Rounded
precision:  32
addx665 add 98471198160.56524417578665886060 -23994.14313393939743548945165462 -> 98471174166.422110236389223371148      Inexact Rounded
precision:  31
addx666 add 98471198160.56524417578665886060 -23994.14313393939743548945165462 -> 98471174166.42211023638922337115       Inexact Rounded
precision:  30
addx667 add 98471198160.56524417578665886060 -23994.14313393939743548945165462 -> 98471174166.4221102363892233711        Inexact Rounded
precision:  29
addx668 add 98471198160.56524417578665886060 -23994.14313393939743548945165462 -> 98471174166.422110236389223371         Inexact Rounded
precision:  28
addx669 add 98471198160.56524417578665886060 -23994.14313393939743548945165462 -> 98471174166.42211023638922337          Inexact Rounded
precision:  27
addx670 add 98471198160.56524417578665886060 -23994.14313393939743548945165462 -> 98471174166.4221102363892234           Inexact Rounded
precision:  26
addx671 add 98471198160.56524417578665886060 -23994.14313393939743548945165462 -> 98471174166.422110236389223            Inexact Rounded
precision:  25
addx672 add 98471198160.56524417578665886060 -23994.14313393939743548945165462 -> 98471174166.42211023638922             Inexact Rounded
precision:  24
addx673 add 98471198160.56524417578665886060 -23994.14313393939743548945165462 -> 98471174166.4221102363892              Inexact Rounded
precision:  23
addx674 add 98471198160.56524417578665886060 -23994.14313393939743548945165462 -> 98471174166.422110236389               Inexact Rounded
precision:  22
addx675 add 98471198160.56524417578665886060 -23994.14313393939743548945165462 -> 98471174166.42211023639                Inexact Rounded
precision:  21
addx676 add 98471198160.56524417578665886060 -23994.14313393939743548945165462 -> 98471174166.4221102364                 Inexact Rounded
precision:  20
addx677 add 98471198160.56524417578665886060 -23994.14313393939743548945165462 -> 98471174166.422110236                  Inexact Rounded
precision:  19
addx678 add 98471198160.56524417578665886060 -23994.14313393939743548945165462 -> 98471174166.42211024                   Inexact Rounded
precision:  18
addx679 add 98471198160.56524417578665886060 -23994.14313393939743548945165462 -> 98471174166.4221102                    Inexact Rounded
precision:  17
addx680 add 98471198160.56524417578665886060 -23994.14313393939743548945165462 -> 98471174166.422110                     Inexact Rounded
precision:  16
addx681 add 98471198160.56524417578665886060 -23994.14313393939743548945165462 -> 98471174166.42211                      Inexact Rounded
precision:  15
addx682 add 98471198160.56524417578665886060 -23994.14313393939743548945165462 -> 98471174166.4221                       Inexact Rounded
precision:  14
addx683 add 98471198160.56524417578665886060 -23994.14313393939743548945165462 -> 98471174166.422                        Inexact Rounded
precision:  13
addx684 add 98471198160.56524417578665886060 -23994.14313393939743548945165462 -> 98471174166.42                         Inexact Rounded
precision:  12
addx685 add 98471198160.56524417578665886060 -23994.14313393939743548945165462 -> 98471174166.4                          Inexact Rounded
precision:  11
addx686 add 98471198160.56524417578665886060 -23994.14313393939743548945165462 -> 98471174166                            Inexact Rounded
precision:  10
addx687 add 98471198160.56524417578665886060 -23994.14313393939743548945165462 -> 9.847117417E+10                        Inexact Rounded
precision:   9
addx688 add 98471198160.56524417578665886060 -23994.14313393939743548945165462 -> 9.84711742E+10                         Inexact Rounded
precision:   8
addx689 add 98471198160.56524417578665886060 -23994.14313393939743548945165462 -> 9.8471174E+10                          Inexact Rounded
precision:   7
addx690 add 98471198160.56524417578665886060 -23994.14313393939743548945165462 -> 9.847117E+10                          Inexact Rounded
precision:   6
addx691 add 98471198160.56524417578665886060 -23994.14313393939743548945165462 -> 9.84712E+10                          Inexact Rounded
precision:   5
addx692 add 98471198160.56524417578665886060 -23994.14313393939743548945165462 -> 9.8471E+10                          Inexact Rounded
precision:   4
addx693 add 98471198160.56524417578665886060 -23994.14313393939743548945165462 -> 9.847E+10                          Inexact Rounded
precision:   3
addx694 add 98471198160.56524417578665886060 -23994.14313393939743548945165462 -> 9.85E+10                          Inexact Rounded
precision:   2
addx695 add 98471198160.56524417578665886060 -23994.14313393939743548945165462 -> 9.8E+10                          Inexact Rounded
precision:   1
addx696 add 98471198160.56524417578665886060 -23994.14313393939743548945165462 -> 1E+11                          Inexact Rounded

-- more zeros, etc.
rounding: half_up
precision:   9

addx701 add 5.00 1.00E-3 -> 5.00100
addx702 add 00.00 0.000  -> 0.000
addx703 add 00.00 0E-3   -> 0.000
addx704 add 0E-3  00.00  -> 0.000

addx710 add 0E+3  00.00  -> 0.00
addx711 add 0E+3  00.0   -> 0.0
addx712 add 0E+3  00.    -> 0
addx713 add 0E+3  00.E+1 -> 0E+1
addx714 add 0E+3  00.E+2 -> 0E+2
addx715 add 0E+3  00.E+3 -> 0E+3
addx716 add 0E+3  00.E+4 -> 0E+3
addx717 add 0E+3  00.E+5 -> 0E+3
addx718 add 0E+3  -00.0   -> 0.0
addx719 add 0E+3  -00.    -> 0
addx731 add 0E+3  -00.E+1 -> 0E+1

addx720 add 00.00  0E+3  -> 0.00
addx721 add 00.0   0E+3  -> 0.0
addx722 add 00.    0E+3  -> 0
addx723 add 00.E+1 0E+3  -> 0E+1
addx724 add 00.E+2 0E+3  -> 0E+2
addx725 add 00.E+3 0E+3  -> 0E+3
addx726 add 00.E+4 0E+3  -> 0E+3
addx727 add 00.E+5 0E+3  -> 0E+3
addx728 add -00.00 0E+3  -> 0.00
addx729 add -00.0  0E+3  -> 0.0
addx730 add -00.   0E+3  -> 0

addx732 add  0     0     ->  0
addx733 add  0    -0     ->  0
addx734 add -0     0     ->  0
addx735 add -0    -0     -> -0     -- IEEE 854 special case

addx736 add  1    -1     ->  0
addx737 add -1    -1     -> -2
addx738 add  1     1     ->  2
addx739 add -1     1     ->  0

addx741 add  0    -1     -> -1
addx742 add -0    -1     -> -1
addx743 add  0     1     ->  1
addx744 add -0     1     ->  1
addx745 add -1     0     -> -1
addx746 add -1    -0     -> -1
addx747 add  1     0     ->  1
addx748 add  1    -0     ->  1

addx751 add  0.0  -1     -> -1.0
addx752 add -0.0  -1     -> -1.0
addx753 add  0.0   1     ->  1.0
addx754 add -0.0   1     ->  1.0
addx755 add -1.0   0     -> -1.0
addx756 add -1.0  -0     -> -1.0
addx757 add  1.0   0     ->  1.0
addx758 add  1.0  -0     ->  1.0

addx761 add  0    -1.0   -> -1.0
addx762 add -0    -1.0   -> -1.0
addx763 add  0     1.0   ->  1.0
addx764 add -0     1.0   ->  1.0
addx765 add -1     0.0   -> -1.0
addx766 add -1    -0.0   -> -1.0
addx767 add  1     0.0   ->  1.0
addx768 add  1    -0.0   ->  1.0

addx771 add  0.0  -1.0   -> -1.0
addx772 add -0.0  -1.0   -> -1.0
addx773 add  0.0   1.0   ->  1.0
addx774 add -0.0   1.0   ->  1.0
addx775 add -1.0   0.0   -> -1.0
addx776 add -1.0  -0.0   -> -1.0
addx777 add  1.0   0.0   ->  1.0
addx778 add  1.0  -0.0   ->  1.0

-- Specials
addx780 add -Inf  -Inf   -> -Infinity
addx781 add -Inf  -1000  -> -Infinity
addx782 add -Inf  -1     -> -Infinity
addx783 add -Inf  -0     -> -Infinity
addx784 add -Inf   0     -> -Infinity
addx785 add -Inf   1     -> -Infinity
addx786 add -Inf   1000  -> -Infinity
addx787 add -1000 -Inf   -> -Infinity
addx788 add -Inf  -Inf   -> -Infinity
addx789 add -1    -Inf   -> -Infinity
addx790 add -0    -Inf   -> -Infinity
addx791 add  0    -Inf   -> -Infinity
addx792 add  1    -Inf   -> -Infinity
addx793 add  1000 -Inf   -> -Infinity
addx794 add  Inf  -Inf   ->  NaN  Invalid_operation

addx800 add  Inf  -Inf   ->  NaN  Invalid_operation
addx801 add  Inf  -1000  ->  Infinity
addx802 add  Inf  -1     ->  Infinity
addx803 add  Inf  -0     ->  Infinity
addx804 add  Inf   0     ->  Infinity
addx805 add  Inf   1     ->  Infinity
addx806 add  Inf   1000  ->  Infinity
addx807 add  Inf   Inf   ->  Infinity
addx808 add -1000  Inf   ->  Infinity
addx809 add -Inf   Inf   ->  NaN  Invalid_operation
addx810 add -1     Inf   ->  Infinity
addx811 add -0     Inf   ->  Infinity
addx812 add  0     Inf   ->  Infinity
addx813 add  1     Inf   ->  Infinity
addx814 add  1000  Inf   ->  Infinity
addx815 add  Inf   Inf   ->  Infinity

addx821 add  NaN -Inf    ->  NaN
addx822 add  NaN -1000   ->  NaN
addx823 add  NaN -1      ->  NaN
addx824 add  NaN -0      ->  NaN
addx825 add  NaN  0      ->  NaN
addx826 add  NaN  1      ->  NaN
addx827 add  NaN  1000   ->  NaN
addx828 add  NaN  Inf    ->  NaN
addx829 add  NaN  NaN    ->  NaN
addx830 add -Inf  NaN    ->  NaN
addx831 add -1000 NaN    ->  NaN
addx832 add -1    NaN    ->  NaN
addx833 add -0    NaN    ->  NaN
addx834 add  0    NaN    ->  NaN
addx835 add  1    NaN    ->  NaN
addx836 add  1000 NaN    ->  NaN
addx837 add  Inf  NaN    ->  NaN

addx841 add  sNaN -Inf   ->  NaN  Invalid_operation
addx842 add  sNaN -1000  ->  NaN  Invalid_operation
addx843 add  sNaN -1     ->  NaN  Invalid_operation
addx844 add  sNaN -0     ->  NaN  Invalid_operation
addx845 add  sNaN  0     ->  NaN  Invalid_operation
addx846 add  sNaN  1     ->  NaN  Invalid_operation
addx847 add  sNaN  1000  ->  NaN  Invalid_operation
addx848 add  sNaN  NaN   ->  NaN  Invalid_operation
addx849 add  sNaN sNaN   ->  NaN  Invalid_operation
addx850 add  NaN  sNaN   ->  NaN  Invalid_operation
addx851 add -Inf  sNaN   ->  NaN  Invalid_operation
addx852 add -1000 sNaN   ->  NaN  Invalid_operation
addx853 add -1    sNaN   ->  NaN  Invalid_operation
addx854 add -0    sNaN   ->  NaN  Invalid_operation
addx855 add  0    sNaN   ->  NaN  Invalid_operation
addx856 add  1    sNaN   ->  NaN  Invalid_operation
addx857 add  1000 sNaN   ->  NaN  Invalid_operation
addx858 add  Inf  sNaN   ->  NaN  Invalid_operation
addx859 add  NaN  sNaN   ->  NaN  Invalid_operation

-- propagating NaNs
addx861 add  NaN1   -Inf    ->  NaN1
addx862 add +NaN2   -1000   ->  NaN2
addx863 add  NaN3    1000   ->  NaN3
addx864 add  NaN4    Inf    ->  NaN4
addx865 add  NaN5   +NaN6   ->  NaN5
addx866 add -Inf     NaN7   ->  NaN7
addx867 add -1000    NaN8   ->  NaN8
addx868 add  1000    NaN9   ->  NaN9
addx869 add  Inf    +NaN10  ->  NaN10
addx871 add  sNaN11  -Inf   ->  NaN11  Invalid_operation
addx872 add  sNaN12  -1000  ->  NaN12  Invalid_operation
addx873 add  sNaN13   1000  ->  NaN13  Invalid_operation
addx874 add  sNaN14   NaN17 ->  NaN14  Invalid_operation
addx875 add  sNaN15  sNaN18 ->  NaN15  Invalid_operation
addx876 add  NaN16   sNaN19 ->  NaN19  Invalid_operation
addx877 add -Inf    +sNaN20 ->  NaN20  Invalid_operation
addx878 add -1000    sNaN21 ->  NaN21  Invalid_operation
addx879 add  1000    sNaN22 ->  NaN22  Invalid_operation
addx880 add  Inf     sNaN23 ->  NaN23  Invalid_operation
addx881 add +NaN25  +sNaN24 ->  NaN24  Invalid_operation
addx882 add -NaN26    NaN28 -> -NaN26
addx883 add -sNaN27  sNaN29 -> -NaN27  Invalid_operation
addx884 add  1000    -NaN30 -> -NaN30
addx885 add  1000   -sNaN31 -> -NaN31  Invalid_operation

-- overflow, underflow and subnormal tests
maxexponent: 999999999
minexponent: -999999999
precision: 9
addx890 add 1E+999999999     9E+999999999   -> Infinity Overflow Inexact Rounded
addx891 add 9E+999999999     1E+999999999   -> Infinity Overflow Inexact Rounded
addx892 add -1.1E-999999999  1E-999999999   -> -1E-1000000000    Subnormal
addx893 add 1E-999999999    -1.1e-999999999 -> -1E-1000000000    Subnormal
addx894 add -1.0001E-999999999  1E-999999999   -> -1E-1000000003 Subnormal
addx895 add 1E-999999999    -1.0001e-999999999 -> -1E-1000000003 Subnormal
addx896 add -1E+999999999   -9E+999999999   -> -Infinity Overflow Inexact Rounded
addx897 add -9E+999999999   -1E+999999999   -> -Infinity Overflow Inexact Rounded
addx898 add +1.1E-999999999 -1E-999999999   -> 1E-1000000000    Subnormal
addx899 add -1E-999999999   +1.1e-999999999 -> 1E-1000000000    Subnormal
addx900 add +1.0001E-999999999 -1E-999999999   -> 1E-1000000003 Subnormal
addx901 add -1E-999999999   +1.0001e-999999999 -> 1E-1000000003 Subnormal
addx902 add -1E+999999999   +9E+999999999   ->  8E+999999999
addx903 add -9E+999999999   +1E+999999999   -> -8E+999999999

precision: 3
addx904 add      0 -9.999E+999999999   -> -Infinity Inexact Overflow Rounded
addx905 add        -9.999E+999999999 0 -> -Infinity Inexact Overflow Rounded
addx906 add      0  9.999E+999999999   ->  Infinity Inexact Overflow Rounded
addx907 add         9.999E+999999999 0 ->  Infinity Inexact Overflow Rounded

precision: 3
maxexponent: 999
minexponent: -999
addx910 add  1.00E-999   0    ->   1.00E-999
addx911 add  0.1E-999    0    ->   1E-1000   Subnormal
addx912 add  0.10E-999   0    ->   1.0E-1000 Subnormal
addx913 add  0.100E-999  0    ->   1.0E-1000 Subnormal Rounded
addx914 add  0.01E-999   0    ->   1E-1001   Subnormal
-- next is rounded to Nmin
addx915 add  0.999E-999  0    ->   1.00E-999 Inexact Rounded Subnormal Underflow
addx916 add  0.099E-999  0    ->   1.0E-1000 Inexact Rounded Subnormal Underflow
addx917 add  0.009E-999  0    ->   1E-1001   Inexact Rounded Subnormal Underflow
addx918 add  0.001E-999  0    ->   0E-1001   Inexact Rounded Subnormal Underflow Clamped
addx919 add  0.0009E-999 0    ->   0E-1001   Inexact Rounded Subnormal Underflow Clamped
addx920 add  0.0001E-999 0    ->   0E-1001   Inexact Rounded Subnormal Underflow Clamped

addx930 add -1.00E-999   0    ->  -1.00E-999
addx931 add -0.1E-999    0    ->  -1E-1000   Subnormal
addx932 add -0.10E-999   0    ->  -1.0E-1000 Subnormal
addx933 add -0.100E-999  0    ->  -1.0E-1000 Subnormal Rounded
addx934 add -0.01E-999   0    ->  -1E-1001   Subnormal
-- next is rounded to Nmin
addx935 add -0.999E-999  0    ->  -1.00E-999 Inexact Rounded Subnormal Underflow
addx936 add -0.099E-999  0    ->  -1.0E-1000 Inexact Rounded Subnormal Underflow
addx937 add -0.009E-999  0    ->  -1E-1001   Inexact Rounded Subnormal Underflow
addx938 add -0.001E-999  0    ->  -0E-1001   Inexact Rounded Subnormal Underflow Clamped
addx939 add -0.0009E-999 0    ->  -0E-1001   Inexact Rounded Subnormal Underflow Clamped
addx940 add -0.0001E-999 0    ->  -0E-1001   Inexact Rounded Subnormal Underflow Clamped

-- some non-zero subnormal adds
addx950 add  1.00E-999    0.1E-999  ->   1.10E-999
addx951 add  0.1E-999     0.1E-999  ->   2E-1000    Subnormal
addx952 add  0.10E-999    0.1E-999  ->   2.0E-1000  Subnormal
addx953 add  0.100E-999   0.1E-999  ->   2.0E-1000  Subnormal Rounded
addx954 add  0.01E-999    0.1E-999  ->   1.1E-1000  Subnormal
addx955 add  0.999E-999   0.1E-999  ->   1.10E-999  Inexact Rounded
addx956 add  0.099E-999   0.1E-999  ->   2.0E-1000  Inexact Rounded Subnormal Underflow
addx957 add  0.009E-999   0.1E-999  ->   1.1E-1000  Inexact Rounded Subnormal Underflow
addx958 add  0.001E-999   0.1E-999  ->   1.0E-1000  Inexact Rounded Subnormal Underflow
addx959 add  0.0009E-999  0.1E-999  ->   1.0E-1000  Inexact Rounded Subnormal Underflow
addx960 add  0.0001E-999  0.1E-999  ->   1.0E-1000  Inexact Rounded Subnormal Underflow
-- negatives...
addx961 add  1.00E-999   -0.1E-999  ->   9.0E-1000  Subnormal
addx962 add  0.1E-999    -0.1E-999  ->   0E-1000
addx963 add  0.10E-999   -0.1E-999  ->   0E-1001
addx964 add  0.100E-999  -0.1E-999  ->   0E-1001    Clamped
addx965 add  0.01E-999   -0.1E-999  ->   -9E-1001   Subnormal
addx966 add  0.999E-999  -0.1E-999  ->   9.0E-1000  Inexact Rounded Subnormal Underflow
addx967 add  0.099E-999  -0.1E-999  ->   -0E-1001   Inexact Rounded Subnormal Underflow Clamped
addx968 add  0.009E-999  -0.1E-999  ->   -9E-1001   Inexact Rounded Subnormal Underflow
addx969 add  0.001E-999  -0.1E-999  ->   -1.0E-1000 Inexact Rounded Subnormal Underflow
addx970 add  0.0009E-999 -0.1E-999  ->   -1.0E-1000 Inexact Rounded Subnormal Underflow
addx971 add  0.0001E-999 -0.1E-999  ->   -1.0E-1000 Inexact Rounded Subnormal Underflow

-- some 'real' numbers
maxExponent: 384
minExponent: -383
precision: 8
addx566 add 99999061735E-394  0E-394 -> 9.999906E-384 Inexact Rounded Underflow Subnormal
precision: 7
addx567 add 99999061735E-394  0E-394 -> 9.99991E-384 Inexact Rounded Underflow Subnormal
precision: 6
addx568 add 99999061735E-394  0E-394 -> 9.9999E-384 Inexact Rounded Underflow Subnormal

-- now the case where we can get underflow but the result is normal
-- [note this can't happen if the operands are also bounded, as we
-- cannot represent 1E-399, for example]
precision:   16
rounding:    half_up
maxExponent: 384
minExponent: -383

addx571 add       1E-383       0  -> 1E-383
addx572 add       1E-384       0  -> 1E-384   Subnormal
addx573 add       1E-383  1E-384  -> 1.1E-383
addx574 subtract  1E-383  1E-384  ->   9E-384 Subnormal

-- Here we explore the boundary of rounding a subnormal to Nmin
addx575 subtract  1E-383  1E-398  ->   9.99999999999999E-384  Subnormal
addx576 subtract  1E-383  1E-398  ->   9.99999999999999E-384  Subnormal
addx577 subtract  1E-383  1E-399  ->   1.000000000000000E-383 Underflow Inexact Subnormal Rounded
addx578 subtract  1E-383  1E-400  ->   1.000000000000000E-383 Underflow Inexact Subnormal Rounded
addx579 subtract  1E-383  1E-401  ->   1.000000000000000E-383 Underflow Inexact Subnormal Rounded
addx580 subtract  1E-383  1E-402  ->   1.000000000000000E-383 Underflow Inexact Subnormal Rounded

-- check overflow edge case
precision:   7
rounding:    half_up
maxExponent: 96
minExponent: -95
addx972 apply   9.999999E+96         -> 9.999999E+96
addx973 add     9.999999E+96  1      -> 9.999999E+96 Inexact Rounded
addx974 add      9999999E+90  1      -> 9.999999E+96 Inexact Rounded
addx975 add      9999999E+90  1E+90  -> Infinity Overflow Inexact Rounded
addx976 add      9999999E+90  9E+89  -> Infinity Overflow Inexact Rounded
addx977 add      9999999E+90  8E+89  -> Infinity Overflow Inexact Rounded
addx978 add      9999999E+90  7E+89  -> Infinity Overflow Inexact Rounded
addx979 add      9999999E+90  6E+89  -> Infinity Overflow Inexact Rounded
addx980 add      9999999E+90  5E+89  -> Infinity Overflow Inexact Rounded
addx981 add      9999999E+90  4E+89  -> 9.999999E+96 Inexact Rounded
addx982 add      9999999E+90  3E+89  -> 9.999999E+96 Inexact Rounded
addx983 add      9999999E+90  2E+89  -> 9.999999E+96 Inexact Rounded
addx984 add      9999999E+90  1E+89  -> 9.999999E+96 Inexact Rounded

addx985 apply  -9.999999E+96         -> -9.999999E+96
addx986 add    -9.999999E+96 -1      -> -9.999999E+96 Inexact Rounded
addx987 add     -9999999E+90 -1      -> -9.999999E+96 Inexact Rounded
addx988 add     -9999999E+90 -1E+90  -> -Infinity Overflow Inexact Rounded
addx989 add     -9999999E+90 -9E+89  -> -Infinity Overflow Inexact Rounded
addx990 add     -9999999E+90 -8E+89  -> -Infinity Overflow Inexact Rounded
addx991 add     -9999999E+90 -7E+89  -> -Infinity Overflow Inexact Rounded
addx992 add     -9999999E+90 -6E+89  -> -Infinity Overflow Inexact Rounded
addx993 add     -9999999E+90 -5E+89  -> -Infinity Overflow Inexact Rounded
addx994 add     -9999999E+90 -4E+89  -> -9.999999E+96 Inexact Rounded
addx995 add     -9999999E+90 -3E+89  -> -9.999999E+96 Inexact Rounded
addx996 add     -9999999E+90 -2E+89  -> -9.999999E+96 Inexact Rounded
addx997 add     -9999999E+90 -1E+89  -> -9.999999E+96 Inexact Rounded

-- check for double-rounded subnormals
precision:   5
maxexponent: 79
minexponent: -79
-- Add: lhs and rhs 0
addx1001 add       1.52444E-80 0 -> 1.524E-80 Inexact Rounded Subnormal Underflow
addx1002 add       1.52445E-80 0 -> 1.524E-80 Inexact Rounded Subnormal Underflow
addx1003 add       1.52446E-80 0 -> 1.524E-80 Inexact Rounded Subnormal Underflow
addx1004 add       0 1.52444E-80 -> 1.524E-80 Inexact Rounded Subnormal Underflow
addx1005 add       0 1.52445E-80 -> 1.524E-80 Inexact Rounded Subnormal Underflow
addx1006 add       0 1.52446E-80 -> 1.524E-80 Inexact Rounded Subnormal Underflow

-- Add: lhs >> rhs and vice versa
addx1011 add       1.52444E-80 1E-100 -> 1.524E-80 Inexact Rounded Subnormal Underflow
addx1012 add       1.52445E-80 1E-100 -> 1.524E-80 Inexact Rounded Subnormal Underflow
addx1013 add       1.52446E-80 1E-100 -> 1.524E-80 Inexact Rounded Subnormal Underflow
addx1014 add       1E-100 1.52444E-80 -> 1.524E-80 Inexact Rounded Subnormal Underflow
addx1015 add       1E-100 1.52445E-80 -> 1.524E-80 Inexact Rounded Subnormal Underflow
addx1016 add       1E-100 1.52446E-80 -> 1.524E-80 Inexact Rounded Subnormal Underflow

-- Add: lhs + rhs addition carried out
addx1021 add       1.52443E-80 1.00001E-80  -> 2.524E-80 Inexact Rounded Subnormal Underflow
addx1022 add       1.52444E-80 1.00001E-80  -> 2.524E-80 Inexact Rounded Subnormal Underflow
addx1023 add       1.52445E-80 1.00001E-80  -> 2.524E-80 Inexact Rounded Subnormal Underflow
addx1024 add       1.00001E-80  1.52443E-80 -> 2.524E-80 Inexact Rounded Subnormal Underflow
addx1025 add       1.00001E-80  1.52444E-80 -> 2.524E-80 Inexact Rounded Subnormal Underflow
addx1026 add       1.00001E-80  1.52445E-80 -> 2.524E-80 Inexact Rounded Subnormal Underflow

-- And for round down full and subnormal results
precision:    16
maxExponent: +384
minExponent: -383
rounding:     down

addx1100 add 1e+2 -1e-383    -> 99.99999999999999 Rounded Inexact
addx1101 add 1e+1 -1e-383    -> 9.999999999999999  Rounded Inexact
addx1103 add   +1 -1e-383    -> 0.9999999999999999  Rounded Inexact
addx1104 add 1e-1 -1e-383    -> 0.09999999999999999  Rounded Inexact
addx1105 add 1e-2 -1e-383    -> 0.009999999999999999  Rounded Inexact
addx1106 add 1e-3 -1e-383    -> 0.0009999999999999999  Rounded Inexact
addx1107 add 1e-4 -1e-383    -> 0.00009999999999999999  Rounded Inexact
addx1108 add 1e-5 -1e-383    -> 0.000009999999999999999  Rounded Inexact
addx1109 add 1e-6 -1e-383    -> 9.999999999999999E-7  Rounded Inexact

rounding:     ceiling
addx1110 add -1e+2 +1e-383   -> -99.99999999999999 Rounded Inexact
addx1111 add -1e+1 +1e-383   -> -9.999999999999999  Rounded Inexact
addx1113 add    -1 +1e-383   -> -0.9999999999999999  Rounded Inexact
addx1114 add -1e-1 +1e-383   -> -0.09999999999999999  Rounded Inexact
addx1115 add -1e-2 +1e-383   -> -0.009999999999999999  Rounded Inexact
addx1116 add -1e-3 +1e-383   -> -0.0009999999999999999  Rounded Inexact
addx1117 add -1e-4 +1e-383   -> -0.00009999999999999999  Rounded Inexact
addx1118 add -1e-5 +1e-383   -> -0.000009999999999999999  Rounded Inexact
addx1119 add -1e-6 +1e-383   -> -9.999999999999999E-7  Rounded Inexact
addx1120 add +1e-383 -1e+2   -> -99.99999999999999 Rounded Inexact
addx1121 add +1e-383 -1e+1   -> -9.999999999999999  Rounded Inexact
addx1123 add +1e-383    -1   -> -0.9999999999999999  Rounded Inexact
addx1124 add +1e-383 -1e-1   -> -0.09999999999999999  Rounded Inexact
addx1125 add +1e-383 -1e-2   -> -0.009999999999999999  Rounded Inexact
addx1126 add +1e-383 -1e-3   -> -0.0009999999999999999  Rounded Inexact
addx1127 add +1e-383 -1e-4   -> -0.00009999999999999999  Rounded Inexact
addx1128 add +1e-383 -1e-5   -> -0.000009999999999999999  Rounded Inexact
addx1129 add +1e-383 -1e-6   -> -9.999999999999999E-7  Rounded Inexact

rounding:     down
precision:    7
maxExponent: +96
minExponent: -95
addx1130 add   1            -1e-200  -> 0.9999999  Rounded Inexact
-- subnormal boundary
addx1131 add   1.000000E-94  -1e-200  ->  9.999999E-95  Rounded Inexact
addx1132 add   1.000001E-95  -1e-200  ->  1.000000E-95  Rounded Inexact
addx1133 add   1.000000E-95  -1e-200  ->  9.99999E-96  Rounded Inexact Subnormal Underflow
addx1134 add   0.999999E-95  -1e-200  ->  9.99998E-96  Rounded Inexact Subnormal Underflow
addx1135 add   0.001000E-95  -1e-200  ->  9.99E-99  Rounded Inexact Subnormal Underflow
addx1136 add   0.000999E-95  -1e-200  ->  9.98E-99  Rounded Inexact Subnormal Underflow
addx1137 add   1.000000E-95  -1e-101  ->  9.99999E-96  Subnormal
addx1138 add      10000E-101 -1e-200  ->  9.999E-98  Subnormal Inexact Rounded Underflow
addx1139 add       1000E-101 -1e-200  ->  9.99E-99   Subnormal Inexact Rounded Underflow
addx1140 add        100E-101 -1e-200  ->  9.9E-100   Subnormal Inexact Rounded Underflow
addx1141 add         10E-101 -1e-200  ->  9E-101     Subnormal Inexact Rounded Underflow
addx1142 add          1E-101 -1e-200  ->  0E-101     Subnormal Inexact Rounded Underflow Clamped
addx1143 add          0E-101 -1e-200  -> -0E-101     Subnormal Inexact Rounded Underflow Clamped
addx1144 add          1E-102 -1e-200  ->  0E-101     Subnormal Inexact Rounded Underflow Clamped

addx1151 add      10000E-102 -1e-200  ->  9.99E-99  Subnormal Inexact Rounded Underflow
addx1152 add       1000E-102 -1e-200  ->  9.9E-100  Subnormal Inexact Rounded Underflow
addx1153 add        100E-102 -1e-200  ->  9E-101   Subnormal Inexact Rounded Underflow
addx1154 add         10E-102 -1e-200  ->  0E-101     Subnormal Inexact Rounded Underflow Clamped
addx1155 add          1E-102 -1e-200  ->  0E-101     Subnormal Inexact Rounded Underflow Clamped
addx1156 add          0E-102 -1e-200  -> -0E-101     Subnormal Inexact Rounded Underflow Clamped
addx1157 add          1E-103 -1e-200  ->  0E-101     Subnormal Inexact Rounded Underflow Clamped

addx1160 add        100E-105 -1e-101  -> -0E-101 Subnormal Inexact Rounded Underflow Clamped
addx1161 add        100E-105 -1e-201  ->  0E-101 Subnormal Inexact Rounded Underflow Clamped

-- tests based on Gunnar Degnbol's edge case
precision:   15
rounding:    half_up
maxExponent: 384
minexponent: -383

addx1200 add 1E15  -0.5                 ->  1.00000000000000E+15 Inexact Rounded
addx1201 add 1E15  -0.50                ->  1.00000000000000E+15 Inexact Rounded
addx1210 add 1E15  -0.51                ->  999999999999999      Inexact Rounded
addx1211 add 1E15  -0.501               ->  999999999999999      Inexact Rounded
addx1212 add 1E15  -0.5001              ->  999999999999999      Inexact Rounded
addx1213 add 1E15  -0.50001             ->  999999999999999      Inexact Rounded
addx1214 add 1E15  -0.500001            ->  999999999999999      Inexact Rounded
addx1215 add 1E15  -0.5000001           ->  999999999999999      Inexact Rounded
addx1216 add 1E15  -0.50000001          ->  999999999999999      Inexact Rounded
addx1217 add 1E15  -0.500000001         ->  999999999999999      Inexact Rounded
addx1218 add 1E15  -0.5000000001        ->  999999999999999      Inexact Rounded
addx1219 add 1E15  -0.50000000001       ->  999999999999999      Inexact Rounded
addx1220 add 1E15  -0.500000000001      ->  999999999999999      Inexact Rounded
addx1221 add 1E15  -0.5000000000001     ->  999999999999999      Inexact Rounded
addx1222 add 1E15  -0.50000000000001    ->  999999999999999      Inexact Rounded
addx1223 add 1E15  -0.500000000000001   ->  999999999999999      Inexact Rounded
addx1224 add 1E15  -0.5000000000000001  ->  999999999999999      Inexact Rounded
addx1225 add 1E15  -0.5000000000000000  ->  1.00000000000000E+15 Inexact Rounded
addx1230 add 1E15  -5000000.000000001   ->  999999995000000      Inexact Rounded

precision:   16

addx1300 add 1E16  -0.5                 ->  1.000000000000000E+16 Inexact Rounded
addx1310 add 1E16  -0.51                ->  9999999999999999      Inexact Rounded
addx1311 add 1E16  -0.501               ->  9999999999999999      Inexact Rounded
addx1312 add 1E16  -0.5001              ->  9999999999999999      Inexact Rounded
addx1313 add 1E16  -0.50001             ->  9999999999999999      Inexact Rounded
addx1314 add 1E16  -0.500001            ->  9999999999999999      Inexact Rounded
addx1315 add 1E16  -0.5000001           ->  9999999999999999      Inexact Rounded
addx1316 add 1E16  -0.50000001          ->  9999999999999999      Inexact Rounded
addx1317 add 1E16  -0.500000001         ->  9999999999999999      Inexact Rounded
addx1318 add 1E16  -0.5000000001        ->  9999999999999999      Inexact Rounded
addx1319 add 1E16  -0.50000000001       ->  9999999999999999      Inexact Rounded
addx1320 add 1E16  -0.500000000001      ->  9999999999999999      Inexact Rounded
addx1321 add 1E16  -0.5000000000001     ->  9999999999999999      Inexact Rounded
addx1322 add 1E16  -0.50000000000001    ->  9999999999999999      Inexact Rounded
addx1323 add 1E16  -0.500000000000001   ->  9999999999999999      Inexact Rounded
addx1324 add 1E16  -0.5000000000000001  ->  9999999999999999      Inexact Rounded
addx1325 add 1E16  -0.5000000000000000  ->  1.000000000000000E+16 Inexact Rounded
addx1326 add 1E16  -0.500000000000000   ->  1.000000000000000E+16 Inexact Rounded
addx1327 add 1E16  -0.50000000000000    ->  1.000000000000000E+16 Inexact Rounded
addx1328 add 1E16  -0.5000000000000     ->  1.000000000000000E+16 Inexact Rounded
addx1329 add 1E16  -0.500000000000      ->  1.000000000000000E+16 Inexact Rounded
addx1330 add 1E16  -0.50000000000       ->  1.000000000000000E+16 Inexact Rounded
addx1331 add 1E16  -0.5000000000        ->  1.000000000000000E+16 Inexact Rounded
addx1332 add 1E16  -0.500000000         ->  1.000000000000000E+16 Inexact Rounded
addx1333 add 1E16  -0.50000000          ->  1.000000000000000E+16 Inexact Rounded
addx1334 add 1E16  -0.5000000           ->  1.000000000000000E+16 Inexact Rounded
addx1335 add 1E16  -0.500000            ->  1.000000000000000E+16 Inexact Rounded
addx1336 add 1E16  -0.50000             ->  1.000000000000000E+16 Inexact Rounded
addx1337 add 1E16  -0.5000              ->  1.000000000000000E+16 Inexact Rounded
addx1338 add 1E16  -0.500               ->  1.000000000000000E+16 Inexact Rounded
addx1339 add 1E16  -0.50                ->  1.000000000000000E+16 Inexact Rounded

addx1340 add 1E16  -5000000.000010001   ->  9999999995000000      Inexact Rounded
addx1341 add 1E16  -5000000.000000001   ->  9999999995000000      Inexact Rounded

addx1349 add 9999999999999999 0.4                 ->  9999999999999999      Inexact Rounded
addx1350 add 9999999999999999 0.49                ->  9999999999999999      Inexact Rounded
addx1351 add 9999999999999999 0.499               ->  9999999999999999      Inexact Rounded
addx1352 add 9999999999999999 0.4999              ->  9999999999999999      Inexact Rounded
addx1353 add 9999999999999999 0.49999             ->  9999999999999999      Inexact Rounded
addx1354 add 9999999999999999 0.499999            ->  9999999999999999      Inexact Rounded
addx1355 add 9999999999999999 0.4999999           ->  9999999999999999      Inexact Rounded
addx1356 add 9999999999999999 0.49999999          ->  9999999999999999      Inexact Rounded
addx1357 add 9999999999999999 0.499999999         ->  9999999999999999      Inexact Rounded
addx1358 add 9999999999999999 0.4999999999        ->  9999999999999999      Inexact Rounded
addx1359 add 9999999999999999 0.49999999999       ->  9999999999999999      Inexact Rounded
addx1360 add 9999999999999999 0.499999999999      ->  9999999999999999      Inexact Rounded
addx1361 add 9999999999999999 0.4999999999999     ->  9999999999999999      Inexact Rounded
addx1362 add 9999999999999999 0.49999999999999    ->  9999999999999999      Inexact Rounded
addx1363 add 9999999999999999 0.499999999999999   ->  9999999999999999      Inexact Rounded
addx1364 add 9999999999999999 0.4999999999999999  ->  9999999999999999      Inexact Rounded
addx1365 add 9999999999999999 0.5000000000000000  ->  1.000000000000000E+16 Inexact Rounded
addx1367 add 9999999999999999 0.500000000000000   ->  1.000000000000000E+16 Inexact Rounded
addx1368 add 9999999999999999 0.50000000000000    ->  1.000000000000000E+16 Inexact Rounded
addx1369 add 9999999999999999 0.5000000000000     ->  1.000000000000000E+16 Inexact Rounded
addx1370 add 9999999999999999 0.500000000000      ->  1.000000000000000E+16 Inexact Rounded
addx1371 add 9999999999999999 0.50000000000       ->  1.000000000000000E+16 Inexact Rounded
addx1372 add 9999999999999999 0.5000000000        ->  1.000000000000000E+16 Inexact Rounded
addx1373 add 9999999999999999 0.500000000         ->  1.000000000000000E+16 Inexact Rounded
addx1374 add 9999999999999999 0.50000000          ->  1.000000000000000E+16 Inexact Rounded
addx1375 add 9999999999999999 0.5000000           ->  1.000000000000000E+16 Inexact Rounded
addx1376 add 9999999999999999 0.500000            ->  1.000000000000000E+16 Inexact Rounded
addx1377 add 9999999999999999 0.50000             ->  1.000000000000000E+16 Inexact Rounded
addx1378 add 9999999999999999 0.5000              ->  1.000000000000000E+16 Inexact Rounded
addx1379 add 9999999999999999 0.500               ->  1.000000000000000E+16 Inexact Rounded
addx1380 add 9999999999999999 0.50                ->  1.000000000000000E+16 Inexact Rounded
addx1381 add 9999999999999999 0.5                 ->  1.000000000000000E+16 Inexact Rounded
addx1382 add 9999999999999999 0.5000000000000001  ->  1.000000000000000E+16 Inexact Rounded
addx1383 add 9999999999999999 0.500000000000001   ->  1.000000000000000E+16 Inexact Rounded
addx1384 add 9999999999999999 0.50000000000001    ->  1.000000000000000E+16 Inexact Rounded
addx1385 add 9999999999999999 0.5000000000001     ->  1.000000000000000E+16 Inexact Rounded
addx1386 add 9999999999999999 0.500000000001      ->  1.000000000000000E+16 Inexact Rounded
addx1387 add 9999999999999999 0.50000000001       ->  1.000000000000000E+16 Inexact Rounded
addx1388 add 9999999999999999 0.5000000001        ->  1.000000000000000E+16 Inexact Rounded
addx1389 add 9999999999999999 0.500000001         ->  1.000000000000000E+16 Inexact Rounded
addx1390 add 9999999999999999 0.50000001          ->  1.000000000000000E+16 Inexact Rounded
addx1391 add 9999999999999999 0.5000001           ->  1.000000000000000E+16 Inexact Rounded
addx1392 add 9999999999999999 0.500001            ->  1.000000000000000E+16 Inexact Rounded
addx1393 add 9999999999999999 0.50001             ->  1.000000000000000E+16 Inexact Rounded
addx1394 add 9999999999999999 0.5001              ->  1.000000000000000E+16 Inexact Rounded
addx1395 add 9999999999999999 0.501               ->  1.000000000000000E+16 Inexact Rounded
addx1396 add 9999999999999999 0.51                ->  1.000000000000000E+16 Inexact Rounded

-- More GD edge cases, where difference between the unadjusted
-- exponents is larger than the maximum precision and one side is 0
precision:   15
rounding:    half_up
maxExponent: 384
minexponent: -383

addx1400 add  0 1.23456789012345     -> 1.23456789012345
addx1401 add  0 1.23456789012345E-1  -> 0.123456789012345
addx1402 add  0 1.23456789012345E-2  -> 0.0123456789012345
addx1403 add  0 1.23456789012345E-3  -> 0.00123456789012345
addx1404 add  0 1.23456789012345E-4  -> 0.000123456789012345
addx1405 add  0 1.23456789012345E-5  -> 0.0000123456789012345
addx1406 add  0 1.23456789012345E-6  -> 0.00000123456789012345
addx1407 add  0 1.23456789012345E-7  -> 1.23456789012345E-7
addx1408 add  0 1.23456789012345E-8  -> 1.23456789012345E-8
addx1409 add  0 1.23456789012345E-9  -> 1.23456789012345E-9
addx1410 add  0 1.23456789012345E-10 -> 1.23456789012345E-10
addx1411 add  0 1.23456789012345E-11 -> 1.23456789012345E-11
addx1412 add  0 1.23456789012345E-12 -> 1.23456789012345E-12
addx1413 add  0 1.23456789012345E-13 -> 1.23456789012345E-13
addx1414 add  0 1.23456789012345E-14 -> 1.23456789012345E-14
addx1415 add  0 1.23456789012345E-15 -> 1.23456789012345E-15
addx1416 add  0 1.23456789012345E-16 -> 1.23456789012345E-16
addx1417 add  0 1.23456789012345E-17 -> 1.23456789012345E-17
addx1418 add  0 1.23456789012345E-18 -> 1.23456789012345E-18
addx1419 add  0 1.23456789012345E-19 -> 1.23456789012345E-19

-- same, precision 16..
precision:   16
addx1420 add  0 1.123456789012345     -> 1.123456789012345
addx1421 add  0 1.123456789012345E-1  -> 0.1123456789012345
addx1422 add  0 1.123456789012345E-2  -> 0.01123456789012345
addx1423 add  0 1.123456789012345E-3  -> 0.001123456789012345
addx1424 add  0 1.123456789012345E-4  -> 0.0001123456789012345
addx1425 add  0 1.123456789012345E-5  -> 0.00001123456789012345
addx1426 add  0 1.123456789012345E-6  -> 0.000001123456789012345
addx1427 add  0 1.123456789012345E-7  -> 1.123456789012345E-7
addx1428 add  0 1.123456789012345E-8  -> 1.123456789012345E-8
addx1429 add  0 1.123456789012345E-9  -> 1.123456789012345E-9
addx1430 add  0 1.123456789012345E-10 -> 1.123456789012345E-10
addx1431 add  0 1.123456789012345E-11 -> 1.123456789012345E-11
addx1432 add  0 1.123456789012345E-12 -> 1.123456789012345E-12
addx1433 add  0 1.123456789012345E-13 -> 1.123456789012345E-13
addx1434 add  0 1.123456789012345E-14 -> 1.123456789012345E-14
addx1435 add  0 1.123456789012345E-15 -> 1.123456789012345E-15
addx1436 add  0 1.123456789012345E-16 -> 1.123456789012345E-16
addx1437 add  0 1.123456789012345E-17 -> 1.123456789012345E-17
addx1438 add  0 1.123456789012345E-18 -> 1.123456789012345E-18
addx1439 add  0 1.123456789012345E-19 -> 1.123456789012345E-19

-- same, reversed 0
addx1440 add 1.123456789012345     0 -> 1.123456789012345
addx1441 add 1.123456789012345E-1  0 -> 0.1123456789012345
addx1442 add 1.123456789012345E-2  0 -> 0.01123456789012345
addx1443 add 1.123456789012345E-3  0 -> 0.001123456789012345
addx1444 add 1.123456789012345E-4  0 -> 0.0001123456789012345
addx1445 add 1.123456789012345E-5  0 -> 0.00001123456789012345
addx1446 add 1.123456789012345E-6  0 -> 0.000001123456789012345
addx1447 add 1.123456789012345E-7  0 -> 1.123456789012345E-7
addx1448 add 1.123456789012345E-8  0 -> 1.123456789012345E-8
addx1449 add 1.123456789012345E-9  0 -> 1.123456789012345E-9
addx1450 add 1.123456789012345E-10 0 -> 1.123456789012345E-10
addx1451 add 1.123456789012345E-11 0 -> 1.123456789012345E-11
addx1452 add 1.123456789012345E-12 0 -> 1.123456789012345E-12
addx1453 add 1.123456789012345E-13 0 -> 1.123456789012345E-13
addx1454 add 1.123456789012345E-14 0 -> 1.123456789012345E-14
addx1455 add 1.123456789012345E-15 0 -> 1.123456789012345E-15
addx1456 add 1.123456789012345E-16 0 -> 1.123456789012345E-16
addx1457 add 1.123456789012345E-17 0 -> 1.123456789012345E-17
addx1458 add 1.123456789012345E-18 0 -> 1.123456789012345E-18
addx1459 add 1.123456789012345E-19 0 -> 1.123456789012345E-19

-- same, Es on the 0
addx1460 add 1.123456789012345  0E-0   -> 1.123456789012345
addx1461 add 1.123456789012345  0E-1   -> 1.123456789012345
addx1462 add 1.123456789012345  0E-2   -> 1.123456789012345
addx1463 add 1.123456789012345  0E-3   -> 1.123456789012345
addx1464 add 1.123456789012345  0E-4   -> 1.123456789012345
addx1465 add 1.123456789012345  0E-5   -> 1.123456789012345
addx1466 add 1.123456789012345  0E-6   -> 1.123456789012345
addx1467 add 1.123456789012345  0E-7   -> 1.123456789012345
addx1468 add 1.123456789012345  0E-8   -> 1.123456789012345
addx1469 add 1.123456789012345  0E-9   -> 1.123456789012345
addx1470 add 1.123456789012345  0E-10  -> 1.123456789012345
addx1471 add 1.123456789012345  0E-11  -> 1.123456789012345
addx1472 add 1.123456789012345  0E-12  -> 1.123456789012345
addx1473 add 1.123456789012345  0E-13  -> 1.123456789012345
addx1474 add 1.123456789012345  0E-14  -> 1.123456789012345
addx1475 add 1.123456789012345  0E-15  -> 1.123456789012345
-- next four flag Rounded because the 0 extends the result
addx1476 add 1.123456789012345  0E-16  -> 1.123456789012345 Rounded
addx1477 add 1.123456789012345  0E-17  -> 1.123456789012345 Rounded
addx1478 add 1.123456789012345  0E-18  -> 1.123456789012345 Rounded
addx1479 add 1.123456789012345  0E-19  -> 1.123456789012345 Rounded

-- sum of two opposite-sign operands is exactly 0 and floor => -0
precision:   16
maxExponent: 384
minexponent: -383

rounding:    half_up
-- exact zeros from zeros
addx1500 add  0        0E-19  ->  0E-19
addx1501 add -0        0E-19  ->  0E-19
addx1502 add  0       -0E-19  ->  0E-19
addx1503 add -0       -0E-19  -> -0E-19
addx1504 add  0E-400   0E-19  ->  0E-398 Clamped
addx1505 add -0E-400   0E-19  ->  0E-398 Clamped
addx1506 add  0E-400  -0E-19  ->  0E-398 Clamped
addx1507 add -0E-400  -0E-19  -> -0E-398 Clamped
-- inexact zeros
addx1511 add  1E-401   1E-400 ->  0E-398 Subnormal Inexact Rounded Underflow Clamped
addx1512 add -1E-401   1E-400 ->  0E-398 Subnormal Inexact Rounded Underflow Clamped
addx1513 add  1E-401  -1E-400 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
addx1514 add -1E-401  -1E-400 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
-- some exact zeros from non-zeros
addx1515 add  1E-401   1E-401 ->  0E-398 Subnormal Inexact Rounded Underflow Clamped
addx1516 add -1E-401   1E-401 ->  0E-398 Clamped
addx1517 add  1E-401  -1E-401 ->  0E-398 Clamped
addx1518 add -1E-401  -1E-401 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped

rounding:    half_down
-- exact zeros from zeros
addx1520 add  0        0E-19  ->  0E-19
addx1521 add -0        0E-19  ->  0E-19
addx1522 add  0       -0E-19  ->  0E-19
addx1523 add -0       -0E-19  -> -0E-19
addx1524 add  0E-400   0E-19  ->  0E-398 Clamped
addx1525 add -0E-400   0E-19  ->  0E-398 Clamped
addx1526 add  0E-400  -0E-19  ->  0E-398 Clamped
addx1527 add -0E-400  -0E-19  -> -0E-398 Clamped
-- inexact zeros
addx1531 add  1E-401   1E-400 ->  0E-398 Subnormal Inexact Rounded Underflow Clamped
addx1532 add -1E-401   1E-400 ->  0E-398 Subnormal Inexact Rounded Underflow Clamped
addx1533 add  1E-401  -1E-400 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
addx1534 add -1E-401  -1E-400 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
-- some exact zeros from non-zeros
addx1535 add  1E-401   1E-401 ->  0E-398 Subnormal Inexact Rounded Underflow Clamped
addx1536 add -1E-401   1E-401 ->  0E-398 Clamped
addx1537 add  1E-401  -1E-401 ->  0E-398 Clamped
addx1538 add -1E-401  -1E-401 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped

rounding:    half_even
-- exact zeros from zeros
addx1540 add  0        0E-19  ->  0E-19
addx1541 add -0        0E-19  ->  0E-19
addx1542 add  0       -0E-19  ->  0E-19
addx1543 add -0       -0E-19  -> -0E-19
addx1544 add  0E-400   0E-19  ->  0E-398 Clamped
addx1545 add -0E-400   0E-19  ->  0E-398 Clamped
addx1546 add  0E-400  -0E-19  ->  0E-398 Clamped
addx1547 add -0E-400  -0E-19  -> -0E-398 Clamped
-- inexact zeros
addx1551 add  1E-401   1E-400 ->  0E-398 Subnormal Inexact Rounded Underflow Clamped
addx1552 add -1E-401   1E-400 ->  0E-398 Subnormal Inexact Rounded Underflow Clamped
addx1553 add  1E-401  -1E-400 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
addx1554 add -1E-401  -1E-400 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
-- some exact zeros from non-zeros
addx1555 add  1E-401   1E-401 ->  0E-398 Subnormal Inexact Rounded Underflow Clamped
addx1556 add -1E-401   1E-401 ->  0E-398 Clamped
addx1557 add  1E-401  -1E-401 ->  0E-398 Clamped
addx1558 add -1E-401  -1E-401 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped

rounding:    up
-- exact zeros from zeros
addx1560 add  0        0E-19  ->  0E-19
addx1561 add -0        0E-19  ->  0E-19
addx1562 add  0       -0E-19  ->  0E-19
addx1563 add -0       -0E-19  -> -0E-19
addx1564 add  0E-400   0E-19  ->  0E-398 Clamped
addx1565 add -0E-400   0E-19  ->  0E-398 Clamped
addx1566 add  0E-400  -0E-19  ->  0E-398 Clamped
addx1567 add -0E-400  -0E-19  -> -0E-398 Clamped
-- inexact zeros
addx1571 add  1E-401   1E-400 ->  1E-398 Subnormal Inexact Rounded Underflow
addx1572 add -1E-401   1E-400 ->  1E-398 Subnormal Inexact Rounded Underflow
addx1573 add  1E-401  -1E-400 -> -1E-398 Subnormal Inexact Rounded Underflow
addx1574 add -1E-401  -1E-400 -> -1E-398 Subnormal Inexact Rounded Underflow
-- some exact zeros from non-zeros
addx1575 add  1E-401   1E-401 ->  1E-398 Subnormal Inexact Rounded Underflow
addx1576 add -1E-401   1E-401 ->  0E-398 Clamped
addx1577 add  1E-401  -1E-401 ->  0E-398 Clamped
addx1578 add -1E-401  -1E-401 -> -1E-398 Subnormal Inexact Rounded Underflow

rounding:    down
-- exact zeros from zeros
addx1580 add  0        0E-19  ->  0E-19
addx1581 add -0        0E-19  ->  0E-19
addx1582 add  0       -0E-19  ->  0E-19
addx1583 add -0       -0E-19  -> -0E-19
addx1584 add  0E-400   0E-19  ->  0E-398 Clamped
addx1585 add -0E-400   0E-19  ->  0E-398 Clamped
addx1586 add  0E-400  -0E-19  ->  0E-398 Clamped
addx1587 add -0E-400  -0E-19  -> -0E-398 Clamped
-- inexact zeros
addx1591 add  1E-401   1E-400 ->  0E-398 Subnormal Inexact Rounded Underflow Clamped
addx1592 add -1E-401   1E-400 ->  0E-398 Subnormal Inexact Rounded Underflow Clamped
addx1593 add  1E-401  -1E-400 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
addx1594 add -1E-401  -1E-400 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
-- some exact zeros from non-zeros
addx1595 add  1E-401   1E-401 ->  0E-398 Subnormal Inexact Rounded Underflow Clamped
addx1596 add -1E-401   1E-401 ->  0E-398 Clamped
addx1597 add  1E-401  -1E-401 ->  0E-398 Clamped
addx1598 add -1E-401  -1E-401 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped

rounding:    ceiling
-- exact zeros from zeros
addx1600 add  0        0E-19  ->  0E-19
addx1601 add -0        0E-19  ->  0E-19
addx1602 add  0       -0E-19  ->  0E-19
addx1603 add -0       -0E-19  -> -0E-19
addx1604 add  0E-400   0E-19  ->  0E-398 Clamped
addx1605 add -0E-400   0E-19  ->  0E-398 Clamped
addx1606 add  0E-400  -0E-19  ->  0E-398 Clamped
addx1607 add -0E-400  -0E-19  -> -0E-398 Clamped
-- inexact zeros
addx1611 add  1E-401   1E-400 ->  1E-398 Subnormal Inexact Rounded Underflow
addx1612 add -1E-401   1E-400 ->  1E-398 Subnormal Inexact Rounded Underflow
addx1613 add  1E-401  -1E-400 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
addx1614 add -1E-401  -1E-400 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
-- some exact zeros from non-zeros
addx1615 add  1E-401   1E-401 ->  1E-398 Subnormal Inexact Rounded Underflow
addx1616 add -1E-401   1E-401 ->  0E-398 Clamped
addx1617 add  1E-401  -1E-401 ->  0E-398 Clamped
addx1618 add -1E-401  -1E-401 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped

-- and the extra-special ugly case; unusual minuses marked by -- *
rounding:    floor
-- exact zeros from zeros
addx1620 add  0        0E-19  ->  0E-19
addx1621 add -0        0E-19  -> -0E-19           -- *
addx1622 add  0       -0E-19  -> -0E-19           -- *
addx1623 add -0       -0E-19  -> -0E-19
addx1624 add  0E-400   0E-19  ->  0E-398 Clamped
addx1625 add -0E-400   0E-19  -> -0E-398 Clamped  -- *
addx1626 add  0E-400  -0E-19  -> -0E-398 Clamped  -- *
addx1627 add -0E-400  -0E-19  -> -0E-398 Clamped
-- inexact zeros
addx1631 add  1E-401   1E-400 ->  0E-398 Subnormal Inexact Rounded Underflow Clamped
addx1632 add -1E-401   1E-400 ->  0E-398 Subnormal Inexact Rounded Underflow Clamped
addx1633 add  1E-401  -1E-400 -> -1E-398 Subnormal Inexact Rounded Underflow
addx1634 add -1E-401  -1E-400 -> -1E-398 Subnormal Inexact Rounded Underflow
-- some exact zeros from non-zeros
addx1635 add  1E-401   1E-401 ->  0E-398 Subnormal Inexact Rounded Underflow Clamped
addx1636 add -1E-401   1E-401 -> -0E-398 Clamped  -- *
addx1637 add  1E-401  -1E-401 -> -0E-398 Clamped  -- *
addx1638 add -1E-401  -1E-401 -> -1E-398 Subnormal Inexact Rounded Underflow

-- BigDecimal problem testcases 2006.01.23
precision:   16
maxExponent: 384
minexponent: -383

rounding:  down
precision: 7
addx1651 add  10001E+2  -2E+1 -> 1.00008E+6
precision: 6
addx1652 add  10001E+2  -2E+1 -> 1.00008E+6
precision: 5
addx1653 add  10001E+2  -2E+1 -> 1.0000E+6   Inexact Rounded
precision: 4
addx1654 add  10001E+2  -2E+1 -> 1.000E+6    Inexact Rounded
precision: 3
addx1655 add  10001E+2  -2E+1 -> 1.00E+6     Inexact Rounded
precision: 2
addx1656 add  10001E+2  -2E+1 -> 1.0E+6      Inexact Rounded
precision: 1
addx1657 add  10001E+2  -2E+1 -> 1E+6        Inexact Rounded

rounding:  half_even
precision: 7
addx1661 add  10001E+2  -2E+1 -> 1.00008E+6
precision: 6
addx1662 add  10001E+2  -2E+1 -> 1.00008E+6
precision: 5
addx1663 add  10001E+2  -2E+1 -> 1.0001E+6   Inexact Rounded
precision: 4
addx1664 add  10001E+2  -2E+1 -> 1.000E+6    Inexact Rounded
precision: 3
addx1665 add  10001E+2  -2E+1 -> 1.00E+6     Inexact Rounded
precision: 2
addx1666 add  10001E+2  -2E+1 -> 1.0E+6      Inexact Rounded
precision: 1
addx1667 add  10001E+2  -2E+1 -> 1E+6        Inexact Rounded

rounding:  up
precision: 7
addx1671 add  10001E+2  -2E+1 -> 1.00008E+6
precision: 6
addx1672 add  10001E+2  -2E+1 -> 1.00008E+6
precision: 5
addx1673 add  10001E+2  -2E+1 -> 1.0001E+6   Inexact Rounded
precision: 4
addx1674 add  10001E+2  -2E+1 -> 1.001E+6    Inexact Rounded
precision: 3
addx1675 add  10001E+2  -2E+1 -> 1.01E+6     Inexact Rounded
precision: 2
addx1676 add  10001E+2  -2E+1 -> 1.1E+6      Inexact Rounded
precision: 1
addx1677 add  10001E+2  -2E+1 -> 2E+6        Inexact Rounded

precision:   34
rounding:    half_up
maxExponent: 6144
minExponent: -6143
-- Examples from SQL proposal (Krishna Kulkarni)
addx1701  add 130E-2    120E-2    -> 2.50
addx1702  add 130E-2    12E-1     -> 2.50
addx1703  add 130E-2    1E0       -> 2.30
addx1704  add 1E2       1E4       -> 1.01E+4
addx1705  subtract 130E-2  120E-2 -> 0.10
addx1706  subtract 130E-2  12E-1  -> 0.10
addx1707  subtract 130E-2  1E0    -> 0.30
addx1708  subtract 1E2     1E4    -> -9.9E+3

------------------------------------------------------------------------
-- Same as above, using decimal64 default parameters                  --
------------------------------------------------------------------------
precision:   16
rounding:    half_even
maxExponent: 384
minexponent: -383

-- [first group are 'quick confidence check']
addx6001 add 1       1       ->  2
addx6002 add 2       3       ->  5
addx6003 add '5.75'  '3.3'   ->  9.05
addx6004 add '5'     '-3'    ->  2
addx6005 add '-5'    '-3'    ->  -8
addx6006 add '-7'    '2.5'   ->  -4.5
addx6007 add '0.7'   '0.3'   ->  1.0
addx6008 add '1.25'  '1.25'  ->  2.50
addx6009 add '1.23456789'  '1.00000000' -> '2.23456789'
addx6010 add '1.23456789'  '1.00000011' -> '2.23456800'

addx6011 add '0.44444444444444444'  '0.55555555555555555' -> '1.000000000000000' Inexact Rounded
addx6012 add '0.44444444444444440'  '0.55555555555555555' -> '1.000000000000000' Inexact Rounded
addx6013 add '0.44444444444444444'  '0.55555555555555550' -> '0.9999999999999999' Inexact Rounded
addx6014 add '0.444444444444444449'    '0' -> '0.4444444444444444' Inexact Rounded
addx6015 add '0.4444444444444444499'   '0' -> '0.4444444444444444' Inexact Rounded
addx6016 add '0.44444444444444444999'  '0' -> '0.4444444444444444' Inexact Rounded
addx6017 add '0.44444444444444445000'  '0' -> '0.4444444444444444' Inexact Rounded
addx6018 add '0.44444444444444445001'  '0' -> '0.4444444444444445' Inexact Rounded
addx6019 add '0.4444444444444444501'   '0' -> '0.4444444444444445' Inexact Rounded
addx6020 add '0.444444444444444451'    '0' -> '0.4444444444444445' Inexact Rounded

addx6021 add 0 1 -> 1
addx6022 add 1 1 -> 2
addx6023 add 2 1 -> 3
addx6024 add 3 1 -> 4
addx6025 add 4 1 -> 5
addx6026 add 5 1 -> 6
addx6027 add 6 1 -> 7
addx6028 add 7 1 -> 8
addx6029 add 8 1 -> 9
addx6030 add 9 1 -> 10

-- some carrying effects
addx6031 add '0.9998'  '0.0000' -> '0.9998'
addx6032 add '0.9998'  '0.0001' -> '0.9999'
addx6033 add '0.9998'  '0.0002' -> '1.0000'
addx6034 add '0.9998'  '0.0003' -> '1.0001'

addx6035 add '70'      '10000e+16' -> '1.000000000000000E+20' Inexact Rounded
addx6036 add '700'     '10000e+16' -> '1.000000000000000E+20' Inexact Rounded
addx6037 add '7000'    '10000e+16' -> '1.000000000000000E+20' Inexact Rounded
addx6038 add '70000'   '10000e+16' -> '1.000000000000001E+20' Inexact Rounded
addx6039 add '700000'  '10000e+16' -> '1.000000000000007E+20' Rounded

-- symmetry:
addx6040 add '10000e+16'  '70' -> '1.000000000000000E+20' Inexact Rounded
addx6041 add '10000e+16'  '700' -> '1.000000000000000E+20' Inexact Rounded
addx6042 add '10000e+16'  '7000' -> '1.000000000000000E+20' Inexact Rounded
addx6044 add '10000e+16'  '70000' -> '1.000000000000001E+20' Inexact Rounded
addx6045 add '10000e+16'  '700000' -> '1.000000000000007E+20' Rounded

addx6046 add '10000e+9'  '7' -> '10000000000007'
addx6047 add '10000e+9'  '70' -> '10000000000070'
addx6048 add '10000e+9'  '700' -> '10000000000700'
addx6049 add '10000e+9'  '7000' -> '10000000007000'
addx6050 add '10000e+9'  '70000' -> '10000000070000'
addx6051 add '10000e+9'  '700000' -> '10000000700000'

-- examples from decarith
addx6053 add '12' '7.00' -> '19.00'
addx6054 add '1.3' '-1.07' -> '0.23'
addx6055 add '1.3' '-1.30' -> '0.00'
addx6056 add '1.3' '-2.07' -> '-0.77'
addx6057 add '1E+2' '1E+4' -> '1.01E+4'

-- from above
addx6060 add 1 '0.1' -> '1.1'
addx6061 add 1 '0.01' -> '1.01'
addx6062 add 1 '0.001' -> '1.001'
addx6063 add 1 '0.0001' -> '1.0001'
addx6064 add 1 '0.00001' -> '1.00001'
addx6065 add 1 '0.000001' -> '1.000001'
addx6066 add 1 '0.0000001' -> '1.0000001'
addx6067 add 1 '0.00000001' -> '1.00000001'

-- cancellation to integer
addx6068 add 99999999999999123456789 -99999999999999E+9 -> 123456789
-- similar from FMA fun
addx6069 add "-1234567890123455.234567890123454" "1234567890123456" -> 0.765432109876546

-- some funny zeros [in case of bad signum]
addx6070 add 1  0    -> 1
addx6071 add 1 0.    -> 1
addx6072 add 1  .0   -> 1.0
addx6073 add 1 0.0   -> 1.0
addx6074 add 1 0.00  -> 1.00
addx6075 add  0  1   -> 1
addx6076 add 0.  1   -> 1
addx6077 add  .0 1   -> 1.0
addx6078 add 0.0 1   -> 1.0
addx6079 add 0.00 1  -> 1.00

-- some carries
addx6080 add 9999999999999998 1  -> 9999999999999999
addx6081 add 9999999999999999 1  -> 1.000000000000000E+16 Rounded
addx6082 add  999999999999999 1  -> 1000000000000000
addx6083 add    9999999999999 1  -> 10000000000000
addx6084 add      99999999999 1  -> 100000000000
addx6085 add        999999999 1  -> 1000000000
addx6086 add          9999999 1  -> 10000000
addx6087 add            99999 1  -> 100000
addx6088 add              999 1  -> 1000
addx6089 add                9 1  -> 10


-- more LHS swaps
addx6090 add '-56267E-10'   0 ->  '-0.0000056267'
addx6091 add '-56267E-6'    0 ->  '-0.056267'
addx6092 add '-56267E-5'    0 ->  '-0.56267'
addx6093 add '-56267E-4'    0 ->  '-5.6267'
addx6094 add '-56267E-3'    0 ->  '-56.267'
addx6095 add '-56267E-2'    0 ->  '-562.67'
addx6096 add '-56267E-1'    0 ->  '-5626.7'
addx6097 add '-56267E-0'    0 ->  '-56267'
addx6098 add '-5E-10'       0 ->  '-5E-10'
addx6099 add '-5E-7'        0 ->  '-5E-7'
addx6100 add '-5E-6'        0 ->  '-0.000005'
addx6101 add '-5E-5'        0 ->  '-0.00005'
addx6102 add '-5E-4'        0 ->  '-0.0005'
addx6103 add '-5E-1'        0 ->  '-0.5'
addx6104 add '-5E0'         0 ->  '-5'
addx6105 add '-5E1'         0 ->  '-50'
addx6106 add '-5E5'         0 ->  '-500000'
addx6107 add '-5E15'        0 ->  '-5000000000000000'
addx6108 add '-5E16'        0 ->  '-5.000000000000000E+16'   Rounded
addx6109 add '-5E17'        0 ->  '-5.000000000000000E+17'  Rounded
addx6110 add '-5E18'        0 ->  '-5.000000000000000E+18'  Rounded
addx6111 add '-5E100'       0 ->  '-5.000000000000000E+100' Rounded

-- more RHS swaps
addx6113 add 0  '-56267E-10' ->  '-0.0000056267'
addx6114 add 0  '-56267E-6'  ->  '-0.056267'
addx6116 add 0  '-56267E-5'  ->  '-0.56267'
addx6117 add 0  '-56267E-4'  ->  '-5.6267'
addx6119 add 0  '-56267E-3'  ->  '-56.267'
addx6120 add 0  '-56267E-2'  ->  '-562.67'
addx6121 add 0  '-56267E-1'  ->  '-5626.7'
addx6122 add 0  '-56267E-0'  ->  '-56267'
addx6123 add 0  '-5E-10'     ->  '-5E-10'
addx6124 add 0  '-5E-7'      ->  '-5E-7'
addx6125 add 0  '-5E-6'      ->  '-0.000005'
addx6126 add 0  '-5E-5'      ->  '-0.00005'
addx6127 add 0  '-5E-4'      ->  '-0.0005'
addx6128 add 0  '-5E-1'      ->  '-0.5'
addx6129 add 0  '-5E0'       ->  '-5'
addx6130 add 0  '-5E1'       ->  '-50'
addx6131 add 0  '-5E5'       ->  '-500000'
addx6132 add 0  '-5E15'      ->  '-5000000000000000'
addx6133 add 0  '-5E16'      ->  '-5.000000000000000E+16'   Rounded
addx6134 add 0  '-5E17'      ->  '-5.000000000000000E+17'   Rounded
addx6135 add 0  '-5E18'      ->  '-5.000000000000000E+18'   Rounded
addx6136 add 0  '-5E100'     ->  '-5.000000000000000E+100'  Rounded

-- related
addx6137 add  1  '0E-19'      ->  '1.000000000000000'  Rounded
addx6138 add -1  '0E-19'      ->  '-1.000000000000000' Rounded
addx6139 add '0E-19' 1        ->  '1.000000000000000'  Rounded
addx6140 add '0E-19' -1       ->  '-1.000000000000000' Rounded
addx6141 add 1E+11   0.0000   ->  '100000000000.0000'
addx6142 add 1E+11   0.00000  ->  '100000000000.0000'  Rounded
addx6143 add 0.000   1E+12    ->  '1000000000000.000'
addx6144 add 0.0000  1E+12    ->  '1000000000000.000'  Rounded

-- [some of the next group are really constructor tests]
addx6146 add '00.0'  0       ->  '0.0'
addx6147 add '0.00'  0       ->  '0.00'
addx6148 add  0      '0.00'  ->  '0.00'
addx6149 add  0      '00.0'  ->  '0.0'
addx6150 add '00.0'  '0.00'  ->  '0.00'
addx6151 add '0.00'  '00.0'  ->  '0.00'
addx6152 add '3'     '.3'    ->  '3.3'
addx6153 add '3.'    '.3'    ->  '3.3'
addx6154 add '3.0'   '.3'    ->  '3.3'
addx6155 add '3.00'  '.3'    ->  '3.30'
addx6156 add '3'     '3'     ->  '6'
addx6157 add '3'     '+3'    ->  '6'
addx6158 add '3'     '-3'    ->  '0'
addx6159 add '0.3'   '-0.3'  ->  '0.0'
addx6160 add '0.03'  '-0.03' ->  '0.00'

-- try borderline precision, with carries, etc.
addx6161 add '1E+13' '-1'    -> '9999999999999'
addx6162 add '1E+13'  '1.11' -> '10000000000001.11'
addx6163 add '1.11'  '1E+13' -> '10000000000001.11'
addx6164 add '-1'    '1E+13' -> '9999999999999'
addx6165 add '7E+13' '-1'    -> '69999999999999'
addx6166 add '7E+13'  '1.11' -> '70000000000001.11'
addx6167 add '1.11'  '7E+13' -> '70000000000001.11'
addx6168 add '-1'    '7E+13' -> '69999999999999'

--             1234567890123456      1234567890123456      1 234567890123456
addx6170 add '0.4444444444444444'  '0.5555555555555563' -> '1.000000000000001' Inexact Rounded
addx6171 add '0.4444444444444444'  '0.5555555555555562' -> '1.000000000000001' Inexact Rounded
addx6172 add '0.4444444444444444'  '0.5555555555555561' -> '1.000000000000000' Inexact Rounded
addx6173 add '0.4444444444444444'  '0.5555555555555560' -> '1.000000000000000' Inexact Rounded
addx6174 add '0.4444444444444444'  '0.5555555555555559' -> '1.000000000000000' Inexact Rounded
addx6175 add '0.4444444444444444'  '0.5555555555555558' -> '1.000000000000000' Inexact Rounded
addx6176 add '0.4444444444444444'  '0.5555555555555557' -> '1.000000000000000' Inexact Rounded
addx6177 add '0.4444444444444444'  '0.5555555555555556' -> '1.000000000000000' Rounded
addx6178 add '0.4444444444444444'  '0.5555555555555555' -> '0.9999999999999999'
addx6179 add '0.4444444444444444'  '0.5555555555555554' -> '0.9999999999999998'
addx6180 add '0.4444444444444444'  '0.5555555555555553' -> '0.9999999999999997'
addx6181 add '0.4444444444444444'  '0.5555555555555552' -> '0.9999999999999996'
addx6182 add '0.4444444444444444'  '0.5555555555555551' -> '0.9999999999999995'
addx6183 add '0.4444444444444444'  '0.5555555555555550' -> '0.9999999999999994'

-- and some more, including residue effects and different roundings
rounding: half_up
addx6200 add '6543210123456789' 0             -> '6543210123456789'
addx6201 add '6543210123456789' 0.000000001   -> '6543210123456789' Inexact Rounded
addx6202 add '6543210123456789' 0.000001      -> '6543210123456789' Inexact Rounded
addx6203 add '6543210123456789' 0.1           -> '6543210123456789' Inexact Rounded
addx6204 add '6543210123456789' 0.4           -> '6543210123456789' Inexact Rounded
addx6205 add '6543210123456789' 0.49          -> '6543210123456789' Inexact Rounded
addx6206 add '6543210123456789' 0.499999      -> '6543210123456789' Inexact Rounded
addx6207 add '6543210123456789' 0.499999999   -> '6543210123456789' Inexact Rounded
addx6208 add '6543210123456789' 0.5           -> '6543210123456790' Inexact Rounded
addx6209 add '6543210123456789' 0.500000001   -> '6543210123456790' Inexact Rounded
addx6210 add '6543210123456789' 0.500001      -> '6543210123456790' Inexact Rounded
addx6211 add '6543210123456789' 0.51          -> '6543210123456790' Inexact Rounded
addx6212 add '6543210123456789' 0.6           -> '6543210123456790' Inexact Rounded
addx6213 add '6543210123456789' 0.9           -> '6543210123456790' Inexact Rounded
addx6214 add '6543210123456789' 0.99999       -> '6543210123456790' Inexact Rounded
addx6215 add '6543210123456789' 0.999999999   -> '6543210123456790' Inexact Rounded
addx6216 add '6543210123456789' 1             -> '6543210123456790'
addx6217 add '6543210123456789' 1.000000001   -> '6543210123456790' Inexact Rounded
addx6218 add '6543210123456789' 1.00001       -> '6543210123456790' Inexact Rounded
addx6219 add '6543210123456789' 1.1           -> '6543210123456790' Inexact Rounded

rounding: half_even
addx6220 add '6543210123456789' 0             -> '6543210123456789'
addx6221 add '6543210123456789' 0.000000001   -> '6543210123456789' Inexact Rounded
addx6222 add '6543210123456789' 0.000001      -> '6543210123456789' Inexact Rounded
addx6223 add '6543210123456789' 0.1           -> '6543210123456789' Inexact Rounded
addx6224 add '6543210123456789' 0.4           -> '6543210123456789' Inexact Rounded
addx6225 add '6543210123456789' 0.49          -> '6543210123456789' Inexact Rounded
addx6226 add '6543210123456789' 0.499999      -> '6543210123456789' Inexact Rounded
addx6227 add '6543210123456789' 0.499999999   -> '6543210123456789' Inexact Rounded
addx6228 add '6543210123456789' 0.5           -> '6543210123456790' Inexact Rounded
addx6229 add '6543210123456789' 0.500000001   -> '6543210123456790' Inexact Rounded
addx6230 add '6543210123456789' 0.500001      -> '6543210123456790' Inexact Rounded
addx6231 add '6543210123456789' 0.51          -> '6543210123456790' Inexact Rounded
addx6232 add '6543210123456789' 0.6           -> '6543210123456790' Inexact Rounded
addx6233 add '6543210123456789' 0.9           -> '6543210123456790' Inexact Rounded
addx6234 add '6543210123456789' 0.99999       -> '6543210123456790' Inexact Rounded
addx6235 add '6543210123456789' 0.999999999   -> '6543210123456790' Inexact Rounded
addx6236 add '6543210123456789' 1             -> '6543210123456790'
addx6237 add '6543210123456789' 1.00000001    -> '6543210123456790' Inexact Rounded
addx6238 add '6543210123456789' 1.00001       -> '6543210123456790' Inexact Rounded
addx6239 add '6543210123456789' 1.1           -> '6543210123456790' Inexact Rounded
-- critical few with even bottom digit...
addx6240 add '6543210123456788' 0.499999999   -> '6543210123456788' Inexact Rounded
addx6241 add '6543210123456788' 0.5           -> '6543210123456788' Inexact Rounded
addx6242 add '6543210123456788' 0.500000001   -> '6543210123456789' Inexact Rounded

rounding: down
addx6250 add '6543210123456789' 0             -> '6543210123456789'
addx6251 add '6543210123456789' 0.000000001   -> '6543210123456789' Inexact Rounded
addx6252 add '6543210123456789' 0.000001      -> '6543210123456789' Inexact Rounded
addx6253 add '6543210123456789' 0.1           -> '6543210123456789' Inexact Rounded
addx6254 add '6543210123456789' 0.4           -> '6543210123456789' Inexact Rounded
addx6255 add '6543210123456789' 0.49          -> '6543210123456789' Inexact Rounded
addx6256 add '6543210123456789' 0.499999      -> '6543210123456789' Inexact Rounded
addx6257 add '6543210123456789' 0.499999999   -> '6543210123456789' Inexact Rounded
addx6258 add '6543210123456789' 0.5           -> '6543210123456789' Inexact Rounded
addx6259 add '6543210123456789' 0.500000001   -> '6543210123456789' Inexact Rounded
addx6260 add '6543210123456789' 0.500001      -> '6543210123456789' Inexact Rounded
addx6261 add '6543210123456789' 0.51          -> '6543210123456789' Inexact Rounded
addx6262 add '6543210123456789' 0.6           -> '6543210123456789' Inexact Rounded
addx6263 add '6543210123456789' 0.9           -> '6543210123456789' Inexact Rounded
addx6264 add '6543210123456789' 0.99999       -> '6543210123456789' Inexact Rounded
addx6265 add '6543210123456789' 0.999999999   -> '6543210123456789' Inexact Rounded
addx6266 add '6543210123456789' 1             -> '6543210123456790'
addx6267 add '6543210123456789' 1.00000001    -> '6543210123456790' Inexact Rounded
addx6268 add '6543210123456789' 1.00001       -> '6543210123456790' Inexact Rounded
addx6269 add '6543210123456789' 1.1           -> '6543210123456790' Inexact Rounded

-- 1 in last place tests
rounding: half_even
addx6301 add  -1   1      ->   0
addx6302 add   0   1      ->   1
addx6303 add   1   1      ->   2
addx6304 add  12   1      ->  13
addx6305 add  98   1      ->  99
addx6306 add  99   1      -> 100
addx6307 add 100   1      -> 101
addx6308 add 101   1      -> 102
addx6309 add  -1  -1      ->  -2
addx6310 add   0  -1      ->  -1
addx6311 add   1  -1      ->   0
addx6312 add  12  -1      ->  11
addx6313 add  98  -1      ->  97
addx6314 add  99  -1      ->  98
addx6315 add 100  -1      ->  99
addx6316 add 101  -1      -> 100

addx6321 add -0.01  0.01    ->  0.00
addx6322 add  0.00  0.01    ->  0.01
addx6323 add  0.01  0.01    ->  0.02
addx6324 add  0.12  0.01    ->  0.13
addx6325 add  0.98  0.01    ->  0.99
addx6326 add  0.99  0.01    ->  1.00
addx6327 add  1.00  0.01    ->  1.01
addx6328 add  1.01  0.01    ->  1.02
addx6329 add -0.01 -0.01    -> -0.02
addx6330 add  0.00 -0.01    -> -0.01
addx6331 add  0.01 -0.01    ->  0.00
addx6332 add  0.12 -0.01    ->  0.11
addx6333 add  0.98 -0.01    ->  0.97
addx6334 add  0.99 -0.01    ->  0.98
addx6335 add  1.00 -0.01    ->  0.99
addx6336 add  1.01 -0.01    ->  1.00

-- some more cases where adding 0 affects the coefficient
addx6340 add 1E+3    0    ->         1000
addx6341 add 1E+15   0    ->    1000000000000000
addx6342 add 1E+16   0    ->   1.000000000000000E+16  Rounded
addx6343 add 1E+17   0    ->   1.000000000000000E+17  Rounded
-- which simply follow from these cases ...
addx6344 add 1E+3    1    ->         1001
addx6345 add 1E+15   1    ->    1000000000000001
addx6346 add 1E+16   1    ->   1.000000000000000E+16  Inexact Rounded
addx6347 add 1E+17   1    ->   1.000000000000000E+17  Inexact Rounded
addx6348 add 1E+3    7    ->         1007
addx6349 add 1E+15   7    ->    1000000000000007
addx6350 add 1E+16   7    ->   1.000000000000001E+16  Inexact Rounded
addx6351 add 1E+17   7    ->   1.000000000000000E+17  Inexact Rounded

-- tryzeros cases
addx6361  add 0E+50 10000E+1  -> 1.0000E+5
addx6362  add 10000E+1 0E-50  -> 100000.0000000000  Rounded
addx6363  add 10000E+1 10000E-50  -> 100000.0000000000  Rounded Inexact
addx6364  add 12.34    0e-398  -> 12.34000000000000  Rounded

-- ulp replacement tests
addx6400 add   1   77e-14      ->  1.00000000000077
addx6401 add   1   77e-15      ->  1.000000000000077
addx6402 add   1   77e-16      ->  1.000000000000008 Inexact Rounded
addx6403 add   1   77e-17      ->  1.000000000000001 Inexact Rounded
addx6404 add   1   77e-18      ->  1.000000000000000 Inexact Rounded
addx6405 add   1   77e-19      ->  1.000000000000000 Inexact Rounded
addx6406 add   1   77e-99      ->  1.000000000000000 Inexact Rounded

addx6410 add  10   77e-14      ->  10.00000000000077
addx6411 add  10   77e-15      ->  10.00000000000008 Inexact Rounded
addx6412 add  10   77e-16      ->  10.00000000000001 Inexact Rounded
addx6413 add  10   77e-17      ->  10.00000000000000 Inexact Rounded
addx6414 add  10   77e-18      ->  10.00000000000000 Inexact Rounded
addx6415 add  10   77e-19      ->  10.00000000000000 Inexact Rounded
addx6416 add  10   77e-99      ->  10.00000000000000 Inexact Rounded

addx6420 add  77e-14       1   ->  1.00000000000077
addx6421 add  77e-15       1   ->  1.000000000000077
addx6422 add  77e-16       1   ->  1.000000000000008 Inexact Rounded
addx6423 add  77e-17       1   ->  1.000000000000001 Inexact Rounded
addx6424 add  77e-18       1   ->  1.000000000000000 Inexact Rounded
addx6425 add  77e-19       1   ->  1.000000000000000 Inexact Rounded
addx6426 add  77e-99       1   ->  1.000000000000000 Inexact Rounded

addx6430 add  77e-14      10   ->  10.00000000000077
addx6431 add  77e-15      10   ->  10.00000000000008 Inexact Rounded
addx6432 add  77e-16      10   ->  10.00000000000001 Inexact Rounded
addx6433 add  77e-17      10   ->  10.00000000000000 Inexact Rounded
addx6434 add  77e-18      10   ->  10.00000000000000 Inexact Rounded
addx6435 add  77e-19      10   ->  10.00000000000000 Inexact Rounded
addx6436 add  77e-99      10   ->  10.00000000000000 Inexact Rounded

-- negative ulps
addx6440 add   1   -77e-14      ->  0.99999999999923
addx6441 add   1   -77e-15      ->  0.999999999999923
addx6442 add   1   -77e-16      ->  0.9999999999999923
addx6443 add   1   -77e-17      ->  0.9999999999999992 Inexact Rounded
addx6444 add   1   -77e-18      ->  0.9999999999999999 Inexact Rounded
addx6445 add   1   -77e-19      ->  1.000000000000000 Inexact Rounded
addx6446 add   1   -77e-99      ->  1.000000000000000 Inexact Rounded

addx6450 add  10   -77e-14      ->   9.99999999999923
addx6451 add  10   -77e-15      ->   9.999999999999923
addx6452 add  10   -77e-16      ->   9.999999999999992 Inexact Rounded
addx6453 add  10   -77e-17      ->   9.999999999999999 Inexact Rounded
addx6454 add  10   -77e-18      ->  10.00000000000000 Inexact Rounded
addx6455 add  10   -77e-19      ->  10.00000000000000 Inexact Rounded
addx6456 add  10   -77e-99      ->  10.00000000000000 Inexact Rounded

addx6460 add  -77e-14       1   ->  0.99999999999923
addx6461 add  -77e-15       1   ->  0.999999999999923
addx6462 add  -77e-16       1   ->  0.9999999999999923
addx6463 add  -77e-17       1   ->  0.9999999999999992 Inexact Rounded
addx6464 add  -77e-18       1   ->  0.9999999999999999 Inexact Rounded
addx6465 add  -77e-19       1   ->  1.000000000000000 Inexact Rounded
addx6466 add  -77e-99       1   ->  1.000000000000000 Inexact Rounded

addx6470 add  -77e-14      10   ->   9.99999999999923
addx6471 add  -77e-15      10   ->   9.999999999999923
addx6472 add  -77e-16      10   ->   9.999999999999992 Inexact Rounded
addx6473 add  -77e-17      10   ->   9.999999999999999 Inexact Rounded
addx6474 add  -77e-18      10   ->  10.00000000000000 Inexact Rounded
addx6475 add  -77e-19      10   ->  10.00000000000000 Inexact Rounded
addx6476 add  -77e-99      10   ->  10.00000000000000 Inexact Rounded

-- negative ulps
addx6480 add  -1    77e-14      ->  -0.99999999999923
addx6481 add  -1    77e-15      ->  -0.999999999999923
addx6482 add  -1    77e-16      ->  -0.9999999999999923
addx6483 add  -1    77e-17      ->  -0.9999999999999992 Inexact Rounded
addx6484 add  -1    77e-18      ->  -0.9999999999999999 Inexact Rounded
addx6485 add  -1    77e-19      ->  -1.000000000000000 Inexact Rounded
addx6486 add  -1    77e-99      ->  -1.000000000000000 Inexact Rounded

addx6490 add -10    77e-14      ->   -9.99999999999923
addx6491 add -10    77e-15      ->   -9.999999999999923
addx6492 add -10    77e-16      ->   -9.999999999999992 Inexact Rounded
addx6493 add -10    77e-17      ->   -9.999999999999999 Inexact Rounded
addx6494 add -10    77e-18      ->  -10.00000000000000 Inexact Rounded
addx6495 add -10    77e-19      ->  -10.00000000000000 Inexact Rounded
addx6496 add -10    77e-99      ->  -10.00000000000000 Inexact Rounded

addx6500 add   77e-14      -1   ->  -0.99999999999923
addx6501 add   77e-15      -1   ->  -0.999999999999923
addx6502 add   77e-16      -1   ->  -0.9999999999999923
addx6503 add   77e-17      -1   ->  -0.9999999999999992 Inexact Rounded
addx6504 add   77e-18      -1   ->  -0.9999999999999999 Inexact Rounded
addx6505 add   77e-19      -1   ->  -1.000000000000000 Inexact Rounded
addx6506 add   77e-99      -1   ->  -1.000000000000000 Inexact Rounded

addx6510 add   77e-14      -10  ->   -9.99999999999923
addx6511 add   77e-15      -10  ->   -9.999999999999923
addx6512 add   77e-16      -10  ->   -9.999999999999992 Inexact Rounded
addx6513 add   77e-17      -10  ->   -9.999999999999999 Inexact Rounded
addx6514 add   77e-18      -10  ->  -10.00000000000000 Inexact Rounded
addx6515 add   77e-19      -10  ->  -10.00000000000000 Inexact Rounded
addx6516 add   77e-99      -10  ->  -10.00000000000000 Inexact Rounded


-- long operands
addx6521 add 101234562345678000 0 -> 1.012345623456780E+17 Rounded
addx6522 add 0 101234562345678000 -> 1.012345623456780E+17 Rounded
addx6523 add 10123456234567800  0 -> 1.012345623456780E+16 Rounded
addx6524 add 0 10123456234567800  -> 1.012345623456780E+16 Rounded
addx6525 add 10123456234567890  0 -> 1.012345623456789E+16 Rounded
addx6526 add 0 10123456234567890  -> 1.012345623456789E+16 Rounded
addx6527 add 10123456234567891  0 -> 1.012345623456789E+16 Inexact Rounded
addx6528 add 0 10123456234567891  -> 1.012345623456789E+16 Inexact Rounded
addx6529 add 101234562345678901 0 -> 1.012345623456789E+17 Inexact Rounded
addx6530 add 0 101234562345678901 -> 1.012345623456789E+17 Inexact Rounded
addx6531 add 10123456234567896  0 -> 1.012345623456790E+16 Inexact Rounded
addx6532 add 0 10123456234567896  -> 1.012345623456790E+16 Inexact Rounded

-- verify a query
rounding:     down
addx6561 add 1e-398 9.000000000000000E+384 -> 9.000000000000000E+384 Inexact Rounded
addx6562 add      0 9.000000000000000E+384 -> 9.000000000000000E+384 Rounded
-- and using decimal64 bounds...
rounding:     down
addx6563 add 1e-388 9.000000000000000E+374 -> 9.000000000000000E+374 Inexact Rounded
addx6564 add      0 9.000000000000000E+374 -> 9.000000000000000E+374 Rounded

-- more zeros, etc.
rounding: half_even

addx6701 add 5.00 1.00E-3 -> 5.00100
addx6702 add 00.00 0.000  -> 0.000
addx6703 add 00.00 0E-3   -> 0.000
addx6704 add 0E-3  00.00  -> 0.000

addx6710 add 0E+3  00.00  -> 0.00
addx6711 add 0E+3  00.0   -> 0.0
addx6712 add 0E+3  00.    -> 0
addx6713 add 0E+3  00.E+1 -> 0E+1
addx6714 add 0E+3  00.E+2 -> 0E+2
addx6715 add 0E+3  00.E+3 -> 0E+3
addx6716 add 0E+3  00.E+4 -> 0E+3
addx6717 add 0E+3  00.E+5 -> 0E+3
addx6718 add 0E+3  -00.0   -> 0.0
addx6719 add 0E+3  -00.    -> 0
addx6731 add 0E+3  -00.E+1 -> 0E+1

addx6720 add 00.00  0E+3  -> 0.00
addx6721 add 00.0   0E+3  -> 0.0
addx6722 add 00.    0E+3  -> 0
addx6723 add 00.E+1 0E+3  -> 0E+1
addx6724 add 00.E+2 0E+3  -> 0E+2
addx6725 add 00.E+3 0E+3  -> 0E+3
addx6726 add 00.E+4 0E+3  -> 0E+3
addx6727 add 00.E+5 0E+3  -> 0E+3
addx6728 add -00.00 0E+3  -> 0.00
addx6729 add -00.0  0E+3  -> 0.0
addx6730 add -00.   0E+3  -> 0

addx6732 add  0     0     ->  0
addx6733 add  0    -0     ->  0
addx6734 add -0     0     ->  0
addx6735 add -0    -0     -> -0     -- IEEE 854 special case

addx6736 add  1    -1     ->  0
addx6737 add -1    -1     -> -2
addx6738 add  1     1     ->  2
addx6739 add -1     1     ->  0

addx6741 add  0    -1     -> -1
addx6742 add -0    -1     -> -1
addx6743 add  0     1     ->  1
addx6744 add -0     1     ->  1
addx6745 add -1     0     -> -1
addx6746 add -1    -0     -> -1
addx6747 add  1     0     ->  1
addx6748 add  1    -0     ->  1

addx6751 add  0.0  -1     -> -1.0
addx6752 add -0.0  -1     -> -1.0
addx6753 add  0.0   1     ->  1.0
addx6754 add -0.0   1     ->  1.0
addx6755 add -1.0   0     -> -1.0
addx6756 add -1.0  -0     -> -1.0
addx6757 add  1.0   0     ->  1.0
addx6758 add  1.0  -0     ->  1.0

addx6761 add  0    -1.0   -> -1.0
addx6762 add -0    -1.0   -> -1.0
addx6763 add  0     1.0   ->  1.0
addx6764 add -0     1.0   ->  1.0
addx6765 add -1     0.0   -> -1.0
addx6766 add -1    -0.0   -> -1.0
addx6767 add  1     0.0   ->  1.0
addx6768 add  1    -0.0   ->  1.0

addx6771 add  0.0  -1.0   -> -1.0
addx6772 add -0.0  -1.0   -> -1.0
addx6773 add  0.0   1.0   ->  1.0
addx6774 add -0.0   1.0   ->  1.0
addx6775 add -1.0   0.0   -> -1.0
addx6776 add -1.0  -0.0   -> -1.0
addx6777 add  1.0   0.0   ->  1.0
addx6778 add  1.0  -0.0   ->  1.0

-- Specials
addx6780 add -Inf  -Inf   -> -Infinity
addx6781 add -Inf  -1000  -> -Infinity
addx6782 add -Inf  -1     -> -Infinity
addx6783 add -Inf  -0     -> -Infinity
addx6784 add -Inf   0     -> -Infinity
addx6785 add -Inf   1     -> -Infinity
addx6786 add -Inf   1000  -> -Infinity
addx6787 add -1000 -Inf   -> -Infinity
addx6788 add -Inf  -Inf   -> -Infinity
addx6789 add -1    -Inf   -> -Infinity
addx6790 add -0    -Inf   -> -Infinity
addx6791 add  0    -Inf   -> -Infinity
addx6792 add  1    -Inf   -> -Infinity
addx6793 add  1000 -Inf   -> -Infinity
addx6794 add  Inf  -Inf   ->  NaN  Invalid_operation

addx6800 add  Inf  -Inf   ->  NaN  Invalid_operation
addx6801 add  Inf  -1000  ->  Infinity
addx6802 add  Inf  -1     ->  Infinity
addx6803 add  Inf  -0     ->  Infinity
addx6804 add  Inf   0     ->  Infinity
addx6805 add  Inf   1     ->  Infinity
addx6806 add  Inf   1000  ->  Infinity
addx6807 add  Inf   Inf   ->  Infinity
addx6808 add -1000  Inf   ->  Infinity
addx6809 add -Inf   Inf   ->  NaN  Invalid_operation
addx6810 add -1     Inf   ->  Infinity
addx6811 add -0     Inf   ->  Infinity
addx6812 add  0     Inf   ->  Infinity
addx6813 add  1     Inf   ->  Infinity
addx6814 add  1000  Inf   ->  Infinity
addx6815 add  Inf   Inf   ->  Infinity

addx6821 add  NaN -Inf    ->  NaN
addx6822 add  NaN -1000   ->  NaN
addx6823 add  NaN -1      ->  NaN
addx6824 add  NaN -0      ->  NaN
addx6825 add  NaN  0      ->  NaN
addx6826 add  NaN  1      ->  NaN
addx6827 add  NaN  1000   ->  NaN
addx6828 add  NaN  Inf    ->  NaN
addx6829 add  NaN  NaN    ->  NaN
addx6830 add -Inf  NaN    ->  NaN
addx6831 add -1000 NaN    ->  NaN
addx6832 add -1    NaN    ->  NaN
addx6833 add -0    NaN    ->  NaN
addx6834 add  0    NaN    ->  NaN
addx6835 add  1    NaN    ->  NaN
addx6836 add  1000 NaN    ->  NaN
addx6837 add  Inf  NaN    ->  NaN

addx6841 add  sNaN -Inf   ->  NaN  Invalid_operation
addx6842 add  sNaN -1000  ->  NaN  Invalid_operation
addx6843 add  sNaN -1     ->  NaN  Invalid_operation
addx6844 add  sNaN -0     ->  NaN  Invalid_operation
addx6845 add  sNaN  0     ->  NaN  Invalid_operation
addx6846 add  sNaN  1     ->  NaN  Invalid_operation
addx6847 add  sNaN  1000  ->  NaN  Invalid_operation
addx6848 add  sNaN  NaN   ->  NaN  Invalid_operation
addx6849 add  sNaN sNaN   ->  NaN  Invalid_operation
addx6850 add  NaN  sNaN   ->  NaN  Invalid_operation
addx6851 add -Inf  sNaN   ->  NaN  Invalid_operation
addx6852 add -1000 sNaN   ->  NaN  Invalid_operation
addx6853 add -1    sNaN   ->  NaN  Invalid_operation
addx6854 add -0    sNaN   ->  NaN  Invalid_operation
addx6855 add  0    sNaN   ->  NaN  Invalid_operation
addx6856 add  1    sNaN   ->  NaN  Invalid_operation
addx6857 add  1000 sNaN   ->  NaN  Invalid_operation
addx6858 add  Inf  sNaN   ->  NaN  Invalid_operation
addx6859 add  NaN  sNaN   ->  NaN  Invalid_operation

-- propagating NaNs
addx6861 add  NaN1   -Inf    ->  NaN1
addx6862 add +NaN2   -1000   ->  NaN2
addx6863 add  NaN3    1000   ->  NaN3
addx6864 add  NaN4    Inf    ->  NaN4
addx6865 add  NaN5   +NaN6   ->  NaN5
addx6866 add -Inf     NaN7   ->  NaN7
addx6867 add -1000    NaN8   ->  NaN8
addx6868 add  1000    NaN9   ->  NaN9
addx6869 add  Inf    +NaN10  ->  NaN10
addx6871 add  sNaN11  -Inf   ->  NaN11  Invalid_operation
addx6872 add  sNaN12  -1000  ->  NaN12  Invalid_operation
addx6873 add  sNaN13   1000  ->  NaN13  Invalid_operation
addx6874 add  sNaN14   NaN17 ->  NaN14  Invalid_operation
addx6875 add  sNaN15  sNaN18 ->  NaN15  Invalid_operation
addx6876 add  NaN16   sNaN19 ->  NaN19  Invalid_operation
addx6877 add -Inf    +sNaN20 ->  NaN20  Invalid_operation
addx6878 add -1000    sNaN21 ->  NaN21  Invalid_operation
addx6879 add  1000    sNaN22 ->  NaN22  Invalid_operation
addx6880 add  Inf     sNaN23 ->  NaN23  Invalid_operation
addx6881 add +NaN25  +sNaN24 ->  NaN24  Invalid_operation
addx6882 add -NaN26    NaN28 -> -NaN26
addx6883 add -sNaN27  sNaN29 -> -NaN27  Invalid_operation
addx6884 add  1000    -NaN30 -> -NaN30
addx6885 add  1000   -sNaN31 -> -NaN31  Invalid_operation

-- now the case where we can get underflow but the result is normal
-- [note this can't happen if the operands are also bounded, as we
-- cannot represent 1E-399, for example]

addx6571 add       1E-383       0  -> 1E-383
addx6572 add       1E-384       0  -> 1E-384   Subnormal
addx6573 add       1E-383  1E-384  -> 1.1E-383
addx6574 subtract  1E-383  1E-384  ->   9E-384 Subnormal

-- Here we explore the boundary of rounding a subnormal to Nmin
addx6575 subtract  1E-383  1E-398  ->   9.99999999999999E-384  Subnormal
addx6576 subtract  1E-383  1E-398  ->   9.99999999999999E-384  Subnormal
addx6577 subtract  1E-383  1E-399  ->   1.000000000000000E-383 Underflow Inexact Subnormal Rounded
addx6578 subtract  1E-383  1E-400  ->   1.000000000000000E-383 Underflow Inexact Subnormal Rounded
addx6579 subtract  1E-383  1E-401  ->   1.000000000000000E-383 Underflow Inexact Subnormal Rounded
addx6580 subtract  1E-383  1E-402  ->   1.000000000000000E-383 Underflow Inexact Subnormal Rounded

-- check overflow edge case
--               1234567890123456
addx6972 apply   9.999999999999999E+384         -> 9.999999999999999E+384
addx6973 add     9.999999999999999E+384  1      -> 9.999999999999999E+384 Inexact Rounded
addx6974 add      9999999999999999E+369  1      -> 9.999999999999999E+384 Inexact Rounded
addx6975 add      9999999999999999E+369  1E+369  -> Infinity Overflow Inexact Rounded
addx6976 add      9999999999999999E+369  9E+368  -> Infinity Overflow Inexact Rounded
addx6977 add      9999999999999999E+369  8E+368  -> Infinity Overflow Inexact Rounded
addx6978 add      9999999999999999E+369  7E+368  -> Infinity Overflow Inexact Rounded
addx6979 add      9999999999999999E+369  6E+368  -> Infinity Overflow Inexact Rounded
addx6980 add      9999999999999999E+369  5E+368  -> Infinity Overflow Inexact Rounded
addx6981 add      9999999999999999E+369  4E+368  -> 9.999999999999999E+384 Inexact Rounded
addx6982 add      9999999999999999E+369  3E+368  -> 9.999999999999999E+384 Inexact Rounded
addx6983 add      9999999999999999E+369  2E+368  -> 9.999999999999999E+384 Inexact Rounded
addx6984 add      9999999999999999E+369  1E+368  -> 9.999999999999999E+384 Inexact Rounded

addx6985 apply  -9.999999999999999E+384         -> -9.999999999999999E+384
addx6986 add    -9.999999999999999E+384 -1      -> -9.999999999999999E+384 Inexact Rounded
addx6987 add     -9999999999999999E+369 -1      -> -9.999999999999999E+384 Inexact Rounded
addx6988 add     -9999999999999999E+369 -1E+369  -> -Infinity Overflow Inexact Rounded
addx6989 add     -9999999999999999E+369 -9E+368  -> -Infinity Overflow Inexact Rounded
addx6990 add     -9999999999999999E+369 -8E+368  -> -Infinity Overflow Inexact Rounded
addx6991 add     -9999999999999999E+369 -7E+368  -> -Infinity Overflow Inexact Rounded
addx6992 add     -9999999999999999E+369 -6E+368  -> -Infinity Overflow Inexact Rounded
addx6993 add     -9999999999999999E+369 -5E+368  -> -Infinity Overflow Inexact Rounded
addx6994 add     -9999999999999999E+369 -4E+368  -> -9.999999999999999E+384 Inexact Rounded
addx6995 add     -9999999999999999E+369 -3E+368  -> -9.999999999999999E+384 Inexact Rounded
addx6996 add     -9999999999999999E+369 -2E+368  -> -9.999999999999999E+384 Inexact Rounded
addx6997 add     -9999999999999999E+369 -1E+368  -> -9.999999999999999E+384 Inexact Rounded

-- And for round down full and subnormal results
rounding:     down
addx61100 add 1e+2 -1e-383    -> 99.99999999999999 Rounded Inexact
addx61101 add 1e+1 -1e-383    -> 9.999999999999999  Rounded Inexact
addx61103 add   +1 -1e-383    -> 0.9999999999999999  Rounded Inexact
addx61104 add 1e-1 -1e-383    -> 0.09999999999999999  Rounded Inexact
addx61105 add 1e-2 -1e-383    -> 0.009999999999999999  Rounded Inexact
addx61106 add 1e-3 -1e-383    -> 0.0009999999999999999  Rounded Inexact
addx61107 add 1e-4 -1e-383    -> 0.00009999999999999999  Rounded Inexact
addx61108 add 1e-5 -1e-383    -> 0.000009999999999999999  Rounded Inexact
addx61109 add 1e-6 -1e-383    -> 9.999999999999999E-7  Rounded Inexact

rounding:     ceiling
addx61110 add -1e+2 +1e-383   -> -99.99999999999999 Rounded Inexact
addx61111 add -1e+1 +1e-383   -> -9.999999999999999  Rounded Inexact
addx61113 add    -1 +1e-383   -> -0.9999999999999999  Rounded Inexact
addx61114 add -1e-1 +1e-383   -> -0.09999999999999999  Rounded Inexact
addx61115 add -1e-2 +1e-383   -> -0.009999999999999999  Rounded Inexact
addx61116 add -1e-3 +1e-383   -> -0.0009999999999999999  Rounded Inexact
addx61117 add -1e-4 +1e-383   -> -0.00009999999999999999  Rounded Inexact
addx61118 add -1e-5 +1e-383   -> -0.000009999999999999999  Rounded Inexact
addx61119 add -1e-6 +1e-383   -> -9.999999999999999E-7  Rounded Inexact

-- tests based on Gunnar Degnbol's edge case
rounding:     half_even

addx61300 add 1E16  -0.5                 ->  1.000000000000000E+16 Inexact Rounded
addx61310 add 1E16  -0.51                ->  9999999999999999      Inexact Rounded
addx61311 add 1E16  -0.501               ->  9999999999999999      Inexact Rounded
addx61312 add 1E16  -0.5001              ->  9999999999999999      Inexact Rounded
addx61313 add 1E16  -0.50001             ->  9999999999999999      Inexact Rounded
addx61314 add 1E16  -0.500001            ->  9999999999999999      Inexact Rounded
addx61315 add 1E16  -0.5000001           ->  9999999999999999      Inexact Rounded
addx61316 add 1E16  -0.50000001          ->  9999999999999999      Inexact Rounded
addx61317 add 1E16  -0.500000001         ->  9999999999999999      Inexact Rounded
addx61318 add 1E16  -0.5000000001        ->  9999999999999999      Inexact Rounded
addx61319 add 1E16  -0.50000000001       ->  9999999999999999      Inexact Rounded
addx61320 add 1E16  -0.500000000001      ->  9999999999999999      Inexact Rounded
addx61321 add 1E16  -0.5000000000001     ->  9999999999999999      Inexact Rounded
addx61322 add 1E16  -0.50000000000001    ->  9999999999999999      Inexact Rounded
addx61323 add 1E16  -0.500000000000001   ->  9999999999999999      Inexact Rounded
addx61324 add 1E16  -0.5000000000000001  ->  9999999999999999      Inexact Rounded
addx61325 add 1E16  -0.5000000000000000  ->  1.000000000000000E+16 Inexact Rounded
addx61326 add 1E16  -0.500000000000000   ->  1.000000000000000E+16 Inexact Rounded
addx61327 add 1E16  -0.50000000000000    ->  1.000000000000000E+16 Inexact Rounded
addx61328 add 1E16  -0.5000000000000     ->  1.000000000000000E+16 Inexact Rounded
addx61329 add 1E16  -0.500000000000      ->  1.000000000000000E+16 Inexact Rounded
addx61330 add 1E16  -0.50000000000       ->  1.000000000000000E+16 Inexact Rounded
addx61331 add 1E16  -0.5000000000        ->  1.000000000000000E+16 Inexact Rounded
addx61332 add 1E16  -0.500000000         ->  1.000000000000000E+16 Inexact Rounded
addx61333 add 1E16  -0.50000000          ->  1.000000000000000E+16 Inexact Rounded
addx61334 add 1E16  -0.5000000           ->  1.000000000000000E+16 Inexact Rounded
addx61335 add 1E16  -0.500000            ->  1.000000000000000E+16 Inexact Rounded
addx61336 add 1E16  -0.50000             ->  1.000000000000000E+16 Inexact Rounded
addx61337 add 1E16  -0.5000              ->  1.000000000000000E+16 Inexact Rounded
addx61338 add 1E16  -0.500               ->  1.000000000000000E+16 Inexact Rounded
addx61339 add 1E16  -0.50                ->  1.000000000000000E+16 Inexact Rounded

addx61340 add 1E16  -5000000.000010001   ->  9999999995000000      Inexact Rounded
addx61341 add 1E16  -5000000.000000001   ->  9999999995000000      Inexact Rounded

addx61349 add 9999999999999999 0.4                 ->  9999999999999999      Inexact Rounded
addx61350 add 9999999999999999 0.49                ->  9999999999999999      Inexact Rounded
addx61351 add 9999999999999999 0.499               ->  9999999999999999      Inexact Rounded
addx61352 add 9999999999999999 0.4999              ->  9999999999999999      Inexact Rounded
addx61353 add 9999999999999999 0.49999             ->  9999999999999999      Inexact Rounded
addx61354 add 9999999999999999 0.499999            ->  9999999999999999      Inexact Rounded
addx61355 add 9999999999999999 0.4999999           ->  9999999999999999      Inexact Rounded
addx61356 add 9999999999999999 0.49999999          ->  9999999999999999      Inexact Rounded
addx61357 add 9999999999999999 0.499999999         ->  9999999999999999      Inexact Rounded
addx61358 add 9999999999999999 0.4999999999        ->  9999999999999999      Inexact Rounded
addx61359 add 9999999999999999 0.49999999999       ->  9999999999999999      Inexact Rounded
addx61360 add 9999999999999999 0.499999999999      ->  9999999999999999      Inexact Rounded
addx61361 add 9999999999999999 0.4999999999999     ->  9999999999999999      Inexact Rounded
addx61362 add 9999999999999999 0.49999999999999    ->  9999999999999999      Inexact Rounded
addx61363 add 9999999999999999 0.499999999999999   ->  9999999999999999      Inexact Rounded
addx61364 add 9999999999999999 0.4999999999999999  ->  9999999999999999      Inexact Rounded
addx61365 add 9999999999999999 0.5000000000000000  ->  1.000000000000000E+16 Inexact Rounded
addx61367 add 9999999999999999 0.500000000000000   ->  1.000000000000000E+16 Inexact Rounded
addx61368 add 9999999999999999 0.50000000000000    ->  1.000000000000000E+16 Inexact Rounded
addx61369 add 9999999999999999 0.5000000000000     ->  1.000000000000000E+16 Inexact Rounded
addx61370 add 9999999999999999 0.500000000000      ->  1.000000000000000E+16 Inexact Rounded
addx61371 add 9999999999999999 0.50000000000       ->  1.000000000000000E+16 Inexact Rounded
addx61372 add 9999999999999999 0.5000000000        ->  1.000000000000000E+16 Inexact Rounded
addx61373 add 9999999999999999 0.500000000         ->  1.000000000000000E+16 Inexact Rounded
addx61374 add 9999999999999999 0.50000000          ->  1.000000000000000E+16 Inexact Rounded
addx61375 add 9999999999999999 0.5000000           ->  1.000000000000000E+16 Inexact Rounded
addx61376 add 9999999999999999 0.500000            ->  1.000000000000000E+16 Inexact Rounded
addx61377 add 9999999999999999 0.50000             ->  1.000000000000000E+16 Inexact Rounded
addx61378 add 9999999999999999 0.5000              ->  1.000000000000000E+16 Inexact Rounded
addx61379 add 9999999999999999 0.500               ->  1.000000000000000E+16 Inexact Rounded
addx61380 add 9999999999999999 0.50                ->  1.000000000000000E+16 Inexact Rounded
addx61381 add 9999999999999999 0.5                 ->  1.000000000000000E+16 Inexact Rounded
addx61382 add 9999999999999999 0.5000000000000001  ->  1.000000000000000E+16 Inexact Rounded
addx61383 add 9999999999999999 0.500000000000001   ->  1.000000000000000E+16 Inexact Rounded
addx61384 add 9999999999999999 0.50000000000001    ->  1.000000000000000E+16 Inexact Rounded
addx61385 add 9999999999999999 0.5000000000001     ->  1.000000000000000E+16 Inexact Rounded
addx61386 add 9999999999999999 0.500000000001      ->  1.000000000000000E+16 Inexact Rounded
addx61387 add 9999999999999999 0.50000000001       ->  1.000000000000000E+16 Inexact Rounded
addx61388 add 9999999999999999 0.5000000001        ->  1.000000000000000E+16 Inexact Rounded
addx61389 add 9999999999999999 0.500000001         ->  1.000000000000000E+16 Inexact Rounded
addx61390 add 9999999999999999 0.50000001          ->  1.000000000000000E+16 Inexact Rounded
addx61391 add 9999999999999999 0.5000001           ->  1.000000000000000E+16 Inexact Rounded
addx61392 add 9999999999999999 0.500001            ->  1.000000000000000E+16 Inexact Rounded
addx61393 add 9999999999999999 0.50001             ->  1.000000000000000E+16 Inexact Rounded
addx61394 add 9999999999999999 0.5001              ->  1.000000000000000E+16 Inexact Rounded
addx61395 add 9999999999999999 0.501               ->  1.000000000000000E+16 Inexact Rounded
addx61396 add 9999999999999999 0.51                ->  1.000000000000000E+16 Inexact Rounded

-- More GD edge cases, where difference between the unadjusted
-- exponents is larger than the maximum precision and one side is 0
addx61420 add  0 1.123456789012345     -> 1.123456789012345
addx61421 add  0 1.123456789012345E-1  -> 0.1123456789012345
addx61422 add  0 1.123456789012345E-2  -> 0.01123456789012345
addx61423 add  0 1.123456789012345E-3  -> 0.001123456789012345
addx61424 add  0 1.123456789012345E-4  -> 0.0001123456789012345
addx61425 add  0 1.123456789012345E-5  -> 0.00001123456789012345
addx61426 add  0 1.123456789012345E-6  -> 0.000001123456789012345
addx61427 add  0 1.123456789012345E-7  -> 1.123456789012345E-7
addx61428 add  0 1.123456789012345E-8  -> 1.123456789012345E-8
addx61429 add  0 1.123456789012345E-9  -> 1.123456789012345E-9
addx61430 add  0 1.123456789012345E-10 -> 1.123456789012345E-10
addx61431 add  0 1.123456789012345E-11 -> 1.123456789012345E-11
addx61432 add  0 1.123456789012345E-12 -> 1.123456789012345E-12
addx61433 add  0 1.123456789012345E-13 -> 1.123456789012345E-13
addx61434 add  0 1.123456789012345E-14 -> 1.123456789012345E-14
addx61435 add  0 1.123456789012345E-15 -> 1.123456789012345E-15
addx61436 add  0 1.123456789012345E-16 -> 1.123456789012345E-16
addx61437 add  0 1.123456789012345E-17 -> 1.123456789012345E-17
addx61438 add  0 1.123456789012345E-18 -> 1.123456789012345E-18
addx61439 add  0 1.123456789012345E-19 -> 1.123456789012345E-19

-- same, reversed 0
addx61440 add 1.123456789012345     0 -> 1.123456789012345
addx61441 add 1.123456789012345E-1  0 -> 0.1123456789012345
addx61442 add 1.123456789012345E-2  0 -> 0.01123456789012345
addx61443 add 1.123456789012345E-3  0 -> 0.001123456789012345
addx61444 add 1.123456789012345E-4  0 -> 0.0001123456789012345
addx61445 add 1.123456789012345E-5  0 -> 0.00001123456789012345
addx61446 add 1.123456789012345E-6  0 -> 0.000001123456789012345
addx61447 add 1.123456789012345E-7  0 -> 1.123456789012345E-7
addx61448 add 1.123456789012345E-8  0 -> 1.123456789012345E-8
addx61449 add 1.123456789012345E-9  0 -> 1.123456789012345E-9
addx61450 add 1.123456789012345E-10 0 -> 1.123456789012345E-10
addx61451 add 1.123456789012345E-11 0 -> 1.123456789012345E-11
addx61452 add 1.123456789012345E-12 0 -> 1.123456789012345E-12
addx61453 add 1.123456789012345E-13 0 -> 1.123456789012345E-13
addx61454 add 1.123456789012345E-14 0 -> 1.123456789012345E-14
addx61455 add 1.123456789012345E-15 0 -> 1.123456789012345E-15
addx61456 add 1.123456789012345E-16 0 -> 1.123456789012345E-16
addx61457 add 1.123456789012345E-17 0 -> 1.123456789012345E-17
addx61458 add 1.123456789012345E-18 0 -> 1.123456789012345E-18
addx61459 add 1.123456789012345E-19 0 -> 1.123456789012345E-19

-- same, Es on the 0
addx61460 add 1.123456789012345  0E-0   -> 1.123456789012345
addx61461 add 1.123456789012345  0E-1   -> 1.123456789012345
addx61462 add 1.123456789012345  0E-2   -> 1.123456789012345
addx61463 add 1.123456789012345  0E-3   -> 1.123456789012345
addx61464 add 1.123456789012345  0E-4   -> 1.123456789012345
addx61465 add 1.123456789012345  0E-5   -> 1.123456789012345
addx61466 add 1.123456789012345  0E-6   -> 1.123456789012345
addx61467 add 1.123456789012345  0E-7   -> 1.123456789012345
addx61468 add 1.123456789012345  0E-8   -> 1.123456789012345
addx61469 add 1.123456789012345  0E-9   -> 1.123456789012345
addx61470 add 1.123456789012345  0E-10  -> 1.123456789012345
addx61471 add 1.123456789012345  0E-11  -> 1.123456789012345
addx61472 add 1.123456789012345  0E-12  -> 1.123456789012345
addx61473 add 1.123456789012345  0E-13  -> 1.123456789012345
addx61474 add 1.123456789012345  0E-14  -> 1.123456789012345
addx61475 add 1.123456789012345  0E-15  -> 1.123456789012345
-- next four flag Rounded because the 0 extends the result
addx61476 add 1.123456789012345  0E-16  -> 1.123456789012345 Rounded
addx61477 add 1.123456789012345  0E-17  -> 1.123456789012345 Rounded
addx61478 add 1.123456789012345  0E-18  -> 1.123456789012345 Rounded
addx61479 add 1.123456789012345  0E-19  -> 1.123456789012345 Rounded

-- sum of two opposite-sign operands is exactly 0 and floor => -0
rounding:    half_up
-- exact zeros from zeros
addx61500 add  0        0E-19  ->  0E-19
addx61501 add -0        0E-19  ->  0E-19
addx61502 add  0       -0E-19  ->  0E-19
addx61503 add -0       -0E-19  -> -0E-19
addx61504 add  0E-400   0E-19  ->  0E-398 Clamped
addx61505 add -0E-400   0E-19  ->  0E-398 Clamped
addx61506 add  0E-400  -0E-19  ->  0E-398 Clamped
addx61507 add -0E-400  -0E-19  -> -0E-398 Clamped
-- inexact zeros
addx61511 add  1E-401   1E-400 ->  0E-398 Subnormal Inexact Rounded Underflow Clamped
addx61512 add -1E-401   1E-400 ->  0E-398 Subnormal Inexact Rounded Underflow Clamped
addx61513 add  1E-401  -1E-400 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
addx61514 add -1E-401  -1E-400 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
-- some exact zeros from non-zeros
addx61515 add  1E-401   1E-401 ->  0E-398 Subnormal Inexact Rounded Underflow Clamped
addx61516 add -1E-401   1E-401 ->  0E-398 Clamped
addx61517 add  1E-401  -1E-401 ->  0E-398 Clamped
addx61518 add -1E-401  -1E-401 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped

rounding:    half_down
-- exact zeros from zeros
addx61520 add  0        0E-19  ->  0E-19
addx61521 add -0        0E-19  ->  0E-19
addx61522 add  0       -0E-19  ->  0E-19
addx61523 add -0       -0E-19  -> -0E-19
addx61524 add  0E-400   0E-19  ->  0E-398 Clamped
addx61525 add -0E-400   0E-19  ->  0E-398 Clamped
addx61526 add  0E-400  -0E-19  ->  0E-398 Clamped
addx61527 add -0E-400  -0E-19  -> -0E-398 Clamped
-- inexact zeros
addx61531 add  1E-401   1E-400 ->  0E-398 Subnormal Inexact Rounded Underflow Clamped
addx61532 add -1E-401   1E-400 ->  0E-398 Subnormal Inexact Rounded Underflow Clamped
addx61533 add  1E-401  -1E-400 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
addx61534 add -1E-401  -1E-400 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
-- some exact zeros from non-zeros
addx61535 add  1E-401   1E-401 ->  0E-398 Subnormal Inexact Rounded Underflow Clamped
addx61536 add -1E-401   1E-401 ->  0E-398 Clamped
addx61537 add  1E-401  -1E-401 ->  0E-398 Clamped
addx61538 add -1E-401  -1E-401 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped

rounding:    half_even
-- exact zeros from zeros
addx61540 add  0        0E-19  ->  0E-19
addx61541 add -0        0E-19  ->  0E-19
addx61542 add  0       -0E-19  ->  0E-19
addx61543 add -0       -0E-19  -> -0E-19
addx61544 add  0E-400   0E-19  ->  0E-398 Clamped
addx61545 add -0E-400   0E-19  ->  0E-398 Clamped
addx61546 add  0E-400  -0E-19  ->  0E-398 Clamped
addx61547 add -0E-400  -0E-19  -> -0E-398 Clamped
-- inexact zeros
addx61551 add  1E-401   1E-400 ->  0E-398 Subnormal Inexact Rounded Underflow Clamped
addx61552 add -1E-401   1E-400 ->  0E-398 Subnormal Inexact Rounded Underflow Clamped
addx61553 add  1E-401  -1E-400 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
addx61554 add -1E-401  -1E-400 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
-- some exact zeros from non-zeros
addx61555 add  1E-401   1E-401 ->  0E-398 Subnormal Inexact Rounded Underflow Clamped
addx61556 add -1E-401   1E-401 ->  0E-398 Clamped
addx61557 add  1E-401  -1E-401 ->  0E-398 Clamped
addx61558 add -1E-401  -1E-401 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped

rounding:    up
-- exact zeros from zeros
addx61560 add  0        0E-19  ->  0E-19
addx61561 add -0        0E-19  ->  0E-19
addx61562 add  0       -0E-19  ->  0E-19
addx61563 add -0       -0E-19  -> -0E-19
addx61564 add  0E-400   0E-19  ->  0E-398 Clamped
addx61565 add -0E-400   0E-19  ->  0E-398 Clamped
addx61566 add  0E-400  -0E-19  ->  0E-398 Clamped
addx61567 add -0E-400  -0E-19  -> -0E-398 Clamped
-- inexact zeros
addx61571 add  1E-401   1E-400 ->  1E-398 Subnormal Inexact Rounded Underflow
addx61572 add -1E-401   1E-400 ->  1E-398 Subnormal Inexact Rounded Underflow
addx61573 add  1E-401  -1E-400 -> -1E-398 Subnormal Inexact Rounded Underflow
addx61574 add -1E-401  -1E-400 -> -1E-398 Subnormal Inexact Rounded Underflow
-- some exact zeros from non-zeros
addx61575 add  1E-401   1E-401 ->  1E-398 Subnormal Inexact Rounded Underflow
addx61576 add -1E-401   1E-401 ->  0E-398 Clamped
addx61577 add  1E-401  -1E-401 ->  0E-398 Clamped
addx61578 add -1E-401  -1E-401 -> -1E-398 Subnormal Inexact Rounded Underflow

rounding:    down
-- exact zeros from zeros
addx61580 add  0        0E-19  ->  0E-19
addx61581 add -0        0E-19  ->  0E-19
addx61582 add  0       -0E-19  ->  0E-19
addx61583 add -0       -0E-19  -> -0E-19
addx61584 add  0E-400   0E-19  ->  0E-398 Clamped
addx61585 add -0E-400   0E-19  ->  0E-398 Clamped
addx61586 add  0E-400  -0E-19  ->  0E-398 Clamped
addx61587 add -0E-400  -0E-19  -> -0E-398 Clamped
-- inexact zeros
addx61591 add  1E-401   1E-400 ->  0E-398 Subnormal Inexact Rounded Underflow Clamped
addx61592 add -1E-401   1E-400 ->  0E-398 Subnormal Inexact Rounded Underflow Clamped
addx61593 add  1E-401  -1E-400 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
addx61594 add -1E-401  -1E-400 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
-- some exact zeros from non-zeros
addx61595 add  1E-401   1E-401 ->  0E-398 Subnormal Inexact Rounded Underflow Clamped
addx61596 add -1E-401   1E-401 ->  0E-398 Clamped
addx61597 add  1E-401  -1E-401 ->  0E-398 Clamped
addx61598 add -1E-401  -1E-401 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped

rounding:    ceiling
-- exact zeros from zeros
addx61600 add  0        0E-19  ->  0E-19
addx61601 add -0        0E-19  ->  0E-19
addx61602 add  0       -0E-19  ->  0E-19
addx61603 add -0       -0E-19  -> -0E-19
addx61604 add  0E-400   0E-19  ->  0E-398 Clamped
addx61605 add -0E-400   0E-19  ->  0E-398 Clamped
addx61606 add  0E-400  -0E-19  ->  0E-398 Clamped
addx61607 add -0E-400  -0E-19  -> -0E-398 Clamped
-- inexact zeros
addx61611 add  1E-401   1E-400 ->  1E-398 Subnormal Inexact Rounded Underflow
addx61612 add -1E-401   1E-400 ->  1E-398 Subnormal Inexact Rounded Underflow
addx61613 add  1E-401  -1E-400 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
addx61614 add -1E-401  -1E-400 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped
-- some exact zeros from non-zeros
addx61615 add  1E-401   1E-401 ->  1E-398 Subnormal Inexact Rounded Underflow
addx61616 add -1E-401   1E-401 ->  0E-398 Clamped
addx61617 add  1E-401  -1E-401 ->  0E-398 Clamped
addx61618 add -1E-401  -1E-401 -> -0E-398 Subnormal Inexact Rounded Underflow Clamped

-- and the extra-special ugly case; unusual minuses marked by -- *
rounding:    floor
-- exact zeros from zeros
addx61620 add  0        0E-19  ->  0E-19
addx61621 add -0        0E-19  -> -0E-19           -- *
addx61622 add  0       -0E-19  -> -0E-19           -- *
addx61623 add -0       -0E-19  -> -0E-19
addx61624 add  0E-400   0E-19  ->  0E-398 Clamped
addx61625 add -0E-400   0E-19  -> -0E-398 Clamped  -- *
addx61626 add  0E-400  -0E-19  -> -0E-398 Clamped  -- *
addx61627 add -0E-400  -0E-19  -> -0E-398 Clamped
-- inexact zeros
addx61631 add  1E-401   1E-400 ->  0E-398 Subnormal Inexact Rounded Underflow Clamped
addx61632 add -1E-401   1E-400 ->  0E-398 Subnormal Inexact Rounded Underflow Clamped
addx61633 add  1E-401  -1E-400 -> -1E-398 Subnormal Inexact Rounded Underflow
addx61634 add -1E-401  -1E-400 -> -1E-398 Subnormal Inexact Rounded Underflow
-- some exact zeros from non-zeros
addx61635 add  1E-401   1E-401 ->  0E-398 Subnormal Inexact Rounded Underflow Clamped
addx61636 add -1E-401   1E-401 -> -0E-398 Clamped  -- *
addx61637 add  1E-401  -1E-401 -> -0E-398 Clamped  -- *
addx61638 add -1E-401  -1E-401 -> -1E-398 Subnormal Inexact Rounded Underflow

-- Examples from SQL proposal (Krishna Kulkarni)
addx61701 add 130E-2    120E-2    -> 2.50
addx61702 add 130E-2    12E-1     -> 2.50
addx61703 add 130E-2    1E0       -> 2.30
addx61704 add 1E2       1E4       -> 1.01E+4
addx61705 subtract 130E-2  120E-2 -> 0.10
addx61706 subtract 130E-2  12E-1  -> 0.10
addx61707 subtract 130E-2  1E0    -> 0.30
addx61708 subtract 1E2     1E4    -> -9.9E+3

-- Gappy coefficients; check residue handling even with full coefficient gap
rounding: half_even

addx62001 add 1234567890123456 1      -> 1234567890123457
addx62002 add 1234567890123456 0.6    -> 1234567890123457  Inexact Rounded
addx62003 add 1234567890123456 0.06   -> 1234567890123456  Inexact Rounded
addx62004 add 1234567890123456 6E-3   -> 1234567890123456  Inexact Rounded
addx62005 add 1234567890123456 6E-4   -> 1234567890123456  Inexact Rounded
addx62006 add 1234567890123456 6E-5   -> 1234567890123456  Inexact Rounded
addx62007 add 1234567890123456 6E-6   -> 1234567890123456  Inexact Rounded
addx62008 add 1234567890123456 6E-7   -> 1234567890123456  Inexact Rounded
addx62009 add 1234567890123456 6E-8   -> 1234567890123456  Inexact Rounded
addx62010 add 1234567890123456 6E-9   -> 1234567890123456  Inexact Rounded
addx62011 add 1234567890123456 6E-10  -> 1234567890123456  Inexact Rounded
addx62012 add 1234567890123456 6E-11  -> 1234567890123456  Inexact Rounded
addx62013 add 1234567890123456 6E-12  -> 1234567890123456  Inexact Rounded
addx62014 add 1234567890123456 6E-13  -> 1234567890123456  Inexact Rounded
addx62015 add 1234567890123456 6E-14  -> 1234567890123456  Inexact Rounded
addx62016 add 1234567890123456 6E-15  -> 1234567890123456  Inexact Rounded
addx62017 add 1234567890123456 6E-16  -> 1234567890123456  Inexact Rounded
addx62018 add 1234567890123456 6E-17  -> 1234567890123456  Inexact Rounded
addx62019 add 1234567890123456 6E-18  -> 1234567890123456  Inexact Rounded
addx62020 add 1234567890123456 6E-19  -> 1234567890123456  Inexact Rounded
addx62021 add 1234567890123456 6E-20  -> 1234567890123456  Inexact Rounded

-- widening second argument at gap
addx62030 add 12345678 1                       -> 12345679
addx62031 add 12345678 0.1                     -> 12345678.1
addx62032 add 12345678 0.12                    -> 12345678.12
addx62033 add 12345678 0.123                   -> 12345678.123
addx62034 add 12345678 0.1234                  -> 12345678.1234
addx62035 add 12345678 0.12345                 -> 12345678.12345
addx62036 add 12345678 0.123456                -> 12345678.123456
addx62037 add 12345678 0.1234567               -> 12345678.1234567
addx62038 add 12345678 0.12345678              -> 12345678.12345678
addx62039 add 12345678 0.123456789             -> 12345678.12345679 Inexact Rounded
addx62040 add 12345678 0.123456785             -> 12345678.12345678 Inexact Rounded
addx62041 add 12345678 0.1234567850            -> 12345678.12345678 Inexact Rounded
addx62042 add 12345678 0.1234567851            -> 12345678.12345679 Inexact Rounded
addx62043 add 12345678 0.12345678501           -> 12345678.12345679 Inexact Rounded
addx62044 add 12345678 0.123456785001          -> 12345678.12345679 Inexact Rounded
addx62045 add 12345678 0.1234567850001         -> 12345678.12345679 Inexact Rounded
addx62046 add 12345678 0.12345678500001        -> 12345678.12345679 Inexact Rounded
addx62047 add 12345678 0.123456785000001       -> 12345678.12345679 Inexact Rounded
addx62048 add 12345678 0.1234567850000001      -> 12345678.12345679 Inexact Rounded
addx62049 add 12345678 0.1234567850000000      -> 12345678.12345678 Inexact Rounded
--                               90123456
rounding: half_even
addx62050 add 12345678 0.0234567750000000      -> 12345678.02345678 Inexact Rounded
addx62051 add 12345678 0.0034567750000000      -> 12345678.00345678 Inexact Rounded
addx62052 add 12345678 0.0004567750000000      -> 12345678.00045678 Inexact Rounded
addx62053 add 12345678 0.0000567750000000      -> 12345678.00005678 Inexact Rounded
addx62054 add 12345678 0.0000067750000000      -> 12345678.00000678 Inexact Rounded
addx62055 add 12345678 0.0000007750000000      -> 12345678.00000078 Inexact Rounded
addx62056 add 12345678 0.0000000750000000      -> 12345678.00000008 Inexact Rounded
addx62057 add 12345678 0.0000000050000000      -> 12345678.00000000 Inexact Rounded
addx62060 add 12345678 0.0234567750000001      -> 12345678.02345678 Inexact Rounded
addx62061 add 12345678 0.0034567750000001      -> 12345678.00345678 Inexact Rounded
addx62062 add 12345678 0.0004567750000001      -> 12345678.00045678 Inexact Rounded
addx62063 add 12345678 0.0000567750000001      -> 12345678.00005678 Inexact Rounded
addx62064 add 12345678 0.0000067750000001      -> 12345678.00000678 Inexact Rounded
addx62065 add 12345678 0.0000007750000001      -> 12345678.00000078 Inexact Rounded
addx62066 add 12345678 0.0000000750000001      -> 12345678.00000008 Inexact Rounded
addx62067 add 12345678 0.0000000050000001      -> 12345678.00000001 Inexact Rounded
-- far-out residues (full coefficient gap is 16+15 digits)
rounding: up
addx62070 add 12345678 1E-8                    -> 12345678.00000001
addx62071 add 12345678 1E-9                    -> 12345678.00000001 Inexact Rounded
addx62072 add 12345678 1E-10                   -> 12345678.00000001 Inexact Rounded
addx62073 add 12345678 1E-11                   -> 12345678.00000001 Inexact Rounded
addx62074 add 12345678 1E-12                   -> 12345678.00000001 Inexact Rounded
addx62075 add 12345678 1E-13                   -> 12345678.00000001 Inexact Rounded
addx62076 add 12345678 1E-14                   -> 12345678.00000001 Inexact Rounded
addx62077 add 12345678 1E-15                   -> 12345678.00000001 Inexact Rounded
addx62078 add 12345678 1E-16                   -> 12345678.00000001 Inexact Rounded
addx62079 add 12345678 1E-17                   -> 12345678.00000001 Inexact Rounded
addx62080 add 12345678 1E-18                   -> 12345678.00000001 Inexact Rounded
addx62081 add 12345678 1E-19                   -> 12345678.00000001 Inexact Rounded
addx62082 add 12345678 1E-20                   -> 12345678.00000001 Inexact Rounded
addx62083 add 12345678 1E-25                   -> 12345678.00000001 Inexact Rounded
addx62084 add 12345678 1E-30                   -> 12345678.00000001 Inexact Rounded
addx62085 add 12345678 1E-31                   -> 12345678.00000001 Inexact Rounded
addx62086 add 12345678 1E-32                   -> 12345678.00000001 Inexact Rounded
addx62087 add 12345678 1E-33                   -> 12345678.00000001 Inexact Rounded
addx62088 add 12345678 1E-34                   -> 12345678.00000001 Inexact Rounded
addx62089 add 12345678 1E-35                   -> 12345678.00000001 Inexact Rounded

-- payload decapitate
precision: 5
addx62100 add      11  sNaN123456789 ->  NaN56789  Invalid_operation
addx62101 add     -11 -sNaN123456789 -> -NaN56789  Invalid_operation
addx62102 add      11   NaN123456789 ->  NaN56789
addx62103 add     -11  -NaN123456789 -> -NaN56789

-- Null tests
addx9990 add 10  # -> NaN Invalid_operation
addx9991 add  # 10 -> NaN Invalid_operation
"hl opt">{"storeScalar4", 5, 0, 1, {OPERAND_LVT4}}, /* Store scalar variable at op1 > 255 in frame; value is stktop */ {"storeScalarStk", 1, -1, 0, {OPERAND_NONE}}, /* Store scalar; value is stktop, scalar name is stknext */ {"storeArray1", 2, -1, 1, {OPERAND_LVT1}}, /* Store array element; array at op1<=255, value is top then elem */ {"storeArray4", 5, -1, 1, {OPERAND_LVT4}}, /* Store array element; array at op1>=256, value is top then elem */ {"storeArrayStk", 1, -2, 0, {OPERAND_NONE}}, /* Store array element; value is stktop, then elem, array names */ {"storeStk", 1, -1, 0, {OPERAND_NONE}}, /* Store general variable; value is stktop, then unparsed name */ {"incrScalar1", 2, 0, 1, {OPERAND_LVT1}}, /* Incr scalar at index op1<=255 in frame; incr amount is stktop */ {"incrScalarStk", 1, -1, 0, {OPERAND_NONE}}, /* Incr scalar; incr amount is stktop, scalar's name is stknext */ {"incrArray1", 2, -1, 1, {OPERAND_LVT1}}, /* Incr array elem; arr at slot op1<=255, amount is top then elem */ {"incrArrayStk", 1, -2, 0, {OPERAND_NONE}}, /* Incr array element; amount is top then elem then array names */ {"incrStk", 1, -1, 0, {OPERAND_NONE}}, /* Incr general variable; amount is stktop then unparsed var name */ {"incrScalar1Imm", 3, +1, 2, {OPERAND_LVT1, OPERAND_INT1}}, /* Incr scalar at slot op1 <= 255; amount is 2nd operand byte */ {"incrScalarStkImm", 2, 0, 1, {OPERAND_INT1}}, /* Incr scalar; scalar name is stktop; incr amount is op1 */ {"incrArray1Imm", 3, 0, 2, {OPERAND_LVT1, OPERAND_INT1}}, /* Incr array elem; array at slot op1 <= 255, elem is stktop, * amount is 2nd operand byte */ {"incrArrayStkImm", 2, -1, 1, {OPERAND_INT1}}, /* Incr array element; elem is top then array name, amount is op1 */ {"incrStkImm", 2, 0, 1, {OPERAND_INT1}}, /* Incr general variable; unparsed name is top, amount is op1 */ {"jump1", 2, 0, 1, {OPERAND_INT1}}, /* Jump relative to (pc + op1) */ {"jump4", 5, 0, 1, {OPERAND_INT4}}, /* Jump relative to (pc + op4) */ {"jumpTrue1", 2, -1, 1, {OPERAND_INT1}}, /* Jump relative to (pc + op1) if stktop expr object is true */ {"jumpTrue4", 5, -1, 1, {OPERAND_INT4}}, /* Jump relative to (pc + op4) if stktop expr object is true */ {"jumpFalse1", 2, -1, 1, {OPERAND_INT1}}, /* Jump relative to (pc + op1) if stktop expr object is false */ {"jumpFalse4", 5, -1, 1, {OPERAND_INT4}}, /* Jump relative to (pc + op4) if stktop expr object is false */ {"lor", 1, -1, 0, {OPERAND_NONE}}, /* Logical or: push (stknext || stktop) */ {"land", 1, -1, 0, {OPERAND_NONE}}, /* Logical and: push (stknext && stktop) */ {"bitor", 1, -1, 0, {OPERAND_NONE}}, /* Bitwise or: push (stknext | stktop) */ {"bitxor", 1, -1, 0, {OPERAND_NONE}}, /* Bitwise xor push (stknext ^ stktop) */ {"bitand", 1, -1, 0, {OPERAND_NONE}}, /* Bitwise and: push (stknext & stktop) */ {"eq", 1, -1, 0, {OPERAND_NONE}}, /* Equal: push (stknext == stktop) */ {"neq", 1, -1, 0, {OPERAND_NONE}}, /* Not equal: push (stknext != stktop) */ {"lt", 1, -1, 0, {OPERAND_NONE}}, /* Less: push (stknext < stktop) */ {"gt", 1, -1, 0, {OPERAND_NONE}}, /* Greater: push (stknext > stktop) */ {"le", 1, -1, 0, {OPERAND_NONE}}, /* Less or equal: push (stknext <= stktop) */ {"ge", 1, -1, 0, {OPERAND_NONE}}, /* Greater or equal: push (stknext >= stktop) */ {"lshift", 1, -1, 0, {OPERAND_NONE}}, /* Left shift: push (stknext << stktop) */ {"rshift", 1, -1, 0, {OPERAND_NONE}}, /* Right shift: push (stknext >> stktop) */ {"add", 1, -1, 0, {OPERAND_NONE}}, /* Add: push (stknext + stktop) */ {"sub", 1, -1, 0, {OPERAND_NONE}}, /* Sub: push (stkext - stktop) */ {"mult", 1, -1, 0, {OPERAND_NONE}}, /* Multiply: push (stknext * stktop) */ {"div", 1, -1, 0, {OPERAND_NONE}}, /* Divide: push (stknext / stktop) */ {"mod", 1, -1, 0, {OPERAND_NONE}}, /* Mod: push (stknext % stktop) */ {"uplus", 1, 0, 0, {OPERAND_NONE}}, /* Unary plus: push +stktop */ {"uminus", 1, 0, 0, {OPERAND_NONE}}, /* Unary minus: push -stktop */ {"bitnot", 1, 0, 0, {OPERAND_NONE}}, /* Bitwise not: push ~stktop */ {"not", 1, 0, 0, {OPERAND_NONE}}, /* Logical not: push !stktop */ {"callBuiltinFunc1", 2, 1, 1, {OPERAND_UINT1}}, /* Call builtin math function with index op1; any args are on stk */ {"callFunc1", 2, INT_MIN, 1, {OPERAND_UINT1}}, /* Call non-builtin func objv[0]; <objc,objv>=<op1,top op1> */ {"tryCvtToNumeric", 1, 0, 0, {OPERAND_NONE}}, /* Try converting stktop to first int then double if possible. */ {"break", 1, 0, 0, {OPERAND_NONE}}, /* Abort closest enclosing loop; if none, return TCL_BREAK code. */ {"continue", 1, 0, 0, {OPERAND_NONE}}, /* Skip to next iteration of closest enclosing loop; if none, return * TCL_CONTINUE code. */ {"foreach_start4", 5, 0, 1, {OPERAND_AUX4}}, /* Initialize execution of a foreach loop. Operand is aux data index * of the ForeachInfo structure for the foreach command. */ {"foreach_step4", 5, +1, 1, {OPERAND_AUX4}}, /* "Step" or begin next iteration of foreach loop. Push 0 if to * terminate loop, else push 1. */ {"beginCatch4", 5, 0, 1, {OPERAND_UINT4}}, /* Record start of catch with the operand's exception index. Push the * current stack depth onto a special catch stack. */ {"endCatch", 1, 0, 0, {OPERAND_NONE}}, /* End of last catch. Pop the bytecode interpreter's catch stack. */ {"pushResult", 1, +1, 0, {OPERAND_NONE}}, /* Push the interpreter's object result onto the stack. */ {"pushReturnCode", 1, +1, 0, {OPERAND_NONE}}, /* Push interpreter's return code (e.g. TCL_OK or TCL_ERROR) as a new * object onto the stack. */ {"streq", 1, -1, 0, {OPERAND_NONE}}, /* Str Equal: push (stknext eq stktop) */ {"strneq", 1, -1, 0, {OPERAND_NONE}}, /* Str !Equal: push (stknext neq stktop) */ {"strcmp", 1, -1, 0, {OPERAND_NONE}}, /* Str Compare: push (stknext cmp stktop) */ {"strlen", 1, 0, 0, {OPERAND_NONE}}, /* Str Length: push (strlen stktop) */ {"strindex", 1, -1, 0, {OPERAND_NONE}}, /* Str Index: push (strindex stknext stktop) */ {"strmatch", 2, -1, 1, {OPERAND_INT1}}, /* Str Match: push (strmatch stknext stktop) opnd == nocase */ {"list", 5, INT_MIN, 1, {OPERAND_UINT4}}, /* List: push (stk1 stk2 ... stktop) */ {"listIndex", 1, -1, 0, {OPERAND_NONE}}, /* List Index: push (listindex stknext stktop) */ {"listLength", 1, 0, 0, {OPERAND_NONE}}, /* List Len: push (listlength stktop) */ {"appendScalar1", 2, 0, 1, {OPERAND_LVT1}}, /* Append scalar variable at op1<=255 in frame; value is stktop */ {"appendScalar4", 5, 0, 1, {OPERAND_LVT4}}, /* Append scalar variable at op1 > 255 in frame; value is stktop */ {"appendArray1", 2, -1, 1, {OPERAND_LVT1}}, /* Append array element; array at op1<=255, value is top then elem */ {"appendArray4", 5, -1, 1, {OPERAND_LVT4}}, /* Append array element; array at op1>=256, value is top then elem */ {"appendArrayStk", 1, -2, 0, {OPERAND_NONE}}, /* Append array element; value is stktop, then elem, array names */ {"appendStk", 1, -1, 0, {OPERAND_NONE}}, /* Append general variable; value is stktop, then unparsed name */ {"lappendScalar1", 2, 0, 1, {OPERAND_LVT1}}, /* Lappend scalar variable at op1<=255 in frame; value is stktop */ {"lappendScalar4", 5, 0, 1, {OPERAND_LVT4}}, /* Lappend scalar variable at op1 > 255 in frame; value is stktop */ {"lappendArray1", 2, -1, 1, {OPERAND_LVT1}}, /* Lappend array element; array at op1<=255, value is top then elem */ {"lappendArray4", 5, -1, 1, {OPERAND_LVT4}}, /* Lappend array element; array at op1>=256, value is top then elem */ {"lappendArrayStk", 1, -2, 0, {OPERAND_NONE}}, /* Lappend array element; value is stktop, then elem, array names */ {"lappendStk", 1, -1, 0, {OPERAND_NONE}}, /* Lappend general variable; value is stktop, then unparsed name */ {"lindexMulti", 5, INT_MIN, 1, {OPERAND_UINT4}}, /* Lindex with generalized args, operand is number of stacked objs * used: (operand-1) entries from stktop are the indices; then list to * process. */ {"over", 5, +1, 1, {OPERAND_UINT4}}, /* Duplicate the arg-th element from top of stack (TOS=0) */ {"lsetList", 1, -2, 0, {OPERAND_NONE}}, /* Four-arg version of 'lset'. stktop is old value; next is new * element value, next is the index list; pushes new value */ {"lsetFlat", 5, INT_MIN, 1, {OPERAND_UINT4}}, /* Three- or >=5-arg version of 'lset', operand is number of stacked * objs: stktop is old value, next is new element value, next come * (operand-2) indices; pushes the new value. */ {"returnImm", 9, -1, 2, {OPERAND_INT4, OPERAND_UINT4}}, /* Compiled [return], code, level are operands; options and result * are on the stack. */ {"expon", 1, -1, 0, {OPERAND_NONE}}, /* Binary exponentiation operator: push (stknext ** stktop) */ /* * NOTE: the stack effects of expandStkTop and invokeExpanded are wrong - * but it cannot be done right at compile time, the stack effect is only * known at run time. The value for invokeExpanded is estimated better at * compile time. * See the comments further down in this file, where INST_INVOKE_EXPANDED * is emitted. */ {"expandStart", 1, 0, 0, {OPERAND_NONE}}, /* Start of command with {*} (expanded) arguments */ {"expandStkTop", 5, 0, 1, {OPERAND_UINT4}}, /* Expand the list at stacktop: push its elements on the stack */ {"invokeExpanded", 1, 0, 0, {OPERAND_NONE}}, /* Invoke the command marked by the last 'expandStart' */ {"listIndexImm", 5, 0, 1, {OPERAND_IDX4}}, /* List Index: push (lindex stktop op4) */ {"listRangeImm", 9, 0, 2, {OPERAND_IDX4, OPERAND_IDX4}}, /* List Range: push (lrange stktop op4 op4) */ {"startCommand", 9, 0, 2, {OPERAND_INT4,OPERAND_UINT4}}, /* Start of bytecoded command: op is the length of the cmd's code, op2 * is number of commands here */ {"listIn", 1, -1, 0, {OPERAND_NONE}}, /* List containment: push [lsearch stktop stknext]>=0) */ {"listNotIn", 1, -1, 0, {OPERAND_NONE}}, /* List negated containment: push [lsearch stktop stknext]<0) */ {"pushReturnOpts", 1, +1, 0, {OPERAND_NONE}}, /* Push the interpreter's return option dictionary as an object on the * stack. */ {"returnStk", 1, -1, 0, {OPERAND_NONE}}, /* Compiled [return]; options and result are on the stack, code and * level are in the options. */ {"dictGet", 5, INT_MIN, 1, {OPERAND_UINT4}}, /* The top op4 words (min 1) are a key path into the dictionary just * below the keys on the stack, and all those values are replaced by * the value read out of that key-path (like [dict get]). * Stack: ... dict key1 ... keyN => ... value */ {"dictSet", 9, INT_MIN, 2, {OPERAND_UINT4, OPERAND_LVT4}}, /* Update a dictionary value such that the keys are a path pointing to * the value. op4#1 = numKeys, op4#2 = LVTindex * Stack: ... key1 ... keyN value => ... newDict */ {"dictUnset", 9, INT_MIN, 2, {OPERAND_UINT4, OPERAND_LVT4}}, /* Update a dictionary value such that the keys are not a path pointing * to any value. op4#1 = numKeys, op4#2 = LVTindex * Stack: ... key1 ... keyN => ... newDict */ {"dictIncrImm", 9, 0, 2, {OPERAND_INT4, OPERAND_LVT4}}, /* Update a dictionary value such that the value pointed to by key is * incremented by some value (or set to it if the key isn't in the * dictionary at all). op4#1 = incrAmount, op4#2 = LVTindex * Stack: ... key => ... newDict */ {"dictAppend", 5, -1, 1, {OPERAND_LVT4}}, /* Update a dictionary value such that the value pointed to by key has * some value string-concatenated onto it. op4 = LVTindex * Stack: ... key valueToAppend => ... newDict */ {"dictLappend", 5, -1, 1, {OPERAND_LVT4}}, /* Update a dictionary value such that the value pointed to by key has * some value list-appended onto it. op4 = LVTindex * Stack: ... key valueToAppend => ... newDict */ {"dictFirst", 5, +2, 1, {OPERAND_LVT4}}, /* Begin iterating over the dictionary, using the local scalar * indicated by op4 to hold the iterator state. The local scalar * should not refer to a named variable as the value is not wholly * managed correctly. * Stack: ... dict => ... value key doneBool */ {"dictNext", 5, +3, 1, {OPERAND_LVT4}}, /* Get the next iteration from the iterator in op4's local scalar. * Stack: ... => ... value key doneBool */ {"dictDone", 5, 0, 1, {OPERAND_LVT4}}, /* Terminate the iterator in op4's local scalar. Use unsetScalar * instead (with 0 for flags). */ {"dictUpdateStart", 9, 0, 2, {OPERAND_LVT4, OPERAND_AUX4}}, /* Create the variables (described in the aux data referred to by the * second immediate argument) to mirror the state of the dictionary in * the variable referred to by the first immediate argument. The list * of keys (top of the stack, not poppsed) must be the same length as * the list of variables. * Stack: ... keyList => ... keyList */ {"dictUpdateEnd", 9, -1, 2, {OPERAND_LVT4, OPERAND_AUX4}}, /* Reflect the state of local variables (described in the aux data * referred to by the second immediate argument) back to the state of * the dictionary in the variable referred to by the first immediate * argument. The list of keys (popped from the stack) must be the same * length as the list of variables. * Stack: ... keyList => ... */ {"jumpTable", 5, -1, 1, {OPERAND_AUX4}}, /* Jump according to the jump-table (in AuxData as indicated by the * operand) and the argument popped from the list. Always executes the * next instruction if no match against the table's entries was found. * Stack: ... value => ... * Note that the jump table contains offsets relative to the PC when * it points to this instruction; the code is relocatable. */ {"upvar", 5, -1, 1, {OPERAND_LVT4}}, /* finds level and otherName in stack, links to local variable at * index op1. Leaves the level on stack. */ {"nsupvar", 5, -1, 1, {OPERAND_LVT4}}, /* finds namespace and otherName in stack, links to local variable at * index op1. Leaves the namespace on stack. */ {"variable", 5, -1, 1, {OPERAND_LVT4}}, /* finds namespace and otherName in stack, links to local variable at * index op1. Leaves the namespace on stack. */ {"syntax", 9, -1, 2, {OPERAND_INT4, OPERAND_UINT4}}, /* Compiled bytecodes to signal syntax error. Equivalent to returnImm * except for the ERR_ALREADY_LOGGED flag in the interpreter. */ {"reverse", 5, 0, 1, {OPERAND_UINT4}}, /* Reverse the order of the arg elements at the top of stack */ {"regexp", 2, -1, 1, {OPERAND_INT1}}, /* Regexp: push (regexp stknext stktop) opnd == nocase */ {"existScalar", 5, 1, 1, {OPERAND_LVT4}}, /* Test if scalar variable at index op1 in call frame exists */ {"existArray", 5, 0, 1, {OPERAND_LVT4}}, /* Test if array element exists; array at slot op1, element is * stktop */ {"existArrayStk", 1, -1, 0, {OPERAND_NONE}}, /* Test if array element exists; element is stktop, array name is * stknext */ {"existStk", 1, 0, 0, {OPERAND_NONE}}, /* Test if general variable exists; unparsed variable name is stktop*/ {"nop", 1, 0, 0, {OPERAND_NONE}}, /* Do nothing */ {"returnCodeBranch", 1, -1, 0, {OPERAND_NONE}}, /* Jump to next instruction based on the return code on top of stack * ERROR: +1; RETURN: +3; BREAK: +5; CONTINUE: +7; * Other non-OK: +9 */ {"unsetScalar", 6, 0, 2, {OPERAND_UINT1, OPERAND_LVT4}}, /* Make scalar variable at index op2 in call frame cease to exist; * op1 is 1 for errors on problems, 0 otherwise */ {"unsetArray", 6, -1, 2, {OPERAND_UINT1, OPERAND_LVT4}}, /* Make array element cease to exist; array at slot op2, element is * stktop; op1 is 1 for errors on problems, 0 otherwise */ {"unsetArrayStk", 2, -2, 1, {OPERAND_UINT1}}, /* Make array element cease to exist; element is stktop, array name is * stknext; op1 is 1 for errors on problems, 0 otherwise */ {"unsetStk", 2, -1, 1, {OPERAND_UINT1}}, /* Make general variable cease to exist; unparsed variable name is * stktop; op1 is 1 for errors on problems, 0 otherwise */ {"dictExpand", 1, -1, 0, {OPERAND_NONE}}, /* Probe into a dict and extract it (or a subdict of it) into * variables with matched names. Produces list of keys bound as * result. Part of [dict with]. * Stack: ... dict path => ... keyList */ {"dictRecombineStk", 1, -3, 0, {OPERAND_NONE}}, /* Map variable contents back into a dictionary in a variable. Part of * [dict with]. * Stack: ... dictVarName path keyList => ... */ {"dictRecombineImm", 5, -2, 1, {OPERAND_LVT4}}, /* Map variable contents back into a dictionary in the local variable * indicated by the LVT index. Part of [dict with]. * Stack: ... path keyList => ... */ {"dictExists", 5, INT_MIN, 1, {OPERAND_UINT4}}, /* The top op4 words (min 1) are a key path into the dictionary just * below the keys on the stack, and all those values are replaced by a * boolean indicating whether it is possible to read out a value from * that key-path (like [dict exists]). * Stack: ... dict key1 ... keyN => ... boolean */ {"verifyDict", 1, -1, 0, {OPERAND_NONE}}, /* Verifies that the word on the top of the stack is a dictionary, * popping it if it is and throwing an error if it is not. * Stack: ... value => ... */ {"strmap", 1, -2, 0, {OPERAND_NONE}}, /* Simplified version of [string map] that only applies one change * string, and only case-sensitively. * Stack: ... from to string => ... changedString */ {"strfind", 1, -1, 0, {OPERAND_NONE}}, /* Find the first index of a needle string in a haystack string, * producing the index (integer) or -1 if nothing found. * Stack: ... needle haystack => ... index */ {"strrfind", 1, -1, 0, {OPERAND_NONE}}, /* Find the last index of a needle string in a haystack string, * producing the index (integer) or -1 if nothing found. * Stack: ... needle haystack => ... index */ {"strrangeImm", 9, 0, 2, {OPERAND_IDX4, OPERAND_IDX4}}, /* String Range: push (string range stktop op4 op4) */ {"strrange", 1, -2, 0, {OPERAND_NONE}}, /* String Range with non-constant arguments. * Stack: ... string idxA idxB => ... substring */ {"yield", 1, 0, 0, {OPERAND_NONE}}, /* Makes the current coroutine yield the value at the top of the * stack, and places the response back on top of the stack when it * resumes. * Stack: ... valueToYield => ... resumeValue */ {"coroName", 1, +1, 0, {OPERAND_NONE}}, /* Push the name of the interpreter's current coroutine as an object * on the stack. */ {"tailcall", 2, INT_MIN, 1, {OPERAND_UINT1}}, /* Do a tailcall with the opnd items on the stack as the thing to * tailcall to; opnd must be greater than 0 for the semantics to work * right. */ {"currentNamespace", 1, +1, 0, {OPERAND_NONE}}, /* Push the name of the interpreter's current namespace as an object * on the stack. */ {"infoLevelNumber", 1, +1, 0, {OPERAND_NONE}}, /* Push the stack depth (i.e., [info level]) of the interpreter as an * object on the stack. */ {"infoLevelArgs", 1, 0, 0, {OPERAND_NONE}}, /* Push the argument words to a stack depth (i.e., [info level <n>]) * of the interpreter as an object on the stack. * Stack: ... depth => ... argList */ {"resolveCmd", 1, 0, 0, {OPERAND_NONE}}, /* Resolves the command named on the top of the stack to its fully * qualified version, or produces the empty string if no such command * exists. Never generates errors. * Stack: ... cmdName => ... fullCmdName */ {"tclooSelf", 1, +1, 0, {OPERAND_NONE}}, /* Push the identity of the current TclOO object (i.e., the name of * its current public access command) on the stack. */ {"tclooClass", 1, 0, 0, {OPERAND_NONE}}, /* Push the class of the TclOO object named at the top of the stack * onto the stack. * Stack: ... object => ... class */ {"tclooNamespace", 1, 0, 0, {OPERAND_NONE}}, /* Push the namespace of the TclOO object named at the top of the * stack onto the stack. * Stack: ... object => ... namespace */ {"tclooIsObject", 1, 0, 0, {OPERAND_NONE}}, /* Push whether the value named at the top of the stack is a TclOO * object (i.e., a boolean). Can corrupt the interpreter result * despite not throwing, so not safe for use in a post-exception * context. * Stack: ... value => ... boolean */ {"arrayExistsStk", 1, 0, 0, {OPERAND_NONE}}, /* Looks up the element on the top of the stack and tests whether it * is an array. Pushes a boolean describing whether this is the * case. Also runs the whole-array trace on the named variable, so can * throw anything. * Stack: ... varName => ... boolean */ {"arrayExistsImm", 5, +1, 1, {OPERAND_UINT4}}, /* Looks up the variable indexed by opnd and tests whether it is an * array. Pushes a boolean describing whether this is the case. Also * runs the whole-array trace on the named variable, so can throw * anything. * Stack: ... => ... boolean */ {"arrayMakeStk", 1, -1, 0, {OPERAND_NONE}}, /* Forces the element on the top of the stack to be the name of an * array. * Stack: ... varName => ... */ {"arrayMakeImm", 5, 0, 1, {OPERAND_UINT4}}, /* Forces the variable indexed by opnd to be an array. Does not touch * the stack. */ {"invokeReplace", 6, INT_MIN, 2, {OPERAND_UINT4,OPERAND_UINT1}}, /* Invoke command named objv[0], replacing the first two words with * the word at the top of the stack; * <objc,objv> = <op4,top op4 after popping 1> */ {"listConcat", 1, -1, 0, {OPERAND_NONE}}, /* Concatenates the two lists at the top of the stack into a single * list and pushes that resulting list onto the stack. * Stack: ... list1 list2 => ... [lconcat list1 list2] */ {"expandDrop", 1, 0, 0, {OPERAND_NONE}}, /* Drops an element from the auxiliary stack, popping stack elements * until the matching stack depth is reached. */ /* New foreach implementation */ {"foreach_start", 5, +2, 1, {OPERAND_AUX4}}, /* Initialize execution of a foreach loop. Operand is aux data index * of the ForeachInfo structure for the foreach command. It pushes 2 * elements which hold runtime params for foreach_step, they are later * dropped by foreach_end together with the value lists. NOTE that the * iterator-tracker and info reference must not be passed to bytecodes * that handle normal Tcl values. NOTE that this instruction jumps to * the foreach_step instruction paired with it; the stack info below * is only nominal. * Stack: ... listObjs... => ... listObjs... iterTracker info */ {"foreach_step", 1, 0, 0, {OPERAND_NONE}}, /* "Step" or begin next iteration of foreach loop. Assigns to foreach * iteration variables. May jump to straight after the foreach_start * that pushed the iterTracker and info values. MUST be followed * immediately by a foreach_end. * Stack: ... listObjs... iterTracker info => * ... listObjs... iterTracker info */ {"foreach_end", 1, 0, 0, {OPERAND_NONE}}, /* Clean up a foreach loop by dropping the info value, the tracker * value and the lists that were being iterated over. * Stack: ... listObjs... iterTracker info => ... */ {"lmap_collect", 1, -1, 0, {OPERAND_NONE}}, /* Appends the value at the top of the stack to the list located on * the stack the "other side" of the foreach-related values. * Stack: ... collector listObjs... iterTracker info value => * ... collector listObjs... iterTracker info */ {"strtrim", 1, -1, 0, {OPERAND_NONE}}, /* [string trim] core: removes the characters (designated by the value * at the top of the stack) from both ends of the string and pushes * the resulting string. * Stack: ... string charset => ... trimmedString */ {"strtrimLeft", 1, -1, 0, {OPERAND_NONE}}, /* [string trimleft] core: removes the characters (designated by the * value at the top of the stack) from the left of the string and * pushes the resulting string. * Stack: ... string charset => ... trimmedString */ {"strtrimRight", 1, -1, 0, {OPERAND_NONE}}, /* [string trimright] core: removes the characters (designated by the * value at the top of the stack) from the right of the string and * pushes the resulting string. * Stack: ... string charset => ... trimmedString */ {"concatStk", 5, INT_MIN, 1, {OPERAND_UINT4}}, /* Wrapper round Tcl_ConcatObj(), used for [concat] and [eval]. opnd * is number of values to concatenate. * Operation: push concat(stk1 stk2 ... stktop) */ {"strcaseUpper", 1, 0, 0, {OPERAND_NONE}}, /* [string toupper] core: converts whole string to upper case using * the default (extended "C" locale) rules. * Stack: ... string => ... newString */ {"strcaseLower", 1, 0, 0, {OPERAND_NONE}}, /* [string tolower] core: converts whole string to upper case using * the default (extended "C" locale) rules. * Stack: ... string => ... newString */ {"strcaseTitle", 1, 0, 0, {OPERAND_NONE}}, /* [string totitle] core: converts whole string to upper case using * the default (extended "C" locale) rules. * Stack: ... string => ... newString */ {"strreplace", 1, -3, 0, {OPERAND_NONE}}, /* [string replace] core: replaces a non-empty range of one string * with the contents of another. * Stack: ... string fromIdx toIdx replacement => ... newString */ {"originCmd", 1, 0, 0, {OPERAND_NONE}}, /* Reports which command was the origin (via namespace import chain) * of the command named on the top of the stack. * Stack: ... cmdName => ... fullOriginalCmdName */ {"tclooNext", 2, INT_MIN, 1, {OPERAND_UINT1}}, /* Push the identity of the current TclOO object (i.e., the name of * its current public access command) on the stack. */ {"numericType", 1, 0, 0, {OPERAND_NONE}}, /* Pushes the numeric type code of the word at the top of the stack. * Stack: ... value => ... typeCode */ {NULL, 0, 0, 0, {OPERAND_NONE}} }; /* * Prototypes for procedures defined later in this file: */ static ByteCode * CompileSubstObj(Tcl_Interp *interp, Tcl_Obj *objPtr, int flags); static void DupByteCodeInternalRep(Tcl_Obj *srcPtr, Tcl_Obj *copyPtr); static unsigned char * EncodeCmdLocMap(CompileEnv *envPtr, ByteCode *codePtr, unsigned char *startPtr); static void EnterCmdExtentData(CompileEnv *envPtr, int cmdNumber, int numSrcBytes, int numCodeBytes); static void EnterCmdStartData(CompileEnv *envPtr, int cmdNumber, int srcOffset, int codeOffset); static void FreeByteCodeInternalRep(Tcl_Obj *objPtr); static void FreeSubstCodeInternalRep(Tcl_Obj *objPtr); static int GetCmdLocEncodingSize(CompileEnv *envPtr); static int IsCompactibleCompileEnv(Tcl_Interp *interp, CompileEnv *envPtr); #ifdef TCL_COMPILE_STATS static void RecordByteCodeStats(ByteCode *codePtr); #endif /* TCL_COMPILE_STATS */ static void RegisterAuxDataType(const AuxDataType *typePtr); static int SetByteCodeFromAny(Tcl_Interp *interp, Tcl_Obj *objPtr); static void StartExpanding(CompileEnv *envPtr); static int FormatInstruction(ByteCode *codePtr, const unsigned char *pc, Tcl_Obj *bufferObj); static void PrintSourceToObj(Tcl_Obj *appendObj, const char *stringPtr, int maxChars); static void UpdateStringOfInstName(Tcl_Obj *objPtr); /* * TIP #280: Helper for building the per-word line information of all compiled * commands. */ static void EnterCmdWordData(ExtCmdLoc *eclPtr, int srcOffset, Tcl_Token *tokenPtr, const char *cmd, int len, int numWords, int line, int *clNext, int **lines, CompileEnv *envPtr); static void ReleaseCmdWordData(ExtCmdLoc *eclPtr); /* * The structure below defines the bytecode Tcl object type by means of * procedures that can be invoked by generic object code. */ const Tcl_ObjType tclByteCodeType = { "bytecode", /* name */ FreeByteCodeInternalRep, /* freeIntRepProc */ DupByteCodeInternalRep, /* dupIntRepProc */ NULL, /* updateStringProc */ SetByteCodeFromAny /* setFromAnyProc */ }; /* * The structure below defines a bytecode Tcl object type to hold the * compiled bytecode for the [subst]itution of Tcl values. */ static const Tcl_ObjType substCodeType = { "substcode", /* name */ FreeSubstCodeInternalRep, /* freeIntRepProc */ DupByteCodeInternalRep, /* dupIntRepProc - shared with bytecode */ NULL, /* updateStringProc */ NULL, /* setFromAnyProc */ }; /* * The structure below defines an instruction name Tcl object to allow * reporting of inner contexts in errorstack without string allocation. */ static const Tcl_ObjType tclInstNameType = { "instname", /* name */ NULL, /* freeIntRepProc */ NULL, /* dupIntRepProc */ UpdateStringOfInstName, /* updateStringProc */ NULL, /* setFromAnyProc */ }; /* * Helper macros. */ #define TclIncrUInt4AtPtr(ptr, delta) \ TclStoreInt4AtPtr(TclGetUInt4AtPtr(ptr)+(delta), (ptr)); /* *---------------------------------------------------------------------- * * TclSetByteCodeFromAny -- * * Part of the bytecode Tcl object type implementation. Attempts to * generate an byte code internal form for the Tcl object "objPtr" by * compiling its string representation. This function also takes a hook * procedure that will be invoked to perform any needed post processing * on the compilation results before generating byte codes. interp is * compilation context and may not be NULL. * * Results: * The return value is a standard Tcl object result. If an error occurs * during compilation, an error message is left in the interpreter's * result. * * Side effects: * Frees the old internal representation. If no error occurs, then the * compiled code is stored as "objPtr"s bytecode representation. Also, if * debugging, initializes the "tcl_traceCompile" Tcl variable used to * trace compilations. * *---------------------------------------------------------------------- */ int TclSetByteCodeFromAny( Tcl_Interp *interp, /* The interpreter for which the code is being * compiled. Must not be NULL. */ Tcl_Obj *objPtr, /* The object to make a ByteCode object. */ CompileHookProc *hookProc, /* Procedure to invoke after compilation. */ ClientData clientData) /* Hook procedure private data. */ { Interp *iPtr = (Interp *) interp; CompileEnv compEnv; /* Compilation environment structure allocated * in frame. */ int length, result = TCL_OK; const char *stringPtr; Proc *procPtr = iPtr->compiledProcPtr; ContLineLoc *clLocPtr; #ifdef TCL_COMPILE_DEBUG if (!traceInitialized) { if (Tcl_LinkVar(interp, "tcl_traceCompile", (char *) &tclTraceCompile, TCL_LINK_INT) != TCL_OK) { Tcl_Panic("SetByteCodeFromAny: unable to create link for tcl_traceCompile variable"); } traceInitialized = 1; } #endif stringPtr = TclGetStringFromObj(objPtr, &length); /* * TIP #280: Pick up the CmdFrame in which the BC compiler was invoked and * use to initialize the tracking in the compiler. This information was * stored by TclCompEvalObj and ProcCompileProc. */ TclInitCompileEnv(interp, &compEnv, stringPtr, length, iPtr->invokeCmdFramePtr, iPtr->invokeWord); /* * Now we check if we have data about invisible continuation lines for the * script, and make it available to the compile environment, if so. * * It is not clear if the script Tcl_Obj* can be free'd while the compiler * is using it, leading to the release of the associated ContLineLoc * structure as well. To ensure that the latter doesn't happen we set a * lock on it. We release this lock in the function TclFreeCompileEnv(), * found in this file. The "lineCLPtr" hashtable is managed in the file * "tclObj.c". */ clLocPtr = TclContinuationsGet(objPtr); if (clLocPtr) { compEnv.clNext = &clLocPtr->loc[0]; } TclCompileScript(interp, stringPtr, length, &compEnv); /* * Successful compilation. Add a "done" instruction at the end. */ TclEmitOpcode(INST_DONE, &compEnv); /* * Check for optimizations! * * Test if the generated code is free of most hazards; if so, recompile * but with generation of INST_START_CMD disabled. This produces somewhat * faster code in some cases, and more compact code in more. */ if (Tcl_GetMaster(interp) == NULL && !Tcl_LimitTypeEnabled(interp, TCL_LIMIT_COMMANDS|TCL_LIMIT_TIME) && IsCompactibleCompileEnv(interp, &compEnv)) { TclFreeCompileEnv(&compEnv); iPtr->compiledProcPtr = procPtr; TclInitCompileEnv(interp, &compEnv, stringPtr, length, iPtr->invokeCmdFramePtr, iPtr->invokeWord); if (clLocPtr) { compEnv.clNext = &clLocPtr->loc[0]; } compEnv.atCmdStart = 2; /* The disabling magic. */ TclCompileScript(interp, stringPtr, length, &compEnv); assert (compEnv.atCmdStart > 1); TclEmitOpcode(INST_DONE, &compEnv); assert (compEnv.atCmdStart > 1); } /* * Apply some peephole optimizations that can cross specific/generic * instruction generator boundaries. */ if (iPtr->extra.optimizer) { (iPtr->extra.optimizer)(&compEnv); } /* * Invoke the compilation hook procedure if one exists. */ if (hookProc) { result = hookProc(interp, &compEnv, clientData); } /* * Change the object into a ByteCode object. Ownership of the literal * objects and aux data items is given to the ByteCode object. */ #ifdef TCL_COMPILE_DEBUG TclVerifyLocalLiteralTable(&compEnv); #endif /*TCL_COMPILE_DEBUG*/ if (result == TCL_OK) { TclInitByteCodeObj(objPtr, &compEnv); #ifdef TCL_COMPILE_DEBUG if (tclTraceCompile >= 2) { TclPrintByteCodeObj(interp, objPtr); fflush(stdout); } #endif /* TCL_COMPILE_DEBUG */ } TclFreeCompileEnv(&compEnv); return result; } /* *----------------------------------------------------------------------- * * SetByteCodeFromAny -- * * Part of the bytecode Tcl object type implementation. Attempts to * generate an byte code internal form for the Tcl object "objPtr" by * compiling its string representation. * * Results: * The return value is a standard Tcl object result. If an error occurs * during compilation, an error message is left in the interpreter's * result unless "interp" is NULL. * * Side effects: * Frees the old internal representation. If no error occurs, then the * compiled code is stored as "objPtr"s bytecode representation. Also, if * debugging, initializes the "tcl_traceCompile" Tcl variable used to * trace compilations. * *---------------------------------------------------------------------- */ static int SetByteCodeFromAny( Tcl_Interp *interp, /* The interpreter for which the code is being * compiled. Must not be NULL. */ Tcl_Obj *objPtr) /* The object to make a ByteCode object. */ { if (interp == NULL) { return TCL_ERROR; } return TclSetByteCodeFromAny(interp, objPtr, NULL, NULL); } /* *---------------------------------------------------------------------- * * DupByteCodeInternalRep -- * * Part of the bytecode Tcl object type implementation. However, it does * not copy the internal representation of a bytecode Tcl_Obj, but * instead leaves the new object untyped (with a NULL type pointer). * Code will be compiled for the new object only if necessary. * * Results: * None. * * Side effects: * None. * *---------------------------------------------------------------------- */ static void DupByteCodeInternalRep( Tcl_Obj *srcPtr, /* Object with internal rep to copy. */ Tcl_Obj *copyPtr) /* Object with internal rep to set. */ { return; } /* *---------------------------------------------------------------------- * * FreeByteCodeInternalRep -- * * Part of the bytecode Tcl object type implementation. Frees the storage * associated with a bytecode object's internal representation unless its * code is actively being executed. * * Results: * None. * * Side effects: * The bytecode object's internal rep is marked invalid and its code gets * freed unless the code is actively being executed. In that case the * cleanup is delayed until the last execution of the code completes. * *---------------------------------------------------------------------- */ static void FreeByteCodeInternalRep( register Tcl_Obj *objPtr) /* Object whose internal rep to free. */ { register ByteCode *codePtr = objPtr->internalRep.twoPtrValue.ptr1; objPtr->typePtr = NULL; codePtr->refCount--; if (codePtr->refCount <= 0) { TclCleanupByteCode(codePtr); } } /* *---------------------------------------------------------------------- * * TclCleanupByteCode -- * * This procedure does all the real work of freeing up a bytecode * object's ByteCode structure. It's called only when the structure's * reference count becomes zero. * * Results: * None. * * Side effects: * Frees objPtr's bytecode internal representation and sets its type NULL * Also releases its literals and frees its auxiliary data items. * *---------------------------------------------------------------------- */ void TclCleanupByteCode( register ByteCode *codePtr) /* Points to the ByteCode to free. */ { Tcl_Interp *interp = (Tcl_Interp *) *codePtr->interpHandle; Interp *iPtr = (Interp *) interp; int numLitObjects = codePtr->numLitObjects; int numAuxDataItems = codePtr->numAuxDataItems; register Tcl_Obj **objArrayPtr, *objPtr; register const AuxData *auxDataPtr; int i; #ifdef TCL_COMPILE_STATS if (interp != NULL) { ByteCodeStats *statsPtr; Tcl_Time destroyTime; int lifetimeSec, lifetimeMicroSec, log2; statsPtr = &iPtr->stats; statsPtr->numByteCodesFreed++; statsPtr->currentSrcBytes -= (double) codePtr->numSrcBytes; statsPtr->currentByteCodeBytes -= (double) codePtr->structureSize; statsPtr->currentInstBytes -= (double) codePtr->numCodeBytes; statsPtr->currentLitBytes -= (double) codePtr->numLitObjects * sizeof(Tcl_Obj *); statsPtr->currentExceptBytes -= (double) codePtr->numExceptRanges * sizeof(ExceptionRange); statsPtr->currentAuxBytes -= (double) codePtr->numAuxDataItems * sizeof(AuxData); statsPtr->currentCmdMapBytes -= (double) codePtr->numCmdLocBytes; Tcl_GetTime(&destroyTime); lifetimeSec = destroyTime.sec - codePtr->createTime.sec; if (lifetimeSec > 2000) { /* avoid overflow */ lifetimeSec = 2000; } lifetimeMicroSec = 1000000 * lifetimeSec + (destroyTime.usec - codePtr->createTime.usec); log2 = TclLog2(lifetimeMicroSec); if (log2 > 31) { log2 = 31; } statsPtr->lifetimeCount[log2]++; } #endif /* TCL_COMPILE_STATS */ /* * A single heap object holds the ByteCode structure and its code, object, * command location, and auxiliary data arrays. This means we only need to * 1) decrement the ref counts of the LiteralEntry's in its literal array, * 2) call the free procs for the auxiliary data items, 3) free the * localCache if it is unused, and finally 4) free the ByteCode * structure's heap object. * * The case for TCL_BYTECODE_PRECOMPILED (precompiled ByteCodes, like * those generated from tbcload) is special, as they doesn't make use of * the global literal table. They instead maintain private references to * their literals which must be decremented. * * In order to insure a proper and efficient cleanup of the literal array * when it contains non-shared literals [Bug 983660], we also distinguish * the case of an interpreter being deleted (signaled by interp == NULL). * Also, as the interp deletion will remove the global literal table * anyway, we avoid the extra cost of updating it for each literal being * released. */ if (codePtr->flags & TCL_BYTECODE_PRECOMPILED) { objArrayPtr = codePtr->objArrayPtr; for (i = 0; i < numLitObjects; i++) { objPtr = *objArrayPtr; if (objPtr) { Tcl_DecrRefCount(objPtr); } objArrayPtr++; } codePtr->numLitObjects = 0; } else { objArrayPtr = codePtr->objArrayPtr; while (numLitObjects--) { /* TclReleaseLiteral calls Tcl_DecrRefCount() for us */ TclReleaseLiteral(interp, *objArrayPtr++); } } auxDataPtr = codePtr->auxDataArrayPtr; for (i = 0; i < numAuxDataItems; i++) { if (auxDataPtr->type->freeProc != NULL) { auxDataPtr->type->freeProc(auxDataPtr->clientData); } auxDataPtr++; } /* * TIP #280. Release the location data associated with this byte code * structure, if any. NOTE: The interp we belong to may be gone already, * and the data with it. * * See also tclBasic.c, DeleteInterpProc */ if (iPtr) { Tcl_HashEntry *hePtr = Tcl_FindHashEntry(iPtr->lineBCPtr, (char *) codePtr); if (hePtr) { ReleaseCmdWordData(Tcl_GetHashValue(hePtr)); Tcl_DeleteHashEntry(hePtr); } } if (codePtr->localCachePtr && (--codePtr->localCachePtr->refCount == 0)) { TclFreeLocalCache(interp, codePtr->localCachePtr); } TclHandleRelease(codePtr->interpHandle); ckfree(codePtr); } /* * --------------------------------------------------------------------- * * IsCompactibleCompileEnv -- * * Checks to see if we may apply some basic compaction optimizations to a * piece of bytecode. Idempotent. * * --------------------------------------------------------------------- */ static int IsCompactibleCompileEnv( Tcl_Interp *interp, CompileEnv *envPtr) { unsigned char *pc; int size; /* * Special: procedures in the '::tcl' namespace (or its children) are * considered to be well-behaved and so can have compaction applied even * if it would otherwise be invalid. */ if (envPtr->procPtr != NULL && envPtr->procPtr->cmdPtr != NULL && envPtr->procPtr->cmdPtr->nsPtr != NULL) { Namespace *nsPtr = envPtr->procPtr->cmdPtr->nsPtr; if (strcmp(nsPtr->fullName, "::tcl") == 0 || strncmp(nsPtr->fullName, "::tcl::", 7) == 0) { return 1; } } /* * Go through and ensure that no operation involved can cause a desired * change of bytecode sequence during running. This comes down to ensuring * that there are no mapped variables (due to traces) or calls to external * commands (traces, [uplevel] trickery). This is actually a very * conservative check; it turns down a lot of code that is OK in practice. */ for (pc = envPtr->codeStart ; pc < envPtr->codeNext ; pc += size) { switch (*pc) { /* Invokes */ case INST_INVOKE_STK1: case INST_INVOKE_STK4: case INST_INVOKE_EXPANDED: case INST_INVOKE_REPLACE: return 0; /* Runtime evals */ case INST_EVAL_STK: case INST_EXPR_STK: case INST_YIELD: return 0; /* Upvars */ case INST_UPVAR: case INST_NSUPVAR: case INST_VARIABLE: return 0; default: size = tclInstructionTable[*pc].numBytes; assert (size > 0); break; } } return 1; } /* *---------------------------------------------------------------------- * * Tcl_SubstObj -- * * This function performs the substitutions specified on the given string * as described in the user documentation for the "subst" Tcl command. * * Results: * A Tcl_Obj* containing the substituted string, or NULL to indicate that * an error occurred. * * Side effects: * See the user documentation. * *---------------------------------------------------------------------- */ Tcl_Obj * Tcl_SubstObj( Tcl_Interp *interp, /* Interpreter in which substitution occurs */ Tcl_Obj *objPtr, /* The value to be substituted. */ int flags) /* What substitutions to do. */ { NRE_callback *rootPtr = TOP_CB(interp); if (TclNRRunCallbacks(interp, Tcl_NRSubstObj(interp, objPtr, flags), rootPtr) != TCL_OK) { return NULL; } return Tcl_GetObjResult(interp); } /* *---------------------------------------------------------------------- * * Tcl_NRSubstObj -- * * Request substitution of a Tcl value by the NR stack. * * Results: * Returns TCL_OK. * * Side effects: * Compiles objPtr into bytecode that performs the substitutions as * governed by flags and places callbacks on the NR stack to execute * the bytecode and store the result in the interp. * *---------------------------------------------------------------------- */ int Tcl_NRSubstObj( Tcl_Interp *interp, Tcl_Obj *objPtr, int flags) { ByteCode *codePtr = CompileSubstObj(interp, objPtr, flags); /* TODO: Confirm we do not need this. */ /* Tcl_ResetResult(interp); */ return TclNRExecuteByteCode(interp, codePtr); } /* *---------------------------------------------------------------------- * * CompileSubstObj -- * * Compile a Tcl value into ByteCode implementing its substitution, as * governed by flags. * * Results: * A (ByteCode *) is returned pointing to the resulting ByteCode. * The caller must manage its refCount and arrange for a call to * TclCleanupByteCode() when the last reference disappears. * * Side effects: * The Tcl_ObjType of objPtr is changed to the "substcode" type, and the * ByteCode and governing flags value are kept in the internal rep for * faster operations the next time CompileSubstObj is called on the same * value. * *---------------------------------------------------------------------- */ static ByteCode * CompileSubstObj( Tcl_Interp *interp, Tcl_Obj *objPtr, int flags) { Interp *iPtr = (Interp *) interp; ByteCode *codePtr = NULL; if (objPtr->typePtr == &substCodeType) { Namespace *nsPtr = iPtr->varFramePtr->nsPtr; codePtr = objPtr->internalRep.ptrAndLongRep.ptr; if ((unsigned long)flags != objPtr->internalRep.ptrAndLongRep.value || ((Interp *) *codePtr->interpHandle != iPtr) || (codePtr->compileEpoch != iPtr->compileEpoch) || (codePtr->nsPtr != nsPtr) || (codePtr->nsEpoch != nsPtr->resolverEpoch) || (codePtr->localCachePtr != iPtr->varFramePtr->localCachePtr)) { FreeSubstCodeInternalRep(objPtr); } } if (objPtr->typePtr != &substCodeType) { CompileEnv compEnv; int numBytes; const char *bytes = Tcl_GetStringFromObj(objPtr, &numBytes); /* TODO: Check for more TIP 280 */ TclInitCompileEnv(interp, &compEnv, bytes, numBytes, NULL, 0); TclSubstCompile(interp, bytes, numBytes, flags, 1, &compEnv); TclEmitOpcode(INST_DONE, &compEnv); TclInitByteCodeObj(objPtr, &compEnv); objPtr->typePtr = &substCodeType; TclFreeCompileEnv(&compEnv); codePtr = objPtr->internalRep.twoPtrValue.ptr1; objPtr->internalRep.ptrAndLongRep.ptr = codePtr; objPtr->internalRep.ptrAndLongRep.value = flags; if (iPtr->varFramePtr->localCachePtr) { codePtr->localCachePtr = iPtr->varFramePtr->localCachePtr; codePtr->localCachePtr->refCount++; } #ifdef TCL_COMPILE_DEBUG if (tclTraceCompile >= 2) { TclPrintByteCodeObj(interp, objPtr); fflush(stdout); } #endif /* TCL_COMPILE_DEBUG */ } return codePtr; } /* *---------------------------------------------------------------------- * * FreeSubstCodeInternalRep -- * * Part of the substcode Tcl object type implementation. Frees the * storage associated with a substcode object's internal representation * unless its code is actively being executed. * * Results: * None. * * Side effects: * The substcode object's internal rep is marked invalid and its code * gets freed unless the code is actively being executed. In that case * the cleanup is delayed until the last execution of the code completes. * *---------------------------------------------------------------------- */ static void FreeSubstCodeInternalRep( register Tcl_Obj *objPtr) /* Object whose internal rep to free. */ { register ByteCode *codePtr = objPtr->internalRep.ptrAndLongRep.ptr; objPtr->typePtr = NULL; codePtr->refCount--; if (codePtr->refCount <= 0) { TclCleanupByteCode(codePtr); } } static void ReleaseCmdWordData( ExtCmdLoc *eclPtr) { int i; if (eclPtr->type == TCL_LOCATION_SOURCE) { Tcl_DecrRefCount(eclPtr->path); } for (i=0 ; i<eclPtr->nuloc ; i++) { ckfree((char *) eclPtr->loc[i].line); } if (eclPtr->loc != NULL) { ckfree((char *) eclPtr->loc); } ckfree((char *) eclPtr); } /* *---------------------------------------------------------------------- * * TclInitCompileEnv -- * * Initializes a CompileEnv compilation environment structure for the * compilation of a string in an interpreter. * * Results: * None. * * Side effects: * The CompileEnv structure is initialized. * *---------------------------------------------------------------------- */ void TclInitCompileEnv( Tcl_Interp *interp, /* The interpreter for which a CompileEnv * structure is initialized. */ register CompileEnv *envPtr,/* Points to the CompileEnv structure to * initialize. */ const char *stringPtr, /* The source string to be compiled. */ int numBytes, /* Number of bytes in source string. */ const CmdFrame *invoker, /* Location context invoking the bcc */ int word) /* Index of the word in that context getting * compiled */ { Interp *iPtr = (Interp *) interp; assert(tclInstructionTable[LAST_INST_OPCODE+1].name == NULL); envPtr->iPtr = iPtr; envPtr->source = stringPtr; envPtr->numSrcBytes = numBytes; envPtr->procPtr = iPtr->compiledProcPtr; iPtr->compiledProcPtr = NULL; envPtr->numCommands = 0; envPtr->exceptDepth = 0; envPtr->maxExceptDepth = 0; envPtr->maxStackDepth = 0; envPtr->currStackDepth = 0; TclInitLiteralTable(&envPtr->localLitTable); envPtr->codeStart = envPtr->staticCodeSpace; envPtr->codeNext = envPtr->codeStart; envPtr->codeEnd = envPtr->codeStart + COMPILEENV_INIT_CODE_BYTES; envPtr->mallocedCodeArray = 0; envPtr->literalArrayPtr = envPtr->staticLiteralSpace; envPtr->literalArrayNext = 0; envPtr->literalArrayEnd = COMPILEENV_INIT_NUM_OBJECTS; envPtr->mallocedLiteralArray = 0; envPtr->exceptArrayPtr = envPtr->staticExceptArraySpace; envPtr->exceptAuxArrayPtr = envPtr->staticExAuxArraySpace; envPtr->exceptArrayNext = 0; envPtr->exceptArrayEnd = COMPILEENV_INIT_EXCEPT_RANGES; envPtr->mallocedExceptArray = 0; envPtr->cmdMapPtr = envPtr->staticCmdMapSpace; envPtr->cmdMapEnd = COMPILEENV_INIT_CMD_MAP_SIZE; envPtr->mallocedCmdMap = 0; envPtr->atCmdStart = 1; envPtr->expandCount = 0; /* * TIP #280: Set up the extended command location information, based on * the context invoking the byte code compiler. This structure is used to * keep the per-word line information for all compiled commands. * * See also tclBasic.c, TclEvalObjEx, for the equivalent code in the * non-compiling evaluator */ envPtr->extCmdMapPtr = ckalloc(sizeof(ExtCmdLoc)); envPtr->extCmdMapPtr->loc = NULL; envPtr->extCmdMapPtr->nloc = 0; envPtr->extCmdMapPtr->nuloc = 0; envPtr->extCmdMapPtr->path = NULL; if (invoker == NULL) { /* * Initialize the compiler for relative counting in case of a * dynamic context. */ envPtr->line = 1; if (iPtr->evalFlags & TCL_EVAL_FILE) { iPtr->evalFlags &= ~TCL_EVAL_FILE; envPtr->extCmdMapPtr->type = TCL_LOCATION_SOURCE; if (iPtr->scriptFile) { /* * Normalization here, to have the correct pwd. Should have * negligible impact on performance, as the norm should have * been done already by the 'source' invoking us, and it * caches the result. */ Tcl_Obj *norm = Tcl_FSGetNormalizedPath(interp, iPtr->scriptFile); if (norm == NULL) { /* * Error message in the interp result. No place to put it. * And no place to serve the error itself to either. Fake * a path, empty string. */ TclNewLiteralStringObj(envPtr->extCmdMapPtr->path, ""); } else { envPtr->extCmdMapPtr->path = norm; } } else { TclNewLiteralStringObj(envPtr->extCmdMapPtr->path, ""); } Tcl_IncrRefCount(envPtr->extCmdMapPtr->path); } else { envPtr->extCmdMapPtr->type = (envPtr->procPtr ? TCL_LOCATION_PROC : TCL_LOCATION_BC); } } else { /* * Initialize the compiler using the context, making counting absolute * to that context. Note that the context can be byte code execution. * In that case we have to fill out the missing pieces (line, path, * ...) which may make change the type as well. */ CmdFrame *ctxPtr = TclStackAlloc(interp, sizeof(CmdFrame)); int pc = 0; *ctxPtr = *invoker; if (invoker->type == TCL_LOCATION_BC) { /* * Note: Type BC => ctx.data.eval.path is not used. * ctx.data.tebc.codePtr is used instead. */ TclGetSrcInfoForPc(ctxPtr); pc = 1; } if ((ctxPtr->nline <= word) || (ctxPtr->line[word] < 0)) { /* * Word is not a literal, relative counting. */ envPtr->line = 1; envPtr->extCmdMapPtr->type = (envPtr->procPtr ? TCL_LOCATION_PROC : TCL_LOCATION_BC); if (pc && (ctxPtr->type == TCL_LOCATION_SOURCE)) { /* * The reference made by 'TclGetSrcInfoForPc' is dead. */ Tcl_DecrRefCount(ctxPtr->data.eval.path); } } else { envPtr->line = ctxPtr->line[word]; envPtr->extCmdMapPtr->type = ctxPtr->type; if (ctxPtr->type == TCL_LOCATION_SOURCE) { envPtr->extCmdMapPtr->path = ctxPtr->data.eval.path; if (pc) { /* * The reference 'TclGetSrcInfoForPc' made is transfered. */ ctxPtr->data.eval.path = NULL; } else { /* * We have a new reference here. */ Tcl_IncrRefCount(envPtr->extCmdMapPtr->path); } } } TclStackFree(interp, ctxPtr); } envPtr->extCmdMapPtr->start = envPtr->line; /* * Initialize the data about invisible continuation lines as empty, i.e. * not used. The caller (TclSetByteCodeFromAny) will set this up, if such * data is available. */ envPtr->clNext = NULL; envPtr->auxDataArrayPtr = envPtr->staticAuxDataArraySpace; envPtr->auxDataArrayNext = 0; envPtr->auxDataArrayEnd = COMPILEENV_INIT_AUX_DATA_SIZE; envPtr->mallocedAuxDataArray = 0; } /* *---------------------------------------------------------------------- * * TclFreeCompileEnv -- * * Free the storage allocated in a CompileEnv compilation environment * structure. * * Results: * None. * * Side effects: * Allocated storage in the CompileEnv structure is freed. Note that its * local literal table is not deleted and its literal objects are not * released. In addition, storage referenced by its auxiliary data items * is not freed. This is done so that, when compilation is successful, * "ownership" of these objects and aux data items is handed over to the * corresponding ByteCode structure. * *---------------------------------------------------------------------- */ void TclFreeCompileEnv( register CompileEnv *envPtr)/* Points to the CompileEnv structure. */ { if (envPtr->localLitTable.buckets != envPtr->localLitTable.staticBuckets){ ckfree(envPtr->localLitTable.buckets); envPtr->localLitTable.buckets = envPtr->localLitTable.staticBuckets; } if (envPtr->iPtr) { /* * We never converted to Bytecode, so free the things we would * have transferred to it. */ int i; LiteralEntry *entryPtr = envPtr->literalArrayPtr; AuxData *auxDataPtr = envPtr->auxDataArrayPtr; for (i = 0; i < envPtr->literalArrayNext; i++) { TclReleaseLiteral((Tcl_Interp *)envPtr->iPtr, entryPtr->objPtr); entryPtr++; } #ifdef TCL_COMPILE_DEBUG TclVerifyGlobalLiteralTable(envPtr->iPtr); #endif /*TCL_COMPILE_DEBUG*/ for (i = 0; i < envPtr->auxDataArrayNext; i++) { if (auxDataPtr->type->freeProc != NULL) { auxDataPtr->type->freeProc(auxDataPtr->clientData); } auxDataPtr++; } } if (envPtr->mallocedCodeArray) { ckfree(envPtr->codeStart); } if (envPtr->mallocedLiteralArray) { ckfree(envPtr->literalArrayPtr); } if (envPtr->mallocedExceptArray) { ckfree(envPtr->exceptArrayPtr); ckfree(envPtr->exceptAuxArrayPtr); } if (envPtr->mallocedCmdMap) { ckfree(envPtr->cmdMapPtr); } if (envPtr->mallocedAuxDataArray) { ckfree(envPtr->auxDataArrayPtr); } if (envPtr->extCmdMapPtr) { ReleaseCmdWordData(envPtr->extCmdMapPtr); envPtr->extCmdMapPtr = NULL; } } /* *---------------------------------------------------------------------- * * TclWordKnownAtCompileTime -- * * Test whether the value of a token is completely known at compile time. * * Results: * Returns true if the tokenPtr argument points to a word value that is * completely known at compile time. Generally, values that are known at * compile time can be compiled to their values, while values that cannot * be known until substitution at runtime must be compiled to bytecode * instructions that perform that substitution. For several commands, * whether or not arguments are known at compile time determine whether * it is worthwhile to compile at all. * * Side effects: * When returning true, appends the known value of the word to the * unshared Tcl_Obj (*valuePtr), unless valuePtr is NULL. * *---------------------------------------------------------------------- */ int TclWordKnownAtCompileTime( Tcl_Token *tokenPtr, /* Points to Tcl_Token we should check */ Tcl_Obj *valuePtr) /* If not NULL, points to an unshared Tcl_Obj * to which we should append the known value * of the word. */ { int numComponents = tokenPtr->numComponents; Tcl_Obj *tempPtr = NULL; if (tokenPtr->type == TCL_TOKEN_SIMPLE_WORD) { if (valuePtr != NULL) { Tcl_AppendToObj(valuePtr, tokenPtr[1].start, tokenPtr[1].size); } return 1; } if (tokenPtr->type != TCL_TOKEN_WORD) { return 0; } tokenPtr++; if (valuePtr != NULL) { tempPtr = Tcl_NewObj(); Tcl_IncrRefCount(tempPtr); } while (numComponents--) { switch (tokenPtr->type) { case TCL_TOKEN_TEXT: if (tempPtr != NULL) { Tcl_AppendToObj(tempPtr, tokenPtr->start, tokenPtr->size); } break; case TCL_TOKEN_BS: if (tempPtr != NULL) { char utfBuf[TCL_UTF_MAX]; int length = TclParseBackslash(tokenPtr->start, tokenPtr->size, NULL, utfBuf); Tcl_AppendToObj(tempPtr, utfBuf, length); } break; default: if (tempPtr != NULL) { Tcl_DecrRefCount(tempPtr); } return 0; } tokenPtr++; } if (valuePtr != NULL) { Tcl_AppendObjToObj(valuePtr, tempPtr); Tcl_DecrRefCount(tempPtr); } return 1; } /* *---------------------------------------------------------------------- * * TclCompileScript -- * * Compile a Tcl script in a string. * * Results: * The return value is TCL_OK on a successful compilation and TCL_ERROR * on failure. If TCL_ERROR is returned, then the interpreter's result * contains an error message. * * Side effects: * Adds instructions to envPtr to evaluate the script at runtime. * *---------------------------------------------------------------------- */ static int ExpandRequested( Tcl_Token *tokenPtr, int numWords) { /* Determine whether any words of the command require expansion */ while (numWords--) { if (tokenPtr->type == TCL_TOKEN_EXPAND_WORD) { return 1; } tokenPtr = TokenAfter(tokenPtr); } return 0; } static void CompileCmdLiteral( Tcl_Interp *interp, Tcl_Obj *cmdObj, CompileEnv *envPtr) { int numBytes; const char *bytes = Tcl_GetStringFromObj(cmdObj, &numBytes); int cmdLitIdx = TclRegisterNewCmdLiteral(envPtr, bytes, numBytes); Command *cmdPtr = (Command *) Tcl_GetCommandFromObj(interp, cmdObj); if (cmdPtr) { TclSetCmdNameObj(interp, TclFetchLiteral(envPtr, cmdLitIdx), cmdPtr); } TclEmitPush(cmdLitIdx, envPtr); } void TclCompileInvocation( Tcl_Interp *interp, Tcl_Token *tokenPtr, Tcl_Obj *cmdObj, int numWords, CompileEnv *envPtr) { int wordIdx = 0, depth = TclGetStackDepth(envPtr); DefineLineInformation; if (cmdObj) { CompileCmdLiteral(interp, cmdObj, envPtr); wordIdx = 1; tokenPtr = TokenAfter(tokenPtr); } for (; wordIdx < numWords; wordIdx++, tokenPtr = TokenAfter(tokenPtr)) { int objIdx; SetLineInformation(wordIdx); if (tokenPtr->type != TCL_TOKEN_SIMPLE_WORD) { CompileTokens(envPtr, tokenPtr, interp); continue; } objIdx = TclRegisterNewLiteral(envPtr, tokenPtr[1].start, tokenPtr[1].size); if (envPtr->clNext) { TclContinuationsEnterDerived(TclFetchLiteral(envPtr, objIdx), tokenPtr[1].start - envPtr->source, envPtr->clNext); } TclEmitPush(objIdx, envPtr); } if (wordIdx <= 255) { TclEmitInvoke(envPtr, INST_INVOKE_STK1, wordIdx); } else { TclEmitInvoke(envPtr, INST_INVOKE_STK4, wordIdx); } TclCheckStackDepth(depth+1, envPtr); } static void CompileExpanded( Tcl_Interp *interp, Tcl_Token *tokenPtr, Tcl_Obj *cmdObj, int numWords, CompileEnv *envPtr) { int wordIdx = 0; DefineLineInformation; int depth = TclGetStackDepth(envPtr); StartExpanding(envPtr); if (cmdObj) { CompileCmdLiteral(interp, cmdObj, envPtr); wordIdx = 1; tokenPtr = TokenAfter(tokenPtr); } for (; wordIdx < numWords; wordIdx++, tokenPtr = TokenAfter(tokenPtr)) { int objIdx; SetLineInformation(wordIdx); if (tokenPtr->type != TCL_TOKEN_SIMPLE_WORD) { CompileTokens(envPtr, tokenPtr, interp); if (tokenPtr->type == TCL_TOKEN_EXPAND_WORD) { TclEmitInstInt4(INST_EXPAND_STKTOP, envPtr->currStackDepth, envPtr); } continue; } objIdx = TclRegisterNewLiteral(envPtr, tokenPtr[1].start, tokenPtr[1].size); if (envPtr->clNext) { TclContinuationsEnterDerived(TclFetchLiteral(envPtr, objIdx), tokenPtr[1].start - envPtr->source, envPtr->clNext); } TclEmitPush(objIdx, envPtr); } /* * The stack depth during argument expansion can only be managed at * runtime, as the number of elements in the expanded lists is not known * at compile time. We adjust here the stack depth estimate so that it is * correct after the command with expanded arguments returns. * * The end effect of this command's invocation is that all the words of * the command are popped from the stack, and the result is pushed: the * stack top changes by (1-wordIdx). * * Note that the estimates are not correct while the command is being * prepared and run, INST_EXPAND_STKTOP is not stack-neutral in general. */ TclEmitInvoke(envPtr, INST_INVOKE_EXPANDED, wordIdx); TclCheckStackDepth(depth+1, envPtr); } static int CompileCmdCompileProc( Tcl_Interp *interp, Tcl_Parse *parsePtr, Command *cmdPtr, CompileEnv *envPtr) { int unwind = 0, incrOffset = -1; DefineLineInformation; int depth = TclGetStackDepth(envPtr); /* * Emit of the INST_START_CMD instruction is controlled by the value of * envPtr->atCmdStart: * * atCmdStart == 2 : We are not using the INST_START_CMD instruction. * atCmdStart == 1 : INST_START_CMD was the last instruction emitted. * : We do not need to emit another. Instead we * : increment the number of cmds started at it (except * : for the special case at the start of a script.) * atCmdStart == 0 : The last instruction was something else. We need * : to emit INST_START_CMD here. */ switch (envPtr->atCmdStart) { case 0: unwind = tclInstructionTable[INST_START_CMD].numBytes; TclEmitInstInt4(INST_START_CMD, 0, envPtr); incrOffset = envPtr->codeNext - envPtr->codeStart; TclEmitInt4(0, envPtr); break; case 1: if (envPtr->codeNext > envPtr->codeStart) { incrOffset = envPtr->codeNext - 4 - envPtr->codeStart; } break; case 2: /* Nothing to do */ ; } if (TCL_OK == TclAttemptCompileProc(interp, parsePtr, 1, cmdPtr, envPtr)) { if (incrOffset >= 0) { /* * We successfully compiled a command. Increment the number of * commands that start at the currently active INST_START_CMD. */ unsigned char *incrPtr = envPtr->codeStart + incrOffset; unsigned char *startPtr = incrPtr - 5; TclIncrUInt4AtPtr(incrPtr, 1); if (unwind) { /* We started the INST_START_CMD. Record the code length. */ TclStoreInt4AtPtr(envPtr->codeNext - startPtr, startPtr + 1); } } TclCheckStackDepth(depth+1, envPtr); return TCL_OK; } envPtr->codeNext -= unwind; /* Unwind INST_START_CMD */ /* * Throw out any line information generated by the failed compile attempt. */ while (mapPtr->nuloc - 1 > eclIndex) { mapPtr->nuloc--; ckfree(mapPtr->loc[mapPtr->nuloc].line); mapPtr->loc[mapPtr->nuloc].line = NULL; } /* * Reset the index of next command. Toss out any from failed nested * partial compiles. */ envPtr->numCommands = mapPtr->nuloc; return TCL_ERROR; } static int CompileCommandTokens( Tcl_Interp *interp, Tcl_Parse *parsePtr, CompileEnv *envPtr) { Interp *iPtr = (Interp *) interp; Tcl_Token *tokenPtr = parsePtr->tokenPtr; ExtCmdLoc *eclPtr = envPtr->extCmdMapPtr; Tcl_Obj *cmdObj = Tcl_NewObj(); Command *cmdPtr = NULL; int code = TCL_ERROR; int cmdKnown, expand = -1; int *wlines, wlineat; int cmdLine = envPtr->line; int *clNext = envPtr->clNext; int cmdIdx = envPtr->numCommands; int startCodeOffset = envPtr->codeNext - envPtr->codeStart; int depth = TclGetStackDepth(envPtr); assert (parsePtr->numWords > 0); /* Pre-Compile */ envPtr->numCommands++; EnterCmdStartData(envPtr, cmdIdx, parsePtr->commandStart - envPtr->source, startCodeOffset); /* * TIP #280. Scan the words and compute the extended location information. * The map first contain full per-word line information for use by the * compiler. This is later replaced by a reduced form which signals * non-literal words, stored in 'wlines'. */ EnterCmdWordData(eclPtr, parsePtr->commandStart - envPtr->source, parsePtr->tokenPtr, parsePtr->commandStart, parsePtr->commandSize, parsePtr->numWords, cmdLine, clNext, &wlines, envPtr); wlineat = eclPtr->nuloc - 1; envPtr->line = eclPtr->loc[wlineat].line[0]; envPtr->clNext = eclPtr->loc[wlineat].next[0]; /* Do we know the command word? */ Tcl_IncrRefCount(cmdObj); tokenPtr = parsePtr->tokenPtr; cmdKnown = TclWordKnownAtCompileTime(tokenPtr, cmdObj); /* Is this a command we should (try to) compile with a compileProc ? */ if (cmdKnown && !(iPtr->flags & DONT_COMPILE_CMDS_INLINE)) { cmdPtr = (Command *) Tcl_GetCommandFromObj(interp, cmdObj); if (cmdPtr) { /* * Found a command. Test the ways we can be told not to attempt * to compile it. */ if ((cmdPtr->compileProc == NULL) || (cmdPtr->nsPtr->flags & NS_SUPPRESS_COMPILATION) || (cmdPtr->flags & CMD_HAS_EXEC_TRACES)) { cmdPtr = NULL; } } if (cmdPtr && !(cmdPtr->flags & CMD_COMPILES_EXPANDED)) { expand = ExpandRequested(parsePtr->tokenPtr, parsePtr->numWords); if (expand) { /* We need to expand, but compileProc cannot. */ cmdPtr = NULL; } } } /* If cmdPtr != NULL, we will try to call cmdPtr->compileProc */ if (cmdPtr) { code = CompileCmdCompileProc(interp, parsePtr, cmdPtr, envPtr); } if (code == TCL_ERROR) { if (expand < 0) { expand = ExpandRequested(parsePtr->tokenPtr, parsePtr->numWords); } if (expand) { CompileExpanded(interp, parsePtr->tokenPtr, cmdKnown ? cmdObj : NULL, parsePtr->numWords, envPtr); } else { TclCompileInvocation(interp, parsePtr->tokenPtr, cmdKnown ? cmdObj : NULL, parsePtr->numWords, envPtr); } } Tcl_DecrRefCount(cmdObj); TclEmitOpcode(INST_POP, envPtr); EnterCmdExtentData(envPtr, cmdIdx, parsePtr->term - parsePtr->commandStart, (envPtr->codeNext-envPtr->codeStart) - startCodeOffset); /* * TIP #280: Free full form of per-word line data and insert the reduced * form now */ envPtr->line = cmdLine; envPtr->clNext = clNext; ckfree(eclPtr->loc[wlineat].line); ckfree(eclPtr->loc[wlineat].next); eclPtr->loc[wlineat].line = wlines; eclPtr->loc[wlineat].next = NULL; TclCheckStackDepth(depth, envPtr); return cmdIdx; } void TclCompileScript( Tcl_Interp *interp, /* Used for error and status reporting. Also * serves as context for finding and compiling * commands. May not be NULL. */ const char *script, /* The source script to compile. */ int numBytes, /* Number of bytes in script. If < 0, the * script consists of all bytes up to the * first null character. */ CompileEnv *envPtr) /* Holds resulting instructions. */ { int lastCmdIdx = -1; /* Index into envPtr->cmdMapPtr of the last * command this routine compiles into bytecode. * Initial value of -1 indicates this routine * has not yet generated any bytecode. */ const char *p = script; /* Where we are in our compile. */ int depth = TclGetStackDepth(envPtr); if (envPtr->iPtr == NULL) { Tcl_Panic("TclCompileScript() called on uninitialized CompileEnv"); } /* Each iteration compiles one command from the script. */ while (numBytes > 0) { Tcl_Parse parse; const char *next; if (TCL_OK != Tcl_ParseCommand(interp, p, numBytes, 0, &parse)) { /* * Compile bytecodes to report the parse error at runtime. */ Tcl_LogCommandInfo(interp, script, parse.commandStart, parse.term + 1 - parse.commandStart); TclCompileSyntaxError(interp, envPtr); return; } #ifdef TCL_COMPILE_DEBUG /* * If tracing, print a line for each top level command compiled. * TODO: Suppress when numWords == 0 ? */ if ((tclTraceCompile >= 1) && (envPtr->procPtr == NULL)) { int commandLength = parse.term - parse.commandStart; fprintf(stdout, " Compiling: "); TclPrintSource(stdout, parse.commandStart, TclMin(commandLength, 55)); fprintf(stdout, "\n"); } #endif /* * TIP #280: Count newlines before the command start. * (See test info-30.33). */ TclAdvanceLines(&envPtr->line, p, parse.commandStart); TclAdvanceContinuations(&envPtr->line, &envPtr->clNext, parse.commandStart - envPtr->source); /* * Advance parser to the next command in the script. */ next = parse.commandStart + parse.commandSize; numBytes -= next - p; p = next; if (parse.numWords == 0) { /* * The "command" parsed has no words. In this case we can skip * the rest of the loop body. With no words, clearly * CompileCommandTokens() has nothing to do. Since the parser * aggressively sucks up leading comment and white space, * including newlines, parse.commandStart must be pointing at * either the end of script, or a command-terminating semi-colon. * In either case, the TclAdvance*() calls have nothing to do. * Finally, when no words are parsed, no tokens have been * allocated at parse.tokenPtr so there's also nothing for * Tcl_FreeParse() to do. * * The advantage of this shortcut is that CompileCommandTokens() * can be written with an assumption that parse.numWords > 0, with * the implication the CCT() always generates bytecode. */ continue; } lastCmdIdx = CompileCommandTokens(interp, &parse, envPtr); /* * TIP #280: Track lines in the just compiled command. */ TclAdvanceLines(&envPtr->line, parse.commandStart, p); TclAdvanceContinuations(&envPtr->line, &envPtr->clNext, p - envPtr->source); Tcl_FreeParse(&parse); } if (lastCmdIdx == -1) { /* * Compiling the script yielded no bytecode. The script must be all * whitespace, comments, and empty commands. Such scripts are defined * to successfully produce the empty string result, so we emit the * simple bytecode that makes that happen. */ PushStringLiteral(envPtr, ""); } else { /* * We compiled at least one command to bytecode. The routine * CompileCommandTokens() follows the bytecode of each compiled * command with an INST_POP, so that stack balance is maintained when * several commands are in sequence. (The result of each command is * thrown away before moving on to the next command). For the last * command compiled, we need to undo that INST_POP so that the result * of the last command becomes the result of the script. The code * here removes that trailing INST_POP. */ envPtr->cmdMapPtr[lastCmdIdx].numCodeBytes--; envPtr->codeNext--; envPtr->currStackDepth++; } TclCheckStackDepth(depth+1, envPtr); } /* *---------------------------------------------------------------------- * * TclCompileTokens -- * * Given an array of tokens parsed from a Tcl command (e.g., the tokens * that make up a word) this procedure emits instructions to evaluate the * tokens and concatenate their values to form a single result value on * the interpreter's runtime evaluation stack. * * Results: * The return value is a standard Tcl result. If an error occurs, an * error message is left in the interpreter's result. * * Side effects: * Instructions are added to envPtr to push and evaluate the tokens at * runtime. * *---------------------------------------------------------------------- */ void TclCompileVarSubst( Tcl_Interp *interp, Tcl_Token *tokenPtr, CompileEnv *envPtr) { const char *p, *name = tokenPtr[1].start; int nameBytes = tokenPtr[1].size; int i, localVar, localVarName = 1; /* * Determine how the variable name should be handled: if it contains any * namespace qualifiers it is not a local variable (localVarName=-1); if * it looks like an array element and the token has a single component, it * should not be created here [Bug 569438] (localVarName=0); otherwise, * the local variable can safely be created (localVarName=1). */ for (i = 0, p = name; i < nameBytes; i++, p++) { if ((*p == ':') && (i < nameBytes-1) && (*(p+1) == ':')) { localVarName = -1; break; } else if ((*p == '(') && (tokenPtr->numComponents == 1) && (*(name + nameBytes - 1) == ')')) { localVarName = 0; break; } } /* * Either push the variable's name, or find its index in the array * of local variables in a procedure frame. */ localVar = -1; if (localVarName != -1) { localVar = TclFindCompiledLocal(name, nameBytes, localVarName, envPtr); } if (localVar < 0) { PushLiteral(envPtr, name, nameBytes); } /* * Emit instructions to load the variable. */ TclAdvanceLines(&envPtr->line, tokenPtr[1].start, tokenPtr[1].start + tokenPtr[1].size); if (tokenPtr->numComponents == 1) { if (localVar < 0) { TclEmitOpcode(INST_LOAD_STK, envPtr); } else if (localVar <= 255) { TclEmitInstInt1(INST_LOAD_SCALAR1, localVar, envPtr); } else { TclEmitInstInt4(INST_LOAD_SCALAR4, localVar, envPtr); } } else { TclCompileTokens(interp, tokenPtr+2, tokenPtr->numComponents-1, envPtr); if (localVar < 0) { TclEmitOpcode(INST_LOAD_ARRAY_STK, envPtr); } else if (localVar <= 255) { TclEmitInstInt1(INST_LOAD_ARRAY1, localVar, envPtr); } else { TclEmitInstInt4(INST_LOAD_ARRAY4, localVar, envPtr); } } } void TclCompileTokens( Tcl_Interp *interp, /* Used for error and status reporting. */ Tcl_Token *tokenPtr, /* Pointer to first in an array of tokens to * compile. */ int count, /* Number of tokens to consider at tokenPtr. * Must be at least 1. */ CompileEnv *envPtr) /* Holds the resulting instructions. */ { Tcl_DString textBuffer; /* Holds concatenated chars from adjacent * TCL_TOKEN_TEXT, TCL_TOKEN_BS tokens. */ char buffer[TCL_UTF_MAX]; int i, numObjsToConcat, length, adjust; unsigned char *entryCodeNext = envPtr->codeNext; #define NUM_STATIC_POS 20 int isLiteral, maxNumCL, numCL; int *clPosition = NULL; int depth = TclGetStackDepth(envPtr); /* * For the handling of continuation lines in literals we first check if * this is actually a literal. For if not we can forego the additional * processing. Otherwise we pre-allocate a small table to store the * locations of all continuation lines we find in this literal, if any. * The table is extended if needed. * * Note: Different to the equivalent code in function 'TclSubstTokens()' * (see file "tclParse.c") we do not seem to need the 'adjust' variable. * We also do not seem to need code which merges continuation line * information of multiple words which concat'd at runtime. Either that or * I have not managed to find a test case for these two possibilities yet. * It might be a difference between compile- versus run-time processing. */ numCL = 0; maxNumCL = 0; isLiteral = 1; for (i=0 ; i < count; i++) { if ((tokenPtr[i].type != TCL_TOKEN_TEXT) && (tokenPtr[i].type != TCL_TOKEN_BS)) { isLiteral = 0; break; } } if (isLiteral) { maxNumCL = NUM_STATIC_POS; clPosition = ckalloc(maxNumCL * sizeof(int)); } adjust = 0; Tcl_DStringInit(&textBuffer); numObjsToConcat = 0; for ( ; count > 0; count--, tokenPtr++) { switch (tokenPtr->type) { case TCL_TOKEN_TEXT: TclDStringAppendToken(&textBuffer, tokenPtr); TclAdvanceLines(&envPtr->line, tokenPtr->start, tokenPtr->start + tokenPtr->size); break; case TCL_TOKEN_BS: length = TclParseBackslash(tokenPtr->start, tokenPtr->size, NULL, buffer); Tcl_DStringAppend(&textBuffer, buffer, length); /* * If the backslash sequence we found is in a literal, and * represented a continuation line, we compute and store its * location (as char offset to the beginning of the _result_ * script). We may have to extend the table of locations. * * Note that the continuation line information is relevant even if * the word we are processing is not a literal, as it can affect * nested commands. See the branch for TCL_TOKEN_COMMAND below, * where the adjustment we are tracking here is taken into * account. The good thing is that we do not need a table of * everything, just the number of lines we have to add as * correction. */ if ((length == 1) && (buffer[0] == ' ') && (tokenPtr->start[1] == '\n')) { if (isLiteral) { int clPos = Tcl_DStringLength(&textBuffer); if (numCL >= maxNumCL) { maxNumCL *= 2; clPosition = ckrealloc(clPosition, maxNumCL * sizeof(int)); } clPosition[numCL] = clPos; numCL ++; } adjust++; } break; case TCL_TOKEN_COMMAND: /* * Push any accumulated chars appearing before the command. */ if (Tcl_DStringLength(&textBuffer) > 0) { int literal = TclRegisterDStringLiteral(envPtr, &textBuffer); TclEmitPush(literal, envPtr); numObjsToConcat++; Tcl_DStringFree(&textBuffer); if (numCL) { TclContinuationsEnter(TclFetchLiteral(envPtr, literal), numCL, clPosition); } numCL = 0; } envPtr->line += adjust; TclCompileScript(interp, tokenPtr->start+1, tokenPtr->size-2, envPtr); envPtr->line -= adjust; numObjsToConcat++; break; case TCL_TOKEN_VARIABLE: /* * Push any accumulated chars appearing before the $<var>. */ if (Tcl_DStringLength(&textBuffer) > 0) { int literal; literal = TclRegisterDStringLiteral(envPtr, &textBuffer); TclEmitPush(literal, envPtr); numObjsToConcat++; Tcl_DStringFree(&textBuffer); } TclCompileVarSubst(interp, tokenPtr, envPtr); numObjsToConcat++; count -= tokenPtr->numComponents; tokenPtr += tokenPtr->numComponents; break; default: Tcl_Panic("Unexpected token type in TclCompileTokens: %d; %.*s", tokenPtr->type, tokenPtr->size, tokenPtr->start); } } /* * Push any accumulated characters appearing at the end. */ if (Tcl_DStringLength(&textBuffer) > 0) { int literal = TclRegisterDStringLiteral(envPtr, &textBuffer); TclEmitPush(literal, envPtr); numObjsToConcat++; if (numCL) { TclContinuationsEnter(TclFetchLiteral(envPtr, literal), numCL, clPosition); } numCL = 0; } /* * If necessary, concatenate the parts of the word. */ while (numObjsToConcat > 255) { TclEmitInstInt1(INST_STR_CONCAT1, 255, envPtr); numObjsToConcat -= 254; /* concat pushes 1 obj, the result */ } if (numObjsToConcat > 1) { TclEmitInstInt1(INST_STR_CONCAT1, numObjsToConcat, envPtr); } /* * If the tokens yielded no instructions, push an empty string. */ if (envPtr->codeNext == entryCodeNext) { PushStringLiteral(envPtr, ""); } Tcl_DStringFree(&textBuffer); /* * Release the temp table we used to collect the locations of continuation * lines, if any. */ if (maxNumCL) { ckfree(clPosition); } TclCheckStackDepth(depth+1, envPtr); } /* *---------------------------------------------------------------------- * * TclCompileCmdWord -- * * Given an array of parse tokens for a word containing one or more Tcl * commands, emit inline instructions to execute them. This procedure * differs from TclCompileTokens in that a simple word such as a loop * body enclosed in braces is not just pushed as a string, but is itself * parsed into tokens and compiled. * * Results: * The return value is a standard Tcl result. If an error occurs, an * error message is left in the interpreter's result. * * Side effects: * Instructions are added to envPtr to execute the tokens at runtime. * *---------------------------------------------------------------------- */ void TclCompileCmdWord( Tcl_Interp *interp, /* Used for error and status reporting. */ Tcl_Token *tokenPtr, /* Pointer to first in an array of tokens for * a command word to compile inline. */ int count, /* Number of tokens to consider at tokenPtr. * Must be at least 1. */ CompileEnv *envPtr) /* Holds the resulting instructions. */ { if ((count == 1) && (tokenPtr->type == TCL_TOKEN_TEXT)) { /* * Handle the common case: if there is a single text token, compile it * into an inline sequence of instructions. */ TclCompileScript(interp, tokenPtr->start, tokenPtr->size, envPtr); } else { /* * Multiple tokens or the single token involves substitutions. Emit * instructions to invoke the eval command procedure at runtime on the * result of evaluating the tokens. */ TclCompileTokens(interp, tokenPtr, count, envPtr); TclEmitInvoke(envPtr, INST_EVAL_STK); } } /* *---------------------------------------------------------------------- * * TclCompileExprWords -- * * Given an array of parse tokens representing one or more words that * contain a Tcl expression, emit inline instructions to execute the * expression. This procedure differs from TclCompileExpr in that it * supports Tcl's two-level substitution semantics for expressions that * appear as command words. * * Results: * The return value is a standard Tcl result. If an error occurs, an * error message is left in the interpreter's result. * * Side effects: * Instructions are added to envPtr to execute the expression. * *---------------------------------------------------------------------- */ void TclCompileExprWords( Tcl_Interp *interp, /* Used for error and status reporting. */ Tcl_Token *tokenPtr, /* Points to first in an array of word tokens * tokens for the expression to compile * inline. */ int numWords, /* Number of word tokens starting at tokenPtr. * Must be at least 1. Each word token * contains one or more subtokens. */ CompileEnv *envPtr) /* Holds the resulting instructions. */ { Tcl_Token *wordPtr; int i, concatItems; /* * If the expression is a single word that doesn't require substitutions, * just compile its string into inline instructions. */ if ((numWords == 1) && (tokenPtr->type == TCL_TOKEN_SIMPLE_WORD)) { TclCompileExpr(interp, tokenPtr[1].start,tokenPtr[1].size, envPtr, 1); return; } /* * Emit code to call the expr command proc at runtime. Concatenate the * (already substituted once) expr tokens with a space between each. */ wordPtr = tokenPtr; for (i = 0; i < numWords; i++) { CompileTokens(envPtr, wordPtr, interp); if (i < (numWords - 1)) { PushStringLiteral(envPtr, " "); } wordPtr += wordPtr->numComponents + 1; } concatItems = 2*numWords - 1; while (concatItems > 255) { TclEmitInstInt1(INST_STR_CONCAT1, 255, envPtr); concatItems -= 254; } if (concatItems > 1) { TclEmitInstInt1(INST_STR_CONCAT1, concatItems, envPtr); } TclEmitOpcode(INST_EXPR_STK, envPtr); } /* *---------------------------------------------------------------------- * * TclCompileNoOp -- * * Function called to compile no-op's * * Results: * The return value is TCL_OK, indicating successful compilation. * * Side effects: * Instructions are added to envPtr to execute a no-op at runtime. No * result is pushed onto the stack: the compiler has to take care of this * itself if the last compiled command is a NoOp. * *---------------------------------------------------------------------- */ int TclCompileNoOp( Tcl_Interp *interp, /* Used for error reporting. */ Tcl_Parse *parsePtr, /* Points to a parse structure for the command * created by Tcl_ParseCommand. */ Command *cmdPtr, /* Points to defintion of command being * compiled. */ CompileEnv *envPtr) /* Holds resulting instructions. */ { Tcl_Token *tokenPtr; int i; tokenPtr = parsePtr->tokenPtr; for (i = 1; i < parsePtr->numWords; i++) { tokenPtr = tokenPtr + tokenPtr->numComponents + 1; if (tokenPtr->type != TCL_TOKEN_SIMPLE_WORD) { CompileTokens(envPtr, tokenPtr, interp); TclEmitOpcode(INST_POP, envPtr); } } PushStringLiteral(envPtr, ""); return TCL_OK; } /* *---------------------------------------------------------------------- * * TclInitByteCodeObj -- * * Create a ByteCode structure and initialize it from a CompileEnv * compilation environment structure. The ByteCode structure is smaller * and contains just that information needed to execute the bytecode * instructions resulting from compiling a Tcl script. The resulting * structure is placed in the specified object. * * Results: * A newly constructed ByteCode object is stored in the internal * representation of the objPtr. * * Side effects: * A single heap object is allocated to hold the new ByteCode structure * and its code, object, command location, and aux data arrays. Note that * "ownership" (i.e., the pointers to) the Tcl objects and aux data items * will be handed over to the new ByteCode structure from the CompileEnv * structure. * *---------------------------------------------------------------------- */ void TclInitByteCodeObj( Tcl_Obj *objPtr, /* Points object that should be initialized, * and whose string rep contains the source * code. */ register CompileEnv *envPtr)/* Points to the CompileEnv structure from * which to create a ByteCode structure. */ { register ByteCode *codePtr; size_t codeBytes, objArrayBytes, exceptArrayBytes, cmdLocBytes; size_t auxDataArrayBytes, structureSize; register unsigned char *p; #ifdef TCL_COMPILE_DEBUG unsigned char *nextPtr; #endif int numLitObjects = envPtr->literalArrayNext; Namespace *namespacePtr; int i, isNew; Interp *iPtr; if (envPtr->iPtr == NULL) { Tcl_Panic("TclInitByteCodeObj() called on uninitialized CompileEnv"); } iPtr = envPtr->iPtr; codeBytes = envPtr->codeNext - envPtr->codeStart; objArrayBytes = envPtr->literalArrayNext * sizeof(Tcl_Obj *); exceptArrayBytes = envPtr->exceptArrayNext * sizeof(ExceptionRange); auxDataArrayBytes = envPtr->auxDataArrayNext * sizeof(AuxData); cmdLocBytes = GetCmdLocEncodingSize(envPtr); /* * Compute the total number of bytes needed for this bytecode. */ structureSize = sizeof(ByteCode); structureSize += TCL_ALIGN(codeBytes); /* align object array */ structureSize += TCL_ALIGN(objArrayBytes); /* align exc range arr */ structureSize += TCL_ALIGN(exceptArrayBytes); /* align AuxData array */ structureSize += auxDataArrayBytes; structureSize += cmdLocBytes; if (envPtr->iPtr->varFramePtr != NULL) { namespacePtr = envPtr->iPtr->varFramePtr->nsPtr; } else { namespacePtr = envPtr->iPtr->globalNsPtr; } p = ckalloc(structureSize); codePtr = (ByteCode *) p; codePtr->interpHandle = TclHandlePreserve(iPtr->handle); codePtr->compileEpoch = iPtr->compileEpoch; codePtr->nsPtr = namespacePtr; codePtr->nsEpoch = namespacePtr->resolverEpoch; codePtr->refCount = 1; if (namespacePtr->compiledVarResProc || iPtr->resolverPtr) { codePtr->flags = TCL_BYTECODE_RESOLVE_VARS; } else { codePtr->flags = 0; } codePtr->source = envPtr->source; codePtr->procPtr = envPtr->procPtr; codePtr->numCommands = envPtr->numCommands; codePtr->numSrcBytes = envPtr->numSrcBytes; codePtr->numCodeBytes = codeBytes; codePtr->numLitObjects = numLitObjects; codePtr->numExceptRanges = envPtr->exceptArrayNext; codePtr->numAuxDataItems = envPtr->auxDataArrayNext; codePtr->numCmdLocBytes = cmdLocBytes; codePtr->maxExceptDepth = envPtr->maxExceptDepth; codePtr->maxStackDepth = envPtr->maxStackDepth; p += sizeof(ByteCode); codePtr->codeStart = p; memcpy(p, envPtr->codeStart, (size_t) codeBytes); p += TCL_ALIGN(codeBytes); /* align object array */ codePtr->objArrayPtr = (Tcl_Obj **) p; for (i = 0; i < numLitObjects; i++) { Tcl_Obj *fetched = TclFetchLiteral(envPtr, i); if (objPtr == fetched) { /* * Prevent circular reference where the bytecode intrep of * a value contains a literal which is that same value. * If this is allowed to happen, refcount decrements may not * reach zero, and memory may leak. Bugs 467523, 3357771 * * NOTE: [Bugs 3392070, 3389764] We make a copy based completely * on the string value, and do not call Tcl_DuplicateObj() so we * can be sure we do not have any lingering cycles hiding in * the intrep. */ int numBytes; const char *bytes = Tcl_GetStringFromObj(objPtr, &numBytes); codePtr->objArrayPtr[i] = Tcl_NewStringObj(bytes, numBytes); Tcl_IncrRefCount(codePtr->objArrayPtr[i]); TclReleaseLiteral((Tcl_Interp *)iPtr, objPtr); } else { codePtr->objArrayPtr[i] = fetched; } } p += TCL_ALIGN(objArrayBytes); /* align exception range array */ if (exceptArrayBytes > 0) { codePtr->exceptArrayPtr = (ExceptionRange *) p; memcpy(p, envPtr->exceptArrayPtr, (size_t) exceptArrayBytes); } else { codePtr->exceptArrayPtr = NULL; } p += TCL_ALIGN(exceptArrayBytes); /* align AuxData array */ if (auxDataArrayBytes > 0) { codePtr->auxDataArrayPtr = (AuxData *) p; memcpy(p, envPtr->auxDataArrayPtr, (size_t) auxDataArrayBytes); } else { codePtr->auxDataArrayPtr = NULL; } p += auxDataArrayBytes; #ifndef TCL_COMPILE_DEBUG EncodeCmdLocMap(envPtr, codePtr, (unsigned char *) p); #else nextPtr = EncodeCmdLocMap(envPtr, codePtr, (unsigned char *) p); if (((size_t)(nextPtr - p)) != cmdLocBytes) { Tcl_Panic("TclInitByteCodeObj: encoded cmd location bytes %lu != expected size %lu", (unsigned long)(nextPtr - p), (unsigned long)cmdLocBytes); } #endif /* * Record various compilation-related statistics about the new ByteCode * structure. Don't include overhead for statistics-related fields. */ #ifdef TCL_COMPILE_STATS codePtr->structureSize = structureSize - (sizeof(size_t) + sizeof(Tcl_Time)); Tcl_GetTime(&codePtr->createTime); RecordByteCodeStats(codePtr); #endif /* TCL_COMPILE_STATS */ /* * Free the old internal rep then convert the object to a bytecode object * by making its internal rep point to the just compiled ByteCode. */ TclFreeIntRep(objPtr); objPtr->internalRep.twoPtrValue.ptr1 = codePtr; objPtr->typePtr = &tclByteCodeType; /* * TIP #280. Associate the extended per-word line information with the * byte code object (internal rep), for use with the bc compiler. */ Tcl_SetHashValue(Tcl_CreateHashEntry(iPtr->lineBCPtr, codePtr, &isNew), envPtr->extCmdMapPtr); envPtr->extCmdMapPtr = NULL; /* We've used up the CompileEnv. Mark as uninitialized. */ envPtr->iPtr = NULL; codePtr->localCachePtr = NULL; } /* *---------------------------------------------------------------------- * * TclFindCompiledLocal -- * * This procedure is called at compile time to look up and optionally * allocate an entry ("slot") for a variable in a procedure's array of * local variables. If the variable's name is NULL, a new temporary * variable is always created. (Such temporary variables can only be * referenced using their slot index.) * * Results: * If create is 0 and the name is non-NULL, then if the variable is * found, the index of its entry in the procedure's array of local * variables is returned; otherwise -1 is returned. If name is NULL, the * index of a new temporary variable is returned. Finally, if create is 1 * and name is non-NULL, the index of a new entry is returned. * * Side effects: * Creates and registers a new local variable if create is 1 and the * variable is unknown, or if the name is NULL. * *---------------------------------------------------------------------- */ int TclFindCompiledLocal( register const char *name, /* Points to first character of the name of a * scalar or array variable. If NULL, a * temporary var should be created. */ int nameBytes, /* Number of bytes in the name. */ int create, /* If 1, allocate a local frame entry for the * variable if it is new. */ CompileEnv *envPtr) /* Points to the current compile environment*/ { register CompiledLocal *localPtr; int localVar = -1; register int i; Proc *procPtr; /* * If not creating a temporary, does a local variable of the specified * name already exist? */ procPtr = envPtr->procPtr; if (procPtr == NULL) { /* * Compiling a non-body script: give it read access to the LVT in the * current localCache */ LocalCache *cachePtr = envPtr->iPtr->varFramePtr->localCachePtr; const char *localName; Tcl_Obj **varNamePtr; int len; if (!cachePtr || !name) { return -1; } varNamePtr = &cachePtr->varName0; for (i=0; i < cachePtr->numVars; varNamePtr++, i++) { if (*varNamePtr) { localName = Tcl_GetStringFromObj(*varNamePtr, &len); if ((len == nameBytes) && !strncmp(name, localName, len)) { return i; } } } return -1; } if (name != NULL) { int localCt = procPtr->numCompiledLocals; localPtr = procPtr->firstLocalPtr; for (i = 0; i < localCt; i++) { if (!TclIsVarTemporary(localPtr)) { char *localName = localPtr->name; if ((nameBytes == localPtr->nameLength) && (strncmp(name,localName,(unsigned)nameBytes) == 0)) { return i; } } localPtr = localPtr->nextPtr; } } /* * Create a new variable if appropriate. */ if (create || (name == NULL)) { localVar = procPtr->numCompiledLocals; localPtr = ckalloc(TclOffset(CompiledLocal, name) + nameBytes + 1); if (procPtr->firstLocalPtr == NULL) { procPtr->firstLocalPtr = procPtr->lastLocalPtr = localPtr; } else { procPtr->lastLocalPtr->nextPtr = localPtr; procPtr->lastLocalPtr = localPtr; } localPtr->nextPtr = NULL; localPtr->nameLength = nameBytes; localPtr->frameIndex = localVar; localPtr->flags = 0; if (name == NULL) { localPtr->flags |= VAR_TEMPORARY; } localPtr->defValuePtr = NULL; localPtr->resolveInfo = NULL; if (name != NULL) { memcpy(localPtr->name, name, (size_t) nameBytes); } localPtr->name[nameBytes] = '\0'; procPtr->numCompiledLocals++; } return localVar; } /* *---------------------------------------------------------------------- * * TclExpandCodeArray -- * * Procedure that uses malloc to allocate more storage for a CompileEnv's * code array. * * Results: * None. * * Side effects: * The byte code array in *envPtr is reallocated to a new array of double * the size, and if envPtr->mallocedCodeArray is non-zero the old array * is freed. Byte codes are copied from the old array to the new one. * *---------------------------------------------------------------------- */ void TclExpandCodeArray( void *envArgPtr) /* Points to the CompileEnv whose code array * must be enlarged. */ { CompileEnv *envPtr = envArgPtr; /* The CompileEnv containing the code array to * be doubled in size. */ /* * envPtr->codeNext is equal to envPtr->codeEnd. The currently defined * code bytes are stored between envPtr->codeStart and envPtr->codeNext-1 * [inclusive]. */ size_t currBytes = envPtr->codeNext - envPtr->codeStart; size_t newBytes = 2 * (envPtr->codeEnd - envPtr->codeStart); if (envPtr->mallocedCodeArray) { envPtr->codeStart = ckrealloc(envPtr->codeStart, newBytes); } else { /* * envPtr->codeStart isn't a ckalloc'd pointer, so we must code a * ckrealloc equivalent for ourselves. */ unsigned char *newPtr = ckalloc(newBytes); memcpy(newPtr, envPtr->codeStart, currBytes); envPtr->codeStart = newPtr; envPtr->mallocedCodeArray = 1; } envPtr->codeNext = envPtr->codeStart + currBytes; envPtr->codeEnd = envPtr->codeStart + newBytes; } /* *---------------------------------------------------------------------- * * EnterCmdStartData -- * * Registers the starting source and bytecode location of a command. This * information is used at runtime to map between instruction pc and * source locations. * * Results: * None. * * Side effects: * Inserts source and code location information into the compilation * environment envPtr for the command at index cmdIndex. The compilation * environment's CmdLocation array is grown if necessary. * *---------------------------------------------------------------------- */ static void EnterCmdStartData( CompileEnv *envPtr, /* Points to the compilation environment * structure in which to enter command * location information. */ int cmdIndex, /* Index of the command whose start data is * being set. */ int srcOffset, /* Offset of first char of the command. */ int codeOffset) /* Offset of first byte of command code. */ { CmdLocation *cmdLocPtr; if ((cmdIndex < 0) || (cmdIndex >= envPtr->numCommands)) { Tcl_Panic("EnterCmdStartData: bad command index %d", cmdIndex); } if (cmdIndex >= envPtr->cmdMapEnd) { /* * Expand the command location array by allocating more storage from * the heap. The currently allocated CmdLocation entries are stored * from cmdMapPtr[0] up to cmdMapPtr[envPtr->cmdMapEnd] (inclusive). */ size_t currElems = envPtr->cmdMapEnd; size_t newElems = 2 * currElems; size_t currBytes = currElems * sizeof(CmdLocation); size_t newBytes = newElems * sizeof(CmdLocation); if (envPtr->mallocedCmdMap) { envPtr->cmdMapPtr = ckrealloc(envPtr->cmdMapPtr, newBytes); } else { /* * envPtr->cmdMapPtr isn't a ckalloc'd pointer, so we must code a * ckrealloc equivalent for ourselves. */ CmdLocation *newPtr = ckalloc(newBytes); memcpy(newPtr, envPtr->cmdMapPtr, currBytes); envPtr->cmdMapPtr = newPtr; envPtr->mallocedCmdMap = 1; } envPtr->cmdMapEnd = newElems; } if (cmdIndex > 0) { if (codeOffset < envPtr->cmdMapPtr[cmdIndex-1].codeOffset) { Tcl_Panic("EnterCmdStartData: cmd map not sorted by code offset"); } } cmdLocPtr = &envPtr->cmdMapPtr[cmdIndex]; cmdLocPtr->codeOffset = codeOffset; cmdLocPtr->srcOffset = srcOffset; cmdLocPtr->numSrcBytes = -1; cmdLocPtr->numCodeBytes = -1; } /* *---------------------------------------------------------------------- * * EnterCmdExtentData -- * * Registers the source and bytecode length for a command. This * information is used at runtime to map between instruction pc and * source locations. * * Results: * None. * * Side effects: * Inserts source and code length information into the compilation * environment envPtr for the command at index cmdIndex. Starting source * and bytecode information for the command must already have been * registered. * *---------------------------------------------------------------------- */ static void EnterCmdExtentData( CompileEnv *envPtr, /* Points to the compilation environment * structure in which to enter command * location information. */ int cmdIndex, /* Index of the command whose source and code * length data is being set. */ int numSrcBytes, /* Number of command source chars. */ int numCodeBytes) /* Offset of last byte of command code. */ { CmdLocation *cmdLocPtr; if ((cmdIndex < 0) || (cmdIndex >= envPtr->numCommands)) { Tcl_Panic("EnterCmdExtentData: bad command index %d", cmdIndex); } if (cmdIndex > envPtr->cmdMapEnd) { Tcl_Panic("EnterCmdExtentData: missing start data for command %d", cmdIndex); } cmdLocPtr = &envPtr->cmdMapPtr[cmdIndex]; cmdLocPtr->numSrcBytes = numSrcBytes; cmdLocPtr->numCodeBytes = numCodeBytes; } /* *---------------------------------------------------------------------- * TIP #280 * * EnterCmdWordData -- * * Registers the lines for the words of a command. This information is * used at runtime by 'info frame'. * * Results: * None. * * Side effects: * Inserts word location information into the compilation environment * envPtr for the command at index cmdIndex. The compilation * environment's ExtCmdLoc.ECL array is grown if necessary. * *---------------------------------------------------------------------- */ static void EnterCmdWordData( ExtCmdLoc *eclPtr, /* Points to the map environment structure in * which to enter command location * information. */ int srcOffset, /* Offset of first char of the command. */ Tcl_Token *tokenPtr, const char *cmd, int len, int numWords, int line, int *clNext, int **wlines, CompileEnv *envPtr) { ECL *ePtr; const char *last; int wordIdx, wordLine, *wwlines, *wordNext; if (eclPtr->nuloc >= eclPtr->nloc) { /* * Expand the ECL array by allocating more storage from the heap. The * currently allocated ECL entries are stored from eclPtr->loc[0] up * to eclPtr->loc[eclPtr->nuloc-1] (inclusive). */ size_t currElems = eclPtr->nloc; size_t newElems = (currElems ? 2*currElems : 1); size_t newBytes = newElems * sizeof(ECL); eclPtr->loc = ckrealloc(eclPtr->loc, newBytes); eclPtr->nloc = newElems; } ePtr = &eclPtr->loc[eclPtr->nuloc]; ePtr->srcOffset = srcOffset; ePtr->line = ckalloc(numWords * sizeof(int)); ePtr->next = ckalloc(numWords * sizeof(int *)); ePtr->nline = numWords; wwlines = ckalloc(numWords * sizeof(int)); last = cmd; wordLine = line; wordNext = clNext; for (wordIdx=0 ; wordIdx<numWords; wordIdx++, tokenPtr += tokenPtr->numComponents + 1) { TclAdvanceLines(&wordLine, last, tokenPtr->start); TclAdvanceContinuations(&wordLine, &wordNext, tokenPtr->start - envPtr->source); wwlines[wordIdx] = (TclWordKnownAtCompileTime(tokenPtr, NULL) ? wordLine : -1); ePtr->line[wordIdx] = wordLine; ePtr->next[wordIdx] = wordNext; last = tokenPtr->start; } *wlines = wwlines; eclPtr->nuloc ++; } /* *---------------------------------------------------------------------- * * TclCreateExceptRange -- * * Procedure that allocates and initializes a new ExceptionRange * structure of the specified kind in a CompileEnv. * * Results: * Returns the index for the newly created ExceptionRange. * * Side effects: * If there is not enough room in the CompileEnv's ExceptionRange array, * the array in expanded: a new array of double the size is allocated, if * envPtr->mallocedExceptArray is non-zero the old array is freed, and * ExceptionRange entries are copied from the old array to the new one. * *---------------------------------------------------------------------- */ int TclCreateExceptRange( ExceptionRangeType type, /* The kind of ExceptionRange desired. */ register CompileEnv *envPtr)/* Points to CompileEnv for which to create a * new ExceptionRange structure. */ { register ExceptionRange *rangePtr; register ExceptionAux *auxPtr; int index = envPtr->exceptArrayNext; if (index >= envPtr->exceptArrayEnd) { /* * Expand the ExceptionRange array. The currently allocated entries * are stored between elements 0 and (envPtr->exceptArrayNext - 1) * [inclusive]. */ size_t currBytes = envPtr->exceptArrayNext * sizeof(ExceptionRange); size_t currBytes2 = envPtr->exceptArrayNext * sizeof(ExceptionAux); int newElems = 2*envPtr->exceptArrayEnd; size_t newBytes = newElems * sizeof(ExceptionRange); size_t newBytes2 = newElems * sizeof(ExceptionAux); if (envPtr->mallocedExceptArray) { envPtr->exceptArrayPtr = ckrealloc(envPtr->exceptArrayPtr, newBytes); envPtr->exceptAuxArrayPtr = ckrealloc(envPtr->exceptAuxArrayPtr, newBytes2); } else { /* * envPtr->exceptArrayPtr isn't a ckalloc'd pointer, so we must * code a ckrealloc equivalent for ourselves. */ ExceptionRange *newPtr = ckalloc(newBytes); ExceptionAux *newPtr2 = ckalloc(newBytes2); memcpy(newPtr, envPtr->exceptArrayPtr, currBytes); memcpy(newPtr2, envPtr->exceptAuxArrayPtr, currBytes2); envPtr->exceptArrayPtr = newPtr; envPtr->exceptAuxArrayPtr = newPtr2; envPtr->mallocedExceptArray = 1; } envPtr->exceptArrayEnd = newElems; } envPtr->exceptArrayNext++; rangePtr = &envPtr->exceptArrayPtr[index]; rangePtr->type = type; rangePtr->nestingLevel = envPtr->exceptDepth; rangePtr->codeOffset = -1; rangePtr->numCodeBytes = -1; rangePtr->breakOffset = -1; rangePtr->continueOffset = -1; rangePtr->catchOffset = -1; auxPtr = &envPtr->exceptAuxArrayPtr[index]; auxPtr->supportsContinue = 1; auxPtr->stackDepth = envPtr->currStackDepth; auxPtr->expandTarget = envPtr->expandCount; auxPtr->expandTargetDepth = -1; auxPtr->numBreakTargets = 0; auxPtr->breakTargets = NULL; auxPtr->allocBreakTargets = 0; auxPtr->numContinueTargets = 0; auxPtr->continueTargets = NULL; auxPtr->allocContinueTargets = 0; return index; } /* * --------------------------------------------------------------------- * * TclGetInnermostExceptionRange -- * * Returns the innermost exception range that covers the current code * creation point, and (optionally) the stack depth that is expected at * that point. Relies on the fact that the range has a numCodeBytes = -1 * when it is being populated and that inner ranges come after outer * ranges. * * --------------------------------------------------------------------- */ ExceptionRange * TclGetInnermostExceptionRange( CompileEnv *envPtr, int returnCode, ExceptionAux **auxPtrPtr) { int exnIdx = -1, i; for (i=0 ; i<envPtr->exceptArrayNext ; i++) { ExceptionRange *rangePtr = &envPtr->exceptArrayPtr[i]; if (CurrentOffset(envPtr) >= rangePtr->codeOffset && (rangePtr->numCodeBytes == -1 || CurrentOffset(envPtr) < rangePtr->codeOffset+rangePtr->numCodeBytes) && (returnCode != TCL_CONTINUE || envPtr->exceptAuxArrayPtr[i].supportsContinue)) { exnIdx = i; } } if (exnIdx == -1) { return NULL; } if (auxPtrPtr) { *auxPtrPtr = &envPtr->exceptAuxArrayPtr[exnIdx]; } return &envPtr->exceptArrayPtr[exnIdx]; } /* * --------------------------------------------------------------------- * * TclAddLoopBreakFixup, TclAddLoopContinueFixup -- * * Adds a place that wants to break/continue to the loop exception range * tracking that will be fixed up once the loop can be finalized. These * functions will generate an INST_JUMP4 that will be fixed up during the * loop finalization. * * --------------------------------------------------------------------- */ void TclAddLoopBreakFixup( CompileEnv *envPtr, ExceptionAux *auxPtr) { int range = auxPtr - envPtr->exceptAuxArrayPtr; if (envPtr->exceptArrayPtr[range].type != LOOP_EXCEPTION_RANGE) { Tcl_Panic("trying to add 'break' fixup to full exception range"); } if (++auxPtr->numBreakTargets > auxPtr->allocBreakTargets) { auxPtr->allocBreakTargets *= 2; auxPtr->allocBreakTargets += 2; if (auxPtr->breakTargets) { auxPtr->breakTargets = ckrealloc(auxPtr->breakTargets, sizeof(int) * auxPtr->allocBreakTargets); } else { auxPtr->breakTargets = ckalloc(sizeof(int) * auxPtr->allocBreakTargets); } } auxPtr->breakTargets[auxPtr->numBreakTargets - 1] = CurrentOffset(envPtr); TclEmitInstInt4(INST_JUMP4, 0, envPtr); } void TclAddLoopContinueFixup( CompileEnv *envPtr, ExceptionAux *auxPtr) { int range = auxPtr - envPtr->exceptAuxArrayPtr; if (envPtr->exceptArrayPtr[range].type != LOOP_EXCEPTION_RANGE) { Tcl_Panic("trying to add 'continue' fixup to full exception range"); } if (++auxPtr->numContinueTargets > auxPtr->allocContinueTargets) { auxPtr->allocContinueTargets *= 2; auxPtr->allocContinueTargets += 2; if (auxPtr->continueTargets) { auxPtr->continueTargets = ckrealloc(auxPtr->continueTargets, sizeof(int) * auxPtr->allocContinueTargets); } else { auxPtr->continueTargets = ckalloc(sizeof(int) * auxPtr->allocContinueTargets); } } auxPtr->continueTargets[auxPtr->numContinueTargets - 1] = CurrentOffset(envPtr); TclEmitInstInt4(INST_JUMP4, 0, envPtr); } /* * --------------------------------------------------------------------- * * TclCleanupStackForBreakContinue -- * * Ditch the extra elements from the auxiliary stack and the main stack. * How to do this exactly depends on whether there are any elements on * the auxiliary stack to pop. * * --------------------------------------------------------------------- */ void TclCleanupStackForBreakContinue( CompileEnv *envPtr, ExceptionAux *auxPtr) { int savedStackDepth = envPtr->currStackDepth; int toPop = envPtr->expandCount - auxPtr->expandTarget; if (toPop > 0) { while (toPop --> 0) { TclEmitOpcode(INST_EXPAND_DROP, envPtr); } TclAdjustStackDepth(auxPtr->expandTargetDepth - envPtr->currStackDepth, envPtr); envPtr->currStackDepth = auxPtr->expandTargetDepth; } toPop = envPtr->currStackDepth - auxPtr->stackDepth; while (toPop --> 0) { TclEmitOpcode(INST_POP, envPtr); } envPtr->currStackDepth = savedStackDepth; } /* * --------------------------------------------------------------------- * * StartExpanding -- * * Pushes an INST_EXPAND_START and does some additional housekeeping so * that the [break] and [continue] compilers can use an exception-free * issue to discard it. * * --------------------------------------------------------------------- */ static void StartExpanding( CompileEnv *envPtr) { int i; TclEmitOpcode(INST_EXPAND_START, envPtr); /* * Update inner exception ranges with information about the environment * where this expansion started. */ for (i=0 ; i<envPtr->exceptArrayNext ; i++) { ExceptionRange *rangePtr = &envPtr->exceptArrayPtr[i]; ExceptionAux *auxPtr = &envPtr->exceptAuxArrayPtr[i]; /* * Ignore loops unless they're still being built. */ if (rangePtr->codeOffset > CurrentOffset(envPtr)) { continue; } if (rangePtr->numCodeBytes != -1) { continue; } /* * Adequate condition: further out loops and further in exceptions * don't actually need this information. */ if (auxPtr->expandTarget == envPtr->expandCount) { auxPtr->expandTargetDepth = envPtr->currStackDepth; } } /* * There's now one more expansion being processed on the auxiliary stack. */ envPtr->expandCount++; } /* * --------------------------------------------------------------------- * * TclFinalizeLoopExceptionRange -- * * Finalizes a loop exception range, binding the registered [break] and * [continue] implementations so that they jump to the correct place. * Note that this must only be called after *all* the exception range * target offsets have been set. * * --------------------------------------------------------------------- */ void TclFinalizeLoopExceptionRange( CompileEnv *envPtr, int range) { ExceptionRange *rangePtr = &envPtr->exceptArrayPtr[range]; ExceptionAux *auxPtr = &envPtr->exceptAuxArrayPtr[range]; int i, offset; unsigned char *site; if (rangePtr->type != LOOP_EXCEPTION_RANGE) { Tcl_Panic("trying to finalize a loop exception range"); } /* * Do the jump fixups. Note that these are always issued as INST_JUMP4 so * there is no need to fuss around with updating code offsets. */ for (i=0 ; i<auxPtr->numBreakTargets ; i++) { site = envPtr->codeStart + auxPtr->breakTargets[i]; offset = rangePtr->breakOffset - auxPtr->breakTargets[i]; TclUpdateInstInt4AtPc(INST_JUMP4, offset, site); } for (i=0 ; i<auxPtr->numContinueTargets ; i++) { site = envPtr->codeStart + auxPtr->continueTargets[i]; if (rangePtr->continueOffset == -1) { int j; /* * WTF? Can't bind, so revert to an INST_CONTINUE. Not enough * space to do anything else. */ *site = INST_CONTINUE; for (j=0 ; j<4 ; j++) { *++site = INST_NOP; } } else { offset = rangePtr->continueOffset - auxPtr->continueTargets[i]; TclUpdateInstInt4AtPc(INST_JUMP4, offset, site); } } /* * Drop the arrays we were holding the only reference to. */ if (auxPtr->breakTargets) { ckfree(auxPtr->breakTargets); auxPtr->breakTargets = NULL; auxPtr->numBreakTargets = 0; } if (auxPtr->continueTargets) { ckfree(auxPtr->continueTargets); auxPtr->continueTargets = NULL; auxPtr->numContinueTargets = 0; } } /* *---------------------------------------------------------------------- * * TclCreateAuxData -- * * Procedure that allocates and initializes a new AuxData structure in a * CompileEnv's array of compilation auxiliary data records. These * AuxData records hold information created during compilation by * CompileProcs and used by instructions during execution. * * Results: * Returns the index for the newly created AuxData structure. * * Side effects: * If there is not enough room in the CompileEnv's AuxData array, the * AuxData array in expanded: a new array of double the size is * allocated, if envPtr->mallocedAuxDataArray is non-zero the old array * is freed, and AuxData entries are copied from the old array to the new * one. * *---------------------------------------------------------------------- */ int TclCreateAuxData( ClientData clientData, /* The compilation auxiliary data to store in * the new aux data record. */ const AuxDataType *typePtr, /* Pointer to the type to attach to this * AuxData */ register CompileEnv *envPtr)/* Points to the CompileEnv for which a new * aux data structure is to be allocated. */ { int index; /* Index for the new AuxData structure. */ register AuxData *auxDataPtr; /* Points to the new AuxData structure */ index = envPtr->auxDataArrayNext; if (index >= envPtr->auxDataArrayEnd) { /* * Expand the AuxData array. The currently allocated entries are * stored between elements 0 and (envPtr->auxDataArrayNext - 1) * [inclusive]. */ size_t currBytes = envPtr->auxDataArrayNext * sizeof(AuxData); int newElems = 2*envPtr->auxDataArrayEnd; size_t newBytes = newElems * sizeof(AuxData); if (envPtr->mallocedAuxDataArray) { envPtr->auxDataArrayPtr = ckrealloc(envPtr->auxDataArrayPtr, newBytes); } else { /* * envPtr->auxDataArrayPtr isn't a ckalloc'd pointer, so we must * code a ckrealloc equivalent for ourselves. */ AuxData *newPtr = ckalloc(newBytes); memcpy(newPtr, envPtr->auxDataArrayPtr, currBytes); envPtr->auxDataArrayPtr = newPtr; envPtr->mallocedAuxDataArray = 1; } envPtr->auxDataArrayEnd = newElems; } envPtr->auxDataArrayNext++; auxDataPtr = &envPtr->auxDataArrayPtr[index]; auxDataPtr->clientData = clientData; auxDataPtr->type = typePtr; return index; } /* *---------------------------------------------------------------------- * * TclInitJumpFixupArray -- * * Initializes a JumpFixupArray structure to hold some number of jump * fixup entries. * * Results: * None. * * Side effects: * The JumpFixupArray structure is initialized. * *---------------------------------------------------------------------- */ void TclInitJumpFixupArray( register JumpFixupArray *fixupArrayPtr) /* Points to the JumpFixupArray structure to * initialize. */ { fixupArrayPtr->fixup = fixupArrayPtr->staticFixupSpace; fixupArrayPtr->next = 0; fixupArrayPtr->end = JUMPFIXUP_INIT_ENTRIES - 1; fixupArrayPtr->mallocedArray = 0; } /* *---------------------------------------------------------------------- * * TclExpandJumpFixupArray -- * * Procedure that uses malloc to allocate more storage for a jump fixup * array. * * Results: * None. * * Side effects: * The jump fixup array in *fixupArrayPtr is reallocated to a new array * of double the size, and if fixupArrayPtr->mallocedArray is non-zero * the old array is freed. Jump fixup structures are copied from the old * array to the new one. * *---------------------------------------------------------------------- */ void TclExpandJumpFixupArray( register JumpFixupArray *fixupArrayPtr) /* Points to the JumpFixupArray structure to * enlarge. */ { /* * The currently allocated jump fixup entries are stored from fixup[0] up * to fixup[fixupArrayPtr->fixupNext] (*not* inclusive). We assume * fixupArrayPtr->fixupNext is equal to fixupArrayPtr->fixupEnd. */ size_t currBytes = fixupArrayPtr->next * sizeof(JumpFixup); int newElems = 2*(fixupArrayPtr->end + 1); size_t newBytes = newElems * sizeof(JumpFixup); if (fixupArrayPtr->mallocedArray) { fixupArrayPtr->fixup = ckrealloc(fixupArrayPtr->fixup, newBytes); } else { /* * fixupArrayPtr->fixup isn't a ckalloc'd pointer, so we must code a * ckrealloc equivalent for ourselves. */ JumpFixup *newPtr = ckalloc(newBytes); memcpy(newPtr, fixupArrayPtr->fixup, currBytes); fixupArrayPtr->fixup = newPtr; fixupArrayPtr->mallocedArray = 1; } fixupArrayPtr->end = newElems; } /* *---------------------------------------------------------------------- * * TclFreeJumpFixupArray -- * * Free any storage allocated in a jump fixup array structure. * * Results: * None. * * Side effects: * Allocated storage in the JumpFixupArray structure is freed. * *---------------------------------------------------------------------- */ void TclFreeJumpFixupArray( register JumpFixupArray *fixupArrayPtr) /* Points to the JumpFixupArray structure to * free. */ { if (fixupArrayPtr->mallocedArray) { ckfree(fixupArrayPtr->fixup); } } /* *---------------------------------------------------------------------- * * TclEmitForwardJump -- * * Procedure to emit a two-byte forward jump of kind "jumpType". Since * the jump may later have to be grown to five bytes if the jump target * is more than, say, 127 bytes away, this procedure also initializes a * JumpFixup record with information about the jump. * * Results: * None. * * Side effects: * The JumpFixup record pointed to by "jumpFixupPtr" is initialized with * information needed later if the jump is to be grown. Also, a two byte * jump of the designated type is emitted at the current point in the * bytecode stream. * *---------------------------------------------------------------------- */ void TclEmitForwardJump( CompileEnv *envPtr, /* Points to the CompileEnv structure that * holds the resulting instruction. */ TclJumpType jumpType, /* Indicates the kind of jump: if true or * false or unconditional. */ JumpFixup *jumpFixupPtr) /* Points to the JumpFixup structure to * initialize with information about this * forward jump. */ { /* * Initialize the JumpFixup structure: * - codeOffset is offset of first byte of jump below * - cmdIndex is index of the command after the current one * - exceptIndex is the index of the first ExceptionRange after the * current one. */ jumpFixupPtr->jumpType = jumpType; jumpFixupPtr->codeOffset = envPtr->codeNext - envPtr->codeStart; jumpFixupPtr->cmdIndex = envPtr->numCommands; jumpFixupPtr->exceptIndex = envPtr->exceptArrayNext; switch (jumpType) { case TCL_UNCONDITIONAL_JUMP: TclEmitInstInt1(INST_JUMP1, 0, envPtr); break; case TCL_TRUE_JUMP: TclEmitInstInt1(INST_JUMP_TRUE1, 0, envPtr); break; default: TclEmitInstInt1(INST_JUMP_FALSE1, 0, envPtr); break; } } /* *---------------------------------------------------------------------- * * TclFixupForwardJump -- * * Procedure that updates a previously-emitted forward jump to jump a * specified number of bytes, "jumpDist". If necessary, the jump is grown * from two to five bytes; this is done if the jump distance is greater * than "distThreshold" (normally 127 bytes). The jump is described by a * JumpFixup record previously initialized by TclEmitForwardJump. * * Results: * 1 if the jump was grown and subsequent instructions had to be moved; * otherwise 0. This result is returned to allow callers to update any * additional code offsets they may hold. * * Side effects: * The jump may be grown and subsequent instructions moved. If this * happens, the code offsets for any commands and any ExceptionRange * records between the jump and the current code address will be updated * to reflect the moved code. Also, the bytecode instruction array in the * CompileEnv structure may be grown and reallocated. * *---------------------------------------------------------------------- */ int TclFixupForwardJump( CompileEnv *envPtr, /* Points to the CompileEnv structure that * holds the resulting instruction. */ JumpFixup *jumpFixupPtr, /* Points to the JumpFixup structure that * describes the forward jump. */ int jumpDist, /* Jump distance to set in jump instr. */ int distThreshold) /* Maximum distance before the two byte jump * is grown to five bytes. */ { unsigned char *jumpPc, *p; int firstCmd, lastCmd, firstRange, lastRange, k; unsigned numBytes; if (jumpDist <= distThreshold) { jumpPc = envPtr->codeStart + jumpFixupPtr->codeOffset; switch (jumpFixupPtr->jumpType) { case TCL_UNCONDITIONAL_JUMP: TclUpdateInstInt1AtPc(INST_JUMP1, jumpDist, jumpPc); break; case TCL_TRUE_JUMP: TclUpdateInstInt1AtPc(INST_JUMP_TRUE1, jumpDist, jumpPc); break; default: TclUpdateInstInt1AtPc(INST_JUMP_FALSE1, jumpDist, jumpPc); break; } return 0; } /* * We must grow the jump then move subsequent instructions down. Note that * if we expand the space for generated instructions, code addresses might * change; be careful about updating any of these addresses held in * variables. */ if ((envPtr->codeNext + 3) > envPtr->codeEnd) { TclExpandCodeArray(envPtr); } jumpPc = envPtr->codeStart + jumpFixupPtr->codeOffset; numBytes = envPtr->codeNext-jumpPc-2; p = jumpPc+2; memmove(p+3, p, numBytes); envPtr->codeNext += 3; jumpDist += 3; switch (jumpFixupPtr->jumpType) { case TCL_UNCONDITIONAL_JUMP: TclUpdateInstInt4AtPc(INST_JUMP4, jumpDist, jumpPc); break; case TCL_TRUE_JUMP: TclUpdateInstInt4AtPc(INST_JUMP_TRUE4, jumpDist, jumpPc); break; default: TclUpdateInstInt4AtPc(INST_JUMP_FALSE4, jumpDist, jumpPc); break; } /* * Adjust the code offsets for any commands and any ExceptionRange records * between the jump and the current code address. */ firstCmd = jumpFixupPtr->cmdIndex; lastCmd = envPtr->numCommands - 1; if (firstCmd < lastCmd) { for (k = firstCmd; k <= lastCmd; k++) { envPtr->cmdMapPtr[k].codeOffset += 3; } } firstRange = jumpFixupPtr->exceptIndex; lastRange = envPtr->exceptArrayNext - 1; for (k = firstRange; k <= lastRange; k++) { ExceptionRange *rangePtr = &envPtr->exceptArrayPtr[k]; rangePtr->codeOffset += 3; switch (rangePtr->type) { case LOOP_EXCEPTION_RANGE: rangePtr->breakOffset += 3; if (rangePtr->continueOffset != -1) { rangePtr->continueOffset += 3; } break; case CATCH_EXCEPTION_RANGE: rangePtr->catchOffset += 3; break; default: Tcl_Panic("TclFixupForwardJump: bad ExceptionRange type %d", rangePtr->type); } } for (k = 0 ; k < envPtr->exceptArrayNext ; k++) { ExceptionAux *auxPtr = &envPtr->exceptAuxArrayPtr[k]; int i; for (i=0 ; i<auxPtr->numBreakTargets ; i++) { if (jumpFixupPtr->codeOffset < auxPtr->breakTargets[i]) { auxPtr->breakTargets[i] += 3; } } for (i=0 ; i<auxPtr->numContinueTargets ; i++) { if (jumpFixupPtr->codeOffset < auxPtr->continueTargets[i]) { auxPtr->continueTargets[i] += 3; } } } return 1; /* the jump was grown */ } /* *---------------------------------------------------------------------- * * TclEmitInvoke -- * * Emit one of the invoke-related instructions, wrapping it if necessary * in code that ensures that any break or continue operation passing * through it gets the stack unwinding correct, converting it into an * internal jump if in an appropriate context. * * Results: * None * * Side effects: * Issues the jump with all correct stack management. May create another * loop exception range; pointers to ExceptionRange and ExceptionAux * structures should not be held across this call. * *---------------------------------------------------------------------- */ void TclEmitInvoke( CompileEnv *envPtr, int opcode, ...) { va_list argList; ExceptionRange *rangePtr; ExceptionAux *auxBreakPtr, *auxContinuePtr; int arg1, arg2, wordCount = 0, expandCount = 0; int loopRange = 0, breakRange = 0, continueRange = 0; int cleanup, depth = TclGetStackDepth(envPtr); /* * Parse the arguments. */ va_start(argList, opcode); switch (opcode) { case INST_INVOKE_STK1: wordCount = arg1 = cleanup = va_arg(argList, int); arg2 = 0; break; case INST_INVOKE_STK4: wordCount = arg1 = cleanup = va_arg(argList, int); arg2 = 0; break; case INST_INVOKE_REPLACE: arg1 = va_arg(argList, int); arg2 = va_arg(argList, int); wordCount = arg1 + arg2 - 1; cleanup = arg1 + 1; break; default: Tcl_Panic("unexpected opcode"); case INST_EVAL_STK: wordCount = cleanup = 1; arg1 = arg2 = 0; break; case INST_RETURN_STK: wordCount = cleanup = 2; arg1 = arg2 = 0; break; case INST_INVOKE_EXPANDED: wordCount = arg1 = cleanup = va_arg(argList, int); arg2 = 0; expandCount = 1; break; } va_end(argList); /* * Determine if we need to handle break and continue exceptions with a * special handling exception range (so that we can correctly unwind the * stack). * * These must be done separately; they can be different (especially for * calls from inside a [for] increment clause). */ rangePtr = TclGetInnermostExceptionRange(envPtr, TCL_BREAK, &auxBreakPtr); if (rangePtr == NULL || rangePtr->type != LOOP_EXCEPTION_RANGE) { auxBreakPtr = NULL; } else if (auxBreakPtr->stackDepth == envPtr->currStackDepth-wordCount && auxBreakPtr->expandTarget == envPtr->expandCount-expandCount) { auxBreakPtr = NULL; } else { breakRange = auxBreakPtr - envPtr->exceptAuxArrayPtr; } rangePtr = TclGetInnermostExceptionRange(envPtr, TCL_CONTINUE, &auxContinuePtr); if (rangePtr == NULL || rangePtr->type != LOOP_EXCEPTION_RANGE) { auxContinuePtr = NULL; } else if (auxContinuePtr->stackDepth == envPtr->currStackDepth-wordCount && auxContinuePtr->expandTarget == envPtr->expandCount-expandCount) { auxContinuePtr = NULL; } else { continueRange = auxBreakPtr - envPtr->exceptAuxArrayPtr; } if (auxBreakPtr != NULL || auxContinuePtr != NULL) { loopRange = TclCreateExceptRange(LOOP_EXCEPTION_RANGE, envPtr); ExceptionRangeStarts(envPtr, loopRange); } /* * Issue the invoke itself. */ switch (opcode) { case INST_INVOKE_STK1: TclEmitInstInt1(INST_INVOKE_STK1, arg1, envPtr); break; case INST_INVOKE_STK4: TclEmitInstInt4(INST_INVOKE_STK4, arg1, envPtr); break; case INST_INVOKE_EXPANDED: TclEmitOpcode(INST_INVOKE_EXPANDED, envPtr); envPtr->expandCount--; TclAdjustStackDepth(1 - arg1, envPtr); break; case INST_EVAL_STK: TclEmitOpcode(INST_EVAL_STK, envPtr); break; case INST_RETURN_STK: TclEmitOpcode(INST_RETURN_STK, envPtr); break; case INST_INVOKE_REPLACE: TclEmitInstInt4(INST_INVOKE_REPLACE, arg1, envPtr); TclEmitInt1(arg2, envPtr); TclAdjustStackDepth(-1, envPtr); /* Correction to stack depth calcs */ break; } /* * If we're generating a special wrapper exception range, we need to * finish that up now. */ if (auxBreakPtr != NULL || auxContinuePtr != NULL) { int savedStackDepth = envPtr->currStackDepth; int savedExpandCount = envPtr->expandCount; JumpFixup nonTrapFixup; if (auxBreakPtr != NULL) { auxBreakPtr = envPtr->exceptAuxArrayPtr + breakRange; } if (auxContinuePtr != NULL) { auxContinuePtr = envPtr->exceptAuxArrayPtr + continueRange; } ExceptionRangeEnds(envPtr, loopRange); TclEmitForwardJump(envPtr, TCL_UNCONDITIONAL_JUMP, &nonTrapFixup); /* * Careful! When generating these stack unwinding sequences, the depth * of stack in the cases where they are taken is not the same as if * the exception is not taken. */ if (auxBreakPtr != NULL) { TclAdjustStackDepth(-1, envPtr); ExceptionRangeTarget(envPtr, loopRange, breakOffset); TclCleanupStackForBreakContinue(envPtr, auxBreakPtr); TclAddLoopBreakFixup(envPtr, auxBreakPtr); TclAdjustStackDepth(1, envPtr); envPtr->currStackDepth = savedStackDepth; envPtr->expandCount = savedExpandCount; } if (auxContinuePtr != NULL) { TclAdjustStackDepth(-1, envPtr); ExceptionRangeTarget(envPtr, loopRange, continueOffset); TclCleanupStackForBreakContinue(envPtr, auxContinuePtr); TclAddLoopContinueFixup(envPtr, auxContinuePtr); TclAdjustStackDepth(1, envPtr); envPtr->currStackDepth = savedStackDepth; envPtr->expandCount = savedExpandCount; } TclFinalizeLoopExceptionRange(envPtr, loopRange); TclFixupForwardJumpToHere(envPtr, &nonTrapFixup, 127); } TclCheckStackDepth(depth+1-cleanup, envPtr); } /* *---------------------------------------------------------------------- * * TclGetInstructionTable -- * * Returns a pointer to the table describing Tcl bytecode instructions. * This procedure is defined so that clients can access the pointer from * outside the TCL DLLs. * * Results: * Returns a pointer to the global instruction table, same as the * expression (&tclInstructionTable[0]). * * Side effects: * None. * *---------------------------------------------------------------------- */ const void * /* == InstructionDesc* == */ TclGetInstructionTable(void) { return &tclInstructionTable[0]; } /* *-------------------------------------------------------------- * * RegisterAuxDataType -- * * This procedure is called to register a new AuxData type in the table * of all AuxData types supported by Tcl. * * Results: * None. * * Side effects: * The type is registered in the AuxData type table. If there was already * a type with the same name as in typePtr, it is replaced with the new * type. * *-------------------------------------------------------------- */ static void RegisterAuxDataType( const AuxDataType *typePtr) /* Information about object type; storage must * be statically allocated (must live forever; * will not be deallocated). */ { register Tcl_HashEntry *hPtr; int isNew; Tcl_MutexLock(&tableMutex); if (!auxDataTypeTableInitialized) { TclInitAuxDataTypeTable(); } /* * If there's already a type with the given name, remove it. */ hPtr = Tcl_FindHashEntry(&auxDataTypeTable, typePtr->name); if (hPtr != NULL) { Tcl_DeleteHashEntry(hPtr); } /* * Now insert the new object type. */ hPtr = Tcl_CreateHashEntry(&auxDataTypeTable, typePtr->name, &isNew); if (isNew) { Tcl_SetHashValue(hPtr, typePtr); } Tcl_MutexUnlock(&tableMutex); } /* *---------------------------------------------------------------------- * * TclGetAuxDataType -- * * This procedure looks up an Auxdata type by name. * * Results: * If an AuxData type with name matching "typeName" is found, a pointer * to its AuxDataType structure is returned; otherwise, NULL is returned. * * Side effects: * None. * *---------------------------------------------------------------------- */ const AuxDataType * TclGetAuxDataType( const char *typeName) /* Name of AuxData type to look up. */ { register Tcl_HashEntry *hPtr; const AuxDataType *typePtr = NULL; Tcl_MutexLock(&tableMutex); if (!auxDataTypeTableInitialized) { TclInitAuxDataTypeTable(); } hPtr = Tcl_FindHashEntry(&auxDataTypeTable, typeName); if (hPtr != NULL) { typePtr = Tcl_GetHashValue(hPtr); } Tcl_MutexUnlock(&tableMutex); return typePtr; } /* *-------------------------------------------------------------- * * TclInitAuxDataTypeTable -- * * This procedure is invoked to perform once-only initialization of the * AuxData type table. It also registers the AuxData types defined in * this file. * * Results: * None. * * Side effects: * Initializes the table of defined AuxData types "auxDataTypeTable" with * builtin AuxData types defined in this file. * *-------------------------------------------------------------- */ void TclInitAuxDataTypeTable(void) { /* * The table mutex must already be held before this routine is invoked. */ auxDataTypeTableInitialized = 1; Tcl_InitHashTable(&auxDataTypeTable, TCL_STRING_KEYS); /* * There are only three AuxData types at this time, so register them here. */ RegisterAuxDataType(&tclForeachInfoType); RegisterAuxDataType(&tclJumptableInfoType); RegisterAuxDataType(&tclDictUpdateInfoType); } /* *---------------------------------------------------------------------- * * TclFinalizeAuxDataTypeTable -- * * This procedure is called by Tcl_Finalize after all exit handlers have * been run to free up storage associated with the table of AuxData * types. This procedure is called by TclFinalizeExecution() which is * called by Tcl_Finalize(). * * Results: * None. * * Side effects: * Deletes all entries in the hash table of AuxData types. * *---------------------------------------------------------------------- */ void TclFinalizeAuxDataTypeTable(void) { Tcl_MutexLock(&tableMutex); if (auxDataTypeTableInitialized) { Tcl_DeleteHashTable(&auxDataTypeTable); auxDataTypeTableInitialized = 0; } Tcl_MutexUnlock(&tableMutex); } /* *---------------------------------------------------------------------- * * GetCmdLocEncodingSize -- * * Computes the total number of bytes needed to encode the command * location information for some compiled code. * * Results: * The byte count needed to encode the compiled location information. * * Side effects: * None. * *---------------------------------------------------------------------- */ static int GetCmdLocEncodingSize( CompileEnv *envPtr) /* Points to compilation environment structure * containing the CmdLocation structure to * encode. */ { register CmdLocation *mapPtr = envPtr->cmdMapPtr; int numCmds = envPtr->numCommands; int codeDelta, codeLen, srcDelta, srcLen; int codeDeltaNext, codeLengthNext, srcDeltaNext, srcLengthNext; /* The offsets in their respective byte * sequences where the next encoded offset or * length should go. */ int prevCodeOffset, prevSrcOffset, i; codeDeltaNext = codeLengthNext = srcDeltaNext = srcLengthNext = 0; prevCodeOffset = prevSrcOffset = 0; for (i = 0; i < numCmds; i++) { codeDelta = mapPtr[i].codeOffset - prevCodeOffset; if (codeDelta < 0) { Tcl_Panic("GetCmdLocEncodingSize: bad code offset"); } else if (codeDelta <= 127) { codeDeltaNext++; } else { codeDeltaNext += 5; /* 1 byte for 0xFF, 4 for positive delta */ } prevCodeOffset = mapPtr[i].codeOffset; codeLen = mapPtr[i].numCodeBytes; if (codeLen < 0) { Tcl_Panic("GetCmdLocEncodingSize: bad code length"); } else if (codeLen <= 127) { codeLengthNext++; } else { codeLengthNext += 5;/* 1 byte for 0xFF, 4 for length */ } srcDelta = mapPtr[i].srcOffset - prevSrcOffset; if ((-127 <= srcDelta) && (srcDelta <= 127) && (srcDelta != -1)) { srcDeltaNext++; } else { srcDeltaNext += 5; /* 1 byte for 0xFF, 4 for delta */ } prevSrcOffset = mapPtr[i].srcOffset; srcLen = mapPtr[i].numSrcBytes; if (srcLen < 0) { Tcl_Panic("GetCmdLocEncodingSize: bad source length"); } else if (srcLen <= 127) { srcLengthNext++; } else { srcLengthNext += 5; /* 1 byte for 0xFF, 4 for length */ } } return (codeDeltaNext + codeLengthNext + srcDeltaNext + srcLengthNext); } /* *---------------------------------------------------------------------- * * EncodeCmdLocMap -- * * Encode the command location information for some compiled code into a * ByteCode structure. The encoded command location map is stored as * three adjacent byte sequences. * * Results: * Pointer to the first byte after the encoded command location * information. * * Side effects: * The encoded information is stored into the block of memory headed by * codePtr. Also records pointers to the start of the four byte sequences * in fields in codePtr's ByteCode header structure. * *---------------------------------------------------------------------- */ static unsigned char * EncodeCmdLocMap( CompileEnv *envPtr, /* Points to compilation environment structure * containing the CmdLocation structure to * encode. */ ByteCode *codePtr, /* ByteCode in which to encode envPtr's * command location information. */ unsigned char *startPtr) /* Points to the first byte in codePtr's * memory block where the location information * is to be stored. */ { register CmdLocation *mapPtr = envPtr->cmdMapPtr; int numCmds = envPtr->numCommands; register unsigned char *p = startPtr; int codeDelta, codeLen, srcDelta, srcLen, prevOffset; register int i; /* * Encode the code offset for each command as a sequence of deltas. */ codePtr->codeDeltaStart = p; prevOffset = 0; for (i = 0; i < numCmds; i++) { codeDelta = mapPtr[i].codeOffset - prevOffset; if (codeDelta < 0) { Tcl_Panic("EncodeCmdLocMap: bad code offset"); } else if (codeDelta <= 127) { TclStoreInt1AtPtr(codeDelta, p); p++; } else { TclStoreInt1AtPtr(0xFF, p); p++; TclStoreInt4AtPtr(codeDelta, p); p += 4; } prevOffset = mapPtr[i].codeOffset; } /* * Encode the code length for each command. */ codePtr->codeLengthStart = p; for (i = 0; i < numCmds; i++) { codeLen = mapPtr[i].numCodeBytes; if (codeLen < 0) { Tcl_Panic("EncodeCmdLocMap: bad code length"); } else if (codeLen <= 127) { TclStoreInt1AtPtr(codeLen, p); p++; } else { TclStoreInt1AtPtr(0xFF, p); p++; TclStoreInt4AtPtr(codeLen, p); p += 4; } } /* * Encode the source offset for each command as a sequence of deltas. */ codePtr->srcDeltaStart = p; prevOffset = 0; for (i = 0; i < numCmds; i++) { srcDelta = mapPtr[i].srcOffset - prevOffset; if ((-127 <= srcDelta) && (srcDelta <= 127) && (srcDelta != -1)) { TclStoreInt1AtPtr(srcDelta, p); p++; } else { TclStoreInt1AtPtr(0xFF, p); p++; TclStoreInt4AtPtr(srcDelta, p); p += 4; } prevOffset = mapPtr[i].srcOffset; } /* * Encode the source length for each command. */ codePtr->srcLengthStart = p; for (i = 0; i < numCmds; i++) { srcLen = mapPtr[i].numSrcBytes; if (srcLen < 0) { Tcl_Panic("EncodeCmdLocMap: bad source length"); } else if (srcLen <= 127) { TclStoreInt1AtPtr(srcLen, p); p++; } else { TclStoreInt1AtPtr(0xFF, p); p++; TclStoreInt4AtPtr(srcLen, p); p += 4; } } return p; } #ifdef TCL_COMPILE_DEBUG /* *---------------------------------------------------------------------- * * TclPrintByteCodeObj -- * * This procedure prints ("disassembles") the instructions of a bytecode * object to stdout. * * Results: * None. * * Side effects: * None. * *---------------------------------------------------------------------- */ void TclPrintByteCodeObj( Tcl_Interp *interp, /* Used only for Tcl_GetStringFromObj. */ Tcl_Obj *objPtr) /* The bytecode object to disassemble. */ { Tcl_Obj *bufPtr = TclDisassembleByteCodeObj(objPtr); fprintf(stdout, "\n%s", TclGetString(bufPtr)); Tcl_DecrRefCount(bufPtr); } /* *---------------------------------------------------------------------- * * TclPrintInstruction -- * * This procedure prints ("disassembles") one instruction from a bytecode * object to stdout. * * Results: * Returns the length in bytes of the current instruiction. * * Side effects: * None. * *---------------------------------------------------------------------- */ int TclPrintInstruction( ByteCode *codePtr, /* Bytecode containing the instruction. */ const unsigned char *pc) /* Points to first byte of instruction. */ { Tcl_Obj *bufferObj; int numBytes; TclNewObj(bufferObj); numBytes = FormatInstruction(codePtr, pc, bufferObj); fprintf(stdout, "%s", TclGetString(bufferObj)); Tcl_DecrRefCount(bufferObj); return numBytes; } /* *---------------------------------------------------------------------- * * TclPrintObject -- * * This procedure prints up to a specified number of characters from the * argument Tcl object's string representation to a specified file. * * Results: * None. * * Side effects: * Outputs characters to the specified file. * *---------------------------------------------------------------------- */ void TclPrintObject( FILE *outFile, /* The file to print the source to. */ Tcl_Obj *objPtr, /* Points to the Tcl object whose string * representation should be printed. */ int maxChars) /* Maximum number of chars to print. */ { char *bytes; int length; bytes = Tcl_GetStringFromObj(objPtr, &length); TclPrintSource(outFile, bytes, TclMin(length, maxChars)); } /* *---------------------------------------------------------------------- * * TclPrintSource -- * * This procedure prints up to a specified number of characters from the * argument string to a specified file. It tries to produce legible * output by adding backslashes as necessary. * * Results: * None. * * Side effects: * Outputs characters to the specified file. * *---------------------------------------------------------------------- */ void TclPrintSource( FILE *outFile, /* The file to print the source to. */ const char *stringPtr, /* The string to print. */ int maxChars) /* Maximum number of chars to print. */ { Tcl_Obj *bufferObj; TclNewObj(bufferObj); PrintSourceToObj(bufferObj, stringPtr, maxChars); fprintf(outFile, "%s", TclGetString(bufferObj)); Tcl_DecrRefCount(bufferObj); } #endif /* TCL_COMPILE_DEBUG */ /* *---------------------------------------------------------------------- * * TclDisassembleByteCodeObj -- * * Given an object which is of bytecode type, return a disassembled * version of the bytecode (in a new refcount 0 object). No guarantees * are made about the details of the contents of the result. * *---------------------------------------------------------------------- */ Tcl_Obj * TclDisassembleByteCodeObj( Tcl_Obj *objPtr) /* The bytecode object to disassemble. */ { ByteCode *codePtr = objPtr->internalRep.twoPtrValue.ptr1; unsigned char *codeStart, *codeLimit, *pc; unsigned char *codeDeltaNext, *codeLengthNext; unsigned char *srcDeltaNext, *srcLengthNext; int codeOffset, codeLen, srcOffset, srcLen, numCmds, delta, i; Interp *iPtr = (Interp *) *codePtr->interpHandle; Tcl_Obj *bufferObj; char ptrBuf1[20], ptrBuf2[20]; TclNewObj(bufferObj); if (codePtr->refCount <= 0) { return bufferObj; /* Already freed. */ } codeStart = codePtr->codeStart; codeLimit = codeStart + codePtr->numCodeBytes; numCmds = codePtr->numCommands; /* * Print header lines describing the ByteCode. */ sprintf(ptrBuf1, "%p", codePtr); sprintf(ptrBuf2, "%p", iPtr); Tcl_AppendPrintfToObj(bufferObj, "ByteCode 0x%s, refCt %u, epoch %u, interp 0x%s (epoch %u)\n", ptrBuf1, codePtr->refCount, codePtr->compileEpoch, ptrBuf2, iPtr->compileEpoch); Tcl_AppendToObj(bufferObj, " Source ", -1); PrintSourceToObj(bufferObj, codePtr->source, TclMin(codePtr->numSrcBytes, 55)); Tcl_AppendPrintfToObj(bufferObj, "\n Cmds %d, src %d, inst %d, litObjs %u, aux %d, stkDepth %u, code/src %.2f\n", numCmds, codePtr->numSrcBytes, codePtr->numCodeBytes, codePtr->numLitObjects, codePtr->numAuxDataItems, codePtr->maxStackDepth, #ifdef TCL_COMPILE_STATS codePtr->numSrcBytes? codePtr->structureSize/(float)codePtr->numSrcBytes : #endif 0.0); #ifdef TCL_COMPILE_STATS Tcl_AppendPrintfToObj(bufferObj, " Code %lu = header %lu+inst %d+litObj %lu+exc %lu+aux %lu+cmdMap %d\n", (unsigned long) codePtr->structureSize, (unsigned long) (sizeof(ByteCode) - sizeof(size_t) - sizeof(Tcl_Time)), codePtr->numCodeBytes, (unsigned long) (codePtr->numLitObjects * sizeof(Tcl_Obj *)), (unsigned long) (codePtr->numExceptRanges*sizeof(ExceptionRange)), (unsigned long) (codePtr->numAuxDataItems * sizeof(AuxData)), codePtr->numCmdLocBytes); #endif /* TCL_COMPILE_STATS */ /* * If the ByteCode is the compiled body of a Tcl procedure, print * information about that procedure. Note that we don't know the * procedure's name since ByteCode's can be shared among procedures. */ if (codePtr->procPtr != NULL) { Proc *procPtr = codePtr->procPtr; int numCompiledLocals = procPtr->numCompiledLocals; sprintf(ptrBuf1, "%p", procPtr); Tcl_AppendPrintfToObj(bufferObj, " Proc 0x%s, refCt %d, args %d, compiled locals %d\n", ptrBuf1, procPtr->refCount, procPtr->numArgs, numCompiledLocals); if (numCompiledLocals > 0) { CompiledLocal *localPtr = procPtr->firstLocalPtr; for (i = 0; i < numCompiledLocals; i++) { Tcl_AppendPrintfToObj(bufferObj, " slot %d%s%s%s%s%s%s", i, (localPtr->flags & (VAR_ARRAY|VAR_LINK)) ? "" : ", scalar", (localPtr->flags & VAR_ARRAY) ? ", array" : "", (localPtr->flags & VAR_LINK) ? ", link" : "", (localPtr->flags & VAR_ARGUMENT) ? ", arg" : "", (localPtr->flags & VAR_TEMPORARY) ? ", temp" : "", (localPtr->flags & VAR_RESOLVED) ? ", resolved" : ""); if (TclIsVarTemporary(localPtr)) { Tcl_AppendToObj(bufferObj, "\n", -1); } else { Tcl_AppendPrintfToObj(bufferObj, ", \"%s\"\n", localPtr->name); } localPtr = localPtr->nextPtr; } } } /* * Print the ExceptionRange array. */ if (codePtr->numExceptRanges > 0) { Tcl_AppendPrintfToObj(bufferObj, " Exception ranges %d, depth %d:\n", codePtr->numExceptRanges, codePtr->maxExceptDepth); for (i = 0; i < codePtr->numExceptRanges; i++) { ExceptionRange *rangePtr = &codePtr->exceptArrayPtr[i]; Tcl_AppendPrintfToObj(bufferObj, " %d: level %d, %s, pc %d-%d, ", i, rangePtr->nestingLevel, (rangePtr->type==LOOP_EXCEPTION_RANGE ? "loop" : "catch"), rangePtr->codeOffset, (rangePtr->codeOffset + rangePtr->numCodeBytes - 1)); switch (rangePtr->type) { case LOOP_EXCEPTION_RANGE: Tcl_AppendPrintfToObj(bufferObj, "continue %d, break %d\n", rangePtr->continueOffset, rangePtr->breakOffset); break; case CATCH_EXCEPTION_RANGE: Tcl_AppendPrintfToObj(bufferObj, "catch %d\n", rangePtr->catchOffset); break; default: Tcl_Panic("TclDisassembleByteCodeObj: bad ExceptionRange type %d", rangePtr->type); } } } /* * If there were no commands (e.g., an expression or an empty string was * compiled), just print all instructions and return. */ if (numCmds == 0) { pc = codeStart; while (pc < codeLimit) { Tcl_AppendToObj(bufferObj, " ", -1); pc += FormatInstruction(codePtr, pc, bufferObj); } return bufferObj; } /* * Print table showing the code offset, source offset, and source length * for each command. These are encoded as a sequence of bytes. */ Tcl_AppendPrintfToObj(bufferObj, " Commands %d:", numCmds); codeDeltaNext = codePtr->codeDeltaStart; codeLengthNext = codePtr->codeLengthStart; srcDeltaNext = codePtr->srcDeltaStart; srcLengthNext = codePtr->srcLengthStart; codeOffset = srcOffset = 0; for (i = 0; i < numCmds; i++) { if ((unsigned) *codeDeltaNext == (unsigned) 0xFF) { codeDeltaNext++; delta = TclGetInt4AtPtr(codeDeltaNext); codeDeltaNext += 4; } else { delta = TclGetInt1AtPtr(codeDeltaNext); codeDeltaNext++; } codeOffset += delta; if ((unsigned) *codeLengthNext == (unsigned) 0xFF) { codeLengthNext++; codeLen = TclGetInt4AtPtr(codeLengthNext); codeLengthNext += 4; } else { codeLen = TclGetInt1AtPtr(codeLengthNext); codeLengthNext++; } if ((unsigned) *srcDeltaNext == (unsigned) 0xFF) { srcDeltaNext++; delta = TclGetInt4AtPtr(srcDeltaNext); srcDeltaNext += 4; } else { delta = TclGetInt1AtPtr(srcDeltaNext); srcDeltaNext++; } srcOffset += delta; if ((unsigned) *srcLengthNext == (unsigned) 0xFF) { srcLengthNext++; srcLen = TclGetInt4AtPtr(srcLengthNext); srcLengthNext += 4; } else { srcLen = TclGetInt1AtPtr(srcLengthNext); srcLengthNext++; } Tcl_AppendPrintfToObj(bufferObj, "%s%4d: pc %d-%d, src %d-%d", ((i % 2)? " " : "\n "), (i+1), codeOffset, (codeOffset + codeLen - 1), srcOffset, (srcOffset + srcLen - 1)); } if (numCmds > 0) { Tcl_AppendToObj(bufferObj, "\n", -1); } /* * Print each instruction. If the instruction corresponds to the start of * a command, print the command's source. Note that we don't need the code * length here. */ codeDeltaNext = codePtr->codeDeltaStart; srcDeltaNext = codePtr->srcDeltaStart; srcLengthNext = codePtr->srcLengthStart; codeOffset = srcOffset = 0; pc = codeStart; for (i = 0; i < numCmds; i++) { if ((unsigned) *codeDeltaNext == (unsigned) 0xFF) { codeDeltaNext++; delta = TclGetInt4AtPtr(codeDeltaNext); codeDeltaNext += 4; } else { delta = TclGetInt1AtPtr(codeDeltaNext); codeDeltaNext++; } codeOffset += delta; if ((unsigned) *srcDeltaNext == (unsigned) 0xFF) { srcDeltaNext++; delta = TclGetInt4AtPtr(srcDeltaNext); srcDeltaNext += 4; } else { delta = TclGetInt1AtPtr(srcDeltaNext); srcDeltaNext++; } srcOffset += delta; if ((unsigned) *srcLengthNext == (unsigned) 0xFF) { srcLengthNext++; srcLen = TclGetInt4AtPtr(srcLengthNext); srcLengthNext += 4; } else { srcLen = TclGetInt1AtPtr(srcLengthNext); srcLengthNext++; } /* * Print instructions before command i. */ while ((pc-codeStart) < codeOffset) { Tcl_AppendToObj(bufferObj, " ", -1); pc += FormatInstruction(codePtr, pc, bufferObj); } Tcl_AppendPrintfToObj(bufferObj, " Command %d: ", i+1); PrintSourceToObj(bufferObj, (codePtr->source + srcOffset), TclMin(srcLen, 55)); Tcl_AppendToObj(bufferObj, "\n", -1); } if (pc < codeLimit) { /* * Print instructions after the last command. */ while (pc < codeLimit) { Tcl_AppendToObj(bufferObj, " ", -1); pc += FormatInstruction(codePtr, pc, bufferObj); } } return bufferObj; } /* *---------------------------------------------------------------------- * * FormatInstruction -- * * Appends a representation of a bytecode instruction to a Tcl_Obj. * *---------------------------------------------------------------------- */ static int FormatInstruction( ByteCode *codePtr, /* Bytecode containing the instruction. */ const unsigned char *pc, /* Points to first byte of instruction. */ Tcl_Obj *bufferObj) /* Object to append instruction info to. */ { Proc *procPtr = codePtr->procPtr; unsigned char opCode = *pc; register const InstructionDesc *instDesc = &tclInstructionTable[opCode]; unsigned char *codeStart = codePtr->codeStart; unsigned pcOffset = pc - codeStart; int opnd = 0, i, j, numBytes = 1; int localCt = procPtr ? procPtr->numCompiledLocals : 0; CompiledLocal *localPtr = procPtr ? procPtr->firstLocalPtr : NULL; char suffixBuffer[128]; /* Additional info to print after main opcode * and immediates. */ char *suffixSrc = NULL; Tcl_Obj *suffixObj = NULL; AuxData *auxPtr = NULL; suffixBuffer[0] = '\0'; Tcl_AppendPrintfToObj(bufferObj, "(%u) %s ", pcOffset, instDesc->name); for (i = 0; i < instDesc->numOperands; i++) { switch (instDesc->opTypes[i]) { case OPERAND_INT1: opnd = TclGetInt1AtPtr(pc+numBytes); numBytes++; if (opCode == INST_JUMP1 || opCode == INST_JUMP_TRUE1 || opCode == INST_JUMP_FALSE1) { sprintf(suffixBuffer, "pc %u", pcOffset+opnd); } Tcl_AppendPrintfToObj(bufferObj, "%+d ", opnd); break; case OPERAND_INT4: opnd = TclGetInt4AtPtr(pc+numBytes); numBytes += 4; if (opCode == INST_JUMP4 || opCode == INST_JUMP_TRUE4 || opCode == INST_JUMP_FALSE4) { sprintf(suffixBuffer, "pc %u", pcOffset+opnd); } else if (opCode == INST_START_CMD) { sprintf(suffixBuffer, "next cmd at pc %u", pcOffset+opnd); } Tcl_AppendPrintfToObj(bufferObj, "%+d ", opnd); break; case OPERAND_UINT1: opnd = TclGetUInt1AtPtr(pc+numBytes); numBytes++; if (opCode == INST_PUSH1) { suffixObj = codePtr->objArrayPtr[opnd]; } Tcl_AppendPrintfToObj(bufferObj, "%u ", (unsigned) opnd); break; case OPERAND_AUX4: case OPERAND_UINT4: opnd = TclGetUInt4AtPtr(pc+numBytes); numBytes += 4; if (opCode == INST_PUSH4) { suffixObj = codePtr->objArrayPtr[opnd]; } else if (opCode == INST_START_CMD && opnd != 1) { sprintf(suffixBuffer+strlen(suffixBuffer), ", %u cmds start here", opnd); } Tcl_AppendPrintfToObj(bufferObj, "%u ", (unsigned) opnd); if (instDesc->opTypes[i] == OPERAND_AUX4) { auxPtr = &codePtr->auxDataArrayPtr[opnd]; } break; case OPERAND_IDX4: opnd = TclGetInt4AtPtr(pc+numBytes); numBytes += 4; if (opnd >= -1) { Tcl_AppendPrintfToObj(bufferObj, "%d ", opnd); } else if (opnd == -2) { Tcl_AppendPrintfToObj(bufferObj, "end "); } else { Tcl_AppendPrintfToObj(bufferObj, "end-%d ", -2-opnd); } break; case OPERAND_LVT1: opnd = TclGetUInt1AtPtr(pc+numBytes); numBytes++; goto printLVTindex; case OPERAND_LVT4: opnd = TclGetUInt4AtPtr(pc+numBytes); numBytes += 4; printLVTindex: if (localPtr != NULL) { if (opnd >= localCt) { Tcl_Panic("FormatInstruction: bad local var index %u (%u locals)", (unsigned) opnd, localCt); } for (j = 0; j < opnd; j++) { localPtr = localPtr->nextPtr; } if (TclIsVarTemporary(localPtr)) { sprintf(suffixBuffer, "temp var %u", (unsigned) opnd); } else { sprintf(suffixBuffer, "var "); suffixSrc = localPtr->name; } } Tcl_AppendPrintfToObj(bufferObj, "%%v%u ", (unsigned) opnd); break; case OPERAND_NONE: default: break; } } if (suffixObj) { const char *bytes; int length; Tcl_AppendToObj(bufferObj, "\t# ", -1); bytes = Tcl_GetStringFromObj(codePtr->objArrayPtr[opnd], &length); PrintSourceToObj(bufferObj, bytes, TclMin(length, 40)); } else if (suffixBuffer[0]) { Tcl_AppendPrintfToObj(bufferObj, "\t# %s", suffixBuffer); if (suffixSrc) { PrintSourceToObj(bufferObj, suffixSrc, 40); } } Tcl_AppendToObj(bufferObj, "\n", -1); if (auxPtr && auxPtr->type->printProc) { Tcl_AppendToObj(bufferObj, "\t\t[", -1); auxPtr->type->printProc(auxPtr->clientData, bufferObj, codePtr, pcOffset); Tcl_AppendToObj(bufferObj, "]\n", -1); } return numBytes; } /* *---------------------------------------------------------------------- * * TclGetInnerContext -- * * If possible, returns a list capturing the inner context. Otherwise * return NULL. * *---------------------------------------------------------------------- */ Tcl_Obj * TclGetInnerContext( Tcl_Interp *interp, const unsigned char *pc, Tcl_Obj **tosPtr) { int objc = 0, off = 0; Tcl_Obj *result; Interp *iPtr = (Interp *) interp; switch (*pc) { case INST_STR_LEN: case INST_LNOT: case INST_BITNOT: case INST_UMINUS: case INST_UPLUS: case INST_TRY_CVT_TO_NUMERIC: case INST_EXPAND_STKTOP: case INST_EXPR_STK: objc = 1; break; case INST_LIST_IN: case INST_LIST_NOT_IN: /* Basic list containment operators. */ case INST_STR_EQ: case INST_STR_NEQ: /* String (in)equality check */ case INST_STR_CMP: /* String compare. */ case INST_STR_INDEX: case INST_STR_MATCH: case INST_REGEXP: case INST_EQ: case INST_NEQ: case INST_LT: case INST_GT: case INST_LE: case INST_GE: case INST_MOD: case INST_LSHIFT: case INST_RSHIFT: case INST_BITOR: case INST_BITXOR: case INST_BITAND: case INST_EXPON: case INST_ADD: case INST_SUB: case INST_DIV: case INST_MULT: objc = 2; break; case INST_RETURN_STK: /* early pop. TODO: dig out opt dict too :/ */ objc = 1; break; case INST_SYNTAX: case INST_RETURN_IMM: objc = 2; break; case INST_INVOKE_STK4: objc = TclGetUInt4AtPtr(pc+1); break; case INST_INVOKE_STK1: objc = TclGetUInt1AtPtr(pc+1); break; } result = iPtr->innerContext; if (Tcl_IsShared(result)) { Tcl_DecrRefCount(result); iPtr->innerContext = result = Tcl_NewListObj(objc + 1, NULL); Tcl_IncrRefCount(result); } else { int len; /* * Reset while keeping the list intrep as much as possible. */ Tcl_ListObjLength(interp, result, &len); Tcl_ListObjReplace(interp, result, 0, len, 0, NULL); } Tcl_ListObjAppendElement(NULL, result, TclNewInstNameObj(*pc)); for (; objc>0 ; objc--) { Tcl_Obj *objPtr; objPtr = tosPtr[1 - objc + off]; if (!objPtr) { Tcl_Panic("InnerContext: bad tos -- appending null object"); } if ((objPtr->refCount<=0) #ifdef TCL_MEM_DEBUG || (objPtr->refCount==0x61616161) #endif ) { Tcl_Panic("InnerContext: bad tos -- appending freed object %p", objPtr); } Tcl_ListObjAppendElement(NULL, result, objPtr); } return result; } /* *---------------------------------------------------------------------- * * TclNewInstNameObj -- * * Creates a new InstName Tcl_Obj based on the given instruction * *---------------------------------------------------------------------- */ Tcl_Obj * TclNewInstNameObj( unsigned char inst) { Tcl_Obj *objPtr = Tcl_NewObj(); objPtr->typePtr = &tclInstNameType; objPtr->internalRep.longValue = (long) inst; objPtr->bytes = NULL; return objPtr; } /* *---------------------------------------------------------------------- * * UpdateStringOfInstName -- * * Update the string representation for an instruction name object. * *---------------------------------------------------------------------- */ static void UpdateStringOfInstName( Tcl_Obj *objPtr) { int inst = objPtr->internalRep.longValue; char *s, buf[20]; int len; if ((inst < 0) || (inst > LAST_INST_OPCODE)) { sprintf(buf, "inst_%d", inst); s = buf; } else { s = (char *) tclInstructionTable[objPtr->internalRep.longValue].name; } len = strlen(s); objPtr->bytes = ckalloc(len + 1); memcpy(objPtr->bytes, s, len + 1); objPtr->length = len; } /* *---------------------------------------------------------------------- * * PrintSourceToObj -- * * Appends a quoted representation of a string to a Tcl_Obj. * *---------------------------------------------------------------------- */ static void PrintSourceToObj( Tcl_Obj *appendObj, /* The object to print the source to. */ const char *stringPtr, /* The string to print. */ int maxChars) /* Maximum number of chars to print. */ { register const char *p; register int i = 0; if (stringPtr == NULL) { Tcl_AppendToObj(appendObj, "\"\"", -1); return; } Tcl_AppendToObj(appendObj, "\"", -1); p = stringPtr; for (; (*p != '\0') && (i < maxChars); p++, i++) { switch (*p) { case '"': Tcl_AppendToObj(appendObj, "\\\"", -1); continue; case '\f': Tcl_AppendToObj(appendObj, "\\f", -1); continue; case '\n': Tcl_AppendToObj(appendObj, "\\n", -1); continue; case '\r': Tcl_AppendToObj(appendObj, "\\r", -1); continue; case '\t': Tcl_AppendToObj(appendObj, "\\t", -1); continue; case '\v': Tcl_AppendToObj(appendObj, "\\v", -1); continue; default: Tcl_AppendPrintfToObj(appendObj, "%c", *p); continue; } } Tcl_AppendToObj(appendObj, "\"", -1); } #ifdef TCL_COMPILE_STATS /* *---------------------------------------------------------------------- * * RecordByteCodeStats -- * * Accumulates various compilation-related statistics for each newly * compiled ByteCode. Called by the TclInitByteCodeObj when Tcl is * compiled with the -DTCL_COMPILE_STATS flag * * Results: * None. * * Side effects: * Accumulates aggregate code-related statistics in the interpreter's * ByteCodeStats structure. Records statistics specific to a ByteCode in * its ByteCode structure. * *---------------------------------------------------------------------- */ void RecordByteCodeStats( ByteCode *codePtr) /* Points to ByteCode structure with info * to add to accumulated statistics. */ { Interp *iPtr = (Interp *) *codePtr->interpHandle; register ByteCodeStats *statsPtr; if (iPtr == NULL) { /* Avoid segfaulting in case we're called in a deleted interp */ return; } statsPtr = &(iPtr->stats); statsPtr->numCompilations++; statsPtr->totalSrcBytes += (double) codePtr->numSrcBytes; statsPtr->totalByteCodeBytes += (double) codePtr->structureSize; statsPtr->currentSrcBytes += (double) codePtr->numSrcBytes; statsPtr->currentByteCodeBytes += (double) codePtr->structureSize; statsPtr->srcCount[TclLog2(codePtr->numSrcBytes)]++; statsPtr->byteCodeCount[TclLog2((int) codePtr->structureSize)]++; statsPtr->currentInstBytes += (double) codePtr->numCodeBytes; statsPtr->currentLitBytes += (double) codePtr->numLitObjects * sizeof(Tcl_Obj *); statsPtr->currentExceptBytes += (double) codePtr->numExceptRanges * sizeof(ExceptionRange); statsPtr->currentAuxBytes += (double) codePtr->numAuxDataItems * sizeof(AuxData); statsPtr->currentCmdMapBytes += (double) codePtr->numCmdLocBytes; } #endif /* TCL_COMPILE_STATS */ /* * Local Variables: * mode: c * c-basic-offset: 4 * fill-column: 78 * tab-width: 8 * End: */