ahk 0.1.2

The ahk language: a lexer, an AST, a parser and an interpreter for AutoHotkey-style scripts
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9466
9467
9468
9469
9470
9471
9472
9473
9474
9475
9476
9477
9478
9479
9480
9481
9482
9483
9484
9485
9486
9487
9488
9489
9490
9491
9492
9493
9494
9495
9496
9497
9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
9526
9527
9528
9529
9530
9531
9532
9533
9534
9535
9536
9537
9538
9539
9540
9541
9542
9543
9544
9545
9546
9547
9548
9549
9550
9551
9552
9553
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570
9571
9572
9573
9574
9575
9576
9577
9578
9579
9580
9581
9582
9583
9584
9585
9586
9587
9588
9589
9590
9591
9592
9593
9594
9595
9596
9597
9598
9599
9600
9601
9602
9603
9604
9605
9606
9607
9608
9609
9610
9611
9612
9613
9614
9615
9616
9617
9618
9619
9620
9621
9622
9623
9624
9625
9626
9627
9628
9629
9630
9631
9632
9633
9634
9635
9636
9637
9638
9639
9640
9641
9642
9643
9644
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655
9656
9657
9658
9659
9660
9661
9662
9663
9664
9665
9666
9667
9668
9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9701
9702
9703
9704
9705
9706
9707
9708
9709
9710
9711
9712
9713
9714
9715
9716
9717
9718
9719
9720
9721
9722
9723
9724
9725
9726
9727
9728
9729
9730
9731
9732
9733
9734
9735
9736
9737
9738
9739
9740
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768
9769
9770
9771
9772
9773
9774
9775
9776
9777
9778
9779
9780
9781
9782
9783
9784
9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9799
9800
9801
9802
9803
9804
9805
9806
9807
9808
9809
9810
9811
9812
9813
9814
9815
9816
9817
9818
9819
9820
9821
9822
9823
9824
9825
9826
9827
9828
9829
9830
9831
9832
9833
9834
9835
9836
9837
9838
9839
9840
9841
9842
9843
9844
9845
9846
9847
9848
9849
9850
9851
9852
9853
9854
9855
9856
9857
9858
9859
9860
9861
9862
9863
9864
9865
9866
9867
9868
9869
9870
9871
9872
9873
9874
9875
9876
9877
9878
9879
9880
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
9894
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905
9906
9907
9908
9909
9910
9911
9912
9913
9914
9915
9916
9917
9918
9919
9920
9921
9922
9923
9924
9925
9926
9927
9928
9929
9930
9931
9932
9933
9934
9935
9936
9937
9938
9939
9940
9941
9942
9943
9944
9945
9946
9947
9948
9949
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9972
9973
9974
9975
9976
9977
9978
9979
9980
9981
9982
9983
9984
9985
9986
9987
9988
9989
9990
9991
9992
9993
9994
9995
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10046
10047
10048
10049
10050
10051
10052
10053
10054
10055
10056
10057
10058
10059
10060
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10076
10077
10078
10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
10102
10103
10104
10105
10106
10107
10108
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128
10129
10130
10131
10132
10133
10134
10135
10136
10137
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
10159
10160
10161
10162
10163
10164
10165
10166
10167
10168
10169
10170
10171
10172
10173
10174
10175
10176
10177
10178
10179
10180
10181
10182
10183
10184
10185
10186
10187
10188
10189
10190
10191
10192
10193
10194
10195
10196
10197
10198
10199
10200
10201
10202
10203
10204
10205
10206
10207
10208
10209
10210
10211
10212
10213
10214
10215
10216
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
10228
10229
10230
10231
10232
10233
10234
10235
10236
10237
10238
10239
10240
10241
10242
10243
10244
10245
10246
10247
10248
10249
10250
10251
10252
10253
10254
10255
10256
10257
10258
10259
10260
10261
10262
10263
10264
10265
10266
10267
10268
10269
10270
10271
10272
10273
10274
10275
10276
10277
10278
10279
10280
10281
10282
10283
10284
10285
10286
10287
10288
10289
10290
10291
10292
10293
10294
10295
10296
10297
10298
10299
10300
10301
10302
10303
10304
10305
10306
10307
10308
10309
10310
10311
10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
10323
10324
10325
10326
10327
10328
10329
10330
10331
10332
10333
10334
10335
10336
10337
10338
10339
10340
10341
10342
10343
10344
10345
10346
10347
10348
10349
10350
10351
10352
10353
10354
10355
10356
10357
10358
10359
10360
10361
10362
10363
10364
10365
10366
10367
10368
10369
10370
10371
10372
10373
10374
10375
10376
10377
10378
10379
10380
10381
10382
10383
10384
10385
10386
10387
10388
10389
10390
10391
10392
10393
10394
10395
10396
10397
10398
10399
10400
10401
10402
10403
10404
10405
10406
10407
10408
10409
10410
10411
10412
10413
10414
10415
10416
10417
10418
10419
10420
10421
10422
10423
10424
10425
10426
10427
10428
10429
10430
10431
10432
10433
10434
10435
10436
10437
10438
10439
10440
10441
10442
10443
10444
10445
10446
10447
10448
10449
10450
10451
10452
10453
10454
10455
10456
10457
10458
10459
10460
10461
10462
10463
10464
10465
10466
10467
10468
10469
10470
10471
10472
10473
10474
10475
10476
10477
10478
10479
10480
10481
10482
10483
10484
10485
10486
10487
10488
10489
10490
10491
10492
10493
10494
10495
10496
10497
10498
10499
10500
10501
10502
10503
10504
10505
10506
10507
10508
10509
10510
10511
10512
10513
10514
10515
10516
10517
10518
10519
10520
10521
10522
10523
10524
10525
10526
10527
10528
10529
10530
10531
10532
10533
10534
10535
10536
10537
10538
10539
10540
10541
10542
10543
10544
10545
10546
10547
10548
10549
10550
10551
10552
10553
10554
10555
10556
10557
10558
10559
10560
10561
10562
10563
10564
10565
10566
10567
10568
10569
10570
10571
10572
10573
10574
10575
10576
10577
10578
10579
10580
10581
10582
10583
10584
10585
10586
10587
10588
10589
10590
10591
10592
10593
10594
10595
10596
10597
10598
10599
10600
10601
10602
10603
10604
10605
10606
10607
10608
10609
10610
10611
10612
10613
10614
10615
10616
10617
10618
10619
10620
10621
10622
10623
10624
10625
10626
10627
10628
10629
10630
10631
10632
10633
10634
10635
10636
10637
10638
10639
10640
10641
10642
10643
10644
10645
10646
10647
10648
10649
10650
10651
10652
10653
10654
10655
10656
10657
10658
10659
10660
10661
10662
10663
10664
10665
10666
10667
10668
10669
10670
10671
10672
10673
10674
10675
10676
10677
10678
10679
10680
10681
10682
10683
10684
10685
10686
10687
10688
10689
10690
10691
10692
10693
10694
10695
10696
10697
10698
10699
10700
10701
10702
10703
10704
10705
10706
10707
10708
10709
10710
10711
10712
10713
10714
10715
10716
10717
10718
10719
10720
10721
10722
10723
10724
10725
10726
10727
10728
10729
10730
10731
10732
10733
10734
10735
10736
10737
10738
10739
10740
10741
10742
10743
10744
10745
10746
10747
10748
10749
10750
10751
10752
10753
10754
10755
10756
10757
10758
10759
10760
10761
10762
10763
10764
10765
10766
10767
10768
10769
10770
10771
10772
10773
10774
10775
10776
10777
10778
10779
10780
10781
10782
10783
10784
10785
10786
10787
10788
10789
10790
10791
10792
10793
10794
10795
10796
10797
10798
10799
10800
10801
10802
10803
10804
10805
10806
10807
10808
10809
10810
10811
10812
10813
10814
10815
10816
10817
10818
10819
10820
10821
10822
10823
10824
10825
10826
10827
10828
10829
10830
10831
10832
10833
10834
10835
10836
10837
10838
10839
10840
10841
10842
10843
10844
10845
10846
10847
10848
10849
10850
10851
10852
10853
10854
10855
10856
10857
10858
10859
10860
10861
10862
10863
10864
10865
10866
10867
10868
10869
10870
10871
10872
10873
10874
10875
10876
10877
10878
10879
10880
10881
10882
10883
10884
10885
10886
10887
10888
10889
10890
10891
10892
10893
10894
10895
10896
10897
10898
10899
10900
10901
10902
10903
10904
10905
10906
10907
10908
10909
10910
10911
10912
10913
10914
10915
10916
10917
10918
10919
10920
10921
10922
10923
10924
10925
10926
10927
10928
10929
10930
10931
10932
10933
10934
10935
10936
10937
10938
10939
10940
10941
10942
10943
10944
10945
10946
10947
10948
10949
10950
10951
10952
10953
10954
10955
10956
10957
10958
10959
10960
10961
10962
10963
10964
10965
10966
10967
10968
10969
10970
10971
10972
10973
10974
10975
10976
10977
10978
10979
10980
10981
10982
10983
10984
10985
10986
10987
10988
10989
10990
10991
10992
10993
10994
10995
10996
10997
10998
10999
11000
11001
11002
11003
11004
11005
11006
11007
11008
11009
11010
11011
11012
11013
11014
11015
11016
11017
11018
11019
11020
11021
11022
11023
11024
11025
11026
11027
11028
11029
11030
11031
11032
11033
11034
11035
11036
11037
11038
11039
11040
11041
11042
11043
11044
11045
11046
11047
11048
11049
11050
11051
11052
11053
11054
11055
11056
11057
11058
11059
11060
11061
11062
11063
11064
11065
11066
11067
11068
11069
11070
11071
11072
11073
11074
11075
11076
11077
11078
11079
11080
11081
11082
11083
11084
11085
11086
11087
11088
11089
11090
11091
11092
11093
11094
11095
11096
11097
11098
11099
11100
11101
11102
11103
11104
11105
11106
11107
11108
11109
11110
11111
11112
11113
11114
11115
11116
11117
11118
11119
11120
11121
11122
11123
11124
11125
11126
11127
11128
11129
11130
11131
11132
11133
11134
11135
11136
11137
11138
11139
11140
11141
11142
11143
11144
11145
11146
11147
11148
11149
11150
11151
11152
11153
11154
11155
11156
11157
11158
11159
11160
11161
11162
11163
11164
11165
11166
11167
11168
11169
11170
11171
11172
11173
11174
11175
11176
11177
11178
11179
11180
11181
11182
11183
11184
11185
11186
11187
11188
11189
11190
11191
11192
11193
11194
11195
11196
11197
11198
11199
11200
11201
11202
11203
11204
11205
11206
11207
11208
11209
11210
11211
11212
11213
11214
11215
11216
11217
11218
11219
11220
11221
11222
11223
11224
11225
11226
11227
11228
11229
11230
11231
11232
11233
11234
11235
11236
11237
11238
11239
11240
11241
11242
11243
11244
11245
11246
11247
11248
11249
11250
11251
11252
11253
11254
11255
11256
11257
11258
11259
11260
11261
11262
11263
11264
11265
11266
11267
11268
11269
11270
11271
11272
11273
11274
11275
11276
11277
11278
11279
11280
11281
11282
11283
11284
11285
11286
11287
11288
11289
11290
11291
11292
11293
11294
11295
11296
11297
11298
11299
11300
11301
11302
11303
11304
11305
11306
11307
11308
11309
11310
11311
11312
11313
11314
11315
11316
11317
11318
11319
11320
11321
11322
11323
11324
11325
11326
11327
11328
11329
11330
11331
11332
11333
11334
11335
11336
11337
11338
11339
11340
11341
11342
11343
11344
11345
11346
11347
11348
11349
11350
11351
11352
11353
11354
11355
11356
11357
11358
11359
11360
11361
11362
11363
11364
11365
11366
11367
11368
11369
11370
11371
11372
11373
11374
11375
11376
11377
11378
11379
11380
11381
11382
11383
11384
11385
11386
11387
11388
11389
11390
11391
11392
11393
11394
11395
11396
11397
11398
11399
11400
11401
11402
11403
11404
11405
11406
11407
11408
11409
11410
11411
11412
11413
11414
11415
11416
11417
11418
11419
11420
11421
11422
11423
11424
11425
11426
11427
11428
11429
11430
11431
11432
11433
11434
11435
11436
11437
11438
11439
11440
11441
11442
11443
11444
11445
11446
11447
11448
11449
11450
11451
11452
11453
11454
11455
11456
11457
11458
11459
11460
11461
11462
11463
11464
11465
11466
11467
11468
11469
11470
11471
11472
11473
11474
11475
11476
11477
11478
11479
11480
11481
11482
11483
11484
11485
11486
11487
11488
11489
11490
11491
11492
11493
11494
11495
11496
11497
11498
11499
11500
11501
11502
11503
11504
11505
11506
11507
11508
11509
11510
11511
11512
11513
11514
11515
11516
11517
11518
11519
11520
11521
11522
11523
11524
11525
11526
11527
11528
11529
11530
11531
11532
11533
11534
11535
11536
11537
11538
11539
11540
11541
11542
11543
11544
11545
11546
11547
11548
11549
11550
11551
11552
11553
11554
11555
11556
11557
11558
11559
11560
11561
11562
11563
11564
11565
11566
11567
11568
11569
11570
11571
11572
11573
11574
11575
11576
11577
11578
11579
11580
11581
11582
11583
11584
11585
11586
11587
11588
11589
11590
11591
11592
11593
11594
11595
11596
11597
11598
11599
11600
11601
11602
11603
11604
11605
11606
11607
11608
11609
11610
11611
11612
11613
11614
11615
11616
11617
11618
11619
11620
11621
11622
11623
11624
11625
11626
11627
11628
11629
11630
11631
11632
11633
11634
11635
11636
11637
11638
11639
11640
11641
11642
11643
11644
11645
11646
11647
11648
11649
11650
11651
11652
11653
11654
11655
11656
11657
11658
11659
11660
11661
11662
11663
11664
11665
11666
11667
11668
11669
11670
11671
11672
11673
11674
11675
11676
11677
11678
11679
11680
11681
11682
11683
11684
11685
11686
11687
11688
11689
11690
11691
11692
11693
11694
11695
11696
11697
11698
11699
11700
11701
11702
11703
11704
11705
11706
11707
11708
11709
11710
11711
11712
11713
11714
11715
11716
11717
11718
11719
11720
11721
11722
11723
11724
11725
11726
11727
11728
11729
11730
11731
11732
11733
11734
11735
11736
11737
11738
11739
11740
11741
11742
11743
11744
11745
11746
11747
11748
11749
11750
11751
11752
11753
11754
11755
11756
11757
11758
11759
11760
11761
11762
11763
11764
11765
11766
11767
11768
11769
11770
11771
11772
11773
11774
11775
11776
11777
11778
11779
11780
11781
11782
11783
11784
11785
11786
11787
11788
11789
11790
11791
11792
11793
11794
11795
11796
11797
11798
11799
11800
11801
11802
11803
11804
11805
11806
11807
11808
11809
11810
11811
11812
11813
11814
11815
11816
11817
11818
11819
11820
11821
11822
11823
11824
11825
11826
11827
11828
11829
11830
11831
11832
11833
11834
11835
11836
11837
11838
11839
11840
11841
11842
11843
11844
11845
11846
11847
11848
11849
11850
11851
11852
11853
11854
11855
11856
11857
11858
11859
11860
11861
11862
11863
11864
11865
11866
11867
11868
11869
11870
11871
11872
11873
11874
11875
11876
11877
11878
11879
11880
11881
11882
11883
11884
11885
11886
11887
11888
11889
11890
11891
11892
11893
11894
11895
11896
11897
11898
11899
11900
11901
11902
11903
11904
11905
11906
11907
11908
11909
11910
11911
11912
11913
11914
11915
11916
11917
11918
11919
11920
11921
11922
11923
11924
11925
11926
11927
11928
11929
11930
11931
11932
11933
11934
11935
11936
11937
11938
11939
11940
11941
11942
11943
11944
11945
11946
11947
11948
11949
11950
11951
11952
11953
11954
11955
11956
11957
11958
11959
11960
11961
11962
11963
11964
11965
11966
11967
11968
11969
11970
11971
11972
11973
11974
11975
11976
11977
11978
11979
11980
11981
11982
11983
11984
11985
11986
11987
11988
11989
11990
11991
11992
11993
11994
11995
11996
11997
11998
11999
12000
12001
12002
12003
12004
12005
12006
12007
12008
12009
12010
12011
12012
12013
12014
12015
12016
12017
12018
12019
12020
12021
12022
12023
12024
12025
12026
12027
12028
12029
12030
12031
12032
12033
12034
12035
12036
12037
12038
12039
12040
12041
12042
12043
12044
12045
12046
12047
12048
12049
12050
12051
12052
12053
12054
12055
12056
12057
12058
12059
12060
12061
12062
12063
12064
12065
12066
12067
12068
12069
12070
12071
12072
12073
12074
12075
12076
12077
12078
12079
12080
12081
12082
12083
12084
12085
12086
12087
12088
12089
12090
12091
12092
12093
12094
12095
12096
12097
12098
12099
12100
12101
12102
12103
12104
12105
12106
12107
12108
12109
12110
12111
12112
12113
12114
12115
12116
12117
12118
12119
12120
12121
12122
12123
12124
12125
12126
12127
12128
12129
12130
12131
12132
12133
12134
12135
12136
12137
12138
12139
12140
12141
12142
12143
12144
12145
12146
12147
12148
12149
12150
12151
12152
12153
12154
12155
12156
12157
12158
12159
12160
12161
12162
12163
12164
12165
12166
12167
12168
12169
12170
12171
12172
12173
12174
12175
12176
12177
12178
12179
12180
12181
12182
12183
12184
12185
12186
12187
12188
12189
12190
12191
12192
12193
12194
12195
12196
12197
12198
12199
12200
12201
12202
12203
12204
12205
12206
12207
12208
12209
12210
12211
12212
12213
12214
12215
12216
12217
12218
12219
12220
12221
12222
12223
12224
12225
12226
12227
12228
12229
12230
12231
12232
12233
12234
12235
12236
12237
12238
12239
12240
12241
12242
12243
12244
12245
12246
12247
12248
12249
12250
12251
12252
12253
12254
12255
12256
12257
12258
12259
12260
12261
12262
12263
12264
12265
12266
12267
12268
12269
12270
12271
12272
12273
12274
12275
12276
12277
12278
12279
12280
12281
12282
12283
12284
12285
12286
12287
12288
12289
12290
12291
12292
12293
12294
12295
12296
12297
12298
12299
12300
12301
12302
12303
12304
12305
12306
12307
12308
12309
12310
12311
12312
12313
12314
12315
12316
12317
12318
12319
12320
12321
12322
12323
12324
12325
12326
12327
12328
12329
12330
12331
12332
12333
12334
12335
12336
12337
12338
12339
12340
12341
12342
12343
12344
12345
12346
12347
12348
12349
12350
12351
12352
12353
12354
12355
12356
12357
12358
12359
12360
12361
12362
12363
12364
12365
12366
12367
12368
12369
12370
12371
12372
12373
12374
12375
12376
12377
12378
12379
12380
12381
12382
12383
12384
12385
12386
12387
12388
12389
12390
12391
12392
12393
12394
12395
12396
12397
12398
12399
12400
12401
12402
12403
12404
12405
12406
12407
12408
12409
12410
12411
12412
12413
12414
12415
12416
12417
12418
12419
12420
12421
12422
12423
12424
12425
12426
12427
12428
12429
12430
12431
12432
12433
12434
12435
12436
12437
12438
12439
12440
12441
12442
12443
12444
12445
12446
12447
12448
12449
12450
12451
12452
12453
12454
12455
12456
12457
12458
12459
12460
12461
12462
12463
12464
12465
12466
12467
12468
12469
12470
12471
12472
12473
12474
12475
12476
12477
12478
12479
12480
12481
12482
12483
12484
12485
12486
12487
12488
12489
12490
12491
12492
12493
12494
12495
12496
12497
12498
12499
12500
12501
12502
12503
12504
12505
12506
12507
12508
12509
12510
12511
12512
12513
12514
12515
12516
12517
12518
12519
12520
12521
12522
12523
12524
12525
12526
12527
12528
12529
12530
12531
12532
12533
12534
12535
12536
12537
12538
12539
12540
12541
12542
12543
12544
12545
12546
12547
12548
12549
12550
12551
12552
12553
12554
12555
12556
12557
12558
12559
12560
12561
12562
12563
12564
12565
12566
12567
12568
12569
12570
12571
12572
12573
12574
12575
12576
12577
12578
12579
12580
12581
12582
12583
12584
12585
12586
12587
12588
12589
12590
12591
12592
12593
12594
12595
12596
12597
12598
12599
12600
12601
12602
12603
12604
12605
12606
12607
12608
12609
12610
12611
12612
12613
12614
12615
12616
12617
12618
12619
12620
12621
12622
12623
12624
12625
12626
12627
12628
12629
12630
12631
12632
12633
12634
12635
12636
12637
12638
12639
12640
12641
12642
12643
12644
12645
12646
12647
12648
12649
12650
12651
12652
12653
12654
12655
12656
12657
12658
12659
12660
12661
12662
12663
12664
12665
12666
12667
12668
12669
12670
12671
12672
12673
12674
12675
12676
12677
12678
12679
12680
12681
12682
12683
12684
12685
12686
12687
12688
12689
12690
12691
12692
12693
12694
12695
12696
12697
12698
12699
12700
12701
12702
12703
12704
12705
12706
12707
12708
12709
12710
12711
12712
12713
12714
12715
12716
12717
12718
12719
12720
12721
12722
12723
12724
12725
12726
12727
12728
12729
12730
12731
12732
12733
12734
12735
12736
12737
12738
12739
12740
12741
12742
12743
12744
12745
12746
12747
12748
12749
12750
12751
12752
12753
12754
12755
12756
12757
12758
12759
12760
12761
12762
12763
12764
12765
12766
12767
12768
12769
12770
12771
12772
12773
12774
12775
12776
12777
12778
12779
12780
12781
12782
12783
12784
12785
12786
12787
12788
12789
12790
12791
12792
12793
12794
12795
12796
12797
12798
12799
12800
12801
12802
12803
12804
12805
12806
12807
12808
12809
12810
12811
12812
12813
12814
12815
12816
12817
12818
12819
12820
12821
12822
12823
12824
12825
12826
12827
12828
12829
12830
12831
12832
12833
12834
12835
12836
12837
12838
12839
12840
12841
12842
12843
12844
12845
12846
12847
12848
12849
12850
12851
12852
12853
12854
12855
12856
12857
12858
12859
12860
12861
12862
12863
12864
12865
12866
12867
12868
12869
12870
12871
12872
12873
12874
12875
12876
12877
12878
12879
12880
12881
12882
12883
12884
12885
12886
12887
12888
12889
12890
12891
12892
12893
12894
12895
12896
12897
12898
12899
12900
12901
12902
12903
12904
12905
12906
12907
12908
12909
12910
12911
12912
12913
12914
12915
12916
12917
12918
12919
12920
12921
12922
12923
12924
12925
12926
12927
12928
12929
12930
12931
12932
12933
12934
12935
12936
12937
12938
12939
12940
12941
12942
12943
12944
12945
12946
12947
12948
12949
12950
12951
12952
12953
12954
12955
12956
12957
12958
12959
12960
12961
12962
12963
12964
12965
12966
12967
12968
12969
12970
12971
12972
12973
12974
12975
12976
12977
12978
12979
12980
12981
12982
12983
12984
12985
12986
12987
12988
12989
12990
12991
12992
12993
12994
12995
12996
12997
12998
12999
13000
13001
13002
13003
13004
13005
13006
13007
13008
13009
13010
13011
13012
13013
13014
13015
13016
13017
13018
13019
13020
13021
13022
13023
13024
13025
13026
13027
13028
13029
13030
13031
13032
13033
13034
13035
13036
13037
13038
13039
13040
13041
13042
13043
13044
13045
13046
13047
13048
13049
13050
13051
13052
13053
13054
13055
13056
13057
13058
13059
13060
13061
13062
13063
13064
13065
13066
13067
13068
13069
13070
13071
13072
13073
13074
13075
13076
13077
13078
13079
13080
13081
13082
13083
13084
13085
13086
13087
13088
13089
13090
13091
13092
13093
13094
13095
13096
13097
13098
13099
13100
13101
13102
13103
13104
13105
13106
13107
13108
13109
13110
13111
13112
13113
13114
13115
13116
13117
13118
13119
13120
13121
13122
13123
13124
13125
13126
13127
13128
13129
13130
13131
13132
13133
13134
13135
13136
13137
13138
13139
13140
13141
13142
13143
13144
13145
13146
13147
13148
13149
13150
13151
13152
13153
13154
13155
13156
13157
13158
13159
13160
13161
13162
13163
13164
13165
13166
13167
13168
13169
13170
13171
13172
13173
13174
13175
13176
13177
13178
13179
13180
13181
13182
13183
13184
13185
13186
13187
13188
13189
13190
13191
13192
13193
13194
13195
13196
13197
13198
13199
13200
13201
13202
13203
13204
13205
13206
13207
13208
13209
13210
13211
13212
13213
13214
13215
13216
13217
13218
13219
13220
13221
13222
13223
13224
13225
13226
13227
13228
13229
13230
13231
13232
13233
13234
13235
13236
13237
13238
13239
13240
13241
13242
13243
13244
13245
13246
13247
13248
13249
13250
13251
13252
13253
13254
13255
13256
13257
13258
13259
13260
13261
13262
13263
13264
13265
13266
13267
13268
13269
13270
13271
13272
13273
13274
13275
13276
13277
13278
13279
13280
13281
13282
13283
13284
13285
13286
13287
13288
13289
13290
13291
13292
13293
13294
13295
13296
13297
13298
13299
13300
13301
13302
13303
13304
13305
13306
13307
13308
13309
13310
13311
13312
13313
13314
13315
13316
13317
13318
13319
13320
13321
13322
13323
13324
13325
13326
13327
13328
13329
13330
13331
13332
13333
13334
13335
13336
13337
13338
13339
13340
13341
13342
13343
13344
13345
13346
13347
13348
13349
13350
13351
13352
13353
13354
13355
13356
13357
13358
13359
13360
13361
13362
13363
13364
13365
13366
13367
13368
13369
13370
13371
13372
13373
13374
13375
13376
13377
13378
13379
13380
13381
13382
13383
13384
13385
13386
13387
13388
13389
13390
13391
13392
13393
13394
13395
13396
13397
13398
13399
13400
13401
13402
13403
13404
13405
13406
13407
13408
13409
13410
13411
13412
13413
13414
13415
13416
13417
13418
13419
13420
13421
13422
13423
13424
13425
13426
13427
13428
13429
13430
13431
13432
13433
13434
13435
13436
13437
13438
13439
13440
13441
13442
13443
13444
13445
13446
13447
13448
13449
13450
13451
13452
13453
13454
13455
13456
13457
13458
13459
13460
13461
13462
13463
13464
13465
13466
13467
13468
13469
13470
13471
13472
13473
13474
13475
13476
13477
13478
13479
13480
13481
13482
13483
13484
13485
13486
13487
13488
13489
13490
13491
13492
13493
13494
13495
13496
13497
13498
13499
13500
13501
13502
13503
13504
13505
13506
13507
13508
13509
13510
13511
13512
13513
13514
13515
13516
13517
13518
13519
13520
13521
13522
13523
13524
13525
13526
13527
13528
13529
13530
13531
13532
13533
13534
13535
13536
13537
13538
13539
13540
13541
13542
13543
13544
13545
13546
13547
13548
13549
13550
13551
13552
13553
13554
13555
13556
13557
13558
13559
13560
13561
13562
13563
13564
13565
13566
13567
13568
13569
13570
13571
13572
13573
13574
13575
13576
13577
13578
13579
13580
13581
13582
13583
13584
13585
13586
13587
13588
13589
13590
13591
13592
13593
13594
13595
13596
13597
13598
13599
13600
13601
13602
13603
13604
13605
13606
13607
13608
13609
13610
13611
13612
13613
13614
13615
13616
13617
13618
13619
13620
13621
13622
13623
13624
13625
13626
13627
13628
13629
13630
13631
13632
13633
13634
13635
13636
13637
13638
13639
13640
13641
13642
13643
13644
13645
13646
13647
13648
13649
13650
13651
13652
13653
13654
13655
13656
13657
13658
13659
13660
13661
13662
13663
13664
13665
13666
13667
13668
13669
13670
13671
13672
13673
13674
13675
13676
13677
13678
13679
13680
13681
13682
13683
13684
13685
13686
13687
13688
13689
13690
13691
13692
13693
13694
13695
13696
13697
13698
13699
13700
13701
13702
13703
13704
13705
13706
13707
13708
13709
13710
13711
13712
13713
13714
13715
13716
13717
13718
13719
13720
13721
13722
13723
13724
13725
13726
13727
13728
13729
13730
13731
13732
13733
13734
13735
13736
13737
13738
13739
13740
13741
13742
13743
13744
13745
13746
13747
13748
13749
13750
13751
13752
13753
13754
13755
13756
13757
13758
13759
13760
13761
13762
13763
13764
13765
13766
13767
13768
13769
13770
13771
13772
13773
13774
13775
13776
13777
13778
13779
13780
13781
13782
13783
13784
13785
13786
13787
13788
13789
13790
13791
13792
13793
13794
13795
13796
13797
13798
13799
13800
13801
13802
13803
13804
13805
13806
13807
13808
13809
13810
13811
13812
13813
13814
13815
13816
13817
13818
13819
13820
13821
13822
13823
13824
13825
13826
13827
13828
13829
13830
13831
13832
13833
13834
13835
13836
13837
13838
13839
13840
13841
13842
13843
13844
13845
13846
13847
13848
13849
13850
13851
13852
13853
13854
13855
13856
13857
13858
13859
13860
13861
13862
13863
13864
13865
13866
13867
13868
13869
13870
13871
13872
13873
13874
13875
13876
13877
13878
13879
13880
13881
13882
13883
13884
13885
13886
13887
13888
13889
13890
13891
13892
13893
13894
13895
13896
13897
13898
13899
13900
13901
13902
13903
13904
13905
13906
13907
13908
13909
13910
13911
13912
//! The runtime: it executes a parsed script against a desktop.
//!
//! A port of the runtime of the archived Python implementation. The script
//! is compiled in memory and executed statement by statement. Nothing is
//! written to disk: the source is gone when the turn is over.
//!
//! Every statement produces a record -- what it did, whether it worked,
//! how long it took -- because a script that drives a desktop has to be
//! able to say what it did, not just that it finished.
//!
//! The desktop is whatever implements [`Desktop`]. The real one lives on
//! the lab box (the `ahk-box` crate); the tests use a fake that records
//! the calls.
//!
//! ## The focus check
//!
//! A script that types into the wrong window is worse than a script that
//! fails, so the language carries the primitives that answer "is the right
//! thing in front of us?":
//!
//! * `MouseGetPos()` -- where the pointer is.
//! * `PixelGet(x, y)` -- the colour under it.
//! * `PixelSearch(x1, y1, x2, y2, colour)` -- where that colour is.
//!
//! These three work on any desktop, because they are read from the screen
//! itself. `WinActive(title)` and `WinExist(title)` are the window-level
//! questions, and they are answered by whatever the desktop can actually
//! ask: on a Wayland session with no window API, the answer is
//! *unknown*, and the runtime says so out loud rather than guessing
//! `false`. A script that cannot answer the question fails; it does not
//! quietly take the wrong branch.

use alloc::boxed::Box;
use alloc::collections::BTreeMap;
use alloc::collections::BTreeSet;
use alloc::format;
use alloc::string::{String, ToString};
use alloc::vec;
use alloc::vec::Vec;
use core::time::Duration;


use alloc::rc::Rc;
use core::cell::RefCell;

use crate::ast::{
    AccessBody, AccessDef, AssignOp, BinaryOp, Declarations, DeclareKind, DynamicPiece, LegacyForm,
    LiteralValue, LoopKind, MemberName, MethodDef, Node, ObjectItem, Parameter, PropertyDef,
    UnaryOp,
};

pub use crate::desktop::{Desktop, Files, WindowAnswer};

/// The variables of the loops, the ones that the runtime writes where it
/// runs.
///
/// Measured on the binary of v2.0.19 on 2026-10-31: they are there
/// before the first loop runs, and the index is zero and the others are
/// empty.
const THE_LOOP_VARIABLES: &[&str] = &[
    "index",
    "loopfield",
    "loopreadline",
    "loopfilename",
    "loopfileext",
    "loopfilepath",
    "loopfilefullpath",
    "loopfiledir",
    "loopregname",
    "loopregtype",
    "loopregkey",
    "loopregtimemodified",
];

/// The type of a value.
///
/// AutoHotkey v2 has four of them, and every value carries the tag of
/// the one it is. The tag is what the diagnostics name, so the name
/// here and the name in the message are the same word.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TypeName {
    /// Text.
    String,
    /// A whole number.
    Integer,
    /// A number with a point.
    Float,
    /// An object: a class instance, an array, a map.
    Object,
    /// A reference to a variable: `&x`.
    ///
    /// v2 names the kind a VarRef, and it is a value of its own: the
    /// operations that want a number or a text say that they got one.
    VarRef,
    /// A number: what the maths wants.
    ///
    /// No value carries this tag -- a whole number is an Integer and a
    /// number with a point is a Float -- but a parameter that wants a
    /// number names it in the message that says it got something else.
    Number,
    /// A class: what the `is` operator wants.
    ///
    /// The value of a class is an object of the tree, and the tag is
    /// what the message about the `is` operator names.
    Class,
    /// A value of COM.
    ///
    /// The tree carries none, and the name is here for the message of
    /// the dialect: "Parameter #1 of ComObjValue requires a ComValue,
    /// but received a VarRef.".
    ComValue,
}

impl TypeName {
    /// The name, the way the diagnostics spell it.
    ///
    /// The names are the ones of v2: a value carries the tag of its
    /// kind, and the tag is the word the diagnostics use.
    pub fn name(self) -> &'static str {
        match self {
            TypeName::String => "String",
            TypeName::Integer => "Integer",
            TypeName::Float => "Float",
            TypeName::Object => "Object",
            TypeName::VarRef => "VarRef",
            TypeName::Number => "Number",
            TypeName::Class => "Class",
            TypeName::ComValue => "ComValue",
        }
    }

    /// The name in lower case.
    ///
    /// v2 spells the kind of a value in two ways: the message about a
    /// built-in says "an Integer", and the message about a parameter of
    /// a function of the script says "an integer".
    pub fn lowercase(self) -> &'static str {
        match self {
            TypeName::String => "string",
            TypeName::Integer => "integer",
            TypeName::Float => "float",
            TypeName::Object => "object",
            TypeName::VarRef => "varref",
            TypeName::Number => "number",
            TypeName::Class => "class",
            TypeName::ComValue => "comvalue",
        }
    }

    /// The letter that goes with the name: "a string", "an integer".
    pub fn article(self) -> &'static str {
        match self {
            TypeName::Integer | TypeName::Object => "n",
            _ => "",
        }
    }

    /// The type as a sentence says it: "an integer".
    pub fn phrase(self) -> String {
        format!("a{} {}", self.article(), self.name())
    }
}

/// The message v2 gives when a value of the wrong type arrives.
///
/// The template is the one in the binary: "Expected a%s %s but got a%s
/// %s.". The two letters are the articles, and the article of an
/// integer or of an object is an "n".
pub fn expected_type(expected: TypeName, got: TypeName) -> String {
    format!(
        "Expected a{} {} but got a{} {}.",
        expected.article(),
        expected.name(),
        got.article(),
        got.name()
    )
}

/// The message v2 gives when a value of the wrong kind arrives.
///
/// The kind of the value that arrived is the name of its class: "an
/// Object", "an Array", "a Map", "a Func", "a Thing".
pub fn expected_the_kind(expected: TypeName, got: &str) -> String {
    format!(
        "Expected a{} {} but got a{} {}.",
        expected.article(),
        expected.name(),
        the_article_of(got),
        got
    )
}

/// The message v2 gives when the class of a value is not the one wanted.
///
/// The kind of the value is the name of its class: "Expected an Array but
/// got a Prototype.". The article follows the first letter of the name.
pub fn expected_the_class(expected: &str, got: &str) -> String {
    format!(
        "Expected a{} {} but got a{} {}.",
        the_article_of(expected),
        expected,
        the_article_of(got),
        got
    )
}

/// The article that goes with the name of a kind: "an Object", "a String".
fn the_article_of(name: &str) -> &'static str {
    match name.chars().next() {
        Some(first) if "AEIOU".contains(first.to_ascii_uppercase()) => "n",
        _ => "",
    }
}

/// The number that a text holds at its front.
///
/// Measured on the binary of v2.0.19 on 2026-10-31: "20x" is 20, "x20" is
/// 0, " 30 " is 30, "1.9" is 1, "1e3" is 1000, "1,5" is 1 and "+7" is 7.
fn the_number_of_the_text(text: &str) -> f64 {
    let text = text.trim();
    let bytes = text.as_bytes();
    let mut end = 0;
    if end < bytes.len() && (bytes[end] == b'+' || bytes[end] == b'-') {
        end += 1;
    }
    let mut digits = 0;
    while end < bytes.len() && bytes[end].is_ascii_digit() {
        end += 1;
        digits += 1;
    }
    if end < bytes.len() && bytes[end] == b'.' {
        end += 1;
        while end < bytes.len() && bytes[end].is_ascii_digit() {
            end += 1;
            digits += 1;
        }
    }
    if digits == 0 {
        return 0.0;
    }
    // The exponent: "1e3" is a thousand.
    if end < bytes.len() && (bytes[end] == b'e' || bytes[end] == b'E') {
        let mut next = end + 1;
        if next < bytes.len() && (bytes[next] == b'+' || bytes[next] == b'-') {
            next += 1;
        }
        let mut exponent = 0;
        while next < bytes.len() && bytes[next].is_ascii_digit() {
            next += 1;
            exponent += 1;
        }
        if exponent > 0 {
            end = next;
        }
    }
    text[..end].parse::<f64>().unwrap_or(0.0)
}

/// The message v2 gives when a maths operation gets something that is
/// not a number.
///
/// The template is the one in the binary: "Expected a%s %s but got a%s
/// %s.". A number is not one of the kinds a value carries: it is what
/// the operation wants, and the value it got is one of them.
pub fn expected_number(value: &Value) -> String {
    format!("Expected a Number but got {}.", the_kind_of(value))
}

/// The message v2 gives when a built-in gets a value of the wrong type.
///
/// The template is the one in the binary: "Parameter #%i of %s requires
/// a%s %s, but received a%s %s.". The type that was wanted and the type
/// that arrived are both named.
pub fn requires(index: usize, name: &str, wants: TypeName, value: &Value) -> String {
    format!(
        "Parameter #{index} of {name} requires a{} {}, but received {}.",
        wants.article(),
        wants.name(),
        the_kind_of(value)
    )
}

/// The message v2 gives when the body of a function checks the kind of a
/// value.
///
/// The template is the one of the binary: "Expected a%s %s but got a%s
/// %s.". The kind that was wanted is named as it is, and the kind that
/// arrived is the name of the class of the value: "Expected an Object
/// but got an empty string.".
pub fn expects_a_kind(kind: TypeName, value: &Value) -> String {
    format!(
        "Expected a{} {} but got {}.",
        kind.article(),
        kind.name(),
        the_kind_of(value)
    )
}

/// Whether a value is the kind that a parameter declares.
///
/// The dialect converts the value to the kind that the parameter
/// declares: a parameter that wants a text takes a number, and one that
/// wants a number takes a text that holds one.
pub fn accepts(kind: TypeName, value: &Value) -> bool {
    match kind {
        TypeName::String => matches!(value, Value::Text(_) | Value::Int(_) | Value::Float(_)),
        TypeName::Number | TypeName::Integer => value.to_number_strict().is_ok(),
        TypeName::Object => matches!(value, Value::Object(_)),
        // The tree carries no value of COM, and nothing is one.
        TypeName::ComValue => false,
        _ => true,
    }
}

/// Whether a value is the kind that the body of a function checks.
///
/// The check is the kind of the value itself: a number is not a text.
pub fn is_of_the_kind(kind: TypeName, value: &Value) -> bool {
    match kind {
        TypeName::String => matches!(value, Value::Text(_)),
        TypeName::Object => matches!(value, Value::Object(_)),
        _ => true,
    }
}

/// The kind of a value, as the message of a built-in names it.
///
/// A text is a String, and an empty one is an empty string; a number is
/// an Integer or a Float; an object is an Object; a reference is a
/// VarRef.
pub fn the_kind_of(value: &Value) -> String {
    match value {
        Value::Text(text) if text.is_empty() => "an empty string".to_string(),
        other => {
            let kind = other.the_kind();
            format!("a{} {}", the_article_of(&kind), kind)
        }
    }
}

/// The message v2 gives for a parameter that has no value.
///
/// A parameter that is an alias of a variable of the caller says that
/// it is the parameter that has no value, and not the variable.
pub fn unassigned_parameter() -> String {
    "This parameter has not been assigned a value.".to_string()
}

/// The mark of a value that has no value of its own.
///
/// The dialect has no value that means "nothing", and the tree carries the
/// mark of it: a list of one number, and the number is zero. The mark is not
/// a value that a script can hold, and the place of an array that has no
/// value of its own carries it.
pub(crate) fn the_mark_of_a_value_without_one() -> Value {
    Value::List(vec![Value::Int(0)])
}

/// Whether a value is the mark of a value that has no value of its own.
pub(crate) fn is_a_value_without_one(value: &Value) -> bool {
    matches!(value, Value::List(items) if items.len() == 1 && items[0] == Value::Int(0))
}

/// The message v2 gives for a parameter that cannot be used.
pub fn invalid_parameter(index: usize, name: &str) -> String {
    format!("Parameter #{index} of {name} is invalid.")
}

/// The message v2 gives when a parameter wants a reference and gets
/// something else.
///
/// The wording is the one of the handler that raises it: the built-in
/// that writes the pieces of a path says "a variable reference" and the
/// one that writes the place of the pointer says "a VarRef".
///
/// Measured on the binary of v2.0.19 on 2026-10-29: the message ends
/// with the kind of the value, and the value that was there is in the
/// `Extra` of the failure, and not in the message. The kind is the name
/// of the class of the value: "an Integer", "an Array", "an empty
/// string".
pub fn wants_a_reference(index: usize, name: &str, wants: &str, value: &Value) -> String {
    format!(
        "Parameter #{index} of {name} requires {wants}, but received {}.",
        the_kind_of(value)
    )
}

/// The reason the runtime refuses the directive of this name, when it does.
///
/// The directive is answered at the run, and the reason is the one of the
/// category of the directive: the hotkeys, the memory limits, the comment
/// flags. A directive that the runtime carries answers with `None`.
///
/// The surface asks this question, and the answer is the one that the run
/// gives: the table of the names and the run are the same truth.
pub fn refusal_of_directive(name: &str) -> Option<&'static str> {
    match name {
        "commentflag" | "escapechar" => Some("the comment flags are not carried by this runtime."),
        "maxmem" => Some("the memory limits are not carried by this runtime."),
        "if"
        | "iftimeout"
        | "ifwinactive"
        | "installkeybdhook"
        | "installmousehook"
        | "keyhistory"
        | "maxhotkeysperinterval"
        | "hotkeyinterval"
        | "hotkeymodifiertimeout"
        | "menumaskkey"
        | "usehook"
        | "hotif"
        | "hotiftimeout"
        | "hotstring"
        | "maxthreads"
        | "maxthreadsperhotkey"
        | "maxthreadsbuffer" => Some("the hotkeys are not carried by this runtime."),
        "clipboardtimeout" => Some("the clipboard is not carried by this runtime."),
        "inputlevel" => Some("the input level is not carried by this runtime."),
        "suspendexempt" => Some("the suspend is not carried by this runtime."),
        "winactivateforce" => Some("the window activation is not carried by this runtime."),
        "warn" => Some("the warnings are not carried by this runtime."),
        "include" | "includeagain" => {
            Some("the includes are resolved by the runner, not by the language.")
        }
        "dllload" => Some("a Windows library is a Windows thing and this box has none."),
        _ => None,
    }
}

/// The name of a file: the part of the path after the last separator.
///
/// The separator is the slash of a Linux path and the backslash of a
/// Windows one: a script may carry either.
fn the_name_of(path: &str) -> &str {
    match path.rfind(['/', '\\']) {
        Some(at) => &path[at + 1..],
        None => path,
    }
}

/// The folder a file is in: the part of the path before the last
/// separator.
fn the_folder_of(path: &str) -> &str {
    match path.rfind(['/', '\\']) {
        Some(at) => &path[..at],
        None => "",
    }
}

/// The path of a file that is relative to the folder that the script runs in.
///
/// Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-05: the path
/// of a file of the loop of the v1 is the one that is relative to the folder
/// that the script runs in: the "a.txt" of the folder itself, and the
/// "sub/d.txt" of a folder of it.
fn the_path_that_is_relative_to(file: &str, folder: &str) -> String {
    let rest = match file.strip_prefix(folder) {
        Some(rest) => rest,
        None => return file.to_string(),
    };
    rest.trim_start_matches(['/', '\\']).to_string()
}

/// The extension of a file: the part of the name after the last dot.
///
/// A dot that opens the name is not one: a file that begins with a dot
/// has no extension.
fn the_extension_of(name: &str) -> &str {
    match name.rfind('.') {
        Some(at) if at > 0 => &name[at + 1..],
        _ => "",
    }
}

/// The letter of the mode of the loop of the files that the mode does not
/// carry.
///
/// Measured on the binary of AutoHotkey v2.0.19 on 2026-11-05 and on the
/// binary of AutoHotkey v1.1.37.02 on 2026-11-05: the mode is a set of
/// letters -- the "R" walks into the folders, the "D" and the "K" give the
/// folders, the "F" and the "V" give the files -- and the spaces and the tabs
/// between them are ignored. The letter "A" is not one of them, and a number
/// is not one either.
fn the_letter_that_the_mode_does_not_carry(mode: &str) -> Option<char> {
    mode.chars().find(|letter| {
        !matches!(
            letter,
            'R' | 'r' | 'D' | 'd' | 'F' | 'f' | 'V' | 'v' | 'K' | 'k' | ' ' | '\t'
        )
    })
}

/// The path of a file without its extension.
fn without_the_extension(path: &str, extension: &str) -> String {
    if extension.is_empty() {
        return path.to_string();
    }
    path[..path.len() - extension.len() - 1].to_string()
}

/// The key the base of an object lives under.
///
/// The base is not a property of the object: v2 does not see it, and the
/// tree keeps it out of the way of the properties of the script. The key
/// has a space in it, so that a script cannot reach it by name.
pub(crate) const BASE: &str = "object base";

/// The class of the descriptor of a property.
///
/// The descriptor of v2 is an object with the members `Value`, `Get`,
/// `Set` and `Call`. The tree keeps the descriptor under a class of its
/// own, so that the read, the write and the call of the property know
/// that it is a descriptor and not a value.
pub(crate) const DESCRIPTOR: &str = "property descriptor";

/// The class that has the method a reference points at.
///
/// The key has a space in it, so that a script cannot reach it by name.
pub(crate) const METHOD_CLASS: &str = "method class";

/// The name of the method a reference points at.
pub(crate) const METHOD_NAME: &str = "method name";

/// The object that a function is bound to.
///
/// The key has a space in it, so that a script cannot reach it by name.
pub(crate) const BOUND: &str = "bound object";

/// What a function that is bound to an object calls.
///
/// The value is the name of a method of the object, or the function that is
/// bound. The key has a space in it, so that a script cannot reach it by
/// name.
pub(crate) const BOUND_TARGET: &str = "bound target";

/// The name under which the runtime keeps a closure.
///
/// The name of a closure of v2 is empty, and the name the runtime keeps it
/// under is not one a script can reach.
pub(crate) const CLOSURE: &str = "function closure";

/// The key the name of a class lives under.
///
/// v2 does not show the name of a class: a class value has no property
/// named `Name`, and a prototype has none either. The tree keeps the name
/// out of the way of the properties of the script. The key has a space in
/// it, so that a script cannot reach it by name.
pub(crate) const CLASS_NAME: &str = "class name";

/// Where a variable lives.
///
/// The scopes of the script are a stack: the global one is under the
/// ones of the functions. A reference says which one it points at.
/// A scope of the runtime: the names of a function.
///
/// The table is shared: a function that is written inside another one
/// closes over the scope of the one around it, and the write of the
/// closure is seen by the scope it closes over.
type ScopeTable = Rc<RefCell<BTreeMap<String, Value>>>;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Scope {
    /// The global scope of the script.
    Global,
    /// A local scope, by its place in the stack.
    Local(usize),
}

/// A reference to a variable: `&x`.
///
/// The reference is a value of its own kind, and v2 names it a VarRef.
#[derive(Debug, Clone, PartialEq)]
pub struct Reference {
    /// The name of the variable.
    pub name: String,
    /// Where the variable lives.
    pub scope: Scope,
    /// Whether the reference is an alias of the variable.
    ///
    /// A parameter written `&x` in the definition of a function is an
    /// alias: reading it reads the variable of the caller, and writing
    /// it writes there. A reference that is only a value is read as
    /// itself, and the operations that want a number or a text say that
    /// they got a VarRef.
    pub alias: bool,
}

/// A value a script can hold.
///
/// AutoHotkey v2 has no boolean: `true` is the integer 1 and `false` is
/// the integer 0. The tree keeps no boolean either, so that the tag on
/// the value is one of the kinds v2 has.
#[derive(Debug, Clone, PartialEq)]
pub enum Value {
    /// A whole number.
    Int(i64),
    /// A number with a point.
    Float(f64),
    /// Text.
    Text(String),
    /// A list of values: what `MouseGetPos` and `PixelSearch` return.
    List(Vec<Value>),
    /// An object: an instance of a class.
    ///
    /// The object is held behind a reference, because an object in a
    /// script is a reference too: writing a property of it is seen by
    /// everyone who holds it.
    Object(Rc<RefCell<Object>>),
    /// A reference to a variable: `&x`.
    ///
    /// The operator is carried by the arguments of a call, and the
    /// value of a reference is the value of the variable it points at.
    Reference(Reference),
}

/// An object: an instance of a class.
#[derive(Debug, Clone, PartialEq)]
pub struct Object {
    /// The name of the class the object is an instance of.
    pub class: String,
    /// The properties of the object.
    ///
    /// The key of the table is the name in lower case, and the name itself
    /// is kept beside the value: v2 gives the name as the script wrote it,
    /// and the first write is the one that fixes the case of it.
    pub properties: BTreeMap<String, Property>,
}

/// A property of an object: the name as the script wrote it, and the value.
#[derive(Debug, Clone, PartialEq)]
pub struct Property {
    /// The name of the property, as the script wrote it.
    pub name: String,
    /// The value of the property.
    pub value: Value,
}

/// Put a property in a table: the key is the name in lower case, and the name
/// is the one that was written.
///
/// Measured on the binary of v2.0.19 on 2026-10-31: the first write is the
/// one that fixes the case of the name -- `o.X := 1` and then `o.x := 2`
/// gives the name "X".
pub(crate) fn put(properties: &mut BTreeMap<String, Property>, name: &str, value: Value) {
    let key = name.to_lowercase();
    // The first write is the one that fixes the case of the name: a write
    // in the other case keeps the name that is there.
    let name = properties
        .get(&key)
        .map(|property| property.name.clone())
        .unwrap_or_else(|| name.to_string());
    properties.insert(key, Property { name, value });
}

impl Object {
    /// The value of a property, by the key of it.
    pub fn value_of(&self, key: &str) -> Option<Value> {
        self.properties
            .get(key)
            .map(|property| property.value.clone())
    }

    /// Put a property in, and keep the name that was written.
    pub fn put(&mut self, name: &str, value: Value) {
        put(&mut self.properties, name, value);
    }
}

/// A class: the methods, the properties, and the class it extends.
#[derive(Clone)]
pub struct Class {
    /// The name of the class.
    pub name: String,
    /// The class this one extends.
    pub extends: Option<String>,
    /// The methods of the class, by their name in lower case.
    pub methods: BTreeMap<String, MethodDef>,
    /// The properties of the class.
    pub properties: Vec<PropertyDef>,
    /// The properties that have a getter or a setter, by their name in
    /// lower case.
    pub accessors: BTreeMap<String, AccessDef>,
    /// The classes that the class holds, by their name in lower case.
    pub nested: Vec<String>,
}

impl Value {
    /// Whether the value counts as true.
    pub fn truthy(&self) -> bool {
        match self {
            // Measured on the binary of v2.0.19 on 2026-10-31: a text that
            // is "0" is false, and a text that is not empty is true.
            Value::Text(text) => !text.is_empty() && text != "0",
            Value::Int(number) => *number != 0,
            Value::Float(number) => *number != 0.0,
            Value::List(items) => !items.is_empty(),
            // An object is always true.
            Value::Object(_) => true,
            // A reference points at something, and that is true.
            Value::Reference(_) => true,
        }
    }

    /// The type of the value, the way v2 names it.
    pub fn type_name(&self) -> TypeName {
        match self {
            Value::Int(_) => TypeName::Integer,
            Value::Float(_) => TypeName::Float,
            Value::Text(_) => TypeName::String,
            Value::List(_) | Value::Object(_) => TypeName::Object,
            Value::Reference(_) => TypeName::VarRef,
        }
    }

    /// The value as text.
    pub fn to_text(&self) -> String {
        match self {
            Value::Int(number) => number.to_string(),
            // A float keeps its point: `2.0` is not `2` in v2, and a
            // script that prints one wants to see it.
            Value::Float(number) => {
                if fract(*number) == 0.0 && number.abs() < 9.0e15 {
                    format!("{number:.1}")
                } else {
                    number.to_string()
                }
            }
            Value::Text(text) => text.clone(),
            Value::List(items) => items
                .iter()
                .map(|item| item.to_text())
                .collect::<Vec<String>>()
                .join(","),
            // An object has no text of its own: what it says is the
            // class it is an instance of.
            Value::Object(object) => object.borrow().class.clone(),
            // A reference has no text of its own either: what it says
            // is the name of the variable it points at.
            Value::Reference(reference) => reference.name.clone(),
        }
    }

    /// The value as text, when it is one.
    ///
    /// A reference is not a text: the operations that want one say that
    /// they got a VarRef.
    pub fn as_text(&self) -> Result<String, TypeName> {
        match self {
            Value::Reference(_) => Err(TypeName::VarRef),
            other => Ok(other.to_text()),
        }
    }

    /// The kind of the value, the way v2 names it.
    ///
    /// An object is named after its class: "Object", "Map", "Func", the
    /// name of the class of the script. An array is an "Array". A class is
    /// a class of its own kind, and a prototype is of its own too.
    pub fn the_kind(&self) -> String {
        match self {
            Value::Int(_) => "Integer".to_string(),
            Value::Float(_) => "Float".to_string(),
            Value::Text(_) => "String".to_string(),
            Value::List(_) => "Array".to_string(),
            Value::Reference(_) => "VarRef".to_string(),
            Value::Object(object) => {
                let borrowed = object.borrow();
                // Measured on the binary of v2.0.19 on 2026-10-31: the
                // prototype is of its own kind, and a class is a class of
                // its own kind.
                if borrowed.class == "prototype" {
                    return "Prototype".to_string();
                }
                // A class holds its prototype, and an instance does not.
                if borrowed.properties.contains_key("prototype") {
                    return "Class".to_string();
                }
                let mut name = borrowed.class.clone();
                if name.is_empty() {
                    // An object without a class is an object: the v1 has no
                    // classes, and the name of the kind of it is the one of
                    // the base.
                    name = "Object".to_string();
                }
                if let Some(first) = name.get_mut(0..1) {
                    first.make_ascii_uppercase();
                }
                name
            }
        }
    }

    /// The value as a number, when it is one.
    ///
    /// A string that does not hold a number is not a number: the maths
    /// operations ask for the difference between the two.
    pub fn to_number(&self) -> Option<f64> {
        match self {
            Value::Int(number) => Some(*number as f64),
            Value::Float(number) => Some(*number),
            Value::Text(text) => text.trim().parse::<f64>().ok(),
            Value::List(_) | Value::Object(_) | Value::Reference(_) => None,
        }
    }

    /// The value as a number, the way a maths operation wants it.
    ///
    /// A string that holds a number is a number. A string that holds
    /// anything else is a string, and the type it actually is comes back
    /// with the failure, so that the message can name it.
    pub fn to_number_strict(&self) -> Result<f64, TypeName> {
        match self {
            Value::Int(number) => Ok(*number as f64),
            Value::Float(number) => Ok(*number),
            Value::Text(text) => {
                let trimmed = text.trim();
                if trimmed.is_empty() {
                    return Err(TypeName::String);
                }
                trimmed.parse::<f64>().map_err(|_| TypeName::String)
            }
            Value::List(_) | Value::Object(_) => Err(TypeName::Object),
            Value::Reference(_) => Err(TypeName::VarRef),
        }
    }

    /// The value as a number, the way a setting takes it.
    ///
    /// Measured on the binary of v2.0.19 on 2026-10-31: a text holds the
    /// number it carries at its front, and a text that holds no number is
    /// zero: "20x" is 20 and "x20" is 0.
    pub fn to_number_lenient(&self) -> f64 {
        match self {
            Value::Int(number) => *number as f64,
            Value::Float(number) => *number,
            Value::Text(text) => the_number_of_the_text(text),
            _ => 0.0,
        }
    }

    /// A number as a whole number when it is one.
    pub fn from_number(number: f64) -> Value {
        if fract(number) == 0.0 && number.abs() < 9.0e15 {
            Value::Int(number as i64)
        } else {
            Value::Float(number)
        }
    }
}

/// A statement failed.
#[derive(Debug)]
pub struct RuntimeError {
    pub message: String,
    pub line: u32,
}

impl core::fmt::Display for RuntimeError {
    fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(formatter, "{} (line {})", self.message, self.line)
    }
}

#[cfg(feature = "std")]
impl std::error::Error for RuntimeError {}

/// The script ran for longer than the caller allowed.
#[derive(Debug)]
pub struct Timeout {
    pub seconds: f64,
}

impl core::fmt::Display for Timeout {
    fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(formatter, "the script ran for more than {}s", self.seconds)
    }
}

#[cfg(feature = "std")]
impl std::error::Error for Timeout {}

/// The clock the runtime measures itself with, and waits on.
///
/// The crate does no I/O of its own, and a clock is I/O in the same way a
/// desktop is: it belongs to the machine the script runs on, not to the
/// language. A hosted platform uses [`SystemClock`]; a target with no
/// `std` at all supplies its own.
pub trait Clock {
    /// The milliseconds since an arbitrary origin. It never goes backwards.
    fn now_ms(&self) -> u64;

    /// Wait for the given number of milliseconds.
    fn sleep_ms(&mut self, millis: u64);

    /// The date and the time of the machine, when it knows them.
    ///
    /// The clock of a run counts from an arbitrary origin, and it does not
    /// know the date. A host that knows the date says so here; a host that
    /// does not leaves it at nothing, and the names of the date answer with
    /// the reason.
    fn wall_clock(&self) -> Option<crate::date::WallClock> {
        None
    }
}

/// The clock of a hosted platform: the monotonic clock, and the system sleep.
#[cfg(feature = "std")]
#[derive(Debug, Clone, Copy)]
pub struct SystemClock {
    started: std::time::Instant,
}

#[cfg(feature = "std")]
impl SystemClock {
    /// A clock that starts counting now.
    pub fn new() -> Self {
        Self {
            started: std::time::Instant::now(),
        }
    }
}

#[cfg(feature = "std")]
impl Default for SystemClock {
    fn default() -> Self {
        Self::new()
    }
}

#[cfg(feature = "std")]
impl Clock for SystemClock {
    fn now_ms(&self) -> u64 {
        self.started.elapsed().as_millis() as u64
    }

    fn sleep_ms(&mut self, millis: u64) {
        std::thread::sleep(Duration::from_millis(millis));
    }

    fn wall_clock(&self) -> Option<crate::date::WallClock> {
        crate::date::system_wall_clock()
    }
}

/// Where the runtime gets the time from.
enum ClockSource<'a> {
    /// A clock the caller owns.
    Borrowed(&'a mut dyn Clock),
    /// The clock of the host.
    #[cfg(feature = "std")]
    System(SystemClock),
}

impl ClockSource<'_> {
    fn now_ms(&self) -> u64 {
        match self {
            ClockSource::Borrowed(clock) => clock.now_ms(),
            #[cfg(feature = "std")]
            ClockSource::System(clock) => clock.now_ms(),
        }
    }

    fn sleep_ms(&mut self, millis: u64) {
        match self {
            ClockSource::Borrowed(clock) => clock.sleep_ms(millis),
            #[cfg(feature = "std")]
            ClockSource::System(clock) => clock.sleep_ms(millis),
        }
    }

    fn wall_clock(&self) -> Option<crate::date::WallClock> {
        match self {
            ClockSource::Borrowed(clock) => clock.wall_clock(),
            #[cfg(feature = "std")]
            ClockSource::System(clock) => clock.wall_clock(),
        }
    }
}

/// What one statement did.
#[derive(Debug, Clone)]
pub struct Step {
    pub line: u32,
    pub op: String,
    pub detail: String,
    pub ok: bool,
    pub elapsed_ms: u64,
}

/// The whole run: the steps, the output, and whether it finished.
#[derive(Debug, Clone, Default)]
pub struct Report {
    pub ok: bool,
    pub steps: Vec<Step>,
    pub output: Vec<String>,
    /// The warnings of the script.
    pub warnings: Vec<crate::warnings::Warning>,
    pub notes: Vec<String>,
    pub error: Option<String>,
    pub error_line: Option<u32>,
    pub exit_code: Option<i32>,
    pub elapsed_ms: u64,
    pub variables: BTreeMap<String, Value>,
}

/// The way a script left a block.
pub(crate) enum Flow {
    Break,
    Continue,
    Return(Option<Value>),
    Exit(i32),
    /// The jump of a `Goto`: the name of the label, as the script wrote
    /// it, and the line of the jump.
    ///
    /// The name is the text of the parameter, and not its value: v2 reads
    /// the name of a label as it stands, and the quotes of a text are part
    /// of it.
    Goto {
        name: String,
        line: u32,
    },
}

/// What the functions of the error said about a failure.
///
/// The answers are the ones of v2: 0 lets the failure go on, 1 hides it,
/// and -1 hides it and lets the thread continue.
enum TheError {
    /// The failure goes on: it is the error of the run.
    Goes,
    /// The failure is hidden, and the thread ends.
    Hidden,
    /// The failure is hidden, and the thread continues.
    Continues,
}

/// A function the script defined.
#[derive(Clone)]
struct Function {
    /// The name of the function, as the script wrote it.
    name: String,
    /// The parameters it takes.
    parameters: Vec<Parameter>,
    body: Vec<Node>,
    /// The declarations of the function.
    declarations: Declarations,
    /// The scopes the function closes over.
    ///
    /// A function that is written inside another one sees the variables of
    /// the one around it, and it writes them there too.
    closure: Vec<ScopeTable>,
}

/// A timer the script set.
///
/// The timer names a function of the script, and it runs between the
/// statements, not in a thread of its own.
struct Timer {
    /// The name of the function the timer runs.
    name: String,
    /// The milliseconds between two runs.
    period: u64,
    /// When it ran the last time.
    last: u64,
}

/// A function of the script that the runtime calls.
///
/// It is the callback of the exit or of the error. The name is the one the
/// script wrote, and the line is the line of the statement that registered
/// it: a function that fails says where it was asked for.
#[derive(Clone)]
pub(crate) struct Callback {
    /// The name of the function the script registered.
    pub name: String,
    /// The line of the statement that registered it.
    pub line: u32,
}

/// A frame of a call that runs.
///
/// The frame is the name of the function or of the method, and the line of
/// the statement that runs in it. The stack of an error of v2 names both.
#[derive(Debug, Clone)]
struct Frame {
    name: String,
    line: u32,
}

/// Executes a script.
///
/// The limits are the guard rails: a script that loops forever must not
/// take the box with it, and one that types a million characters must not
/// either. Both limits are reported when they are hit.
pub struct Runtime<'a> {
    desktop: &'a mut dyn Desktop,
    clock: ClockSource<'a>,
    /// The dialect that the run speaks.
    ///
    /// The v2 is the dialect of the tree, and it is the one of every run
    /// that does not ask for another one. The v1 is behind the gate of the
    /// `--dialect=v1` of the runner, and it has a table of its own names
    /// and rules of its own.
    dialect: &'static dyn crate::dialect::Dialect,
    /// Whether the environment is looked up.
    ///
    /// The directive `#NoEnv` of the v1 turns the lookup off, and the
    /// substitution of a parameter of the v1 is then the variable of the
    /// script alone.
    no_env: bool,
    /// The warnings of the script.
    ///
    /// Measured on the binary of AutoHotkey v2.0.19 on 2026-11-05: the
    /// warnings are computed before the script runs, and they go to the
    /// report.
    warnings: Vec<crate::warnings::Warning>,
    /// The mode of each warning of the script.
    ///
    /// Measured on the binary of AutoHotkey v2.0.19 on 2026-11-05 and on the
    /// binary of AutoHotkey v1.1.37.02 on 2026-11-05: the directives are read
    /// before the script runs, and the mode of each warning is the one of the
    /// last `#Warn` that names it.
    modes: crate::warnings::TheModes,
    /// Whether the text of a legacy assignment is trimmed.
    ///
    /// Measured on the binary of v1.1.37.02 on 2026-11-02: the `AutoTrim`
    /// of the v1 is On when the script begins, and the command turns it off.
    /// The text of a legacy assignment is trimmed when it is On, and the
    /// command parameters of the v1 are not trimmed by it.
    auto_trim: bool,
    /// The format of the whole numbers, the way the dialect formats them.
    integer_format: IntegerFormat,
    /// The format of the floats, the way the dialect formats them.
    float_format: FloatFormat,
    /// The sense of the case, the way the dialect compares the letters.
    ///
    /// Measured on the binary of v1.1.37.02 on 2026-11-02: the sense is Off
    /// when the script begins, and the `StringCaseSense` turns it into On or
    /// into Locale.
    case_sense: CaseSense,
    /// The number of the lines that the script runs at once.
    ///
    /// Measured on the binary of v1.1.37.02 on 2026-11-02: the number is
    /// "10ms" when the script begins, and the `SetBatchLines` turns it into
    /// the number that was written.
    batch_lines: alloc::string::String,
    timeout: Duration,
    variables: BTreeMap<String, Value>,
    /// The directory where the run started.
    ///
    /// The runtime asks the desktop for it when it is made, and it keeps
    /// it: a script that changes the working directory does not change the
    /// one where the run began.
    initial_working_dir: Option<String>,
    scopes: Vec<ScopeTable>,
    /// The labels of the scope that runs.
    ///
    /// A label belongs to the scope it is written in: the scope of the
    /// script, or the scope of a function or of a method. `IsLabel` asks
    /// the scope that runs whether it holds the label, and the name of a
    /// label does not know its case.
    label_scopes: Vec<Vec<String>>,
    /// Whether the runtime is running the body of a hotkey of the v1.
    ///
    /// Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-03: the
    /// body of a hotkey is the code that comes after it, and the `return` of
    /// it ends the thread of the hotkey and not the script.
    in_the_body_of_a_hotkey: bool,
    /// The declarations of the functions that run.
    ///
    /// The frame of a function says where its names live: the ones it
    /// declares global live in the scope of the script, and the ones it
    /// declares local live in the scope of the function.
    declarations: Vec<Declarations>,
    /// The static variables of the functions that ran.
    ///
    /// A static variable belongs to the function that declares it, and it
    /// keeps its value between the calls: the table of the function is
    /// here, and not in the scope of the call.
    ///
    /// Measured on the binary of v2.0.19 on 2026-10-31: the static of a
    /// function is the same one in every call of it, the static of a
    /// recursion is the same one in every turn of it, and two functions
    /// have two of them.
    statics: BTreeMap<String, BTreeMap<String, Value>>,
    /// The static declarations that already ran their value.
    ///
    /// Measured on the binary of v2.0.19 on 2026-10-31: the value of a
    /// static declaration runs the first time that declaration is reached,
    /// and a declaration that the function does not reach on the first call
    /// runs its value on the call that reaches it.
    statics_run: BTreeMap<String, BTreeSet<String>>,
    /// The classes of the methods that run.
    ///
    /// `super` asks the base of the class where the method was defined,
    /// and that class is the one the frame carries.
    current_classes: Vec<String>,
    /// The frames of the calls that run.
    ///
    /// The frame is the name of the function or of the method that
    /// runs: v2 puts it in the `What` of an error that does not carry
    /// one. The frame carries the line of the statement that runs in it,
    /// and the stack of an error names it.
    frames: Vec<Frame>,
    /// The files of the file-reading loops that run.
    ///
    /// The name of the file of a `FileAppend` may be left out inside the
    /// body of a `Loop Read` that has a file of its own, and the text goes
    /// to that file. The last one of the list is the loop that runs.
    loop_output_files: Vec<String>,
    /// Whether the short names of the files are refused.
    ///
    /// Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-05: the
    /// `A_LoopFileShortName` is the name that Windows gives to a file that has
    /// a short one, and this box has none: the script that reads the name is
    /// told that. The field is set when a loop of the files runs, and the
    /// name has no value before it.
    the_short_names_of_the_files_are_refused: bool,
    /// The lines of the script, when the host gave them.
    ///
    /// The stack of an error names the source of the line that failed,
    /// and the script of the runner has no file of its own.
    source: Vec<String>,
    /// The line of the statement that runs in the section that starts the
    /// script.
    ///
    /// The section that starts the script is the last frame of the stack
    /// of v2, and it has no name.
    auto_execute_line: u32,
    functions: BTreeMap<String, Function>,
    /// How many closures the runtime made.
    ///
    /// The name of a closure is empty, and the runtime keeps every one of
    /// them under a name of its own.
    closures: usize,
    classes: BTreeMap<String, Class>,
    /// The class values the runtime made.
    ///
    /// A class is one object for the whole run: the name of it, the class
    /// it extends and the prototype of it. Two names of the same class
    /// are the same object, and that is what tells a class from an
    /// instance of one.
    class_values: RefCell<BTreeMap<String, Value>>,
    /// The classes that are already initialised.
    ///
    /// A class of v2 is initialised when it is first used: its variables
    /// that belong to it are assigned then, and the `__New` that is static
    /// is the one that runs.
    initialised: RefCell<BTreeSet<String>>,
    steps: Vec<Step>,
    output: Vec<String>,
    notes: Vec<String>,
    started_ms: u64,
    steps_taken: usize,
    /// The calls that are running right now.
    depth: usize,
    /// Where the stack was when the runtime was made.
    stack_base: usize,
    /// How much stack the run may use.
    stack_budget: usize,
    /// The timers the script set.
    timers: Vec<Timer>,
    /// The hotkeys the script set.
    ///
    /// The runtime owns the function that a hotkey runs; the desktop owns
    /// the watching of the keyboard, and says which hotkey was pressed.
    hotkeys: Vec<crate::hotkeys::Hotkey>,
    /// The code the script asked to stop with.
    exit_requested: Option<i32>,
    /// The functions to call when the script ends.
    ///
    /// The script asks for them with `OnExit`, and the runtime calls them
    /// when the script ends, whatever the reason the script ended.
    exit_callbacks: Vec<Callback>,
    /// The functions to call when a failure is not caught.
    ///
    /// The script asks for them with `OnError`.
    error_callbacks: Vec<Callback>,
    /// Whether the body of a `try` is running.
    ///
    /// While it runs, the functions of the error are not called: the catch
    /// of the script takes the failure first, and the functions of the
    /// error are called only when no catch took it.
    try_active: usize,
    /// Whether the functions of the error hid a failure.
    ///
    /// A failure that was hidden is not the error of the run: the script
    /// asked for it to be hidden, and it is.
    failure_hidden: bool,
    /// The value that the catch of the running `try` took.
    ///
    /// `throw` without a value throws it again, the way v2 does.
    caught_value: Option<Value>,
}

impl<'a> Runtime<'a> {
    /// The most statements one script may execute.
    ///
    /// The guard rail is for a script that runs away, not for a script
    /// that types: a thousand characters are a thousand statements, and a
    /// script that clears a field of a thousand characters is doing its
    /// job. The timeout is the other bound.
    pub const MAX_STEPS: usize = 20_000;
    /// The most times a loop body may run.
    pub const MAX_ITERATIONS: usize = 1000;
    /// The most nested calls a script may make.
    ///
    /// v2.0.19 stops at about 1105 nested calls, with "Function recursion
    /// limit exceeded." The tree stops at the same place.
    pub const MAX_DEPTH: usize = 1000;
    /// How much stack a run may use, when the host does not say.
    ///
    /// The frames of the tree are heavier than the ones of v2: a debug
    /// build uses about 50 KB of stack per call and a release build about
    /// 5 KB. A host with a small stack would run out of it before the
    /// depth says so, and the run stops when the stack is gone.
    pub const MAX_STACK: usize = 512 * 1024;

    /// A runtime that drives `desktop` for at most `timeout`, measured by
    /// the system clock.
    #[cfg(feature = "std")]
    pub fn new(desktop: &'a mut dyn Desktop, timeout: Duration) -> Self {
        let initial_working_dir = desktop.initial_working_directory().ok();
        Self {
            desktop,
            clock: ClockSource::System(SystemClock::new()),
            dialect: crate::dialect::v2(),
            no_env: false,
            warnings: Vec::new(),
            modes: crate::warnings::TheModes::the_defaults_of_the_v2(),
            auto_trim: true,
            integer_format: IntegerFormat::Decimal,
            float_format: FloatFormat::DEFAULT,
            case_sense: CaseSense::Off,
            batch_lines: "10ms".to_string(),
            timeout,
            variables: BTreeMap::new(),
            statics: BTreeMap::new(),
            statics_run: BTreeMap::new(),
            initial_working_dir,
            scopes: Vec::new(),
            label_scopes: Vec::new(),
            in_the_body_of_a_hotkey: false,
            declarations: Vec::new(),
            current_classes: Vec::new(),
            frames: Vec::new(),
            loop_output_files: Vec::new(),
            the_short_names_of_the_files_are_refused: false,
            source: Vec::new(),
            auto_execute_line: 0,
            functions: BTreeMap::new(),
            closures: 0,
            classes: BTreeMap::new(),
            class_values: RefCell::new(BTreeMap::new()),
            initialised: RefCell::new(BTreeSet::new()),
            steps: Vec::new(),
            output: Vec::new(),
            notes: Vec::new(),
            started_ms: 0,
            steps_taken: 0,
            depth: 0,
            stack_base: Self::stack_here(),
            stack_budget: Self::MAX_STACK,
            timers: Vec::new(),
            hotkeys: Vec::new(),
            exit_requested: None,
            exit_callbacks: Vec::new(),
            error_callbacks: Vec::new(),
            try_active: 0,
            failure_hidden: false,
            caught_value: None,
        }
    }

    /// A runtime that drives `desktop` for at most `timeout`, measured by
    /// `clock`.
    ///
    /// This is the constructor for a target with no `std`: the clock is
    /// the platform's, and so is the pause the `Sleep` statement asks
    /// for.
    pub fn with_clock(
        desktop: &'a mut dyn Desktop,
        clock: &'a mut dyn Clock,
        timeout: Duration,
    ) -> Self {
        let started_ms = clock.now_ms();
        let initial_working_dir = desktop.initial_working_directory().ok();
        Self {
            desktop,
            clock: ClockSource::Borrowed(clock),
            dialect: crate::dialect::v2(),
            no_env: false,
            warnings: Vec::new(),
            modes: crate::warnings::TheModes::the_defaults_of_the_v2(),
            auto_trim: true,
            integer_format: IntegerFormat::Decimal,
            float_format: FloatFormat::DEFAULT,
            case_sense: CaseSense::Off,
            batch_lines: "10ms".to_string(),
            timeout,
            variables: BTreeMap::new(),
            statics: BTreeMap::new(),
            statics_run: BTreeMap::new(),
            initial_working_dir,
            scopes: Vec::new(),
            label_scopes: Vec::new(),
            in_the_body_of_a_hotkey: false,
            declarations: Vec::new(),
            current_classes: Vec::new(),
            frames: Vec::new(),
            loop_output_files: Vec::new(),
            the_short_names_of_the_files_are_refused: false,
            source: Vec::new(),
            auto_execute_line: 0,
            functions: BTreeMap::new(),
            closures: 0,
            classes: BTreeMap::new(),
            class_values: RefCell::new(BTreeMap::new()),
            initialised: RefCell::new(BTreeSet::new()),
            steps: Vec::new(),
            output: Vec::new(),
            notes: Vec::new(),
            started_ms,
            steps_taken: 0,
            depth: 0,
            stack_base: Self::stack_here(),
            stack_budget: Self::MAX_STACK,
            timers: Vec::new(),
            hotkeys: Vec::new(),
            exit_requested: None,
            exit_callbacks: Vec::new(),
            error_callbacks: Vec::new(),
            try_active: 0,
            failure_hidden: false,
            caught_value: None,
        }
    }

    /// A runtime whose run may use `bytes` of stack.
    ///
    /// The host that gives the run a deep stack says so here, and the run
    /// stops before the stack is gone.
    pub fn with_stack_budget(mut self, bytes: usize) -> Self {
        self.stack_budget = bytes;
        self
    }

    /// A runtime that knows the source of the script.
    ///
    /// The stack of an error of v2 names the source of the line that
    /// failed, and the host that reads the script gives it here.
    pub fn with_source(mut self, source: &str) -> Self {
        self.source = source.lines().map(|line| line.to_string()).collect();
        self
    }

    /// A runtime that speaks the dialect of this name.
    ///
    /// The v2 is the dialect of the tree, and a runtime that does not ask
    /// for another one speaks it. The v1 is behind the gate of the
    /// `--dialect=v1` of the runner.
    pub fn with_dialect(mut self, dialect: &'static dyn crate::dialect::Dialect) -> Self {
        self.dialect = dialect;
        // The settings of the script begin with the defaults of the dialect
        // that the run speaks: the v1 and the v2 do not begin with the same
        // values.
        self.dialect.the_defaults_of_the_settings();
        self
    }

    /// The dialect that the run speaks.
    pub fn dialect(&self) -> &'static dyn crate::dialect::Dialect {
        self.dialect
    }

    /// Whether the text of a legacy assignment is trimmed.
    ///
    /// Measured on the binary of v1.1.37.02 on 2026-11-02: the `AutoTrim`
    /// of the v1 is On when the script begins, and the command turns it off.
    pub fn auto_trim(&self) -> bool {
        self.auto_trim
    }

    /// The trim of the legacy assignments of the v1, on or off.
    pub fn set_auto_trim(&mut self, on: bool) {
        self.auto_trim = on;
    }

    /// The number of the lines that the script runs at once.
    ///
    /// Measured on the binary of v1.1.37.02 on 2026-11-02: the number is
    /// "10ms" when the script begins, and the `SetBatchLines` turns it into
    /// the number that was written.
    pub fn batch_lines(&self) -> &str {
        &self.batch_lines
    }

    /// The number of the lines that the script runs at once.
    pub fn set_batch_lines(&mut self, text: &str) {
        self.batch_lines = text.to_string();
    }

    /// The format of the integers, the way the dialect formats them.
    pub fn integer_format(&self) -> IntegerFormat {
        self.integer_format
    }

    /// The format of the floats, the way the dialect formats them.
    pub fn float_format(&self) -> FloatFormat {
        self.float_format
    }

    /// The format of the integers, the way the dialect formats them.
    pub fn set_integer_format(&mut self, format: IntegerFormat) {
        self.integer_format = format;
    }

    /// The format of the floats, the way the dialect formats them.
    pub fn set_float_format(&mut self, format: FloatFormat) {
        self.float_format = format;
    }

    /// The sense of the case, the way the dialect compares the letters.
    ///
    /// Measured on the binary of v1.1.37.02 on 2026-11-02: the sense is Off
    /// when the script begins, and the `StringCaseSense` turns it into On or
    /// into Locale.
    pub fn case_sense(&self) -> CaseSense {
        self.case_sense
    }

    /// The write of the last error of the run, the way the v1 keeps it.
    ///
    /// Measured on the binary of v1.1.37.02 on 2026-11-02: the `ErrorLevel`
    /// of the v1 is the global variable of the script, and a command that
    /// fails writes it -- the `StringGetPos` writes zero when it finds the
    /// text and one when it does not, and the `StringReplace` writes the
    /// number of the replacements when the parameter says "useerrorlevel" and
    /// zero when it does not. The write is the one of the script, and it does
    /// not care about the scope that runs: a function that writes the name
    /// writes a local one, and the machine writes the global.
    pub(crate) fn set_the_error_level(&mut self, value: Value) {
        self.variables.insert(the_key_of("ErrorLevel"), value);
    }

    /// The sense of the case of the run.
    pub fn set_case_sense(&mut self, sense: CaseSense) {
        self.case_sense = sense;
    }

    /// Whether an object has no text in the dialect that runs.
    ///
    /// Measured on the binary of v1.1.37.02 on 2026-11-02: the text of an
    /// object of the v1 is the empty text.
    pub(crate) fn an_object_has_no_text(&self) -> bool {
        self.dialect.an_object_has_no_text()
    }

    /// The text of a value, in the format of the dialect.
    ///
    /// Measured on the binary of v1.1.37.02 on 2026-11-02: the numbers of
    /// the v1 are formatted by the `SetFormat`: the float is rounded to the
    /// decimals of the format, and the whole number is in the base of the
    /// format. The v2 writes the numbers the way they are.
    pub fn the_text_of(&self, value: &Value) -> String {
        // Measured on the binary of v1.1.37.02 on 2026-11-02: the text of an
        // object of the v1 is the empty text -- `Object()` is a blank text,
        // and `Object() . "a"` is "a".
        if self.dialect.an_object_has_no_text() {
            if let Value::Object(_) = value {
                return String::new();
            }
        }
        if !self.dialect.formats_the_numbers() {
            return value.to_text();
        }
        match value {
            Value::Int(number) => self.integer_format.the_text_of(*number),
            Value::Float(number) => self.float_format.the_text_of(*number),
            other => other.to_text(),
        }
    }

    /// The built-in of this name, in the dialect that runs.
    ///
    /// The name is matched the way AutoHotkey matches it: without regard
    /// to the case.
    pub(crate) fn builtin(&self, name: &str) -> Option<&'static crate::builtins::Builtin> {
        let wanted = name.to_lowercase();
        self.dialect
            .builtins()
            .iter()
            .find(|builtin| builtin.name.to_lowercase() == wanted)
    }

    /// The built-in of this name and of this kind, in the dialect that runs.
    ///
    /// Measured on the binary of v1.1.37.02 on 2026-11-03: the `GetKeyState`
    /// of the v1 is a command and a function, and the call of an expression
    /// is the function: it takes one parameter and it answers the state of
    /// the key. The name that the dialect carries once is the row of it,
    /// whatever the kind is.
    pub(crate) fn the_builtin_of_the_kind(
        &self,
        name: &str,
        kind: crate::builtins::BuiltinKind,
    ) -> Option<&'static crate::builtins::Builtin> {
        let wanted = name.to_lowercase();
        let builtins = self.dialect.builtins();
        builtins
            .iter()
            .find(|builtin| builtin.name.to_lowercase() == wanted && builtin.kind == kind)
            .or_else(|| {
                builtins
                    .iter()
                    .find(|builtin| builtin.name.to_lowercase() == wanted)
            })
    }

    /// The milliseconds since the run started.
    fn elapsed_ms(&self) -> u64 {
        self.clock.now_ms().saturating_sub(self.started_ms)
    }

    /// The milliseconds the run has left before the timeout of the script.
    ///
    /// The timeout is checked between the statements, and a built-in that
    /// waits inside one does not pass through that check.
    pub(crate) fn remaining_ms(&self) -> u64 {
        let limit = self.timeout.as_millis() as u64;
        limit.saturating_sub(self.elapsed_ms())
    }

    /// The hotkeys of the v1 are registered when the script loads.
    ///
    /// Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-03: the
    /// hotkey that is written in the body of another one is registered too,
    /// and the registration of it does not wait for the code that comes
    /// before it.
    fn register_the_hotkeys_of_the_v1(&mut self, statements: &[Node]) -> Result<(), RuntimeError> {
        for statement in statements {
            if let Node::HotkeyDefinition {
                name, body, line, ..
            } = statement
            {
                crate::hotkeys::register_the_hotkey_of_the_v1(self, name, body.clone(), *line)
                    .map_err(|failure| match failure {
                        RuntimeFailure::Error(error) => error,
                        RuntimeFailure::Detailed(error, _) => error,
                        RuntimeFailure::Fatal(error) => error,
                        _ => RuntimeError {
                            message: "the hotkey could not be registered.".to_string(),
                            line: *line,
                        },
                    })?;
                self.register_the_hotkeys_of_the_v1(body)?;
            }
        }
        Ok(())
    }

    /// Run the script and report what happened.
    pub fn run(mut self, statements: &[Node]) -> Report {
        let mut error = None;
        let mut error_line = None;
        let mut exit_code = None;
        // The functions are collected before the first statement runs, so a
        // script may call a function it defines further down.
        self.collect_functions(statements);
        // The warnings of the script are computed before the script runs, the
        // way the v2 computes them: the directives are all read, and then the
        // script is checked.
        //
        // Measured on the binary of AutoHotkey v2.0.19 on 2026-11-05: the
        // warning of the unreachable line is given before the first statement
        // runs, and the mode of the "StdOut" writes it to the standard
        // output.
        self.warnings = self.the_warnings_of_the_script(statements);
        // The hotkeys of the v1 are registered when the script loads, and
        // the one that is written in the body of another one is registered
        // too.
        //
        // Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-03: the
        // hotkey of the v1 is registered when the script loads, and not when
        // the code that comes before it runs.
        let registered = self.register_the_hotkeys_of_the_v1(statements);
        // The labels of the script are the scope of the script.
        self.label_scopes.push(the_labels_of(statements));
        match registered {
            Ok(()) => match self.run_block(statements) {
                Ok(()) => {}
                Err(RuntimeFailure::Flow(Flow::Break))
                | Err(RuntimeFailure::Flow(Flow::Continue)) => {}
                Err(RuntimeFailure::Flow(Flow::Return(_))) => {}
                Err(RuntimeFailure::Flow(Flow::Exit(code))) => exit_code = Some(code),
                // The jump of a `Goto` that leaves the script: the label is not
                // in the scope of the script.
                Err(RuntimeFailure::Flow(Flow::Goto { name, line })) => {
                    let failure = self.the_label_is_not_there(&name, statements, line);
                    error = Some(failure.message);
                    error_line = Some(failure.line);
                }
                Err(RuntimeFailure::Fatal(failure)) => {
                    error = Some(failure.message);
                    error_line = Some(failure.line);
                }
                Err(RuntimeFailure::Error(failure)) => {
                    error = Some(failure.message);
                    error_line = Some(failure.line);
                }
                Err(RuntimeFailure::Detailed(failure, _)) => {
                    error = Some(failure.message);
                    error_line = Some(failure.line);
                }
                Err(RuntimeFailure::Timeout(timeout)) => {
                    error = Some(timeout.to_string());
                }
                // A value that was thrown and that no catch took.
                Err(RuntimeFailure::Thrown(value)) => {
                    error = Some(thrown_message(&value));
                }
            },
            // The desktop cannot watch the keyboard, and the script is told
            // why: a hotkey that is registered and never fires is a hotkey
            // that does not work.
            Err(failure) => {
                error = Some(failure.message);
                error_line = Some(failure.line);
            }
        }
        // A failure that the functions of the error hid is not the error of
        // the run: the script asked for it to be hidden, and it is.
        if self.failure_hidden {
            error = None;
            error_line = None;
        }
        // The script has ended. The functions it asked to run at its exit
        // run now: the end is the moment the runtime knows, and it knows
        // it whatever the reason the script ended.
        let reason = if error.is_some() { "Error" } else { "Exit" };
        let code = exit_code.unwrap_or(0);
        // The script has already stopped: the flag that stops it does not
        // stop the functions of the exit, and the code of the run is the
        // code the script asked with.
        self.exit_requested = None;
        let mut prevented = false;
        let callbacks: Vec<Callback> = core::mem::take(&mut self.exit_callbacks);
        for callback in callbacks {
            let values = [Value::Text(reason.to_string()), Value::Int(code as i64)];
            match self.call_named(&callback.name, &values, callback.line, Route::Written) {
                Ok(answer) => {
                    // A function that answers a number that is not zero
                    // keeps the script alive, and the functions that come
                    // after it are not called.
                    if answer.to_number().unwrap_or(0.0) != 0.0 {
                        prevented = true;
                        break;
                    }
                }
                Err(failure) => {
                    let (message, line) = match failure {
                        RuntimeFailure::Error(error) => (error.message, error.line),
                        RuntimeFailure::Detailed(error, _) => (error.message, error.line),
                        RuntimeFailure::Fatal(error) => (error.message, error.line),
                        RuntimeFailure::Thrown(value) => (thrown_message(&value), 0),
                        RuntimeFailure::Timeout(timeout) => (timeout.to_string(), 0),
                        RuntimeFailure::Flow(_) => (
                            "the function of the exit left the script in the middle of a block."
                                .to_string(),
                            0,
                        ),
                    };
                    if error.is_none() {
                        error = Some(message);
                        error_line = Some(if line == 0 { callback.line } else { line });
                    } else {
                        // The script had already failed: its failure is the
                        // error of the run, and the failure of the function of
                        // the exit is a note, so that it is not lost.
                        self.note(format!("the function of the exit failed: {message}"));
                    }
                }
            }
        }
        if prevented {
            // The exit was prevented, and the code the script asked for is
            // not the code of the run. This runtime has no way to keep a
            // script alive, so the run ends anyway.
            exit_code = None;
            self.note(
                "a function of the exit asked to keep the script alive, and this runtime ends the script when its statements end.",
            );
        }
        // A function of the exit may ask to stop with a code of its own,
        // and that code is the code of the run.
        if let Some(code) = self.exit_requested {
            exit_code = Some(code);
        }
        let elapsed_ms = self.elapsed_ms();
        Report {
            ok: error.is_none(),
            steps: self.steps,
            output: self.output,
            warnings: self.warnings,
            notes: self.notes,
            error,
            error_line,
            exit_code,
            elapsed_ms,
            variables: self.variables.clone(),
        }
    }

    /// The warnings of the script.
    ///
    /// Measured on the binary of AutoHotkey v2.0.19 on 2026-11-05: the check
    /// of the unreachable lines is made before the script runs, and the mode
    /// of the "StdOut" writes the warning to the standard output with the
    /// line of it. The tree has no dialog, and the warning goes to the
    /// report.
    fn the_warnings_of_the_script(&mut self, statements: &[Node]) -> Vec<crate::warnings::Warning> {
        self.modes = crate::warnings::the_modes_of_the_script(statements, self.dialect);
        // The type of the warning that the tree does not carry yet is named in
        // the report: the script asks for it, and the tree does not give it.
        for kind in crate::warnings::the_types_of_the_script(statements, self.dialect) {
            if !crate::warnings::the_types_that_are_carried().contains(&kind) {
                self.note(format!(
                    "the warnings of the type \"{}\" are not carried by this runtime.",
                    crate::warnings::the_name_of_the_type(kind)
                ));
            }
        }
        let mut warnings = Vec::new();
        // Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-05 and on
        // the binary of AutoHotkey v2.0.19 on 2026-11-05: the warning of the
        // local that has the name of a global is given when the script is
        // read, and it comes before the warning of the variable that is read
        // and never written.
        if self.modes.local_same_as_global != crate::warnings::WarningMode::Off {
            let mode = self.modes.local_same_as_global;
            for warning in crate::warnings::the_warnings_of_the_locals_that_are_globals(
                statements,
                self.dialect,
            ) {
                self.warn(warning.line, warning.message.clone(), mode);
                warnings.push(warning);
            }
        }
        // Measured on the binary of AutoHotkey v2.0.19 on 2026-11-05: the
        // warning of the variable that is read and never written is given when
        // the script is read, and not when the variable is read.
        if self.modes.var_unset != crate::warnings::WarningMode::Off {
            let mode = self.modes.var_unset;
            for warning in
                crate::warnings::the_warnings_of_the_variables_that_are_never_written(statements)
            {
                self.warn(warning.line, warning.message.clone(), mode);
                warnings.push(warning);
            }
        }
        // Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-05: the
        // warning of the class that is overwritten comes after the warning of
        // the local that has the name of a global.
        if self.modes.class_overwrite != crate::warnings::WarningMode::Off {
            let mode = self.modes.class_overwrite;
            for warning in
                crate::warnings::the_warnings_of_the_classes_that_are_overwritten(statements)
            {
                self.warn(warning.line, warning.message.clone(), mode);
                warnings.push(warning);
            }
        }
        // Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-05 and on
        // the binary of AutoHotkey v2.0.19 on 2026-11-05: the warning of the
        // line that never runs comes last.
        if self.modes.unreachable != crate::warnings::WarningMode::Off {
            let mode = self.modes.unreachable;
            for warning in crate::warnings::the_warnings_of_the_script(statements) {
                self.warn(warning.line, warning.message.clone(), mode);
                warnings.push(warning);
            }
        }
        warnings
    }

    /// The warning of the script.
    ///
    /// Measured on the binary of AutoHotkey v2.0.19 on 2026-11-05: the mode
    /// of the "StdOut" writes the warning to the standard output with the
    /// line of it, and the tree has no dialog: the other modes write it to
    /// the report alone.
    fn warn(&mut self, line: u32, message: String, mode: crate::warnings::WarningMode) {
        self.warnings.push(crate::warnings::Warning {
            line,
            message: message.clone(),
        });
        if mode == crate::warnings::WarningMode::StdOut {
            self.output
                .push(format!("({line}) : ==> Warning: {message}"));
        }
    }

    /// The warning of the variable that is read and never written.
    ///
    /// Measured on the binary of AutoHotkey v2.0.19 on 2026-11-05: the
    /// warning is given before the failure of the run, and the text of it
    /// names the kind of the variable -- "This global variable appears to
    /// never be assigned a value." and "This local variable appears to never
    /// be assigned a value.".
    ///
    /// Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-05: the
    /// text of the v1 is one for the two kinds, and the kind is in the text
    /// that names the variable -- "This variable has not been assigned a
    /// value." and "nope  (a global variable)". A local variable that has the
    /// name of a global one says so -- "x  (a local variable with same name
    /// as a global)".
    fn warn_about_the_variable_that_has_no_value(&mut self, name: &str, line: u32) {
        // Measured on the binary of AutoHotkey v2.0.19 on 2026-11-05: the
        // warning of the v2 is given when the script is read, and not when the
        // variable is read: the runtime only fails.
        if !self.dialect.unset_is_blank() {
            return;
        }
        let local = !matches!(self.the_scope_of(name), Scope::Global);
        let kind = if local {
            if self.variables.contains_key(&the_key_of(name)) {
                "a local variable with same name as a global"
            } else {
                "a local variable"
            }
        } else {
            "a global variable"
        };
        let mode = if local {
            self.modes.use_unset_local
        } else {
            self.modes.use_unset_global
        };
        if mode == crate::warnings::WarningMode::Off {
            return;
        }
        self.warn(
            line,
            format!(
                "This variable has not been assigned a value.\n     Specifically: {name}  ({kind})"
            ),
            mode,
        );
    }

    /// The warning of the environment variable that is accessed.
    ///
    /// Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-05: the
    /// text of it is "An environment variable is being accessed; see
    /// #NoEnv." and the name of the variable, and it is given when the
    /// environment is accessed.
    fn warn_about_the_environment_that_is_accessed(&mut self, name: &str, line: u32) {
        let mode = self.modes.use_env;
        if mode == crate::warnings::WarningMode::Off {
            return;
        }
        let message = format!(
            "An environment variable is being accessed; see #NoEnv.\n     Specifically: {name}"
        );
        self.warn(line, message, mode);
    }

    /// A note for the report: a thing the script should know, and that is
    /// not the error of the run.
    pub fn note(&mut self, note: impl Into<String>) {
        self.notes.push(note.into());
    }

    /// Find the functions and the classes the script defines, wherever
    /// they are.
    fn collect_functions(&mut self, statements: &[Node]) {
        for statement in statements {
            match statement {
                Node::ClassDef {
                    name,
                    extends,
                    methods,
                    properties,
                    accessors,
                    nested,
                    ..
                } => {
                    let mut table: BTreeMap<String, MethodDef> = BTreeMap::new();
                    for method in methods {
                        table.insert(method.name.to_lowercase(), method.clone());
                    }
                    let mut properties_with_a_getter: BTreeMap<String, AccessDef> = BTreeMap::new();
                    for access in accessors {
                        properties_with_a_getter.insert(access.name.to_lowercase(), access.clone());
                    }
                    // The classes that a class holds are classes of their own.
                    let mut held = Vec::new();
                    for node in nested {
                        if let Node::ClassDef { name, .. } = node {
                            held.push(name.to_lowercase());
                        }
                    }
                    self.classes.insert(
                        name.to_lowercase(),
                        Class {
                            name: name.clone(),
                            extends: extends.clone(),
                            methods: table,
                            properties: properties.clone(),
                            accessors: properties_with_a_getter,
                            nested: held,
                        },
                    );
                    self.collect_functions(nested);
                }
                Node::FunctionDef {
                    name,
                    parameters,
                    body,
                    declarations,
                    ..
                } => {
                    self.functions.insert(
                        name.to_lowercase(),
                        Function {
                            name: name.clone(),
                            parameters: parameters.clone(),
                            body: body.clone(),
                            declarations: declarations.clone(),
                            closure: Vec::new(),
                        },
                    );
                }
                Node::Block { body, .. } => self.collect_functions(body),
                Node::LegacyIf {
                    body, otherwise, ..
                } => {
                    self.collect_functions(body);
                    self.collect_functions(otherwise);
                }
                Node::If {
                    branches,
                    otherwise,
                    ..
                } => {
                    for branch in branches {
                        self.collect_functions(&branch.tail);
                        self.collect_functions(&branch.body);
                    }
                    self.collect_functions(otherwise);
                }
                Node::Switch { cases, .. } => {
                    for case in cases {
                        self.collect_functions(&case.body);
                    }
                }
                Node::While { body, .. } | Node::Loop { body, .. } => self.collect_functions(body),
                Node::Try {
                    body,
                    catches,
                    otherwise,
                    finally,
                    ..
                } => {
                    self.collect_functions(body);
                    for catch in catches {
                        self.collect_functions(&catch.body);
                    }
                    self.collect_functions(otherwise);
                    self.collect_functions(finally);
                }
                _ => {}
            }
        }
    }

    /// The functions that are written inside a function.
    ///
    /// v2 knows them when the function is read: a function that is written
    /// inside another one is there before the statement that defines it
    /// runs, and it closes over the scope of the function that has it.
    fn collect_the_nested_functions(&mut self, statements: &[Node]) {
        for statement in statements {
            match statement {
                Node::FunctionDef {
                    name,
                    parameters,
                    body,
                    declarations,
                    ..
                } => {
                    let function = Function {
                        name: name.clone(),
                        parameters: parameters.clone(),
                        body: body.clone(),
                        declarations: declarations.clone(),
                        closure: self.scopes.clone(),
                    };
                    let closure = self.make_a_closure(function.clone());
                    let value = closure_value(&closure, &function);
                    self.assign_in_the_scope(name, value);
                }
                Node::Block { body, .. } => self.collect_the_nested_functions(body),
                Node::LegacyIf {
                    body, otherwise, ..
                } => {
                    self.collect_the_nested_functions(body);
                    self.collect_the_nested_functions(otherwise);
                }
                Node::If {
                    branches,
                    otherwise,
                    ..
                } => {
                    for branch in branches {
                        self.collect_the_nested_functions(&branch.body);
                    }
                    self.collect_the_nested_functions(otherwise);
                }
                Node::Switch { cases, .. } => {
                    for case in cases {
                        self.collect_the_nested_functions(&case.body);
                    }
                }
                Node::While { body, .. } | Node::Loop { body, .. } => {
                    self.collect_the_nested_functions(body)
                }
                Node::Try {
                    body,
                    catches,
                    otherwise,
                    finally,
                    ..
                } => {
                    self.collect_the_nested_functions(body);
                    for catch in catches {
                        self.collect_the_nested_functions(&catch.body);
                    }
                    self.collect_the_nested_functions(otherwise);
                    self.collect_the_nested_functions(finally);
                }
                _ => {}
            }
        }
    }

    /// The failure of a `Goto` that does not find its label.
    ///
    /// Measured on the binary of v2.0.19 on 2026-10-31: a label of another
    /// scope is not found in the current one, and a label of a block that
    /// does not enclose the jump is refused with a failure of its own.
    fn the_label_is_not_there(&self, name: &str, scope: &[Node], line: u32) -> RuntimeError {
        if the_labels_of(scope)
            .iter()
            .any(|label| label.eq_ignore_ascii_case(name))
        {
            return RuntimeError {
                message: self
                    .dialect
                    .the_refusal_of_a_jump_into_a_block()
                    .to_string(),
                line,
            };
        }
        RuntimeError {
            message: format!("Label not found in current scope.\n     Specifically: {name}"),
            line,
        }
    }

    /// Whether the scope that runs holds the label.
    ///
    /// Measured on the binary of v2.0.19 on 2026-10-31: the label is asked
    /// in the scope that runs, and the name of a label does not know its
    /// case.
    pub fn has_label(&self, name: &str) -> bool {
        let Some(scope) = self.label_scopes.last() else {
            return false;
        };
        scope.iter().any(|label| label.eq_ignore_ascii_case(name))
    }

    fn run_block(&mut self, statements: &[Node]) -> Result<(), RuntimeFailure> {
        let mut index = 0;
        while index < statements.len() {
            let statement = &statements[index];
            // Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-05:
            // the `A_LineNumber` is the line of the statement that runs, and
            // the tree did not write it.
            self.set_global("A_LineNumber", Value::Int(statement.line() as i64));
            // A failure of the statement is given to the functions that
            // asked to see it, before the stack unwinds: one of them may
            // say that the thread continues.
            match self.execute(statement) {
                Ok(()) => {}
                // The jump of a `Goto` is not a failure: the run goes on at
                // the label when this block holds it, and it goes out of
                // the block when it does not.
                Err(RuntimeFailure::Flow(Flow::Goto { name, line })) => {
                    match the_place_of_the_label(statements, &name) {
                        Some(place) => index = place,
                        None => return Err(RuntimeFailure::Flow(Flow::Goto { name, line })),
                    }
                }
                // A failure that no catch takes goes out at once.
                Err(failure @ RuntimeFailure::Fatal(_)) => return Err(failure),
                Err(failure) => match self.ask_the_error_callbacks(&failure) {
                    // The thread continues: the statement that failed is
                    // over, and the failure is not the error of the run.
                    TheError::Continues => {}
                    // The failure is hidden, and the thread ends.
                    TheError::Hidden => {
                        self.failure_hidden = true;
                        self.note(format!(
                            "the functions of the error hid the failure: {}",
                            the_message_of(&failure)
                        ));
                        return Err(failure);
                    }
                    TheError::Goes => return Err(failure),
                },
            }
            // The timers of the script run between its statements, and
            // only there: a function of the script is not the script.
            if self.the_section_that_runs() {
                self.run_timers()?;
                // The hotkeys of the script run between its statements,
                // and only there: a function of the script is not the
                // script, and a hotkey runs with the scope of the script
                // and not with the scope of the function.
                //
                // Measured on the binary of AutoHotkey v1.1.37.02 on
                // 2026-11-03: the body of a hotkey of the v1 may jump to a
                // label of the script, and the jump goes on at the label.
                match crate::hotkeys::run_fired(self) {
                    Ok(()) => {}
                    Err(RuntimeFailure::Flow(Flow::Goto { name, line })) => {
                        match the_place_of_the_label(statements, &name) {
                            Some(place) => index = place,
                            None => return Err(RuntimeFailure::Flow(Flow::Goto { name, line })),
                        }
                    }
                    Err(failure) => return Err(failure),
                }
                // Measured on the binary of AutoHotkey v1.1.37.02 on
                // 2026-11-03: the section of the script that runs ends at
                // the first hotkey or at the first hotstring of the v1, and
                // the hotkey itself is registered when the script loads.
                if self.dialect.the_section_that_runs_ends_at_the_hotkey()
                    && self.the_statement_ends_the_section(statement)
                {
                    return Ok(());
                }
            }
            // A script that asked to stop, stops at the end of the
            // statement it asked in.
            if let Some(code) = self.exit_requested {
                return Err(RuntimeFailure::Flow(Flow::Exit(code)));
            }
            index += 1;
        }
        Ok(())
    }

    /// The body of a hotkey of the v1.
    ///
    /// Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-03: the
    /// body of a hotkey runs with the scope of the script, and the `return`
    /// of it ends the thread of the hotkey and not the script.
    pub(crate) fn run_the_body_of_a_hotkey(&mut self, body: &[Node]) -> Result<(), RuntimeFailure> {
        let was_in_the_body = self.in_the_body_of_a_hotkey;
        self.in_the_body_of_a_hotkey = true;
        let answer = self.run_block(body);
        self.in_the_body_of_a_hotkey = was_in_the_body;
        match answer {
            // The `return` ends the hotkey, and the script goes on.
            Err(RuntimeFailure::Flow(Flow::Return(_))) => Ok(()),
            other => other,
        }
    }

    /// Whether the runtime is running the section of the script that runs.
    ///
    /// The body of a hotkey of the v1 runs with the scope of the script, and
    /// it is not the section: the timers of the script do not run there, and
    /// the section does not end there.
    fn the_section_that_runs(&self) -> bool {
        self.scopes.is_empty() && !self.in_the_body_of_a_hotkey
    }

    /// Whether the statement ends the section of the script that runs.
    ///
    /// Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-03: the
    /// section of the v1 ends at the first hotkey or at the first
    /// hotstring, and the code that comes after it does not run.
    fn the_statement_ends_the_section(&self, statement: &Node) -> bool {
        match statement {
            Node::HotkeyDefinition { .. } => true,
            Node::LegacyCall { name, .. } => name == "hotstring",
            _ => false,
        }
    }

    /// The `try` of the dialect: the block is guarded, the catches take
    /// the values that were thrown, the `else` runs when nothing was
    /// thrown, and the `finally` always runs.
    fn run_try(
        &mut self,
        body: &[Node],
        catches: &[crate::ast::Catch],
        otherwise: &[Node],
        finally: &[Node],
    ) -> Result<(), RuntimeFailure> {
        self.try_active += 1;
        let mut failure = self.run_block(body).err();
        self.try_active -= 1;
        let mut taken = false;
        // The value that the catch sees: the error of the runtime is an
        // object of the class `error`, and a thrown value is the value
        // itself.
        let thrown = match failure.as_ref() {
            Some(RuntimeFailure::Error(error)) => Some(self.error_value(error)),
            Some(RuntimeFailure::Detailed(error, detail)) => {
                Some(self.error_value_with(error, detail))
            }
            Some(RuntimeFailure::Thrown(value)) => Some(value.clone()),
            _ => None,
        };
        if let Some(value) = thrown {
            for catch in catches {
                if !self.catch_takes(catch, &value)? {
                    continue;
                }
                taken = true;
                if let Some(variable) = &catch.variable {
                    self.assign(variable, value.clone());
                }
                // The `throw` without a value throws again what this catch
                // took.
                let before = self.caught_value.replace(value);
                let result = self.run_block(&catch.body);
                self.caught_value = before;
                failure = result.err();
                break;
            }
        }
        if !taken && failure.is_none() {
            // Nothing was thrown: the `else` runs.
            failure = self.run_block(otherwise).err();
        }
        // The `finally` always runs, and the failure it leaves is the one
        // that is left.
        if let Err(other) = self.run_block(finally) {
            failure = Some(other);
        }
        match failure {
            Some(failure) => Err(failure),
            None => Ok(()),
        }
    }

    /// Whether the catch takes the value that was thrown.
    ///
    /// The class of the catch is a name: `any` takes everything, `error`
    /// takes the errors of the runtime, and a class of the script takes the
    /// objects of that class and of the classes that extend it.
    fn catch_takes(
        &self,
        catch: &crate::ast::Catch,
        value: &Value,
    ) -> Result<bool, RuntimeFailure> {
        let class = catch.class.to_lowercase();
        if class == "any" {
            return Ok(true);
        }
        if class == "error" {
            // Measured on the binary of v2.0.19 on 2026-10-31: a catch that
            // names no class takes every error of the runtime. The errors
            // are a tree of classes, and every one of them is an `Error`.
            let Value::Object(object) = value else {
                return Ok(false);
            };
            return Ok(crate::classes::error::is_a_class(&object.borrow().class));
        }
        // A class of the script. A class that the tree does not know is a
        // question it cannot answer, and it says so.
        let known = self.classes.contains_key(&class)
            || crate::classes::is_type(&class)
            || class == "object";
        if !known {
            return Err(RuntimeFailure::Error(RuntimeError {
                message: format!(
                    "the class of a catch is not a class of this runtime: {}",
                    catch.class
                ),
                line: 0,
            }));
        }
        Ok(self.value_has_class(value, &class))
    }

    /// Whether the value is an object of the class, or of one that extends
    /// it.
    fn value_has_class(&self, value: &Value, class: &str) -> bool {
        let Value::Object(object) = value else {
            return false;
        };
        let mut name = object.borrow().class.clone();
        loop {
            if name.eq_ignore_ascii_case(class) {
                return true;
            }
            match self.classes.get(&name.to_lowercase()) {
                Some(definition) => match &definition.extends {
                    Some(base) => name = base.clone(),
                    None => return false,
                },
                None => return false,
            }
        }
    }

    /// The error of the runtime as a value: an object of the class `error`,
    /// the way v2 hands it to a catch.
    fn error_value(&self, error: &RuntimeError) -> Value {
        crate::classes::error::error_value_of(
            crate::classes::error::the_class_of(&error.message),
            &error.message,
            "",
            "",
            error.line,
            &self.the_stack(),
        )
    }

    /// The error of the runtime as a value, with the detail of it.
    ///
    /// The detail is the name of the thing that raised the failure, and
    /// the detail that goes with it.
    fn error_value_with(&self, error: &RuntimeError, detail: &Detail) -> Value {
        crate::classes::error::error_value_of(
            crate::classes::error::the_class_of(&error.message),
            &error.message,
            &detail.what,
            &detail.extra,
            error.line,
            &self.the_stack(),
        )
    }

    /// The stack of an error, the way v2 writes it.
    ///
    /// Measured on the binary of v2.0.19 on 2026-10-31: every frame is a
    /// line of its own -- the file, the line, the name of the frame and
    /// the source of the line -- and the last line names the section
    /// that starts the script.
    ///
    /// The script of the runner has no file of its own, and the file of
    /// every frame is empty.
    pub(crate) fn the_stack(&self) -> String {
        let mut lines: Vec<String> = Vec::new();
        for frame in self.frames.iter().rev() {
            lines.push(self.the_line_of_a_frame(&frame.name, frame.line));
        }
        lines.push(self.the_line_of_a_frame("", self.auto_execute_line));
        lines.push("> Auto-execute".to_string());
        lines.join("\n")
    }

    /// The line of a frame of the stack.
    fn the_line_of_a_frame(&self, name: &str, line: u32) -> String {
        format!(" ({line}) : [{name}] {}", self.the_source_of_the_line(line))
    }

    /// The source of a line of the script, when the host gave it.
    ///
    /// Measured on the binary of v2.0.19 on 2026-10-31: the source that
    /// the stack names is the text of the line without the space that
    /// indents it.
    fn the_source_of_the_line(&self, line: u32) -> String {
        self.source
            .get(line.saturating_sub(1) as usize)
            .map(|text| text.trim().to_string())
            .unwrap_or_default()
    }

    /// The name of the thing that threw a value.
    ///
    /// v2 puts the name of the function or of the method in the `What`
    /// of an error that does not carry one.
    fn name_the_thrower(&self, value: &Value) {
        let Value::Object(object) = value else { return };
        if object.borrow().class != "error" {
            return;
        }
        let carries = object
            .borrow()
            .value_of("what")
            .map(|what| !what.to_text().is_empty())
            .unwrap_or(false);
        if carries {
            return;
        }
        let Some(frame) = self.frames.last() else {
            return;
        };
        put(
            &mut object.borrow_mut().properties,
            "what",
            Value::Text(frame.name.clone()),
        );
    }

    /// The timers that are due.
    ///
    /// The steps of a timer are steps of the script, so the budget of a
    /// timer is the budget of the script.
    fn run_timers(&mut self) -> Result<(), RuntimeFailure> {
        let now = self.now_ms();
        let due: Vec<String> = self
            .timers
            .iter_mut()
            .filter(|timer| now.saturating_sub(timer.last) >= timer.period)
            .map(|timer| {
                timer.last = now;
                timer.name.clone()
            })
            .collect();
        for name in due {
            let Some(function) = self.functions.get(&name.to_lowercase()).cloned() else {
                continue;
            };
            self.call_function(&function, &[], 0, Route::Written)?;
        }
        Ok(())
    }

    /// Set a timer of the script.
    pub(crate) fn add_timer(&mut self, name: &str, period: u64) {
        let last = self.now_ms();
        self.timers.push(Timer {
            name: name.to_string(),
            period,
            last,
        });
    }

    /// Stop the script with this code.
    pub(crate) fn exit_with(&mut self, code: i32) {
        self.exit_requested = Some(code);
    }

    /// A method of the base object, for the names that ask about an
    /// object.
    pub(crate) fn base_object(
        &mut self,
        target: &Value,
        name: &str,
        arguments: &[Value],
        line: u32,
    ) -> Result<Value, RuntimeError> {
        match self.base_method(target, name, arguments, line) {
            Some(Ok(value)) => Ok(value),
            Some(Err(RuntimeFailure::Error(error))) => Err(error),
            Some(Err(RuntimeFailure::Detailed(error, _))) => Err(error),
            Some(Err(_)) => Err(RuntimeError {
                message: "the runtime cannot answer that.".into(),
                line,
            }),
            None => Err(RuntimeError {
                message: format!(
                    "This value of type \"{}\" has no method named {name:?}.",
                    self.the_type_of(target)
                ),
                line,
            }),
        }
    }

    fn execute(&mut self, statement: &Node) -> Result<(), RuntimeFailure> {
        self.steps_taken += 1;
        // The stack of an error names the line of the statement that runs
        // in every frame.
        match self.frames.last_mut() {
            Some(frame) => frame.line = statement.line(),
            None => self.auto_execute_line = statement.line(),
        }
        if self.steps_taken > Self::MAX_STEPS {
            return Err(RuntimeFailure::Error(RuntimeError {
                message: format!("the script ran more than {} statements", Self::MAX_STEPS),
                line: statement.line(),
            }));
        }
        if self.elapsed_ms() > self.timeout.as_millis() as u64 {
            return Err(RuntimeFailure::Timeout(Timeout {
                seconds: self.timeout.as_secs_f64(),
            }));
        }

        let started = self.clock.now_ms();
        let mut detail = String::new();

        match statement {
            Node::Assign {
                name,
                op,
                value,
                line,
            } => {
                let value = self.evaluate(value)?;
                let stored = self.write_a_variable(name, *op, value, *line)?;
                detail = format!("{name} = {}", stored.to_text());
            }
            Node::LegacyAssign { name, text, line } => {
                // Measured on the binary of v1.1.37.02 on 2026-11-02: the
                // legacy assignment of the v1 is a text and not an
                // expression: `x = 5 + 3` leaves `x` at "5 + 3".
                let value = self.the_value_of_a_legacy_assignment(text, *line)?;
                let stored = self.write_a_variable(name, AssignOp::Set, value, *line)?;
                detail = format!("{name} = {}", stored.to_text());
            }
            Node::LegacyCall {
                name,
                parameters,
                line,
            } => {
                // The legacy command of the v1: `Msg, text`.
                let value = self.the_legacy_command(name, parameters, *line)?;
                detail = value.to_text();
            }
            Node::LegacyIf {
                name,
                parameters,
                body,
                otherwise,
                line,
            } => {
                // Measured on the binary of v1.1.37.02 on 2026-11-02: the
                // command of the v1 that has a body runs its action when the
                // condition holds, and the action of the other side when it
                // does not.
                let holds = self.the_condition_of_a_legacy_if(name, parameters, *line)?;
                if holds {
                    self.run_block(body)?;
                } else {
                    self.run_block(otherwise)?;
                }
            }
            Node::ClassDef { name, line, .. } => {
                // Measured on the binary of v2.0.19 on 2026-10-31: the class
                // is initialised when it is first used, and the statement
                // that defines it is a use.
                self.initialise_the_class(name, *line)?;
                detail = format!("the class {name} is defined");
            }
            Node::ArrayLiteral { .. } => {
                // An array literal is an expression: the parser never
                // gives one as a statement of its own.
            }
            Node::ObjectLiteral { .. } => {
                // The literal of an object is an expression too.
            }
            Node::Lambda { .. } => {
                // The literal of a function is an expression too.
            }
            Node::For {
                variables,
                source,
                body,
                line,
            } => {
                self.for_loop(variables, source, body, *line)?;
            }
            Node::MethodCall {
                target,
                name,
                arguments,
                line,
            } => {
                // `super.m()`: the method of the base.
                let name = self.the_name_of_the_member(name, *line)?;
                let value = if let Node::Super { .. } = &**target {
                    self.call_the_method_of_the_base(&name, arguments, *line)?
                } else {
                    let target_value = self.evaluate(target)?;
                    self.call_method_on(&target_value, &name, arguments, *line)?
                };
                detail = value.to_text();
            }
            Node::Property { target, name, line } => {
                // `super.value`: the property of the base.
                let name = self.the_name_of_the_member(name, *line)?;
                let value = if let Node::Super { .. } = &**target {
                    self.read_the_property_of_the_base(&name, *line)?
                } else {
                    let target_value = self.evaluate(target)?;
                    self.read_property(&target_value, &name, *line)?
                };
                detail = value.to_text();
            }
            Node::AssignDynamic {
                name,
                op,
                value,
                line,
            } => {
                let name = self.the_name_of_the_pieces(name, *line)?;
                let value = self.evaluate(value)?;
                let stored = self.write_a_dynamic_name(&name, *op, value, *line)?;
                detail = format!("{name} = {}", stored.to_text());
            }
            Node::AssignProperty {
                target,
                name,
                op,
                value,
                line,
            } => {
                let value = self.evaluate(value)?;
                let name = self.the_name_of_the_member(name, *line)?;
                let stored = self.write_a_property(target, &name, *op, value, *line)?;
                detail = format!("{name} = {}", stored.to_text());
            }
            Node::AssignIndex {
                target,
                index,
                op,
                value,
                line,
            } => {
                let target_value = self.evaluate(target)?;
                let key = self.evaluate(index)?;
                let value = self.evaluate(value)?;
                let stored = self.set_item(&target_value, &key, *op, value, *line)?;
                detail = format!("{} = {}", key.to_text(), stored.to_text());
            }
            Node::Call {
                name,
                arguments,
                line,
            } => {
                let value = self.call(name, arguments, *line)?;
                detail = value.to_text();
            }
            Node::New {
                path,
                arguments,
                line,
            } => {
                let value = self.new_instance(path, arguments, *line)?;
                detail = value.to_text();
            }
            Node::Block { body, .. } => {
                self.run_block(body)?;
            }
            Node::If {
                branches,
                otherwise,
                ..
            } => {
                let mut taken = false;
                for branch in branches {
                    let value = self.the_value_of_the_condition(&branch.condition)?;
                    // Measured on the binary of AutoHotkey v1.1.37.02 on
                    // 2026-11-04: the items that come after the comma of the
                    // line of the condition run after the condition is
                    // evaluated, and they run whether it is true or false.
                    for item in &branch.tail {
                        self.evaluate(item)?;
                    }
                    if self.the_value_is_true(&value) {
                        self.run_block(&branch.body)?;
                        taken = true;
                        break;
                    }
                }
                if !taken {
                    self.run_block(otherwise)?;
                }
            }
            Node::Switch {
                subject,
                cases,
                line,
            } => {
                let value = self.evaluate(subject)?;
                let mut matched = false;
                for case in cases {
                    if case.values.is_empty() {
                        // The default: it matches when no other case did.
                        self.run_block(&case.body)?;
                        matched = true;
                        break;
                    }
                    // A case may name many values, and it matches when the
                    // subject of the switch is one of them.
                    for expected in &case.values {
                        let expected = self.evaluate(expected)?;
                        if values_equal(&value, &expected, false) {
                            self.run_block(&case.body)?;
                            matched = true;
                            break;
                        }
                    }
                    if matched {
                        break;
                    }
                }
                let _ = (matched, line);
            }
            Node::While {
                condition, body, ..
            } => {
                // Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-04:
                // the v1 takes the body of the loop from the statement that
                // comes next, and the script that has none ends at the loop:
                // the `while 1` that is the last line of the script ends the
                // script at once.
                if body.is_empty() && self.dialect.a_loop_without_a_body_ends_the_script() {
                    return Err(RuntimeFailure::Flow(Flow::Return(None)));
                }
                let mut iterations = 0usize;
                // Measured on the binary of v2.0.19 on 2026-11-01: the index
                // of the turn is the number of it, and a while loop counts
                // as well. The body may write the index, and the loop does
                // not mind: the next turn sets it again.
                let mut turn = 1i64;
                // Measured on the binary of v2.0.19 on 2026-11-01: every
                // loop saves the value of `A_Index` when it starts and
                // gives it back when it ends.
                let saved = self.the_index_is_saved();
                loop {
                    let value = self.the_value_of_the_condition(condition)?;
                    if !self.the_value_is_true(&value) {
                        break;
                    }
                    iterations += 1;
                    if iterations > Self::MAX_ITERATIONS {
                        return Err(RuntimeFailure::Error(RuntimeError {
                            message: format!(
                                "the loop ran more than {} times",
                                Self::MAX_ITERATIONS
                            ),
                            line: statement.line(),
                        }));
                    }
                    self.set_global("A_Index", Value::Int(turn));
                    turn += 1;
                    match self.run_block(body) {
                        Ok(()) => {}
                        Err(RuntimeFailure::Flow(Flow::Break)) => break,
                        Err(RuntimeFailure::Flow(Flow::Continue)) => continue,
                        Err(other) => return Err(other),
                    }
                }
                self.the_index_is_given_back(saved);
            }
            Node::Try {
                body,
                catches,
                otherwise,
                finally,
                ..
            } => {
                self.run_try(body, catches, otherwise, finally)?;
            }
            Node::Super { line } => {
                // A `super` with no member: the parser refuses it, and the
                // runtime refuses it too.
                return Err(RuntimeFailure::Error(RuntimeError {
                    message: "Syntax error.\n     Specifically: super".into(),
                    line: *line,
                }));
            }
            Node::Declare { scope, names, line } => {
                // The names of the declaration are read when the script is
                // read; the value waits for the statement that carries it.
                for declared in names {
                    if let Some(value) = &declared.value {
                        // The value of a static declaration runs the first
                        // time that declaration is reached.
                        if *scope == DeclareKind::Static
                            && self.the_static_already_ran(*line, &declared.name)
                        {
                            continue;
                        }
                        let value = self.evaluate(value)?;
                        self.assign(&declared.name, value);
                        if *scope == DeclareKind::Static {
                            self.mark_the_static_as_ran(*line, &declared.name);
                        }
                    }
                }
                let _ = line;
            }
            Node::Throw { value, line } => {
                // A `throw` without a value throws again the value that the
                // catch of the running `try` took.
                let value = match value {
                    Some(value) => self.evaluate(value)?,
                    None => match self.caught_value.clone() {
                        Some(value) => value,
                        None => {
                            return Err(RuntimeFailure::Error(RuntimeError {
                                message: "there is nothing to throw again: no catch took a value."
                                    .into(),
                                line: *line,
                            }));
                        }
                    },
                };
                // v2 puts the name of the thing that threw the error in
                // its `What`, when the error does not carry one.
                self.name_the_thrower(&value);
                return Err(RuntimeFailure::Thrown(value));
            }
            Node::Loop {
                mode,
                arguments,
                body,
                until,
                line,
            } => {
                // Measured on the binary of v2.0.19 on 2026-11-01: every loop
                // saves the value of `A_Index` when it starts and gives it
                // back when it ends.
                let saved = self.the_index_is_saved();
                match mode {
                    LoopKind::Count => {
                        match arguments.first() {
                            Some(node) => {
                                // Measured on the binary of AutoHotkey
                                // v1.1.37.02 on 2026-11-05: the `Loop` of the
                                // v1 is a loop of files when the text of its
                                // first parameter is not a number, and it is a
                                // loop of a number of turns when it is.
                                if self.dialect.legacy_commands() {
                                    if let Some(pattern) = self.the_pattern_of_the_files_of_the_v1(
                                        node, arguments, *line,
                                    )? {
                                        self.the_loop_of_the_files_of_the_v1(
                                            &pattern, arguments, body, until, *line,
                                        )?;
                                        self.the_index_is_given_back(saved);
                                        return Ok(());
                                    }
                                }
                                let count = self.the_count_of_the_loop(node, *line)?;
                                // Measured on the binary of v2.0.19 on 2026-11-01:
                                // the index of the turn is the value of
                                // `A_Index`, and the body may write it: the
                                // loop goes on from the value that was written.
                                let mut turn = 1i64;
                                while turn <= count.max(0) {
                                    self.set_global("A_Index", Value::Int(turn));
                                    let broken = match self.run_block(body) {
                                        Ok(()) => false,
                                        Err(RuntimeFailure::Flow(Flow::Break)) => true,
                                        Err(RuntimeFailure::Flow(Flow::Continue)) => false,
                                        Err(other) => return Err(other),
                                    };
                                    if broken {
                                        break;
                                    }
                                    // Measured on the binary of AutoHotkey
                                    // v1.1.37.02 on 2026-11-04: the `until` of
                                    // the v1 is the condition of the loop, and it
                                    // is read after every turn of the body.
                                    if self.the_until_ends_the_loop(until)? {
                                        break;
                                    }
                                    turn = self.the_index_of_the_turn() + 1;
                                }
                            }
                            None => {
                                // Measured on the binary of AutoHotkey
                                // v1.1.37.02 on 2026-11-04: the v1 takes the
                                // body of the loop from the statement that
                                // comes next, and the script that has none
                                // ends at the loop: the `loop` that is the
                                // last line of the script ends the script at
                                // once.
                                if body.is_empty()
                                    && self.dialect.a_loop_without_a_body_ends_the_script()
                                {
                                    return Err(RuntimeFailure::Flow(Flow::Return(None)));
                                }
                                // Measured on the binary of v2.0.19 on
                                // 2026-10-31: the loop without a count goes
                                // on until a break. The step count is the
                                // bound of it, and the body may be empty.
                                // Measured on the binary of v2.0.19 on 2026-11-01:
                                // the index of the turn is the number of it,
                                // and the loop without a count counts as
                                // well.
                                let mut turn = 1i64;
                                loop {
                                    self.steps_taken += 1;
                                    if self.steps_taken > Self::MAX_STEPS {
                                        return Err(RuntimeFailure::Error(RuntimeError {
                                            message: format!(
                                                "the script ran more than {} statements",
                                                Self::MAX_STEPS
                                            ),
                                            line: *line,
                                        }));
                                    }
                                    self.set_global("A_Index", Value::Int(turn));
                                    turn += 1;
                                    match self.run_block(body) {
                                        Ok(()) => {}
                                        Err(RuntimeFailure::Flow(Flow::Break)) => break,
                                        Err(RuntimeFailure::Flow(Flow::Continue)) => continue,
                                        Err(other) => return Err(other),
                                    }
                                    // Measured on the binary of AutoHotkey
                                    // v1.1.37.02 on 2026-11-04: the `until` of
                                    // the v1 is the condition of the loop, and it
                                    // is read after every turn of the body.
                                    if self.the_until_ends_the_loop(until)? {
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    LoopKind::Parse => {
                        // Measured on the binary of AutoHotkey v1.1.37.02 on
                        // 2026-11-05: the parse loop of the v1 takes the name
                        // of the variable whose text is separated, and not its
                        // value.
                        if self.dialect.legacy_commands() {
                            self.the_parse_loop_of_the_v1(arguments, body, until, *line)?;
                            self.the_index_is_given_back(saved);
                            return Ok(());
                        }
                        let text = self.loop_argument(arguments, 0, *line)?.to_text();
                        let delimiters = match arguments.get(1) {
                            Some(node) => self.evaluate(node)?.to_text(),
                            None => String::new(),
                        };
                        // The characters that are not wanted at the ends
                        // of a field.
                        let omitted = match arguments.get(2) {
                            Some(node) => self.evaluate(node)?.to_text(),
                            None => String::new(),
                        };
                        let pieces: Vec<String> = if delimiters.is_empty() {
                            // Measured on the binary of v2.0.19 on
                            // 2026-10-31: the delimiters that are not
                            // there make every character of the text a
                            // field of its own, and the spaces are
                            // fields too.
                            text.chars()
                                .filter(|character| !omitted.contains(*character))
                                .map(|character| character.to_string())
                                .collect()
                        } else {
                            split_on_any(&text, &delimiters)
                                .into_iter()
                                .map(|piece| {
                                    piece
                                        .trim_matches(|character| omitted.contains(character))
                                        .to_string()
                                })
                                .collect()
                        };
                        for (index, piece) in pieces.iter().enumerate() {
                            self.set_global("A_Index", Value::Int(index as i64 + 1));
                            self.set_global("A_LoopField", Value::Text(piece.clone()));
                            match self.run_block(body) {
                                Ok(()) => {}
                                Err(RuntimeFailure::Flow(Flow::Break)) => break,
                                Err(RuntimeFailure::Flow(Flow::Continue)) => continue,
                                Err(other) => return Err(other),
                            }
                        }
                    }
                    LoopKind::Files => {
                        // Measured on the binary of AutoHotkey v1.1.37.02 on
                        // 2026-11-05: the `Loop Files` of the v1 is the `Loop`
                        // whose first parameter is the word "Files": the
                        // pattern of the files is the second parameter and the
                        // mode is the third one.
                        if self.dialect.legacy_commands() {
                            self.the_loop_of_the_files_of_the_v1_with_the_kind(
                                arguments, body, until, *line,
                            )?;
                            self.the_index_is_given_back(saved);
                            return Ok(());
                        }
                        // v2 takes the pattern first and the mode second,
                        // and the folder is the one the script runs in.
                        if arguments.len() > 2 {
                            return Err(RuntimeFailure::Error(RuntimeError {
                                message: "\"Loop Files\" accepts at most 2 parameters.".into(),
                                line: *line,
                            }));
                        }
                        let pattern = self.loop_argument(arguments, 0, *line)?.to_text();
                        let mode = match arguments.get(1) {
                            Some(node) => self.evaluate(node)?.to_text(),
                            None => String::new(),
                        };
                        // Measured on the binary of AutoHotkey v2.0.19 on
                        // 2026-11-05: the mode of the `Loop Files` is a set of
                        // letters -- the "R" walks into the folders, the "D"
                        // and the "K" give the folders, the "F" and the "V"
                        // give the files -- and the spaces between them are
                        // ignored. The letter that is not one of them is
                        // refused when the loop runs.
                        if let Some(letter) = the_letter_that_the_mode_does_not_carry(&mode) {
                            return Err(RuntimeFailure::Error(RuntimeError {
                                message: format!(
                                    "the mode of a `Loop Files` is the \"R\", the \"D\", the \"F\", the \"V\" or the \"K\", and the letter \"{letter}\" is not one of them."
                                ),
                                line: *line,
                            }));
                        }
                        let folder = self.desktop().working_directory().map_err(|reason| {
                            RuntimeFailure::Error(RuntimeError {
                                message: reason,
                                line: *line,
                            })
                        })?;
                        let files = self
                            .desktop()
                            .list_files(&folder, &pattern, &mode)
                            .map_err(|reason| {
                                RuntimeFailure::Error(RuntimeError {
                                    message: reason,
                                    line: *line,
                                })
                            })?;
                        for (index, file) in files.iter().enumerate() {
                            let name = the_name_of(file);
                            let extension = the_extension_of(name);
                            self.set_global("A_Index", Value::Int(index as i64 + 1));
                            self.set_global("A_LoopFileFullPath", Value::Text(file.clone()));
                            self.set_global("A_LoopFileName", Value::Text(name.to_string()));
                            self.set_global("A_LoopFileExt", Value::Text(extension.to_string()));
                            self.set_global(
                                "A_LoopFileDir",
                                Value::Text(the_folder_of(file).to_string()),
                            );
                            self.set_global(
                                "A_LoopFilePath",
                                Value::Text(without_the_extension(file, extension)),
                            );
                            // The short names of the files are a thing of
                            // Windows, and this box has none.
                            self.the_short_names_of_the_files_are_refused = true;
                            match self.run_block(body) {
                                Ok(()) => {}
                                Err(RuntimeFailure::Flow(Flow::Break)) => break,
                                Err(RuntimeFailure::Flow(Flow::Continue)) => continue,
                                Err(other) => return Err(other),
                            }
                        }
                    }
                    LoopKind::Read => {
                        // Measured on the binary of AutoHotkey v1.1.37.02 on
                        // 2026-11-05: the read loop of the v1 takes the name
                        // of the file in its second parameter, and the file
                        // where the text goes in its third one.
                        if self.dialect.legacy_commands() {
                            self.the_read_loop_of_the_v1(arguments, body, until, *line)?;
                            self.the_index_is_given_back(saved);
                            return Ok(());
                        }
                        let path = self.loop_argument(arguments, 0, *line)?.to_text();
                        // The file of the loop is where a `FileAppend` that
                        // has no name of its own writes.
                        //
                        // Measured on the binary of v2.0.19 on 2026-11-01:
                        // the name of the file of a `FileAppend` may be left
                        // out inside the body of a `Loop Read` that has a
                        // file of its own.
                        let output = match arguments.get(1) {
                            Some(node) => self.evaluate(node)?.to_text(),
                            None => String::new(),
                        };
                        let lines = self.desktop().read_file(&path).map_err(|reason| {
                            RuntimeFailure::Error(RuntimeError {
                                message: reason,
                                line: *line,
                            })
                        })?;
                        self.loop_output_files.push(output);
                        let mut failure = None;
                        for (index, line_text) in lines.iter().enumerate() {
                            self.set_global("A_Index", Value::Int(index as i64 + 1));
                            // Measured on the binary of v2.0.19 on
                            // 2026-10-31: the line of the file is
                            // `A_LoopReadLine`, and `A_LoopField` is the
                            // field of the loop that parses.
                            self.set_global("A_LoopReadLine", Value::Text(line_text.clone()));
                            match self.run_block(body) {
                                Ok(()) => {}
                                Err(RuntimeFailure::Flow(Flow::Break)) => break,
                                Err(RuntimeFailure::Flow(Flow::Continue)) => continue,
                                Err(other) => {
                                    failure = Some(other);
                                    break;
                                }
                            }
                        }
                        self.loop_output_files.pop();
                        if let Some(other) = failure {
                            return Err(other);
                        }
                    }
                    LoopKind::Reg => {
                        return Err(RuntimeFailure::Error(RuntimeError {
                            message: "the registry is a Windows thing and this box has none."
                                .into(),
                            line: *line,
                        }));
                    }
                }
                self.the_index_is_given_back(saved);
            }
            Node::Directive {
                name,
                argument,
                line,
            } => {
                detail = self.directive(name, argument, *line)?;
            }
            // A label names a line of the script: it does nothing by
            // itself.
            Node::Label { .. } => {}
            // The value of an expression that is a statement is computed and
            // thrown away.
            Node::Expression { value, .. } => {
                self.evaluate(value)?;
            }
            // The expression of a parameter of the v1 is not a statement: the
            // command that holds the parameter reads it.
            Node::LegacyExpression { value, .. } => {
                self.evaluate(value)?;
            }
            // The jump of a `Goto`: the run goes on at the label.
            Node::Goto { name, line } => {
                return Err(RuntimeFailure::Flow(Flow::Goto {
                    name: name.clone(),
                    line: *line,
                }));
            }
            // The hotkey of the v1: the definition of it is a label, and
            // the code that comes after it is a part of the thread that is
            // running. The hotkey itself is registered when the script
            // loads, and the section of the script that runs ends at the
            // definition.
            //
            // Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-03:
            // the body of a hotkey runs with the scope of the script, and
            // the `return` of it ends the thread of the hotkey.
            Node::HotkeyDefinition { body, .. } => {
                if self.in_the_body_of_a_hotkey {
                    self.run_block(body)?;
                }
            }
            Node::Break { .. } => return Err(RuntimeFailure::Flow(Flow::Break)),
            Node::Continue { .. } => return Err(RuntimeFailure::Flow(Flow::Continue)),
            Node::Return { value, .. } => {
                let value = match value {
                    Some(node) => Some(self.evaluate(node)?),
                    None => None,
                };
                return Err(RuntimeFailure::Flow(Flow::Return(value)));
            }
            Node::ExitApp { code, .. } => {
                let code = match code {
                    Some(node) => self.evaluate(node)?.to_number().unwrap_or(0.0) as i32,
                    None => 0,
                };
                return Err(RuntimeFailure::Flow(Flow::Exit(code)));
            }
            Node::FunctionDef { name, .. } => {
                detail = format!("{name} is defined");
            }
            Node::Unary { op, operand, line } => {
                // `x++` and `x--` are statements of their own: they have
                // a side, and the value they leave behind is not used.
                if matches!(
                    op,
                    UnaryOp::PreIncrement
                        | UnaryOp::PreDecrement
                        | UnaryOp::PostIncrement
                        | UnaryOp::PostDecrement
                ) {
                    self.increment(*op, operand, *line)?;
                    detail = "the variable moved".into();
                } else {
                    return Err(RuntimeFailure::Error(RuntimeError {
                        message: "this is an expression, not a statement".into(),
                        line: statement.line(),
                    }));
                }
            }
            Node::Index { .. } => {
                // An item that is a statement is read, and the value it
                // leaves behind is not used: v2 reads it.
                self.evaluate(statement)?;
                detail = "the item was read".into();
            }
            Node::DynamicName { .. } => {
                // A name that the script builds is a statement that reads
                // it, and the value it leaves behind is not used.
                self.evaluate(statement)?;
                detail = "the variable was read".into();
            }
            Node::Literal { .. }
            | Node::Var { .. }
            | Node::Binary { .. }
            | Node::Unset { .. }
            | Node::Ternary { .. }
            | Node::Group { .. }
            | Node::LegacyComparison { .. }
            | Node::LegacyMatch { .. }
            | Node::LegacyControl { .. }
            | Node::Empty { .. } => {
                return Err(RuntimeFailure::Error(RuntimeError {
                    message: "this is an expression, not a statement".into(),
                    line: statement.line(),
                }));
            }
            Node::Legacy { items, .. } => {
                // Measured on the binary of v2.0.19 on 2026-10-31: the list
                // of v1 is evaluated, and its value is thrown away.
                for item in items {
                    self.evaluate(item)?;
                }
                detail = "the list of v1".into();
            }
        }

        self.steps.push(Step {
            line: statement.line(),
            op: op_name_in(statement, self.dialect).to_string(),
            detail,
            ok: true,
            elapsed_ms: self.clock.now_ms().saturating_sub(started),
        });
        Ok(())
    }

    // -- the for loop ---------------------------------------------------------------

    /// The loop that walks what an object enumerates.
    ///
    /// The source is asked once, before the loop, and the enumerator it
    /// gives is walked turn by turn. The variables of the loop go back
    /// to the values they had before it: v2 restores them.
    fn for_loop(
        &mut self,
        variables: &[String],
        source: &Node,
        body: &[Node],
        line: u32,
    ) -> Result<(), RuntimeFailure> {
        // v2 gives the loop two variables at most: the key and the
        // value under it.
        if variables.len() > 2 {
            return Err(RuntimeFailure::Error(RuntimeError {
                message: "a for loop takes at most two variables.".into(),
                line,
            }));
        }
        // The variables keep the values they had before the loop, and
        // they get them back when the loop ends.
        let saved: Vec<(String, Option<Value>)> = variables
            .iter()
            .filter(|name| !name.is_empty())
            .map(|name| (name.clone(), self.lookup_variable(name)))
            .collect();
        let object = self.evaluate(source)?;
        if self.dialect.the_for_is_the_one_of_the_v1() {
            // Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-04:
            // the `for` of the v1 walks the items of an array and nothing
            // else: the `for i in 5` has no turn and it does not fail.
            if self.the_class_of_the_value(&object) != "Array" {
                return Ok(());
            }
        }
        // Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-04: the
        // `for` of the v1 walks the keys of the array, and it asks for them
        // even when the script gave it one name.
        let wanted = if self.dialect.the_for_is_the_one_of_the_v1() {
            2
        } else {
            variables.len()
        };
        let enumerator = self.the_enumerator(&object, wanted, line)?;
        // The enumerator has to be something that can be called: v2 fails
        // there before the body of the loop runs.
        if let Err(failure) = self.check_the_enumerator(&enumerator, line) {
            for (name, value) in saved {
                self.restore_variable(&name, value);
            }
            return Err(failure);
        }
        // Measured on the binary of v2.0.19 on 2026-11-01: every loop saves
        // the value of `A_Index` when it starts and gives it back when it
        // ends.
        let saved_index = self.the_index_is_saved();
        let mut turns = 0usize;
        let mut outcome = Ok(());
        loop {
            // The enumerator hands out the turns one by one, and the body
            // of the loop runs between them.
            let item = match self.the_next_item(&enumerator, variables, wanted, line) {
                Ok(Some(item)) => item,
                Ok(None) => break,
                Err(failure) => {
                    outcome = Err(failure);
                    break;
                }
            };
            turns += 1;
            if turns > Self::MAX_ITERATIONS {
                outcome = Err(RuntimeFailure::Error(RuntimeError {
                    message: format!("the loop ran more than {} times", Self::MAX_ITERATIONS),
                    line,
                }));
                break;
            }
            // The values of the turn are given to the variables before
            // the body runs: the key and the value, or the value alone.
            if let Err(failure) = self.set_loop_variables(variables, &item, line) {
                outcome = Err(failure);
                break;
            }
            self.set_global("A_Index", Value::Int(turns as i64));
            match self.run_block(body) {
                Ok(()) => {}
                Err(RuntimeFailure::Flow(Flow::Break)) => break,
                Err(RuntimeFailure::Flow(Flow::Continue)) => continue,
                Err(other) => {
                    outcome = Err(other);
                    break;
                }
            }
        }
        for (name, value) in saved {
            self.restore_variable(&name, value);
        }
        self.the_index_is_given_back(saved_index);
        outcome
    }

    /// The enumerator of a value.
    ///
    /// The value is asked for its `__Enum`, and the enumerator it gives is
    /// the one the loop walks. A value that has no `__Enum` and is an
    /// enumerator of its own is the enumerator itself.
    fn the_enumerator(
        &mut self,
        object: &Value,
        wanted: usize,
        line: u32,
    ) -> Result<Value, RuntimeFailure> {
        if self.can_enumerate(object) {
            let count = Node::Literal {
                value: LiteralValue::Integer(wanted as i64),
                line,
            };
            return self.call_method_on(object, "__enum", &[count], line);
        }
        // An enumerator is a function of its own kind, and a loop walks it
        // the way it walks any other function.
        if crate::classes::enumerator::is_one(object) {
            return Ok(object.clone());
        }
        Err(RuntimeFailure::Error(RuntimeError {
            message: "Value not enumerable.".into(),
            line,
        }))
    }

    /// Whether the enumerator is something that can be called.
    ///
    /// Measured on the binary of v2.0.19 on 2026-10-31: the enumerator of
    /// v2 is a function, an enumerator of the runtime, or an object with a
    /// `Call` method. A list is not one, and the tree used to walk it; a
    /// value that is not an object at all is a mismatch of the type; and an
    /// object that cannot be called is not enumerable.
    fn check_the_enumerator(&self, enumerator: &Value, line: u32) -> Result<(), RuntimeFailure> {
        match enumerator {
            // An enumerator of the runtime and a function of the script are
            // called the way they are.
            Value::Object(_) if crate::classes::enumerator::is_one(enumerator) => Ok(()),
            Value::Object(_) if self.is_a_function(enumerator) => Ok(()),
            // An object with a `Call` method is an enumerator too.
            Value::Object(_) if self.find_method_on(enumerator, "call").is_some() => Ok(()),
            // An object that cannot be called is not enumerable.
            Value::Object(_) => Err(RuntimeFailure::Error(RuntimeError {
                message: "Value not enumerable.".into(),
                line,
            })),
            // A value that is not an object at all is a mismatch of the type.
            _ => Err(RuntimeFailure::Error(RuntimeError {
                message: "Type mismatch.".into(),
                line,
            })),
        }
    }

    /// The next item of an enumeration.
    ///
    /// The enumerator of the runtime hands out the turns one by one. A
    /// function of the script is asked for the next one: it writes the
    /// values into the variables of the loop and answers one while it has
    /// something to give, and zero when it has nothing left.
    fn the_next_item(
        &mut self,
        enumerator: &Value,
        variables: &[String],
        wanted: usize,
        line: u32,
    ) -> Result<Option<Value>, RuntimeFailure> {
        if crate::classes::enumerator::is_one(enumerator) {
            return Ok(crate::classes::enumerator::the_turn(enumerator, wanted));
        }
        // The variables of the loop are given to the enumerator by
        // reference: v2 calls it with them.
        let references: Vec<Value> = variables
            .iter()
            .filter(|name| !name.is_empty())
            .map(|name| {
                Value::Reference(Reference {
                    name: name.clone(),
                    scope: self.the_scope_of(name),
                    alias: true,
                })
            })
            .collect();
        let answer = if self.is_a_function(enumerator) {
            match crate::classes::func::call_the_value(enumerator, &references, self, line) {
                Some(result) => result?,
                None => return Err(self.no_method(enumerator, "Call", line)),
            }
        } else {
            self.own_method(enumerator, "call", &references, line)?
        };
        // The enumerator answers one while it has something to give, and
        // zero when it has nothing left.
        if !answer.truthy() {
            return Ok(None);
        }
        // The values are read back from the variables of the loop.
        let mut values = Vec::new();
        for reference in &references {
            let Value::Reference(reference) = reference else {
                continue;
            };
            values.push(
                self.read_reference(reference)
                    .unwrap_or(Value::Text(String::new())),
            );
        }
        let item = if values.len() >= 2 {
            Value::List(vec![values[0].clone(), values[1].clone()])
        } else {
            values
                .into_iter()
                .next()
                .unwrap_or(Value::Text(String::new()))
        };
        Ok(Some(item))
    }

    /// The scope a name lives in.
    ///
    /// The scope of a name is the one the write of it goes to: the scope of
    /// the script, the scope of a function around it that names it, or the
    /// scope of the function that runs.
    fn the_scope_of(&self, name: &str) -> Scope {
        let name = the_key_of(name);
        if self.lives_in_the_script(&name) {
            return Scope::Global;
        }
        // A name that a scope around the call has is shared with it.
        //
        // Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-02: the
        // v1 does not share them: the name lives in the scope of the
        // function that runs.
        if self.the_scopes_around_are_shared() {
            for (depth, scope) in self.scopes.iter().enumerate().rev().skip(1) {
                if scope.borrow().contains_key(&name) {
                    return Scope::Local(depth);
                }
            }
        }
        match self.scopes.len() {
            0 => Scope::Global,
            depth => Scope::Local(depth - 1),
        }
    }

    /// Whether a value can be walked.
    ///
    /// The enumerator of a value is its `__Enum`: a class of the script
    /// may have one, and the class types of the runtime have their own.
    fn can_enumerate(&self, object: &Value) -> bool {
        let Value::Object(value) = object else {
            return false;
        };
        if self.find_method_on(object, "__enum").is_some() {
            return true;
        }
        let class = value.borrow().class.clone();
        crate::classes::carries(&class, "__enum")
    }

    /// The variables of a turn of a `for` loop.
    ///
    /// With one variable the enumerator gives the value, with two it
    /// gives the key and the value under it. A name the script left
    /// out is given to nobody.
    fn set_loop_variables(
        &mut self,
        variables: &[String],
        item: &Value,
        line: u32,
    ) -> Result<(), RuntimeFailure> {
        if self.dialect.the_for_is_the_one_of_the_v1() {
            // Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-04:
            // the `for` of the v1 gives the key to the first name that is not
            // empty: the `for i in [10,20]` gives 1 and 2 to the `i`, and the
            // `for , v in [10,20]` gives them to the `v`.
            let pair = match item {
                Value::List(pair) if pair.len() == 2 => pair,
                _ => {
                    return Err(RuntimeFailure::Error(RuntimeError {
                        message: "the enumeration did not give a key and a value.".into(),
                        line,
                    }));
                }
            };
            let names: Vec<&String> = variables.iter().filter(|name| !name.is_empty()).collect();
            if let Some(name) = names.first() {
                self.assign(name, pair[0].clone());
            }
            if let Some(name) = names.get(1) {
                self.assign(name, pair[1].clone());
            }
            return Ok(());
        }
        match variables.len() {
            0 => Ok(()),
            1 => {
                // The enumerator gives the value alone.
                if !variables[0].is_empty() {
                    // Measured on the binary of v2.0.19 on 2026-11-01: a turn
                    // that has no value of its own leaves the variable of the
                    // loop without a value: the script that reads it is told
                    // that the variable has no value.
                    if is_a_value_without_one(item) {
                        self.unset_variable(&variables[0]);
                    } else {
                        self.assign(&variables[0], item.clone());
                    }
                }
                Ok(())
            }
            _ => {
                // The enumerator gives the key and the value under it.
                let pair = match item {
                    Value::List(pair) if pair.len() == 2 => pair,
                    _ => {
                        return Err(RuntimeFailure::Error(RuntimeError {
                            message: "the enumeration did not give a key and a value.".into(),
                            line,
                        }));
                    }
                };
                for (name, value) in variables.iter().zip(pair.iter()) {
                    if name.is_empty() {
                        continue;
                    }
                    // The key of the turn is the place of it, and it is there
                    // even when the value under it is not.
                    if is_a_value_without_one(value) {
                        self.unset_variable(name);
                    } else {
                        self.assign(name, value.clone());
                    }
                }
                Ok(())
            }
        }
    }

    /// A variable of a loop, put back the way it was.
    ///
    /// v2 restores the variables of a loop when the loop ends: a name
    /// that had no value before it has no value after it either.
    fn restore_variable(&mut self, name: &str, value: Option<Value>) {
        match value {
            Some(value) => self.assign(name, value),
            None => match self.scopes.last() {
                Some(scope) => {
                    scope.borrow_mut().remove(the_key_of(name).as_str());
                }
                None => {
                    self.variables.remove(the_key_of(name).as_str());
                }
            },
        }
    }

    /// Take the value of a variable away.
    ///
    /// Measured on the binary of v2.0.19 on 2026-11-01: the turn of a loop
    /// that has no value of its own leaves the variable of the loop without
    /// a value, and not with the value that the turn before it gave. The
    /// name is written where `assign` writes it, and it is taken away from
    /// there.
    fn unset_variable(&mut self, name: &str) {
        // A parameter that is an alias of a variable of the caller: the
        // variable of the caller goes without a value.
        if let Some(reference) = self.alias_of(name) {
            self.unset_reference(&Value::Reference(reference));
            return;
        }
        let name = the_key_of(name);
        // A static variable belongs to the function that declares it.
        if self.is_declared_static(&name) {
            self.the_statics_of_the_frame().remove(name.as_str());
            return;
        }
        // A name that the script has is a global one.
        if self.lives_in_the_script(&name) {
            self.variables.remove(name.as_str());
            return;
        }
        // A name that a scope around the call has is shared with it.
        for scope in self.scopes.iter().rev().skip(1) {
            if scope.borrow().contains_key(&name) {
                scope.borrow_mut().remove(name.as_str());
                return;
            }
        }
        match self.scopes.last() {
            Some(scope) => {
                scope.borrow_mut().remove(name.as_str());
            }
            None => {
                self.variables.remove(name.as_str());
            }
        }
    }

    // -- scopes ---------------------------------------------------------------------

    /// The value of a variable, from the innermost scope outwards.
    ///
    /// A function and a class are values too: a script can hold one and
    /// hand it on, and `Func` is the class of a function.
    ///
    /// Measured on the binary of v1.1.37.02 on 2026-11-02: the name of a
    /// function of the v1 is not a value, and the name of a command of the
    /// v1 is not a value either -- `x := StrLen` is a blank text -- and the
    /// dialect says so.
    fn lookup(&self, name: &str) -> Option<Value> {
        if let Some(value) = self.lookup_variable(name) {
            return Some(value);
        }
        let key = name.to_lowercase();
        if let Some(function) = self.functions.get(&key) {
            if !self.dialect.the_name_of_a_function_is_a_value() {
                return Some(Value::Text(String::new()));
            }
            return Some(func_value(&function.name, function));
        }
        // A built-in is a function, and a function is a value. The name
        // of it comes before the class: the `Hotkey` is a function of the
        // dialect, and the class of a hotkey is the class of the object
        // that the function makes.
        if let Some(builtin) = self.builtin(&key) {
            if !self.dialect.the_name_of_a_function_is_a_value() {
                return Some(Value::Text(String::new()));
            }
            return Some(builtin_value(builtin.name, builtin.min, builtin.max as u32));
        }
        if self.classes.contains_key(&key) || crate::classes::is_type(&key) {
            return self.class_value_of(&key);
        }
        None
    }

    /// The value of a class: the class itself.
    ///
    /// The class is one object for the whole run, so that the `is`
    /// operator and the base of an object can tell a class from an
    /// instance of one.
    pub(crate) fn class_value_of(&self, name: &str) -> Option<Value> {
        let key = name.to_lowercase();
        if let Some(value) = self.class_values.borrow().get(&key) {
            return Some(value.clone());
        }
        let value = if let Some(class) = self.classes.get(&key) {
            class_value(&key, class)
        } else if crate::classes::is_type(&key) {
            crate::classes::class_value(&key)
        } else {
            return None;
        };
        self.class_values.borrow_mut().insert(key, value.clone());
        Some(value)
    }

    /// The name of the class of an object, the way v2 names it.
    ///
    /// An object is named after the class it is an instance of, and a
    /// class is named after itself.
    pub(crate) fn class_of(&self, target: &Value) -> Option<String> {
        let Value::Object(object) = target else {
            return None;
        };
        let class = object.borrow().class.clone();
        // The name the class was written with, when the runtime knows it.
        if let Some(Value::Object(class)) = self.class_value_of(&class) {
            if let Some(name) = class.borrow().value_of(CLASS_NAME) {
                return Some(name.to_text());
            }
        }
        // The other objects are named after the class they carry.
        Some(crate::classes::the_spelling_of(&class))
    }

    /// The name of the class a value is, when the value is a class.
    ///
    /// The classes the runtime made are known to it, and it can tell one
    /// of them from an instance of one.
    pub(crate) fn class_name_of(&self, value: &Value) -> Option<String> {
        let Value::Object(object) = value else {
            return None;
        };
        for class in self.class_values.borrow().values() {
            let Value::Object(other) = class else {
                continue;
            };
            if Rc::ptr_eq(object, other) {
                return object
                    .borrow()
                    .value_of(CLASS_NAME)
                    .map(|name| name.to_text().to_lowercase());
            }
        }
        None
    }

    /// The base of an object: the prototype of its class.
    ///
    /// v2 gives every object a base, and the base of an instance is the
    /// prototype of the class it is an instance of. A script may set
    /// another one with `ObjSetBase`.
    pub(crate) fn base_of(&self, target: &Value) -> Option<Value> {
        let Value::Object(object) = target else {
            return None;
        };
        // A base that the script set is the base of the object.
        if let Some(base) = object.borrow().value_of(BASE) {
            return Some(base.clone());
        }
        let class = object.borrow().class.clone();
        let Value::Object(class) = self.class_value_of(&class)? else {
            return None;
        };
        class.borrow().value_of("prototype")
    }

    /// The base of an object that the script set, if it set one.
    ///
    /// An object of a script has no base of its own until `ObjSetBase`
    /// gives it one: the prototype of its class is what `ObjGetBase`
    /// answers with.
    pub(crate) fn stored_base_of(&self, target: &Value) -> Option<Value> {
        let Value::Object(object) = target else {
            return None;
        };
        object.borrow().value_of(BASE)
    }

    /// A method of the base object, asked of an object.
    ///
    /// The class of the object answers first when it owns the whole of
    /// its properties: the state of a map is not one of them.
    pub(crate) fn own_method(
        &mut self,
        target: &Value,
        name: &str,
        arguments: &[Value],
        line: u32,
    ) -> Result<Value, RuntimeError> {
        let Value::Object(object) = target else {
            return Err(RuntimeError {
                message: expected_type(TypeName::Object, target.type_name()),
                line,
            });
        };
        // A class value of the runtime: the own properties of it are the
        // ones that v2 gives it, and not the table that the tree keeps.
        //
        // Measured on the binary of v2.0.19 on 2026-10-31: the own
        // properties of the class value of the `Map` are "Call" and
        // "Prototype".
        if name == "ownprops" && self.class_name_of(target).is_some() {
            return self.base_object(target, name, arguments, line);
        }
        let class = object.borrow().class.clone();
        match crate::classes::call(&class, name, target, arguments, self, line) {
            Some(Ok(value)) => Ok(value),
            Some(Err(failure)) => Err(as_error(failure, line)),
            None => self.base_object(target, name, arguments, line),
        }
    }

    /// The property of an object, when it has one.
    pub(crate) fn property_of(&mut self, target: &Value, name: &str, line: u32) -> Option<Value> {
        self.read_property(target, name, line).ok()
    }

    /// The property of an object, written.
    pub(crate) fn write_property_of(
        &mut self,
        target: &Value,
        name: &str,
        value: Value,
        line: u32,
    ) -> Result<(), RuntimeError> {
        self.write_property(target, name, value, line)
            .map_err(|failure| as_error(failure, line))
    }

    /// The base of an object, set to another one.
    ///
    /// Measured on the binary of v2.0.19 on 2026-10-31: the base of an
    /// object of a class type of the runtime cannot be written -- the
    /// prototype of the class is there -- and the refusal says "Invalid
    /// base.". The base of a plain object, of an error, of a prototype, of
    /// a class value and of an instance of a class of the script can be
    /// written.
    pub(crate) fn set_base_of(
        &mut self,
        target: &Value,
        base: Value,
        line: u32,
    ) -> Result<(), RuntimeError> {
        let Value::Object(object) = target else {
            return Err(RuntimeError {
                message: expected_type(TypeName::Object, target.type_name()),
                line,
            });
        };
        let class = object.borrow().class.clone();
        // A class value is not an instance of its class, and the base of it
        // is the class that it extends: the write of it is the write of the
        // `ObjSetBase` of a class.
        //
        // Measured on the binary of v2.0.19 on 2026-10-31.
        if self.class_name_of(target).is_none()
            && matches!(
                class.as_str(),
                "array" | "buffer" | "enumerator" | "file" | "func" | "gui" | "map" | "menu"
            )
        {
            return Err(RuntimeError {
                message: "Invalid base.".to_string(),
                line,
            });
        }
        object.borrow_mut().put(BASE, base);
        Ok(())
    }

    /// The value of a variable, from the innermost scope outwards.
    ///
    /// The functions and the classes are not variables, and this is the
    /// lookup that says so.
    ///
    /// A parameter that is an alias of a variable of the caller reads
    /// that variable: the alias and the variable are the same thing.
    fn lookup_variable(&self, name: &str) -> Option<Value> {
        let name = the_key_of(name);
        // The scope of the call is the last one: the parameters of the
        // function are there.
        if let Some(scope) = self.scopes.last() {
            match scope.borrow().get(&name) {
                Some(Value::Reference(reference)) if reference.alias => {
                    return self.read_reference(reference);
                }
                Some(value) => return Some(value.clone()),
                None => {}
            }
        }
        // The static of the function that runs belongs to it: it is not in
        // the scope of the call, and it is read before the scopes around
        // the call.
        if let Some(value) = self.the_static_of_the_frame(&name) {
            return Some(value);
        }
        // Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-02: the
        // v1 does not share the scopes around the call: a function has its
        // own scope, and the name of an outer call is not visible in it.
        if self.the_scopes_around_are_shared() {
            for scope in self.scopes.iter().rev().skip(1) {
                match scope.borrow().get(&name) {
                    Some(Value::Reference(reference)) if reference.alias => {
                        return self.read_reference(reference);
                    }
                    Some(value) => return Some(value.clone()),
                    None => continue,
                }
            }
        }
        // A name that the function declares local is the local one, and not
        // the global of the script: a local that has no value yet has no
        // value at all.
        //
        // Measured on the binary of v2.0.19 on 2026-10-31: `local g` and a
        // global `g` are two names, and the local is the one that the
        // function reads.
        if self.is_declared_local(&name) {
            return None;
        }
        // Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-02: the
        // v1 does not fall back to the scope of the script either: the name
        // of the script is not visible in a function, and only the `global`
        // declaration makes it visible.
        // Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-05: the
        // variables that the runtime owns are not the variables of the script,
        // and they are seen in a function: the `A_LineNumber` is the line of
        // the statement that runs, and the `A_ThisFunc` is the name of the
        // function that runs.
        let owned = crate::variables::spelled(&name)
            .map(|rest| crate::variables::THE_RUNTIME_OWNS.contains(&rest.as_str()))
            .unwrap_or(false);
        if self.dialect.the_scope_of_a_function_is_its_own()
            && !self.scopes.is_empty()
            && !owned
            && !self.lives_in_the_script(&name)
        {
            return None;
        }
        self.variables.get(&name).cloned()
    }

    /// Whether the scopes around the call are shared with it.
    ///
    /// Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-02: the v1
    /// does not share them: every function of the v1 has its own scope, and
    /// the name of an outer call is not visible in it. The v2 shares the name
    /// that a scope around the call has.
    fn the_scopes_around_are_shared(&self) -> bool {
        !self.dialect.the_scope_of_a_function_is_its_own()
    }

    /// Whether the name is one that the function that runs declares
    /// static.
    ///
    /// A name that the function declares static is not a local one: it
    /// lives in the storage of the function.
    fn is_declared_static(&self, name: &str) -> bool {
        let Some(frame) = self.declarations.last() else {
            return false;
        };
        frame.statics.contains(name)
    }

    /// The value of the built-in variable of this name, when the name is one.
    ///
    /// The dialect is asked, and not the table of the v2: the v1 has names
    /// of its own, and the two tables meet in the dialect.
    fn the_built_in_variable(&mut self, name: &str) -> Option<Result<Value, RuntimeError>> {
        let dialect = self.dialect;
        dialect.lookup_variable(name, self)
    }

    /// The value that the write of the built-in variable of this name leaves.
    ///
    /// The dialect is asked, and not the table of the v2: the v1 has names
    /// of its own, and the two tables meet in the dialect.
    fn the_write_of_the_built_in_variable(
        &mut self,
        name: &str,
        op: AssignOp,
        value: &Value,
        line: u32,
    ) -> Option<Result<Value, RuntimeError>> {
        let dialect = self.dialect;
        dialect.write_variable(name, op, value, line, self)
    }

    /// Whether a variable of this name has a value.
    ///
    /// The name is the one that the dialect spells, and the built-in
    /// variables of the dialect are the ones that its table carries.
    pub(crate) fn has_a_value(&mut self, name: &str) -> bool {
        if self.lookup_variable(name).is_some() {
            return true;
        }
        self.dialect.carries_variable(name)
    }

    /// Whether the script has a function of this name.
    pub(crate) fn has_a_function(&self, name: &str) -> bool {
        self.functions.contains_key(&name.to_lowercase())
    }

    /// Whether the dialect has the built-in function of this name.
    ///
    /// A command of the v1 is not a function: `IsFunc("MsgBox")` is zero in
    /// the v1. Measured on the binary of v1.1.37.02 on 2026-11-02.
    pub(crate) fn has_a_builtin_function(&self, name: &str) -> bool {
        self.dialect.builtins().iter().any(|builtin| {
            builtin.kind == crate::builtins::BuiltinKind::Function
                && builtin.name.eq_ignore_ascii_case(name)
        })
    }

    /// The value of the built-in function of this name.
    ///
    /// The v1 asks for it: the `Func` of the v1 is a reference to a function,
    /// and the reference of a built-in carries the name of it and the number
    /// of its parameters. Measured on the binary of v1.1.37.02 on 2026-11-02.
    ///
    /// The name that is a command and a function at the same time -- the
    /// `GetKeyState` of the v1 -- is a function: the table has a row for
    /// each of them, and the row of the function is the one that answers.
    pub(crate) fn the_builtin_function(&self, name: &str) -> Option<Value> {
        let builtin = self.dialect.builtins().iter().find(|builtin| {
            builtin.kind == crate::builtins::BuiltinKind::Function
                && builtin.name.eq_ignore_ascii_case(name)
        })?;
        let max = self.dialect.the_maximum_of_the_parameters(builtin.max);
        Some(builtin_value(builtin.name, builtin.min, max))
    }

    /// Whether the variable of this name is a reference.
    pub(crate) fn is_a_reference(&self, name: &str) -> bool {
        matches!(self.lookup_variable(name), Some(Value::Reference(_)))
    }

    /// The value of the function of the script of this name.
    ///
    /// Measured on the binary of v1.1.37.02 on 2026-11-02: the `Func` of
    /// the v1 hands the function of the script over as a value, and the
    /// value carries the name of it and the number of its parameters.
    pub(crate) fn the_function_of_the_script(&self, name: &str) -> Option<Value> {
        let function = self.functions.get(&name.to_lowercase())?;
        Some(func_value(&function.name, function))
    }

    /// The static variables of the function that runs.
    ///
    /// The frame is the name of the function or of the method that runs,
    /// and the table of the function is under it.
    fn the_statics_of_the_frame(&mut self) -> &mut BTreeMap<String, Value> {
        let frame = self
            .frames
            .last()
            .map(|frame| frame.name.clone())
            .unwrap_or_default();
        self.statics.entry(frame).or_default()
    }

    /// The value of a static variable of the function that runs.
    fn the_static_of_the_frame(&self, name: &str) -> Option<Value> {
        let frame = self.frames.last()?;
        self.statics.get(&frame.name)?.get(name).cloned()
    }

    /// Whether the value of a static declaration already ran.
    ///
    /// The value of a static declaration runs the first time that
    /// declaration is reached.
    fn the_static_already_ran(&self, line: u32, name: &str) -> bool {
        let Some(frame) = self.frames.last() else {
            return false;
        };
        let Some(ran) = self.statics_run.get(&frame.name) else {
            return false;
        };
        ran.contains(&the_key_of_a_declaration(line, name))
    }

    /// Mark the value of a static declaration as one that ran.
    fn mark_the_static_as_ran(&mut self, line: u32, name: &str) {
        let frame = self
            .frames
            .last()
            .map(|frame| frame.name.clone())
            .unwrap_or_default();
        self.statics_run
            .entry(frame)
            .or_default()
            .insert(the_key_of_a_declaration(line, name));
    }

    /// Whether the name is one that the function that runs declares local.
    ///
    /// A name that the function declares global is not one of them, and a
    /// name that the function does not name is not one either: a function
    /// that assumes the scope of the script says it for every name it does
    /// not name.
    fn is_declared_local(&self, name: &str) -> bool {
        let Some(frame) = self.declarations.last() else {
            return false;
        };
        frame.locals.contains(name)
    }

    /// The refusal of a local that takes the class of its own name.
    ///
    /// Measured on the binary of v2.0.19 on 2026-10-31: `foo := Foo()` in a
    /// function is refused, and so is `foo := Foo`, and a local that is
    /// declared says the same words without the hint. The check is of a
    /// function: at the top level the parser refuses the assignment when it
    /// reads the script.
    fn the_class_is_not_written(
        &self,
        name: &str,
        value: &Value,
        line: u32,
    ) -> Result<(), RuntimeFailure> {
        if self.declarations.is_empty() {
            return Ok(());
        }
        let key = the_key_of(name);
        if self.lives_in_the_script(&key) {
            return Ok(());
        }
        let Some(class) = self.the_class_of_the_name(&key) else {
            return Ok(());
        };
        if self.the_class_key_of_the_value(value).as_deref() != Some(class.as_str()) {
            return Ok(());
        }
        let message = if self.is_declared_local(&key) {
            "This local variable has not been assigned a value.".to_string()
        } else {
            "This local variable has not been assigned a value. A global declaration inside the function may be required.".to_string()
        };
        Err(RuntimeFailure::Error(RuntimeError { message, line }))
    }

    /// The class of that name, when the name is the name of a class.
    ///
    /// The classes of the script and the classes of the runtime are both
    /// names of the script, and the key of the table is the name in lower
    /// case.
    fn the_class_of_the_name(&self, name: &str) -> Option<String> {
        if self.classes.contains_key(name) || crate::classes::is_type(name) {
            return Some(name.to_string());
        }
        None
    }

    /// The class of a value, in the key of the table of the classes.
    ///
    /// The class of an instance is the class it is an instance of, and the
    /// class of a class is the class itself. The name that v2 shows is
    /// another one: a class is a "Class" there.
    fn the_class_key_of_the_value(&self, value: &Value) -> Option<String> {
        let Value::Object(object) = value else {
            return None;
        };
        Some(object.borrow().class.clone())
    }

    /// The alias of this name, if the name is one.
    ///
    /// A parameter written `&x` in the definition of a function is an
    /// alias of the variable of the caller.
    fn alias_of(&self, name: &str) -> Option<Reference> {
        let name = the_key_of(name);
        for scope in self.scopes.iter().rev() {
            let Some(found) = scope.borrow().get(&name).cloned() else {
                continue;
            };
            if let Value::Reference(reference) = found {
                if reference.alias {
                    return Some(reference);
                }
            }
            return None;
        }
        None
    }

    /// The value of the variable a reference points at.
    ///
    /// The answer is nothing when the variable has no value: that is the
    /// difference between a variable that is set and one that is not.
    pub(crate) fn read_reference(&self, reference: &Reference) -> Option<Value> {
        let name = the_key_of(&reference.name);
        match reference.scope {
            Scope::Global => self.variables.get(&name).cloned(),
            Scope::Local(depth) => self.scopes.get(depth)?.borrow().get(&name).cloned(),
        }
    }

    /// Write into the variable a reference points at.
    ///
    /// This is what a built-in does with the variable of the caller that
    /// it was given by reference.
    pub(crate) fn write_reference(&mut self, value: &Value, written: Value) {
        let Value::Reference(reference) = value else {
            return;
        };
        let name = the_key_of(&reference.name);
        match reference.scope {
            Scope::Global => {
                self.variables.insert(name, written);
            }
            Scope::Local(depth) => {
                if let Some(scope) = self.scopes.get(depth) {
                    scope.borrow_mut().insert(name, written);
                }
            }
        }
    }

    /// Take the value of the variable a reference points at away.
    ///
    /// The variable is left without a value: the enumeration of a place that
    /// has no value of its own writes nothing into it.
    pub(crate) fn unset_reference(&mut self, value: &Value) {
        let Value::Reference(reference) = value else {
            return;
        };
        let name = the_key_of(&reference.name);
        match reference.scope {
            Scope::Global => {
                self.variables.remove(name.as_str());
            }
            Scope::Local(depth) => {
                if let Some(scope) = self.scopes.get(depth) {
                    scope.borrow_mut().remove(name.as_str());
                }
            }
        }
    }

    /// Set a variable: in the innermost scope when there is one, in the
    /// global one otherwise. A function that assigns a name creates a local
    /// one, the way AutoHotkey v2 does.
    ///
    /// A parameter that is an alias of a variable of the caller writes
    /// there: the alias and the variable are the same thing.
    fn assign(&mut self, name: &str, value: Value) {
        if let Some(reference) = self.alias_of(name) {
            self.write_reference(&Value::Reference(reference), value);
            return;
        }
        let name = the_key_of(name);
        // A static variable belongs to the function that declares it: it is
        // written in the table of the function, and it is not in the scope
        // of the call.
        //
        // Measured on the binary of v2.0.19 on 2026-10-31: the static
        // shadows a global of the same name inside the function.
        if self.is_declared_static(&name) {
            self.the_statics_of_the_frame().insert(name, value);
            return;
        }
        // A name that a function declares global lives in the scope of the
        // script, and a name that it declares local lives in the scope of
        // the function. A function that assumes the scope of the script
        // says it for every name it does not name.
        if self.lives_in_the_script(&name) {
            self.variables.insert(name, value);
            return;
        }
        // A name that a scope around the call has is shared with it: v2
        // writes there, and not in the scope of the function that closes
        // over it.
        //
        // Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-02: the
        // v1 does not share them: the name is written in the scope of the
        // function that runs.
        if self.the_scopes_around_are_shared() {
            for scope in self.scopes.iter().rev().skip(1) {
                if scope.borrow().contains_key(&name) {
                    scope.borrow_mut().insert(name, value);
                    return;
                }
            }
        }
        match self.scopes.last() {
            Some(scope) => {
                scope.borrow_mut().insert(name, value);
            }
            None => {
                self.variables.insert(name, value);
            }
        }
    }

    /// Whether a name lives in the scope of the script.
    ///
    /// The frame of the function that runs says: the innermost one that
    /// names the variable decides, and a function that assumes the scope
    /// of the script says it for every name it does not name.
    fn lives_in_the_script(&self, name: &str) -> bool {
        let Some(frame) = self.declarations.last() else {
            return false;
        };
        if frame.globals.contains(name) {
            return true;
        }
        if frame.locals.contains(name) {
            return false;
        }
        frame.assume_global
    }

    /// The kind of a name whose reference cannot be taken.
    ///
    /// A built-in variable, a function and a class are not variables of
    /// the script, and v2 says which one of them it is.
    fn cannot_be_referenced(&self, name: &str) -> Option<&'static str> {
        let key = name.to_lowercase();
        if crate::variables::is_built_in(name) || self.dialect.carries_variable(name) {
            return Some("built-in variable");
        }
        if self.functions.contains_key(&key) || self.builtin(&key).is_some() {
            return Some("Func");
        }
        if self.classes.contains_key(&key) || crate::classes::is_type(&key) {
            return Some("Class");
        }
        None
    }

    /// The chain of the bases of an object.
    ///
    /// The base of an object is the prototype of its class, and the base of
    /// a prototype is the prototype of the class that the class extends.
    /// Every chain ends at the prototype of the base object.
    fn the_chain_of_the_bases(&self, target: &Value) -> Vec<Rc<RefCell<Object>>> {
        let mut chain: Vec<Rc<RefCell<Object>>> = Vec::new();
        let Value::Object(object) = target else {
            return chain;
        };
        let mut class = object.borrow().class.clone();
        // A class is not an instance of itself: the chain of a class begins
        // at the base of the class, and not at its own prototype.
        if self.class_name_of(target).is_some() {
            let Some(base) = self.the_base_class_of(&class) else {
                return chain;
            };
            class = base;
        }
        // A base that the script set is the base of the object.
        if let Some(Value::Object(base)) = object.borrow().value_of(BASE) {
            chain.push(base.clone());
            class = base.borrow().class.clone();
        }
        while let Some(prototype) = self.the_prototype_of_the_class(&class) {
            if chain.iter().any(|seen| Rc::ptr_eq(seen, &prototype)) {
                break;
            }
            chain.push(prototype);
            let Some(base) = self.the_base_class_of(&class) else {
                break;
            };
            class = base;
        }
        chain
    }

    /// The prototype of a class, the object that holds its methods.
    fn the_prototype_of_the_class(&self, class: &str) -> Option<Rc<RefCell<Object>>> {
        let Some(Value::Object(value)) = self.class_value_of(class) else {
            return None;
        };
        let prototype = value.borrow().value_of("prototype");
        let Some(Value::Object(prototype)) = prototype else {
            return None;
        };
        Some(prototype)
    }

    /// The class that a class extends.
    ///
    /// Every class of the script and every class of the runtime derives
    /// from the base object, and the enumerator and the errors have a base
    /// of their own.
    fn the_base_class_of(&self, class: &str) -> Option<String> {
        if let Some(definition) = self.classes.get(class) {
            if let Some(base) = &definition.extends {
                return Some(base.to_lowercase());
            }
            return Some("object".to_string());
        }
        if let Some(base) = crate::classes::the_base_of(class) {
            return Some(base.to_string());
        }
        Some("object".to_string())
    }

    /// The names of a class and of the classes it extends, the class
    /// first.
    fn class_chain(&self, name: &str) -> Vec<String> {
        let mut chain: Vec<String> = Vec::new();
        let mut current = Some(name.to_lowercase());
        while let Some(class) = current {
            // A class that extends itself, directly or through another,
            // would loop forever.
            if chain.contains(&class) {
                break;
            }
            chain.push(class.clone());
            current = match self.classes.get(&class) {
                Some(definition) => definition.extends.clone().map(|base| base.to_lowercase()),
                // The class types of the runtime have their own bases: the
                // errors of v2 are a tree, and every one of them is an
                // `Error`.
                None => crate::classes::the_base_of(&class).or_else(|| {
                    // The primitive types of v2 are a tree of their own,
                    // and the chain of them is the one of the `is`.
                    crate::classes::the_base_of_the_primitive_of_the_class(&class)
                })
                .map(|base| base.to_string()),
            };
        }
        chain
    }

    /// The method a name asks for, on a class, and the class that has it.
    ///
    /// The class matters: `super` asks the base of the class where the
    /// method was defined, and not the base of the class of the object.
    fn find_method_in(&self, class: &str, name: &str) -> Option<(String, MethodDef)> {
        let name = name.to_lowercase();
        for class in self.class_chain(class) {
            if let Some(definition) = self.classes.get(&class) {
                if let Some(method) = definition.methods.get(&name) {
                    return Some((class.clone(), method.clone()));
                }
            }
        }
        None
    }

    /// The method a name asks for, on a value.
    ///
    /// A static method belongs to the class and not to its instances, and
    /// the prototype of a class carries the methods of the class.
    fn find_method_on(&self, target: &Value, name: &str) -> Option<(String, MethodDef)> {
        let Value::Object(object) = target else {
            return None;
        };
        let class = object.borrow().class.clone();
        // A class value is not an instance of its class: the methods of the
        // class are not its own, and only the static ones are.
        //
        // Measured on the binary of v2.0.19 on 2026-10-31: the call of a
        // method of an instance is refused with 'This value of type "Class"
        // has no method named "Say".'
        if self.class_name_of(target).is_some() {
            // Measured on the binary of v1.1.37.02 on 2026-11-02: the v1
            // calls the method of the class object, and the `this` of the
            // method is the class object.
            if self
                .dialect
                .a_method_of_the_class_object_is_a_method_of_the_class()
            {
                return self.find_the_instance_method_in(&class, name);
            }
            return self.find_the_static_method_in(&class, name);
        }
        // A static method is not a member of an instance, and it is not a
        // member of the prototype of the class either.
        //
        // Measured on the binary of v2.0.19 on 2026-10-31: `obj.Say()` is
        // refused with 'This value of type "C" has no method named "Say".',
        // and a static method of a class does not hide the instance method
        // of its base: the instance has that one.
        let class = self.the_class_of_the_prototype(target).unwrap_or(class);
        self.find_the_instance_method_in(&class, name)
    }

    /// The object a class makes.
    fn construct(
        &mut self,
        class: &str,
        arguments: &[Node],
        line: u32,
    ) -> Result<Value, RuntimeFailure> {
        // A class type of the runtime makes its own object: the script
        // has no class of that name, and cannot extend one.
        if !self.classes.contains_key(&class.to_lowercase()) {
            let values = self.evaluate_all(arguments)?;
            return self.construct_with_values(class, &values, line);
        }
        let object = self.the_object_of_a_class(class);
        // The `__Init` of v2 runs before the `__New`, and the variables of
        // the class are assigned in it.
        self.call_the_init(class, &object, line)?;
        // `__New` runs with the new object as `this`, and may answer an
        // object of its own.
        if let Some((defining, method)) = self.find_the_instance_method_in(class, "__new") {
            let result = self.call_method(&defining, &method, &object, arguments, line)?;
            return Ok(match result {
                Value::Object(_) => result,
                _ => object,
            });
        }
        Ok(object)
    }

    /// The instance that the `new` of the v1 makes.
    ///
    /// Measured on the binary of v1.1.37.02 on 2026-11-02: the `new` makes
    /// an instance of a class of the script, the `__Init` of the class runs
    /// before the `__New`, and the arguments of the `new` are the ones of the
    /// `__New`. The new of a class that is not there is the empty text, and
    /// the v1 does not fail.
    fn new_instance(
        &mut self,
        path: &[String],
        arguments: &[Node],
        line: u32,
    ) -> Result<Value, RuntimeFailure> {
        // Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-02: the
        // class of the v1 is a variable of the script, and the `new` reads
        // it.
        if self.dialect.the_class_is_a_variable() {
            return self.new_instance_of_the_v1(path, arguments, line);
        }
        let Some(class) = path.first() else {
            return Ok(Value::Text(String::new()));
        };
        if !self.classes.contains_key(&class.to_lowercase()) {
            return Ok(Value::Text(String::new()));
        }
        self.construct(class, arguments, line)
    }

    /// The instance that the `new` of the v1 makes.
    ///
    /// Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-02: the
    /// `new` reads the variable of the name, and the class is the value of
    /// it: `new v` makes an instance of the class that `v` holds, and the
    /// `new` of an instance makes another one of the same class. A name that
    /// holds another value makes nothing, and the v1 does not fail.
    ///
    /// Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-02: the
    /// name may be followed by the names of the classes that the class of
    /// the value holds: the `new C.D` is an instance of D, and the
    /// `new this.D` is an instance of the class that the instance of the
    /// method holds.
    fn new_instance_of_the_v1(
        &mut self,
        path: &[String],
        arguments: &[Node],
        line: u32,
    ) -> Result<Value, RuntimeFailure> {
        let Some(first) = path.first() else {
            return Ok(Value::Text(String::new()));
        };
        // The first name of the path: the variable that holds the class, or
        // the class of the script, or the instance of the method that runs.
        let mut value = if first == "this" {
            self.the_this()
        } else {
            match self
                .lookup_variable(first)
                .or_else(|| self.class_value_of(first))
            {
                Some(value) => value,
                None => return Ok(Value::Text(String::new())),
            }
        };
        // Each name that follows is a class that the class of the value
        // holds.
        for name in &path[1..] {
            let Some(class) = self.the_class_that_the_v1_holds(&value, name) else {
                return Ok(Value::Text(String::new()));
            };
            value = class;
        }
        let Value::Object(object) = &value else {
            return Ok(Value::Text(String::new()));
        };
        // The class of the value: a class carries its own name, and an
        // instance carries the class of it.
        let class = match self.class_name_of(&value) {
            Some(class) => class,
            None => object.borrow().class.clone(),
        };
        self.construct(&class, arguments, line)
    }

    /// The object a class makes, with the arguments already read.
    fn construct_with_values(
        &mut self,
        class: &str,
        values: &[Value],
        line: u32,
    ) -> Result<Value, RuntimeFailure> {
        if !self.classes.contains_key(&class.to_lowercase()) {
            if let Some(result) = crate::classes::construct(class, values, self, line) {
                return result;
            }
        }
        let object = self.the_object_of_a_class(class);
        self.call_the_init(class, &object, line)?;
        if let Some((defining, method)) = self.find_the_instance_method_in(class, "__new") {
            let result = self.call_method_with(&defining, &method, &object, values, line)?;
            return Ok(match result {
                Value::Object(_) => result,
                _ => object,
            });
        }
        Ok(object)
    }

    /// The object of a class: an object of that class, with nothing in it.
    fn the_object_of_a_class(&self, class: &str) -> Value {
        Value::Object(Rc::new(RefCell::new(Object {
            class: class.to_lowercase(),
            properties: BTreeMap::new(),
        })))
    }

    /// The `__Init` of an instance, the way v2 calls it.
    ///
    /// The most derived `__Init` is the one that runs: the explicit one of
    /// the class, or the automatic one that carries the variables of the
    /// class. The automatic one calls the `__Init` of the base before it
    /// assigns the variables, and the explicit one calls nothing: the
    /// variables of the base are not assigned when the derived has an
    /// `__Init` of its own.
    fn call_the_init(
        &mut self,
        class: &str,
        object: &Value,
        line: u32,
    ) -> Result<(), RuntimeFailure> {
        let chain = self.class_chain(class);
        self.call_the_init_of(&chain, object, line)
    }

    /// The initialisation of a class of v2.
    ///
    /// A class is initialised when it is first used: the statement that
    /// defines it and the first reference to it. The variables that belong
    /// to the class are assigned then, and the `__New` that is static is
    /// the one that runs.
    fn initialise_the_class(&mut self, class: &str, line: u32) -> Result<(), RuntimeFailure> {
        let key = class.to_lowercase();
        // A class of the runtime has no variables of its own.
        if !self.classes.contains_key(&key) {
            return Ok(());
        }
        if !self.initialised.borrow_mut().insert(key.clone()) {
            // The class is already initialised.
            return Ok(());
        }
        self.assign_the_static_variables(&key)?;
        if let Some((defining, method)) = self.find_the_static_method_in(&key, "__new") {
            if let Some(value) = self.class_value_of(&key) {
                self.call_method(&defining, &method, &value, &[], line)?;
            }
        }
        Ok(())
    }

    /// The variables that belong to a class, assigned to the class.
    fn assign_the_static_variables(&mut self, class: &str) -> Result<(), RuntimeFailure> {
        let Some(definition) = self.classes.get(class).cloned() else {
            return Ok(());
        };
        let Some(value) = self.class_value_of(class) else {
            return Ok(());
        };
        let Value::Object(object) = value else {
            return Ok(());
        };
        for property in &definition.properties {
            if !property.is_static {
                continue;
            }
            let value = match &property.value {
                Some(node) => self.evaluate(node)?,
                None => Value::Text(String::new()),
            };
            put(&mut object.borrow_mut().properties, &property.name, value);
        }
        Ok(())
    }

    /// The method a name asks for, on a class, and that is static.
    ///
    /// A method that belongs to the class is not one of an instance: the
    /// `__New` that is static is the initialiser of the class, and it does
    /// not run when an instance is made.
    fn find_the_static_method_in(&self, class: &str, name: &str) -> Option<(String, MethodDef)> {
        let name = name.to_lowercase();
        for class in self.class_chain(class) {
            if let Some(definition) = self.classes.get(&class) {
                if let Some(method) = definition.methods.get(&name) {
                    if method.is_static {
                        return Some((class.clone(), method.clone()));
                    }
                }
            }
        }
        None
    }

    /// The method a name asks for, on a class, and that is not static.
    fn find_the_instance_method_in(&self, class: &str, name: &str) -> Option<(String, MethodDef)> {
        let name = name.to_lowercase();
        for class in self.class_chain(class) {
            if let Some(definition) = self.classes.get(&class) {
                if let Some(method) = definition.methods.get(&name) {
                    if !method.is_static {
                        return Some((class.clone(), method.clone()));
                    }
                }
            }
        }
        None
    }

    /// The `__Init` of an instance, over the chain of the classes.
    ///
    /// The chain goes from the class itself to the base of it.
    fn call_the_init_of(
        &mut self,
        chain: &[String],
        object: &Value,
        line: u32,
    ) -> Result<(), RuntimeFailure> {
        for (index, name) in chain.iter().enumerate() {
            let Some(definition) = self.classes.get(name).cloned() else {
                continue;
            };
            if let Some(method) = definition.methods.get("__init").cloned() {
                // The `__Init` of this class: it runs, and the ones of the
                // base do not.
                //
                // Measured on the binary of v2.0.19 on 2026-10-31: the
                // properties of the class are assigned after the body of the
                // `__Init`, and not before it -- the body may write them,
                // and the assignment of the class is the one that is left.
                self.call_method(name, &method, object, &[], line)?;
                self.assign_the_variables(name, object)?;
                return Ok(());
            }
            if !definition.properties.is_empty() {
                // The automatic `__Init`: the base comes first, and then
                // the variables of this class.
                if index + 1 < chain.len() {
                    self.call_the_init_of(&chain[index + 1..], object, line)?;
                }
                self.assign_the_variables(name, object)?;
                return Ok(());
            }
        }
        Ok(())
    }

    /// The variables of a class, assigned to the object.
    fn assign_the_variables(&mut self, class: &str, object: &Value) -> Result<(), RuntimeFailure> {
        let Some(definition) = self.classes.get(class).cloned() else {
            return Ok(());
        };
        let Value::Object(cell) = object else {
            return Ok(());
        };
        for property in &definition.properties {
            // A variable that belongs to the class is not one of the
            // instance: it is the class that has it.
            if property.is_static {
                continue;
            }
            let value = match &property.value {
                Some(node) => self.evaluate(node)?,
                None => Value::Text(String::new()),
            };
            // A variable of the class that has a getter of its own is one
            // name and not two: the write of it goes through the property.
            //
            // Measured on the binary of v2.0.19 on 2026-10-31: the
            // construction of the class is refused with "Property is
            // read-only." when the property has no setter.
            if self.the_accessor_of(object, &property.name).is_some() {
                self.the_write_of_an_accessor(object, &property.name, value, 0)?;
                continue;
            }
            put(&mut cell.borrow_mut().properties, &property.name, value);
        }
        Ok(())
    }

    /// The values of a list of arguments.
    fn evaluate_all(&mut self, arguments: &[Node]) -> Result<Vec<Value>, RuntimeFailure> {
        let mut values = Vec::with_capacity(arguments.len());
        for argument in arguments {
            values.push(self.evaluate(argument)?);
        }
        Ok(values)
    }

    /// The base of the class where the method that runs was defined.
    fn the_base_of_the_running_method(&self) -> Option<String> {
        let class = self.current_classes.last()?;
        self.class_chain(class).get(1).cloned()
    }

    /// The value the method that runs was called on.
    fn the_this(&self) -> Value {
        for scope in self.scopes.iter().rev() {
            if let Some(value) = scope.borrow().get("this") {
                return value.clone();
            }
        }
        Value::Text(String::new())
    }

    /// The class of the value the method that runs was called on.
    ///
    /// The name is the one the class was written with: v2 names the class
    /// of the value in its refusals.
    fn the_class_of_this(&self) -> String {
        self.class_of(&self.the_this()).unwrap_or_default()
    }

    /// The method of the base of the class where the method was defined.
    ///
    /// `super.m()` is this one.
    fn call_the_method_of_the_base(
        &mut self,
        name: &str,
        arguments: &[Node],
        line: u32,
    ) -> Result<Value, RuntimeFailure> {
        // Every class of v2 has an `__Init`: the automatic one that carries
        // the variables of the class. So `super.__Init()` runs the one of
        // the base, and it never fails for want of a method.
        if name.eq_ignore_ascii_case("__init") {
            let this = self.the_this();
            if let Some(base) = self.the_base_of_the_running_method() {
                let chain = self.class_chain(&base);
                self.call_the_init_of(&chain, &this, line)?;
            }
            return Ok(Value::Text(String::new()));
        }
        let found = self
            .the_base_of_the_running_method()
            .and_then(|base| self.find_method_in(&base, name));
        let Some((defining, method)) = found else {
            return Err(RuntimeFailure::Error(RuntimeError {
                message: format!(
                    "This value of type \"{}\" has no method named \"{name}\".",
                    self.the_class_of_this()
                ),
                line,
            }));
        };
        let this = self.the_this();
        self.call_method(&defining, &method, &this, arguments, line)
    }

    /// The property of the base, the way v2 reads it.
    ///
    /// `super.value` is this one: the base has to have the getter, and the
    /// value of the object alone is not enough.
    fn read_the_property_of_the_base(
        &mut self,
        name: &str,
        line: u32,
    ) -> Result<Value, RuntimeFailure> {
        let base = self.the_base_of_the_running_method();
        let this = self.the_this();
        if let Some(base) = base {
            // The base has to have the getter: the property of the object
            // alone is not enough. Measured on the binary of v2.0.19 on
            // 2026-10-30, `super.value` refuses when the base only has
            // `this.value := ...`.
            if let Some((defining, method)) = self.find_method_in(&base, "__get") {
                let params = self.the_params(&[], line)?;
                return self.call_method_with(
                    &defining,
                    &method,
                    &this,
                    &[Value::Text(name.to_string()), params],
                    line,
                );
            }
        }
        Err(RuntimeFailure::Error(RuntimeError {
            message: format!(
                "This value of type \"{}\" has no property named \"{name}\".",
                self.the_class_of_this()
            ),
            line,
        }))
    }

    /// The item of the base, the way v2 reads it.
    ///
    /// `super["value"]` is this one.
    fn read_the_item_of_the_base(
        &mut self,
        key: &Value,
        line: u32,
    ) -> Result<Value, RuntimeFailure> {
        let base = self.the_base_of_the_running_method();
        let this = self.the_this();
        if let Some(base) = base {
            if let Some((defining, method)) = self.find_method_in(&base, "__item") {
                let arguments = [Node::Literal {
                    value: LiteralValue::Text(key.to_text()),
                    line,
                }];
                return self.call_method(&defining, &method, &this, &arguments, line);
            }
        }
        Err(RuntimeFailure::Error(RuntimeError {
            message: format!(
                "This value of type \"{}\" has no property named \"__Item\".",
                self.the_class_of_this()
            ),
            line,
        }))
    }

    /// A method, called on a value.
    ///
    /// The class of the script answers first. A class type of the
    /// runtime answers for itself, and the two never overlap: the
    /// script cannot extend a class type of the runtime.
    fn call_method_on(
        &mut self,
        target: &Value,
        name: &str,
        arguments: &[Node],
        line: u32,
    ) -> Result<Value, RuntimeFailure> {
        if let Some((defining, method)) = self.find_method_on(target, name) {
            return self.call_method(&defining, &method, target, arguments, line);
        }
        // A class is not an instance of itself: the call of a class value
        // makes an object of the class, the way `Map()` does, and the
        // copy of a class is a class and not an object of it.
        //
        // Measured on the binary of v2.0.19 on 2026-10-31.
        if self.class_name_of(target).is_some() {
            if name.eq_ignore_ascii_case("call") {
                let class = self.class_name_of(target).unwrap_or_default();
                // Measured on the binary of AutoHotkey v1.1.37.02 on
                // 2026-11-02: the class of the v1 has no `Call`, and the
                // call of it makes nothing: the `C.Call()` is the empty
                // text. The instance of a class of the script is made with
                // the `new`.
                if self.dialect.the_call_of_a_class_makes_nothing() {
                    return Ok(Value::Text(String::new()));
                }
                return self.construct(&class, arguments, line);
            }
            if name.eq_ignore_ascii_case("clone") {
                return Ok(self.clone_of_a_class(target));
            }
            // The methods of a class are the static ones, and the tree
            // hands them over as values.
            //
            // Measured on the binary of v2.0.19 on 2026-10-31.
            if name.eq_ignore_ascii_case("getmethod") {
                let values = self.evaluate_all(arguments)?;
                return self.the_static_method(target, &values, line);
            }
            // A class that the class holds is a class of its own, and the
            // call of it makes an object of it.
            //
            // Measured on the binary of v2.0.19 on 2026-10-31:
            // `Outer.Inner()` is an object of the class inside `Outer`.
            //
            // Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-02:
            // the class of the v1 has no `Call`, and the call of the class
            // that a class holds makes nothing: the `C.D()` is the empty
            // text. The instance is made with the `new`.
            if let Some(value) = self.the_class_that_a_class_holds(target, name) {
                if self.dialect.the_call_of_a_class_makes_nothing() {
                    return Ok(Value::Text(String::new()));
                }
                let class = self.class_name_of(&value).unwrap_or_default();
                return self.construct(&class, arguments, line);
            }
        }
        // A property of the class that has a getter and that takes
        // parameters: the call of it invokes the getter, and the parameters
        // of the property are the ones of the index.
        //
        // Measured on the binary of v2.0.19 on 2026-10-31: `obj.value("a")`
        // is refused with "Missing a required parameter." when the property
        // takes parameters, and a property without parameters is not called
        // at all.
        if let Some(access) = self.the_accessor_of(target, name) {
            if !access.parameters.is_empty() {
                let Some(getter) = &access.getter else {
                    return Err(self.no_method(target, name, line));
                };
                return self.call_the_body_of_an_accessor(target, &access, getter, line, &[], None);
            }
        }
        // The automatic `__Init` of the class, the one that carries the
        // variables: `d.__Init()` runs it again.
        if name.eq_ignore_ascii_case("__init") {
            if let Value::Object(object) = target {
                let class = object.borrow().class.clone();
                let chain = self.class_chain(&class);
                self.call_the_init_of(&chain, target, line)?;
                return Ok(Value::Text(String::new()));
            }
        }
        let values = self.evaluate_all(arguments)?;
        // A property that is a descriptor may have a call of its own: the
        // property of the object shadows the method of the class.
        if let Some(call) = self.the_call_of_the_descriptor(target, name) {
            return self.call_the_function(&call, target, &values, line);
        }
        // A property that has no call of its own may be a function: v2
        // asks the getter for the value of it and calls that.
        if let Some(value) = self.the_value_of_the_descriptor_for_a_call(target, name, line)? {
            if self.is_a_function(&value) {
                return self.call_the_function(&value, target, &values, line);
            }
        }
        let class = match target {
            Value::Object(object) => object.borrow().class.clone(),
            _ => String::new(),
        };
        // The number of the arguments is checked here: v2 checks it when
        // the script writes the call, and the failure carries the name of
        // the method.
        if let Some((min, max)) = crate::classes::the_arity_of(&class, name) {
            let count = values.len() as i64;
            if count < min || (max >= 0 && count > max) {
                let message = if count < min {
                    "Too few parameters passed to function."
                } else {
                    "Too many parameters passed to function."
                };
                return Err(crate::classes::the_arity_failure(
                    &class, name, message, line,
                ));
            }
        }
        // A class value is not an instance of its class: the methods of the
        // class do not answer it.
        //
        // Measured on the binary of v2.0.19 on 2026-10-31: `Map.Get("a")` and
        // `Map.Clear()` are refused.
        if self.class_name_of(target).is_none() {
            if let Some(result) = crate::classes::call(&class, name, target, &values, self, line) {
                return result;
            }
        }
        // The prototype of an `Any`, of a `ComObject` and of a `ComValue` is
        // not a prototype: it has no method at all.
        //
        // Measured on the binary of v2.0.19 on 2026-10-31: the refusal says
        // 'This value of type "Prototype" has no method named "OwnProps".',
        // and the name of the member is not in it.
        if let Some(class) = self.the_class_of_the_prototype(target) {
            if crate::classes::the_prototype_is_not_one(&class) {
                return Err(RuntimeFailure::Detailed(
                    RuntimeError {
                        message: format!(
                            "This value of type \"{}\" has no method named \"{}\".",
                            self.the_type_of(target),
                            name
                        ),
                        line,
                    },
                    Detail {
                        what: String::new(),
                        extra: String::new(),
                    },
                ));
            }
        }
        // A method of the class cannot be called on the prototype of it: the
        // value is not an instance of the class.
        //
        // Measured on the binary of v2.0.19 on 2026-10-31:
        // `Map.Prototype.Get("a")` is refused with "Expected a Map but got a
        // Prototype.".
        if let Some(class) = self.the_class_of_the_prototype(target) {
            if self.the_class_has_the_method(&class, name) {
                // A method of a class of the script runs on the prototype:
                // v2 calls it, and `this` is the prototype.
                //
                // Measured on the binary of v2.0.19 on 2026-10-31:
                // `D.Prototype.Say()` answers 1, and the class of the
                // value that it answers is the class of the prototype.
                if self.classes.contains_key(&class) {
                    if let Some((defining, method)) = self.find_the_instance_method_in(&class, name)
                    {
                        return self.call_method_with(&defining, &method, target, &values, line);
                    }
                }
                let spelled = self.the_spelling_of_the_method_of_a_class(&class, name);
                return Err(RuntimeFailure::Detailed(
                    RuntimeError {
                        message: expected_the_class(
                            &self.the_spelling_of_the_class(&class),
                            "Prototype",
                        ),
                        line,
                    },
                    Detail {
                        what: self.the_name_of_a_member(&class, &spelled),
                        extra: String::new(),
                    },
                ));
            }
        }
        // Every object has the methods of the base object.
        if let Some(result) = self.base_method(target, name, &values, line) {
            return result;
        }
        // `__Call` is asked when the method is not there: v2 asks it with
        // the name of the method and the parameters of the call.
        if let Some((defining, method)) = self.find_method_in(&class, "__call") {
            let params = self.the_params(&values, line)?;
            return self.call_method_with(
                &defining,
                &method,
                target,
                &[Value::Text(name.to_string()), params],
                line,
            );
        }
        // Measured on the binary of v1.1.37.02 on 2026-11-02: the v1 does
        // not refuse the method that a value does not have, and the answer
        // is a blank text.
        if self.dialect.a_member_that_is_not_there_is_answered() {
            return Ok(Value::Text(String::new()));
        }
        Err(self.no_method(target, name, line))
    }

    /// A method, called on a value.
    fn call_method(
        &mut self,
        class: &str,
        method: &MethodDef,
        this: &Value,
        arguments: &[Node],
        line: u32,
    ) -> Result<Value, RuntimeFailure> {
        // Measured on the binary of v2.0.19 on 2026-10-31: the number of the
        // arguments is checked before the arguments are evaluated: v2
        // refuses the script when it loads, and the refusal of the arity
        // comes before the failure of an argument.
        self.the_arity_of_a_method(class, method, arguments, line)?;
        let mut values: Vec<Value> = Vec::with_capacity(arguments.len());
        for argument in arguments {
            values.push(self.evaluate(argument)?);
        }
        // Measured on the binary of v2.0.19 on 2026-10-31: the parameter
        // that the command does not give a value to is the one that is not
        // there: the place of it is kept, and it has no value.
        let missing: Vec<bool> = arguments
            .iter()
            .map(|argument| matches!(argument, Node::Empty { .. }))
            .collect();
        self.call_method_with_missing(class, method, this, &values, line, &missing)
    }

    /// The number of the arguments of the call of a method.
    ///
    /// Measured on the binary of v2.0.19 on 2026-10-30: the failure of the
    /// arity of a method carries the name of the method in the `Extra`, and
    /// the parameter that is missing carries the name of it.
    fn the_arity_of_a_method(
        &self,
        class: &str,
        method: &MethodDef,
        arguments: &[Node],
        line: u32,
    ) -> Result<(), RuntimeFailure> {
        // Measured on the binary of v1.1.37.02 on 2026-11-02: the v1 does
        // not check the number of the arguments of a method, and the
        // parameters that the call does not give a value to are empty.
        if !self.dialect.the_call_of_a_method_checks_the_arity() {
            return Ok(());
        }
        // The rest of the arguments may be any number of them, and a
        // method that has one has no maximum.
        let variadic = method.parameters.iter().any(|parameter| parameter.variadic);
        if !variadic && arguments.len() > method.parameters.len() {
            let extra = self.the_name_of_the_method(class, method);
            return Err(RuntimeFailure::Detailed(
                RuntimeError {
                    message: "Too many parameters passed to function.".into(),
                    line,
                },
                Detail {
                    what: String::new(),
                    extra,
                },
            ));
        }
        // A parameter that has no default is required: v2 refuses the call
        // and says that the parameter is missing.
        for (index, parameter) in method.parameters.iter().enumerate() {
            let is_missing = matches!(arguments.get(index), Some(Node::Empty { .. }));
            if (is_missing || arguments.get(index).is_none())
                && parameter.default.is_none()
                && !parameter.variadic
            {
                return Err(RuntimeFailure::Detailed(
                    RuntimeError {
                        message: "Missing a required parameter.".into(),
                        line,
                    },
                    Detail {
                        what: String::new(),
                        extra: parameter.name.clone(),
                    },
                ));
            }
        }
        Ok(())
    }

    /// A method, called with the values of the arguments.
    ///
    /// The number of the arguments is checked the way v2 checks it: a
    /// parameter that has no default is required, and the call cannot
    /// give more arguments than the method has parameters.
    fn call_method_with(
        &mut self,
        class: &str,
        method: &MethodDef,
        this: &Value,
        values: &[Value],
        line: u32,
    ) -> Result<Value, RuntimeFailure> {
        self.call_method_with_missing(class, method, this, values, line, &[])
    }

    /// A method, called with the values of the arguments, and with the
    /// parameters that the call does not give a value to.
    ///
    /// Measured on the binary of v2.0.19 on 2026-10-31: a parameter that
    /// the command does not give a value to is a missing one, and the call
    /// is refused with "Missing a required parameter." -- the name of the
    /// parameter is in the `Extra`. A parameter that has a default takes
    /// it.
    fn call_method_with_missing(
        &mut self,
        class: &str,
        method: &MethodDef,
        this: &Value,
        values: &[Value],
        line: u32,
        missing: &[bool],
    ) -> Result<Value, RuntimeFailure> {
        // The rest of the arguments may be any number of them, and a
        // method that has one has no maximum.
        let variadic = method.parameters.iter().any(|parameter| parameter.variadic);
        // Measured on the binary of v1.1.37.02 on 2026-11-02: the v1 does
        // not check the number of the arguments of a method.
        if self.dialect.the_call_of_a_method_checks_the_arity() {
            if !variadic && values.len() > method.parameters.len() {
                let extra = self.the_name_of_the_method(class, method);
                return Err(RuntimeFailure::Detailed(
                    RuntimeError {
                        message: "Too many parameters passed to function.".into(),
                        line,
                    },
                    Detail {
                        what: String::new(),
                        extra,
                    },
                ));
            }
            // A parameter that has no default is required: v2 refuses the
            // call and says that the parameter is missing.
            for (index, parameter) in method.parameters.iter().enumerate() {
                let is_missing = missing.get(index).copied().unwrap_or(false);
                if (is_missing || values.get(index).is_none())
                    && parameter.default.is_none()
                    && !parameter.variadic
                {
                    return Err(RuntimeFailure::Detailed(
                        RuntimeError {
                            message: "Missing a required parameter.".into(),
                            line,
                        },
                        Detail {
                            what: String::new(),
                            extra: parameter.name.clone(),
                        },
                    ));
                }
            }
        } else {
            // Measured on the binary of v1.1.37.02 on 2026-11-02: the v1
            // calls the method only when the call gives a value to every
            // parameter that has no default. Otherwise the method does not
            // run, and the answer of the call is the empty text.
            for (index, parameter) in method.parameters.iter().enumerate() {
                let is_missing = missing.get(index).copied().unwrap_or(false);
                if (is_missing || values.get(index).is_none())
                    && parameter.default.is_none()
                    && !parameter.variadic
                {
                    return Ok(Value::Text(String::new()));
                }
            }
        }
        let mut scope: BTreeMap<String, Value> = BTreeMap::new();
        // The value the method was called on is `this`.
        scope.insert("this".to_string(), this.clone());
        // The parameters that the call does not give a value to take
        // their default, and the ones that have none are empty.
        for (index, parameter) in method.parameters.iter().enumerate() {
            let given = values.get(index);
            // A parameter that the command does not give a value to is a
            // missing one: the default of it is taken, and one that has no
            // default at all was refused above.
            let is_missing = missing.get(index).copied().unwrap_or(false);
            let value = match given {
                Some(value) if !is_missing => value.clone(),
                // A parameter that the call does not give a value to takes
                // its default, and one that has no default at all is empty.
                _ => match &parameter.default {
                    Some(default) => self.evaluate(default)?,
                    None => Value::Text(String::new()),
                },
            };
            // A parameter that the call does not give a value to is a local
            // one, even when it is written `&x`: the default of v2 is a
            // value of its own.
            if parameter.by_ref && given.is_some() && !is_missing {
                // The caller must pass a reference: the parameter is an
                // alias of the variable the reference points at.
                let Value::Reference(reference) = value else {
                    return Err(RuntimeFailure::Error(RuntimeError {
                        message: wants_a_reference(
                            index + 1,
                            &method.name,
                            "a variable reference",
                            &value,
                        ),
                        line,
                    }));
                };
                let mut alias = reference;
                alias.alias = true;
                scope.insert(the_key_of(&parameter.name), Value::Reference(alias));
                continue;
            }
            scope.insert(the_key_of(&parameter.name), value);
        }
        // The parameter that takes the rest of the arguments takes them as
        // an array, the way v2 has it.
        if let Some(index) = method
            .parameters
            .iter()
            .position(|parameter| parameter.variadic)
        {
            let rest: Vec<Value> = values.iter().skip(index).cloned().collect();
            let array = match crate::classes::construct("array", &rest, self, line) {
                Some(result) => result?,
                None => Value::List(rest),
            };
            scope.insert(the_key_of(&method.parameters[index].name), array);
        }
        let frame = self.the_name_of_the_method(class, method);
        self.enter_call(line)?;
        self.scopes.push(Rc::new(RefCell::new(scope)));
        // The functions that are written inside the method are there
        // before the body runs.
        self.collect_the_nested_functions(&method.body);
        self.declarations.push(method.declarations.clone());
        self.current_classes.push(class.to_lowercase());
        self.frames.push(Frame { name: frame, line });
        // The labels of the method are the scope of the method.
        self.label_scopes.push(the_labels_of(&method.body));
        let outcome = self.run_block(&method.body);
        self.label_scopes.pop();
        self.frames.pop();
        self.current_classes.pop();
        self.declarations.pop();
        self.scopes.pop();
        self.leave_call();
        match outcome {
            Ok(()) => Ok(Value::Text(String::new())),
            Err(RuntimeFailure::Flow(Flow::Return(value))) => {
                Ok(value.unwrap_or(Value::Text(String::new())))
            }
            // The jump of a `Goto` that leaves the method: the label is not
            // in the scope of the method.
            Err(RuntimeFailure::Flow(Flow::Goto { name, line })) => Err(RuntimeFailure::Fatal(
                self.the_label_is_not_there(&name, &method.body, line),
            )),
            Err(other) => Err(other),
        }
    }

    /// The base of a value.
    ///
    /// Measured on the binary of v2.0.19 on 2026-10-31: the base of an
    /// object is the prototype of its class, the base of a class is the
    /// class that it extends, and the base of a prototype is the
    /// prototype of the class that it extends.
    fn the_base_of_the_value(&self, target: &Value) -> Option<Value> {
        let Value::Object(object) = target else {
            return None;
        };
        let class = object.borrow().class.clone();
        // The prototype of a class: its base is the prototype of the
        // class that the class extends.
        if class == "prototype" {
            let name = object
                .borrow()
                .value_of(CLASS_NAME)
                .map(|value| value.to_text().to_lowercase())?;
            let base = crate::classes::the_base_class_of_a_class(&name)?;
            return self.the_prototype_of(base);
        }
        // A class is not an instance of itself: the base of a class is
        // the class that it extends. A base that the script wrote is the
        // base of the class, and it is an object and not a class.
        //
        // Measured on the binary of v2.0.19 on 2026-10-31.
        if let Some(name) = self.class_name_of(target) {
            if let Some(base) = self.stored_base_of(target) {
                return Some(base);
            }
            return self.the_base_of_the_class(&name);
        }
        self.base_of(target)
    }

    /// The base of a class: the class that it extends.
    ///
    /// A class of the script extends the class it names, and the base
    /// object when it names none. A class of the runtime has the bases of
    /// v2: the errors of v2 are a tree, and the `Any` is the root of it.
    fn the_base_of_the_class(&self, name: &str) -> Option<Value> {
        let base = self.the_base_of_the_class_name(name)?;
        self.class_value_of(&base)
    }

    /// The name of the class that a class extends.
    fn the_base_of_the_class_name(&self, name: &str) -> Option<String> {
        let name = name.to_lowercase();
        if let Some(definition) = self.classes.get(&name) {
            let base = definition
                .extends
                .clone()
                .unwrap_or_else(|| "object".to_string());
            return Some(base.to_lowercase());
        }
        crate::classes::the_base_class_of_a_class(&name).map(|base| base.to_string())
    }

    /// The chain of the bases of a class.
    ///
    /// Measured on the binary of v2.0.19 on 2026-10-31: the chain of a
    /// class is the chain of the classes that it extends, and it begins at
    /// the base of the class: a class is not a base of itself. A base that
    /// the script wrote replaces the chain.
    fn the_chain_of_the_class_bases(&self, target: &Value) -> Vec<Value> {
        let mut chain: Vec<Value> = Vec::new();
        let Some(name) = self.class_name_of(target) else {
            return chain;
        };
        if self.stored_base_of(target).is_some() {
            return chain;
        }
        let mut current = self.the_base_of_the_class_name(&name);
        while let Some(class) = current {
            let Some(value) = self.class_value_of(&class) else {
                break;
            };
            let Value::Object(object) = &value else { break };
            // A class that extends itself would loop for ever.
            if chain.iter().any(|seen| match seen {
                Value::Object(other) => Rc::ptr_eq(other, object),
                _ => false,
            }) {
                break;
            }
            chain.push(value);
            current = self.the_base_of_the_class_name(&class);
        }
        chain
    }

    /// The prototype of a class.
    fn the_prototype_of(&self, class: &str) -> Option<Value> {
        let Value::Object(value) = self.class_value_of(class)? else {
            return None;
        };
        value.borrow().value_of("prototype")
    }

    /// The static method of a class, as a value.
    ///
    /// Measured on the binary of v2.0.19 on 2026-10-31: every class has
    /// the methods of the base object as static ones -- `HasProp`,
    /// `HasMethod`, `GetMethod`, `HasBase`, `OwnProps`, `HasOwnProp`,
    /// `DefineProp`, `DeleteProp`, `GetOwnPropDesc` and `Clone` -- and
    /// the call of the class is one of them.
    fn the_static_method(
        &self,
        target: &Value,
        arguments: &[Value],
        line: u32,
    ) -> Result<Value, RuntimeFailure> {
        let Some(name) = arguments.first().map(|value| value.to_text()) else {
            return Err(RuntimeFailure::Error(RuntimeError {
                message: "GetMethod needs a name.".to_string(),
                line,
            }));
        };
        let lower = name.to_lowercase();
        // The prototype of a class is a property of it, and the `GetMethod`
        // of it fails with the words of the prototype.
        //
        // Measured on the binary of v2.0.19 on 2026-10-31: "This value of
        // type \"Prototype\" has no method named \"Call\"."
        if lower == "prototype" {
            return Err(crate::classes::named(
                RuntimeFailure::Error(RuntimeError {
                    message: "This value of type \"Prototype\" has no method named \"Call\"."
                        .to_string(),
                    line,
                }),
                "GetMethod",
            ));
        }
        // A static method that the class declares is its own, and the
        // `GetMethod` of a class hands it over.
        //
        // Measured on the binary of v2.0.19 on 2026-10-31:
        // `C.GetMethod("Say")` is a function whose name is "C.Say".
        if let Some(class) = self.class_name_of(target) {
            if let Some((defining, method)) = self.find_the_static_method_in(&class, &lower) {
                return Ok(self.static_method_reference(&defining, &method));
            }
        }
        if !crate::classes::the_static_methods_of_a_class().contains(&lower.as_str()) {
            // The class does not have the method: the words of the
            // dialect say so, and the name of the method goes in the
            // `What`.
            return Err(crate::classes::named(
                self.no_method(target, &name, line),
                "GetMethod",
            ));
        }
        // The name of the method is the way v2 spells it, and the object
        // is one of the arguments of the call.
        let spelled = if lower == "call" {
            let class = self.class_name_of(target).unwrap_or_default();
            format!("{}.Call", crate::classes::the_spelling_of(&class))
        } else {
            crate::classes::the_name_of_a_method_of_the_base_object(&lower)
        };
        let (min, max) = crate::classes::the_arity_of("object", &lower).unwrap_or((0, 0));
        Ok(self.method_reference_of_the_base_object(&spelled, &lower, min + 1, max + 1))
    }

    /// The static methods of a class value.
    ///
    /// Measured on the binary of v2.0.19 on 2026-10-31: a class has the
    /// methods of the base object, the call of the class, and the static
    /// methods that it declares. The methods of its instances are not its
    /// own.
    fn the_static_methods_of_a_class_value(&self, target: &Value) -> Vec<String> {
        let mut names: Vec<String> = crate::classes::the_static_methods_of_a_class()
            .iter()
            .map(|name| name.to_string())
            .collect();
        for name in self.the_static_methods_declared_by_a_class(target) {
            if !names.contains(&name) {
                names.push(name);
            }
        }
        names
    }

    /// The static methods that a class declares.
    ///
    /// Measured on the binary of v2.0.19 on 2026-10-31: they are the own
    /// properties of the class value, the way the call of the class is.
    fn the_static_methods_declared_by_a_class(&self, target: &Value) -> Vec<String> {
        let mut names: Vec<String> = Vec::new();
        let Some(class) = self.class_name_of(target) else {
            return names;
        };
        for class in self.class_chain(&class) {
            let Some(definition) = self.classes.get(&class) else {
                continue;
            };
            for (name, method) in &definition.methods {
                if method.is_static && !names.contains(name) {
                    names.push(name.clone());
                }
            }
        }
        names
    }

    /// The static method of a class value, as a value.
    ///
    /// Measured on the binary of v2.0.19 on 2026-10-31: a class has the
    /// methods of the base object and the static methods that it declares,
    /// and v2 hands them over as values: `Map.Call` is a function whose
    /// name is "Map.Call", and `C.Say` is one whose name is "C.Say".
    fn the_static_method_of_a_class_value(
        &mut self,
        target: &Value,
        name: &str,
        line: u32,
    ) -> Result<Option<Value>, RuntimeFailure> {
        let lower = name.to_lowercase();
        if !self
            .the_static_methods_of_a_class_value(target)
            .contains(&lower)
        {
            return Ok(None);
        }
        // The static methods that the class of the script declares.
        if let Some(class) = self.class_name_of(target) {
            if let Some((defining, method)) = self.find_the_static_method_in(&class, &lower) {
                return Ok(Some(self.static_method_reference(&defining, &method)));
            }
        }
        // The methods of the base object.
        let values = [Value::Text(name.to_string())];
        Ok(Some(self.the_static_method(target, &values, line)?))
    }

    /// The class that a value is the prototype of.
    ///
    /// The prototype of a class holds the members of the class, and the name
    /// of the class is under the key of it.
    fn the_class_of_the_prototype(&self, target: &Value) -> Option<String> {
        let Value::Object(object) = target else {
            return None;
        };
        if object.borrow().class != "prototype" {
            return None;
        }
        object
            .borrow()
            .value_of(CLASS_NAME)
            .map(|name| name.to_text().to_lowercase())
    }

    /// The name of a class, the way v2 spells it.
    ///
    /// The class of the runtime has a spelling of its own, and the class of
    /// the script is spelled the way the script wrote it.
    fn the_spelling_of_the_class(&self, class: &str) -> String {
        self.classes
            .get(class)
            .map(|definition| definition.name.clone())
            .unwrap_or_else(|| crate::classes::the_spelling_of(class))
    }

    /// The name of a member of a class, the way v2 names it in a failure.
    ///
    /// The name of the class, the name of the prototype, and the name of the
    /// member.
    fn the_name_of_a_member(&self, class: &str, member: &str) -> String {
        format!(
            "{}.Prototype.{}",
            self.the_spelling_of_the_class(class),
            member
        )
    }

    /// The name of a method of a class, the way v2 spells it.
    fn the_spelling_of_the_method_of_a_class(&self, class: &str, name: &str) -> String {
        let lower = name.to_lowercase();
        if let Some(definition) = self.classes.get(class) {
            if let Some(method) = definition.methods.get(&lower) {
                return method.name.clone();
            }
        }
        crate::classes::the_method_of(class, &lower)
            .map(|(spelled, _, _)| spelled.to_string())
            .unwrap_or_else(|| name.to_string())
    }

    /// Whether the class has a method of that name.
    ///
    /// The methods of the base object are the ones every object has, and the
    /// prototype of a class answers for them.
    fn the_class_has_the_method(&self, class: &str, name: &str) -> bool {
        let lower = name.to_lowercase();
        if crate::classes::the_base_object_has_the_method(&lower) {
            return false;
        }
        if self.classes.contains_key(class) {
            // A static method is not a method of the prototype.
            //
            // Measured on the binary of v2.0.19 on 2026-10-31:
            // `C.Prototype.Say()` is refused with 'This value of type
            // "Prototype" has no method named "Say".' when `Say` is a
            // static method of the class.
            return self.find_the_instance_method_in(class, &lower).is_some();
        }
        crate::classes::the_methods_of_the_prototype(class)
            .iter()
            .any(|method| method.to_lowercase() == lower)
    }

    /// Whether the prototype of a class has a member of that name.
    ///
    /// The members of a class of the runtime are in the table of the
    /// prototype, and the class of the script declares the methods of it.
    fn the_prototype_has_the_member(&self, class: &str, name: &str) -> bool {
        let lower = name.to_lowercase();
        if let Some(definition) = self.classes.get(class) {
            return definition
                .methods
                .values()
                .any(|method| !method.is_static && method.name.to_lowercase() == lower)
                || definition
                    .accessors
                    .values()
                    .any(|access| !access.is_static && access.name.to_lowercase() == lower);
        }
        crate::classes::the_members_of_the_prototype(class)
            .iter()
            .any(|member| member.to_lowercase() == lower)
    }

    /// The own properties of a prototype.
    ///
    /// Measured on the binary of v2.0.19 on 2026-10-31: the prototype of a
    /// class owns the class of the value and the members that the class
    /// declares -- the methods of it and the properties of it. The prototype
    /// of the base object owns the six members of the base object, and the
    /// prototype of a class of the script owns the methods that the class
    /// declares itself.
    fn the_own_properties_of_a_prototype(&self, target: &Value) -> Vec<String> {
        let mut names = vec!["__Class".to_string()];
        let Some(class) = self.the_class_of_the_prototype(target) else {
            return names;
        };
        match self.classes.get(&class) {
            // A class of the script: the methods that it declares itself.
            // The static ones belong to the class and not to its prototype.
            Some(definition) => {
                for method in definition.methods.values() {
                    if !method.is_static {
                        names.push(method.name.clone());
                    }
                }
                for access in definition.accessors.values() {
                    if !access.is_static {
                        names.push(access.name.clone());
                    }
                }
                // The automatic `__Init` is own of the prototype when the
                // class has variables of its own: it is the one that
                // carries them.
                //
                // Measured on the binary of v2.0.19 on 2026-10-31: the
                // prototype of a class with a property owns "__Init".
                if !definition.methods.contains_key("__init")
                    && definition
                        .properties
                        .iter()
                        .any(|property| !property.is_static)
                {
                    names.push("__Init".to_string());
                }
            }
            // A class of the runtime: the members of the class type.
            None => {
                for name in crate::classes::the_members_of_the_prototype(&class) {
                    names.push((*name).to_string());
                }
            }
        }
        // The names are in the order of v2, and the case of them does not
        // count.
        names.sort_by_key(|name| name.to_lowercase());
        names.dedup();
        names
    }

    /// The value of an own property of a prototype.
    ///
    /// The class of the value is its own property, and a method of the class
    /// is handed over as a function. A property of the class cannot be read
    /// on the prototype of it, and the value of it is empty.
    fn the_value_of_an_own_property_of_a_prototype(&self, target: &Value, name: &str) -> Value {
        let lower = name.to_lowercase();
        if lower == "__class" {
            return Value::Text(self.the_class_of_the_value(target));
        }
        let Some(class) = self.the_class_of_the_prototype(target) else {
            return Value::Text(String::new());
        };
        // A method of a class of the script.
        if let Some((defining, method)) = self.find_method_in(&class, &lower) {
            return self.method_reference(&defining, &method);
        }
        // A method of a class of the runtime.
        if let Some((spelled, min, max)) = crate::classes::the_method_of(&class, &lower) {
            return self.method_reference_of_a_class_type(&class, spelled, min, max);
        }
        // A method of the base object.
        if crate::classes::the_base_object_has_the_method(&lower) {
            let spelled = crate::classes::the_name_of_a_method_of_the_base_object(&lower);
            let (min, max) = crate::classes::the_arity_of("object", &lower).unwrap_or((0, 0));
            return self.method_reference_of_the_base_object(&spelled, &lower, min + 1, max + 1);
        }
        Value::Text(String::new())
    }

    /// The own properties of a class value.
    ///
    /// Measured on the binary of v2.0.19 on 2026-10-31: the class value of
    /// a class of the runtime owns the call of the class and the prototype,
    /// and the class value of a class of the script owns the initialiser of
    /// the class, the prototype and the static methods that the class
    /// declares.
    fn the_own_properties_of_a_class_value(&self, target: &Value) -> Vec<String> {
        let mut names: Vec<String> = Vec::new();
        let Some(class) = self.class_name_of(target) else {
            return names;
        };
        match self.classes.get(&class) {
            Some(definition) => {
                // A class of the script: the initialiser of it, the static
                // methods that it declares, and the classes that it holds.
                //
                // Measured on the binary of v2.0.19 on 2026-10-31: the own
                // properties of `Outer` are "__Init", "Inner" and
                // "Prototype".
                names.push("__Init".to_string());
                for method in definition.methods.values() {
                    if method.is_static {
                        names.push(method.name.clone());
                    }
                }
                for access in definition.accessors.values() {
                    if access.is_static {
                        names.push(access.name.clone());
                    }
                }
                for nested in &definition.nested {
                    names.push(self.the_name_of_a_class(nested));
                }
            }
            // A class of the runtime: the call of it, when the class is one
            // that a script calls.
            //
            // Measured on the binary of v2.0.19 on 2026-10-31: the class
            // value of the `Map` owns the call and the prototype, and the
            // class value of the `Error` owns the prototype alone.
            None => {
                if crate::classes::the_class_owns_the_call(&class) {
                    names.push("Call".to_string());
                }
            }
        }
        names.push("Prototype".to_string());
        names
    }

    /// The value of an own property of a class value.
    fn the_value_of_an_own_property_of_a_class_value(
        &self,
        target: &Value,
        name: &str,
        line: u32,
    ) -> Value {
        let lower = name.to_lowercase();
        match lower.as_str() {
            "call" => self
                .the_static_method(target, &[Value::Text(name.to_string())], line)
                .unwrap_or_else(|_| Value::Text(String::new())),
            "__init" => self.the_init_of_a_class_value(target),
            "prototype" => match target {
                Value::Object(object) => object
                    .borrow()
                    .value_of("prototype")
                    .unwrap_or_else(|| Value::Text(String::new())),
                _ => Value::Text(String::new()),
            },
            // A static method that the class declares, or a class that the
            // class holds.
            _ => {
                let Some(class) = self.class_name_of(target) else {
                    return Value::Text(String::new());
                };
                if let Some(value) = self.the_class_that_a_class_holds(target, name) {
                    return value;
                }
                match self.find_the_static_method_in(&class, &lower) {
                    Some((defining, method)) => self.static_method_reference(&defining, &method),
                    None => Value::Text(String::new()),
                }
            }
        }
    }

    /// The initialiser of a class, as a value.
    ///
    /// Measured on the binary of v2.0.19 on 2026-10-31: every class has an
    /// automatic initialiser, and it is a member of the class value. The
    /// name of it is "C.__Init" for a class of the script, and it is empty
    /// for a class of the runtime -- and the initialiser of a class of the
    /// runtime is a built-in, and the one of a class of the script is not.
    fn the_init_of_a_class_value(&self, target: &Value) -> Value {
        let mut properties: BTreeMap<String, Property> = BTreeMap::new();
        let mut name = String::new();
        let mut built_in = 1;
        if let Some(class) = self.class_name_of(target) {
            if let Some(definition) = self.classes.get(&class) {
                name = format!("{}.__Init", definition.name);
                built_in = 0;
            }
        }
        put(&mut properties, "name", Value::Text(name));
        // The first parameter of the reference is `this`.
        put(&mut properties, "minparams", Value::Int(1));
        put(&mut properties, "maxparams", Value::Int(1));
        put(&mut properties, "isbuiltin", Value::Int(built_in));
        put(&mut properties, "isvariadic", Value::Int(0));
        Value::Object(Rc::new(RefCell::new(Object {
            class: "func".to_string(),
            properties,
        })))
    }

    /// The value of a static method of a class of the script.
    ///
    /// A static method belongs to the class and not to its prototype, and
    /// the name of the value carries the class and the method.
    fn static_method_reference(&self, class: &str, method: &MethodDef) -> Value {
        let owner = self
            .classes
            .get(class)
            .map(|definition| definition.name.clone())
            .unwrap_or_else(|| class.to_string());
        let mut properties: BTreeMap<String, Property> = BTreeMap::new();
        put(
            &mut properties,
            "name",
            Value::Text(format!("{owner}.{}", method.name)),
        );
        // The first parameter of the reference is `this`.
        let required = method
            .parameters
            .iter()
            .filter(|parameter| parameter.default.is_none() && !parameter.variadic)
            .count();
        put(
            &mut properties,
            "minparams",
            Value::Int(required as i64 + 1),
        );
        put(
            &mut properties,
            "maxparams",
            Value::Int(method.parameters.len() as i64 + 1),
        );
        put(&mut properties, "isbuiltin", Value::Int(0));
        put(&mut properties, "isvariadic", Value::Int(0));
        // The class and the name of the method: the reference calls them.
        put(
            &mut properties,
            METHOD_CLASS,
            Value::Text(class.to_string()),
        );
        put(
            &mut properties,
            METHOD_NAME,
            Value::Text(method.name.clone()),
        );
        Value::Object(Rc::new(RefCell::new(Object {
            class: "func".to_string(),
            properties,
        })))
    }

    /// The reference of a static method of a class.
    ///
    /// The reference is the method, and the object is one of the
    /// arguments of the call.
    fn method_reference_of_the_base_object(
        &self,
        spelled: &str,
        method: &str,
        min: i64,
        max: i64,
    ) -> Value {
        let mut properties = BTreeMap::new();
        put(&mut properties, "name", Value::Text(spelled.to_string()));
        put(&mut properties, "minparams", Value::Int(min));
        put(&mut properties, "maxparams", Value::Int(max));
        put(&mut properties, "isbuiltin", Value::Int(1));
        put(&mut properties, "isvariadic", Value::Int(0));
        // The class and the name of the method: the reference calls them.
        put(
            &mut properties,
            METHOD_CLASS,
            Value::Text("object".to_string()),
        );
        put(
            &mut properties,
            METHOD_NAME,
            Value::Text(method.to_string()),
        );
        Value::Object(Rc::new(RefCell::new(Object {
            class: "func".to_string(),
            properties,
        })))
    }

    /// The copy of an object: the state of it is copied, and the class of
    /// it is the same.
    fn clone_of_an_object(&self, target: &Value) -> Value {
        let Value::Object(object) = target else {
            return target.clone();
        };
        let class = object.borrow().class.clone();
        let mut properties = BTreeMap::new();
        for (key, property) in object.borrow().properties.iter() {
            properties.insert(key.clone(), property.clone());
        }
        Value::Object(Rc::new(RefCell::new(Object { class, properties })))
    }

    /// The copy of a class: a class of its own, and not an object of it.
    ///
    /// Measured on the binary of v2.0.19 on 2026-10-31: the copy of a
    /// class is a class, and it is not the class it was copied from.
    fn clone_of_a_class(&self, target: &Value) -> Value {
        let Value::Object(object) = target else {
            return target.clone();
        };
        let class = object.borrow().class.clone();
        let mut properties = BTreeMap::new();
        for (key, property) in object.borrow().properties.iter() {
            properties.insert(key.clone(), property.clone());
        }
        let key = format!("{} copy {}", class, self.class_values.borrow().len());
        let copy = Value::Object(Rc::new(RefCell::new(Object { class, properties })));
        // The copy is a class too, and the tree keeps it in the list of
        // the classes it made: that is what tells a class from an
        // instance of one.
        self.class_values.borrow_mut().insert(key, copy.clone());
        copy
    }

    /// A method every object has.
    ///
    /// The methods of the base object are the same for every class: they
    /// ask about the object itself. The class of the script inherits them
    /// without writing them.
    pub(crate) fn base_method(
        &mut self,
        target: &Value,
        name: &str,
        arguments: &[Value],
        line: u32,
    ) -> Option<Result<Value, RuntimeFailure>> {
        let answer = self.the_base_method(target, name, arguments, line);
        // Measured on the binary of v2.0.19 on 2026-10-31: the failure of
        // a method of the base object carries the name of the method in
        // the `What`, the way v2 does.
        answer.map(|result| {
            result.map_err(|failure| {
                crate::classes::named(
                    failure,
                    &crate::classes::the_name_of_a_method_of_the_base_object(name),
                )
            })
        })
    }

    /// The methods of the object of the v1: the `Count()` and the `Length()`.
    ///
    /// Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-04: the
    /// `a.Count()` is the number of the members of the object -- the property
    /// "b" of the `{b: 1}` is one, the items of an array are members as
    /// well, and the places that are not there are not members. The
    /// `a.Length()` is the number of the items of the object: the `{b: 1}` is
    /// zero, and the `[1, 2]` is two.
    fn the_method_of_the_v1(
        &mut self,
        target: &Value,
        name: &str,
        _arguments: &[Value],
        _line: u32,
    ) -> Option<Result<Value, RuntimeFailure>> {
        match name.to_lowercase().as_str() {
            "count" => Some(Ok(Value::Int(self.the_members_of_the_v1(target) as i64))),
            "length" => Some(Ok(Value::Int(self.the_items_of_the_v1(target) as i64))),
            _ => None,
        }
    }

    /// The members of an object of the v1: the properties that it owns and
    /// the items of it.
    ///
    /// Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-04: the
    /// `{b: 1}` has one member, and the `[1, 2]` has two, and the `[1, 2]`
    /// with the property "b" has three.
    fn the_members_of_the_v1(&self, target: &Value) -> usize {
        let Value::Object(object) = target else {
            return 0;
        };
        let mut count = 0;
        for name in object.borrow().properties.keys() {
            // The names that the runtime owns are not members of the object.
            if name.as_str() == BASE
                || name.as_str() == CLASS_NAME
                || name.as_str() == "prototype"
                || name.as_str() == "array state"
            {
                continue;
            }
            count += 1;
        }
        count + crate::classes::array::the_number_of_the_items(target)
    }

    /// The items of an object of the v1.
    ///
    /// Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-04: the
    /// `{b: 1}` has no item, and the `[1, 2]` has two. The places that are
    /// not there are places: the `[1, 2]` with the fifth one written has
    /// five places.
    fn the_items_of_the_v1(&self, target: &Value) -> usize {
        crate::classes::array::the_number_of_the_places(target)
    }

    /// A method every object has, and the name of it is not in the
    /// failure.
    fn the_base_method(
        &mut self,
        target: &Value,
        name: &str,
        arguments: &[Value],
        line: u32,
    ) -> Option<Result<Value, RuntimeFailure>> {
        let Value::Object(object) = target else {
            return None;
        };
        // Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-04: the
        // object of the v1 has no method of the base object of the v2, and it
        // has the `Count()` and the `Length()`.
        if !self.dialect.the_object_has_the_methods_of_the_base_object() {
            return self.the_method_of_the_v1(target, name, arguments, line);
        }
        let class = object.borrow().class.clone();
        let method = name.to_string();
        let missing = || {
            RuntimeFailure::Error(RuntimeError {
                message: format!("{method} needs a name."),
                line,
            })
        };
        match name.to_lowercase().as_str() {
            "clone" => {
                // Measured on the binary of v2.0.19 on 2026-10-31: the
                // copy of an object is an object of the same class, and
                // the state of it is copied. The copy of the base object
                // refuses an object of a class of the runtime that has a
                // copy of its own: the type of the argument is not the
                // one that is wanted.
                //
                // The copy of a prototype is refused the same way: the
                // prototype is not an object that can be copied.
                if class == "prototype" {
                    return Some(Err(RuntimeFailure::Error(RuntimeError {
                        message: "Type mismatch.".to_string(),
                        line,
                    })));
                }
                if crate::classes::the_method_of(&class, "clone").is_some() {
                    return Some(Err(RuntimeFailure::Error(RuntimeError {
                        message: "Type mismatch.".to_string(),
                        line,
                    })));
                }
                Some(Ok(self.clone_of_an_object(target)))
            }
            "call" => {
                // The call of a class value makes an object of the class:
                // the static method of a class is the call of it.
                //
                // Measured on the binary of v2.0.19 on 2026-10-31.
                let class = self.class_name_of(target)?;
                Some(self.construct_with_values(&class, arguments, line))
            }
            "hasprop" => {
                let Some(name) = arguments.first().map(|value| value.to_text()) else {
                    return Some(Err(missing()));
                };
                let found = object.borrow().properties.contains_key(&name.to_lowercase())
                    || self.declares_an_instance_property(&class, &name)
                    // Every value carries its class, and the base object
                    // has the property of it.
                    || name.eq_ignore_ascii_case("__class")
                    // Every object has a base.
                    //
                    // Measured on the binary of v2.0.19 on 2026-10-31:
                    // `obj.HasProp("Base")` answers 1.
                    || name.eq_ignore_ascii_case("base")
                    // The methods of the class are the properties of the
                    // object, and a static method is not one of them.
                    //
                    // Measured on the binary of v2.0.19 on 2026-10-31:
                    // `obj.HasProp("Say")` answers 1 when `Say` is a method
                    // of the class, and 0 when it is a static one.
                    || self.find_the_instance_method_in(&class, &name).is_some()
                    || crate::classes::the_method_of(&class, &name).is_some()
                    // The properties that have a getter are the properties
                    // of the object.
                    || self.the_accessor_of(target, &name).is_some()
                    // Every class has an initialiser, and it is a member of
                    // the class.
                    || name.eq_ignore_ascii_case("__init")
                    || crate::classes::the_base_object_has_the_method(&name);
                // The prototype of a class has the properties of the class.
                //
                // Measured on the binary of v2.0.19 on 2026-10-31:
                // `Map.Prototype.HasProp("Count")` answers 1.
                let found = if let Some(class) = self.the_class_of_the_prototype(target) {
                    // The prototype of a class has the methods of the class
                    // and the ones of its base, and not the properties of
                    // the class.
                    //
                    // Measured on the binary of v2.0.19 on 2026-10-31:
                    // `Map.Prototype.HasProp("Count")` answers 1, and
                    // `C.Prototype.HasProp("value")` answers 0 when `value`
                    // is a variable of the class.
                    crate::classes::the_members_of_the_prototype(&class)
                        .iter()
                        .any(|member| member.to_lowercase() == name.to_lowercase())
                        || self.find_the_instance_method_in(&class, &name).is_some()
                        // The properties that have a getter are the members
                        // of the prototype.
                        || self.the_accessor_of(target, &name).is_some()
                        || name.eq_ignore_ascii_case("__init")
                        || name.eq_ignore_ascii_case("__class")
                } else if self.class_name_of(target).is_some() {
                    // A class value has the prototype, the base and the
                    // static methods, and every value carries its class.
                    // The properties of the class are not its own.
                    //
                    // Measured on the binary of v2.0.19 on 2026-10-31:
                    // `C.HasProp("__Init")` answers 1, and the initialiser
                    // is an own property of the class value.
                    self.the_own_properties_of_a_class_value(target)
                        .iter()
                        .any(|own| own.to_lowercase() == name.to_lowercase())
                        || object
                            .borrow()
                            .properties
                            .contains_key(&name.to_lowercase())
                        || name.eq_ignore_ascii_case("base")
                        || self
                            .the_static_methods_of_a_class_value(target)
                            .iter()
                            .any(|method| *method == name.to_lowercase())
                        || name.eq_ignore_ascii_case("__class")
                } else {
                    found
                };
                Some(Ok(Value::Int(found as i64)))
            }
            "hasmethod" => {
                let Some(name) = arguments.first().map(|value| value.to_text()) else {
                    // Measured on the binary of v2.0.19 on 2026-10-31: the
                    // question with no name asks whether the value is a
                    // class, and a class has the methods of the base
                    // object.
                    return Some(Ok(Value::Int(self.class_name_of(target).is_some() as i64)));
                };
                // The methods of the base object are the methods of every
                // object, and the methods of a class of the runtime are the
                // methods of its instances. A class has the methods of the
                // base object, and not the methods of the class it is.
                // The prototype of a class carries the methods of the class
                // it is the prototype of.
                let class = if class == "prototype" {
                    object
                        .borrow()
                        .value_of(CLASS_NAME)
                        .map(|name| name.to_text().to_lowercase())
                        .unwrap_or(class)
                } else {
                    class
                };
                let found = if self.class_name_of(target).is_some() {
                    // A class has the static methods, and the methods of its
                    // instances are not its own.
                    self.the_static_methods_of_a_class_value(target)
                        .contains(&name.to_lowercase())
                } else if let Some(class) = self.the_class_of_the_prototype(target) {
                    // The prototype of a class has the methods of the class
                    // and the ones of its base, and not the static ones.
                    //
                    // Measured on the binary of v2.0.19 on 2026-10-31:
                    // `C.Prototype.HasMethod("Say")` answers 1 when `Say` is
                    // a method of the class, and 0 when it is a static one.
                    self.find_the_instance_method_in(&class, &name).is_some()
                        || crate::classes::the_methods_of_the_prototype(&class)
                            .iter()
                            .any(|method| method.to_lowercase() == name.to_lowercase())
                        || crate::classes::the_base_object_has_the_method(&name)
                } else {
                    // A static method is not a member of an instance.
                    //
                    // Measured on the binary of v2.0.19 on 2026-10-31:
                    // `obj.HasMethod("Say")` answers 0 when `Say` is a
                    // static method of the class of the object.
                    self.find_the_instance_method_in(&class, &name).is_some()
                        || crate::classes::the_method_of(&class, &name).is_some()
                        || crate::classes::the_base_object_has_the_method(&name)
                };
                // Every class has an initialiser, and it is a method of the
                // class and of its instances.
                //
                // Measured on the binary of v2.0.19 on 2026-10-31:
                // `m.HasMethod("__Init")` answers 1, and so does
                // `C.HasMethod("__Init")`.
                let found = found || name.eq_ignore_ascii_case("__init");
                Some(Ok(Value::Int(found as i64)))
            }
            "getmethod" => {
                let Some(name) = arguments.first().map(|value| value.to_text()) else {
                    return Some(Err(missing()));
                };
                // The prototype of a class holds the methods of the class.
                //
                // Measured on the binary of v2.0.19 on 2026-10-31:
                // `Map.Prototype.GetMethod("Get")` is the method of the `Map`,
                // and `Object.Prototype.GetMethod("Clone")` is the method of
                // the base object.
                if let Some(class) = self.the_class_of_the_prototype(target) {
                    // A method of a class of the script. The static ones are
                    // not the methods of the prototype.
                    //
                    // Measured on the binary of v2.0.19 on 2026-10-31:
                    // `C.Prototype.GetMethod("Say")` is refused when `Say` is
                    // a static method of the class.
                    if let Some((defining, method)) =
                        self.find_the_instance_method_in(&class, &name)
                    {
                        return Some(Ok(self.method_reference(&defining, &method)));
                    }
                    // A method of a class type of the runtime.
                    if let Some((spelled, min, max)) = crate::classes::the_method_of(&class, &name)
                    {
                        let reference =
                            self.method_reference_of_a_class_type(&class, spelled, min, max);
                        return Some(Ok(reference));
                    }
                    // A method of the base object.
                    if crate::classes::the_base_object_has_the_method(&name) {
                        let spelled =
                            crate::classes::the_name_of_a_method_of_the_base_object(&name);
                        let (min, max) =
                            crate::classes::the_arity_of("object", &name).unwrap_or((0, 0));
                        let reference = self.method_reference_of_the_base_object(
                            &spelled,
                            &name,
                            min + 1,
                            max + 1,
                        );
                        return Some(Ok(reference));
                    }
                    return Some(Err(self.no_method(target, &name, line)));
                }
                // A method of a class of the script. A static method is
                // not a member of an instance.
                //
                // Measured on the binary of v2.0.19 on 2026-10-31:
                // `obj.GetMethod("Say")` is refused when `Say` is a static
                // method of the class.
                if let Some((defining, method)) = self.find_the_instance_method_in(&class, &name) {
                    return Some(Ok(self.method_reference(&defining, &method)));
                }
                // A method of a class type of the runtime.
                //
                // Measured on the binary of v2.0.19 on 2026-10-31:
                // `m.GetMethod("Get")` is the method of the `Map`.
                if let Some((spelled, min, max)) = crate::classes::the_method_of(&class, &name) {
                    let reference =
                        self.method_reference_of_a_class_type(&class, spelled, min, max);
                    return Some(Ok(reference));
                }
                // A method of the base object.
                //
                // Measured on the binary of v2.0.19 on 2026-10-31:
                // `o.GetMethod("Clone")` is the method of the base object.
                if crate::classes::the_base_object_has_the_method(&name) {
                    let spelled = crate::classes::the_name_of_a_method_of_the_base_object(&name);
                    let (min, max) =
                        crate::classes::the_arity_of("object", &name).unwrap_or((0, 0));
                    let reference =
                        self.method_reference_of_the_base_object(&spelled, &name, min + 1, max + 1);
                    return Some(Ok(reference));
                }
                Some(Err(self.no_method(target, &name, line)))
            }
            "hasbase" => {
                // Measured on the binary of v2.0.19 on 2026-10-31: the base
                // is an object, and the question is whether the base of the
                // object is it.
                let Some(base) = arguments.first() else {
                    return Some(Err(missing()));
                };
                let Value::Object(base) = base else {
                    return Some(Err(RuntimeFailure::Error(RuntimeError {
                        message: format!("Expected an object but got {}.", the_kind_of(base)),
                        line,
                    })));
                };
                // A class value is a class and not an instance of one: the
                // chain of a class is the chain of the classes that it
                // extends.
                //
                // Measured on the binary of v2.0.19 on 2026-10-31.
                if self.class_name_of(target).is_some() {
                    let chain = self.the_chain_of_the_class_bases(target);
                    return Some(Ok(Value::Int(chain.iter().any(|object| match object {
                        Value::Object(one) => Rc::ptr_eq(one, base),
                        _ => false,
                    }) as i64)));
                }
                let chain = self.the_chain_of_the_bases(target);
                Some(Ok(Value::Int(
                    chain.iter().any(|object| Rc::ptr_eq(object, base)) as i64,
                )))
            }
            "hasownprop" => {
                let Some(name) = arguments.first().map(|value| value.to_text()) else {
                    return Some(Err(missing()));
                };
                let lower = name.to_lowercase();
                // The prototype of a class owns the members of the class.
                //
                // Measured on the binary of v2.0.19 on 2026-10-31: the
                // prototype of a `Map` owns the class of the value and the
                // twelve members of the class.
                if let Some(class) = self.the_class_of_the_prototype(target) {
                    // The prototype of an `Any`, of a `ComObject` and of a
                    // `ComValue` is not a prototype: it has no method at all.
                    if crate::classes::the_prototype_is_not_one(&class) {
                        return Some(Err(RuntimeFailure::Detailed(
                            RuntimeError {
                                message: format!(
                                    "This value of type \"{}\" has no method named \"HasOwnProp\".",
                                    self.the_type_of(target)
                                ),
                                line,
                            },
                            Detail {
                                what: String::new(),
                                extra: String::new(),
                            },
                        )));
                    }
                    let own = self
                        .the_own_properties_of_a_prototype(target)
                        .iter()
                        .any(|name| name.to_lowercase() == lower);
                    return Some(Ok(Value::Int(own as i64)));
                }
                // The members of a function are not own properties of it:
                // they live on the prototype of the class of it.
                //
                // Measured on the binary of v2.0.19 on 2026-10-31: the own
                // properties of a function are none.
                let own = if object.borrow().class == "func" {
                    false
                } else if self.class_name_of(target).is_some() {
                    // The table of a class value is the tree's own, and the
                    // name of the class and the base and the prototype are
                    // not properties of it. The names that the script wrote
                    // are its own properties.
                    object.borrow().properties.contains_key(&lower)
                        && lower != CLASS_NAME
                        && lower != BASE
                        && lower != "prototype"
                } else {
                    object.borrow().properties.contains_key(&lower)
                };
                // The call of a class is its own property, and so are the
                // static methods that the class declares. The methods of
                // the base object are inherited, and not own.
                //
                // Measured on the binary of v2.0.19 on 2026-10-31.
                // A class value owns the members that v2 gives it, and the
                // methods of the base object are inherited, and not own.
                //
                // Measured on the binary of v2.0.19 on 2026-10-31.
                let own = own
                    || (self.class_name_of(target).is_some()
                        && self
                            .the_own_properties_of_a_class_value(target)
                            .iter()
                            .any(|name| name.to_lowercase() == lower));
                Some(Ok(Value::Int(own as i64)))
            }
            "ownprops" => {
                // Measured on the binary of v2.0.19 on 2026-10-31: the own
                // properties of v2 are an enumerator, and it gives the name
                // when the caller wants one value. The value of a property
                // that is a descriptor is the value of the property, and
                // not the descriptor.
                // The prototype of a class owns the members of the class.
                //
                // Measured on the binary of v2.0.19 on 2026-10-31: the
                // prototype of a `Map` owns the class of the value and the
                // twelve members of the class.
                if let Some(class) = self.the_class_of_the_prototype(target) {
                    // The prototype of an `Any`, of a `ComObject` and of a
                    // `ComValue` is not a prototype: it has no method at all.
                    if crate::classes::the_prototype_is_not_one(&class) {
                        return Some(Err(RuntimeFailure::Detailed(
                            RuntimeError {
                                message: format!(
                                    "This value of type \"{}\" has no method named \"OwnProps\".",
                                    self.the_type_of(target)
                                ),
                                line,
                            },
                            Detail {
                                what: String::new(),
                                extra: String::new(),
                            },
                        )));
                    }
                    let mut pairs: Vec<(Value, Value)> = Vec::new();
                    for name in self.the_own_properties_of_a_prototype(target) {
                        let value = self.the_value_of_an_own_property_of_a_prototype(target, &name);
                        pairs.push((Value::Text(name), value));
                    }
                    return Some(Ok(crate::classes::enumerator::make(
                        pairs,
                        crate::classes::enumerator::Alone::TheKey,
                    )));
                }
                // A class value owns the members that v2 gives it.
                //
                // Measured on the binary of v2.0.19 on 2026-10-31: the class
                // value of a class of the runtime owns the call of the class
                // and the prototype, and the class value of a class of the
                // script owns the initialiser of the class, the prototype
                // and the static methods that the class declares.
                if self.class_name_of(target).is_some() {
                    let mut pairs: Vec<(Value, Value)> = Vec::new();
                    for name in self.the_own_properties_of_a_class_value(target) {
                        let value =
                            self.the_value_of_an_own_property_of_a_class_value(target, &name, line);
                        pairs.push((Value::Text(name), value));
                    }
                    // The properties that the script wrote are own as well.
                    for (name, property) in object.borrow().properties.iter() {
                        if name.as_str() == BASE
                            || name.as_str() == CLASS_NAME
                            || name.as_str() == "prototype"
                        {
                            continue;
                        }
                        pairs.push((Value::Text(property.name.clone()), property.value.clone()));
                    }
                    // The names are in the order of v2, and the case of them
                    // does not count.
                    pairs.sort_by(|left, right| {
                        left.0
                            .to_text()
                            .to_lowercase()
                            .cmp(&right.0.to_text().to_lowercase())
                    });
                    return Some(Ok(crate::classes::enumerator::make(
                        pairs,
                        crate::classes::enumerator::Alone::TheKey,
                    )));
                }
                // The members of a function are not own properties of it:
                // they live on the prototype of the class of it.
                //
                // Measured on the binary of v2.0.19 on 2026-10-31: the own
                // properties of a function are none.
                if object.borrow().class == "func" {
                    return Some(Ok(crate::classes::enumerator::make(
                        Vec::new(),
                        crate::classes::enumerator::Alone::TheKey,
                    )));
                }
                // The names are the ones that the script wrote, and they
                // are in the order of v2: the case of them does not count.
                //
                // Measured on the binary of v2.0.19 on 2026-10-31: `o.X := 1`
                // gives the own property the name "X", and the first write
                // is the one that fixes the case of it.
                let mut own: Vec<(String, Value)> = object
                    .borrow()
                    .properties
                    .iter()
                    .filter(|(name, _)| name.as_str() != BASE && name.as_str() != CLASS_NAME)
                    .map(|(_, property)| (property.name.clone(), property.value.clone()))
                    .collect();
                own.sort_by_key(|(name, _)| name.to_lowercase());
                let mut pairs: Vec<(Value, Value)> = Vec::with_capacity(own.len());
                for (name, value) in own {
                    let value = match self.the_value_of_the_descriptor(&value, target, &name, line)
                    {
                        Ok(Some(value)) => value,
                        Ok(None) => value,
                        Err(_) => Value::Text(String::new()),
                    };
                    pairs.push((Value::Text(name), value));
                }
                Some(Ok(crate::classes::enumerator::make(
                    pairs,
                    crate::classes::enumerator::Alone::TheKey,
                )))
            }
            "defineprop" => {
                let Some(name) = arguments.first().map(|value| value.to_text()) else {
                    return Some(Err(missing()));
                };
                // Measured on the binary of v2.0.19 on 2026-10-31: the
                // second parameter is a descriptor, and a value that is
                // not one is refused with the reason.
                let descriptor = match self.the_descriptor(arguments.get(1), line) {
                    Ok(descriptor) => descriptor,
                    Err(failure) => return Some(Err(failure)),
                };
                put(&mut object.borrow_mut().properties, &name, descriptor);
                // The answer of v2 is the object itself.
                Some(Ok(target.clone()))
            }
            "deleteprop" => {
                let Some(name) = arguments.first().map(|value| value.to_text()) else {
                    return Some(Err(missing()));
                };
                let gone = object
                    .borrow_mut()
                    .properties
                    .remove(&name.to_lowercase())
                    .map(|property| property.value);
                // Measured on the binary of v2.0.19 on 2026-10-31: the
                // answer is the value of the property that is taken away,
                // and an empty text when there was none.
                Some(Ok(match gone {
                    None => Value::Text(String::new()),
                    Some(value) => {
                        match self.the_value_of_the_descriptor(&value, target, &name, line) {
                            Ok(Some(value)) => value,
                            _ => value,
                        }
                    }
                }))
            }
            "getownpropdesc" => {
                let Some(name) = arguments.first().map(|value| value.to_text()) else {
                    return Some(Err(missing()));
                };
                let key = name.to_lowercase();
                let value = object.borrow().value_of(&key);
                match value {
                    Some(value) => {
                        // Measured on the binary of v2.0.19 on 2026-10-31:
                        // the descriptor that comes back is an object with
                        // the members of it, and not a class of its own.
                        let table = match self.the_members_of_a_descriptor(&value) {
                            Some(members) => members,
                            None => {
                                let mut table = BTreeMap::new();
                                put(&mut table, "value", value);
                                table
                            }
                        };
                        Some(Ok(Value::Object(Rc::new(RefCell::new(Object {
                            class: "object".to_string(),
                            properties: table,
                        })))))
                    }
                    // The property is not there: v2 says so.
                    None => Some(Err(self.no_property(target, &name, line))),
                }
            }
            _ => None,
        }
    }

    /// The name of the type of a value, the way v2 writes it.
    ///
    /// An object is named after its class, and the other values after their
    /// kind: "Integer", "String", "Object".
    fn the_type_of(&self, value: &Value) -> String {
        // A class is a value of its own kind, and v2 names it "Class".
        if self.class_name_of(value).is_some() {
            return "Class".to_string();
        }
        match self.class_of(value) {
            Some(name) => name,
            None => value.the_kind(),
        }
    }

    /// The class of a value, the way v2 names it.
    ///
    /// Every value carries the class of it, and the `__Class` of the
    /// value is the name of that class: "Integer", "Float", "String",
    /// "Array", "VarRef", the name of the class of the script, and
    /// "Class" for a class itself. The prototype of a class is of the
    /// class it is the prototype of.
    fn the_class_of_the_value(&self, value: &Value) -> String {
        // Measured on the binary of v1.1.37.02 on 2026-11-02: the `__Class`
        // of the v1 is a property of an object: a value that is not an
        // object has none, and the answer is the empty text. A class of the
        // script is named after itself.
        if !self.dialect.every_value_carries_its_class() {
            return self.class_of(value).unwrap_or_default();
        }
        // A class is a value of its own kind, and v2 names it "Class".
        if self.class_name_of(value).is_some() {
            return "Class".to_string();
        }
        if let Value::Object(object) = value {
            if object.borrow().class == "prototype" {
                let name = object
                    .borrow()
                    .value_of(CLASS_NAME)
                    .map(|value| value.to_text())
                    .unwrap_or_default();
                return crate::classes::the_spelling_of(&name);
            }
        }
        match value {
            Value::Int(_) => "Integer".to_string(),
            Value::Float(_) => "Float".to_string(),
            Value::Text(_) => "String".to_string(),
            Value::List(_) => "Array".to_string(),
            Value::Reference(_) => "VarRef".to_string(),
            Value::Object(_) => self.the_type_of(value),
        }
    }

    /// The refusal of a property that a value does not have.
    pub(crate) fn no_property(&self, target: &Value, name: &str, line: u32) -> RuntimeFailure {
        let kind = self.the_type_of(target);
        // A class that this runtime does not carry is not refused with the
        // words of the dialect: the name is there, and the tree does not
        // carry it. A class value is a class of the dialect, and the
        // refusal of a member that is not there keeps the words of the
        // dialect.
        if self.class_name_of(target).is_none() {
            if let Some(reason) = crate::classes::the_reason_of_a_class_that_is_not_carried(&kind) {
                return RuntimeFailure::Error(RuntimeError {
                    message: reason.to_string(),
                    line,
                });
            }
        }
        RuntimeFailure::Error(RuntimeError {
            message: format!("This value of type \"{kind}\" has no property named {name:?}."),
            line,
        })
    }

    /// The message of the refusal of a property that a value does not have.
    ///
    /// Measured on the binary of v2.0.19 on 2026-10-31: v2 reads the
    /// property "Ptr" of the value that it writes, and an object has none:
    /// 'This value of type "Map" has no property named "Ptr".'.
    pub(crate) fn the_message_of_no_property(
        &self,
        target: &Value,
        name: &str,
        line: u32,
    ) -> String {
        match self.no_property(target, name, line) {
            RuntimeFailure::Error(error) => error.message,
            RuntimeFailure::Detailed(error, _) => error.message,
            _ => format!(
                "This value of type \"{}\" has no property named {name:?}.",
                self.the_type_of(target)
            ),
        }
    }

    /// The descriptor of a property, out of the value that was given.
    ///
    /// v2 wants an object with one or more of the members `Value`, `Get`,
    /// `Set` and `Call`, and refuses anything else with "Parameter #2 of
    /// Object.Prototype.DefineProp is invalid.". A descriptor that carries
    /// a value and an accessor at the same time is refused as well.
    pub(crate) fn the_descriptor(
        &self,
        value: Option<&Value>,
        line: u32,
    ) -> Result<Value, RuntimeFailure> {
        // Measured on the binary of v2.0.19 on 2026-10-31: the value that
        // is not a descriptor goes in the `Extra` of the failure.
        let invalid = || {
            RuntimeFailure::Detailed(
                RuntimeError {
                    message: "Parameter #2 of Object.Prototype.DefineProp is invalid.".into(),
                    line,
                },
                Detail {
                    what: String::new(),
                    extra: value.map(|value| value.to_text()).unwrap_or_default(),
                },
            )
        };
        let Some(Value::Object(object)) = value else {
            return Err(invalid());
        };
        let table = object.borrow();
        let mut members: BTreeMap<String, Property> = BTreeMap::new();
        for key in ["value", "get", "set", "call"] {
            if let Some(member) = table.properties.get(key) {
                members.insert(key.to_string(), member.clone());
            }
        }
        // A value and an accessor at the same time is not a descriptor.
        if members.is_empty() || (members.contains_key("value") && members.len() > 1) {
            return Err(invalid());
        }
        Ok(Value::Object(Rc::new(RefCell::new(Object {
            class: DESCRIPTOR.to_string(),
            properties: members,
        }))))
    }

    /// Whether a value is the descriptor of a property.
    fn is_a_descriptor(&self, value: &Value) -> bool {
        let Value::Object(object) = value else {
            return false;
        };
        object.borrow().class == DESCRIPTOR
    }

    /// The members of a descriptor, when the value is one.
    pub(crate) fn the_members_of_a_descriptor(
        &self,
        value: &Value,
    ) -> Option<BTreeMap<String, Property>> {
        if !self.is_a_descriptor(value) {
            return None;
        }
        let Value::Object(object) = value else {
            return None;
        };
        Some(object.borrow().properties.clone())
    }

    /// The value of a property that is a descriptor.
    ///
    /// v2 asks the getter of the descriptor for the value, and the value of
    /// the descriptor is the value of the property when there is no getter.
    /// A descriptor with no getter and no value is not a property that can
    /// be read: v2 says that the property is not there.
    pub(crate) fn the_value_of_the_descriptor(
        &mut self,
        value: &Value,
        target: &Value,
        written: &str,
        line: u32,
    ) -> Result<Option<Value>, RuntimeFailure> {
        if !self.is_a_descriptor(value) {
            return Ok(None);
        }
        let Value::Object(object) = value else {
            return Ok(None);
        };
        let getter = object.borrow().value_of("get");
        let held = object.borrow().value_of("value");
        if let Some(getter) = getter {
            // The getter is asked with the object as its first parameter.
            return Ok(Some(self.call_the_function(&getter, target, &[], line)?));
        }
        if let Some(held) = held {
            return Ok(Some(held));
        }
        Err(self.no_property(target, written, line))
    }

    /// The call of a property that is a descriptor.
    fn the_call_of_the_descriptor(&self, target: &Value, name: &str) -> Option<Value> {
        let Value::Object(object) = target else {
            return None;
        };
        let current = object.borrow().value_of(&name.to_lowercase())?;
        if !self.is_a_descriptor(&current) {
            return None;
        }
        let Value::Object(descriptor) = &current else {
            return None;
        };
        descriptor.borrow().value_of("call")
    }

    /// The value of a property that is called.
    ///
    /// v2 asks the getter of the descriptor for the value of the property,
    /// and calls it when it is a function. A property that is not a
    /// descriptor is not here: the class of the object answers for it.
    fn the_value_of_the_descriptor_for_a_call(
        &mut self,
        target: &Value,
        name: &str,
        line: u32,
    ) -> Result<Option<Value>, RuntimeFailure> {
        let Value::Object(object) = target else {
            return Ok(None);
        };
        let Some(current) = object.borrow().value_of(&name.to_lowercase()) else {
            return Ok(None);
        };
        if !self.is_a_descriptor(&current) {
            return Ok(None);
        }
        let Value::Object(descriptor) = &current else {
            return Ok(None);
        };
        let getter = descriptor.borrow().value_of("get");
        let Some(getter) = getter else {
            return Ok(None);
        };
        Ok(Some(self.call_the_function(&getter, target, &[], line)?))
    }

    /// Whether a value is a function of the script.
    fn is_a_function(&self, value: &Value) -> bool {
        let Value::Object(object) = value else {
            return false;
        };
        object.borrow().class == "func"
    }

    /// The write of a property that is a descriptor.
    ///
    /// v2 asks the setter of the descriptor for the write, and a
    /// descriptor that carries a value is written straight away. A
    /// descriptor with neither of them is read-only.
    fn the_write_of_the_descriptor(
        &mut self,
        descriptor: &Value,
        target: &Value,
        value: Value,
        written: &str,
        line: u32,
    ) -> Result<(), RuntimeFailure> {
        let Value::Object(object) = descriptor else {
            return Ok(());
        };
        let setter = object.borrow().value_of("set");
        if let Some(setter) = setter {
            // The setter is asked with the object and the value that is
            // written as its two first parameters.
            self.call_the_function(&setter, target, &[value], line)?;
            return Ok(());
        }
        let holds = object.borrow().properties.contains_key("value");
        if holds {
            object.borrow_mut().put("value", value);
            return Ok(());
        }
        Err(RuntimeFailure::Detailed(
            RuntimeError {
                message: "Property is read-only.".to_string(),
                line,
            },
            Detail {
                what: String::new(),
                extra: written.to_string(),
            },
        ))
    }

    /// The call of a function of the script, with the values of its
    /// arguments.
    ///
    /// The first argument of the call is the object the function belongs
    /// to: v2 asks the getter and the setter of a descriptor with it.
    fn call_the_function(
        &mut self,
        function: &Value,
        target: &Value,
        arguments: &[Value],
        line: u32,
    ) -> Result<Value, RuntimeFailure> {
        let mut values = Vec::with_capacity(arguments.len() + 1);
        values.push(target.clone());
        values.extend_from_slice(arguments);
        match crate::classes::func::call_the_value(function, &values, self, line) {
            Some(result) => result,
            None => Err(self.no_method(target, "Call", line)),
        }
    }

    /// The refusal of a method that a value does not have.
    pub(crate) fn no_method(&self, target: &Value, name: &str, line: u32) -> RuntimeFailure {
        let kind = self.the_type_of(target);
        // A class that this runtime does not carry is not refused with the
        // words of the dialect: the name is there, and the tree does not
        // carry it. A class value is a class of the dialect, and the
        // refusal of a member that is not there keeps the words of the
        // dialect.
        if self.class_name_of(target).is_none() {
            if let Some(reason) = crate::classes::the_reason_of_a_class_that_is_not_carried(&kind) {
                return RuntimeFailure::Error(RuntimeError {
                    message: reason.to_string(),
                    line,
                });
            }
        }
        RuntimeFailure::Error(RuntimeError {
            message: format!("This value of type \"{kind}\" has no method named {name:?}."),
            line,
        })
    }

    /// The refusal of an item that a value does not have.
    ///
    /// The item of a value is the `__Item` of it, and that is the name the
    /// refusal carries.
    fn no_item(&self, target: &Value, line: u32) -> RuntimeFailure {
        RuntimeFailure::Error(RuntimeError {
            message: format!(
                "This value of type \"{}\" has no property named \"__Item\".",
                self.the_type_of(target)
            ),
            line,
        })
    }

    /// The name of a method, the way v2 names it.
    ///
    /// The name of the class, the name of the prototype, and the name of
    /// the method.
    fn the_name_of_the_method(&self, class: &str, method: &MethodDef) -> String {
        let owner = self
            .classes
            .get(class)
            .map(|definition| definition.name.clone())
            .unwrap_or_else(|| class.to_string());
        format!("{owner}.Prototype.{}", method.name)
    }

    /// The value of a method of a class of the script.
    ///
    /// v2 hands a method over as a function whose first parameter is
    /// `this`: the reference is the method itself, and the object is one
    /// of the arguments of the call.
    fn method_reference(&self, class: &str, method: &MethodDef) -> Value {
        let mut properties: BTreeMap<String, Property> = BTreeMap::new();
        put(
            &mut properties,
            "name",
            Value::Text(self.the_name_of_the_method(class, method)),
        );
        // The first parameter of the reference is `this`.
        let required = method
            .parameters
            .iter()
            .filter(|parameter| parameter.default.is_none() && !parameter.variadic)
            .count();
        put(
            &mut properties,
            "minparams",
            Value::Int(required as i64 + 1),
        );
        put(
            &mut properties,
            "maxparams",
            Value::Int(method.parameters.len() as i64 + 1),
        );
        put(&mut properties, "isbuiltin", Value::Int(0));
        put(&mut properties, "isvariadic", Value::Int(0));
        // The class and the name of the method: the reference calls them.
        put(
            &mut properties,
            METHOD_CLASS,
            Value::Text(class.to_string()),
        );
        put(
            &mut properties,
            METHOD_NAME,
            Value::Text(method.name.clone()),
        );
        Value::Object(Rc::new(RefCell::new(Object {
            class: "func".to_string(),
            properties,
        })))
    }

    /// The value of a function that is bound to an object.
    ///
    /// Measured on the binary of AutoHotkey v2.0.19 on 2026-11-05: the
    /// `ObjBindMethod` hands over a value of the class `BoundFunc`, and the
    /// name of it is empty. The target is what the call of the value calls:
    /// the name of a method of the object, or the function that is bound.
    ///
    /// The v1 makes the binding too, and it does not check the name of the
    /// method: the `ObjBindMethod(t, "Nope")` is made, and the call of it
    /// fails.
    pub(crate) fn bound_function(&self, object: Value, target: Value) -> Value {
        let mut properties: BTreeMap<String, Property> = BTreeMap::new();
        put(&mut properties, "name", Value::Text(String::new()));
        put(&mut properties, "minparams", Value::Int(0));
        put(&mut properties, "maxparams", Value::Int(0));
        put(&mut properties, "isbuiltin", Value::Int(0));
        put(&mut properties, "isvariadic", Value::Int(0));
        // The object and the target: the call of the value calls them.
        put(&mut properties, BOUND, object);
        put(&mut properties, BOUND_TARGET, target);
        Value::Object(Rc::new(RefCell::new(Object {
            class: "boundfunc".to_string(),
            properties,
        })))
    }

    /// The reference to a method of a class type of the runtime.
    ///
    /// v2 hands a method over as a function whose first parameter is
    /// `this`: the reference is the method itself, and the object is one
    /// of the arguments of the call.
    pub(crate) fn method_reference_of_a_class_type(
        &self,
        class: &str,
        spelled: &str,
        min: i64,
        max: i64,
    ) -> Value {
        let mut properties = BTreeMap::new();
        let owner = crate::classes::the_spelling_of(class);
        put(
            &mut properties,
            "name",
            Value::Text(format!("{owner}.Prototype.{spelled}")),
        );
        put(&mut properties, "minparams", Value::Int(min));
        put(&mut properties, "maxparams", Value::Int(max));
        put(&mut properties, "isbuiltin", Value::Int(0));
        put(&mut properties, "isvariadic", Value::Int(0));
        // The class and the name of the method: the reference calls them.
        put(
            &mut properties,
            METHOD_CLASS,
            Value::Text(class.to_string()),
        );
        put(
            &mut properties,
            METHOD_NAME,
            Value::Text(spelled.to_string()),
        );
        Value::Object(Rc::new(RefCell::new(Object {
            class: "func".to_string(),
            properties,
        })))
    }

    /// A method of a class of the script, called through the reference to it.
    ///
    /// The reference is the method itself: the first argument of the
    /// call is `this`, and the rest are the arguments of the method.
    pub(crate) fn call_a_method_reference(
        &mut self,
        class: &str,
        method: &str,
        arguments: &[Value],
        line: u32,
    ) -> Result<Value, RuntimeFailure> {
        // A method of a class type of the runtime is answered by the
        // class that owns it, and not by the runtime.
        if crate::classes::is_type(class) {
            // The number of the arguments is checked here: the call goes
            // through a value, and the object is one of the arguments of
            // it.
            if let Some((min, max)) = crate::classes::the_arity_of(class, method) {
                let count = arguments.len() as i64;
                if count < min + 1 || (max >= 0 && count > max + 1) {
                    let message = if count < min + 1 {
                        "Too few parameters passed to function."
                    } else {
                        "Too many parameters passed to function."
                    };
                    return Err(crate::classes::the_arity_failure(
                        class, method, message, line,
                    ));
                }
            }
            let Some((this, rest)) = arguments.split_first() else {
                return Err(crate::classes::the_arity_failure(
                    class,
                    method,
                    "Too few parameters passed to function.",
                    line,
                ));
            };
            return match crate::classes::call(class, method, this, rest, self, line) {
                Some(result) => result,
                None => Err(self.no_method(this, method, line)),
            };
        }
        let Some((defining, definition)) = self.find_method_in(class, method) else {
            return Err(RuntimeFailure::Error(RuntimeError {
                message: format!("There is no method named {method:?} in this class."),
                line,
            }));
        };
        // The object is the first argument: the reference is the method,
        // and the method takes the object as `this`.
        let Some((this, rest)) = arguments.split_first() else {
            return Err(RuntimeFailure::Error(RuntimeError {
                message: "Missing a required parameter.".into(),
                line,
            }));
        };
        self.call_method_with(&defining, &definition, this, rest, line)
    }

    /// The call of a function that is bound to an object.
    ///
    /// Measured on the binary of AutoHotkey v2.0.19 on 2026-11-05: the
    /// object is the first argument of the call of the function that is
    /// bound, and the arguments of the call are the rest.
    pub(crate) fn call_a_bound_function(
        &mut self,
        bound: &Value,
        target: &Value,
        arguments: &[Value],
        line: u32,
    ) -> Result<Value, RuntimeFailure> {
        match target {
            // The name of a method of the object: the method is looked for
            // when the call runs, and the object is its `this`.
            Value::Text(method) => self.call_a_method_of_an_object(bound, method, arguments, line),
            // The function that is bound: the object is its first argument.
            _ => {
                let mut all = Vec::with_capacity(arguments.len() + 1);
                all.push(bound.clone());
                all.extend_from_slice(arguments);
                let class = match target {
                    Value::Object(object) => object.borrow().class.clone(),
                    _ => String::new(),
                };
                match crate::classes::call_the_value(&class, target, &all, self, line) {
                    Some(result) => result,
                    None => Err(self.no_method(bound, &target.to_text(), line)),
                }
            }
        }
    }

    /// The call of a method of an object.
    ///
    /// The method is looked for when the call runs: the `ObjBindMethod` does
    /// not check the name of it when it makes the value.
    pub(crate) fn call_a_method_of_an_object(
        &mut self,
        target: &Value,
        method: &str,
        arguments: &[Value],
        line: u32,
    ) -> Result<Value, RuntimeFailure> {
        // A method of a class of the script.
        if let Some((defining, definition)) = self.find_method_on(target, method) {
            return self.call_method_with(&defining, &definition, target, arguments, line);
        }
        // A method of a class type of the runtime.
        let class = match target {
            Value::Object(object) => object.borrow().class.clone(),
            _ => String::new(),
        };
        if crate::classes::is_type(&class) {
            if let Some((min, max)) = crate::classes::the_arity_of(&class, method) {
                let count = arguments.len() as i64;
                if count < min || (max >= 0 && count > max) {
                    let message = if count < min {
                        "Too few parameters passed to function."
                    } else {
                        "Too many parameters passed to function."
                    };
                    return Err(crate::classes::the_arity_failure(
                        &class, method, message, line,
                    ));
                }
            }
            return match crate::classes::call(&class, method, target, arguments, self, line) {
                Some(result) => result,
                None => Err(self.no_method(target, method, line)),
            };
        }
        // A method of the base object.
        if crate::classes::the_base_object_has_the_method(&method.to_lowercase()) {
            return match self.base_method(target, &method.to_lowercase(), arguments, line) {
                Some(result) => result,
                None => Err(self.no_method(target, method, line)),
            };
        }
        Err(self.no_method(target, method, line))
    }

    /// A property of a value.
    pub(crate) fn read_property(
        &mut self,
        target: &Value,
        name: &str,
        line: u32,
    ) -> Result<Value, RuntimeFailure> {
        self.read_property_with(target, name, &[], line)
    }

    /// A property of a value, with the parameters of the access.
    ///
    /// The parameters are the ones between the brackets of the access:
    /// `x.y[z]` asks the `__Get` of `x.y` with the index `z`.
    fn read_property_with(
        &mut self,
        target: &Value,
        name: &str,
        params: &[Value],
        line: u32,
    ) -> Result<Value, RuntimeFailure> {
        self.read_property_fully(target, name, params, line)
            .map(|(value, _)| value)
    }

    /// A property of a value, with the parameters of the access.
    ///
    /// The answer says whether a meta-function answered it: the
    /// meta-function of a class handles the whole access, and the
    /// brackets of the access are its parameters.
    fn read_property_fully(
        &mut self,
        target: &Value,
        name: &str,
        params: &[Value],
        line: u32,
    ) -> Result<(Value, bool), RuntimeFailure> {
        // The name is written as the script wrote it, and the lookup is in
        // lower case: the tree does not know the case of a property.
        let written = name.to_string();
        let name = name.to_lowercase();
        let Value::Object(object) = target else {
            // Every value carries its class, and the class of a value
            // that is not an object is the kind of it.
            if name == "__class" {
                return Ok((Value::Text(self.the_class_of_the_value(target)), false));
            }
            // Measured on the binary of v1.1.37.02 on 2026-11-02: the v1 does
            // not refuse the property of a value that is not an object, and
            // the answer is a blank text.
            if self.dialect.a_member_that_is_not_there_is_answered() {
                return Ok((Value::Text(String::new()), false));
            }
            return Err(self.no_property(target, &written, line));
        };
        let class = object.borrow().class.clone();
        // The prototype of a class holds the members of the class, and the
        // class that it is the prototype of is the one that answers for
        // them.
        //
        // Measured on the binary of v2.0.19 on 2026-10-31: `Map.Prototype.Get`
        // is the method of the `Map`, and `Map.Prototype.Count` is refused.
        let owner = self.the_class_of_the_prototype(target);
        let members = owner.clone().unwrap_or_else(|| class.clone());
        // A property of the class cannot be read on the prototype of it: the
        // value is not an instance of the class.
        //
        // Measured on the binary of v2.0.19 on 2026-10-31:
        // `Map.Prototype.Count` is refused with "Expected a Map but got a
        // Prototype.".
        if let Some(class) = &owner {
            let property = crate::classes::the_property_of_the_prototype(class, &name)
                .map(|spelled| spelled.to_string());
            if let Some(spelled) = property {
                return Err(RuntimeFailure::Detailed(
                    RuntimeError {
                        message: expected_the_class(
                            &self.the_spelling_of_the_class(class),
                            "Prototype",
                        ),
                        line,
                    },
                    Detail {
                        what: self.the_name_of_a_member(class, &format!("{spelled}.Get")),
                        extra: String::new(),
                    },
                ));
            }
        }
        // A class type of the runtime has properties of its own, and it
        // owns the whole of them. A class value is not an instance of its
        // class, and the properties of the class do not answer it.
        //
        // Measured on the binary of v2.0.19 on 2026-10-31: `Map.Count` is
        // refused with 'This value of type "Class" has no property named
        // "Count".'
        if self.class_name_of(target).is_none() {
            if let Some(result) = crate::classes::property(&class, &name, target, self, line) {
                return result.map(|value| (value, false));
            }
        }
        // A property of the class that has a getter: the read of it is the
        // value of the getter.
        //
        // Measured on the binary of v2.0.19 on 2026-10-31: `obj.value` is
        // the value of the getter of the property, and a property that has
        // no getter is not read.
        if let Some(value) = self.the_value_of_an_accessor(target, &written, line)? {
            return Ok((value, false));
        }
        if let Some(value) = object.borrow().value_of(&name) {
            // A property may be a descriptor: the getter of it is asked
            // for the value of the property.
            if let Some(answer) =
                self.the_value_of_the_descriptor(&value, target, &written, line)?
            {
                return Ok((answer, false));
            }
            return Ok((value, false));
        }
        // The static methods of a class are its own properties, and v2
        // hands them over as values.
        //
        // Measured on the binary of v2.0.19 on 2026-10-31: `Map.Call` is a
        // function whose name is "Map.Call".
        //
        // Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-02: the
        // class that a class holds is a member of the instance of it too:
        // the `o.D` is the class that C holds.
        if self.dialect.the_nested_class_is_a_member_of_the_instance() {
            if let Some(value) = self.the_class_that_the_v1_holds(target, &name) {
                return Ok((value, false));
            }
        }
        if self.class_name_of(target).is_some() {
            if let Some(value) = self.the_static_method_of_a_class_value(target, &name, line)? {
                return Ok((value, false));
            }
            // Every class has an initialiser, and it is a member of the
            // class value.
            //
            // Measured on the binary of v2.0.19 on 2026-10-31: `Map.__Init`
            // is a function whose name is empty, and `C.__Init` is one
            // whose name is "C.__Init".
            if name == "__init" {
                return Ok((self.the_init_of_a_class_value(target), false));
            }
            // The classes that a class holds are its own properties.
            //
            // Measured on the binary of v2.0.19 on 2026-10-31: `Outer.Inner`
            // is the class value of the class inside `Outer`.
            if let Some(value) = self.the_class_that_a_class_holds(target, &name) {
                return Ok((value, false));
            }
        }
        // The base of an object is a property of every object, and the
        // base of a class is a property of every class.
        //
        // Measured on the binary of v2.0.19 on 2026-10-31: the base of
        // an object is the prototype of its class, the base of a class
        // is the class that it extends, and the base of a prototype is
        // the prototype of the class that it extends.
        if name == "base" {
            if let Some(base) = self.the_base_of_the_value(target) {
                return Ok((base, false));
            }
        }
        // Every value carries its class.
        if name == "__class" {
            return Ok((Value::Text(self.the_class_of_the_value(target)), false));
        }
        // A method of the class is a value: v2 hands it over as a
        // function whose first parameter is `this`. A class is not an
        // instance, and its methods are not handed over.
        if self.class_name_of(target).is_none() {
            // A static method is not a member of an instance, and it is not
            // a member of the prototype of the class either.
            //
            // Measured on the binary of v2.0.19 on 2026-10-31: `obj.Say` is
            // refused with 'This value of type "C" has no property named
            // "Say".', and the prototype of the class refuses it the same
            // way.
            if let Some((defining, method)) = self.find_the_instance_method_in(&members, &name) {
                return Ok((self.method_reference(&defining, &method), false));
            }
            // A method of a class type of the runtime is a value too: v2
            // hands it over as a function whose first parameter is
            // `this`.
            if let Some((spelled, min, max)) = crate::classes::the_method_of(&members, &name) {
                let reference = self.method_reference_of_a_class_type(&members, spelled, min, max);
                return Ok((reference, false));
            }
            // A method of the base object is a value too, and every object
            // has it.
            //
            // Measured on the binary of v2.0.19 on 2026-10-31:
            // `o.Clone` is a function whose name is "Object.Prototype.Clone",
            // and `o.HasProp` is one whose name is "HasProp".
            if crate::classes::the_base_object_has_the_method(&name) {
                let spelled = crate::classes::the_name_of_a_method_of_the_base_object(&name);
                let (min, max) = crate::classes::the_arity_of("object", &name).unwrap_or((0, 0));
                let reference =
                    self.method_reference_of_the_base_object(&spelled, &name, min + 1, max + 1);
                return Ok((reference, false));
            }
        }
        // `__Get` is asked when the property is not there. It takes the
        // name of the property and the parameters of the access.
        if let Some((defining, method)) = self.find_the_instance_method_in(&class, "__get") {
            let params = self.the_params(params, line)?;
            let value = self.call_method_with(
                &defining,
                &method,
                target,
                &[Value::Text(written), params],
                line,
            )?;
            return Ok((value, true));
        }
        // Measured on the binary of v1.1.37.02 on 2026-11-02: the v1 does
        // not refuse the property that an object does not have, and the
        // answer is a blank text.
        if self.dialect.a_member_that_is_not_there_is_answered() {
            return Ok((Value::Text(String::new()), false));
        }
        Err(self.no_property(target, &written, line))
    }

    /// A property of a value that is written.
    fn write_property(
        &mut self,
        target: &Value,
        name: &str,
        value: Value,
        line: u32,
    ) -> Result<(), RuntimeFailure> {
        self.write_property_with(target, name, &[], value, line)
    }

    /// A property of a value that is written, with the parameters of the
    /// access.
    ///
    /// The parameters are the ones between the brackets of the access.
    fn write_property_with(
        &mut self,
        target: &Value,
        name: &str,
        params: &[Value],
        value: Value,
        line: u32,
    ) -> Result<(), RuntimeFailure> {
        let written = name.to_string();
        let name = name.to_lowercase();
        let Value::Object(object) = target else {
            // Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-04:
            // the v1 does not refuse the write of a property of a value that
            // is not an object: the `a.b := 5` is accepted when the `a` is
            // not an object, and the write is dropped.
            if self
                .dialect
                .the_write_of_a_property_of_a_value_that_is_not_an_object_is_dropped()
            {
                return Ok(());
            }
            // The class of a value that is not an object cannot be
            // written: v2 says that the property is read-only.
            if name == "__class" {
                return Err(RuntimeFailure::Detailed(
                    RuntimeError {
                        message: "Property is read-only.".to_string(),
                        line,
                    },
                    Detail {
                        what: String::new(),
                        extra: written,
                    },
                ));
            }
            return Err(self.no_property(target, &written, line));
        };
        let class = object.borrow().class.clone();
        // A class value is not an instance of its class: the properties of
        // the class do not answer it, and a property of the class value is
        // a property of the class value itself.
        //
        // Measured on the binary of v2.0.19 on 2026-10-31: `Map.Count` may
        // be written, and `Map.HasProp` may not.
        if self.class_name_of(target).is_some() {
            return self
                .write_the_property_of_a_class_value(target, &class, &name, &written, value, line);
        }
        // The base of an object is written the way the `ObjSetBase` built-in
        // writes it: the value has to be an object, and the base of an
        // object of a class type of the runtime cannot be written.
        //
        // Measured on the binary of v2.0.19 on 2026-10-31: `m.Base := 1` is
        // refused with "Expected an Object but got an Integer." and the
        // `What` "ObjSetBase".
        if name == "base" {
            if !matches!(value, Value::Object(_)) {
                return Err(RuntimeFailure::Detailed(
                    RuntimeError {
                        message: expected_type(TypeName::Object, value.type_name()),
                        line,
                    },
                    Detail {
                        what: "ObjSetBase".to_string(),
                        extra: value.to_text(),
                    },
                ));
            }
            let base = value.clone();
            return self.set_base_of(target, base, line).map_err(|error| {
                RuntimeFailure::Detailed(
                    error,
                    Detail {
                        what: "ObjSetBase".to_string(),
                        extra: String::new(),
                    },
                )
            });
        }
        // The members of the prototype of a class are read-only: the class
        // holds them, and the prototype is not the one that has them.
        //
        // Measured on the binary of v2.0.19 on 2026-10-31: `Map.Prototype.Count := 5`
        // is refused with "Property is read-only." and the name of the member
        // in the `Extra`. A name that the prototype does not own is written,
        // and it becomes an own property of the prototype.
        if let Some(class) = self.the_class_of_the_prototype(target) {
            if self.the_prototype_has_the_member(&class, &name) {
                return Err(RuntimeFailure::Detailed(
                    RuntimeError {
                        message: "Property is read-only.".to_string(),
                        line,
                    },
                    Detail {
                        what: String::new(),
                        extra: written.clone(),
                    },
                ));
            }
        }
        // A class type of the runtime owns the whole of its properties.
        //
        // Measured on the binary of v2.0.19 on 2026-10-31: the property that
        // the class owns and that may not be written is refused with
        // "Property is read-only.", the name of the property is in the
        // `Extra`, and the `What` is empty.
        if crate::classes::the_property_is_read_only(&class, &name) {
            return Err(RuntimeFailure::Detailed(
                RuntimeError {
                    message: "Property is read-only.".to_string(),
                    line,
                },
                Detail {
                    what: String::new(),
                    extra: written,
                },
            ));
        }
        if let Some(result) =
            crate::classes::set_property(&class, &name, target, value.clone(), self, line)
        {
            return result;
        }
        // A property of the class that has a setter: the write of it calls
        // the setter.
        //
        // Measured on the binary of v2.0.19 on 2026-10-31: a property that
        // has no setter is not written, and the write of it is refused with
        // "Property is read-only.".
        if self.the_write_of_an_accessor(target, &written, value.clone(), line)? {
            return Ok(());
        }
        // A property that is a descriptor has a setter of its own, and a
        // descriptor that carries a value is written straight away.
        if let Some(current) = object.borrow().value_of(&name) {
            if self.is_a_descriptor(&current) {
                return self.the_write_of_the_descriptor(&current, target, value, &written, line);
            }
        }
        // A property the class declares is written straight away. The
        // others are the ones `__Set` is asked about, and it is the one
        // that keeps the value: a class that writes a property of its
        // own inside `__Set` would otherwise call itself for ever.
        if !self.declares_property(&class, &name) {
            if let Some((defining, method)) = self.find_method_in(&class, "__set") {
                // `__Set` takes the name of the property, the parameters
                // of the access, and the value that is written.
                let params = self.the_params(params, line)?;
                self.call_method_with(
                    &defining,
                    &method,
                    target,
                    &[Value::Text(written), params, value],
                    line,
                )?;
                return Ok(());
            }
        }
        // The name of the property is the one that the script wrote.
        put(&mut object.borrow_mut().properties, &written, value);
        Ok(())
    }

    /// A property of a class value, written.
    ///
    /// Measured on the binary of v2.0.19 on 2026-10-31: the static methods
    /// of a class are read-only, the base of a class is written the way
    /// the `ObjSetBase` built-in writes it, and every other name is a
    /// property of the class value itself.
    fn write_the_property_of_a_class_value(
        &mut self,
        target: &Value,
        class: &str,
        name: &str,
        written: &str,
        value: Value,
        line: u32,
    ) -> Result<(), RuntimeFailure> {
        // The static methods of a class are read-only: `Map.HasProp` is a
        // method of the class and not of an instance of it.
        //
        // Measured on the binary of v2.0.19 on 2026-10-31: the write of a
        // static method of a class of the script is refused as well.
        if self
            .the_static_methods_of_a_class_value(target)
            .contains(&name.to_string())
        {
            return Err(RuntimeFailure::Detailed(
                RuntimeError {
                    message: "Property is read-only.".to_string(),
                    line,
                },
                Detail {
                    what: String::new(),
                    extra: written.to_string(),
                },
            ));
        }
        // The base of a class is written the way the `ObjSetBase` built-in
        // writes it: the value has to be an object.
        //
        // Measured on the binary of v2.0.19 on 2026-10-31: `c.Base := 1` is
        // refused with "Expected an Object but got an Integer." and the
        // `What` "ObjSetBase".
        if name == "base" {
            if !matches!(value, Value::Object(_)) {
                return Err(RuntimeFailure::Detailed(
                    RuntimeError {
                        message: expected_type(TypeName::Object, value.type_name()),
                        line,
                    },
                    Detail {
                        what: "ObjSetBase".to_string(),
                        extra: value.to_text(),
                    },
                ));
            }
            let base = value.clone();
            return self.set_base_of(target, base, line).map_err(|error| {
                RuntimeFailure::Detailed(
                    error,
                    Detail {
                        what: "ObjSetBase".to_string(),
                        extra: String::new(),
                    },
                )
            });
        }
        let Value::Object(object) = target else {
            return Err(self.no_property(target, written, line));
        };
        // A property of the class that has a setter: the write of it calls
        // the setter.
        //
        // Measured on the binary of v2.0.19 on 2026-10-31: the static
        // property of a class that has a setter is written through it.
        if self.the_write_of_an_accessor(target, written, value.clone(), line)? {
            return Ok(());
        }
        // A property that is a descriptor has a setter of its own, and a
        // descriptor that carries a value is written straight away.
        if let Some(current) = object.borrow().value_of(name) {
            if self.is_a_descriptor(&current) {
                return self.the_write_of_the_descriptor(&current, target, value, written, line);
            }
        }
        // A property the class declares is written straight away. The
        // others are the ones `__Set` is asked about.
        if !self.declares_property(class, name) {
            if let Some((defining, method)) = self.find_method_in(class, "__set") {
                let params = self.the_params(&[], line)?;
                self.call_method_with(
                    &defining,
                    &method,
                    target,
                    &[Value::Text(written.to_string()), params, value],
                    line,
                )?;
                return Ok(());
            }
        }
        // The name of the property is the one that the script wrote.
        put(&mut object.borrow_mut().properties, written, value);
        Ok(())
    }

    /// The parameters of an access, as an array.
    ///
    /// v2 hands them to the meta-functions as an array, and it is empty
    /// when the access has no parameters.
    fn the_params(&mut self, params: &[Value], line: u32) -> Result<Value, RuntimeFailure> {
        match crate::classes::construct("array", params, self, line) {
            Some(result) => result,
            None => Ok(Value::List(params.to_vec())),
        }
    }

    /// Whether a class declares a property.
    fn declares_property(&self, class: &str, name: &str) -> bool {
        let name = name.to_lowercase();
        self.class_chain(class).iter().any(|class| {
            self.classes
                .get(class)
                .map(|definition| {
                    definition
                        .properties
                        .iter()
                        .any(|property| property.name.to_lowercase() == name)
                })
                .unwrap_or(false)
        })
    }

    /// Whether the class declares a property of its instances.
    ///
    /// A static variable belongs to the class and not to its instances.
    ///
    /// Measured on the binary of v2.0.19 on 2026-10-31: `obj.HasProp("value")`
    /// answers 0 when `value` is a static variable of the class.
    fn declares_an_instance_property(&self, class: &str, name: &str) -> bool {
        let name = name.to_lowercase();
        self.class_chain(class).iter().any(|class| {
            self.classes
                .get(class)
                .map(|definition| {
                    definition
                        .properties
                        .iter()
                        .any(|property| !property.is_static && property.name.to_lowercase() == name)
                })
                .unwrap_or(false)
        })
    }

    /// The property of the class that has a getter or a setter.
    ///
    /// Measured on the binary of v2.0.19 on 2026-10-31: a class may
    /// declare a property with a getter and a setter, and the properties
    /// of the base are the ones of the instances too. A class value has the
    /// static properties of the class, and the properties of the instances
    /// are not its own.
    fn the_accessor_of(&self, target: &Value, name: &str) -> Option<AccessDef> {
        let lower = name.to_lowercase();
        let (class, is_static) = match self.class_name_of(target) {
            Some(class) => (class, true),
            None => {
                let class = match self.the_class_of_the_prototype(target) {
                    Some(class) => class,
                    None => match target {
                        Value::Object(object) => object.borrow().class.clone(),
                        _ => return None,
                    },
                };
                (class, false)
            }
        };
        for class in self.class_chain(&class) {
            let Some(definition) = self.classes.get(&class) else {
                continue;
            };
            let Some(access) = definition.accessors.get(&lower) else {
                continue;
            };
            if access.is_static == is_static {
                return Some(access.clone());
            }
        }
        None
    }

    /// The value of a property that has a getter.
    ///
    /// Measured on the binary of v2.0.19 on 2026-10-31: the read of the
    /// property is the value of the getter, and a property that has no
    /// getter is not read.
    fn the_value_of_an_accessor(
        &mut self,
        target: &Value,
        name: &str,
        line: u32,
    ) -> Result<Option<Value>, RuntimeFailure> {
        let Some(access) = self.the_accessor_of(target, name) else {
            return Ok(None);
        };
        let Some(getter) = &access.getter else {
            return Err(self.no_property(target, name, line));
        };
        let value = self.call_the_body_of_an_accessor(target, &access, getter, line, &[], None)?;
        Ok(Some(value))
    }

    /// The write of a property that has a setter.
    ///
    /// Measured on the binary of v2.0.19 on 2026-10-31: the write of the
    /// property calls the setter, and a property that has no setter is not
    /// written: the write is refused with "Property is read-only." and the
    /// name of the property is the `Extra`.
    fn the_write_of_an_accessor(
        &mut self,
        target: &Value,
        name: &str,
        value: Value,
        line: u32,
    ) -> Result<bool, RuntimeFailure> {
        let Some(access) = self.the_accessor_of(target, name) else {
            return Ok(false);
        };
        let Some(setter) = &access.setter else {
            return Err(RuntimeFailure::Detailed(
                RuntimeError {
                    message: "Property is read-only.".to_string(),
                    line,
                },
                Detail {
                    what: String::new(),
                    extra: name.to_string(),
                },
            ));
        };
        self.call_the_body_of_an_accessor(target, &access, setter, line, &[], Some(&value))?;
        Ok(true)
    }

    /// The body of a getter or of a setter, run on a value.
    ///
    /// The body runs as the body of a method: `this` is the value, and the
    /// parameters of the property are the ones of the method.
    fn call_the_body_of_an_accessor(
        &mut self,
        target: &Value,
        access: &AccessDef,
        body: &AccessBody,
        line: u32,
        given: &[Value],
        written: Option<&Value>,
    ) -> Result<Value, RuntimeFailure> {
        let mut parameters = access.parameters.clone();
        let mut values: Vec<Value> = given.to_vec();
        if let Some(written) = written {
            // The setter of v2 takes the value that is written after the
            // parameters of the property, and the name of it is "value".
            //
            // Measured on the binary of v2.0.19 on 2026-10-31: the setter of
            // the property writes with it: `set => this.stored := value`.
            parameters.push(Parameter {
                name: "value".to_string(),
                default: None,
                variadic: false,
                by_ref: false,
            });
            values.push(written.clone());
        }
        let method = MethodDef {
            name: access.name.clone(),
            parameters,
            body: body.body.clone(),
            declarations: body.declarations.clone(),
            is_static: access.is_static,
            line: access.line,
            body_line: body.line,
        };
        let class = match self.class_name_of(target) {
            Some(class) => class,
            None => match self.the_class_of_the_prototype(target) {
                Some(class) => class,
                None => match target {
                    Value::Object(object) => object.borrow().class.clone(),
                    _ => String::new(),
                },
            },
        };
        self.call_method_with(&class, &method, target, &values, line)
    }

    /// The name of a class, as the class that holds it writes it.
    ///
    /// The class inside `Outer` is "Outer.Inner", and the name of it as a
    /// property of `Outer` is "Inner".
    fn the_name_of_a_class(&self, class: &str) -> String {
        let name = self
            .classes
            .get(class)
            .map(|definition| definition.name.clone())
            .unwrap_or_else(|| class.to_string());
        name.rsplit('.').next().unwrap_or(&name).to_string()
    }

    /// The class that a value holds, as a value, the way the v1 reads it.
    ///
    /// Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-02: the
    /// `new` of the v1 reads the class that the value holds: the `new o.D`
    /// is an instance of the class that the instance of C holds, and the
    /// `new C.D` is an instance of the class that the class holds.
    fn the_class_that_the_v1_holds(&self, target: &Value, name: &str) -> Option<Value> {
        // The class of the value: a class carries its own name, and an
        // instance carries the class of it.
        let class = match self.class_name_of(target) {
            Some(class) => class,
            None => match target {
                Value::Object(object) => object.borrow().class.clone(),
                _ => return None,
            },
        };
        let definition = self.classes.get(&class)?;
        let lower = name.to_lowercase();
        for nested in &definition.nested {
            if self.the_name_of_a_class(nested).to_lowercase() == lower {
                return self.class_value_of(nested);
            }
        }
        None
    }

    /// The class that a class holds, as a value.
    ///
    /// Measured on the binary of v2.0.19 on 2026-10-31: the class inside
    /// `Outer` is an own property of the class value of `Outer`, and it is
    /// not a member of an instance of it.
    fn the_class_that_a_class_holds(&self, target: &Value, name: &str) -> Option<Value> {
        let class = self.class_name_of(target)?;
        let definition = self.classes.get(&class)?;
        let lower = name.to_lowercase();
        for nested in &definition.nested {
            if self.the_name_of_a_class(nested).to_lowercase() == lower {
                return self.class_value_of(nested);
            }
        }
        None
    }

    /// The argument of a loop, which has to be there.
    fn loop_argument(
        &mut self,
        arguments: &[Node],
        index: usize,
        line: u32,
    ) -> Result<Value, RuntimeFailure> {
        let node = arguments.get(index).ok_or_else(|| {
            RuntimeFailure::Error(RuntimeError {
                message: format!("the loop needs an argument {}.", index + 1),
                line,
            })
        })?;
        self.evaluate(node)
    }

    /// What a directive asks for, and whether this runtime can do it.
    ///
    /// A directive that names a thing this runtime does not have fails
    /// the script with the reason: a script that asks for a hotkey and
    /// is given none has been told a lie. A directive that asks for what
    /// is already the case is accepted.
    fn directive(
        &mut self,
        name: &str,
        argument: &str,
        line: u32,
    ) -> Result<String, RuntimeFailure> {
        match name {
            // There is no tray icon to hide, and the runner is one
            // process: both are already what the directive asks for.
            "notrayicon" => Ok("there is no tray icon to hide".into()),
            // Measured on the binary of v1.1.37.02 on 2026-11-01: the
            // directive `#NoEnv` turns the lookup of the environment off,
            // and the substitution of a parameter of the v1 is the variable
            // of the script alone.
            "noenv" => {
                self.no_env = true;
                Ok("the environment is not looked up".into())
            }
            // Measured on the binary of v1.1.37.02 on 2026-11-01: the
            // script of the v1 stays alive on its own, and the runner is one
            // process that stays alive on its own.
            "persistent" => Ok("the runner is one process".into()),
            "singleinstance" => Ok("the runner is one process".into()),
            // The errors are always in the report, and the report is
            // always on the standard output.
            "errorstdout" => Ok("the errors are in the report".into()),
            // Measured on the binary of AutoHotkey v2.0.19 on 2026-11-05: the
            // `#Warn` of the v2 takes the type of the warning and the mode of
            // it, and the warnings go to the report: the tree has no dialog.
            "warn" => Ok("the warnings are in the report".into()),
            "requires" => self.the_requires(argument, line),
            // The rest is what the table of the directives says: the reason
            // is the one of the category of the directive, and the table and
            // the run are the same truth.
            other => match refusal_of_directive(other) {
                Some(why) => Err(RuntimeFailure::Error(RuntimeError {
                    message: why.into(),
                    line,
                })),
                None => Err(RuntimeFailure::Error(RuntimeError {
                    message: format!("{other} is not a directive this runtime knows."),
                    line,
                })),
            },
        }
    }

    /// The `#Requires` directive: what the script says it needs to run.
    ///
    /// Measured on the binaries of both dialects: the argument names the
    /// interpreter and, when the script wants to be exact, the dialect it
    /// needs -- `v2` or `v1`. The name of the interpreter is compared without
    /// the case, and the dialect has to be the one this run speaks.
    ///
    /// An empty argument is refused with "Parameter #1 required", which is
    /// the wording of the binary, and a dialect the run does not speak is
    /// refused with the whole argument in the message and the dialect it is:
    /// "This script requires v1. This interpreter is v2.".
    ///
    /// # The line names the dialect and not the implementation
    ///
    /// The line is `#Requires v2`. It names the dialect, which is the fact a
    /// script actually depends on, and it needs no invented name for this
    /// tree: the project is called `ahk`, and a name made up for the directive
    /// would be a second name to keep in step with the first.
    ///
    /// The line still tells the two implementations apart, because mainline
    /// AutoHotkey reads the first word as the name of the interpreter:
    /// measured on the binary of v2.0.31, `#Requires v2` is refused with
    /// "This script requires v2. Current interpreter: AutoHotkey v2.0.31
    /// 64-bit.". A script that carries the line therefore runs here and not
    /// there.
    ///
    /// `#Requires AutoHotkey v2` is accepted as well, for a script that is
    /// meant to run in both: the mainline binary accepts that line too.
    fn the_requires(&self, argument: &str, line: u32) -> Result<String, RuntimeFailure> {
        let argument = argument.trim();
        if argument.is_empty() {
            return Err(RuntimeFailure::Error(RuntimeError {
                message: "Parameter #1 required".into(),
                line,
            }));
        }
        // Two forms: the dialect alone, and the name of the interpreter before
        // it. The name is the mainline one and nothing else -- there is no
        // second name of this tree to write here.
        let mut words = argument.split_whitespace();
        let first = words.next().unwrap_or("");
        let second = words.next();
        let spare = words.next();
        let meets = spare.is_none() && {
            match second {
                // `#Requires v2` and `#Requires v1`.
                None => first.eq_ignore_ascii_case(self.dialect.name())
                    // `#Requires AutoHotkey` asks for the interpreter and not
                    // for a dialect, and the mainline binary accepts it.
                    || first.eq_ignore_ascii_case("autohotkey"),
                // `#Requires AutoHotkey v2`, which runs in both.
                Some(dialect) => {
                    first.eq_ignore_ascii_case("autohotkey")
                        && dialect.eq_ignore_ascii_case(self.dialect.name())
                }
            }
        };
        if meets {
            return Ok(format!(
                "this runtime is the {} dialect, and it meets {argument}",
                self.dialect.name()
            ));
        }
        Err(RuntimeFailure::Error(RuntimeError {
            message: format!(
                "This script requires {argument}. This interpreter is {}.",
                self.dialect.name()
            ),
            line,
        }))
    }

    /// The result of an assignment: the value that is stored.
    ///
    /// The compound operators read what is there before they write, so a
    /// variable that has no value yet is an error and not a zero. The
    /// concat is the one that is not: it reads a variable that has no
    /// value as an empty text.
    fn apply_assign(
        &self,
        op: AssignOp,
        name: &str,
        current: Option<Value>,
        value: Value,
        line: u32,
    ) -> Result<Value, RuntimeFailure> {
        // Measured on the binary of v1.1.37.02 on 2026-11-02: the
        // operators that write a variable of the v1 read the value that is
        // there as a number when it can be one -- the "5" is 5, and the
        // "0x10" is 16 -- and the text that is not a number is the number
        // zero: the `x += 1` of the "abc" is 1.
        if self.dialect.a_value_that_is_not_a_number_is_blank()
            && !matches!(op, AssignOp::Set | AssignOp::Concat)
        {
            // Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-04:
            // the compound write of a variable that has no value makes the
            // variable: the `zz += 2` is the two, and the `zz -= 2` is the
            // minus two. The value that is not there is the empty text, and
            // the empty text is the number zero.
            let current = match current {
                Some(value) => value,
                None => Value::Text(String::new()),
            };
            return self.the_value_of_the_write_of_the_v1(op, &current, &value, line);
        }
        Ok(match op {
            AssignOp::Set => value,
            AssignOp::Add => {
                // Measured on the binary of v2.0.19 on 2026-10-31: the
                // dialect converts the value that is written before it
                // reads the one that is there, and the kind it names is
                // the kind of the value that was written.
                let written = self.number(&value, line)?;
                let current = self.assigned(name, current, line)?;
                let a = self.number(&current, line)?;
                match (&current, &value) {
                    (Value::Int(a), Value::Int(b)) => Value::Int(a + b),
                    _ => Value::Float(a + written),
                }
            }
            AssignOp::Subtract => {
                // Measured on the binary of v2.0.19 on 2026-10-31: the
                // dialect converts the value that is written before it
                // reads the one that is there, and the kind it names is
                // the kind of the value that was written.
                let written = self.number(&value, line)?;
                let current = self.assigned(name, current, line)?;
                let a = self.number(&current, line)?;
                match (&current, &value) {
                    (Value::Int(a), Value::Int(b)) => Value::Int(a - b),
                    _ => Value::Float(a - written),
                }
            }
            AssignOp::Multiply => {
                // Measured on the binary of v2.0.19 on 2026-10-31: the
                // dialect converts the value that is written before it
                // reads the one that is there, and the kind it names is
                // the kind of the value that was written.
                let written = self.number(&value, line)?;
                let current = self.assigned(name, current, line)?;
                let a = self.number(&current, line)?;
                match (&current, &value) {
                    (Value::Int(a), Value::Int(b)) => Value::Int(a * b),
                    _ => Value::Float(a * written),
                }
            }
            AssignOp::Divide => {
                // Measured on the binary of v2.0.19 on 2026-10-31: the
                // dialect converts the value that is written before it
                // reads the one that is there, and the kind it names is
                // the kind of the value that was written.
                let written = self.number(&value, line)?;
                let current = self.assigned(name, current, line)?;
                let a = self.number(&current, line)?;
                if written == 0.0 {
                    return Err(RuntimeFailure::Error(RuntimeError {
                        message: "Divide by zero.".into(),
                        line,
                    }));
                }
                Value::Float(a / written)
            }
            AssignOp::IntegerDivide => {
                // Measured on the binary of v2.0.19 on 2026-10-31: the
                // dialect converts the value that is written before it
                // reads the one that is there, and the kind it names is
                // the kind of the value that was written.
                let written = self.integer(&value, line)?;
                let current = self.assigned(name, current, line)?;
                let a = self.integer(&current, line)?;
                if written == 0 {
                    return Err(RuntimeFailure::Error(RuntimeError {
                        message: "Divide by zero.".into(),
                        line,
                    }));
                }
                Value::Int(a / written)
            }
            AssignOp::Concat => {
                // Measured on the binary of v2.0.19 on 2026-10-31: the
                // concat of a variable that has no value is the concat of
                // an empty text, and the write makes the variable. The
                // other operators want a value that is there, and a
                // variable that has no value is an error for them.
                let current = match current {
                    Some(value) => value,
                    None => Value::Text(String::new()),
                };
                Value::Text(format!("{}{}", current.to_text(), value.to_text()))
            }
            AssignOp::BitwiseAnd => {
                // Measured on the binary of v2.0.19 on 2026-10-31: the
                // dialect converts the value that is written before it
                // reads the one that is there, and the kind it names is
                // the kind of the value that was written.
                let written = self.integer(&value, line)?;
                let current = self.assigned(name, current, line)?;
                Value::Int(self.integer(&current, line)? & written)
            }
            AssignOp::BitwiseOr => {
                // Measured on the binary of v2.0.19 on 2026-10-31: the
                // dialect converts the value that is written before it
                // reads the one that is there, and the kind it names is
                // the kind of the value that was written.
                let written = self.integer(&value, line)?;
                let current = self.assigned(name, current, line)?;
                Value::Int(self.integer(&current, line)? | written)
            }
            AssignOp::BitwiseXor => {
                // Measured on the binary of v2.0.19 on 2026-10-31: the
                // dialect converts the value that is written before it
                // reads the one that is there, and the kind it names is
                // the kind of the value that was written.
                let written = self.integer(&value, line)?;
                let current = self.assigned(name, current, line)?;
                Value::Int(self.integer(&current, line)? ^ written)
            }
            AssignOp::ShiftLeft => {
                // Measured on the binary of v2.0.19 on 2026-10-31: the
                // dialect converts the value that is written before it
                // reads the one that is there, and the kind it names is
                // the kind of the value that was written.
                let written = self.shift(&value, line)?;
                let current = self.assigned(name, current, line)?;
                Value::Int(self.integer(&current, line)? << written)
            }
            AssignOp::ShiftRight => {
                // Measured on the binary of v2.0.19 on 2026-10-31: the
                // dialect converts the value that is written before it
                // reads the one that is there, and the kind it names is
                // the kind of the value that was written.
                let written = self.shift(&value, line)?;
                let current = self.assigned(name, current, line)?;
                Value::Int(self.integer(&current, line)? >> written)
            }
            AssignOp::ShiftRightUnsigned => {
                // Measured on the binary of v2.0.19 on 2026-10-31: the
                // dialect converts the value that is written before it
                // reads the one that is there, and the kind it names is
                // the kind of the value that was written.
                let written = self.shift(&value, line)?;
                let current = self.assigned(name, current, line)?;
                let left = self.integer(&current, line)? as u64;
                Value::Int((left >> written) as i64)
            }
        })
    }

    /// The value that an operator that writes a variable writes, the way
    /// the v1 does it.
    ///
    /// Measured on the binary of v1.1.37.02 on 2026-11-02: the values are
    /// numbers when they can be one -- the "5" is 5, and the "0x10" is 16
    /// -- and the text that is not a number is the number zero: the
    /// `x += 1` of the "abc" is 1. The whole numbers stay whole numbers,
    /// and the division of two whole numbers is a whole number: the
    /// `x /= 2` of the 5 is 2.
    fn the_value_of_the_write_of_the_v1(
        &self,
        op: AssignOp,
        current: &Value,
        value: &Value,
        line: u32,
    ) -> Result<Value, RuntimeFailure> {
        let a = self.the_number_of_a_value_of_the_v1(current);
        let b = self.the_number_of_a_value_of_the_v1(value);
        let one = a.to_number().unwrap_or(0.0);
        let other = b.to_number().unwrap_or(0.0);
        let whole = |one: &Value, other: &Value| match (one, other) {
            (Value::Int(one), Value::Int(other)) => Some((*one, *other)),
            _ => None,
        };
        Ok(match op {
            AssignOp::Add => match whole(&a, &b) {
                Some((one, other)) => Value::Int(one.wrapping_add(other)),
                None => Value::Float(one + other),
            },
            AssignOp::Subtract => match whole(&a, &b) {
                Some((one, other)) => Value::Int(one.wrapping_sub(other)),
                None => Value::Float(one - other),
            },
            AssignOp::Multiply => match whole(&a, &b) {
                Some((one, other)) => Value::Int(one.wrapping_mul(other)),
                None => Value::Float(one * other),
            },
            AssignOp::Divide => {
                if other == 0.0 {
                    // The division by zero of the v1 is a blank result and
                    // not a failure.
                    return Ok(Value::Text(String::new()));
                }
                match whole(&a, &b) {
                    Some((one, other)) => Value::Int(one.wrapping_div(other)),
                    None => Value::Float(one / other),
                }
            }
            AssignOp::IntegerDivide => {
                let other = self.the_whole_number_of_a_value_of_the_v1(&b);
                if other == 0 {
                    return Err(RuntimeFailure::Error(RuntimeError {
                        message: "Divide by zero.".into(),
                        line,
                    }));
                }
                Value::Int(
                    self.the_whole_number_of_a_value_of_the_v1(&a)
                        .wrapping_div(other),
                )
            }
            AssignOp::BitwiseAnd => Value::Int(
                self.the_whole_number_of_a_value_of_the_v1(&a)
                    & self.the_whole_number_of_a_value_of_the_v1(&b),
            ),
            AssignOp::BitwiseOr => Value::Int(
                self.the_whole_number_of_a_value_of_the_v1(&a)
                    | self.the_whole_number_of_a_value_of_the_v1(&b),
            ),
            AssignOp::BitwiseXor => Value::Int(
                self.the_whole_number_of_a_value_of_the_v1(&a)
                    ^ self.the_whole_number_of_a_value_of_the_v1(&b),
            ),
            AssignOp::ShiftLeft => Value::Int(
                self.the_whole_number_of_a_value_of_the_v1(&a)
                    .wrapping_shl(self.the_whole_number_of_a_value_of_the_v1(&b) as u32),
            ),
            AssignOp::ShiftRight => Value::Int(
                self.the_whole_number_of_a_value_of_the_v1(&a)
                    .wrapping_shr(self.the_whole_number_of_a_value_of_the_v1(&b) as u32),
            ),
            AssignOp::ShiftRightUnsigned => Value::Int(
                (self.the_whole_number_of_a_value_of_the_v1(&a) as u64
                    >> (self.the_whole_number_of_a_value_of_the_v1(&b) as u32 & 63))
                    as i64,
            ),
            AssignOp::Set | AssignOp::Concat => Value::Text(String::new()),
        })
    }

    /// The number of a value in the v1, for the operators that write.
    ///
    /// Measured on the binary of v1.1.37.02 on 2026-11-02: the value of the
    /// v1 is a number when it can be one -- the "5" is 5, and the "0x10" is
    /// 16 -- and the text that is not a number is the number zero.
    fn the_number_of_a_value_of_the_v1(&self, value: &Value) -> Value {
        match value {
            Value::Int(number) => Value::Int(*number),
            Value::Float(number) => Value::Float(*number),
            other => match crate::v1::the_number_of_a_text(&other.to_text()) {
                Some(number) => number,
                None => Value::Int(0),
            },
        }
    }

    /// Whether the value is a number in the v1.
    ///
    /// Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-04: the
    /// value of the v1 is a number when it can be one -- the "5" is 5 -- and
    /// the text that is not a number ("abc", "5abc" and the empty text) is
    /// not one at all.
    fn the_value_is_a_number_of_the_v1(&self, value: &Value) -> bool {
        match value {
            Value::Int(_) | Value::Float(_) => true,
            other => crate::v1::the_number_of_a_text(&other.to_text()).is_some(),
        }
    }

    /// The whole number of a value in the v1, for the operators that write.
    ///
    /// Measured on the binary of v1.1.37.02 on 2026-11-02: the value of the
    /// v1 is a number when it can be one -- the "5" is 5, and the "0x10" is
    /// 16 -- and the text that is not a number is the number zero.
    fn the_whole_number_of_a_value_of_the_v1(&self, value: &Value) -> i64 {
        match value {
            Value::Int(number) => *number,
            Value::Float(number) => *number as i64,
            other => {
                crate::v1::the_whole_number_at_the_start_of_a_text(&other.to_text()).unwrap_or(0)
            }
        }
    }

    /// The reason the short names of the files are not answered.
    ///
    /// Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-05: the
    /// `A_LoopFileShortName` is the name that Windows gives to a file that has
    /// a short one -- the "LONGNA~1.TXT" of a file that is called "long
    /// name.txt" -- and this box has none. The reason is there after a loop of
    /// the files has run: before it, the name has no value.
    fn the_reason_of_the_short_names_of_the_files(&self, name: &str) -> Option<&'static str> {
        if !self.the_short_names_of_the_files_are_refused {
            return None;
        }
        if name.eq_ignore_ascii_case("A_LoopFileShortName")
            || name.eq_ignore_ascii_case("A_LoopFileShortPath")
        {
            return Some(crate::variables::NO_SHORT_NAMES_OF_THE_FILES);
        }
        None
    }

    /// The value of a variable of the runtime, when it has none yet.
    ///
    /// Measured on the binary of v2.0.19 on 2026-10-31: the variables of
    /// the loops are there before the first loop runs: the index is zero
    /// and the others are empty.
    fn the_value_of_a_variable_of_the_runtime(&self, name: &str) -> Option<Value> {
        let rest = crate::variables::spelled(name)?;
        // Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-05: the
        // name of the function that runs is the name of it, and it is an
        // empty text when there is no function that runs.
        if rest == "thisfunc" {
            let name = self
                .frames
                .last()
                .map(|frame| frame.name.clone())
                .unwrap_or_default();
            return Some(Value::Text(name));
        }
        // Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-05: the
        // line of the statement that runs is the line of it, and the name has
        // no value before the first statement runs.
        if rest == "linenumber" {
            return Some(Value::Text(String::new()));
        }
        if !THE_LOOP_VARIABLES.contains(&rest.as_str()) {
            return None;
        }
        if rest == "index" {
            Some(Value::Int(0))
        } else {
            Some(Value::Text(String::new()))
        }
    }

    /// The value of the index of the turn, and the way to give it back.
    ///
    /// Measured on the binary of v2.0.19 on 2026-11-01: every loop saves the
    /// value of `A_Index` when it starts and gives it back when it ends, and
    /// a loop that is inside another one does not disturb the index of the
    /// outer one. A name that had no value before the loop has no value
    /// after it either.
    fn the_index_is_saved(&self) -> Option<Value> {
        self.variables.get(&the_key_of("A_Index")).cloned()
    }

    /// The index of the turn, given back the way it was.
    fn the_index_is_given_back(&mut self, saved: Option<Value>) {
        match saved {
            Some(value) => self.set_global("A_Index", value),
            None => {
                self.variables.remove(&the_key_of("A_Index"));
            }
        }
    }

    /// The value of the index of the turn, as a number.
    ///
    /// Measured on the binary of v2.0.19 on 2026-11-01: the index of a
    /// counted loop is the value of `A_Index`, and the body may write it:
    /// the loop goes on from the value that was written.
    fn the_index_of_the_turn(&self) -> i64 {
        self.variables
            .get(&the_key_of("A_Index"))
            .and_then(|value| value.to_number())
            .unwrap_or(0.0) as i64
    }

    /// The message v2 gives for a variable that has no value.
    ///
    /// v2 names the kind of the variable and not the name of it: a
    /// variable of the script and a variable of a function are told
    /// apart.
    pub(crate) fn the_unassigned(&self, name: &str) -> String {
        let key = the_key_of(name);
        // A name that lives in the scope of the script is a global one,
        // and a name that lives in the scope of the function is a local
        // one.
        let local = self.declarations.last().is_some() && !self.lives_in_the_script(&key);
        if local {
            "This local variable has not been assigned a value.".to_string()
        } else {
            "This global variable has not been assigned a value.".to_string()
        }
    }

    /// The item of a value, at a position.
    ///
    /// An object is asked for its item: the class of the script first,
    /// and then the class types of the runtime. The other values have no
    /// item, and v2 refuses the index of one.
    fn index_a_value(
        &mut self,
        target: &Value,
        key: &Value,
        line: u32,
    ) -> Result<Value, RuntimeFailure> {
        if let Value::Object(_) = target {
            return self.read_item(target, key, line);
        }
        let position = key.to_number().unwrap_or(0.0) as i64;
        // The positions count from one, the way AutoHotkey counts them.
        let position = position.max(1) as usize;
        match target {
            Value::List(items) => items.get(position - 1).cloned().ok_or_else(|| {
                RuntimeFailure::Error(RuntimeError {
                    message: "Invalid index.".into(),
                    line,
                })
            }),
            // A text has no item, and v2 refuses the index of one:
            // `SubStr` is the way to take a letter out.
            //
            // Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-04:
            // the v1 does not refuse the index of a value that is not an
            // object, and the answer is a blank text.
            _ => {
                if self.dialect.a_member_that_is_not_there_is_answered() {
                    return Ok(Value::Text(String::new()));
                }
                Err(self.no_item(target, line))
            }
        }
    }

    /// The failure of a variable that has no value.
    ///
    /// Measured on the binary of v2.0.19 on 2026-10-31: the name of the
    /// variable goes in the `Extra` of the error, and the `What` is empty.
    fn the_unassigned_failure(&self, name: &str, line: u32) -> RuntimeFailure {
        RuntimeFailure::Detailed(
            RuntimeError {
                message: self.the_unassigned(name),
                line,
            },
            Detail {
                what: String::new(),
                extra: name.to_string(),
            },
        )
    }

    /// The failure of a parameter that has no value.
    ///
    /// Measured on the binary of v2.0.19 on 2026-10-31: the name of the
    /// parameter is in the `Extra` of the failure, and the `What` is empty.
    fn the_missing_parameter(&self, name: &str, line: u32) -> RuntimeFailure {
        RuntimeFailure::Detailed(
            RuntimeError {
                message: "Missing a required parameter.".into(),
                line,
            },
            Detail {
                what: String::new(),
                extra: name.to_string(),
            },
        )
    }

    /// The value of a variable that has to be there.
    pub(crate) fn assigned(
        &self,
        name: &str,
        value: Option<Value>,
        line: u32,
    ) -> Result<Value, RuntimeFailure> {
        value.ok_or_else(|| self.the_unassigned_failure(name, line))
    }

    /// The value as a number, the way the maths operations want it.
    ///
    /// The message names the kind of the value that arrived, and the value
    /// itself goes in the `Extra` of the failure.
    pub(crate) fn number(&self, value: &Value, line: u32) -> Result<f64, RuntimeFailure> {
        value.to_number_strict().map_err(|_| {
            RuntimeFailure::Detailed(
                RuntimeError {
                    // The name of the kind is the one of v2, and an empty
                    // text has a name of its own.
                    message: expected_number(value),
                    line,
                },
                Detail {
                    what: String::new(),
                    extra: the_extra_of_the_value(value),
                },
            )
        })
    }

    /// The value as a whole number, the way the bitwise operations want it.
    ///
    /// The number comes first: a text that holds a number is a number. A
    /// number with a point is not a whole one, and v2 says so.
    pub(crate) fn integer(&self, value: &Value, line: u32) -> Result<i64, RuntimeFailure> {
        self.the_whole_number(value, line, TypeName::Integer)
    }

    /// The value as a whole number, and the name of the kind it wants.
    ///
    /// The bitwise operations want a whole number, and the bitwise not
    /// says that it wants a number: the message names the one that it says.
    fn the_whole_number(
        &self,
        value: &Value,
        line: u32,
        wants: TypeName,
    ) -> Result<i64, RuntimeFailure> {
        if let Value::Int(number) = value {
            return Ok(*number);
        }
        let number = self.number(value, line)?;
        if fract(number) != 0.0 {
            return Err(RuntimeFailure::Detailed(
                RuntimeError {
                    message: expected_the_kind(wants, &self.the_type_of(value)),
                    line,
                },
                Detail {
                    what: String::new(),
                    extra: the_extra_of_the_value(value),
                },
            ));
        }
        Ok(number as i64)
    }

    /// The place of an item, the way the index of an array wants it.
    ///
    /// v2 wants a number: a text that holds a number is a number, and a
    /// number with a point is taken as the whole one before it. A value
    /// that is not a number is not a place at all.
    pub(crate) fn the_place_of_an_item(&self, value: &Value) -> Option<i64> {
        value.to_number().map(|number| trunc(number) as i64)
    }

    /// The text of a value in a concatenation.
    ///
    /// v2 wants a text or a number: an object, an array and a function are
    /// refused, and the message names the kind of the value that arrived.
    ///
    /// Measured on the binary of v1.1.37.02 on 2026-11-02: the v1 does not
    /// refuse the object, and the text of it is the empty text -- the
    /// concatenation of an object and of "a" is "a".
    fn the_text_of_the_concat(&self, value: &Value, line: u32) -> Result<String, RuntimeFailure> {
        match value {
            Value::Text(text) => Ok(text.clone()),
            // The numbers of the v1 are formatted by the `SetFormat` when
            // they become a text.
            Value::Int(_) | Value::Float(_) => Ok(self.the_text_of(value)),
            Value::Object(_) if self.dialect.an_object_has_no_text() => Ok(String::new()),
            other => Err(RuntimeFailure::Detailed(
                RuntimeError {
                    message: expected_the_kind(TypeName::String, &self.the_type_of(other)),
                    line,
                },
                Detail {
                    what: String::new(),
                    extra: String::new(),
                },
            )),
        }
    }

    /// The number of a value in the v1, when it can be one.
    ///
    /// Measured on the binary of v1.1.37.02 on 2026-11-02: the text that is
    /// written between quotes is a string, and it is never a number. The
    /// value of a variable is a number when it can be one: "5" is 5, and
    /// "0x10" is 16, and " 5 " is 5.
    fn the_number_of_the_v1(&self, node: &Node, value: &Value) -> Option<Value> {
        match value {
            Value::Int(number) => Some(Value::Int(*number)),
            Value::Float(number) => Some(Value::Float(*number)),
            Value::Text(text) => {
                if self.the_node_is_a_quoted_text(node) {
                    return None;
                }
                crate::v1::the_number_of_a_text(text)
            }
            _ => None,
        }
    }

    /// Whether the node is a text that is written between quotes.
    ///
    /// Measured on the binary of v1.1.37.02 on 2026-11-02: the text that is
    /// written between quotes is a string, and the arithmetic of the v1
    /// never turns it into a number: `"5" + 1` is "51".
    fn the_node_is_a_quoted_text(&self, node: &Node) -> bool {
        matches!(
            node,
            Node::Literal {
                value: LiteralValue::Text(_),
                ..
            }
        )
    }

    /// The comparison of the v1.
    ///
    /// Measured on the binary of v1.1.37.02 on 2026-11-02: the comparison is
    /// a number when both sides are numbers, and a text otherwise: "abc" > 1
    /// is true, and "abc" < 1 is false. The sense of the case says whether
    /// the letters of the texts are the same.
    fn the_comparison_of_the_v1(
        &self,
        left_node: &Node,
        right_node: &Node,
        left: &Value,
        right: &Value,
        op: &BinaryOp,
    ) -> bool {
        let numbers = match (
            self.the_number_of_the_v1(left_node, left),
            self.the_number_of_the_v1(right_node, right),
        ) {
            (Some(left), Some(right)) => Some((
                left.to_number().unwrap_or(0.0),
                right.to_number().unwrap_or(0.0),
            )),
            _ => None,
        };
        self.the_order_of_the_v1(numbers, &left.to_text(), &right.to_text(), op)
    }

    /// The order of the v1: the numbers when both sides are numbers, and the
    /// texts otherwise.
    ///
    /// Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-02: the
    /// comparison is a number when both sides are numbers, and a text
    /// otherwise: "abc" > 1 is true, and "abc" < 1 is false. The sense of the
    /// case says whether the letters of the texts are the same.
    fn the_order_of_the_v1(
        &self,
        numbers: Option<(f64, f64)>,
        left: &str,
        right: &str,
        op: &BinaryOp,
    ) -> bool {
        match numbers {
            Some((left, right)) => match op {
                BinaryOp::Less => left < right,
                BinaryOp::Greater => left > right,
                BinaryOp::LessEqual => left <= right,
                BinaryOp::GreaterEqual => left >= right,
                _ => false,
            },
            // The texts are compared, and the sense of the case says whether
            // the letters of them are the same.
            None => {
                let order = the_order_of_the_texts(left, right, self.case_sense.the_method());
                match op {
                    BinaryOp::Less => order == core::cmp::Ordering::Less,
                    BinaryOp::Greater => order == core::cmp::Ordering::Greater,
                    BinaryOp::LessEqual => order != core::cmp::Ordering::Greater,
                    BinaryOp::GreaterEqual => order != core::cmp::Ordering::Less,
                    _ => false,
                }
            }
        }
    }

    /// The value of a variable of the v1 that has no value.
    ///
    /// Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-04: a
    /// variable of the v1 that has no value is blank, and the variable
    /// that is named "0" is the exception: it holds the text "0". The
    /// `if 0 = 0` is true because of it, and the `0 := 9` turns the
    /// `if 0 = 0` into a false condition.
    fn the_value_of_an_unset_variable(&self, name: &str) -> Value {
        if name == "0" {
            return Value::Text(String::from("0"));
        }
        Value::Text(String::new())
    }

    /// The comparison of the legacy `if` of the v1.
    ///
    /// Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-04:
    ///
    /// - The right side of the comparison is the text of the rest of the
    ///   line, and the text goes through the legacy substitution: the
    ///   `if x = %y%` compares the value of `x` with the value of `y`.
    /// - The `=` and the `!=` ignore the case, and they are a number when
    ///   both sides are numbers: the `if x = 1` is true when the value of
    ///   `x` is the number 1, and the `if x = 01` is true as well.
    /// - The order compares the numbers when both sides are numbers, and the
    ///   texts otherwise.
    ///
    /// The legacy `if` has no strict comparison: the `==` of the v2 is the
    /// `=` of the legacy `if`, and the second equal sign is a part of the
    /// text.
    fn the_comparison_of_a_legacy_if(
        &mut self,
        left: &Node,
        op: BinaryOp,
        text: &str,
        line: u32,
    ) -> Result<Value, RuntimeFailure> {
        let left_value = self.evaluate(left)?;
        // The text of the right side is the text of the script, and the
        // `%name%` of it is the value of the variable of that name.
        let right_text = self.the_substitution_of_the_v1(text, line)?;
        // The number of the right side: the text is a number when it can be
        // one, the way the value of a variable is.
        let right_number = crate::v1::the_number_of_a_text(&right_text);
        let left_number = self.the_number_of_the_v1(left, &left_value);
        let answer = match op {
            BinaryOp::Equal | BinaryOp::NotEqual => {
                // The equal sign of the legacy `if` follows the sense of the
                // case, and the not equal sign is its opposite.
                //
                // Measured on the binary of AutoHotkey v1.1.37.02 on
                // 2026-11-04: the equal sign of the legacy `if` is the
                // comparison of the sense of the case, and not the one of the
                // equal sign of an expression: the `if x = abc` is false when
                // the sense of the case is On and the value of `x` is "ABC".
                let method = self.case_sense.the_method();
                let same = match (left_number, right_number) {
                    (Some(one), Some(other)) => the_same_number(&one, &other),
                    _ => the_same_text(&left_value.to_text(), &right_text, method),
                };
                match op {
                    BinaryOp::Equal => same,
                    _ => !same,
                }
            }
            _ => {
                // The order of the v1.
                let numbers = match (left_number, right_number) {
                    (Some(one), Some(other)) => Some((
                        one.to_number().unwrap_or(0.0),
                        other.to_number().unwrap_or(0.0),
                    )),
                    _ => None,
                };
                self.the_order_of_the_v1(numbers, &left_value.to_text(), &right_text, &op)
            }
        };
        Ok(Value::Int(answer as i64))
    }

    /// The forms of the legacy `if` of the v1 that are not a comparison:
    /// the `between`, the `in` and the `contains`.
    ///
    /// Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-04:
    ///
    /// - The `between` compares the numbers when the value and the two
    ///   bounds are numbers, and the texts otherwise. The bounds are in
    ///   the range: the `if x between 1 and 3` holds when the value of
    ///   `x` is 1.
    /// - The `in` compares the text of the value with the text of the
    ///   item, and the comparison is always a comparison of texts: the
    ///   "11" does not match the item "11.0".
    /// - The `contains` asks whether the text of the value has the text
    ///   of the item in it.
    /// - The texts of the form go through the legacy substitution, and
    ///   the sense of the case says whether the letters of them are the
    ///   same.
    fn the_match_of_a_legacy_if(
        &mut self,
        left: &Node,
        form: LegacyForm,
        texts: &[String],
        negated: bool,
        line: u32,
    ) -> Result<Value, RuntimeFailure> {
        let left_value = self.evaluate(left)?;
        let text_of_the_value = left_value.to_text();
        // The texts of the form are the texts of the script, and the
        // `%name%` of them is the value of the variable of that name.
        let mut items = Vec::new();
        for text in texts {
            items.push(self.the_substitution_of_the_v1(text, line)?);
        }
        let holds = match form {
            LegacyForm::Between => {
                let low = items.first().map(String::as_str).unwrap_or_default();
                let high = items.get(1).map(String::as_str).unwrap_or_default();
                // The numbers when the value and the two bounds are
                // numbers, and the texts otherwise.
                let numbers = match (
                    self.the_number_of_the_v1(left, &left_value),
                    crate::v1::the_number_of_a_text(low),
                    crate::v1::the_number_of_a_text(high),
                ) {
                    (Some(value), Some(low), Some(high)) => Some((
                        value.to_number().unwrap_or(0.0),
                        low.to_number().unwrap_or(0.0),
                        high.to_number().unwrap_or(0.0),
                    )),
                    _ => None,
                };
                match numbers {
                    Some((value, low, high)) => value >= low && value <= high,
                    None => {
                        // The order of the texts, and the bounds are in
                        // the range.
                        let method = self.case_sense.the_method();
                        let at_the_low = the_order_of_the_texts(&text_of_the_value, low, method);
                        let at_the_high = the_order_of_the_texts(&text_of_the_value, high, method);
                        at_the_low != core::cmp::Ordering::Less
                            && at_the_high != core::cmp::Ordering::Greater
                    }
                }
            }
            LegacyForm::In => {
                // The comparison of the texts follows the sense of the case.
                let method = self.case_sense.the_method();
                items
                    .iter()
                    .any(|item| the_same_text(&text_of_the_value, item, method))
            }
            LegacyForm::Contains => {
                let method = self.case_sense.the_method();
                items
                    .iter()
                    .any(|item| the_text_contains(&text_of_the_value, item, method))
            }
        };
        Ok(Value::Int(if negated { !holds } else { holds } as i64))
    }

    /// The amount of a shift: a whole number between zero and sixty-three.
    fn shift(&self, value: &Value, line: u32) -> Result<u32, RuntimeFailure> {
        let count = self.integer(value, line)?;
        if !(0..64).contains(&count) {
            return Err(RuntimeFailure::Error(RuntimeError {
                message: "Invalid shift count.".into(),
                line,
            }));
        }
        Ok(count as u32)
    }

    /// `x++`, `x--`, `++x`, `--x`.
    ///
    /// The operator after the name answers the value the variable had
    /// before; the one before it answers the value it has now.
    fn increment(
        &mut self,
        op: UnaryOp,
        operand: &Node,
        line: u32,
    ) -> Result<Value, RuntimeFailure> {
        let step = match op {
            UnaryOp::PreIncrement | UnaryOp::PostIncrement => 1,
            _ => -1,
        };
        match operand {
            Node::Var { name, .. } => {
                // Measured on the binary of AutoHotkey v1.1.37.02 on
                // 2026-11-02: the v1 does not let a script write a built-in
                // variable, and the increment of one changes nothing: the
                // value is the empty text, and the built-in keeps the value
                // that it had.
                if self
                    .dialect
                    .the_increment_of_a_built_in_variable_changes_nothing(name)
                {
                    return Ok(Value::Text(String::new()));
                }
                let current = match self.lookup(name) {
                    Some(current) => current,
                    // Measured on the binary of AutoHotkey v1.1.37.02 on
                    // 2026-11-04: the increment of a variable of the v1 that
                    // has no value is the increment of the blank: the `0++`
                    // writes the variable "0" with the value 1.
                    None if self.dialect.unset_is_blank() => {
                        self.the_value_of_an_unset_variable(name)
                    }
                    None => return Err(self.the_unassigned_failure(name, line)),
                };
                let stored = self.the_number_after(&current, step, line)?;
                self.assign(name, stored.clone());
                Ok(match op {
                    UnaryOp::PreIncrement | UnaryOp::PreDecrement => stored,
                    _ => current,
                })
            }
            // Measured on the binary of v2.0.19 on 2026-10-31: the increment
            // of a property and of an item writes to them.
            Node::Property {
                target,
                name,
                line: property_line,
            } => {
                let target_value = self.evaluate(target)?;
                let name = self.the_name_of_the_member(name, *property_line)?;
                let current = self.read_property(&target_value, &name, *property_line)?;
                let stored = self.the_number_after(&current, step, *property_line)?;
                self.write_a_property(
                    target,
                    &name,
                    AssignOp::Set,
                    stored.clone(),
                    *property_line,
                )?;
                Ok(match op {
                    UnaryOp::PreIncrement | UnaryOp::PreDecrement => stored,
                    _ => current,
                })
            }
            Node::Index {
                target,
                index,
                line: item_line,
            } => {
                let target_value = self.evaluate(target)?;
                let key = self.evaluate(index)?;
                let current = self.index_a_value(&target_value, &key, *item_line)?;
                let stored = self.the_number_after(&current, step, *item_line)?;
                self.set_item(
                    &target_value,
                    &key,
                    AssignOp::Set,
                    stored.clone(),
                    *item_line,
                )?;
                Ok(match op {
                    UnaryOp::PreIncrement | UnaryOp::PreDecrement => stored,
                    _ => current,
                })
            }
            // Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-04:
            // the increment of a literal of the v1 is the empty text: the
            // `x := 5++` is a script that runs, and the value of the
            // expression is the empty text.
            Node::Literal { .. } if self.dialect.the_increment_of_a_literal_is_blank() => {
                Ok(Value::Text(String::new()))
            }
            _ => Err(RuntimeFailure::Error(RuntimeError {
                message: "the operator needs a variable to work on".into(),
                line,
            })),
        }
    }

    /// The value that comes after the increment of a value.
    fn the_number_after(
        &mut self,
        current: &Value,
        step: i64,
        line: u32,
    ) -> Result<Value, RuntimeFailure> {
        // Measured on the binary of v1.1.37.02 on 2026-11-02: the value of
        // the v1 is a number when it can be one -- the "5" is 5 -- and the
        // whole number stays a whole number: the `x++` of the "5" is 6.
        //
        // Measured on the binary of v1.1.37.02 on 2026-11-04: the increment
        // reads the value that is there as a number, the way the operators
        // that write a variable read it: the text that is not a number is the
        // number zero, and the `a++` of the "abc" is one, and the `a++` of a
        // variable that has no value is one too.
        if self.dialect.a_value_that_is_not_a_number_is_blank() {
            return Ok(match self.the_number_of_a_value_of_the_v1(current) {
                Value::Int(number) => Value::Int(number.wrapping_add(step)),
                Value::Float(number) => Value::Float(number + step as f64),
                other => other,
            });
        }
        Ok(match current {
            Value::Int(number) => Value::Int(number.wrapping_add(step)),
            other => Value::Float(self.number(other, line)? + step as f64),
        })
    }

    // -- calls ----------------------------------------------------------------------

    /// Call a function: the one the script defined, or one of the builtins.
    fn call(&mut self, name: &str, arguments: &[Node], line: u32) -> Result<Value, RuntimeFailure> {
        if let Some(function) = self.functions.get(name).cloned() {
            return self.call_function(&function, arguments, line, Route::Written);
        }
        // The name of a class makes an object. The class types of the
        // runtime are classes too: the script cannot extend one, but it
        // can make one.
        //
        // The v1 has no class types: the name `Func` of it is a function,
        // and not a class. Measured on the binary of v1.1.37.02 on
        // 2026-11-02.
        if self.classes.contains_key(&name.to_lowercase())
            || self.dialect.carries_the_class_of_the_runtime(name)
        {
            return self.construct(name, arguments, line);
        }
        // A method of a class of the script that is held in a variable
        // is called through the reference to it: the first argument of
        // the call is `this`.
        if let Some((class, method)) = self.method_reference_in_a_variable(name) {
            let values = self.evaluate_all(arguments)?;
            return self.call_a_method_reference(&class, &method, &values, line);
        }
        // A function that is held in a variable is called through it.
        if let Some(function) = self.function_in_a_variable(name) {
            return self.call_function(&function, arguments, line, Route::ThroughValue);
        }
        // Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-02: the
        // v1 takes the name of a built-in as the name of a variable, and the
        // call still goes to the built-in: `Abs := 5` and then `Abs(3)`
        // answers 3.
        if self.dialect.the_call_of_a_built_in_wins_over_the_variable()
            && self.builtin(name).is_some()
        {
            return self.call_a_builtin_by_name(name, arguments, line);
        }
        // The value of the name is what the call asks for: a variable of
        // the script, or a built-in variable of the dialect.
        let from_the_script = self.lookup_variable(name);
        let value = match from_the_script {
            Some(value) => Some(Ok(value)),
            None => self.the_built_in_variable(name),
        };
        // An object that is called is asked through its `Call` method:
        // v2 does not ask the `__Call` of the class when the object
        // itself is called.
        if let Some(value) = value {
            let value = value.map_err(|error| {
                RuntimeFailure::Error(RuntimeError {
                    message: error.message,
                    line,
                })
            })?;
            if let Value::Object(object) = &value {
                // A class is a value, and the call of it makes an object of
                // that class. Measured on the binary of v2.0.19 on 2026-10-31:
                // `c := Map; c()` makes a map, the way `Map()` does, and the
                // `Any` is refused because it is not a class that can be
                // made.
                if let Some(class) = self.class_name_of(&value) {
                    return self.construct(&class, arguments, line);
                }
                let class = object.borrow().class.clone();
                if let Some((defining, method)) = self.find_method_in(&class, "call") {
                    return self.call_method(&defining, &method, &value, arguments, line);
                }
                let values = self.evaluate_all(arguments)?;
                if let Some(result) =
                    crate::classes::call_the_value(&class, &value, &values, self, line)
                {
                    return result;
                }
                return Err(self.no_method(&value, "Call", line));
            }
            // Measured on the binary of v2.0.19 on 2026-10-31: a value that
            // is not an object cannot be called either, and v2 names the
            // kind of it: "This value of type "Integer" has no method named
            // "Call".". The failure is of the class `MethodError`.
            return Err(self.no_method(&value, "Call", line));
        }
        // The name is not a function of the script, not a class and not a
        // built-in: it is a variable of the script, and v2 reads it. A
        // variable that has no value is a variable that has no value.
        self.call_a_builtin_by_name(name, arguments, line)
    }

    /// The call of a built-in: the arguments are read, and the built-in
    /// answers.
    ///
    /// Measured on the binary of v2.0.19 on 2026-10-31: the number of the
    /// arguments is checked before the arguments are evaluated: v2 refuses
    /// the script when it loads, and the refusal of the arity comes before
    /// the failure of an argument.
    fn call_a_builtin_by_name(
        &mut self,
        name: &str,
        arguments: &[Node],
        line: u32,
    ) -> Result<Value, RuntimeFailure> {
        let Some(builtin) =
            self.the_builtin_of_the_kind(name, crate::builtins::BuiltinKind::Function)
        else {
            return Err(self.the_unassigned_failure(name, line));
        };
        // Measured on the binary of v2.0.19 on 2026-10-31: the number of the
        // arguments is checked before the arguments are evaluated: v2
        // refuses the script when it loads, and the refusal of the arity
        // comes before the failure of an argument.
        self.the_arity_of_a_builtin(builtin, arguments.len(), line, Route::Written)?;
        let mut values = Vec::with_capacity(arguments.len());
        // The v1 has functions that ask for the name of a variable and not
        // for its value: `IsSet(x)` asks whether the variable `x` has a
        // value. Measured on the binary of v1.1.37.02 on 2026-11-02.
        let wants_the_name = self
            .dialect
            .the_place_of_the_argument_that_wants_the_name(builtin.name);
        // The v1 has functions that ask for the variable itself: the
        // `VarSetCapacity(y, 100)` empties `y`, and the `StrReplace` of the
        // v1 writes the number of the replacements into the variable of its
        // fourth argument. Measured on the binary of v1.1.37.02 on
        // 2026-11-02. The argument that is not a variable is a value, and
        // the built-in has nowhere to write into.
        let wants_the_variable = self
            .dialect
            .the_place_of_the_argument_that_wants_the_variable(builtin.name);
        for (index, argument) in arguments.iter().enumerate() {
            if wants_the_variable == Some(index) {
                if let Node::Var { name, .. } = argument {
                    values.push(Value::Reference(Reference {
                        name: name.clone(),
                        scope: self.the_scope_of(name),
                        alias: true,
                    }));
                    continue;
                }
            }
            if wants_the_name == Some(index) {
                if let Node::Var { name, .. } = argument {
                    values.push(Value::Text(name.clone()));
                    continue;
                }
            }
            values.push(self.evaluate(argument)?);
        }
        self.call_builtin(name, &values, line, Route::Written)
    }

    /// The number of the arguments of the call of a built-in.
    ///
    /// Measured on the binary of v2.0.19 on 2026-10-29: the arity is in the
    /// table, so the check is the same for every built-in and it says what
    /// AutoHotkey says.
    fn the_arity_of_a_builtin(
        &self,
        builtin: &crate::builtins::Builtin,
        count: usize,
        line: u32,
        route: Route,
    ) -> Result<(), RuntimeFailure> {
        if count < builtin.min as usize {
            return Err(self.the_arity_failure(
                "Too few parameters passed to function.",
                builtin.name,
                route,
                line,
            ));
        }
        // The table says 255 when the built-in takes any number of them.
        if builtin.max < 255 && count > builtin.max as usize {
            return Err(self.the_arity_failure(
                "Too many parameters passed to function.",
                builtin.name,
                route,
                line,
            ));
        }
        Ok(())
    }

    /// Call a function the script defined.
    fn call_function(
        &mut self,
        function: &Function,
        arguments: &[Node],
        line: u32,
        route: Route,
    ) -> Result<Value, RuntimeFailure> {
        // Measured on the binary of v2.0.19 on 2026-10-31: the number of the
        // arguments is checked before the arguments are evaluated: v2
        // refuses the script when it loads, and the refusal of the arity
        // comes before the failure of an argument.
        self.the_arity_of_a_call(function, arguments.len(), line, route)?;
        let values = self.evaluate_all(arguments)?;
        // The parameters that the command does not give a value to are the
        // ones that are not there: the place of them is kept, and they have
        // no value.
        let missing: Vec<bool> = arguments
            .iter()
            .map(|argument| matches!(argument, Node::Empty { .. }))
            .collect();
        self.call_function_with(function, &values, line, route, &missing)
    }

    /// The number of the arguments of a call, checked the way v2 checks it.
    ///
    /// Measured on the binary of v2.0.19 on 2026-10-29: a call that the
    /// script wrote is checked when the script loads, and the failure names
    /// the function: "Too few parameters passed to function.\n     Specifically:
    /// Abs". A call that goes through a value is checked when the call runs,
    /// and it says so in other words: the name of the parameter that is
    /// missing goes in the `Extra`.
    fn the_arity_of_a_call(
        &self,
        function: &Function,
        count: usize,
        line: u32,
        route: Route,
    ) -> Result<(), RuntimeFailure> {
        // The arity of a function is in its definition: the parameters that
        // have no default are needed, and the ones that are there are the
        // most it takes unless one of them takes the rest.
        let needed = function
            .parameters
            .iter()
            .filter(|parameter| parameter.default.is_none() && !parameter.variadic)
            .count();
        if count < needed {
            // A call that the script wrote is checked when the script
            // loads, and the failure names the function. A call that
            // goes through a value is checked when the call runs, and
            // the failure names the parameter that is missing.
            if matches!(route, Route::Written) {
                return Err(self.the_arity_failure(
                    "Too few parameters passed to function.",
                    &function.name,
                    route,
                    line,
                ));
            }
            let missing = function
                .parameters
                .iter()
                .filter(|parameter| parameter.default.is_none() && !parameter.variadic)
                .nth(count)
                .map(|parameter| parameter.name.clone())
                .unwrap_or_default();
            return Err(self.the_missing_parameter(&missing, line));
        }
        let variadic = function
            .parameters
            .iter()
            .any(|parameter| parameter.variadic);
        if !variadic && count > function.parameters.len() {
            return Err(self.the_arity_failure(
                "Too many parameters passed to function.",
                &function.name,
                route,
                line,
            ));
        }
        Ok(())
    }

    /// The call of a function, with the values of the arguments already
    /// there: a function held in a variable is called with values.
    fn call_function_with(
        &mut self,
        function: &Function,
        values: &[Value],
        line: u32,
        route: Route,
        missing: &[bool],
    ) -> Result<Value, RuntimeFailure> {
        self.the_arity_of_a_call(function, values.len(), line, route)?;
        // Measured on the binary of v2.0.19 on 2026-10-31: a parameter that
        // the command does not give a value to is a missing one, and the
        // call is refused with "Missing a required parameter." -- the name
        // of the parameter is in the `Extra`. The number of the arguments
        // is checked before it.
        for (index, parameter) in function.parameters.iter().enumerate() {
            if missing.get(index).copied().unwrap_or(false)
                && parameter.default.is_none()
                && !parameter.variadic
            {
                return Err(self.the_missing_parameter(&parameter.name, line));
            }
        }
        let mut scope: BTreeMap<String, Value> = BTreeMap::new();
        for (index, parameter) in function.parameters.iter().enumerate() {
            let given = values.get(index);
            // A parameter that the command does not give a value to is a
            // missing one: the default of it is taken, and one that has no
            // default at all was refused above.
            let is_missing = missing.get(index).copied().unwrap_or(false);
            let value = match given {
                Some(value) if !is_missing => value.clone(),
                // A parameter that the call does not give a value to takes
                // its default, and one that has no default at all is empty.
                _ => match &parameter.default {
                    Some(default) => self.evaluate(default)?,
                    None => Value::Text(String::new()),
                },
            };
            // A parameter that the call does not give a value to is a local
            // one, even when it is written `&x`: the default of v2 is a
            // value of its own.
            if parameter.by_ref && given.is_some() && !is_missing {
                // The caller must pass a reference: the parameter is an
                // alias of the variable the reference points at.
                let Value::Reference(reference) = value else {
                    return Err(RuntimeFailure::Error(RuntimeError {
                        message: wants_a_reference(
                            index + 1,
                            &function.name,
                            "a variable reference",
                            &value,
                        ),
                        line,
                    }));
                };
                let mut alias = reference;
                alias.alias = true;
                scope.insert(the_key_of(&parameter.name), Value::Reference(alias));
                continue;
            }
            scope.insert(the_key_of(&parameter.name), value);
        }
        // The parameter that takes the rest of the arguments takes them as
        // an array, the way v2 has it.
        if let Some(index) = function
            .parameters
            .iter()
            .position(|parameter| parameter.variadic)
        {
            let rest: Vec<Value> = values.iter().skip(index).cloned().collect();
            let array = match crate::classes::construct("array", &rest, self, line) {
                Some(result) => result?,
                None => Value::List(rest),
            };
            scope.insert(the_key_of(&function.parameters[index].name), array);
        }
        self.enter_call(line)?;
        // A function that was written inside another one closes over the
        // scope of the one around it: the scopes go under the scope of the
        // call.
        for closed in &function.closure {
            self.scopes.push(closed.clone());
        }
        self.scopes.push(Rc::new(RefCell::new(scope)));
        // The functions that are written inside this one are there before
        // the body runs.
        self.collect_the_nested_functions(&function.body);
        self.declarations.push(function.declarations.clone());
        self.frames.push(Frame {
            name: function.name.clone(),
            line,
        });
        // The labels of the function are the scope of the function.
        self.label_scopes.push(the_labels_of(&function.body));
        let outcome = self.run_block(&function.body);
        self.label_scopes.pop();
        self.frames.pop();
        self.declarations.pop();
        self.scopes.pop();
        for _ in &function.closure {
            self.scopes.pop();
        }
        self.leave_call();
        match outcome {
            Ok(()) => Ok(Value::Text(String::new())),
            Err(RuntimeFailure::Flow(Flow::Return(value))) => {
                Ok(value.unwrap_or(Value::Text(String::new())))
            }
            // The jump of a `Goto` that leaves the function: the label is
            // not in the scope of the function.
            Err(RuntimeFailure::Flow(Flow::Goto { name, line })) => Err(RuntimeFailure::Fatal(
                self.the_label_is_not_there(&name, &function.body, line),
            )),
            Err(other) => Err(other),
        }
    }

    /// Keep a closure under a name of its own, and answer with the name.
    ///
    /// The name of a closure of v2 is empty, and the runtime keeps it under
    /// a name that a script cannot reach.
    fn make_a_closure(&mut self, function: Function) -> String {
        self.closures += 1;
        let name = format!("\u{1}closure {}", self.closures);
        self.functions.insert(name.to_lowercase(), function);
        name
    }

    /// Set a variable in the innermost scope, and not in the scope around
    /// it.
    ///
    /// The name of a function that is written inside another one is local
    /// to the function that has it.
    fn assign_in_the_scope(&mut self, name: &str, value: Value) {
        let name = the_key_of(name);
        match self.scopes.last() {
            Some(scope) => {
                scope.borrow_mut().insert(name, value);
            }
            None => {
                self.variables.insert(name, value);
            }
        }
    }

    /// The write of a variable, and the value that was written.
    ///
    /// A built-in variable that is not a variable of the script is written
    /// where it lives, and not in the table of the script: the clipboard is
    /// the one.
    fn write_a_variable(
        &mut self,
        name: &str,
        op: AssignOp,
        value: Value,
        line: u32,
    ) -> Result<Value, RuntimeFailure> {
        // Measured on the binary of v1.1.37.02 on 2026-11-02: the concat on a
        // built-in variable of the v1 is accepted, and the built-in keeps the
        // value that it had: the write goes nowhere. The rule is asked here,
        // because the settings of the run are written where they live, and
        // the settings of the v2 are built-in variables of the v1.
        if self
            .dialect
            .the_write_of_a_built_in_variable_goes_nowhere(name, op)
        {
            return Ok(value);
        }
        // A setting of the runtime is written where it lives: the setting
        // changes, and the compound operators read it before they write
        // it. The dialect writes the setting itself, and it is the tree
        // that keeps it.
        if let Some(spelled) = crate::variables::spelled(name) {
            if let Some(Ok(current)) = crate::settings::value_of(&spelled) {
                let stored = self.apply_assign(op, name, Some(current), value, line)?;
                let written = crate::settings::write_of(&spelled, &stored).ok_or_else(|| {
                    RuntimeFailure::Error(RuntimeError {
                        message: "the runtime keeps no such setting.".into(),
                        line,
                    })
                })?;
                return written
                    .map_err(|message| RuntimeFailure::Error(RuntimeError { message, line }));
            }
        }
        match self.the_write_of_the_built_in_variable(name, op, &value, line) {
            Some(written) => {
                // The reason of a write carries no line: the statement
                // that asked is the one that carries it.
                let stored = written.map_err(|mut error| {
                    if error.line == 0 {
                        error.line = line;
                    }
                    RuntimeFailure::Error(error)
                })?;
                Ok(stored)
            }
            None => {
                // The value that is there before the write: the variable
                // of the script, or the built-in variable of the same
                // name.
                let current = match self.lookup(name) {
                    Some(value) => Some(value),
                    None => match self.the_built_in_variable(name) {
                        Some(Ok(value)) => Some(value),
                        // A name that the runtime owns has a value before the
                        // first loop runs: the index of the turn is zero.
                        // Measured on the binary of v2.0.19 on 2026-11-01,
                        // the compound operator reads the value that is
                        // there, and it does not say that the variable has
                        // no value.
                        _ => self.the_value_of_a_variable_of_the_runtime(name),
                    },
                };
                // Measured on the binary of v2.0.19 on 2026-10-31: the name
                // of a class is a name of the script, and a local that has
                // that name may not hold the class or an instance of it.
                self.the_class_is_not_written(name, &value, line)?;
                let stored = self.apply_assign(op, name, current, value, line)?;
                // A built-in variable that the dialect lets a script write
                // is converted the way the dialect converts it: the value
                // that is written is the value the name keeps.
                let stored = match crate::variables::the_kind_of_the_write(name) {
                    Some(kind) => crate::variables::the_written_value(kind, &stored, line)
                        .map_err(RuntimeFailure::Error)?,
                    None => stored,
                };
                self.assign(name, stored.clone());
                Ok(stored)
            }
        }
    }

    /// The write of a property, and the value that was written.
    fn write_a_property(
        &mut self,
        target: &Node,
        name: &str,
        op: AssignOp,
        value: Value,
        line: u32,
    ) -> Result<Value, RuntimeFailure> {
        let target_value = self.evaluate(target)?;
        // Measured on the binary of v2.0.19 on 2026-10-31: the compound
        // operators read the property before they write it, and a property
        // that is not there is an error that names the property: the write
        // never happens, and the setter of the object is not called.
        let current = match op {
            AssignOp::Set => self.read_property(&target_value, name, line).ok(),
            _ => Some(self.read_property(&target_value, name, line)?),
        };
        // Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-04: the
        // v1 does not write the property when the value that is there is not
        // a number: the `a.b += 2` of the "abc" leaves the property as it
        // was.
        if self
            .dialect
            .the_compound_write_of_a_thing_that_is_not_a_number_is_dropped()
            && !matches!(op, AssignOp::Set | AssignOp::Concat)
        {
            if let Some(current) = &current {
                if !self.the_value_is_a_number_of_the_v1(current) {
                    return Ok(current.clone());
                }
            }
        }
        let stored = self.apply_assign(op, name, current, value, line)?;
        self.write_property(&target_value, name, stored.clone(), line)?;
        Ok(stored)
    }

    /// The recursion is a rail: a script that calls itself for ever stops
    /// here, and says so.
    ///
    /// There are two bounds. The depth is the one of v2: v2.0.19 stops at
    /// about 1105 nested calls, with "Function recursion limit exceeded."
    /// The stack is the other one: the frames of the tree are heavier than
    /// the ones of v2, and a host with a small stack would run out of it
    /// before the depth says so.
    fn enter_call(&mut self, line: u32) -> Result<(), RuntimeFailure> {
        if self.depth >= Self::MAX_DEPTH || self.stack_used() > self.stack_budget {
            return Err(RuntimeFailure::Error(RuntimeError {
                message: "Function recursion limit exceeded.".into(),
                line,
            }));
        }
        self.depth += 1;
        Ok(())
    }

    /// The call is over: the depth goes down.
    fn leave_call(&mut self) {
        self.depth = self.depth.saturating_sub(1);
    }

    /// How much stack the run has used since the runtime was made.
    fn stack_used(&self) -> usize {
        self.stack_base.abs_diff(Self::stack_here())
    }

    /// Where the stack is right now.
    ///
    /// The address of a local is the address of the stack: the marker is
    /// not read, and the compiler is told that it may not fold the address
    /// away.
    fn stack_here() -> usize {
        let marker = 0u8;
        core::hint::black_box(&marker) as *const u8 as usize
    }

    /// The call of a name, with the values of the arguments already
    /// there.
    ///
    /// The name may be a function of the script or a built-in.
    pub(crate) fn call_named(
        &mut self,
        name: &str,
        values: &[Value],
        line: u32,
        route: Route,
    ) -> Result<Value, RuntimeFailure> {
        // A function that is written inside another one is a variable of
        // the scope around it, and the call finds it there.
        if let Some(function) = self.function_in_a_variable(name) {
            return self.call_function_with(&function, values, line, route, &[]);
        }
        if let Some(function) = self.functions.get(&name.to_lowercase()).cloned() {
            return self.call_function_with(&function, values, line, route, &[]);
        }
        self.call_builtin(name, values, line, route)
    }

    /// The function a variable holds, if it holds one.
    fn function_in_a_variable(&self, name: &str) -> Option<Function> {
        let value = self.lookup_variable(name)?;
        let Value::Object(object) = &value else {
            return None;
        };
        let object = object.borrow();
        if object.class != "func" {
            return None;
        }
        // A closure is kept under a name of its own.
        if let Some(closure) = object.value_of(CLOSURE) {
            return self
                .functions
                .get(&closure.to_text().to_lowercase())
                .cloned();
        }
        let function_name = object.value_of("name")?.to_text().to_lowercase();
        self.functions.get(&function_name).cloned()
    }

    /// The method a variable holds, if it holds a reference to one.
    ///
    /// A reference to a method is a function whose first parameter is
    /// `this`: the class and the name of the method are what it carries.
    fn method_reference_in_a_variable(&self, name: &str) -> Option<(String, String)> {
        let value = self.lookup_variable(name)?;
        let Value::Object(object) = &value else {
            return None;
        };
        let object = object.borrow();
        if object.class != "func" {
            return None;
        }
        let class = object.value_of(METHOD_CLASS)?.to_text();
        let method = object.value_of(METHOD_NAME)?.to_text();
        Some((class, method))
    }

    /// The failure of a call that does not have the number of the
    /// arguments the function wants.
    ///
    /// A call that the script wrote is checked when the script loads,
    /// and the failure names the function: "Too few parameters passed
    /// to function.\n     Specifically: Abs". A call that goes through a
    /// value is checked when the call runs, and the failure is the one
    /// of the run: the name of the function goes in the `Extra`.
    pub(crate) fn the_arity_failure(
        &self,
        message: &str,
        name: &str,
        route: Route,
        line: u32,
    ) -> RuntimeFailure {
        match route {
            Route::Written => RuntimeFailure::Error(RuntimeError {
                message: format!("{message}\n     Specifically: {name}"),
                line,
            }),
            Route::ThroughValue => RuntimeFailure::Detailed(
                RuntimeError {
                    message: message.to_string(),
                    line,
                },
                Detail {
                    what: String::new(),
                    extra: name.to_string(),
                },
            ),
            Route::ThroughTheCall => RuntimeFailure::Detailed(
                RuntimeError {
                    message: message.to_string(),
                    line,
                },
                // The call went through the `Call` method of a value, and
                // v2 names that method in the `What`.
                Detail {
                    what: "Func.Prototype.Call".to_string(),
                    extra: name.to_string(),
                },
            ),
        }
    }

    /// The legacy command of the v1: `Msg, text`.
    ///
    /// The parameters of a command of the v1 are texts, and the shape of
    /// the command says what each one of them is: the value of an
    /// expression, the name of a variable of the script, or the name of
    /// the variable that the command writes into.
    ///
    /// Measured on the binary of v1.1.37.02 on 2026-11-01: `StringLen, n,
    /// hello` is five when `hello` is a variable of the script, and zero
    /// when it is not: the second parameter of that command is the *name*
    /// of a variable.
    pub(crate) fn the_legacy_command(
        &mut self,
        name: &str,
        parameters: &[crate::ast::LegacyParameter],
        line: u32,
    ) -> Result<Value, RuntimeFailure> {
        let Some(builtin) =
            self.the_builtin_of_the_kind(name, crate::builtins::BuiltinKind::Command)
        else {
            // The name is not a command of the dialect: the line holds no
            // action, and it is named.
            return Err(RuntimeFailure::Error(RuntimeError {
                message: format!(
                    "This line does not contain a recognized action.\n     Specifically: {name}"
                ),
                line,
            }));
        };
        let values = self.the_parameters_of_a_legacy_command(builtin, parameters, line)?;
        self.call_the_row(builtin, &values, line, Route::Written)
    }

    /// The values of the parameters of a command of the v1.
    ///
    /// The shape of the command says what the text of each one of them is.
    pub(crate) fn the_parameters_of_a_legacy_command(
        &mut self,
        builtin: &'static crate::builtins::Builtin,
        parameters: &[crate::ast::LegacyParameter],
        line: u32,
    ) -> Result<Vec<Value>, RuntimeFailure> {
        let mut values = Vec::with_capacity(parameters.len());
        for (index, parameter) in parameters.iter().enumerate() {
            values.push(self.the_parameter_of_a_legacy_command(builtin, index, parameter, line)?);
        }
        Ok(values)
    }

    /// The condition of a command of the v1 that has a body.
    ///
    /// The row of the command answers the condition, and the shape of the
    /// command says what the text of each parameter of it is.
    fn the_condition_of_a_legacy_if(
        &mut self,
        name: &str,
        parameters: &[String],
        line: u32,
    ) -> Result<bool, RuntimeFailure> {
        let Some(builtin) = self.builtin(name) else {
            return Ok(false);
        };
        // The command of the v1 that has a body takes texts: the haystack
        // and the needle are texts.
        let parameters: Vec<crate::ast::LegacyParameter> = parameters
            .iter()
            .map(|text| crate::ast::LegacyParameter::Text(text.clone()))
            .collect();
        let values = self.the_parameters_of_a_legacy_command(builtin, &parameters, line)?;
        let answer = self.call_the_row(builtin, &values, line, Route::Written)?;
        Ok(answer.truthy())
    }

    /// The value of a parameter of a command of the v1.
    ///
    /// The shape of the command says what the text of the parameter is.
    fn the_parameter_of_a_legacy_command(
        &mut self,
        builtin: &'static crate::builtins::Builtin,
        index: usize,
        parameter: &crate::ast::LegacyParameter,
        line: u32,
    ) -> Result<Value, RuntimeFailure> {
        match builtin.parameters.get(index) {
            // The name of a variable of the script: the command writes into
            // it, and the reference is the alias of that variable.
            Some(crate::builtins::Parameter::Output) => {
                let name = the_text_of_the_parameter(parameter);
                let scope = self.the_scope_of(&name);
                Ok(Value::Reference(Reference {
                    name,
                    scope,
                    alias: true,
                }))
            }
            // The name of a variable of the script: the value of it is the
            // parameter.
            Some(crate::builtins::Parameter::Variable) => {
                let name = the_text_of_the_parameter(parameter);
                match self.lookup(&name) {
                    Some(value) => Ok(value),
                    // Measured on the binary of v1.1.37.02 on 2026-11-01: a
                    // variable that has no value is blank, and it is not a
                    // failure.
                    None if self.dialect.unset_is_blank() => Ok(Value::Text(String::new())),
                    None => Err(self.the_unassigned_failure(&name, line)),
                }
            }
            // Measured on the binary of v1.1.37.02 on 2026-11-02: the
            // parameter that wants a number is an expression: the `Sleep,
            // 100+50` waits for a hundred and fifty milliseconds.
            _ => match parameter {
                crate::ast::LegacyParameter::Expression(node) => self.evaluate(node),
                // The text of the parameter, with the substitution of the v1.
                crate::ast::LegacyParameter::Text(text) => {
                    Ok(Value::Text(self.the_substitution_of_the_v1(text, line)?))
                }
            },
        }
    }

    /// The count of the loop.
    ///
    /// Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-04: the
    /// count of the `Loop` of the v1 is the text that the script wrote, with
    /// the substitution of the v1, and the loop is skipped when the text is
    /// not a number: the `loop n` is skipped.
    fn the_count_of_the_loop(&mut self, node: &Node, line: u32) -> Result<i64, RuntimeFailure> {
        if self.dialect.the_count_of_the_loop_is_a_number() {
            if let Node::Literal {
                value: crate::ast::LiteralValue::Text(text),
                ..
            } = node
            {
                let text = self.the_substitution_of_the_v1(text, line)?;
                return Ok(crate::v1::the_count_of_the_loop(&text));
            }
        }
        Ok(self.evaluate(node)?.to_number().unwrap_or(0.0) as i64)
    }

    /// The pattern of the files of the v1, when the loop is a loop of files.
    ///
    /// Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-05: the
    /// text of the first parameter of the `Loop` of the v1 is the count of the
    /// turns when it is a number and when it is the only parameter, and it is
    /// the pattern of the files when it is not. With more than one parameter,
    /// the v1 reads it always as the pattern: the `Loop, 3, *.txt` is a loop
    /// of the files that match the "3", and it has no turn.
    fn the_pattern_of_the_files_of_the_v1(
        &mut self,
        node: &Node,
        arguments: &[Node],
        line: u32,
    ) -> Result<Option<String>, RuntimeFailure> {
        let text = match node {
            Node::Literal {
                value: crate::ast::LiteralValue::Text(text),
                ..
            } => text,
            _ => return Ok(None),
        };
        let text = self
            .the_substitution_of_the_v1(text, line)?
            .trim()
            .to_string();
        if arguments.len() == 1 && crate::v1::the_text_is_the_count_of_a_loop(&text) {
            return Ok(None);
        }
        Ok(Some(text))
    }

    /// The mode of the loop of the files of the v1.
    ///
    /// Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-05: the mode
    /// is a number, and the v1 refuses the one that is not a zero, a one or a
    /// two when the script loads. The text that carries the name of a variable
    /// is read when the loop runs, and the value that is not one of the three
    /// is a failure then.
    fn the_mode_of_the_loop_of_the_files_of_the_v1(
        &mut self,
        arguments: &[Node],
        line: u32,
    ) -> Result<u8, RuntimeFailure> {
        let Some(node) = arguments.get(1) else {
            return Ok(crate::v1::THE_FILES);
        };
        let text = self.the_text_of_the_parameter_of_the_loop(node, line)?;
        match crate::v1::the_mode_of_the_loop_of_the_files(&text) {
            Some(mode) => Ok(mode),
            None => Err(RuntimeFailure::Error(RuntimeError {
                message: format!("Parameter #2 invalid.\n     Specifically: {}", text.trim()),
                line,
            })),
        }
    }

    /// The flag of the recursion of the loop of the files of the v1.
    ///
    /// Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-05: the flag
    /// is a zero or a one, and the one asks for the folders of the files. The
    /// value that is not a zero or a one is not a failure when the loop runs:
    /// the loop does not walk into the folders.
    fn the_flag_of_the_recursion_of_the_v1(
        &mut self,
        arguments: &[Node],
        line: u32,
    ) -> Result<bool, RuntimeFailure> {
        let Some(node) = arguments.get(2) else {
            return Ok(false);
        };
        let text = self.the_text_of_the_parameter_of_the_loop(node, line)?;
        Ok(crate::v1::the_flag_asks_for_the_recursion(&text))
    }

    /// The text of a parameter of the loop of the v1.
    ///
    /// The parameters of the loop of the v1 are texts, and the text of them is
    /// read with the substitution of the v1.
    fn the_text_of_the_parameter_of_the_loop(
        &mut self,
        node: &Node,
        line: u32,
    ) -> Result<String, RuntimeFailure> {
        match node {
            Node::Literal {
                value: crate::ast::LiteralValue::Text(text),
                ..
            } => Ok(self.the_substitution_of_the_v1(text, line)?),
            _ => Ok(self.evaluate(node)?.to_text()),
        }
    }

    /// The loop of the files of the v1.
    ///
    /// Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-05: the
    /// `Loop` of the v1 walks over the files that match the pattern, and it
    /// gives the name of the file, its extension, the folder it is in and the
    /// path of it to the script. The name keeps its extension, and the path is
    /// the one that is relative to the folder the script runs in.
    fn the_loop_of_the_files_of_the_v1(
        &mut self,
        pattern: &str,
        arguments: &[Node],
        body: &[Node],
        until: &Option<Box<Node>>,
        line: u32,
    ) -> Result<(), RuntimeFailure> {
        let mode = self.the_mode_of_the_loop_of_the_files_of_the_v1(arguments, line)?;
        let recurse = self.the_flag_of_the_recursion_of_the_v1(arguments, line)?;
        // The mode of the desktop is the one of the v2: the "R" walks into the
        // folders, the "D" gives the folders alone, and the "A" gives the
        // files and the folders.
        //
        // Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-05: the
        // flag of the recursion walks into the folders when the mode is the
        // files, and it does nothing when the mode is the folders or the two
        // of them.
        let mut wanted = String::new();
        match mode {
            crate::v1::THE_FOLDERS => wanted.push('D'),
            crate::v1::THE_FILES_AND_THE_FOLDERS => wanted.push('A'),
            _ => {}
        }
        if recurse && mode == crate::v1::THE_FILES {
            wanted.push('R');
        }
        self.the_walk_of_the_files_of_the_v1(pattern, &wanted, body, until, line)
    }

    /// The loop of the files of the v1 that names the kind of the loop.
    ///
    /// Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-05: the
    /// `Loop Files` of the v1 is the `Loop` whose first parameter is the word
    /// "Files": the pattern of the files is the second parameter and the mode
    /// is the third one. The mode is a set of letters -- the "R" walks into
    /// the folders, the "D" and the "K" give the folders, the "F" and the "V"
    /// give the files -- and the spaces and the tabs between them are ignored.
    /// The letter that is not one of them is refused when the loop runs, and
    /// the "A" is not one of them.
    fn the_loop_of_the_files_of_the_v1_with_the_kind(
        &mut self,
        arguments: &[Node],
        body: &[Node],
        until: &Option<Box<Node>>,
        line: u32,
    ) -> Result<(), RuntimeFailure> {
        let pattern = match arguments.get(1) {
            Some(node) => self.the_text_of_the_parameter_of_the_loop(node, line)?,
            None => String::new(),
        };
        let mode = match arguments.get(2) {
            Some(node) => self.the_text_of_the_parameter_of_the_loop(node, line)?,
            None => String::new(),
        };
        if the_letter_that_the_mode_does_not_carry(&mode).is_some() {
            return Err(RuntimeFailure::Error(RuntimeError {
                message: format!("Parameter #3 invalid.\n     Specifically: {}", mode.trim()),
                line,
            }));
        }
        self.the_walk_of_the_files_of_the_v1(&pattern, &mode, body, until, line)
    }

    /// The walk of the files of the v1.
    ///
    /// The mode is the mode of the desktop: the "R" walks into the folders,
    /// the "D" and the "K" give the folders, the "F" and the "V" give the
    /// files, and the "A" gives the two of them.
    fn the_walk_of_the_files_of_the_v1(
        &mut self,
        pattern: &str,
        mode: &str,
        body: &[Node],
        until: &Option<Box<Node>>,
        line: u32,
    ) -> Result<(), RuntimeFailure> {
        let folder = self.desktop().working_directory().map_err(|reason| {
            RuntimeFailure::Error(RuntimeError {
                message: reason,
                line,
            })
        })?;
        let files = self
            .desktop()
            .list_files(&folder, pattern, mode)
            .map_err(|reason| {
                RuntimeFailure::Error(RuntimeError {
                    message: reason,
                    line,
                })
            })?;
        for (index, file) in files.iter().enumerate() {
            self.set_global("A_Index", Value::Int(index as i64 + 1));
            let name = the_name_of(file).to_string();
            let path = the_path_that_is_relative_to(file, &folder);
            self.set_global("A_LoopFileName", Value::Text(name.clone()));
            self.set_global(
                "A_LoopFileExt",
                Value::Text(the_extension_of(&name).to_string()),
            );
            self.set_global(
                "A_LoopFileDir",
                Value::Text(the_folder_of(&path).to_string()),
            );
            self.set_global("A_LoopFilePath", Value::Text(path.clone()));
            // The short names of the files are a thing of Windows, and this
            // box has none.
            self.the_short_names_of_the_files_are_refused = true;
            // Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-05:
            // the `A_LoopFileFullPath` of the v1 is the path of the file that
            // is relative to the folder the script runs in, and not the long
            // one: the name of the v1 is a mistake that the v1 keeps.
            self.set_global("A_LoopFileFullPath", Value::Text(path));
            self.set_global("A_LoopFileLongPath", Value::Text(file.clone()));
            // The size of the file, and the times of it. Measured on the
            // binary of AutoHotkey v1.1.37.02 on 2026-11-05: the size is the
            // number of the bytes of the file, the kilobytes and the megabytes
            // are the parts of it, and the times are the fourteen digits of
            // the local time of the machine.
            //
            // The variable that the machine cannot answer is left out, and the
            // script that reads it is told that it has no value.
            if let Ok(size) = self.desktop().the_size_of_a_file(file) {
                self.set_global("A_LoopFileSize", Value::Int(size));
                self.set_global("A_LoopFileSizeKB", Value::Int(size / 1024));
                self.set_global("A_LoopFileSizeMB", Value::Int(size / 1024 / 1024));
            }
            if let Ok(letters) = self.desktop().file_attributes(file) {
                self.set_global("A_LoopFileAttrib", Value::Text(letters.concat()));
            }
            if let Ok(times) = self.desktop().file_times(file) {
                let offset = crate::files::local_offset(self);
                self.set_global(
                    "A_LoopFileTimeCreated",
                    Value::Text(crate::files::stamp_of(times.0, offset)),
                );
                self.set_global(
                    "A_LoopFileTimeModified",
                    Value::Text(crate::files::stamp_of(times.1, offset)),
                );
                self.set_global(
                    "A_LoopFileTimeAccessed",
                    Value::Text(crate::files::stamp_of(times.2, offset)),
                );
            }
            match self.run_block(body) {
                Ok(()) => {}
                Err(RuntimeFailure::Flow(Flow::Break)) => break,
                Err(RuntimeFailure::Flow(Flow::Continue)) => {}
                Err(other) => return Err(other),
            }
            // The `until` of the v1 is the condition of the loop, and it is
            // read after every turn of the body.
            if self.the_until_ends_the_loop(until)? {
                break;
            }
        }
        Ok(())
    }

    /// The read loop of the v1.
    ///
    /// Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-05: the
    /// `Loop, Read, file` reads the file and gives its lines in
    /// `A_LoopReadLine`, one turn for each line, and the number of the line
    /// is in `A_Index`. The file that is not there is not a failure: the loop
    /// has no turn. The second parameter is the file where the `FileAppend`
    /// that has no name of its own writes, and the third one is not carried.
    fn the_read_loop_of_the_v1(
        &mut self,
        arguments: &[Node],
        body: &[Node],
        until: &Option<Box<Node>>,
        line: u32,
    ) -> Result<(), RuntimeFailure> {
        let path = match arguments.get(1) {
            Some(node) => self.the_text_of_the_parameter_of_the_loop(node, line)?,
            None => String::new(),
        };
        let output = match arguments.get(2) {
            Some(node) => self.the_text_of_the_parameter_of_the_loop(node, line)?,
            None => String::new(),
        };
        // Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-05: the
        // file that is not there is not a failure, and the loop has no turn.
        let lines = self.desktop().read_file(&path).unwrap_or_default();
        self.loop_output_files.push(output);
        let mut failure = None;
        for (index, line_text) in lines.iter().enumerate() {
            self.set_global("A_Index", Value::Int(index as i64 + 1));
            self.set_global("A_LoopReadLine", Value::Text(line_text.clone()));
            match self.run_block(body) {
                Ok(()) => {}
                Err(RuntimeFailure::Flow(Flow::Break)) => break,
                Err(RuntimeFailure::Flow(Flow::Continue)) => continue,
                Err(other) => {
                    failure = Some(other);
                    break;
                }
            }
            // The `until` of the v1 is the condition of the loop, and it is
            // read after every turn of the body.
            if self.the_until_ends_the_loop(until)? {
                break;
            }
        }
        self.loop_output_files.pop();
        if let Some(other) = failure {
            return Err(other);
        }
        Ok(())
    }

    /// The parse loop of the v1.
    ///
    /// Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-05: the
    /// `Loop, Parse, name, delimiters` separates the text of the variable
    /// whose name is the second parameter, and every character of the
    /// delimiters is a delimiter of its own. The field is in `A_LoopField`
    /// and its number is in `A_Index`. The delimiters that are not there make
    /// every character of the text a field of its own, and the variable that
    /// has no value is a blank text: the loop has no turn.
    fn the_parse_loop_of_the_v1(
        &mut self,
        arguments: &[Node],
        body: &[Node],
        until: &Option<Box<Node>>,
        line: u32,
    ) -> Result<(), RuntimeFailure> {
        // The text that is separated is the value of the variable, or the
        // value of the expression when the percent sign and a space are in
        // front of the parameter.
        let text = match arguments.get(1) {
            // Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-05:
            // the percent sign and a space in front of the parameter make it
            // an expression, and the value of it is the text that is
            // separated.
            Some(Node::LegacyExpression { value, .. }) => self.evaluate(value)?.to_text(),
            Some(Node::Literal {
                value: crate::ast::LiteralValue::Text(text),
                ..
            }) => {
                // Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-05:
                // the name of the variable is the text of the parameter, and
                // the substitution of the v1 may bring the name from another
                // variable: the `Loop, Parse, %x%, "|"` separates the text of
                // the variable that the value of `x` names.
                let name = self.the_substitution_of_the_v1(text.trim(), line)?;
                // Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-05:
                // the name that is not the name of a variable is not a failure:
                // the v1 looks for it, does not find it, and the loop has no
                // turn.
                match self.lookup(&name) {
                    Some(value) => value.to_text(),
                    None => String::new(),
                }
            }
            Some(node) => self.evaluate(node)?.to_text(),
            None => String::new(),
        };
        let delimiters = match arguments.get(2) {
            Some(node) => self.the_text_of_the_parameter_of_the_loop(node, line)?,
            None => String::new(),
        };
        // Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-05: the
        // word "CSV" asks for the comma separated value format, and the case
        // of it and the spaces around it do not matter.
        let comma_separated =
            crate::v1::the_delimiters_ask_for_the_comma_separated_values(&delimiters);
        // The characters that are not wanted at the ends of a field.
        let omitted = match arguments.get(3) {
            Some(node) => self.the_text_of_the_parameter_of_the_loop(node, line)?,
            None => String::new(),
        };
        // Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-05: the
        // text that is empty has no field, and the loop has no turn: the
        // variable that has no value is a blank text.
        if text.is_empty() {
            return Ok(());
        }
        let pieces: Vec<String> = if comma_separated {
            // Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-05:
            // the comma separated value format does not use the characters
            // that are left out.
            crate::v1::the_fields_of_the_comma_separated_values(&text)
        } else if delimiters.is_empty() {
            // The delimiters that are not there make every character of the
            // text a field of its own, and the characters that are left out
            // are not seen at all.
            text.chars()
                .filter(|character| !omitted.contains(*character))
                .map(|character| character.to_string())
                .collect()
        } else {
            split_on_any(&text, &delimiters)
                .into_iter()
                .map(|piece| {
                    piece
                        .trim_matches(|character| omitted.contains(character))
                        .to_string()
                })
                .collect()
        };
        for (index, piece) in pieces.iter().enumerate() {
            self.set_global("A_Index", Value::Int(index as i64 + 1));
            self.set_global("A_LoopField", Value::Text(piece.clone()));
            match self.run_block(body) {
                Ok(()) => {}
                Err(RuntimeFailure::Flow(Flow::Break)) => break,
                Err(RuntimeFailure::Flow(Flow::Continue)) => continue,
                Err(other) => return Err(other),
            }
            // The `until` of the v1 is the condition of the loop, and it is
            // read after every turn of the body.
            if self.the_until_ends_the_loop(until)? {
                break;
            }
        }
        Ok(())
    }

    /// The `until` of the v1 ends the loop.
    ///
    /// Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-04: the
    /// `until` of the v1 is the statement that comes right after the body of
    /// a loop, and it is the condition that ends it: the body runs, and the
    /// condition is read after every turn of it. The condition is an
    /// expression, and the `=` of the v1 is an assignment: the `until i = 2`
    /// writes the variable "i" and the condition is true.
    ///
    /// The v2 has no such statement, and the loop has no condition.
    fn the_until_ends_the_loop(
        &mut self,
        until: &Option<Box<Node>>,
    ) -> Result<bool, RuntimeFailure> {
        let Some(condition) = until else {
            return Ok(false);
        };
        let value = self.evaluate(condition)?;
        Ok(self.the_value_is_true(&value))
    }

    /// The substitution of the parameters of a command of the v1.
    ///
    /// Measured on the binary of v1.1.37.02 on 2026-11-01: `%name%` is the
    /// value of the variable of the script when it has one, and the value
    /// of the environment otherwise. A `%` that does not close a name is
    /// left alone.
    ///
    /// Measured on the binary of v1.1.37.02 on 2026-11-04: the escape of the
    /// v1 is expanded here, and the character that it carries is a literal:
    /// the percent sign that it carries does not open the name of a variable,
    /// and the percent sign that closes a name is not the one that the
    /// escape carries.
    pub(crate) fn the_substitution_of_the_v1(
        &mut self,
        text: &str,
        line: u32,
    ) -> Result<String, RuntimeFailure> {
        if !text.contains('%') && !text.contains('`') {
            return Ok(text.to_string());
        }
        let mut out = String::with_capacity(text.len());
        let chars: Vec<char> = text.chars().collect();
        let mut index = 0usize;
        while index < chars.len() {
            if chars[index] == '`' {
                match chars.get(index + 1) {
                    Some(next) => {
                        out.push(self.dialect.the_escape_of_the_dialect(*next));
                        index += 2;
                    }
                    None => {
                        out.push('`');
                        index += 1;
                    }
                }
                continue;
            }
            if chars[index] == '%' {
                if let Some(close) = self.the_closing_percent(&chars, index + 1) {
                    let name: String = chars[index + 1..close].iter().collect();
                    match self.the_value_of_the_substitution(name.trim(), line)? {
                        Some(value) => {
                            // The numbers of the v1 are formatted by the
                            // `SetFormat` when they become a text.
                            let text = self.the_text_of(&value);
                            out.push_str(&text);
                            index = close + 1;
                            continue;
                        }
                        None => {
                            // Measured on the binary of v1.1.37.02 on
                            // 2026-11-01: a name that has no value is
                            // substituted by nothing, and not by the text
                            // of the name.
                            index = close + 1;
                            continue;
                        }
                    }
                }
                out.extend(&chars[index..]);
                break;
            }
            out.push(chars[index]);
            index += 1;
        }
        Ok(out)
    }

    /// The place of the percent sign that closes the name of a variable.
    ///
    /// Measured on the binary of v1.1.37.02 on 2026-11-04: the escape of the
    /// v1 makes the character that follows it a literal, and the percent sign
    /// that it carries does not close the name of a variable.
    fn the_closing_percent(&self, chars: &[char], from: usize) -> Option<usize> {
        let mut index = from;
        while index < chars.len() {
            match chars[index] {
                '`' => index += 2,
                '%' => return Some(index),
                _ => index += 1,
            }
        }
        None
    }

    /// The value of the legacy assignment of the v1.
    ///
    /// Measured on the binary of v1.1.37.02 on 2026-11-02:
    ///
    /// - The text of the right side is the text of the script, and the
    ///   `%name%` of it is the value of the variable of that name.
    /// - The `AutoTrim` trims the text of the assignment: with it On,
    ///   `x = %z%` leaves `x` at the value of `z` without the spaces that
    ///   come before it and the spaces that come after it, and with it Off
    ///   the spaces are there.
    /// - The text is a whole number when it is one in base ten: `x = 5`
    ///   leaves `x` at the number 5, and `x = 5.5` leaves it at the text
    ///   "5.5", and `x = 0x10` leaves it at the text "0x10".
    fn the_value_of_a_legacy_assignment(
        &mut self,
        text: &str,
        line: u32,
    ) -> Result<Value, RuntimeFailure> {
        let text = self.the_substitution_of_the_v1(text, line)?;
        // The `AutoTrim` of the v1 trims the text of the assignment. The
        // parameters of a command are not trimmed by it.
        let text = if self.auto_trim {
            text.trim().to_string()
        } else {
            text
        };
        Ok(crate::v1::the_number_of_a_legacy_text(&text).unwrap_or(Value::Text(text)))
    }

    /// The value of the substitution of a parameter of the v1.
    ///
    /// The variable of the script comes first, and the environment is what
    /// is left. The lookup of the environment is the one of the machine.
    fn the_value_of_the_substitution(
        &mut self,
        name: &str,
        line: u32,
    ) -> Result<Option<Value>, RuntimeFailure> {
        if let Some(value) = self.lookup(name) {
            return Ok(Some(value));
        }
        // Measured on the binary of v1.1.37.02 on 2026-11-04: the
        // variable that is named "0" holds the text "0" when it has no
        // value.
        if self.dialect.unset_is_blank() && name == "0" {
            return Ok(Some(self.the_value_of_an_unset_variable(name)));
        }
        // Measured on the binary of v1.1.37.02 on 2026-11-02: the built-in
        // variable of the v1 is a value too: `%A_AutoTrim%` is "On".
        if let Some(answer) = self.the_built_in_variable(name) {
            return match answer {
                Ok(value) => Ok(Some(value)),
                Err(error) => Err(RuntimeFailure::Error(RuntimeError {
                    message: error.message,
                    line: if error.line == 0 { line } else { error.line },
                })),
            };
        }
        // Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-05: the
        // short names of the files are a thing of Windows, and this box has
        // none: the script that reads the name is told that.
        if let Some(reason) = self.the_reason_of_the_short_names_of_the_files(name) {
            return Err(RuntimeFailure::Error(RuntimeError {
                message: reason.to_string(),
                line,
            }));
        }
        // Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-05: the
        // variables that the runtime owns are values too: the `%A_Index%` is
        // "0" outside a loop, and the tree answered an empty text, because
        // the substitution of the v1 did not ask the runtime for them.
        if let Some(value) = self.the_value_of_a_variable_of_the_runtime(name) {
            return Ok(Some(value));
        }
        if !self.dialect.percent_looks_at_the_environment() {
            return Ok(None);
        }
        // The directive `#NoEnv` of the v1 turns the lookup of the
        // environment off.
        if self.no_env {
            return Ok(None);
        }
        match self.desktop().env_get(name) {
            Ok(Some(value)) => {
                // Measured on the binary of AutoHotkey v1.1.37.02 on
                // 2026-11-05: the environment variable that is accessed is
                // warned about.
                self.warn_about_the_environment_that_is_accessed(name, line);
                Ok(Some(Value::Text(value)))
            }
            // Measured on the binary of v1.1.37.02 on 2026-11-01: a name
            // that the environment does not have is substituted by nothing.
            Ok(None) => {
                // Measured on the binary of AutoHotkey v1.1.37.02 on
                // 2026-11-05: the name that is not a variable of the script
                // and not of the environment is a variable that has no value.
                self.warn_about_the_variable_that_has_no_value(name, line);
                Ok(None)
            }
            Err(_) => {
                // Measured on the binary of AutoHotkey v1.1.37.02 on
                // 2026-11-05: the name that is not a variable of the script
                // and not of the environment is a variable that has no value.
                self.warn_about_the_variable_that_has_no_value(name, line);
                Ok(None)
            }
        }
    }

    /// The functions the language carries.
    fn call_builtin(
        &mut self,
        name: &str,
        values: &[Value],
        line: u32,
        route: Route,
    ) -> Result<Value, RuntimeFailure> {
        let Some(builtin) =
            self.the_builtin_of_the_kind(name, crate::builtins::BuiltinKind::Function)
        else {
            return Err(RuntimeFailure::Error(RuntimeError {
                message: "Call to nonexistent function.".into(),
                line,
            }));
        };
        self.call_the_row(builtin, values, line, route)
    }

    /// The call of the built-in of this row.
    ///
    /// The row is the one of the dialect that runs, and its column of the
    /// shape says what each parameter is: a value, a reference that the
    /// caller passes, the name of a variable of the script, or the name of
    /// the variable that the built-in writes into.
    fn call_the_row(
        &mut self,
        builtin: &'static crate::builtins::Builtin,
        values: &[Value],
        line: u32,
        route: Route,
    ) -> Result<Value, RuntimeFailure> {
        // The arity is in the table, so the check is the same for every
        // built-in and it says what AutoHotkey says.
        if values.len() < builtin.min as usize {
            return Err(self.the_arity_failure(
                "Too few parameters passed to function.",
                builtin.name,
                route,
                line,
            ));
        }
        // The table says 255 when the built-in takes any number of them, and
        // the v1 has no complaint for a command that takes more parameters
        // than it needs.
        if builtin.max < 255 && values.len() > builtin.max as usize {
            return Err(self.the_arity_failure(
                "Too many parameters passed to function.",
                builtin.name,
                route,
                line,
            ));
        }
        // A reference is for the parameters that are written back: the
        // rest want a value, and v2 says which parameter got one and what
        // the built-in wanted there.
        //
        // The column of the shape says which parameters are written back:
        // the reference of the v2, and the output of the v1.
        // The built-in that says itself which parameters take a reference
        // asks in its own handler.
        //
        // Measured on the binary of v1.1.37.02 on 2026-11-02: the v1 does
        // not check the kind of the arguments -- the built-in of the v1
        // takes the text that holds a number, and it does not fail -- so the
        // two checks below are the ones of the v2.
        let checks_the_kind = self.dialect.the_built_in_checks_the_kind_of_its_arguments();
        // The v1 does not check the kind of the arguments, and the parameter
        // that wants a number takes the number that the text of it starts
        // with: the dialect converts the arguments before the body of the
        // built-in runs.
        //
        // Measured on the binary of v1.1.37.02 on 2026-11-02.
        let converted = if checks_the_kind {
            None
        } else {
            self.the_numbers_that_the_arguments_hold(builtin.name, values)
        };
        let values = converted.as_deref().unwrap_or(values);
        let decides = crate::builtins::decides_references(builtin.name);
        for (index, value) in values.iter().enumerate() {
            if !matches!(value, Value::Reference(_))
                || builtin.writes_back(index)
                || decides
                || crate::builtins::refuses_itself(builtin.name)
                || !checks_the_kind
            {
                continue;
            }
            // A reference is a value of its own kind. Where the parameter
            // wants a text, a number or an object, the reference does not
            // fit and the built-in says so. Where the parameter takes any
            // value, the reference goes through, and the built-in answers
            // about it: the `Type` names it "VarRef".
            let message = match crate::builtins::wants(builtin.name, index) {
                crate::builtins::Wants::Declared(kind) => {
                    requires(index + 1, builtin.name, kind, value)
                }
                crate::builtins::Wants::Checked(kind) => expects_a_kind(kind, value),
                // A parameter that wants a reference takes one.
                crate::builtins::Wants::Reference(_) => continue,
                crate::builtins::Wants::Value => continue,
            };
            // The name of the built-in goes in the `What` of the
            // failure: v2 carries it there.
            return Err(RuntimeFailure::Detailed(
                RuntimeError { message, line },
                Detail {
                    what: builtin.name.to_string(),
                    extra: String::new(),
                },
            ));
        }
        // A parameter that v2 declares wants a value of a kind, and a
        // value of another kind is refused with the reason: the name of
        // the built-in, the number of the parameter and the kind that
        // arrived.
        //
        // Measured on the binary of v2.0.19 on 2026-10-31: a parameter
        // that wants a text takes a text and a number, and one that
        // wants a number takes a number and a text that holds one. A
        // check that the body of the function makes wants the kind of
        // the value itself: a number is not a text.
        for (index, value) in values.iter().enumerate() {
            // A reference is the business of the guard above: the
            // parameters that are written back take one.
            if matches!(value, Value::Reference(_)) || !checks_the_kind {
                continue;
            }
            let message = match crate::builtins::wants(builtin.name, index) {
                crate::builtins::Wants::Declared(kind) => {
                    if accepts(kind, value) {
                        continue;
                    }
                    // Measured on the binary of v1.1.37.02 on 2026-11-02: the
                    // v1 does not refuse an object where a parameter wants a
                    // text -- the text of the object is the empty text, and
                    // `StrLen(Object())` is zero.
                    if kind == TypeName::String
                        && matches!(value, Value::Object(_))
                        && self.dialect.an_object_has_no_text()
                    {
                        continue;
                    }
                    requires(index + 1, builtin.name, kind, value)
                }
                crate::builtins::Wants::Checked(kind) => {
                    if is_of_the_kind(kind, value) {
                        continue;
                    }
                    expects_a_kind(kind, value)
                }
                crate::builtins::Wants::Reference(wants) => {
                    wants_a_reference(index + 1, builtin.name, wants, value)
                }
                crate::builtins::Wants::Value => continue,
            };
            // v2 carries the value that arrived in the `Extra`: the
            // text of it, and nothing for an object, an array or a
            // function.
            return Err(RuntimeFailure::Detailed(
                RuntimeError { message, line },
                Detail {
                    what: builtin.name.to_string(),
                    extra: the_extra_of_the_value(value),
                },
            ));
        }
        // A command may declare fewer parameters than it needs: the table
        // of the binary says how many the command takes, and the command
        // says which one it cannot do without. The refusal of v2 names
        // the parameter and not the count, and it comes after the kind of
        // the values that are there: the dialect converts the arguments
        // before the body of the function runs.
        for number in self
            .dialect
            .the_parameters_that_may_not_be_left_out(builtin.name)
        {
            if values.len() < *number as usize {
                return Err(RuntimeFailure::Detailed(
                    RuntimeError {
                        message: format!(
                            "Parameter #{number} of {} must not be omitted in this case.",
                            builtin.name
                        ),
                        line,
                    },
                    // The name of the built-in goes in the `What` of the
                    // failure, the way it goes in the failure of a value
                    // that is not the one that was wanted.
                    //
                    // Measured on the binary of v2.0.19 on 2026-11-01.
                    Detail {
                        what: builtin.name.to_string(),
                        extra: String::new(),
                    },
                ));
            }
        }
        (builtin.handler)(self, values, line, builtin.variant).map_err(|error| {
            // The failure of a built-in carries the name of the built-in
            // in the `What`, and the value of the parameter that failed
            // in the `Extra`.
            let extra = crate::builtins::the_extra_of(builtin.name, &error.message, values)
                .unwrap_or_else(|| the_parameter_that_failed(&error.message, values));
            RuntimeFailure::Detailed(
                error,
                Detail {
                    what: builtin.name.to_string(),
                    extra,
                },
            )
        })
    }

    /// The numbers that the arguments of the built-in hold.
    ///
    /// Measured on the binary of v1.1.37.02 on 2026-11-02: the v1 does not
    /// check the kind of the arguments, and the parameter that wants a number
    /// takes the number that the text of it starts with -- "65abc" is 65 --
    /// and the hex of the v1 is a number: "0x10" is 16.
    ///
    /// The answer is nothing when every argument that wants a number already
    /// holds one.
    fn the_numbers_that_the_arguments_hold(
        &self,
        name: &str,
        values: &[Value],
    ) -> Option<Vec<Value>> {
        let mut numbers: Option<Vec<Value>> = None;
        for (index, value) in values.iter().enumerate() {
            if !self.dialect.the_parameter_wants_a_number(name, index) {
                continue;
            }
            // Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-04:
            // the parameter that keeps its text is not a number, and the
            // command reads the text of it: the amount of the `EnvAdd` that
            // is "5abc" is not a number.
            if self.dialect.the_parameter_keeps_its_text(name, index) {
                continue;
            }
            // A number is the number that it is.
            if matches!(value, Value::Int(_) | Value::Float(_)) {
                continue;
            }
            let number = crate::v1::the_number_at_the_start_of_a_text(&self.the_text_of(value))
                .unwrap_or(Value::Int(0));
            let numbers = numbers.get_or_insert_with(|| values.to_vec());
            numbers[index] = number;
        }
        numbers
    }

    /// The desktop the script drives.
    pub(crate) fn desktop(&mut self) -> &mut (dyn crate::runtime::Desktop + 'a) {
        &mut *self.desktop
    }

    /// The directory where the run started, when the runtime knows it.
    ///
    /// The desktop says it when the runtime is made, and the runtime keeps
    /// it: a script that changes the working directory does not change the
    /// one where the run began.
    pub(crate) fn initial_working_dir(&self) -> Option<&str> {
        self.initial_working_dir.as_deref()
    }

    /// The file of the file-reading loop that runs, when it has one.
    ///
    /// Measured on the binary of v2.0.19 on 2026-11-01: the name of the
    /// file of a `FileAppend` may be left out inside the body of a `Loop
    /// Read` that has a file of its own, and the text goes to that file.
    pub(crate) fn the_output_file_of_the_loop(&self) -> Option<&str> {
        self.loop_output_files
            .last()
            .map(|path| path.as_str())
            .filter(|path| !path.is_empty())
    }

    /// The file of the loop of the files that runs.
    ///
    /// Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-05: the
    /// name of the file of the commands of the files of the v1 may be left
    /// out, and the file of the loop that runs is the one that is used.
    pub(crate) fn the_file_of_the_loop(&self) -> Option<String> {
        self.lookup("A_LoopFileLongPath")
            .map(|value| value.to_text())
            .filter(|path| !path.is_empty())
    }

    /// The pause the script asked for.
    pub(crate) fn sleep_ms(&mut self, millis: u64) {
        self.clock.sleep_ms(millis)
    }

    /// The milliseconds the clock says, for a built-in that needs a
    /// number that is not the same every time.
    ///
    /// The clock is the one the host gave us: on a hosted platform it is
    /// the monotonic clock, and on a target with no `std` it is
    /// whatever the embedder supplied. It is not a wall clock, so a
    /// built-in that wants the date and the time cannot use it.
    pub(crate) fn now_ms(&self) -> u64 {
        self.clock.now_ms()
    }

    /// The hotkeys of the script.
    pub(crate) fn hotkeys(&mut self) -> &mut Vec<crate::hotkeys::Hotkey> {
        &mut self.hotkeys
    }

    /// The function the script asks to run when it ends.
    ///
    /// The name is the one the script wrote, and the line is the line of
    /// the statement that registered it.
    ///
    /// v2 keeps one entry for a callback: registering the same function
    /// again does not make it run twice.
    pub(crate) fn set_exit_callback(&mut self, name: &str, line: u32) {
        match self
            .exit_callbacks
            .iter_mut()
            .find(|callback| callback.name.eq_ignore_ascii_case(name))
        {
            Some(callback) => callback.line = line,
            None => self.exit_callbacks.push(Callback {
                name: name.to_string(),
                line,
            }),
        }
    }

    /// The function the script asks to run when a failure is not caught.
    pub(crate) fn set_error_callback(&mut self, name: &str, line: u32) {
        match self
            .error_callbacks
            .iter_mut()
            .find(|callback| callback.name.eq_ignore_ascii_case(name))
        {
            Some(callback) => callback.line = line,
            None => self.error_callbacks.push(Callback {
                name: name.to_string(),
                line,
            }),
        }
    }

    /// The callback of the exit that has this name is not called any more.
    pub(crate) fn remove_exit_callback(&mut self, name: &str) {
        self.exit_callbacks
            .retain(|callback| !callback.name.eq_ignore_ascii_case(name));
    }

    /// The callback of the error that has this name is not called any more.
    pub(crate) fn remove_error_callback(&mut self, name: &str) {
        self.error_callbacks
            .retain(|callback| !callback.name.eq_ignore_ascii_case(name));
    }

    /// Put a callback before the ones that are registered, or after them.
    pub(crate) fn order_exit_callback(&mut self, name: &str, before: bool) {
        let Some(at) = self
            .exit_callbacks
            .iter()
            .position(|callback| callback.name.eq_ignore_ascii_case(name))
        else {
            return;
        };
        let callback = self.exit_callbacks.remove(at);
        if before {
            self.exit_callbacks.insert(0, callback);
        } else {
            self.exit_callbacks.push(callback);
        }
    }

    /// Put a callback before the ones that are registered, or after them.
    pub(crate) fn order_error_callback(&mut self, name: &str, before: bool) {
        let Some(at) = self
            .error_callbacks
            .iter()
            .position(|callback| callback.name.eq_ignore_ascii_case(name))
        else {
            return;
        };
        let callback = self.error_callbacks.remove(at);
        if before {
            self.error_callbacks.insert(0, callback);
        } else {
            self.error_callbacks.push(callback);
        }
    }

    /// The function of the script that a callback names.
    ///
    /// v2 wants a function object, and the prototype of the function has
    /// to take the two parameters of the callback: the reason and the code
    /// for the exit, the value and the mode for the error.
    ///
    /// The three refusals are the ones of v2, measured on its binary: a
    /// value that is not an object, a value that cannot be called, and a
    /// prototype that does not take the two parameters.
    pub(crate) fn the_callback(
        &self,
        value: Option<&Value>,
        name: &str,
        line: u32,
    ) -> Result<Callback, RuntimeError> {
        let Some(value) = value else {
            return Err(RuntimeError {
                message: format!(
                    "Parameter #1 of {name} requires an Object, but received nothing."
                ),
                line,
            });
        };
        // A value that is not an object is refused with the kind of the
        // value it is.
        let Value::Object(object) = value else {
            return Err(RuntimeError {
                message: crate::runtime::wants_a_reference(1, name, "an Object", value),
                line,
            });
        };
        let object = object.borrow();
        // v2 calls the value, and a value that cannot be called has no
        // method named "Call".
        if object.class != "func" {
            return Err(RuntimeError {
                message: format!(
                    "This value of type \"{}\" has no method named \"Call\".",
                    value.type_name().name()
                ),
                line,
            });
        }
        let function_name = match object.value_of("name") {
            Some(Value::Text(text)) => text.clone(),
            _ => String::new(),
        };
        // The prototype has to take the two parameters of the callback. A
        // parameter that takes the rest fits: it takes what is left.
        let takes_two = match self.functions.get(&function_name.to_lowercase()) {
            Some(function) => {
                let fewest = function
                    .parameters
                    .iter()
                    .filter(|parameter| parameter.default.is_none() && !parameter.variadic)
                    .count();
                let variadic = function
                    .parameters
                    .iter()
                    .any(|parameter| parameter.variadic);
                fewest <= 2 && (variadic || function.parameters.len() >= 2)
            }
            // A built-in has its own arity, and the same rule is asked of
            // it.
            None => {
                let fewest = number_of(&object.properties, "minparams");
                let most = number_of(&object.properties, "maxparams");
                fewest <= 2 && most >= 2
            }
        };
        if !takes_two {
            return Err(RuntimeError {
                message: "Invalid callback function.".into(),
                line,
            });
        }
        Ok(Callback {
            name: function_name,
            line,
        })
    }

    /// The functions that asked to see the failure, and what they said.
    ///
    /// The answers are the ones of v2: 0 lets the failure go on, 1 hides
    /// it, and -1 hides it and lets the thread continue.
    fn ask_the_error_callbacks(&mut self, failure: &RuntimeFailure) -> TheError {
        // While the body of a `try` runs, the functions of the error are
        // not called: the catch of the script takes the failure first, and
        // the functions of the error are called only when no catch took
        // it.
        if self.error_callbacks.is_empty() || self.try_active > 0 {
            return TheError::Goes;
        }
        let (value, mode) = match failure {
            // A failure of the runtime is a continuable one: the thread
            // goes on when a function says so.
            RuntimeFailure::Error(error) => (self.error_value(error), "Return"),
            RuntimeFailure::Detailed(error, detail) => {
                (self.error_value_with(error, detail), "Return")
            }
            // A value that the script threw is not a continuable failure.
            RuntimeFailure::Thrown(value) => (value.clone(), "Exit"),
            // The timeout of the tree stops the program.
            RuntimeFailure::Timeout(timeout) => (
                self.error_value(&RuntimeError {
                    message: timeout.to_string(),
                    line: 0,
                }),
                "ExitApp",
            ),
            _ => return TheError::Goes,
        };
        let mut answer = 0;
        let callbacks = self.error_callbacks.clone();
        for callback in callbacks {
            let values = [value.clone(), Value::Text(mode.to_string())];
            // A function that fails does not hide the failure.
            if let Ok(said) =
                self.call_named(&callback.name, &values, callback.line, Route::Written)
            {
                let said = said.to_number().unwrap_or(0.0) as i64;
                if said != 0 {
                    answer = said;
                    // A function that answered stops the ones that come
                    // after it.
                    break;
                }
            }
        }
        match answer {
            1 => TheError::Hidden,
            -1 if mode == "Return" => TheError::Continues,
            -1 => TheError::Hidden,
            _ => TheError::Goes,
        }
    }

    /// Call a function of the script by name, with no arguments.
    ///
    /// A name that is not a function of the script is a name that does
    /// nothing: the caller of this is a hotkey, and the hotkey of a
    /// function that the script does not have is a hotkey of nothing.
    pub(crate) fn call_function_by_name(
        &mut self,
        name: &str,
        line: u32,
    ) -> Result<(), RuntimeFailure> {
        let Some(function) = self.functions.get(&name.to_lowercase()).cloned() else {
            return Ok(());
        };
        self.call_function(&function, &[], line, Route::Written)
            .map(|_| ())
    }

    /// The date and the time of the machine, when the clock knows them.
    pub(crate) fn wall_clock(&self) -> Option<crate::date::WallClock> {
        self.clock.wall_clock()
    }

    /// A variable of the script, by name.
    pub(crate) fn set_global(&mut self, name: &str, value: Value) {
        self.variables.insert(the_key_of(name), value);
    }

    /// A line of the report, from the script.
    pub(crate) fn push_output(&mut self, text: String) {
        self.output.push(text);
    }

    // -- expressions ---------------------------------------------------------------

    /// Whether the value of the operand is true in the dialect of the run.
    ///
    /// Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-04: the
    /// text that was written between quotes is a string of the v1, and a
    /// string is true when it is not empty: the `!("00")` is zero. The value
    /// of a variable is a number when it can be one, and the `!x` with `x`
    /// holding "00" is one.
    fn the_operand_is_true(&self, node: &Node, value: &Value) -> bool {
        if self.dialect.the_text_that_was_written_is_a_string()
            && self.the_node_is_a_quoted_text(node)
        {
            return match value {
                Value::Text(text) => !text.is_empty(),
                other => other.truthy(),
            };
        }
        self.the_value_is_true(value)
    }

    /// The answer of the `&&` and of the `||`.
    ///
    /// Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-04: the
    /// `&&` and the `||` of the v1 answer one and zero, and not the operand:
    /// the `"a" && "b"` is 1. The v2 answers the operand.
    fn the_answer_of_the_boolean(&self, node: &Node, value: &Value) -> Value {
        if self.dialect.the_operators_answer_a_number() {
            return Value::Int(self.the_operand_is_true(node, value) as i64);
        }
        value.clone()
    }

    /// Whether the value is true in the dialect of the run.
    ///
    /// Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-04: the
    /// text of a condition of the v1 is a number when the syntax of the v1
    /// accepts it, and the condition is false when that number is zero: the
    /// "00" is false, and the "0.0" is false. The v2 keeps the text as it
    /// was written: the "00" is true, and only the text "0" is false.
    fn the_value_is_true(&self, value: &Value) -> bool {
        if self.dialect.the_text_that_is_a_number_is_false() {
            if let Value::Text(text) = value {
                return match crate::v1::the_number_of_a_text(text) {
                    Some(number) => number.truthy(),
                    None => !text.is_empty(),
                };
            }
        }
        value.truthy()
    }

    /// The value of the condition of a construct.
    ///
    /// Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-04: the v1
    /// does not report the failure of the condition of an `if` or of a
    /// `while`: the `if 1/0`, the `if x.y` and the `if x.y := 5` are
    /// accepted, the condition is false, and the body of the construct does
    /// not run.
    ///
    /// The failure that a throw carries, the failure that no catch takes and
    /// the timeout are not the failure of a condition, and they are reported.
    fn the_value_of_the_condition(&mut self, condition: &Node) -> Result<Value, RuntimeFailure> {
        match self.evaluate(condition) {
            Ok(value) => Ok(value),
            Err(failure) => {
                if !self.dialect.the_failure_of_a_condition_is_not_reported() {
                    return Err(failure);
                }
                if !matches!(
                    failure,
                    RuntimeFailure::Error(_) | RuntimeFailure::Detailed(_, _)
                ) {
                    return Err(failure);
                }
                Ok(Value::Int(0))
            }
        }
    }

    fn evaluate(&mut self, node: &Node) -> Result<Value, RuntimeFailure> {
        match node {
            Node::Unset { .. } => {
                // Measured on the binary of AutoHotkey v1.1.37.02 on
                // 2026-11-04: the value of the expression whose operand is
                // not there is the empty text.
                Ok(Value::Text(String::new()))
            }
            Node::Assign {
                name,
                op,
                value,
                line,
            } => {
                // The assignment of v2 is an expression, and the value of
                // it is the value that was written.
                let value = self.evaluate(value)?;
                self.write_a_variable(name, *op, value, *line)
            }
            Node::LegacyComparison {
                left,
                op,
                text,
                line,
            } => {
                // The comparison of the legacy `if` of the v1: the right side
                // of it is the text of the rest of the line.
                self.the_comparison_of_a_legacy_if(left, *op, text, *line)
            }
            Node::LegacyMatch {
                left,
                form,
                texts,
                negated,
                line,
            } => {
                // The forms of the legacy `if` of the v1 that are not a
                // comparison: the `between`, the `in` and the `contains`.
                self.the_match_of_a_legacy_if(left, *form, texts, *negated, *line)
            }
            Node::AssignProperty {
                target,
                name,
                op,
                value,
                line,
            } => {
                let value = self.evaluate(value)?;
                let name = self.the_name_of_the_member(name, *line)?;
                self.write_a_property(target, &name, *op, value, *line)
            }
            Node::AssignIndex {
                target,
                index,
                op,
                value,
                line,
            } => {
                let target_value = self.evaluate(target)?;
                let key = self.evaluate(index)?;
                let value = self.evaluate(value)?;
                self.set_item(&target_value, &key, *op, value, *line)
            }
            Node::Literal { value, line } => Ok(match value {
                // The shape of the literal is the shape of the value: the
                // whole number of v2 is a whole number, and a number with
                // a point or with an exponent is a float.
                LiteralValue::Integer(number) => Value::Int(*number),
                LiteralValue::Float(number) => Value::Float(*number),
                // Measured on the binary of v1.1.37.02 on 2026-11-02: the
                // number of the v1 is a "pure number": it keeps the text
                // that was written, and that text is the value of it. The
                // whole number that does not fit in the machine is the
                // one that fits, and the number that is a number and not
                // a pure number follows the format of the dialect.
                LiteralValue::Number(text) => {
                    let text = crate::v1::the_text_of_the_number_that_fits(text);
                    if crate::v1::the_number_is_a_number(&text) {
                        return Ok(match crate::v1::the_number_of_a_text(&text) {
                            Some(Value::Int(number)) => {
                                Value::Text(self.integer_format.the_text_of(number))
                            }
                            Some(Value::Float(number)) => {
                                Value::Text(self.float_format.the_text_of(number))
                            }
                            _ => Value::Text(text),
                        });
                    }
                    Value::Text(text)
                }
                // A string is read where it is written: the names it
                // holds are the names of the scope that writes it.
                LiteralValue::Text(text) => Value::Text(self.interpolate(text, *line)?),
                LiteralValue::Bool(flag) => Value::Int(*flag as i64),
            }),
            Node::ObjectLiteral { items, line } => {
                // The literal of an object of v2: an object of the base
                // class with the properties it writes. The names of the
                // properties do not know their case, and a name that the
                // script builds is the name of the property.
                //
                // The v1 has no classes, and the object of it has no class
                // either: measured on the binary of v1.1.37.02 on
                // 2026-11-02, the `__Class` of the object of the v1 is
                // empty.
                let object = crate::classes::object(self.dialect.class_of_an_object());
                if let Value::Object(cell) = &object {
                    for item in items {
                        match item {
                            ObjectItem::Property(name, value) => {
                                let name = self.the_name_of_the_member(name, *line)?;
                                let value = self.evaluate(value)?;
                                put(&mut cell.borrow_mut().properties, &name, value);
                            }
                            ObjectItem::LegacyKey(key, value) => {
                                // Measured on the binary of AutoHotkey
                                // v1.1.37.02 on 2026-11-04: the key of the v1
                                // is the value of the expression that is
                                // written until the colon: the `{1 + 1: 1}`
                                // has the property "2", and the `{a.b: 1}`
                                // has the property of the value of `a.b`.
                                let key = self.evaluate(key)?;
                                let value = self.evaluate(value)?;
                                put(&mut cell.borrow_mut().properties, &key.to_text(), value);
                            }
                            ObjectItem::Value(value) => {
                                // Measured on the binary of AutoHotkey
                                // v1.1.37.02 on 2026-11-04: a value that has
                                // no name is evaluated, and it is dropped: the
                                // `a := {, 1}` is an object of no property.
                                self.evaluate(value)?;
                            }
                        }
                    }
                }
                Ok(object)
            }
            Node::Lambda {
                parameters,
                body,
                line,
            } => {
                // The arrow function of v2: a function that closes over the
                // scope where it was written, and whose body is an
                // expression.
                let function = Function {
                    name: String::new(),
                    parameters: parameters.clone(),
                    body: vec![Node::Return {
                        value: Some(Box::new((**body).clone())),
                        line: *line,
                    }],
                    declarations: Declarations::default(),
                    closure: self.scopes.clone(),
                };
                let name = self.make_a_closure(function.clone());
                Ok(closure_value(&name, &function))
            }
            Node::ArrayLiteral { items, line } => {
                // The literal is the array the `Array` built-in makes:
                // the values go in, in the order they are written. The hole
                // of the literal is a place of the array that has no value
                // of its own.
                let mut values = Vec::new();
                for item in items {
                    match item {
                        Some(item) => values.push(Some(self.evaluate(item)?)),
                        None => values.push(None),
                    }
                }
                Ok(crate::classes::array::construct_with_holes(
                    &values, self, *line,
                ))
            }
            Node::Group { items, .. } => {
                // Measured on the binary of v2.0.19 on 2026-10-31: the value
                // of a parenthesized list is the last of its items, and
                // every item of it runs.
                let mut value = Value::Text(String::new());
                for item in items {
                    value = self.evaluate(item)?;
                }
                Ok(value)
            }
            Node::Empty { .. } => {
                // Measured on the binary of v2.0.19 on 2026-10-31: the
                // parameter that is not there keeps its place, and the
                // parameter has no value. The call that takes it gives it
                // the default of the parameter, or refuses the call with
                // "Missing a required parameter.".
                //
                // The value here is the one that a built-in sees, and the
                // built-in of v2 has a default of its own for it.
                Ok(Value::Text(String::new()))
            }
            Node::Legacy { items, .. } => {
                // Measured on the binary of v2.0.19 on 2026-10-31: the list
                // of v1 is evaluated, and its value is thrown away.
                let mut value = Value::Text(String::new());
                for item in items {
                    value = self.evaluate(item)?;
                }
                Ok(value)
            }
            Node::LegacyControl { condition, .. } => {
                // Measured on the binary of AutoHotkey v1.1.37.02 on
                // 2026-11-04: the construct that comes inside the line of the
                // condition of an `if` has no body of its own, and the value
                // of it is the value of its condition.
                self.evaluate(condition)
            }
            Node::For { line, .. } => {
                // A for loop is a statement: the parser never gives one
                // where an expression is asked for.
                Err(RuntimeFailure::Error(RuntimeError {
                    message: "the for loop is not an expression.".into(),
                    line: *line,
                }))
            }
            Node::Declare { line, .. } => {
                // A declaration is a statement: the parser never gives one
                // where an expression is asked for.
                Err(RuntimeFailure::Error(RuntimeError {
                    message: "a declaration is not an expression.".into(),
                    line: *line,
                }))
            }
            Node::Super { line } => {
                // A `super` with no member: the parser refuses it, and the
                // runtime refuses it too.
                Err(RuntimeFailure::Error(RuntimeError {
                    message: "Syntax error.\n     Specifically: super".into(),
                    line: *line,
                }))
            }
            Node::Var { name, line } => match self.lookup(name) {
                Some(value) => {
                    // A class of v2 is initialised when it is first used.
                    if let Value::Object(object) = &value {
                        let class = object.borrow().class.clone();
                        self.initialise_the_class(&class, *line)?;
                    }
                    Ok(value)
                }
                // The name may be one of the built-in variables: the
                // table of them knows whether it is one, and the runtime
                // may not be able to answer it.
                None => match self.the_built_in_variable(name) {
                    Some(Ok(value)) => Ok(value),
                    Some(Err(error)) => Err(RuntimeFailure::Error(RuntimeError {
                        message: error.message,
                        line: *line,
                    })),
                    None => {
                        // Measured on the binary of AutoHotkey v1.1.37.02 on
                        // 2026-11-05: the short names of the files are a thing
                        // of Windows, and this box has none: the script that
                        // reads the name is told that, and the tree does not
                        // make up a name for the file.
                        if let Some(reason) = self.the_reason_of_the_short_names_of_the_files(name)
                        {
                            return Err(RuntimeFailure::Error(RuntimeError {
                                message: reason.to_string(),
                                line: *line,
                            }));
                        }
                        match self.the_value_of_a_variable_of_the_runtime(name) {
                            Some(value) => Ok(value),
                            None => {
                                // Measured on the binary of AutoHotkey v2.0.19 on
                                // 2026-11-05: the warning of the variable that
                                // is read and never written is given before
                                // the failure of the run.
                                self.warn_about_the_variable_that_has_no_value(name, *line);
                                // Measured on the binary of v1.1.37.02 on
                                // 2026-11-01: a variable of the v1 that has no
                                // value is blank, and it is not a failure.
                                if self.dialect.unset_is_blank() {
                                    return Ok(self.the_value_of_an_unset_variable(name));
                                }
                                Err(match self.alias_of(name) {
                                    // A parameter that is an alias says that it is
                                    // the parameter that has no value.
                                    Some(_) => RuntimeFailure::Error(RuntimeError {
                                        message: unassigned_parameter(),
                                        line: *line,
                                    }),
                                    None => self.the_unassigned_failure(name, *line),
                                })
                            }
                        }
                    }
                },
            },
            Node::Unary { op, operand, line } => match op {
                // The four increments move a variable and answer a value.
                UnaryOp::PreIncrement
                | UnaryOp::PreDecrement
                | UnaryOp::PostIncrement
                | UnaryOp::PostDecrement => self.increment(*op, operand, *line),
                // `!` and `not` are the same operation: the word binds
                // looser, and the parser keeps them apart for that.
                UnaryOp::Not | UnaryOp::NotWord => {
                    let value = self.evaluate(operand)?;
                    Ok(Value::Int(!self.the_operand_is_true(operand, &value) as i64))
                }
                // The word that is an operator and that has no left operand.
                //
                // Measured on the binary of AutoHotkey v1.1.37.02 on
                // 2026-11-04: the word takes the value of the right side, and
                // it answers the truth of it as a number: the `x := and 2` is
                // one, and the `x := or 2` is one.
                UnaryOp::Boolean => {
                    let value = self.evaluate(operand)?;
                    Ok(self.the_answer_of_the_boolean(operand, &value))
                }
                // A whole number stays a whole number: `-3` is the
                // integer -3, the way AutoHotkey v2 has it.
                UnaryOp::Negate => {
                    let value = self.evaluate(operand)?;
                    // Measured on the binary of v1.1.37.02 on 2026-11-02:
                    // the value of the v1 is a number when it can be one --
                    // the "5" is 5, and the "0x10" is 16 -- and the whole
                    // number stays a whole number: the `-x` of the "5" is
                    // "-5". The value that is not a number makes the
                    // operation blank.
                    if self.dialect.a_value_that_is_not_a_number_is_blank() {
                        return Ok(match self.the_number_of_the_v1(operand, &value) {
                            Some(Value::Int(number)) => Value::Int(number.wrapping_neg()),
                            Some(Value::Float(number)) => Value::Float(-number),
                            _ => Value::Text(String::new()),
                        });
                    }
                    Ok(match value {
                        Value::Int(number) => Value::Int(number.wrapping_neg()),
                        other => Value::Float(-self.number(&other, *line)?),
                    })
                }
                // The unary plus turns a numeric string into a number.
                UnaryOp::Plus => {
                    let value = self.evaluate(operand)?;
                    // Measured on the binary of v1.1.37.02 on 2026-11-02: the
                    // plus of the v1 changes nothing: the `+x` of the
                    // "0x10" is "0x10", and the `+x` of the "abc" is "abc".
                    if self.dialect.a_value_that_is_not_a_number_is_blank() {
                        return Ok(value);
                    }
                    Ok(match value {
                        Value::Int(number) => Value::Int(number),
                        other => Value::Float(self.number(&other, *line)?),
                    })
                }
                // The bitwise not works on the bits of a whole number.
                UnaryOp::BitwiseNot => {
                    let value = self.evaluate(operand)?;
                    // v2 says that the bitwise not wants a number here, and
                    // not a whole one: the message is the one of the number.
                    Ok(Value::Int(!self.the_whole_number(
                        &value,
                        *line,
                        TypeName::Number,
                    )?))
                }
                // The reference operator: `&x`.
                //
                // The operator is carried by the arguments of a call, and
                // it points at the variable of the scope that is running:
                // a function has variables of its own, the way v2 has
                // them.
                UnaryOp::Address => {
                    let Node::Var { name, .. } = operand.as_ref() else {
                        return Err(RuntimeFailure::Error(RuntimeError {
                            message: "\"&\" requires a variable.".into(),
                            line: *line,
                        }));
                    };
                    // A built-in variable, a function and a class cannot
                    // have their reference taken, and v2 says which one
                    // of them it is.
                    if let Some(kind) = self.cannot_be_referenced(name) {
                        return Err(RuntimeFailure::Error(RuntimeError {
                            message: format!(
                                "This {kind} cannot have its reference taken.\n     Specifically: {name}"
                            ),
                            line: *line,
                        }));
                    }
                    let scope = match self.scopes.len() {
                        0 => Scope::Global,
                        depth => Scope::Local(depth - 1),
                    };
                    Ok(Value::Reference(Reference {
                        name: name.clone(),
                        scope,
                        alias: false,
                    }))
                }
            },
            Node::Binary {
                op,
                left,
                right,
                line,
            } => {
                let line = *line;
                // The or-maybe is about a variable that may have no value
                // at all, so its left side is not read the way the other
                // operators read their left side.
                if *op == BinaryOp::Coalesce {
                    let Node::Var { name, .. } = left.as_ref() else {
                        return Err(RuntimeFailure::Error(RuntimeError {
                            message: "the left side of ?? must be a variable".into(),
                            line,
                        }));
                    };
                    if let Some(value) = self.lookup(name) {
                        return Ok(value);
                    }
                    return self.evaluate(right);
                }
                let left_value = self.evaluate(left)?;
                match op {
                    // `and` and `or` answer the operand and not a truth:
                    // v2 hands back the last one that was true, or the
                    // first one that was not.
                    //
                    // Measured on the binary of AutoHotkey v1.1.37.02 on
                    // 2026-11-04: the `&&` and the `||` of the v1 answer
                    // one and zero, and not the operand: the `"a" && "b"`
                    // is 1.
                    BinaryOp::And => {
                        if !self.the_operand_is_true(left, &left_value) {
                            return Ok(self.the_answer_of_the_boolean(left, &left_value));
                        }
                        // Measured on the binary of AutoHotkey v1.1.37.02 on
                        // 2026-11-04: the operand that is not there poisons
                        // the operation that holds it: the `1 and` is the
                        // empty text, and not the zero that the `1 and ""`
                        // answers.
                        if matches!(right.as_ref(), Node::Unset { .. }) {
                            return Ok(Value::Text(String::new()));
                        }
                        let right_value = self.evaluate(right)?;
                        return Ok(self.the_answer_of_the_boolean(right, &right_value));
                    }
                    BinaryOp::Or => {
                        if self.the_operand_is_true(left, &left_value) {
                            return Ok(self.the_answer_of_the_boolean(left, &left_value));
                        }
                        if matches!(right.as_ref(), Node::Unset { .. }) {
                            return Ok(Value::Text(String::new()));
                        }
                        let right_value = self.evaluate(right)?;
                        return Ok(self.the_answer_of_the_boolean(right, &right_value));
                    }
                    _ => {}
                }
                let right_value = self.evaluate(right)?;
                // The arithmetic of the v1 is not the one of the v2: the text
                // that is written between quotes is a string, and the value
                // of a variable is a number when it can be one.
                let (left_value, right_value) = if self
                    .dialect
                    .a_value_that_is_not_a_number_is_blank()
                {
                    // The sum of a text that is written is a concatenation.
                    if *op == BinaryOp::Add && self.the_node_is_a_quoted_text(left) {
                        let text =
                            format!("{}{}", left_value.to_text(), self.the_text_of(&right_value));
                        return Ok(Value::Text(text));
                    }
                    // The comparison is a number when both sides are numbers,
                    // and a text otherwise.
                    if matches!(
                        op,
                        BinaryOp::Less
                            | BinaryOp::Greater
                            | BinaryOp::LessEqual
                            | BinaryOp::GreaterEqual
                    ) {
                        let answer = self.the_comparison_of_the_v1(
                            left,
                            right,
                            &left_value,
                            &right_value,
                            op,
                        );
                        return Ok(Value::Int(answer as i64));
                    }
                    if matches!(op, BinaryOp::Equal | BinaryOp::NotEqual) {
                        // The equal sign of the v1 is always without regard
                        // to the case, and the method of the locale is the
                        // one it uses when the sense of the case is On. The
                        // not equal sign follows the sense of the case.
                        let method = match op {
                            BinaryOp::Equal => self.case_sense.the_method_of_the_equal_sign(),
                            _ => self.case_sense.the_method(),
                        };
                        // Measured on the binary of v1.1.37.02 on 2026-11-02:
                        // the comparison is a number when both sides are
                        // numbers, and a text otherwise: the "0x10" is the
                        // number 16, and the "0x10" that is written between
                        // quotes is a text that is not a number.
                        let same = match (
                            self.the_number_of_the_v1(left, &left_value),
                            self.the_number_of_the_v1(right, &right_value),
                        ) {
                            (Some(one), Some(other)) => the_same_number(&one, &other),
                            _ => {
                                the_same_text(&left_value.to_text(), &right_value.to_text(), method)
                            }
                        };
                        let answer = match op {
                            BinaryOp::Equal => same,
                            _ => !same,
                        };
                        return Ok(Value::Int(answer as i64));
                    }
                    if matches!(
                        op,
                        BinaryOp::StrictEqual
                            | BinaryOp::StrictNotEqual
                            | BinaryOp::Concat
                            | BinaryOp::RegexMatch
                    ) {
                        // The equality compares the values as they are, and
                        // the concatenation wants the text of them.
                        (left_value, right_value)
                    } else {
                        // The operands of the arithmetic are numbers: the text
                        // that is written between quotes is not one, and the
                        // value of a variable is one when it can be.
                        let left = self.the_number_of_the_v1(left, &left_value);
                        let right = self.the_number_of_the_v1(right, &right_value);
                        match (left, right) {
                            (Some(left), Some(right)) => (left, right),
                            // A value that is not a number makes the operation
                            // blank, and it is not a failure.
                            _ => return Ok(Value::Text(String::new())),
                        }
                    }
                } else {
                    (left_value, right_value)
                };
                Ok(match op {
                    BinaryOp::Equal => {
                        Value::Int(values_equal(&left_value, &right_value, false) as i64)
                    }
                    BinaryOp::NotEqual => {
                        Value::Int(!values_equal(&left_value, &right_value, false) as i64)
                    }
                    BinaryOp::StrictEqual => {
                        Value::Int(values_equal(&left_value, &right_value, true) as i64)
                    }
                    BinaryOp::StrictNotEqual => {
                        Value::Int(!values_equal(&left_value, &right_value, true) as i64)
                    }
                    BinaryOp::Less => {
                        let a = self.number(&left_value, line)?;
                        let b = self.number(&right_value, line)?;
                        Value::Int((a < b) as i64)
                    }
                    BinaryOp::Greater => {
                        let a = self.number(&left_value, line)?;
                        let b = self.number(&right_value, line)?;
                        Value::Int((a > b) as i64)
                    }
                    BinaryOp::LessEqual => {
                        let a = self.number(&left_value, line)?;
                        let b = self.number(&right_value, line)?;
                        Value::Int((a <= b) as i64)
                    }
                    BinaryOp::GreaterEqual => {
                        let a = self.number(&left_value, line)?;
                        let b = self.number(&right_value, line)?;
                        Value::Int((a >= b) as i64)
                    }
                    BinaryOp::Add => {
                        // Measured on the binary of v1.1.37.02 on 2026-11-01:
                        // the sum of the v1 joins a text and a number: `"5" +
                        // 1` is `51`, and the sum of two numbers is a number.
                        //
                        // Measured on the binary of v1.1.37.02 on 2026-11-02:
                        // the whole number that does not fit in the machine
                        // wraps the way the machine does: the sum of the
                        // 9223372036854775807 and the one is
                        // -9223372036854775808, and the product of it and the
                        // two is -2.
                        if self.dialect.add_concatenates()
                            && (matches!(left_value, Value::Text(_))
                                || matches!(right_value, Value::Text(_)))
                        {
                            Value::Text(format!(
                                "{}{}",
                                left_value.to_text(),
                                right_value.to_text()
                            ))
                        } else {
                            let a = self.number(&left_value, line)?;
                            let b = self.number(&right_value, line)?;
                            match (&left_value, &right_value) {
                                (Value::Int(a), Value::Int(b)) => Value::Int(a.wrapping_add(*b)),
                                _ => Value::Float(a + b),
                            }
                        }
                    }
                    BinaryOp::Subtract => {
                        let a = self.number(&left_value, line)?;
                        let b = self.number(&right_value, line)?;
                        match (&left_value, &right_value) {
                            (Value::Int(a), Value::Int(b)) => Value::Int(a.wrapping_sub(*b)),
                            _ => Value::Float(a - b),
                        }
                    }
                    BinaryOp::Multiply => {
                        let a = self.number(&left_value, line)?;
                        let b = self.number(&right_value, line)?;
                        match (&left_value, &right_value) {
                            (Value::Int(a), Value::Int(b)) => Value::Int(a.wrapping_mul(*b)),
                            _ => Value::Float(a * b),
                        }
                    }
                    BinaryOp::Divide => {
                        let a = self.number(&left_value, line)?;
                        let b = self.number(&right_value, line)?;
                        if b == 0.0 {
                            // Measured on the binary of v1.1.37.02 on 2026-11-01:
                            // the division by zero of the v1 is a blank result
                            // and not a failure.
                            if self.dialect.division_by_zero_is_blank() {
                                return Ok(Value::Text(String::new()));
                            }
                            return Err(RuntimeFailure::Error(RuntimeError {
                                message: "Divide by zero.".into(),
                                line,
                            }));
                        }
                        Value::Float(a / b)
                    }
                    BinaryOp::IntegerDivide => {
                        let a = self.integer(&left_value, line)?;
                        let b = self.integer(&right_value, line)?;
                        if b == 0 {
                            return Err(RuntimeFailure::Error(RuntimeError {
                                message: "Divide by zero.".into(),
                                line,
                            }));
                        }
                        Value::Int(a.wrapping_div(b))
                    }
                    BinaryOp::Power => {
                        let a = self.number(&left_value, line)?;
                        let b = self.number(&right_value, line)?;
                        // Two whole numbers with a whole exponent give a
                        // whole number; a negative exponent gives a float.
                        if let (Value::Int(base), Value::Int(exponent)) =
                            (&left_value, &right_value)
                        {
                            if *exponent >= 0 && *exponent <= 63 {
                                if let Some(power) = base.checked_pow(*exponent as u32) {
                                    return Ok(Value::Int(power));
                                }
                            }
                        }
                        Value::Float(powf(a, b))
                    }
                    BinaryOp::BitwiseAnd => {
                        let a = self.integer(&left_value, line)?;
                        let b = self.integer(&right_value, line)?;
                        Value::Int(a & b)
                    }
                    BinaryOp::BitwiseOr => {
                        let a = self.integer(&left_value, line)?;
                        let b = self.integer(&right_value, line)?;
                        Value::Int(a | b)
                    }
                    BinaryOp::BitwiseXor => {
                        let a = self.integer(&left_value, line)?;
                        let b = self.integer(&right_value, line)?;
                        Value::Int(a ^ b)
                    }
                    BinaryOp::ShiftLeft => {
                        let a = self.integer(&left_value, line)?;
                        let b = self.shift(&right_value, line)?;
                        Value::Int(a.wrapping_shl(b))
                    }
                    BinaryOp::ShiftRight => {
                        let a = self.integer(&left_value, line)?;
                        let b = self.shift(&right_value, line)?;
                        Value::Int(a.wrapping_shr(b))
                    }
                    BinaryOp::ShiftRightUnsigned => {
                        let a = self.integer(&left_value, line)? as u64;
                        let b = self.shift(&right_value, line)?;
                        Value::Int((a >> b) as i64)
                    }
                    BinaryOp::Concat => {
                        let left_text = self.the_text_of_the_concat(&left_value, line)?;
                        let right_text = self.the_text_of_the_concat(&right_value, line)?;
                        Value::Text(format!("{left_text}{right_text}"))
                    }
                    BinaryOp::RegexMatch => {
                        let text = left_value.to_text();
                        let pattern = right_value.to_text();
                        match crate::regex::find(&text, &pattern) {
                            Ok(Some(position)) => Value::Int(position as i64),
                            Ok(None) => Value::Int(0),
                            Err(reason) => {
                                return Err(RuntimeFailure::Error(RuntimeError {
                                    message: reason,
                                    line,
                                }));
                            }
                        }
                    }
                    BinaryOp::Is => {
                        // The right side has to be a class, and v2 says so
                        // when it is not.
                        //
                        // Measured on the binary of v2.0.19 on 2026-10-31:
                        // the value that arrived goes in the `Extra` of the
                        // failure, and the `What` is empty.
                        let Some(class) = self.class_name_of(&right_value) else {
                            return Err(RuntimeFailure::Detailed(
                                RuntimeError {
                                    message: expected_type(
                                        TypeName::Class,
                                        right_value.type_name(),
                                    ),
                                    line,
                                },
                                Detail {
                                    what: String::new(),
                                    extra: the_extra_of_the_value(&right_value),
                                },
                            ));
                        };
                        let answer = match &left_value {
                            Value::Object(object) => {
                                let name = object.borrow().class.clone();
                                // Every object is an Object: it is the root
                                // of the chain of the classes.
                                class == "object" || self.class_chain(&name).contains(&class)
                            }
                            // A number and a text are not objects, and v2
                            // still knows their classes: `3 is Integer` is
                            // one and `3 is Object` is zero. The class of the
                            // value is the one of the kinds of v2, and the
                            // chain of it goes up through the `Number` and
                            // the `Primitive` to the `Any`.
                            _ => {
                                let name = left_value.type_name().name().to_lowercase();
                                class == "any"
                                    || class == name
                                    || self.class_chain(&name).contains(&class)
                            }
                        };
                        Value::Int(answer as i64)
                    }
                    BinaryOp::And | BinaryOp::Or | BinaryOp::Coalesce => {
                        unreachable!("handled above")
                    }
                })
            }
            Node::Call {
                name,
                arguments,
                line,
            } => self.call(name, arguments, *line),
            Node::New {
                path,
                arguments,
                line,
            } => self.new_instance(path, arguments, *line),
            Node::MethodCall {
                target,
                name,
                arguments,
                line,
            } => {
                // `super.m()`: the method of the base.
                if let Node::Super { .. } = &**target {
                    let name = self.the_name_of_the_member(name, *line)?;
                    return self.call_the_method_of_the_base(&name, arguments, *line);
                }
                let target_value = self.evaluate(target)?;
                let name = self.the_name_of_the_member(name, *line)?;
                self.call_method_on(&target_value, &name, arguments, *line)
            }
            Node::Property { target, name, line } => {
                // `super.value`: the property of the base.
                if let Node::Super { .. } = &**target {
                    let name = self.the_name_of_the_member(name, *line)?;
                    return self.read_the_property_of_the_base(&name, *line);
                }
                let target_value = self.evaluate(target)?;
                let name = self.the_name_of_the_member(name, *line)?;
                self.read_property(&target_value, &name, *line)
            }
            Node::Index {
                target,
                index,
                line,
            } => {
                // `super["value"]`: the item of the base.
                if let Node::Super { .. } = &**target {
                    let key = self.evaluate(index)?;
                    return self.read_the_item_of_the_base(&key, *line);
                }
                let key = self.evaluate(index)?;
                // `x.y[z]`: the `__Get` of `x.y` is asked with the
                // parameters of the access, and the value it answers is
                // the one that is indexed.
                if let Node::Property {
                    target: object,
                    name,
                    line: property_line,
                } = &**target
                {
                    let object_value = self.evaluate(object)?;
                    let name = self.the_name_of_the_member(name, *property_line)?;
                    let (value, by_meta) = self.read_property_fully(
                        &object_value,
                        &name,
                        core::slice::from_ref(&key),
                        *property_line,
                    )?;
                    // The meta-function of a class handles the whole
                    // access: the brackets are its parameters and its
                    // answer is the answer.
                    if by_meta {
                        return Ok(value);
                    }
                    return self.index_a_value(&value, &key, *line);
                }
                let target = self.evaluate(target)?;
                self.index_a_value(&target, &key, *line)
            }
            Node::Ternary {
                condition,
                then,
                otherwise,
                ..
            } => {
                let value = self.evaluate(condition)?;
                if self.the_value_is_true(&value) {
                    self.evaluate(then)
                } else {
                    self.evaluate(otherwise)
                }
            }
            Node::DynamicName { pieces, line } => {
                // Measured on the binary of v2.0.19 on 2026-10-31: the name
                // of the variable is the one that the pieces make, and a name
                // that is not a variable fails with "Variable not found." and
                // the name in the `Extra`.
                let name = self.the_name_of_the_pieces(pieces, *line)?;
                match self.the_variable_of_the_name(&name, *line)? {
                    Some(value) => Ok(value),
                    None => {
                        // Measured on the binary of AutoHotkey v1.1.37.02 on
                        // 2026-11-04: the v1 does not refuse the name that is
                        // not there: it creates the variable of that name and
                        // reads it, and the answer is the empty text.
                        if self
                            .dialect
                            .the_name_that_the_script_builds_and_that_is_not_there_is_answered()
                        {
                            return Ok(Value::Text(String::new()));
                        }
                        Err(RuntimeFailure::Detailed(
                            RuntimeError {
                                message: "Variable not found.".to_string(),
                                line: *line,
                            },
                            Detail {
                                what: String::new(),
                                extra: name,
                            },
                        ))
                    }
                }
            }
            Node::AssignDynamic {
                name,
                op,
                value,
                line,
            } => {
                let name = self.the_name_of_the_pieces(name, *line)?;
                let value = self.evaluate(value)?;
                self.write_a_dynamic_name(&name, *op, value, *line)?;
                Ok(Value::Text(String::new()))
            }
            Node::Expression { .. }
            | Node::LegacyExpression { .. }
            | Node::Block { .. }
            | Node::LegacyCall { .. }
            | Node::LegacyIf { .. }
            | Node::LegacyAssign { .. }
            | Node::If { .. }
            | Node::Switch { .. }
            | Node::While { .. }
            | Node::Try { .. }
            | Node::Throw { .. }
            | Node::Loop { .. }
            | Node::Break { .. }
            | Node::Continue { .. }
            | Node::Label { .. }
            | Node::Goto { .. }
            | Node::HotkeyDefinition { .. }
            | Node::Return { .. }
            | Node::ExitApp { .. }
            | Node::FunctionDef { .. }
            | Node::Directive { .. }
            | Node::ClassDef { .. } => Err(RuntimeFailure::Error(RuntimeError {
                message: "this is a statement, not an expression".into(),
                line: node.line(),
            })),
        }
    }

    /// Replace `%name%` with the value of the name.
    ///
    /// AutoHotkey's way of putting a variable in a string. A `%` that is
    /// not a complete `%name%` is left alone, so a path with a percent
    /// sign in it survives. A name that is not set is left alone too.
    ///
    /// The name may be a path: `%object.property%` is the property of
    /// the object, and the path may go deeper. The string is read where
    /// it is written, so the name that answers is the name of the scope
    /// that is writing it.
    ///
    /// A name that the runtime cannot answer fails the statement with
    /// the reason, the way the bare name does.
    pub(crate) fn interpolate(&mut self, text: &str, line: u32) -> Result<String, RuntimeError> {
        if !text.contains('%') {
            return Ok(text.to_string());
        }
        let mut out = String::with_capacity(text.len());
        let chars: Vec<char> = text.chars().collect();
        let mut index = 0usize;
        while index < chars.len() {
            if chars[index] == '%' {
                if let Some(offset) = chars[index + 1..].iter().position(|c| *c == '%') {
                    let close = index + 1 + offset;
                    let reference: String = chars[index + 1..close].iter().collect();
                    if let Some(value) = self.resolve_reference(reference.trim(), line)? {
                        let text = value.as_text().map_err(|got| RuntimeError {
                            message: expected_type(TypeName::String, got),
                            line,
                        })?;
                        out.push_str(&text);
                        index = close + 1;
                        continue;
                    }
                    out.push_str(&chars[index..=close].iter().collect::<String>());
                    index = close + 1;
                    continue;
                }
                out.extend(&chars[index..]);
                break;
            }
            out.push(chars[index]);
            index += 1;
        }
        Ok(out)
    }

    /// Write an item of a value: `obj[key] := value`.
    ///
    /// The write goes to the class that owns the value: the map and the
    /// array know how to write an item of theirs. A class of the script
    /// has no way to write one, and v2.0.19 asks nothing else of it:
    /// the meta-functions answer for the properties that are not there,
    /// and `x[y]` asks only the `__Item` property.
    fn set_item(
        &mut self,
        target: &Value,
        key: &Value,
        op: AssignOp,
        value: Value,
        line: u32,
    ) -> Result<Value, RuntimeFailure> {
        // Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-04: the
        // write of the item of a value that is not an object is dropped by
        // the v1.
        let Value::Object(object) = target else {
            if self.dialect.the_item_of_an_object_is_its_property()
                && self
                    .dialect
                    .the_write_of_a_property_of_a_value_that_is_not_an_object_is_dropped()
            {
                return Ok(value);
            }
            return Err(self.no_item(target, line));
        };
        let class = object.borrow().class.clone();
        // The compound operators read what is there before they write.
        let value = match op {
            AssignOp::Set => value,
            other => {
                let current = self.read_item(target, key, line)?;
                // Measured on the binary of AutoHotkey v1.1.37.02 on
                // 2026-11-04: the v1 does not write the item when the value
                // that is there is not a number: the `a[5] += 2` of an array
                // of two leaves the place as it was.
                if self
                    .dialect
                    .the_compound_write_of_a_thing_that_is_not_a_number_is_dropped()
                    && !matches!(op, AssignOp::Set | AssignOp::Concat)
                    && !self.the_value_is_a_number_of_the_v1(&current)
                {
                    return Ok(current);
                }
                self.apply_assign(other, "the item", Some(current), value, line)?
            }
        };
        if let Some(result) =
            crate::classes::set_item(&class, key, target, value.clone(), self, line)
        {
            result?;
            return Ok(value);
        }
        // Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-04: the
        // item of an object of the v1 is the property of that name: the
        // `a["b"] := 5` writes the property "b".
        if self.dialect.the_item_of_an_object_is_its_property() {
            let name = key.to_text();
            let current = match op {
                AssignOp::Set => self.read_property(target, &name, line).ok(),
                _ => Some(self.read_property(target, &name, line)?),
            };
            let stored = self.apply_assign(op, &name, current, value, line)?;
            self.write_property(target, &name, stored.clone(), line)?;
            return Ok(stored);
        }
        Err(self.no_item(target, line))
    }

    /// The value of an item of an object: `obj[key]`.
    fn read_item(
        &mut self,
        target: &Value,
        key: &Value,
        line: u32,
    ) -> Result<Value, RuntimeFailure> {
        let Value::Object(object) = target else {
            // Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-04:
            // the v1 does not refuse the item of a value that is not an
            // object, and the answer is a blank text.
            if self.dialect.a_member_that_is_not_there_is_answered() {
                return Ok(Value::Text(String::new()));
            }
            return Err(self.no_item(target, line));
        };
        let class = object.borrow().class.clone();
        // The class of the script first, and then the class types of the
        // runtime.
        //
        // Measured on the binary of v2.0.19 on 2026-10-31: the item of an
        // object of a class of the script is the property `__Item` of it,
        // and the getter of it takes the index.
        if let Some(access) = self.the_accessor_of(target, "__Item") {
            let Some(getter) = &access.getter else {
                return Err(self.no_item(target, line));
            };
            if access.parameters.is_empty() {
                // The index goes to the `__Item` of the value that the
                // getter answers.
                //
                // Measured on the binary of v2.0.19 on 2026-10-31:
                // `obj["a"]` is refused with 'This value of type "Integer"
                // has no property named "__Item".' when the getter answers
                // a number.
                let value =
                    self.call_the_body_of_an_accessor(target, &access, getter, line, &[], None)?;
                return self.read_item(&value, key, line);
            }
            // The parameters of the property are the ones of the index.
            let value = self.call_the_body_of_an_accessor(
                target,
                &access,
                getter,
                line,
                core::slice::from_ref(key),
                None,
            )?;
            return Ok(value);
        }
        // A method of that name is not the item of the object: the item is
        // the method itself.
        //
        // Measured on the binary of v2.0.19 on 2026-10-31: `obj[3]` is a
        // function whose name is "C.Prototype.__Item" when the class
        // declares a method of that name.
        if let Some((defining, method)) = self.find_method_in(&class, "__item") {
            return Ok(self.method_reference(&defining, &method));
        }
        if let Some(result) = crate::classes::item(&class, key, target, self, line) {
            return result;
        }
        // Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-04: the
        // item of an object of the v1 is the property of that name: the
        // `a["b"]` reads the property "b", and the `a["B"]` reads it too.
        // The v2 asks the `__Item` of the object, and a plain object of it
        // has no such thing.
        if self.dialect.the_item_of_an_object_is_its_property() {
            let name = key.to_text();
            return self.read_property(target, &name, line);
        }
        // The `__Item` of the class is the method behind the index syntax,
        // and a class that has one answers it.
        if let Some(result) = crate::classes::call(
            &class,
            "__item",
            target,
            core::slice::from_ref(key),
            self,
            line,
        ) {
            return result;
        }
        // Measured on the binary of v1.1.37.02 on 2026-11-02: the v1 does
        // not refuse the item that an object does not have, and the answer is
        // a blank text.
        if self.dialect.a_member_that_is_not_there_is_answered() {
            return Ok(Value::Text(String::new()));
        }
        Err(self.no_item(target, line))
    }

    /// The value of a reference: a name, or a path of names.
    ///
    /// `p.x` is the property `x` of the object `p`, and the path may go
    /// deeper. A name that is not set has no value, and a path that
    /// breaks has none either: the text is left alone, the way
    /// AutoHotkey leaves it alone.
    ///
    /// A name that is one of the built-in variables is answered by the
    /// table of them, and one that the runtime cannot answer fails with
    /// the reason.
    fn resolve_reference(
        &mut self,
        reference: &str,
        line: u32,
    ) -> Result<Option<Value>, RuntimeError> {
        let mut parts = reference.split('.');
        let Some(name) = parts.next() else {
            return Ok(None);
        };
        let found = self.lookup(name);
        let mut value = match found {
            Some(value) => value,
            // The name may be one of the built-in variables: the table of
            // them knows whether it is one, and the runtime may not be
            // able to answer it.
            None => match self.the_built_in_variable(name) {
                Some(Ok(value)) => value,
                Some(Err(error)) => {
                    return Err(RuntimeError {
                        message: error.message,
                        line,
                    });
                }
                // A name that is not set is left alone.
                None => return Ok(None),
            },
        };
        for part in parts {
            let Ok(next) = self.read_property(&value, part, line) else {
                return Ok(None);
            };
            value = next;
        }
        Ok(Some(value))
    }

    /// The name that the pieces of the script make.
    ///
    /// Measured on the binary of v2.0.19 on 2026-10-31: the value of a
    /// piece is a text or a reference, and a value of another kind is
    /// refused with the kind of it.
    fn the_name_of_the_pieces(
        &mut self,
        pieces: &[DynamicPiece],
        line: u32,
    ) -> Result<String, RuntimeFailure> {
        let mut name = String::new();
        for piece in pieces {
            match piece {
                DynamicPiece::Text(text) => name.push_str(text),
                DynamicPiece::Value(value) => {
                    let value = self.evaluate(value)?;
                    match &value {
                        Value::Text(text) => name.push_str(text),
                        Value::Int(_) | Value::Float(_) => name.push_str(&value.to_text()),
                        Value::Reference(reference) => name.push_str(&reference.name),
                        other => {
                            let kind = other.the_kind();
                            return Err(RuntimeFailure::Error(RuntimeError {
                                message: format!(
                                    "Expected a String or VarRef but got a{} {}.",
                                    the_article_of(&kind),
                                    kind
                                ),
                                line,
                            }));
                        }
                    }
                }
            }
        }
        Ok(name)
    }

    /// The name of a member, when the script builds it.
    ///
    /// Measured on the binary of v2.0.19 on 2026-10-31: the name of the
    /// member is the text that is written and the values of the
    /// expressions, and `m.%x%` is the member whose name is the value of
    /// `x`.
    fn the_name_of_the_member(
        &mut self,
        name: &MemberName,
        line: u32,
    ) -> Result<String, RuntimeFailure> {
        match name {
            MemberName::Text(text) => Ok(text.clone()),
            MemberName::Dynamic(pieces) => self.the_name_of_the_pieces(pieces, line),
        }
    }

    /// The value of the variable of that name.
    ///
    /// Measured on the binary of v2.0.19 on 2026-10-31: the name of a
    /// dynamic variable reference is the name of a variable, and not a path
    /// of names: `%m.a%` is the variable `m.a`, and it is not there. The
    /// name is looked up the way a name that is written is looked up: a
    /// function of the script and a class are values too.
    fn the_variable_of_the_name(
        &mut self,
        name: &str,
        line: u32,
    ) -> Result<Option<Value>, RuntimeFailure> {
        if let Some(value) = self.lookup(name) {
            return Ok(Some(value));
        }
        match self.the_built_in_variable(name) {
            Some(Ok(value)) => Ok(Some(value)),
            Some(Err(error)) => Err(RuntimeFailure::Error(RuntimeError {
                message: error.message,
                line,
            })),
            None => Ok(None),
        }
    }

    /// The write of a name that the script builds.
    ///
    /// Measured on the binary of v2.0.19 on 2026-10-31: the variable has to
    /// be there, and a function that writes a name of the script says that
    /// it wants a global declaration.
    fn write_a_dynamic_name(
        &mut self,
        name: &str,
        op: AssignOp,
        value: Value,
        line: u32,
    ) -> Result<Value, RuntimeFailure> {
        let key = the_key_of(name);
        // Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-04: the
        // v1 refuses the write of a name that the script builds inside a
        // function, and it refuses it whatever the variable of that name is.
        if self.declarations.last().is_some()
            && self
                .dialect
                .the_dynamic_write_inside_a_function_is_refused()
        {
            return Err(RuntimeFailure::Detailed(
                RuntimeError {
                    message: self
                        .dialect
                        .the_message_of_the_dynamic_write_inside_a_function()
                        .to_string(),
                    line,
                },
                Detail {
                    what: String::new(),
                    extra: name.to_string(),
                },
            ));
        }
        // A dynamic reference does not create a variable: the one that is
        // written has to be there.
        let exists = self.lookup_variable(name).is_some() || self.variables.contains_key(&key);
        if !exists {
            // Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-04:
            // the v1 creates the variable of the name that the script builds
            // and writes it: the `a := 1` and the `%a% := 7` write the
            // variable "1".
            if self
                .dialect
                .the_name_that_the_script_builds_and_that_is_not_there_is_answered()
            {
                self.assign(name, Value::Text(String::new()));
            } else {
                return Err(RuntimeFailure::Detailed(
                    RuntimeError {
                        message: "Variable not found.".to_string(),
                        line,
                    },
                    Detail {
                        what: String::new(),
                        extra: name.to_string(),
                    },
                ));
            }
        }
        // A function that writes a name of the script says that it wants a
        // global declaration: the name is not a local of the function.
        let is_local = self
            .scopes
            .last()
            .map(|scope| scope.borrow().contains_key(&key))
            .unwrap_or(false)
            || self.is_declared_local(&key);
        if self.declarations.last().is_some() && !is_local && !self.lives_in_the_script(&key) {
            return Err(RuntimeFailure::Detailed(
                RuntimeError {
                    message: "This dynamic assignment requires a \"global\" declaration."
                        .to_string(),
                    line,
                },
                Detail {
                    what: String::new(),
                    extra: name.to_string(),
                },
            ));
        }
        // The compound operators read the variable before they write it.
        let current = self.lookup_variable(name);
        let stored = self.apply_assign(op, name, current, value, line)?;
        self.assign(name, stored.clone());
        Ok(stored)
    }
}

// -- the arithmetic -------------------------------------------------------------
//
// `f64::sqrt` and its neighbours live in `std`: they call the platform's
// library. A target with no `std` takes the same numbers from `math`, the
// same maths in this crate, so the language answers the same on both.

/// The square root of `value`.
#[cfg(feature = "std")]
pub(crate) fn sqrt(value: f64) -> f64 {
    value.sqrt()
}

/// The square root of `value`.
#[cfg(not(feature = "std"))]
pub(crate) fn sqrt(value: f64) -> f64 {
    crate::math::sqrt(value)
}

/// The largest whole number that is not greater than `value`.
#[cfg(feature = "std")]
pub(crate) fn floor(value: f64) -> f64 {
    value.floor()
}

/// The largest whole number that is not greater than `value`.
#[cfg(not(feature = "std"))]
pub(crate) fn floor(value: f64) -> f64 {
    crate::math::floor(value)
}

/// The smallest whole number that is not less than `value`.
#[cfg(feature = "std")]
pub(crate) fn ceil(value: f64) -> f64 {
    value.ceil()
}

/// The smallest whole number that is not less than `value`.
#[cfg(not(feature = "std"))]
pub(crate) fn ceil(value: f64) -> f64 {
    crate::math::ceil(value)
}

/// `value` rounded to the nearest whole number, halves away from zero.
#[cfg(feature = "std")]
pub(crate) fn round(value: f64) -> f64 {
    value.round()
}

/// `value` rounded to the nearest whole number, halves away from zero.
#[cfg(not(feature = "std"))]
pub(crate) fn round(value: f64) -> f64 {
    crate::math::round(value)
}

/// The power of two numbers.
///
/// The same shape as the square root: `std` has it, and `math` has it
/// for a target that has no `std`.
#[cfg(feature = "std")]
pub(crate) fn powf(base: f64, exponent: f64) -> f64 {
    base.powf(exponent)
}

/// The power of two numbers.
#[cfg(not(feature = "std"))]
pub(crate) fn powf(base: f64, exponent: f64) -> f64 {
    crate::math::pow(base, exponent)
}

/// The arc cosine of `value`.
#[cfg(feature = "std")]
pub(crate) fn acos(value: f64) -> f64 {
    value.acos()
}

/// The arc cosine of `value`.
#[cfg(not(feature = "std"))]
pub(crate) fn acos(value: f64) -> f64 {
    crate::math::acos(value)
}

/// The arc sine of `value`.
#[cfg(feature = "std")]
pub(crate) fn asin(value: f64) -> f64 {
    value.asin()
}

/// The arc sine of `value`.
#[cfg(not(feature = "std"))]
pub(crate) fn asin(value: f64) -> f64 {
    crate::math::asin(value)
}

/// The arc tangent of `value`.
#[cfg(feature = "std")]
pub(crate) fn atan(value: f64) -> f64 {
    value.atan()
}

/// The arc tangent of `value`.
#[cfg(not(feature = "std"))]
pub(crate) fn atan(value: f64) -> f64 {
    crate::math::atan(value)
}

/// The cosine of `value`.
#[cfg(feature = "std")]
pub(crate) fn cos(value: f64) -> f64 {
    value.cos()
}

/// The cosine of `value`.
#[cfg(not(feature = "std"))]
pub(crate) fn cos(value: f64) -> f64 {
    crate::math::cos(value)
}

/// The sine of `value`.
#[cfg(feature = "std")]
pub(crate) fn sin(value: f64) -> f64 {
    value.sin()
}

/// The sine of `value`.
#[cfg(not(feature = "std"))]
pub(crate) fn sin(value: f64) -> f64 {
    crate::math::sin(value)
}

/// The tangent of `value`.
#[cfg(feature = "std")]
pub(crate) fn tan(value: f64) -> f64 {
    value.tan()
}

/// The tangent of `value`.
#[cfg(not(feature = "std"))]
pub(crate) fn tan(value: f64) -> f64 {
    crate::math::tan(value)
}

/// The exponential of `value`.
#[cfg(feature = "std")]
pub(crate) fn exp(value: f64) -> f64 {
    value.exp()
}

/// The exponential of `value`.
#[cfg(not(feature = "std"))]
pub(crate) fn exp(value: f64) -> f64 {
    crate::math::exp(value)
}

/// The natural logarithm of `value`.
#[cfg(feature = "std")]
pub(crate) fn ln(value: f64) -> f64 {
    value.ln()
}

/// The natural logarithm of `value`.
#[cfg(not(feature = "std"))]
pub(crate) fn ln(value: f64) -> f64 {
    crate::math::ln(value)
}

/// The logarithm of `value` in base ten.
#[cfg(feature = "std")]
pub(crate) fn log10(value: f64) -> f64 {
    value.log10()
}

/// The logarithm of `value` in base ten.
#[cfg(not(feature = "std"))]
pub(crate) fn log10(value: f64) -> f64 {
    crate::math::log10(value)
}

/// The fractional part of `value`: it keeps the sign of the value.
#[cfg(feature = "std")]
pub(crate) fn fract(value: f64) -> f64 {
    value.fract()
}

/// The fractional part of `value`: it keeps the sign of the value.
#[cfg(not(feature = "std"))]
pub(crate) fn fract(value: f64) -> f64 {
    value - crate::math::trunc(value)
}

/// The whole part of `value`: the number without its fraction.
#[cfg(feature = "std")]
fn trunc(value: f64) -> f64 {
    value.trunc()
}

/// The whole part of `value`: the number without its fraction.
#[cfg(not(feature = "std"))]
fn trunc(value: f64) -> f64 {
    crate::math::trunc(value)
}

/// `value` raised to a whole power.
///
/// The loop is the same in both configurations, so the two answers agree
/// to the last bit: the dialect cannot depend on the target.
pub(crate) fn powi(value: f64, exponent: i32) -> f64 {
    let mut result = 1.0f64;
    let mut factor = value;
    let mut rest = exponent.unsigned_abs();
    while rest > 0 {
        if rest & 1 == 1 {
            result *= factor;
        }
        factor *= factor;
        rest >>= 1;
    }
    if exponent < 0 { 1.0 / result } else { result }
}

/// The value of a function: an object of the class `Func`.
///
/// A function in a script is a value, and `Func` is the class of it.
fn func_value(name: &str, function: &Function) -> Value {
    // The fewest parameters are the ones that have no default, and the
    // most are all of them.
    let fewest = function
        .parameters
        .iter()
        .filter(|parameter| parameter.default.is_none() && !parameter.variadic)
        .count();
    let mut properties: BTreeMap<String, Property> = BTreeMap::new();
    put(&mut properties, "name", Value::Text(name.to_string()));
    put(&mut properties, "minparams", Value::Int(fewest as i64));
    put(
        &mut properties,
        "maxparams",
        Value::Int(function.parameters.len() as i64),
    );
    put(&mut properties, "isbuiltin", Value::Int(0));
    put(&mut properties, "isvariadic", Value::Int(0));
    Value::Object(Rc::new(RefCell::new(Object {
        class: "func".to_string(),
        properties,
    })))
}

/// The value of a closure: an object of the class `Func`.
///
/// The name of a closure of v2 is empty, and the name under which the
/// runtime keeps it is in the object and not in the name.
fn closure_value(name: &str, function: &Function) -> Value {
    let value = func_value("", function);
    if let Value::Object(object) = &value {
        object
            .borrow_mut()
            .put(CLOSURE, Value::Text(name.to_string()));
    }
    value
}

/// The value of a built-in: an object of the class `Func`.
///
/// A built-in is a function of the runtime, and it is a value like any
/// other: it can be held in a variable and called through it.
///
/// The most parameters that it takes is the one of the dialect: the v1
/// counts ten thousand for a built-in that takes a variable number of
/// arguments.
fn builtin_value(name: &str, min: u8, max: u32) -> Value {
    let mut properties: BTreeMap<String, Property> = BTreeMap::new();
    put(&mut properties, "name", Value::Text(name.to_string()));
    put(&mut properties, "minparams", Value::Int(min as i64));
    put(&mut properties, "maxparams", Value::Int(max as i64));
    put(&mut properties, "isbuiltin", Value::Int(1));
    put(&mut properties, "isvariadic", Value::Int(0));
    Value::Object(Rc::new(RefCell::new(Object {
        class: "func".to_string(),
        properties,
    })))
}

/// The value of a class: an object of the class itself.
fn class_value(name: &str, class: &Class) -> Value {
    let mut properties: BTreeMap<String, Property> = BTreeMap::new();
    put(&mut properties, CLASS_NAME, Value::Text(class.name.clone()));
    put(&mut properties, "prototype", prototype_value(&class.name));
    Value::Object(Rc::new(RefCell::new(Object {
        class: name.to_lowercase(),
        properties,
    })))
}

/// The value of the parameter that a failure names.
///
/// The text of a parameter of a command of the v1.
///
/// The parameter that wants the name of a variable is a text, and the
/// parameter that is an expression has no name: the shape of the command
/// says which one it is.
fn the_text_of_the_parameter(parameter: &crate::ast::LegacyParameter) -> String {
    match parameter {
        crate::ast::LegacyParameter::Text(text) => text.trim().to_string(),
        crate::ast::LegacyParameter::Expression(_) => String::new(),
    }
}

/// v2 carries the value that a built-in complained about in the `Extra`
/// of the error: the message names the parameter, and the value is the
/// one that was given to it.
fn the_parameter_that_failed(message: &str, values: &[Value]) -> String {
    let Some(rest) = message.strip_prefix("Parameter #") else {
        return String::new();
    };
    let Some((number, _)) = rest.split_once(" of ") else {
        return String::new();
    };
    let Ok(number) = number.parse::<usize>() else {
        return String::new();
    };
    values
        .get(number.saturating_sub(1))
        .map(the_extra_of_the_value)
        .unwrap_or_default()
}

/// The value in the `Extra` of a failure.
///
/// v2 carries the value that arrived, and a text and a number have a text
/// of their own: an object, an array and a function have none.
pub(crate) fn the_extra_of_the_value(value: &Value) -> String {
    match value {
        // Measured on the binary of v2.0.19 on 2026-11-01: a text that is
        // empty is named "empty string" in the `Extra` of a failure, the way
        // the message of the kind of a value names it.
        Value::Text(text) if text.is_empty() => "empty string".to_string(),
        Value::Text(text) => text.clone(),
        Value::Int(_) | Value::Float(_) => value.to_text(),
        Value::List(_) | Value::Object(_) | Value::Reference(_) => String::new(),
    }
}

/// The prototype of a class: the object that holds its methods.
///
/// v2 gives every class one, and the base of an instance is the prototype
/// of its class.
pub(crate) fn prototype_value(name: &str) -> Value {
    let mut properties: BTreeMap<String, Property> = BTreeMap::new();
    put(&mut properties, CLASS_NAME, Value::Text(name.to_string()));
    Value::Object(Rc::new(RefCell::new(Object {
        class: "prototype".to_string(),
        properties,
    })))
}

/// The format of the whole numbers, the way the dialect formats them.
///
/// Measured on the binary of v1.1.37.02 on 2026-11-02: the format is "D"
/// when the script begins, and the `SetFormat` turns it into "H" or "h".
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum IntegerFormat {
    /// The base ten: 255.
    Decimal,
    /// The base sixteen with the prefix: 0xFF.
    Hexadecimal,
    /// The base sixteen with the prefix and the lower case digits: 0xff.
    HexadecimalLower,
}

impl IntegerFormat {
    /// The name of the format, the way the `A_FormatInteger` says it.
    pub fn name(&self) -> &'static str {
        match self {
            IntegerFormat::Decimal => "D",
            IntegerFormat::Hexadecimal => "H",
            IntegerFormat::HexadecimalLower => "h",
        }
    }

    /// The text of a whole number in this format.
    ///
    /// Measured on the binary of v1.1.37.02 on 2026-11-02: the sign is in
    /// front of the prefix: the -255 is "-0xFF".
    pub fn the_text_of(&self, number: i64) -> String {
        match self {
            IntegerFormat::Decimal => number.to_string(),
            IntegerFormat::Hexadecimal => the_hexadecimal_text_of(number, true),
            IntegerFormat::HexadecimalLower => the_hexadecimal_text_of(number, false),
        }
    }
}

/// The text of a whole number in the base of sixteen.
///
/// Measured on the binary of v1.1.37.02 on 2026-11-02: the sign is in
/// front of the prefix, and not in front of the digits: the -255 is
/// "-0xFF".
fn the_hexadecimal_text_of(number: i64, upper: bool) -> String {
    let sign = if number < 0 { "-" } else { "" };
    let digits = number.unsigned_abs();
    if upper {
        format!("{sign}0x{digits:X}")
    } else {
        format!("{sign}0x{digits:x}")
    }
}

/// The format of the floats, the way the dialect formats them.
///
/// Measured on the binary of v1.1.37.02 on 2026-11-02: the format is "0.6"
/// when the script begins, and it is the width of the text, the number of
/// the decimals and the scientific notation.
#[derive(Clone, Copy, PartialEq, Eq)]
pub struct FloatFormat {
    /// The width of the text: the number is padded to it.
    pub width: u32,
    /// The text is padded with zeroes and not with spaces.
    pub zeroes: bool,
    /// The text is justified to the left and not to the right.
    pub left: bool,
    /// The number of the decimals of the text.
    pub decimals: u32,
    /// The text is in the scientific notation.
    pub scientific: bool,
    /// The exponent is in upper case.
    pub upper: bool,
}

impl FloatFormat {
    /// The format of the v1 when the script begins: "0.6".
    pub const DEFAULT: FloatFormat = FloatFormat {
        width: 0,
        zeroes: false,
        left: false,
        decimals: 6,
        scientific: false,
        upper: false,
    };

    /// The name of the format, the way the `A_FormatFloat` says it.
    ///
    /// Measured on the binary of v1.1.37.02 on 2026-11-02: the name is the
    /// format that was written, with the width and the decimals.
    pub fn name(&self) -> String {
        let mut name = String::new();
        if self.left {
            name.push('-');
        }
        if self.zeroes {
            name.push('0');
        }
        name.push_str(&self.width.to_string());
        name.push('.');
        name.push_str(&self.decimals.to_string());
        if self.scientific {
            name.push(if self.upper { 'E' } else { 'e' });
        }
        name
    }

    /// The text of a float in this format.
    ///
    /// The number is rounded to the decimals of the format, and the text is
    /// padded to the width of it.
    pub fn the_text_of(&self, number: f64) -> String {
        // Measured on the binary of v1.1.37.02 on 2026-11-02: the infinity
        // of the v1 is the text of the C library: "1.#INF00" and "-1.#INF00".
        if number.is_infinite() {
            return if number < 0.0 {
                "-1.#INF00".to_string()
            } else {
                "1.#INF00".to_string()
            };
        }
        let decimals = self.decimals as usize;
        let text = if self.scientific {
            let formatted = format!("{:.*e}", decimals, number);
            // The exponent of the v1 has a sign and three digits: `1.0e+003`.
            let (mantissa, exponent) = match formatted.split_once('e') {
                Some((mantissa, exponent)) => (mantissa.to_string(), exponent.to_string()),
                None => (formatted.clone(), String::new()),
            };
            let exponent = match exponent.strip_prefix('-') {
                Some(rest) => format!("-{}", the_digits_of_the_exponent(rest)),
                None => format!("+{}", the_digits_of_the_exponent(&exponent)),
            };
            format!("{mantissa}e{exponent}")
        } else {
            the_text_of_the_number(number, decimals)
        };
        let width = self.width as usize;
        if text.chars().count() >= width {
            return text;
        }
        let padding = width - text.chars().count();
        if self.zeroes {
            // The zeroes go before the number, and the sign keeps its place.
            let (sign, rest) = match text.strip_prefix('-') {
                Some(rest) => ("-", rest),
                None => ("", text.as_str()),
            };
            let mut padded = String::from(sign);
            padded.push_str(&"0".repeat(padding));
            padded.push_str(rest);
            padded
        } else if self.left {
            let mut padded = text;
            padded.push_str(&" ".repeat(padding));
            padded
        } else {
            let mut padded = " ".repeat(padding);
            padded.push_str(&text);
            padded
        }
    }
}

/// The sense of the case, the way the dialect compares the letters.
///
/// Measured on the binary of v1.1.37.02 on 2026-11-02: the sense is "Off"
/// when the script begins, and the `StringCaseSense` turns it into "On" or
/// into "Locale".
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum CaseSense {
    /// The letters A-Z are the same as their lower case, and the others are
    /// not.
    Off,
    /// The letters are taken as they are.
    On,
    /// The letters follow the rules of the locale of the machine.
    Locale,
}

impl CaseSense {
    /// The name of the sense, the way the `A_StringCaseSense` says it.
    pub fn name(&self) -> &'static str {
        match self {
            CaseSense::Off => "Off",
            CaseSense::On => "On",
            CaseSense::Locale => "Locale",
        }
    }

    /// The method that compares two texts.
    ///
    /// Measured on the binary of v1.1.37.02 on 2026-11-02: the sense that is
    /// On takes the letters as they are, and the sense that is Off treats the
    /// letters A-Z as their lower case and the others as they are.
    pub fn the_method(&self) -> CaseMethod {
        match self {
            CaseSense::Off => CaseMethod::Ascii,
            CaseSense::On => CaseMethod::Exact,
            CaseSense::Locale => CaseMethod::Locale,
        }
    }

    /// The method that the equal sign of the v1 uses.
    ///
    /// Measured on the binary of v1.1.37.02 on 2026-11-02: the equal sign is
    /// always without regard to the case, and the method of the locale is the
    /// one it uses when the sense is On: `"ä" = "Ä"` is true when the sense
    /// is On, and it is false when the sense is Off.
    pub fn the_method_of_the_equal_sign(&self) -> CaseMethod {
        match self {
            CaseSense::Off => CaseMethod::Ascii,
            CaseSense::On | CaseSense::Locale => CaseMethod::Locale,
        }
    }
}

/// The method that compares the letters of two texts.
///
/// The method of the locale is the one of the machine, and the tree does
/// not ask the machine for it: it folds the letters of the Unicode, which
/// is the method of the locale of every machine that is written in the
/// Latin alphabet.
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum CaseMethod {
    /// The letters A-Z are the same as their lower case, and the others are
    /// not.
    Ascii,
    /// The letters are taken as they are.
    Exact,
    /// The letters follow the rules of the locale of the machine.
    Locale,
}

/// Whether two texts are the same, with the method of the case.
pub(crate) fn the_same_text(left: &str, right: &str, method: CaseMethod) -> bool {
    match method {
        CaseMethod::Ascii => left.eq_ignore_ascii_case(right),
        CaseMethod::Exact => left == right,
        CaseMethod::Locale => left.to_lowercase() == right.to_lowercase(),
    }
}

/// Whether two numbers are the same number.
///
/// The whole numbers are compared as whole numbers: the machine cannot
/// hold every one of them exactly as a float, and the numbers that it
/// rounds are not the same number.
pub(crate) fn the_same_number(left: &Value, right: &Value) -> bool {
    match (left, right) {
        (Value::Int(one), Value::Int(other)) => one == other,
        _ => left.to_number() == right.to_number(),
    }
}

/// Whether the text of the needle is in the text of the haystack, with the
/// method of the case.
///
/// Measured on the binary of v1.1.37.02 on 2026-11-02: the `IfInString` of
/// the v1 finds the text of the needle in the variable, and the sense of the
/// case says whether the letters of them are the same.
pub(crate) fn the_text_contains(haystack: &str, needle: &str, method: CaseMethod) -> bool {
    match method {
        CaseMethod::Ascii => haystack
            .to_ascii_lowercase()
            .contains(&needle.to_ascii_lowercase()),
        CaseMethod::Exact => haystack.contains(needle),
        CaseMethod::Locale => haystack.to_lowercase().contains(&needle.to_lowercase()),
    }
}

/// How two texts stand to each other, with the method of the case.
///
/// Measured on the binary of v1.1.37.02 on 2026-11-02: the texts of the v1
/// are compared letter by letter, and the method of the case says whether
/// the letters of them are the same: `"a" < "B"` is true when the sense is
/// Off, and it is false when the sense is On.
pub(crate) fn the_order_of_the_texts(
    left: &str,
    right: &str,
    method: CaseMethod,
) -> core::cmp::Ordering {
    match method {
        CaseMethod::Ascii => {
            let left = left.to_ascii_lowercase();
            let right = right.to_ascii_lowercase();
            left.cmp(&right)
        }
        CaseMethod::Exact => left.cmp(right),
        CaseMethod::Locale => left.to_lowercase().cmp(&right.to_lowercase()),
    }
}

/// The digits of the exponent of the scientific notation: three at least.
fn the_digits_of_the_exponent(digits: &str) -> String {
    let digits = digits.trim_start_matches('0');
    if digits.is_empty() {
        "000".to_string()
    } else if digits.len() < 3 {
        format!("0{digits:0>2}")
    } else {
        digits.to_string()
    }
}

/// The text of a number, with the decimals of the format.
///
/// Measured on the binary of AutoHotkey v1.1.37.02 on 2026-11-02: the v1
/// writes the number with seventeen digits, and it rounds that number to
/// the decimals of the format -- a half goes away from the zero. The text of
/// the C library writes the digits that the double holds, and the two tell
/// each other apart in the numbers that are big: `Exp(65)` is
/// "16948892444103338000000000000.000000" and not
/// "16948892444103337803358666752.000000".
fn the_text_of_the_number(number: f64, decimals: usize) -> String {
    let negative = number < 0.0;
    // The seventeen digits of the double, and the place of the point.
    let exact = format!("{:.16e}", number.abs());
    let (mantissa, exponent) = match exact.split_once('e') {
        Some((mantissa, exponent)) => (mantissa, exponent),
        None => (exact.as_str(), "0"),
    };
    let digits: String = mantissa
        .chars()
        .filter(|character| character.is_ascii_digit())
        .collect();
    let exponent: i32 = exponent.parse().unwrap_or(0);
    // The number is the digits with the point after `exponent + 1` of them.
    let point = exponent + 1;
    let mut whole = String::new();
    let mut fraction = String::new();
    if point <= 0 {
        whole.push('0');
        for _ in 0..-point {
            fraction.push('0');
        }
        fraction.push_str(&digits);
    } else {
        let point = point as usize;
        if point >= digits.len() {
            whole.push_str(&digits);
            for _ in 0..point - digits.len() {
                whole.push('0');
            }
        } else {
            whole.push_str(&digits[..point]);
            fraction.push_str(&digits[point..]);
        }
    }
    // The rounding: a half goes away from the zero.
    if fraction.len() > decimals {
        if fraction.as_bytes()[decimals] >= b'5' {
            let mut index = decimals;
            let mut carries = true;
            while carries && index > 0 {
                index -= 1;
                let digit = fraction.as_bytes()[index] - b'0';
                if digit == 9 {
                    fraction.replace_range(index..index + 1, "0");
                } else {
                    fraction.replace_range(index..index + 1, &format!("{}", digit + 1));
                    carries = false;
                }
            }
            if carries {
                // The rounding passed the point, and the whole number grows.
                let mut index = whole.len();
                let mut carries = true;
                while carries && index > 0 {
                    index -= 1;
                    let digit = whole.as_bytes()[index] - b'0';
                    if digit == 9 {
                        whole.replace_range(index..index + 1, "0");
                    } else {
                        whole.replace_range(index..index + 1, &format!("{}", digit + 1));
                        carries = false;
                    }
                }
                if carries {
                    whole.insert(0, '1');
                }
            }
        }
        fraction.truncate(decimals);
    } else {
        for _ in fraction.len()..decimals {
            fraction.push('0');
        }
    }
    let mut text = String::new();
    if negative {
        text.push('-');
    }
    text.push_str(&whole);
    if decimals > 0 {
        text.push('.');
        text.push_str(&fraction);
    }
    text
}

/// The failure of the runtime, as the failure of a built-in.
///
/// A built-in answers with a message and a line, and not with the flow
/// of the script: a timeout or a return is not a thing a built-in can
/// hand back.
pub(crate) fn as_error(failure: RuntimeFailure, line: u32) -> RuntimeError {
    match failure {
        RuntimeFailure::Error(error) => error,
        RuntimeFailure::Detailed(error, _) => error,
        _ => RuntimeError {
            message: "the runtime cannot answer that.".into(),
            line,
        },
    }
}

/// The pieces of a text, cut at every character of the delimiters.
///
/// The pieces keep the order they had, and an empty piece is a piece:
/// the text "a,,b" has three.
pub(crate) fn split_on_any(text: &str, delimiters: &str) -> Vec<String> {
    let mut pieces: Vec<String> = Vec::new();
    let mut current = String::new();
    for character in text.chars() {
        if delimiters.contains(character) {
            pieces.push(core::mem::take(&mut current));
            continue;
        }
        current.push(character);
    }
    pieces.push(current);
    pieces
}

/// Whether two values are equal, the way a script expects.
///
/// A number that came out of an addition is compared with a number that
/// was written down: `2` and `2.0` are the same number, even though one
/// of them is a whole number and the other is not.
fn values_equal(left: &Value, right: &Value, case_sensitive: bool) -> bool {
    values_equal_with(
        left,
        right,
        if case_sensitive {
            CaseMethod::Exact
        } else {
            CaseMethod::Ascii
        },
    )
}

/// Whether two values are equal, with the method of the case.
///
/// The numbers are the same number, and the texts are the same text with
/// the method that the caller asks for.
fn values_equal_with(left: &Value, right: &Value, method: CaseMethod) -> bool {
    // An object is the same object and nothing else.
    //
    // Measured on the binary of v2.0.19 on 2026-10-31: two maps that hold
    // the same entries are not the same map, an instance is not the class
    // of it, and an object is never equal to a value that is not an
    // object -- not even to a text that carries the name of its class.
    //
    // This is a rule of v2: the v1 dialect compares the objects by what
    // they hold, and it bypasses this place.
    if let (Value::Object(one), Value::Object(other)) = (left, right) {
        return Rc::ptr_eq(one, other);
    }
    if matches!(left, Value::Object(_)) || matches!(right, Value::Object(_)) {
        return false;
    }
    // The comparison is a number when both sides are numbers, and a
    // text otherwise: that is the rule v2 follows.
    if let (Some(a), Some(b)) = (left.to_number(), right.to_number()) {
        return a == b;
    }
    the_same_text(&left.to_text(), &right.to_text(), method)
}

/// The message of a failure, the way the report carries it.
pub(crate) fn the_message_of(failure: &RuntimeFailure) -> String {
    match failure {
        RuntimeFailure::Error(error) => error.message.clone(),
        RuntimeFailure::Detailed(error, _) => error.message.clone(),
        RuntimeFailure::Fatal(error) => error.message.clone(),
        RuntimeFailure::Thrown(value) => thrown_message(value),
        RuntimeFailure::Timeout(timeout) => timeout.to_string(),
        RuntimeFailure::Flow(_) => "the script left a block in the middle of it.".to_string(),
    }
}

/// The number of a property of an object, when it has one.
fn number_of(properties: &BTreeMap<String, Property>, name: &str) -> i64 {
    properties
        .get(name)
        .map(|property| property.value.to_number().unwrap_or(0.0) as i64)
        .unwrap_or(0)
}

/// The key of a static declaration: the line it is on and the name it
/// declares.
///
/// The value of a static declaration runs once, and the key is what tells
/// the tree that it ran.
fn the_key_of_a_declaration(line: u32, name: &str) -> String {
    format!("{}:{}", line, the_key_of(name))
}

/// The key of a variable, as the tree keeps it.
///
/// The dialect does not know the case of the names: `x` and `X` are the
/// same variable. The names of the functions were in lower case already;
/// the variables are like them now.
fn the_key_of(name: &str) -> String {
    name.to_lowercase()
}

/// The message of a value that was thrown and that nobody caught.
///
/// A text is the message of the exception, the way v2 shows it, and
/// anything else is the message of an exception without a name.
fn thrown_message(value: &Value) -> String {
    match value {
        Value::Text(text) => format!("Unhandled exception.\n     Specifically: {text}"),
        _ => "Unhandled exception.".to_string(),
    }
}

/// The place of the label in a block, when the block holds it.
///
/// The names of the labels do not know their case, the way the names of the
/// variables do not.
fn the_place_of_the_label(statements: &[Node], name: &str) -> Option<usize> {
    statements.iter().position(|statement| match statement {
        Node::Label { name: label, .. } => label.eq_ignore_ascii_case(name),
        _ => false,
    })
}

/// The labels of a scope, the way the script wrote them.
///
/// The labels of a function are the ones of its body, and the body of a
/// function that is written inside another one belongs to the function it
/// is written in.
fn the_labels_of(body: &[Node]) -> Vec<String> {
    let mut labels = Vec::new();
    collect_the_labels(body, &mut labels);
    labels
}

/// The labels of the blocks of a body.
fn collect_the_labels(body: &[Node], labels: &mut Vec<String>) {
    for statement in body {
        match statement {
            Node::Label { name, .. } => labels.push(name.clone()),
            // The body of a hotkey of the v1 is of the scope that carries
            // it: the hotkey is not a block, and a jump may leave it.
            Node::HotkeyDefinition { body, .. } => collect_the_labels(body, labels),
            Node::If {
                branches,
                otherwise,
                ..
            } => {
                for branch in branches {
                    collect_the_labels(&branch.body, labels);
                }
                collect_the_labels(otherwise, labels);
            }
            Node::Switch { cases, .. } => {
                for case in cases {
                    collect_the_labels(&case.body, labels);
                }
            }
            Node::Block { body, .. }
            | Node::While { body, .. }
            | Node::Loop { body, .. }
            | Node::For { body, .. } => {
                collect_the_labels(body, labels);
            }
            Node::LegacyIf {
                body, otherwise, ..
            } => {
                collect_the_labels(body, labels);
                collect_the_labels(otherwise, labels);
            }
            Node::Try {
                body,
                catches,
                otherwise,
                finally,
                ..
            } => {
                collect_the_labels(body, labels);
                for catch in catches {
                    collect_the_labels(&catch.body, labels);
                }
                collect_the_labels(otherwise, labels);
                collect_the_labels(finally, labels);
            }
            _ => {}
        }
    }
}

/// The built-in of this name, in the dialect that runs.
///
/// The name is matched the way AutoHotkey matches it: without regard
/// to the case.
pub fn the_builtin_in(
    dialect: &'static dyn crate::dialect::Dialect,
    name: &str,
) -> Option<&'static crate::builtins::Builtin> {
    let wanted = name.to_lowercase();
    dialect
        .builtins()
        .iter()
        .find(|builtin| builtin.name.to_lowercase() == wanted)
}
/// The name a statement is reported under.
pub fn op_name(statement: &Node) -> &str {
    op_name_in(statement, crate::dialect::v2())
}

/// The name a statement is reported under, in the dialect of the run.
pub fn op_name_in<'a>(
    statement: &'a Node,
    dialect: &'static dyn crate::dialect::Dialect,
) -> &'a str {
    match statement {
        Node::Assign { .. } => "Assign",
        Node::AssignIndex { .. } => "AssignIndex",
        // A call to a built-in is reported under the name of the built-in,
        // the way AutoHotkey reports a command.
        Node::Call { name, .. } => match the_builtin_in(dialect, name) {
            Some(builtin) => builtin.name,
            None => "Call",
        },
        // The legacy command of the v1 is reported under its own name.
        Node::LegacyCall { name, .. } => name,
        // The `new` of the v1 is reported under its own name.
        Node::New { .. } => "New",
        // The command of the v1 that has a body is reported under its own
        // name as well.
        Node::LegacyIf { name, .. } => name,
        Node::Expression { value, .. } => match the_call_of(value) {
            // The statement reads the member of the answer of a call, and
            // it is still the call that the report names.
            Some(name) => match the_builtin_in(dialect, name) {
                Some(builtin) => builtin.name,
                None => "Call",
            },
            None => "Expression",
        },
        Node::Block { .. } => "Block",
        Node::If { .. } => "If",
        Node::Switch { .. } => "Switch",
        Node::While { .. } => "While",
        Node::Try { .. } => "Try",
        Node::Throw { .. } => "Throw",
        Node::Declare { .. } => "Declare",
        Node::Super { .. } => "Super",
        Node::Loop { .. } => "Loop",
        Node::ArrayLiteral { .. } => "ArrayLiteral",
        Node::ObjectLiteral { .. } => "ObjectLiteral",
        Node::Lambda { .. } => "Lambda",
        Node::For { .. } => "For",
        Node::Directive { name, .. } => name,
        Node::Break { .. } => "Break",
        Node::Continue { .. } => "Continue",
        Node::Label { .. } => "Label",
        Node::Goto { .. } => "Goto",
        Node::HotkeyDefinition { .. } => "HotkeyDefinition",
        Node::Return { .. } => "Return",
        Node::ExitApp { .. } => "ExitApp",
        Node::FunctionDef { .. } => "FunctionDef",
        Node::ClassDef { .. } => "ClassDef",
        Node::MethodCall { .. } => "MethodCall",
        Node::Property { .. } => "Property",
        Node::AssignProperty { .. } => "AssignProperty",
        Node::Literal { .. } => "Literal",
        Node::Var { .. } => "Var",
        Node::Unary { .. } => "Unary",
        Node::Binary { .. } => "Binary",
        Node::Unset { .. } => "Unset",
        Node::Ternary { .. } => "Ternary",
        Node::DynamicName { .. } => "DynamicName",
        Node::AssignDynamic { .. } => "AssignDynamic",
        Node::Index { .. } => "Index",
        Node::Group { .. } => "Group",
        Node::Empty { .. } => "Empty",
        Node::Legacy { .. } => "Legacy",
        Node::LegacyExpression { .. } => "LegacyExpression",
        Node::LegacyControl { .. } => "LegacyControl",
        Node::LegacyAssign { .. } => "LegacyAssign",
        Node::LegacyComparison { .. } => "LegacyComparison",
        Node::LegacyMatch { .. } => "LegacyMatch",
    }
}

/// The call that a value holds, when it holds one.
///
/// A statement that reads the member of the answer of a call is the call
/// itself: `Map().Count` is the call of `Map` and the reading of a member.
fn the_call_of(node: &Node) -> Option<&str> {
    match node {
        Node::Call { name, .. } => Some(name),
        Node::Property { target, .. }
        | Node::Index { target, .. }
        | Node::MethodCall { target, .. } => the_call_of(target),
        _ => None,
    }
}

pub(crate) enum RuntimeFailure {
    Error(RuntimeError),
    /// A failure with the detail that v2 carries in the error object.
    ///
    /// `What` names the thing that raised the failure, and `Extra` is
    /// the detail that goes with it.
    Detailed(RuntimeError, Detail),
    /// A failure that no catch takes.
    ///
    /// Measured on the binary of v2.0.19 on 2026-10-31: the failure of a
    /// `Goto` that does not find its label ends the script, and a catch
    /// does not take it.
    Fatal(RuntimeError),
    /// A value that the script threw.
    Thrown(Value),
    Timeout(Timeout),
    Flow(Flow),
}

/// The name of the thing that raised a failure, and the detail that
/// goes with it.
///
/// v2 carries both in the error object: `What` names the thing that
/// raised the failure, and `Extra` is the detail.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct Detail {
    /// The name of the thing that raised the failure.
    pub what: String,
    /// The detail of the failure.
    pub extra: String,
}

/// How a call found the function it calls.
///
/// v2 checks the number of the arguments in two places. A call that the
/// script writes is checked when the script loads, and the failure says
/// the name of the function: "Too few parameters passed to function.
/// \n     Specifically: Abs". A call that goes through a value is checked when
/// the call runs, and the failure is the one of the run: "Missing a
/// required parameter." for a function of the script, and "Too few
/// parameters passed to function." for a built-in.
#[derive(Clone, Copy, PartialEq)]
pub(crate) enum Route {
    /// The script wrote the call, and the name of the function is known
    /// when the script loads.
    Written,
    /// The call goes through a value, and the name of the function is
    /// not known when the script loads.
    ThroughValue,
    /// The call went through the `Call` method of a value of a function.
    ///
    /// v2 names that method in the `What` of the failure of the number
    /// of the arguments, and the call of the value itself does not.
    ThroughTheCall,
}

impl From<RuntimeError> for RuntimeFailure {
    fn from(error: RuntimeError) -> Self {
        RuntimeFailure::Error(error)
    }
}

impl From<Timeout> for RuntimeFailure {
    fn from(timeout: Timeout) -> Self {
        RuntimeFailure::Timeout(timeout)
    }
}

impl From<Flow> for RuntimeFailure {
    fn from(flow: Flow) -> Self {
        RuntimeFailure::Flow(flow)
    }
}

impl From<String> for RuntimeFailure {
    fn from(message: String) -> Self {
        RuntimeFailure::Error(RuntimeError { message, line: 0 })
    }
}