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
|
/*
* EVAL, APPLY and bytecode interpreter for CLISP
* Bruno Haible 1990-2005
* Sam Steingold 1998-2005
* German comments translated into English: Stefan Kain 2001-08-13
*/
#include "lispbibl.c"
/* function-table:
In this table only SUBRS are listed, which may be inlined by the compiler.
In FUNTAB1 and FUNTAB2 SUBRs without Rest-Parameter (i.e. with
fixed number of arguments known at compile-time) are listed.
In FUNTABR SUBRs with Rest-Parameter are listed. */
#define _(name) &subr_tab.D_##name /* address of SUBR name, like L(name) */
/* FUNTAB1 and FUNTAB2, first: */
local const Subr FUNTAB[] = {
/* SPVW : 0 SUBRs */
/* EVAL : 3 SUBRs */
_(funtabref), _(subr_info), _(special_variable_p),
/* ARRAY : 30-2 SUBRs */
_(copy_simple_vector), /* _(svref), _(psvstore), */ _(row_major_aref),
_(row_major_store), _(array_element_type), _(array_rank),
_(array_dimension), _(array_dimensions), _(array_total_size),
_(adjustable_array_p), _(bit_and), _(bit_ior), _(bit_xor), _(bit_eqv),
_(bit_nand), _(bit_nor), _(bit_andc1), _(bit_andc2), _(bit_orc1),
_(bit_orc2), _(bit_not), _(array_has_fill_pointer_p), _(fill_pointer),
_(set_fill_pointer), _(vector_push), _(vector_pop), _(vector_push_extend),
_(make_array), _(adjust_array),
/* CHARSTRG : 47 SUBRs */
_(standard_char_p), _(graphic_char_p), _(string_char_p), _(alpha_char_p),
_(upper_case_p), _(lower_case_p), _(both_case_p), _(digit_char_p),
_(alphanumericp), _(char_code), _(code_char), _(character), _(char_upcase),
_(char_downcase), _(digit_char), _(char_int), _(int_char), _(char_name),
_(char), _(schar), _(store_char), _(store_schar), _(string_gleich),
_(string_ungleich), _(string_kleiner), _(string_groesser),
_(string_klgleich), _(string_grgleich), _(string_equal),
_(string_not_equal), _(string_lessp), _(string_greaterp),
_(string_not_greaterp), _(string_not_lessp), _(search_string_gleich),
_(search_string_equal), _(make_string), _(string_both_trim),
_(nstring_upcase), _(string_upcase), _(nstring_downcase),
_(string_downcase), _(nstring_capitalize), _(string_capitalize),
_(string), _(name_char), _(substring),
/* CONTROL : 23-2 SUBRs */
_(symbol_value), /* _(symbol_function), */ _(boundp), _(fboundp),
_(special_operator_p), _(set), _(makunbound), _(fmakunbound),
/* _(values_list), */ _(driver), _(unwind_to_driver), _(macro_function),
_(macroexpand), _(macroexpand_1), _(proclaim), _(eval),
_(evalhook), _(applyhook), _(constantp), _(function_side_effect),
_(function_name_p),_(parse_body), _(keyword_test),
/* DEBUG : 0 SUBRs */
/* ERROR : 1 SUBR */
_(invoke_debugger),
/* HASHTABL : 11 SUBRs */
_(make_hash_table), _(gethash), _(puthash), _(remhash), _(maphash),
_(clrhash), _(hash_table_count), _(hash_table_iterator),
_(hash_table_iterate), _(class_gethash), _(sxhash),
/* IO : 36 SUBRs */
_(copy_readtable), _(set_syntax_from_char), _(set_macro_character),
_(get_macro_character), _(make_dispatch_macro_character),
_(set_dispatch_macro_character), _(get_dispatch_macro_character),
_(read), _(read_preserving_whitespace), _(read_delimited_list),
_(read_line), _(read_char), _(unread_char), _(peek_char), _(listen),
_(read_char_no_hang), _(clear_input), _(read_from_string),
_(parse_integer), _(write), _(prin1), _(print), _(pprint), _(princ),
_(write_to_string), _(prin1_to_string), _(princ_to_string), _(write_char),
_(write_string), _(write_line), _(terpri), _(fresh_line),
_(finish_output), _(force_output), _(clear_output), _(line_position),
/* LIST : 84-36=48 SUBRs */
/* _(car), _(cdr), _(caar), _(cadr), _(cdar), _(cddr), _(caaar), _(caadr),
_(cadar), _(caddr), _(cdaar), _(cdadr), _(cddar), _(cdddr), _(caaaar),
_(caaadr), _(caadar), _(caaddr), _(cadaar), _(cadadr), _(caddar),
_(cadddr), _(cdaaar), _(cdaadr), _(cdadar), _(cdaddr), _(cddaar),
_(cddadr), _(cdddar), _(cddddr), _(cons), */ _(tree_equal), _(endp),
_(list_length), _(nth), /* _(first), _(second), _(third), _(fourth), */
_(fifth), _(sixth), _(seventh), _(eighth), _(ninth), _(tenth), /* _(rest), */
_(nthcdr), _(last), _(make_list), _(copy_list), _(copy_alist), _(memq),
_(copy_tree), _(revappend), _(nreconc), _(list_nreverse), _(butlast),
_(nbutlast), _(ldiff), _(rplaca), _(prplaca), _(rplacd), _(prplacd),
_(subst), _(subst_if), _(subst_if_not), _(nsubst), _(nsubst_if),
_(nsubst_if_not), _(sublis), _(nsublis), _(member), _(member_if),
_(member_if_not), _(tailp), _(adjoin), _(acons), _(pairlis), _(assoc),
_(assoc_if), _(assoc_if_not), _(rassoc), _(rassoc_if), _(rassoc_if_not),
/* MISC : 10 SUBRs */
_(lisp_implementation_type), _(lisp_implementation_version),
_(software_type), _(software_version), _(identity), _(get_universal_time),
_(get_internal_run_time), _(get_internal_real_time), _(sleep), _(time),
/* PACKAGE : 26 SUBRs */
_(make_symbol), _(find_package), _(package_name), _(package_nicknames),
_(rename_package), _(package_use_list), _(package_used_by_list),
_(package_shadowing_symbols), _(list_all_packages), _(intern),
_(find_symbol), _(unintern), _(export), _(unexport), _(import),
_(shadowing_import), _(shadow), _(use_package), _(unuse_package),
_(make_package), _(pin_package), _(find_all_symbols),
_(map_symbols), _(map_external_symbols), _(map_all_symbols),
_(pfind_package), _(re_export),
/* PATHNAME : 27 SUBRs */
_(parse_namestring), _(pathname), _(pathnamehost), _(pathnamedevice),
_(pathnamedirectory), _(pathnamename), _(pathnametype),
_(pathnameversion), _(file_namestring), _(directory_namestring),
_(host_namestring), _(merge_pathnames), _(enough_namestring),
_(make_pathname), _(namestring), _(truename), _(probe_file),
_(delete_file), _(rename_file), _(open), _(directory), _(cd),
_(make_dir), _(delete_dir), _(file_write_date), _(file_author),
_(savemem),
/* PREDTYPE : 44-3 SUBRs */
/* _(eq), */ _(eql), _(equal), _(equalp), _(consp), _(atom), _(symbolp),
_(stringp), _(numberp), _(compiled_function_p), /* _(null), _(not), */
_(closurep), _(listp), _(integerp), _(fixnump), _(rationalp), _(floatp),
_(short_float_p), _(single_float_p), _(double_float_p), _(long_float_p),
_(realp), _(complexp), _(streamp), _(random_state_p), _(readtablep),
_(hash_table_p), _(pathnamep), _(logical_pathname_p), _(characterp),
_(functionp), _(packagep), _(arrayp), _(simple_array_p), _(bit_vector_p),
_(vectorp), _(simple_vector_p), _(simple_string_p), _(simple_bit_vector_p),
_(type_of), _(class_of), _(find_class), _(coerce),
/* RECORD : 23 SUBRs */
_(record_ref), _(record_store), _(record_length), _(structure_ref),
_(structure_store), _(make_structure), _(copy_structure),
_(structure_type_p), _(closure_name), _(closure_codevec),
_(closure_consts), _(make_code_vector), _(make_closure),
_(copy_generic_function), _(make_load_time_eval),
_(function_macro_function), _(structure_object_p), _(std_instance_p),
_(slot_value), _(set_slot_value), _(slot_boundp), _(slot_makunbound),
_(slot_exists_p),
/* SEQUENCE : 40 SUBRs */
_(sequencep), _(elt), _(setelt), _(subseq), _(copy_seq), _(length),
_(reverse), _(nreverse), _(make_sequence), _(reduce), _(fill),
_(replace), _(remove), _(remove_if), _(remove_if_not), _(delete),
_(delete_if), _(delete_if_not), _(remove_duplicates),
_(delete_duplicates), _(substitute), _(substitute_if),
_(substitute_if_not), _(nsubstitute), _(nsubstitute_if),
_(nsubstitute_if_not), _(find), _(find_if), _(find_if_not), _(position),
_(position_if), _(position_if_not), _(count), _(count_if),
_(count_if_not), _(mismatch), _(search), _(sort), _(stable_sort),
_(merge),
/* STREAM : 24 SUBRs */
_(file_stream_p), _(make_synonym_stream), _(synonym_stream_p),
_(broadcast_stream_p), _(concatenated_stream_p), _(make_two_way_stream),
_(two_way_stream_p), _(make_echo_stream), _(echo_stream_p),
_(make_string_input_stream), _(string_input_stream_index),
_(make_string_output_stream), _(get_output_stream_string),
_(make_string_push_stream), _(string_stream_p), _(input_stream_p),
_(output_stream_p), _(built_in_stream_element_type),
_(stream_external_format), _(built_in_stream_close), _(read_byte),
_(write_byte), _(file_position), _(file_length),
/* SYMBOL : 14 SUBRs */
_(putd), _(proclaim_constant), _(get), _(getf), _(get_properties),
_(putplist), _(put), _(remprop), _(symbol_package), _(symbol_plist),
_(symbol_name), _(keywordp), _(gensym), _(gensym),
/* LISPARIT : 84 SUBRs */
_(decimal_string), _(zerop), _(plusp), _(minusp), _(oddp), _(evenp),
_(einsplus), _(einsminus), _(conjugate), _(exp), _(expt), _(log),
_(sqrt), _(isqrt), _(abs), _(phase), _(signum), _(sin), _(cos), _(tan),
_(cis), _(asin), _(acos), _(atan), _(sinh), _(cosh), _(tanh), _(asinh),
_(acosh), _(atanh), _(float), _(rational), _(rationalize), _(numerator),
_(denominator), _(floor), _(ceiling), _(truncate), _(round), _(mod),
_(rem), _(ffloor), _(fceiling), _(ftruncate), _(fround), _(decode_float),
_(scale_float), _(float_radix), _(float_sign), _(float_digits),
_(float_precision), _(integer_decode_float), _(complex), _(realpart),
_(imagpart), _(lognand), _(lognor), _(logandc1), _(logandc2), _(logorc1),
_(logorc2), _(boole), _(lognot), _(logtest), _(logbitp), _(ash),
_(logcount), _(integer_length), _(byte), _(bytesize), _(byteposition),
_(ldb), _(ldb_test), _(mask_field), _(dpb), _(deposit_field), _(random),
_(make_random_state), _(fakultaet), _(exquo), _(long_float_digits),
_(set_long_float_digits), _(log2), _(log10),
/* other: */
}; /* that were 529-43 SUBRs. */
/* Now FUNTABR : */
local const Subr FUNTABR[] = {
/* SPVW : 0 SUBRs */
/* EVAL : 0 SUBRs */
/* ARRAY : 7 SUBRs */
_(vector), _(aref), _(store), _(array_in_bounds_p),
_(array_row_major_index), _(bit), _(sbit),
/* CHARSTRG : 13 SUBRs */
_(char_gleich), _(char_ungleich), _(char_kleiner), _(char_groesser),
_(char_klgleich), _(char_grgleich), _(char_equal), _(char_not_equal),
_(char_lessp), _(char_greaterp), _(char_not_greaterp), _(char_not_lessp),
_(string_concat),
/* CONTROL : 9 SUBRs */
_(apply), _(funcall), _(mapcar), _(maplist), _(mapc),
_(mapl), _(mapcan), _(mapcon), _(values),
/* DEBUG : 0 SUBRs */
/* ERROR : 2 SUBRs */
_(error), _(error_of_type),
/* HASHTABL : 1 SUBR */
_(class_tuple_gethash),
/* IO : 0 SUBRs */
/* LIST : 4 SUBRs */
_(list), _(liststern), _(append), _(nconc),
/* MISC : 0 SUBRs */
/* PACKAGE : 0 SUBRs */
/* PATHNAME : 0 SUBRs */
/* PREDTYPE : 0 SUBRs */
/* RECORD : 1 SUBR */
_(pallocate_instance),
/* SEQUENCE : 6 SUBRs */
_(concatenate), _(map), _(some), _(every), _(notany), _(notevery),
/* STREAM : 2 SUBRs */
_(make_broadcast_stream), _(make_concatenated_stream),
/* SYMBOL : 0 SUBRs */
/* LISPARIT : 18 SUBRs */
_(gleich), _(ungleich), _(kleiner), _(groesser), _(klgleich),
_(grgleich), _(max), _(min), _(plus), _(minus), _(mal), _(durch), _(gcd),
_(lcm), _(logior), _(logxor), _(logand), _(logeqv),
}; /* That were 63 SUBRs. */
#undef _
#define FUNTAB1 (&FUNTAB[0])
#define FUNTAB2 (&FUNTAB[256])
#define FUNTAB_length (sizeof(FUNTAB)/sizeof(Subr))
#define FUNTABR_length (sizeof(FUNTABR)/sizeof(Subr))
/* argument-type-tokens for compiled closures: */
typedef enum {
cclos_argtype_default,
cclos_argtype_0_0,
cclos_argtype_1_0,
cclos_argtype_2_0,
cclos_argtype_3_0,
cclos_argtype_4_0,
cclos_argtype_5_0,
cclos_argtype_0_1,
cclos_argtype_1_1,
cclos_argtype_2_1,
cclos_argtype_3_1,
cclos_argtype_4_1,
cclos_argtype_0_2,
cclos_argtype_1_2,
cclos_argtype_2_2,
cclos_argtype_3_2,
cclos_argtype_0_3,
cclos_argtype_1_3,
cclos_argtype_2_3,
cclos_argtype_0_4,
cclos_argtype_1_4,
cclos_argtype_0_5,
cclos_argtype_0_0_rest,
cclos_argtype_1_0_rest,
cclos_argtype_2_0_rest,
cclos_argtype_3_0_rest,
cclos_argtype_4_0_rest,
cclos_argtype_0_0_key,
cclos_argtype_1_0_key,
cclos_argtype_2_0_key,
cclos_argtype_3_0_key,
cclos_argtype_4_0_key,
cclos_argtype_0_1_key,
cclos_argtype_1_1_key,
cclos_argtype_2_1_key,
cclos_argtype_3_1_key,
cclos_argtype_0_2_key,
cclos_argtype_1_2_key,
cclos_argtype_2_2_key,
cclos_argtype_0_3_key,
cclos_argtype_1_3_key,
cclos_argtype_0_4_key,
cclos_argtype_for_broken_compilers_that_dont_like_trailing_commas
} cclos_argtype_t;
/* Call of the bytecode-interpreter:
interpretes the bytecode of a compiled closure.
interpret_bytecode(closure,codevec,index);
> closure: compiled closure
> codevec: its codevector, a Simple-Bit-Vector
> index: Start-Index
< mv_count/mv_space: values
changes STACK, can trigger GC
local Values interpret_bytecode (object closure, object codevec, uintL index);
*/
local /*maygc*/ Values interpret_bytecode_ (object closure, Sbvector codeptr,
const uintB* byteptr);
#define interpret_bytecode(closure,codevec,index) \
with_saved_back_trace_cclosure(closure, \
interpret_bytecode_(closure,TheSbvector(codevec),&TheSbvector(codevec)->data[index]); )
/* GCC2 can jump directly to labels.
This results in faster code than switch(). */
#if defined(GNU) && !(__APPLE_CC__ > 1)
#if (__GNUC__ >= 2) && !defined(UNIX_HPUX) && !defined(NO_FAST_DISPATCH) /* work around HP-UX Linker Bug */
#define FAST_DISPATCH
#if (__GNUC__ >= 3) || (__GNUC_MINOR__ >= 7) /* work around gcc-2.6.3 Bug (-fno-defer-pop ginge auch) */
#define FAST_DISPATCH_THREADED
#endif
#endif
#endif
/* Values of the bytecodes (256 totally): */
typedef enum {
#define BYTECODE(code) code,
#include "bytecode.c"
#undef BYTECODE
cod_for_broken_compilers_that_dont_like_trailing_commas
} bytecode_enum_t;
/* ---------------------- LISP-FUNCTIONS ----------------------- */
/* (SYS::%FUNTABREF i) returns the name of function Nr. i from the function-
table (a symbol), resp. NIL if i is not in the right range. */
LISPFUNNF(funtabref,1)
{
var object arg = popSTACK(); /* argument */
var uintV i;
if (posfixnump(arg) /* should be Fixnum >=0 */
&& (i = posfixnum_to_V(arg),
i < FUNTAB_length+FUNTABR_length)) { /* and < table-length */
/* Name of the indexed element of the table: */
value1 = (i < FUNTAB_length
? FUNTAB[i] /* from FUNTAB1/2 */
: FUNTABR[i-FUNTAB_length] /* resp. from FUNTABR */
)->name;
} else {
value1 = NIL; /* or NIL */
}
mv_count=1; /* as value */
}
/* (SYS::SUBR-INFO obj) returns information for this SUBR, if obj is a SUBR
(or a Symbol with a SUBR as global function definition),
6 values:
name Name,
req-anz number of required parameters,
opt-anz number of optional parameters,
rest-p flag, if &rest is specified,
keywords list of admissible keywords (empty: no &key specified),
allow-other-keys flag, if additional keywords are allowed,
otherwise NIL. */
LISPFUNNR(subr_info,1)
{
var object obj = popSTACK();
if (!subrp(obj)) {
if (!(symbolp(obj) && subrp(Symbol_function(obj)))) {
VALUES0; return; /* no SUBR -> no value */
}
obj = Symbol_function(obj);
}
/* obj is a SUBR */
pushSTACK(TheSubr(obj)->name); /* Name */
pushSTACK(fixnum(TheSubr(obj)->req_anz)); /* req-anz (req-nr) */
pushSTACK(fixnum(TheSubr(obj)->opt_anz)); /* opt-anz (opt-nr) */
pushSTACK(TheSubr(obj)->rest_flag == subr_norest ? NIL : T); /* rest-p */
/* during bootstrap, before defseq.lisp is loaded, this may fail: */
coerce_sequence(TheSubr(obj)->keywords,S(list),false);
/* keyword-vector as list (during bootstrap: vector) */
pushSTACK(eq(value1,nullobj) ? (object)TheSubr(obj)->keywords : value1);
pushSTACK(TheSubr(obj)->key_flag == subr_key_allow ? T : NIL); /* allow-other-keys */
funcall(L(values),6); /* 6 values */
}
/* ----------------------- SUBROUTINES ----------------------- */
/* UP: unwinds a frame, which is pointed at by STACK.
unwind();
The values mv_count/mv_space remain unmodified.
If it is no Unwind-Protect-Frame: return normally.
If it is a Unwind-Protect-Frame:
save the values, climbs(?) up STACK and SP
and then calls unwind_protect_to_save.fun .
changes STACK
can trigger GC */
global /*maygc*/ void unwind (void)
{
var fcint frame_info = framecode(STACK_0);
GCTRIGGER_IF(frame_info == APPLY_frame_info || frame_info == TRAPPED_APPLY_frame_info
|| frame_info == EVAL_frame_info || frame_info == TRAPPED_EVAL_frame_info,
GCTRIGGER1(mv_space));
#ifdef unwind_bit_t
if (frame_info & bit(unwind_bit_t)) /* anything to do? */
#else
if (frame_info >= unwind_limit_t) /* anything to do? */
#endif
{ /* (not at APPLY, EVAL untrapped, CATCH, HANDLER,
IBLOCK or ITAGBODY unnested) */
if ((frame_info & bit(skip2_bit_t)) == 0) { /* ENV- or DYNBIND-Frame? */
#ifdef entrypoint_bit_t
if (frame_info & bit(entrypoint_bit_t)) /* BLOCK, TAGBODY, CATCH etc. ? */
#else
if (frame_info < entrypoint_limit_t) /* BLOCK, TAGBODY, CATCH etc. ? */
#endif
/* Frame with Exitpoint */
if (frame_info & bit(blockgo_bit_t)) { /* BLOCK or TAGBODY? */
/* BLOCK_FRAME or TAGBODY_FRAME */
if (frame_info & bit(cframe_bit_t)) { /* compiled? */
/* CBLOCK_FRAME or CTAGBODY_FRAME
In Cons (NAME/Tags . <Framepointer>) */
Cdr(STACK_(frame_ctag)) = disabled; /* disable Exit/Tags */
} else {
/* IBLOCK_FRAME or ITAGBODY_FRAME, nested
In Cons (NAME/Tags . <Framepointer>)
(first pair of alist next_env) */
Cdr(Car(STACK_(frame_next_env))) = disabled; /* disable Exit/Tags */
}
} else {
/* UNWIND_PROTECT_FRAME DRIVER_FRAME or trapped APPLY/EVAL_FRAME */
if (frame_info & bit(dynjump_bit_t)) {
/* UNWIND_PROTECT_FRAME or DRIVER_FRAME */
if (frame_info & bit(driver_bit_t)) {
/* DRIVER_FRAME */
} else {
/* UNWIND_PROTECT_FRAME */
enter_frame_at_STACK();
}
} else {
/* trapped APPLY/EVAL_FRAME
like in the tracer: */
var object values;
mv_to_list(); values = popSTACK(); /* pack values into list */
dynamic_bind(S(trace_values),values); /* bind *TRACE-VALUES* */
break_driver(true); /* call break-driver */
list_to_mv(Symbol_value(S(trace_values)), /* build values again */
fehler_mv_zuviel(framecode(STACK_(0+3))==
TRAPPED_EVAL_frame_info
? S(eval)
: S(apply)););
dynamic_unbind(S(trace_values)); /* unbind */
}
}
else {
#ifdef HAVE_SAVED_REGISTERS
if ((frame_info & bit(callback_bit_t)) == 0) {
/* CALLBACK_FRAME */
var gcv_object_t* new_STACK = topofframe(STACK_0); /* Pointer to Frame */
/* set callback_saved_registers: */
callback_saved_registers = (struct registers *)(aint)as_oint(STACK_1);
/* set STACK, thus unwind frame: */
setSTACK(STACK = new_STACK);
goto fertig;
} else
#endif
{
/* VAR_FRAME or FUN_FRAME */
var gcv_object_t* new_STACK = topofframe(STACK_0); /* Pointer to Frame */
if (frame_info & bit(fun_bit_t)) {
/* for functions: do nothing */
} else {
/* VAR_FRAME, bindingptr iterates over the bindungs */
var gcv_object_t* frame_end = STACKpointable(new_STACK);
var gcv_object_t* bindingptr = &STACK_(frame_bindings); /* start of the variable-/functionbindings */
while (bindingptr != frame_end) {
if (as_oint(*(bindingptr STACKop 0)) & wbit(dynam_bit_o))
if (as_oint(*(bindingptr STACKop 0)) & wbit(active_bit_o)) {
/* binding static or inactive -> nothing to do
binding dynamic and active -> write back value: */
TheSymbolflagged(*(bindingptr STACKop varframe_binding_sym))->symvalue =
*(bindingptr STACKop varframe_binding_value);
}
bindingptr skipSTACKop varframe_binding_size; /* next binding */
}
}
/* set STACK, thus unwind frame: */
setSTACK(STACK = new_STACK);
goto fertig;
}
}
} else {
/* DYNBIND_FRAME or CALLBACK_FRAME or ENV_FRAME */
if (frame_info & bit(envbind_bit_t)) {
/* ENV_FRAME */
var gcv_object_t* ptr = &STACK_1;
switch (frame_info & envbind_case_mask_t) {
case (ENV1V_frame_info & envbind_case_mask_t): /* 1 VAR_ENV */
aktenv.var_env = *ptr; ptr skipSTACKop 1; break;
case (ENV1F_frame_info & envbind_case_mask_t): /* 1 FUN_ENV */
aktenv.fun_env = *ptr; ptr skipSTACKop 1; break;
case (ENV1B_frame_info & envbind_case_mask_t): /* 1 BLOCK_ENV */
aktenv.block_env = *ptr; ptr skipSTACKop 1; break;
case (ENV1G_frame_info & envbind_case_mask_t): /* 1 GO_ENV */
aktenv.go_env = *ptr; ptr skipSTACKop 1; break;
case (ENV1D_frame_info & envbind_case_mask_t): /* 1 DECL_ENV */
aktenv.decl_env = *ptr; ptr skipSTACKop 1; break;
case (ENV2VD_frame_info & envbind_case_mask_t): /* 1 VAR_ENV and 1 DECL_ENV */
aktenv.var_env = *ptr; ptr skipSTACKop 1;
aktenv.decl_env = *ptr; ptr skipSTACKop 1;
break;
case (ENV5_frame_info & envbind_case_mask_t): /* all 5 Environments */
aktenv.var_env = *ptr; ptr skipSTACKop 1;
aktenv.fun_env = *ptr; ptr skipSTACKop 1;
aktenv.block_env = *ptr; ptr skipSTACKop 1;
aktenv.go_env = *ptr; ptr skipSTACKop 1;
aktenv.decl_env = *ptr; ptr skipSTACKop 1;
break;
default: NOTREACHED;
}
} else {
/* DYNBIND_FRAME */
var gcv_object_t* new_STACK = topofframe(STACK_0); /* Pointer to Frame */
var gcv_object_t* frame_end = STACKpointable(new_STACK);
var gcv_object_t* bindingptr = &STACK_1; /* start of the bindings */
/* bindingptr iterates through the bindings */
until (bindingptr == frame_end) {
Symbol_value(*(bindingptr STACKop 0)) = *(bindingptr STACKop 1);
bindingptr skipSTACKop 2; /* next binding */
}
/* set STACK, thus unwind frame: */
setSTACK(STACK = new_STACK);
goto fertig;
}
}
}
/* set STACK, thus unwind frame: */
setSTACK(STACK = topofframe(STACK_0));
fertig: ;
}
/* UP: "unwinds" the STACK up to the next DRIVER_FRAME and
jumps into the corresponding top-level-loop.
if count=0, unwind to TOP; otherwise reset that many times */
nonreturning_function(global, reset, (uintL count)) {
/* when unwinding UNWIND-PROTECT-frames, don't save values: */
bool top_p = (count==0);
VALUES0;
unwind_protect_to_save.fun = (restartf_t)&reset;
loop {
/* does STACK end here? */
if (eq(STACK_0,nullobj) && eq(STACK_1,nullobj)) {
driver(); quit(); /* STACK completely gone -> restart */
}
if (framecode(STACK_0) & bit(frame_bit_t)) {
/* at STACK_0: beginning of a frame */
if (framecode(STACK_0) == DRIVER_frame_info /* DRIVER_FRAME ? */
&& !top_p && --count==0) /* done count resets */
break; /* yes -> found */
unwind(); /* unwind frame */
} else {
/* STACK_0 contains a normal LISP-object */
skipSTACK(1);
}
}
/* At STACK_0 a new Driver-Frame starts. */
enter_frame_at_STACK();
}
/* UP: dynamically binds the symbols of list symlist
to the the values of list vallist.
progv(symlist,vallist);
> symlist, vallist: two lists
Exactly one variable binding frame is constructed.
changes STACK
can trigger GC */
global maygc void progv (object symlist, object vallist) {
/* check symlist */
var uintL llen = 0;
var bool need_new_symlist = true;
pushSTACK(symlist); pushSTACK(vallist);
for (pushSTACK(symlist); consp(STACK_0); STACK_0 = Cdr(STACK_0), llen++) {
var object sym = check_symbol_non_constant(Car(STACK_0),S(progv));
if (!eq(sym,Car(STACK_0))) { /* changed symbol ==> must copy symlist */
if (need_new_symlist) { /* have not copied symlist yet */
pushSTACK(sym); /* save sym */
STACK_1 = STACK_3 = copy_list(STACK_3); /* copy symlist */
var uintL pos = llen; /* skip copy ... */
while (pos--) STACK_1 = Cdr(STACK_1); /* ... to the right position */
need_new_symlist = false; /* do not copy symlist twice */
sym = popSTACK(); /* restore sym */
}
Car(STACK_0) = sym;
}
}
skipSTACK(1); vallist = popSTACK(); symlist = popSTACK();
/* demand room on STACK: */
get_space_on_STACK(llen * 2 * sizeof(gcv_object_t));
/* build frame: */
var gcv_object_t* top_of_frame = STACK; /* Pointer to Frame */
var object symlistr = symlist;
while (consp(symlistr)) { /* loop over symbol list */
var object sym = Car(symlistr);
pushSTACK(Symbol_value(sym)); /* old value of the variables */
pushSTACK(sym); /* variable */
symlistr = Cdr(symlistr);
}
finish_frame(DYNBIND);
/* building of frame completed, now change the values of the variables: */
while (consp(symlist)) {
if (atomp(vallist)) {
/* value list shorter than symbol list
-> all further "values" are #<UNBOUND> */
do {
Symbol_value(Car(symlist)) = unbound;
symlist = Cdr(symlist);
} while (consp(symlist));
break;
}
/* symbol obtains new value: */
Symbol_value(Car(symlist)) = Car(vallist);
symlist = Cdr(symlist); vallist = Cdr(vallist);
}
}
/* UP: unwinds the dynamic nesting in STACK up to the frame
(exclusively), which is pointed to by upto, and then jumps to it.
unwind_upto(upto);
> upto: pointer to a frame (into the stack, without typinfo).
saves the values mv_count/mv_space.
changes STACK,SP
can trigger GC
then jumps to the frame, which was found. */
nonreturning_function(global /*maygc*/, unwind_upto, (gcv_object_t* upto_frame)) {
GCTRIGGER1(mv_space);
unwind_protect_to_save.fun = &unwind_upto;
unwind_protect_to_save.upto_frame = upto_frame;
until (STACK == upto_frame) { /* arrived at target-frame? */
if (framecode(STACK_0) & bit(frame_bit_t)) { /* is it a frame? */
unwind(); /* yes -> unwind */
/* (if this is a Unwind-Protect-Frame, then
unwind_upto(upto_frame) is called again, and we are again here.) */
} else {
skipSTACK(1); /* no -> simply go ahead */
}
}
/* now STACK points to the FRAME found. */
enter_frame_at_STACK();
}
/* UP: throws to the Tag tag and passes the values mv_count/mv_space.
returns only, if there is no CATCH-Frame for this tag.
throw_to(tag); */
global void throw_to (object tag) {
/* search for Catch-Frame with Tag = tag: */
var gcv_object_t* FRAME = STACK;
loop { /* search in the Stack starting at FRAME
for a CATCH-Frame with the same Tag: */
if (eq(FRAME_(0),nullobj)) /* end of Stack? */
return; /* yes -> no suitable Catch there -> jump back */
if (framecode(FRAME_(0)) & bit(frame_bit_t)) {
/* found frame */
if ((framecode(FRAME_(0)) == CATCH_frame_info) /* Catch-Frame? */
&& eq(FRAME_(frame_tag),tag)) /* with the same tag? */
break; /* yes -> search-loop finished */
/* skip Frame: */
FRAME = topofframe(FRAME_(0));
} else {
FRAME skipSTACKop 1;
}
}
/* FRAME points to the lowest CATCH-Frame with the same Tag */
unwind_upto(FRAME); /* unwind upto there, then jump */
}
/* UP: Invokes all handlers for condition cond. Returns only, if none
of these handlers feels responsible (i.e. if each handler returns).
invoke_handlers(cond);
can trigger GC
This deactivates the handler, that is called right now,
and all newer handlers. */
global maygc void invoke_handlers (object cond) {
/* Also deactivates the handler being called, and all newer handlers.
the handler-ranges, which are screened off: */
var stack_range_t* other_ranges = inactive_handlers;
var stack_range_t new_range;
/* Search for Handler-Frame, that handles a Type with (TYPEP cond type): */
var gcv_object_t* FRAME = STACK;
loop { /* search in Stack starting at FRAME for a suitable HANDLER-Frame: */
if (!(other_ranges == NULL) && (FRAME == other_ranges->low_limit)) {
FRAME = other_ranges->high_limit;
other_ranges = other_ranges->next;
} else if (eq(FRAME_(0),nullobj)) { /* End of Stack? */
break; /* yes -> finised, jump back */
} else if (framecode(FRAME_(0)) & bit(frame_bit_t)) {
/* found frame */
if (framecode(FRAME_(0)) == HANDLER_frame_info) { /* Handler-Frame? */
/* loop over types of the vectors #(type1 label1 ... typem labelm): */
var uintL m2 = Svector_length(Car(FRAME_(frame_handlers))); /* 2*m */
var uintL i = 0;
do {
pushSTACK(cond); /* save cond */
pushSTACK(cond);
pushSTACK(TheSvector(Car(FRAME_(frame_handlers)))->data[i]); /* typei */
funcall(S(safe_typep),2); /* execute (SYS::SAFE-TYPEP cond typei) */
if (!nullp(value1)) { /* found a suitable handler */
/* CLtL2 S. 873, 884:
"A handler is executed in the dynamic context
of the signaler, except that the set of available condition
handlers will have been rebound to the value that was active
at the time the condition handler was made active."
we make the whole thing bullet-proof by an
Unwind-Protect-Frame: */
var stack_range_t* saved_inactive_handlers = inactive_handlers;
new_range.low_limit = STACK;
new_range.high_limit = topofframe(FRAME_(0));
new_range.next = other_ranges;
var gcv_object_t* top_of_frame = STACK;
var sp_jmp_buf returner; /* return point */
finish_entry_frame(UNWIND_PROTECT,returner,, {
var restartf_t fun = unwind_protect_to_save.fun;
var gcv_object_t* arg = unwind_protect_to_save.upto_frame;
skipSTACK(2); /* unwind Unwind-Protect-Frame */
/* Cleanup: reactivate Handler: */
inactive_handlers = saved_inactive_handlers;
/* and jump ahead: */
fun(arg);
NOTREACHED;
});
/* deactivate Handler: */
inactive_handlers = &new_range;
if (!nullp(Cdr(FRAME_(frame_handlers)))) {
/* make information available for Handler: */
handler_args.condition = STACK_(0+2);
handler_args.stack = FRAME STACKop 4;
handler_args.sp = (SPint*)(aint)as_oint(FRAME_(frame_SP));
handler_args.spdepth = Cdr(FRAME_(frame_handlers));
/* call Handler: */
var object closure = FRAME_(frame_closure);
var object codevec = TheCclosure(closure)->clos_codevec;
var uintL index = (TheCodevec(codevec)->ccv_flags & bit(7) ? CCV_START_KEY : CCV_START_NONKEY)
+ (uintL)posfixnum_to_V(TheSvector(Car(FRAME_(frame_handlers)))->data[i+1]);
interpret_bytecode(closure,codevec,index);
} else {
/* call C-Handler: */
void* handler_fn = TheMachineCode(FRAME_(frame_closure));
((void (*) (void*, gcv_object_t*, object, object)) handler_fn)
((void*)(aint)as_oint(FRAME_(frame_SP)),FRAME,
TheSvector(Car(FRAME_(frame_handlers)))->data[i+1],
STACK_(0+2));
}
skipSTACK(2); /* unwind Unwind-Protect-Frame */
/* reactivate Handler: */
inactive_handlers = saved_inactive_handlers;
}
cond = popSTACK(); /* cond back */
i += 2;
} while (i < m2);
}
/* skip Frame: */
FRAME = topofframe(FRAME_(0));
} else {
FRAME skipSTACKop 1;
}
}
var object handler = Symbol_function(S(global_handler));
if (boundp(handler)) { /* unbound during bootstrap */
pushSTACK(cond); funcall(handler,1); /* (GLOBAL-HANDLER cond) */
}
}
/* UP: finds out, if an object is a function name, i.e. a Symbol or
a list of the form (SETF symbol).
funnamep(obj)
> obj: Object
< result: true if function name */
global bool funnamep (object obj) {
if (symbolp(obj))
return true;
if (consp(obj) && eq(Car(obj),S(setf))) {
obj = Cdr(obj);
if (consp(obj) && nullp(Cdr(obj)) && symbolp(Car(obj)))
return true;
}
return false;
}
/* UP: find whether the symbol is bound in the environment */
local inline gcv_object_t* symbol_env_search (object sym, object venv)
{
/* Does the binding at bindptr bind the symbol sym? */
#ifdef NO_symbolflags
#define binds_sym_p(bindingptr) \
(eq(*(bindingptr STACKop 1),sym) /* the right symbol? */ \
&& eq(*(bindingptr STACKop 0),fixnum(bit(active_bit)))) /* active & static? */
#else
var object cmp = SET_BIT(sym,active_bit_o); /* for comparison: binding must be active */
#define binds_sym_p(bindingptr) \
(eq(*(bindingptr STACKop 0),cmp)) /* right symbol & active & static? */
#endif
next_env:
if (framepointerp(venv)) {
/* Environment is a Pointer to a variable-binding-frame */
var gcv_object_t* FRAME = TheFramepointer(venv);
var uintL count = as_oint(FRAME_(frame_anz)); /* number of bindings */
if (count > 0) {
var gcv_object_t* bindingsptr = &FRAME_(frame_bindings); /* 1st binding */
do {
if (binds_sym_p(bindingsptr)) /* right symbol & active & static? */
return bindingsptr STACKop varframe_binding_value;
bindingsptr skipSTACKop varframe_binding_size; /* no: next binding */
} while (--count);
}
venv = FRAME_(frame_next_env);
goto next_env;
}
var bool from_inside_macrolet = false;
for (;;) {
if (simple_vector_p(venv)) {
/* environment is a simple-vector */
var uintL count = floor(Svector_length(venv),2); /* number of bindings */
var gcv_object_t* ptr = &TheSvector(venv)->data[0];
dotimesL(count,count, {
if (eq(*ptr,sym)) { /* right symbol? */
if (from_inside_macrolet && !eq(*(ptr+1),specdecl)
&& !symbolmacrop(*(ptr+1)))
goto macrolet_error;
return ptr+1;
}
ptr += 2; /* next binding */
});
venv = *ptr; /* next environment */
continue;
} else if (consp(venv)) {
/* environment is a MACROLET capsule */
ASSERT(eq(Car(venv),S(macrolet)));
from_inside_macrolet = true;
venv = Cdr(venv);
continue;
} else
break;
}
/* Environment is NIL */
return NULL;
#undef binds_sym_p
macrolet_error:
pushSTACK(sym); /* SOURCE-PROGRAM-ERROR slot DETAIL */
pushSTACK(S(macrolet)); pushSTACK(sym);
fehler(program_error,
GETTEXT("Invalid access to the value of the lexical variable ~S from within a ~S definition"));
}
/* (SYS::SPECIAL-VARIABLE-P symbol &optional environment)
tests whether the symbol is a special variable or a constant.
A missing or NIL environment means the global environment. */
LISPFUN(special_variable_p,seclass_read,1,1,norest,nokey,0,NIL)
{
var object symbol = check_symbol(STACK_1);
var object env = STACK_0; skipSTACK(2);
if (special_var_p(TheSymbol(symbol))) {
value1 = T;
} else if (missingp(env)) {
value1 = NIL;
} else {
if (simple_vector_p(env)) {
var uintL len = Svector_length(env);
if (len == 2 || len == 5)
env = TheSvector(env)->data[0]; /* venv */
else
fehler_environment(env);
}
var gcv_object_t *binding = symbol_env_search(symbol,env);
if ((binding != NULL) && eq(*binding,specdecl))
value1 = T;
else
value1 = NIL;
}
mv_count = 1;
}
/* UP: returns the value of a symbol in an environment.
sym_value(symbol,venv,&symbolmacro)
> symbol: Symbol
> venv: a Variable- and Symbolmacro-Environment
< symbolmacro: symbol-macro definition, or nullobj if not a symbol-macro
< result: value of the symbol in this environment, or
nullobj if a symbol-macro */
local gcv_object_t sym_value (object sym, object env, object* symbolmacro_)
{
if (special_var_p(TheSymbol(sym))) {
/* Constants and symbols declared special have only global values. */
goto global_value;
} else {
var gcv_object_t* binding = symbol_env_search(sym,env);
if (binding != NULL) {
var object val = *binding;
if (eq(val,specdecl))
goto global_value;
if (symbolmacrop(val)) {
*symbolmacro_ = val;
return nullobj;
}
*symbolmacro_ = nullobj;
return val;
}
if (symmacro_var_p(TheSymbol(sym))) {
/* Fetch the symbol-macro definition from the property list: */
var object symbolmacro = get(sym,S(symbolmacro));
if (!eq(symbolmacro,unbound)) {
ASSERT(globalsymbolmacrop(symbolmacro));
*symbolmacro_ = TheGlobalSymbolmacro(symbolmacro)->globalsymbolmacro_definition;
return nullobj;
}
/* Huh? The symbol-macro definition got lost. */
clear_symmacro_flag(TheSymbol(sym));
}
}
global_value: /* the global (dynamic) value of the Symbol */
*symbolmacro_ = nullobj;
return Symbol_value(sym);
}
/* UP: determines, if a Symbol is a Macro in the current environment.
sym_macrop(symbol)
> symbol: Symbol
< result: true if sym is a Symbol-Macro */
global bool sym_macrop (object sym) {
var object symbolmacro;
sym_value(sym,aktenv.var_env,&symbolmacro);
return !eq(symbolmacro,nullobj);
}
/* UP: Sets the value of a Symbol in the current Environment.
setq(symbol,value);
> symbol: Symbol, no constant, not a symbol-macro in the current Environment
> value: desired value of the Symbols in the current Environment
< result: value
can trigger GC */
global maygc object setq (object sym, object value)
{
if (special_var_p(TheSymbol(sym))) {
/* Constants and symbols declared special have only global values. */
goto global_value;
} else {
var gcv_object_t* binding = symbol_env_search(sym,aktenv.var_env);
if (binding != NULL) {
var object val = *binding;
if (eq(val,specdecl))
goto global_value;
ASSERT(!symbolmacrop(val));
return *binding = value;
}
ASSERT(!symmacro_var_p(TheSymbol(sym)));
}
global_value: /* the global (dynamic) value of the Symbol */
pushSTACK(value); pushSTACK(sym);
symbol_value_check_lock(S(setq),sym);
Symbol_value(STACK_0) = STACK_1;
skipSTACK(1);
return popSTACK();
}
# UP: returns for a Symbol its function definition in an Environment
# sym_function(sym,fenv)
# > sym: function name (e.g. Symbol)
# > fenv: a function- and macro-bindung-environment
# < result: function definition, either unbound (if undefined function)
# or Closure/SUBR/FSUBR/Macro/FunctionMacro.
global object sym_function (object sym, object env)
{
var object value;
{
next_env:
if (framepointerp(env)) {
# Environment is a Pointer to a function-binding-frame
var gcv_object_t* FRAME = TheFramepointer(env);
var uintL count = as_oint(FRAME_(frame_anz)); # number of bindings
if (count > 0) {
var gcv_object_t* bindingsptr = &FRAME_(frame_bindings); # pointer to the first binding
dotimespL(count,count, {
if (equal(*(bindingsptr STACKop 0),sym)) { # right Symbol?
value = *(bindingsptr STACKop 1); goto fertig;
}
bindingsptr skipSTACKop 2; # no: next binding
});
}
env = FRAME_(frame_next_env);
goto next_env;
}
var bool from_inside_macrolet = false;
for (;;) {
if (simple_vector_p(env)) {
# Environment is a Simple-Vector
var uintL count = floor(Svector_length(env),2); # number of bindings
var gcv_object_t* ptr = &TheSvector(env)->data[0];
dotimesL(count,count, {
if (equal(*ptr,sym)) { # right Symbol?
value = *(ptr+1);
if (from_inside_macrolet && !macrop(value))
goto macrolet_error;
goto fertig;
}
ptr += 2; # next binding
});
env = *ptr; # next Environment
continue;
} else if (consp(env)) {
/* environment is a MACROLET capsule */
ASSERT(eq(Car(env),S(macrolet)));
from_inside_macrolet = true;
env = Cdr(env);
continue;
} else
# Environment is NIL
goto global_value;
}
}
global_value: # global function-definition
if (!symbolp(sym)) {
sym = get(Car(Cdr(sym)),S(setf_function)); # (get ... 'SYS::SETF-FUNCTION)
if (!symbolp(sym)) # should be (uninterned) Symbol
return unbound; # else undefined
}
return Symbol_function(sym);
fertig: # Symbol found active in Environment, "Value" value
# (a Closure or Macro or FunctionMacro or NIL)
# if Definition = NIL (during LABELS), the function is passed for
# as undefined:
if (nullp(value))
value = unbound;
return value;
macrolet_error:
pushSTACK(sym); /* SOURCE-PROGRAM-ERROR slot DETAIL */
pushSTACK(S(macrolet)); pushSTACK(sym);
fehler(source_program_error,
GETTEXT("Invalid access to the local function definition of ~S from within a ~S definition"));
}
# UP: evaluates a Form in a given Environment.
# eval_5env(form,var,fun,block,go,decl);
# > var_env: value for VAR_ENV
# > fun_env: value for FUN_ENV
# > block_env: value for BLOCK_ENV
# > go_env: value for GO_ENV
# > decl_env: value for DECL_ENV
# > form: Form
# < mv_count/mv_space: values
# can trigger GC
global maygc Values eval_5env (object form, object var_env, object fun_env,
object block_env, object go_env, object decl_env) {
# bind Environments:
make_ENV5_frame();
# set current Environments:
aktenv.var_env = var_env;
aktenv.fun_env = fun_env;
aktenv.block_env = block_env;
aktenv.go_env = go_env;
aktenv.decl_env = decl_env;
# evaluate Form:
eval(form);
# unwind Environment-Frame:
unwind();
return; # finished
}
# UP: evaluates a form in an empty environment.
# eval_noenv(form);
# > form: Form
# < mv_count/mv_space: values
# can trigger GC
global maygc Values eval_noenv (object form) {
return_Values eval_5env(form,NIL,NIL,NIL,NIL,O(top_decl_env));
}
# UP: "nests" a FUN-Environment, i.e. writes all active bindings
# from the Stack into freshly allocated vectors.
# nest_fun(env)
# > env: FUN-Env
# < result: same environment, no Pointer into the Stack
# can trigger GC
global maygc object nest_fun (object env)
{
var uintL depth = 0; # recursion counter := 0
# Pseudorecursion with Input env, Output env.
nest_start: # start of recursion
if (framepointerp(env)) {
# env is a pointer to a STACK-Frame.
check_STACK();
pushSTACK(env); # save env
# execute nest_fun(NEXT_ENV(env)) "disrecursified" :-) :
{
var gcv_object_t* FRAME = TheFramepointer(env);
env = FRAME_(frame_next_env); depth++; goto nest_start;
}
nest_reentry: depth--;
# NEXT_ENV is now nested.
{
var gcv_object_t* FRAME = TheFramepointer(STACK_0); # next STACK-Frame to be nested
STACK_0 = env; # bisher genestetes Environment
var uintL anzahl = as_oint(FRAME_(frame_anz)); # number of not yet netsted bindings
if (anzahl == 0) {
# no bindings -> unnecessary, to create a vector.
env = popSTACK();
} else {
# create vector for anzahl bindings:
env = allocate_vector(2*anzahl+1);
# and fill:
{
var gcv_object_t* ptr = &TheSvector(env)->data[0];
var gcv_object_t* bindingsptr = &FRAME_(frame_bindings); # Pointer to the first binding
# put anzahl bindings starting at bindingsptr into the vector at ptr:
dotimespL(anzahl,anzahl, {
*ptr++ = *(bindingsptr STACKop 0); # copy binding into the vector
*ptr++ = *(bindingsptr STACKop 1);
bindingsptr skipSTACKop 2;
});
*ptr++ = popSTACK(); # put nested NEXT_ENV into vector
}
FRAME_(frame_next_env) = env; # Vector as NEXT_ENV into the Frame
FRAME_(frame_anz) = as_object(0); # new number of not yet nested bindings
}
}
}
# finished with this Nest-substep.
if (depth>0) # end of recursion
goto nest_reentry;
return env;
}
# UP: "nests" a VAR-Environment, i.e. writes all active bindings
# from the Stack in freshly allocated vectors.
# nest_var(env)
# > env: VAR-Env
# < result: same Environment, no Pointer in the Stack
# can trigger GC
local maygc object nest_var (object env)
{
var uintL depth = 0; # Recursion counter := 0
# Pseudorecursion with Input env, Output env.
nest_start: # start of Recursion
if (framepointerp(env)) {
# env is a Pointer to a STACK-Frame.
check_STACK();
pushSTACK(env); # save env
# execute nest_var(NEXT_ENV(env)) "disrecursified" :-) :
{
var gcv_object_t* FRAME = TheFramepointer(env);
env = FRAME_(frame_next_env); depth++; goto nest_start;
}
nest_reentry: depth--;
# NEXT_ENV is now nested.
{
var gcv_object_t* FRAME = TheFramepointer(STACK_0); # next STACK-Frame to be nested
STACK_0 = env; # formerly nested Environment
# Search (from bottom) the first active among the not yet
# nested bindings:
var uintL anzahl = as_oint(FRAME_(frame_anz)); # number of not yet nested bindings
var uintL count = 0;
var gcv_object_t* bindingsptr = &FRAME_(frame_bindings); # Pointer to the first binding
until ((count>=anzahl) # all unnested bindings through?
|| (as_oint(*(bindingsptr STACKop 0)) & wbit(active_bit_o))) { # discovered active binding?
# no -> continue search:
bindingsptr skipSTACKop varframe_binding_size;
count++;
}
# Below bindingsptr are count inactive bindings.
# From bindingsptr on there are anzahl-count active, to be nested bindings.
anzahl = anzahl-count; # number of bindings to be nested
if (anzahl == 0) {
# no bindings -> creating a vector is unnecessary.
env = popSTACK();
} else {
# create vector for anzahl bindings:
env = allocate_vector(2*anzahl+1);
# and fill:
{
var gcv_object_t* ptr = &TheSvector(env)->data[0];
# put bindungs starting at bindingsptr in the vector at ptr:
dotimespL(anzahl,anzahl, {
if (as_oint(*(bindingsptr STACKop varframe_binding_mark)) & wbit(dynam_bit_o)) { # binding dynamic?
# dynamic binding, lexical scope
*ptr++ = symbol_without_flags(*(bindingsptr STACKop varframe_binding_sym)); # put Symbol without Flag-Bits in the Vector
*ptr++ = specdecl; # mark as special reference
# binding stays active in the Frame
} else {
# static binding, lexical scope
*(bindingsptr STACKop varframe_binding_mark) =
CLR_BIT(*(bindingsptr STACKop varframe_binding_mark),active_bit_o); /* deactivate binding */
*ptr++ = *(bindingsptr STACKop varframe_binding_sym); # copy binding in the vector
*ptr++ = *(bindingsptr STACKop varframe_binding_value);
}
bindingsptr skipSTACKop varframe_binding_size;
});
*ptr++ = popSTACK(); # put nested NEXT_ENV in the vector
}
FRAME_(frame_next_env) = env; # vector as NEXT_ENV in the Frame
FRAME_(frame_anz) = fake_gcv_object(count); # new number of not yet nested bindings
}
}
}
# finished with this Nest-substep.
if (depth>0) # end of recursion
goto nest_reentry;
return env;
}
/* UP: Nests the Environments in *env (i.e. writes all information in
Stack-independent structures) and pushes them onto the STACK.
(The values VAR_ENV, FUN_ENV, BLOCK_ENV, GO_ENV, DECL_ENV will not
be changed, because inactive bindings might poss. still sit in the frames.
It has to be feasible, to activate these bindings without change of VAR_ENV.)
nest_env(env)
> gcv_environment_t* env: Pointer to five Environments
< gcv_environment_t* result: Pointer to the Environments in the STACK
changes STACK, can trigger GC */
global maygc gcv_environment_t* nest_env (gcv_environment_t* env5)
{
/* First copy all Environments in the STACK: */
make_STACK_env(env5->var_env,env5->fun_env,env5->block_env,env5->go_env,
env5->decl_env,env5 = );
/* DECL_ENV: Not to be changed. */
{ /* GO_ENV: */
var object env = env5->go_env;
var uintL depth = 0; /* recursion depth := 0 */
/* pseudo-recursion: nests a GO_ENV. */
/* Input: env, a GO_ENV. Output: env, with Alist. */
nest_go_start: { /* start of recursion */
var gcv_object_t* FRAME;
if (framepointerp(env)) {
/* env is a pointer into the STACK to a ITAGBODY-frame. */
check_STACK();
FRAME = TheFramepointer(env);
if (framecode(FRAME_(0)) & bit(nested_bit_t)) { /* frame already nested? */
env = FRAME_(frame_next_env); /* yes -> fetch former Alist */
} else {
pushSTACK(env); /* save env */
/* execute nest_go(NEXT_ENV(env)) "disrecursivied": */
env = FRAME_(frame_next_env); depth++; goto nest_go_start;
nest_go_reentry: depth--;
{ /* NEXT_ENV is now nested. */
var object frame = STACK_0; /* next to be nested STACK-Frame */
FRAME = uTheFramepointer(frame);
STACK_0 = env; /* so far nested Environment */
var gcv_object_t* tagsptr = &FRAME_(frame_bindings); /* Pointer to the bottom Tag */
var gcv_object_t* frame_end = STACKpointable(topofframe(FRAME_(0))); /* Pointer to Frame */
var uintL count = /* number of tags */
/* subtract the pointers tagsptr and frame_end (both without Typinfo!): */
STACK_item_count(tagsptr,frame_end) / 2;
{ /* create vector for count tags: */
var object tagvec = allocate_vector(count);
/* and fill: */
if (count > 0) {
var gcv_object_t* ptr = &TheSvector(tagvec)->data[0];
/* put tags starting at tagsptr in the vector at ptr: */
dotimespL(count,count, {
*ptr++ = *(tagsptr STACKop 0);
tagsptr skipSTACKop 2;
});
}
pushSTACK(tagvec); /* and save */
}
{ /* create next Alist Cons (cons tag-vector frame-pointer) : */
var object new_cons = allocate_cons();
Car(new_cons) = STACK_0; /* tagvec */
Cdr(new_cons) = frame;
STACK_0 = new_cons;
}
/* and prepend to Alist: */
env = allocate_cons();
Car(env) = popSTACK(); /* new_cons */
Cdr(env) = popSTACK(); /* previous Alist */
FRAME_(frame_next_env) = env; /* store new NEXT_ENV */
*(oint*)(&FRAME_(0)) |= wbit(nested_bit_o); /* this frame is now nested. */
}
}
}
/* finished with this Nest-Substep. */
if (depth>0) /* end of Recursion */
goto nest_go_reentry;
env5->go_env = env; /* file nested GO_ENV */
}
}
{ /* BLOCK_ENV: */
var object env = env5->block_env;
var uintL depth = 0; /* recursion depth := 0 */
/* Pseudo-Recursion: nests a BLOCK_ENV. */
/* Input: env, a BLOCK_ENV. Output: env, with Aliste. */
nest_block_start: { /* start of recursion */
var gcv_object_t* FRAME;
if (framepointerp(env)) {
/* env is a pointer into the STACK to a IBLOCK-Frame. */
check_STACK();
FRAME = TheFramepointer(env);
if (framecode(FRAME_(0)) & bit(nested_bit_t)) { /* Frame already nested? */
env = FRAME_(frame_next_env); /* yes -> fetch previous Alist */
} else {
pushSTACK(env); /* save env */
/* execute nest_block(NEXT_ENV(env)) "disrecursified": */
env = FRAME_(frame_next_env); depth++; goto nest_block_start;
nest_block_reentry: depth--;
{ /* NEXT_ENV is now nested. */
var object frame = STACK_0; /* next to be nested STACK-Frame */
FRAME = TheFramepointer(frame);
STACK_0 = env; /* so far nested Environment */
{ /* create next Alist Cons (cons Block-Name Frame-Pointer) : */
var object new_cons = allocate_cons();
Car(new_cons) = FRAME_(frame_name);
Cdr(new_cons) = frame;
pushSTACK(new_cons);
}
/* and prepend to the Aliste: */
env = allocate_cons();
Car(env) = popSTACK(); /* new_cons */
Cdr(env) = popSTACK(); /* previous Alist */
FRAME_(frame_next_env) = env; /* store new NEXT_ENV */
*(oint*)(&FRAME_(0)) |= wbit(nested_bit_o); /* this frame is now nested. */
}
}
}
}
/* finished with this Nest-Substep. */
if (depth>0) /* end of recursion */
goto nest_block_reentry;
env5->block_env = env; /* file nested BLOCK_ENV */
}
/* FUN_ENV: */
env5->fun_env = nest_fun(env5->fun_env);
/* VAR_ENV: */
env5->var_env = nest_var(env5->var_env);
/* done */
return env5;
}
# UP: Nests the current environments (i.e. writes all Information in
# Stack-independent Structures) and pushes them onto the STACK.
# (The values VAR_ENV, FUN_ENV, BLOCK_ENV, GO_ENV, DECL_ENV are not
# modified, because inactive bindings might poss. still sit in the Frames.
# It has to be feasible, to activate these bindings without change of VAR_ENV.)
# nest_aktenv()
# < gcv_environment* result: Pointer to the Environments in the STACK
# changes STACK, can trigger GC
#define nest_aktenv() nest_env(&aktenv)
# UP: augments a Declaration-Environment with a decl-spec.
# augment_decl_env(declspec,env)
# > declspec: Declaration-Specifier, a Cons
# > env: Declaration-Environment
# < result: new (poss. augmented) Declaration-Environment
# can trigger GC
global maygc object augment_decl_env (object new_declspec, object env)
{
var object decltype = Car(new_declspec); # Declaration-Type
# Is this a declaration type to be payed attention to?
# Is there a Decl-Spec of the form (DECLARATION ... decltype ...) in env?
# Aside: The List O(declaration_types) is the last Decl-Spec in env.
if (symbolp(decltype)) {
# loop over all local to be respected Declaration-Types:
var object declspecs = env;
while (consp(declspecs)) { # loop over all declspecs from env
var object declspec = Car(declspecs);
if (eq(Car(declspec),S(declaration)) # (DECLARATION ...) ?
&& !nullp(memq(decltype,Cdr(declspec))))
goto beachten;
declspecs = Cdr(declspecs);
}
}
# not to be respected Declaration.
return env; # leave env unchanged
beachten:
# a to be respected Declaration -> env := (cons new_declspec env)
pushSTACK(env); pushSTACK(new_declspec);
env = allocate_cons();
Car(env) = popSTACK(); Cdr(env) = popSTACK();
return env;
}
# UP: expands a form, if possible, (however it doesn't, if FSUBR-Call
# or Symbol or FunctionMacro-Call) in an Environment
# macroexp(form,venv,fenv);
# > form: Form
# > venv: a Variable- and Symbolmacro-Environment
# > fenv: a Function- and Macrobinding-Environment
# < value1: the expansion
# < value2: NIL, if not expanded,
# T, if expansion has taken place
# can trigger GC
global maygc void macroexp (object form, object venv, object fenv)
{
if (consp(form)) { # only lists can be a macro-call
var object funname = Car(form); # function name
if (symbolp(funname)) {
var object fdef = sym_function(funname,fenv); # fetch function definition
# is it a #<MACRO expander> ?
if (macrop(fdef)) {
# yes -> expand:
# execute (FUNCALL *MACROEXPAND-HOOK* expander form env) :
pushSTACK(TheMacro(fdef)->macro_expander); # expander as first argument
pushSTACK(form); # form as second argument
pushSTACK(fenv);
pushSTACK(nest_var(venv)); # nested Variable- and Symbolmacro-Environment
STACK_1 = nest_fun(STACK_1); # nested Functions- and Macrobinding-Environment
var object env = allocate_vector(2); # Environment for both
TheSvector(env)->data[0] = popSTACK(); # venv as 1. component
TheSvector(env)->data[1] = STACK_0; # fenv as 2. component
STACK_0 = env; # Environment as third Argument
funcall(Symbol_value(S(macroexpand_hook)),3);
value2 = T; # expanded Form as 1. value, T as 2. value
return;
}
}
}
# else, don't expand:
value1 = form; value2 = NIL;
}
# UP: expands a form, if possible, (also, when FSUBR-Call or
# Symbol, however not, when FunctionMacro-Call) in an Environment
# macroexp0(form,env);
# > form: Form
# > env: a Macroexpansion-Environment
# < value1: the Expansion
# < value2: NIL, if not expanded,
# T, if expansion has taken place
# can trigger GC
global maygc void macroexp0 (object form, object env)
{
if (consp(form)) { # only lists can be a macro-call
var object funname = Car(form); # function name
if (symbolp(funname)) {
var object fdef = sym_function(funname,TheSvector(env)->data[1]); # fetch function definition
if (fsubrp(fdef)) {
# fdef is a FSUBR, so the global function definition was valid.
# loop up, if the property list contains a macro definition:
var object expander = get(funname,S(macro)); # search for Property SYS::MACRO
if (boundp(expander)) {
# found. Expand with th Expander from the property list:
# execute (FUNCALL *MACROEXPAND-HOOK* expander form env) :
pushSTACK(expander); # expander as first argument
pushSTACK(form); # form as second Argument
pushSTACK(env); # environment as third argument
funcall(Symbol_value(S(macroexpand_hook)),3);
value2 = T; # expanded form as 1. value, t as 2. value
return;
}
} else {
# 4 possibilities:
# #UNBOUND/SUBR/Closure (global or lexical function def.)
# -> don't expand
# #<MACRO expander> (lexical macro definition)
# -> expand (call expander)
# #<FUNCTION-MACRO function expander> (lexical FunctionMacro-
# Definition) -> don't expand, because
# (MACRO-FUNCTION funname) => NIL
# Symbol (lexical function definition during SYS::%EXPAND)
# expand: (list* 'FUNCALL Symbol (cdr form))
if (macrop(fdef)) {
# #<MACRO expander> -> expand:
# execute (FUNCALL *MACROEXPAND-HOOK* expander form env) :
pushSTACK(TheMacro(fdef)->macro_expander); # Expander as first Argument
pushSTACK(form); # Form as second Argument
pushSTACK(env); # Environment as third Argument
funcall(Symbol_value(S(macroexpand_hook)),3);
value2 = T; # expanded Form as 1. value, T as 2. value
return;
} else if (symbolp(fdef)) {
# fdef a Symbol
# Must be expanded to (FUNCALL fdef ...) :
pushSTACK(Cdr(form)); # (cdr form)
pushSTACK(fdef); # Symbol
{
var object new_cons = allocate_cons();
Car(new_cons) = popSTACK(); Cdr(new_cons) = STACK_0;
STACK_0 = new_cons; # (cons Symbol (cdr form))
}
{
var object new_cons = allocate_cons();
Car(new_cons) = S(funcall); Cdr(new_cons) = popSTACK();
value1 = new_cons; # (cons 'FUNCALL (cons Symbol (cdr form)))
}
value2 = T; return; # expansion has taken place.
}
}
}
} else if (symbolp(form)) {
var object symbolmacro;
var object val = sym_value(form,TheSvector(env)->data[0],&symbolmacro);
if (!eq(symbolmacro,nullobj)) { # found Symbol-Macro?
# yes -> expand
value1 = TheSymbolmacro(symbolmacro)->symbolmacro_expansion; value2 = T;
return;
}
}
# else, don't expand:
value1 = form; value2 = NIL;
}
/* UP: Parse-Declarations-Docstring. Detaches those from a list of forms,
that have to be viewed as declarations resp. documentation string.
parse_dd(formlist)
> formlist: ( {decl|doc-string} . body )
< value1: body
< value2: List of decl-specs
< value3: Doc-String or NIL
< result: true if one (COMPILE)-declaration occurred, else false
can trigger GC */
global maygc bool parse_dd (object formlist)
{
pushSTACK(formlist); /* store formlist for error message */
pushSTACK(NIL); /* preliminary Doc-String */
pushSTACK(NIL); /* start of decl-spec-Liste */
/* stack layout: formlist, docstring, declspecs. */
var bool compile_decl = false; /* flag: (COMPILE)-declaration occurred */
var object body = formlist; /* rest of the form-list */
while (consp(body)) {
var object form = Car(body); /* next form */
var object body_rest = Cdr(body); /* shorten body */
if (stringp(form)) { /* found Doc-String? */
if (atomp(body_rest)) /* at the last position of the form list? */
goto fertig; /* yes -> last form can't be a Doc-String! */
if (!nullp(STACK_1)) { /* preceding Doc-String? */
/* yes -> more than one Doc-String is too much: */
pushSTACK(STACK_2); /* SOURCE-PROGRAM-ERROR slot DETAIL */
pushSTACK(STACK_0);
fehler(source_program_error,
GETTEXT("Too many documentation strings in ~S"));
}
STACK_1 = form; /* new Doc-String */
body = body_rest;
} else if (consp(form) && eq(Car(form),S(declare))) {/* (DECLARE ...) */
/* cons decl-specs one by one onto STACK_0: */
pushSTACK(body_rest); /* save body_rest */
pushSTACK(Cdr(form)); /* list of the new decl-specs */
while (mconsp(STACK_0)) {
var object declspec = Car(STACK_0); /* next decl-spec */
/* check for (COMPILE)
Test: (EQUAL d '(COMPILE)) =
(and (consp d) (eq (car d) 'COMPILE) (null (cdr d))) */
if (consp(declspec)
&& eq(Car(declspec),S(compile))
&& nullp(Cdr(declspec)))
compile_decl = true;
{ /* push this declaration onto STACK_(0+2) : */
pushSTACK(declspec);
var object new_cons = allocate_cons();
Car(new_cons) = popSTACK(); /* declspec */
Cdr(new_cons) = STACK_(0+2);
STACK_(0+2) = new_cons;
}
/* go to next decl-spec: */
STACK_0 = Cdr(STACK_0);
}
skipSTACK(1);
body = popSTACK(); /* body := old body_rest */
} else {
fertig: /* finished with loop over the form list */
break;
}
}
value1 = body;
value2 = nreverse(popSTACK()); /* decl-spec-Liste */
value3 = popSTACK(); /* Doc-String */
skipSTACK(1);
return compile_decl;
}
# UP: binds *EVALHOOK* and *APPLYHOOK* dynamically to the specified values.
# bindhooks(evalhook_value,applyhook_value);
# > evalhook_value: value for *EVALHOOK*
# > applyhook_value: value for *APPLYHOOK*
# changes STACK
global void bindhooks (object evalhook_value, object applyhook_value) {
# build frame:
{
var gcv_object_t* top_of_frame = STACK; # Pointer to Frame
pushSTACK(Symbol_value(S(evalhookstern))); # old value of *EVALHOOK*
pushSTACK(S(evalhookstern)); # *EVALHOOK*
pushSTACK(Symbol_value(S(applyhookstern))); # old value of *APPLYHOOK*
pushSTACK(S(applyhookstern)); # *APPLYHOOK*
finish_frame(DYNBIND);
}
# Frame got ready, now change the values of the variables:
Symbol_value(S(evalhookstern)) = evalhook_value; # (SETQ *EVALHOOK* evalhook_value)
Symbol_value(S(applyhookstern)) = applyhook_value; # (SETQ *APPLYHOOK* applyhook_value)
}
# UP: binds *EVALHOOK* and *APPLYHOOK* dynamically to NIL.
# bindhooks_NIL();
# changes STACK
#define bindhooks_NIL() bindhooks(NIL,NIL)
# UP: Determines the source-lambdabody of a lambda body.
# lambdabody_source(lambdabody)
# > lambdabody: Lambdabody (a Cons)
# < result: Source-Lambdabody (unbound if no source specified)
local object lambdabody_source (object lambdabody) {
var object body = Cdr(lambdabody);
# body = ((DECLARE (SOURCE ...) ...) ...) ?
if (consp(body)) {
var object form = Car(body); # first Form
# form = (DECLARE (SOURCE ...) ...) ?
if (consp(form) && eq(Car(form),S(declare))) {
var object declspecs = Cdr(form);
# declspecs = ((SOURCE ...) ...) ?
if (consp(declspecs)) {
var object declspec = Car(declspecs);
# declspec = (SOURCE ...) ?
if (consp(declspec) && eq(Car(declspec),S(source))) {
var object declspecr = Cdr(declspec);
if (consp(declspecr))
# found Source
return Car(declspecr);
}
}
}
}
return unbound;
}
/* UP: Inserts an implicit BLOCK in a lambda body.
add_implicit_block();
> STACK_1: function name
> STACK_0: lambda body
> value1: body
> value2: list of decl-specs
> value3: Doc-String or NIL
< STACK_0: new lambda body
can trigger GC */
local /*maygc*/ void add_implicit_block (void)
{
GCTRIGGER3(value1,value2,value3);
/* Replace lambdabody with
(cons (car lambdabody) ; lambda list
(multiple-value-bind (body-rest declarations docstring)
(sys::parse-body (cdr lambdabody) t) ; body
(append (if declarations (list (cons 'DECLARE declarations)))
(if docstring (list docstring))
(list (list* 'BLOCK (function-block-name name)
body-rest))))) */
var object new_body;
pushSTACK(value2); /* declarations */
pushSTACK(value3); /* docstring */
pushSTACK(funname_blockname(STACK_(1+2))); /* blockname */
pushSTACK(value1); /* body-rest */
{ /* stack layout: name, lambdabody, declarations, docstring,
blockname, body-rest. */
var object tmp = allocate_cons();
Cdr(tmp) = popSTACK(); Car(tmp) = STACK_0;
STACK_0 = tmp;
}
{
var object tmp = allocate_cons();
Car(tmp) = S(block); Cdr(tmp) = STACK_0;
STACK_0 = tmp;
}
{ /* stack layout: name, lambdabody, declarations, docstring, block-form. */
var object tmp = allocate_cons();
Car(tmp) = popSTACK();
new_body = tmp;
}
/* stack layout: name, lambdabody, declarations, docstring. */
if (nullp(STACK_0)) {
skipSTACK(1);
} else {
pushSTACK(new_body);
var object tmp = allocate_cons();
Cdr(tmp) = popSTACK(); Car(tmp) = popSTACK();
new_body = tmp;
}
/* stack layout: name, lambdabody, declarations. */
if (nullp(STACK_0)) {
STACK_0 = new_body;
} else {
pushSTACK(new_body);
{
var object tmp = allocate_cons();
Car(tmp) = S(declare); Cdr(tmp) = STACK_1;
STACK_1 = tmp;
}
{
var object tmp = allocate_cons();
Cdr(tmp) = popSTACK(); Car(tmp) = STACK_0;
STACK_0 = tmp;
}
}
{ /* stack layout: name, lambdabody, new-body. */
var object tmp = allocate_cons();
Cdr(tmp) = popSTACK(); Car(tmp) = Car(STACK_0);
STACK_0 = tmp;
}
}
LISPFUNNR(add_implicit_block,2)
{ /* (ADD-IMPLICIT-BLOCK name (lambda-list . lambda-body))
inserts an implicit BLOCK in the BODY */
parse_dd(Cdr(STACK_0)); /* just the lambda-body */
add_implicit_block();
VALUES1(STACK_0);
skipSTACK(2);
}
LISPFUNNR(function_block_name,1)
{ /* returns the name of the implicit block for a function-name */
var object funname =
check_funname(type_error,S(function_block_name),popSTACK());
VALUES1(funname_blockname(funname));
}
/* UP: Creates the corresponding Closure for a Lambdabody by decomposition
of the lambda list and poss. macro-expansion of all forms.
get_closure(lambdabody,name,blockp,env)
> lambdabody: (lambda-list {decl|doc} {form})
> name: Name, a Symbol or (SETF symbol)
> blockp: if an implicit BLOCK has to be inserted
> env: Pointer to the five distinct environments:
env->var_env = VENV, env->fun_env = FENV,
env->block_env = BENV, env->go_env = GENV,
env->decl_env = DENV.
< result: Closure
can trigger GC */
global maygc object get_closure (object lambdabody, object name, bool blockp,
gcv_environment_t* env)
{
/* Lambdabody must be a Cons: */
if (atomp(lambdabody)) {
pushSTACK(lambdabody); /* SOURCE-PROGRAM-ERROR slot DETAIL */
pushSTACK(name);
fehler(source_program_error,GETTEXT("~S: lambda-list for ~S is missing"));
}
{ /* and the CAR must be a List: */
var object lambdalist = Car(lambdabody);
if (!listp(lambdalist)) {
pushSTACK(lambdalist); /* SOURCE-PROGRAM-ERROR slot DETAIL */
pushSTACK(lambdalist); pushSTACK(name); pushSTACK(S(function));
fehler(source_program_error,
GETTEXT("~S: lambda-list for ~S should be a list, not ~S"));
}
}
pushSTACK(name);
pushSTACK(lambdabody);
/* stack layout: name, lambdabody.
decompose ({decl|doc} {form}) */
if (parse_dd(Cdr(lambdabody))) {
/* A (COMPILE)-Declaration occurred.
replace Lambdabody by its source (because some Macros
can be compiled more efficiently than their Macro-Expansion): */
{ var object source = lambdabody_source(STACK_0);
if (!boundp(source)) {
if (blockp)
add_implicit_block();
} else {
STACK_0 = source;
}
}
{ /* nest environments: */
var gcv_environment_t* stack_env = nest_env(env); /* push on STACK */
#if !defined(STACK_UP)
/* and transfer over here */
var object my_var_env = stack_env->var_env;
var object my_fun_env = stack_env->fun_env;
var object my_block_env = stack_env->block_env;
var object my_go_env = stack_env->go_env;
var object my_decl_env = stack_env->decl_env;
skipSTACK(5); /* and pop from STACK again */
pushSTACK(my_var_env);
pushSTACK(my_fun_env);
pushSTACK(my_block_env);
pushSTACK(my_go_env);
pushSTACK(my_decl_env);
#endif
/* stack layout: name, lambdabody, venv, fenv, benv, genv, denv. */
}
/* (SYS::COMPILE-LAMBDA name lambdabody venv fenv benv genv denv t) : */
pushSTACK(T); funcall(S(compile_lambda),8);
return value1; /* compiled Closure as value */
}
{ /* build Interpreted Closure: */
var object source = lambdabody_source(STACK_0);
if (!boundp(source)) { /* no source specified -> expand Lambdabody: */
if (blockp)
add_implicit_block();
/* call (SYS::%EXPAND-LAMBDABODY-MAIN lambdabody venv fenv) : */
pushSTACK(STACK_0); /* Lambdabody */
pushSTACK(nest_var(env->var_env)); /* nested Variable Environment */
pushSTACK(nest_fun(env->fun_env)); /* nested Function Environment */
funcall(S(expand_lambdabody_main),3);
lambdabody = value1; /* expanded Lambdabody */
} else { /* Source specified -> it replaces the old Lambdabody: */
lambdabody = STACK_0; /* Lambdabody */
STACK_0 = source; /* Source-Lambdabody */
}
}
/* Now STACK_0 is the Source-Lambdabody,
lambdabody is the Lambdabody to be used. */
pushSTACK(Car(lambdabody)); /* Lambdalist */
/* decompose ({decl|doc} {form}) : */
parse_dd(Cdr(lambdabody));
pushSTACK(value1); /* Body */
pushSTACK(value2); /* Declarations */
pushSTACK(value3); /* Doc-String or NIL */
var gcv_object_t* closure_; /* Pointer to the Closure in the STACK */
{ /* create Closure (filled with NIL): */
var object closure = allocate_closure(iclos_length,seclass_default<<4);
/* and fill partially: */
TheIclosure(closure)->clos_docstring = popSTACK(); /* Doc-String */
var object declarations = popSTACK(); /* Declarations */
TheIclosure(closure)->clos_body = popSTACK(); /* Body */
var object lambdalist = popSTACK(); /* Lambda-List */
TheIclosure(closure)->clos_form = popSTACK(); /* Source-Lambdabody */
TheIclosure(closure)->clos_name = STACK_0; /* Name */
/* and save: */
STACK_0 = closure;
/* stack layout: closure. */
closure_ = &STACK_0; /* Pointer to the Closure in the STACK */
if (!nullpSv(defun_accept_specialized_lambda_list)
&& functionp(Symbol_function(S(specialized_lambda_list_to_ordinary)))) {
/* convert lambda list to ordinary */
pushSTACK(declarations); /* save */
pushSTACK(lambdalist); pushSTACK(S(function));
funcall(S(specialized_lambda_list_to_ordinary),2);
lambdalist = value1; /* new ordinary lambda list */
declarations = popSTACK(); /* restore */
if (!nullp(value2)) /* merge in declarations */
declarations = nreconc(value2,declarations);
}
pushSTACK(lambdalist); pushSTACK(lambdalist); pushSTACK(lambdalist);
pushSTACK(declarations);
}
{ /* nest Environments and put them nested in the closure: */
var gcv_environment_t* stack_env = nest_env(env);
var object closure = *closure_;
TheIclosure(closure)->clos_var_env = stack_env->var_env ;
TheIclosure(closure)->clos_fun_env = stack_env->fun_env ;
TheIclosure(closure)->clos_block_env = stack_env->block_env;
TheIclosure(closure)->clos_go_env = stack_env->go_env ;
TheIclosure(closure)->clos_decl_env = stack_env->decl_env ;
skipSTACK(5);
/* keywords:=0, as long as &KEY is missing: */
TheIclosure(closure)->clos_keywords = Fixnum_0;
}
/* stack layout:
closure, lambdalist, lalist-save, lalist-rest, declarations */
var uintL spec_count = 0; /* number of dynamic references */
var uintL req_count = 0; /* number of required-parameters */
var uintL opt_count = 0; /* number of optional-parameters */
var uintL key_count = 0; /* number of keyword-parameters */
var uintL aux_count = 0; /* number of &AUX-variables */
var uintL var_count = 0; /* total number of the variables on the STACK */
{ /* process declarations:
read dynamically referenced variables from the decl-spec-list
declarations and push them on STACK. Other to be respected
declarations change the declarations-environment of the Closure. */
var object declarations = popSTACK();
while (consp(declarations)) { /* all decl-specs processed? */
var object declspec = Car(declarations);
/* declspec must be a List: */
if (atomp(declspec)) {
pushSTACK(declspec); /* SOURCE-PROGRAM-ERROR slot DETAIL */
pushSTACK(declspec); pushSTACK(S(function));
fehler(source_program_error,
GETTEXT("~S: illegal declaration ~S"));
}
/* process SPECIAL-declaration: */
if (eq(Car(declspec),S(special))) { /* SPECIAL-declaration ? */
var object declspecrest = Cdr(declspec);
while (consp(declspecrest)) {
var object sym = Car(declspecrest);
if (!symbolp(sym)) {
pushSTACK(declarations); pushSTACK(declspec); /* save */
pushSTACK(declspecrest);
sym = check_symbol_special(sym,S(function));
declspecrest = popSTACK(); Car(declspecrest) = sym;
declspec = popSTACK(); declarations = popSTACK(); /* restore */
}
/* push Symbol on STACK: */
check_STACK(); pushSTACK(sym); spec_count++; var_count++;
declspecrest = Cdr(declspecrest);
}
}
/* process other declaration: */
pushSTACK(Cdr(declarations)); /* shorten and save declarations */
{
var object denv = TheIclosure(*closure_)->clos_decl_env;
denv = augment_decl_env(declspec,denv);
TheIclosure(*closure_)->clos_decl_env = denv;
}
declarations = popSTACK();
}
}
/* stack layout:
closure, lambdalist, lalist-save, lalist-rest [special symbols]* */
var gcv_object_t *lalist_ = closure_ STACKop -2; /* remaining lambda list */
var gcv_object_t *lalist_save_ = closure_ STACKop -3; /* save fixed items */
var object item; /* element of the lambda list */
/* Macro:
NEXT_ITEM(&OPTIONAL_label,&REST_label,&KEY_label,
&ALLOW-OTHER-KEYS_label,&AUX_label,Ende_label)
shortens the rest of the lambda list, moves the next Element to "item"
and in case of one of the 6 specified lambda-list-markers, it jumps to
the respective locations. */
#define NEXT_ITEM(opt_label,rest_label,key_label,allow_label,aux_label,end_label) \
{ if (atomp(*lalist_)) goto end_label; /* Lambda-List finished? */ \
item = Car(*lalist_); *lalist_save_ = *lalist_; /* next element */ \
*lalist_ = Cdr(*lalist_); /* shorten List */ \
if (eq(item,S(LLoptional))) goto opt_label; /* &OPTIONAL ? */ \
if (eq(item,S(LLrest))) goto rest_label; /* &REST ? */ \
if (eq(item,S(LLkey))) goto key_label; /* &KEY ? */ \
if (eq(item,S(LLallow_other_keys))) goto allow_label; /* &ALLOW-OTHER-KEYS ? */ \
if (eq(item,S(LLaux))) goto aux_label; /* &AUX ? */ \
if (eq(item,S(LLbody))) goto badLLkey; /* &BODY ? */ \
}
req: /* process required-parameter push on STACK: */
while (1) {
NEXT_ITEM(opt,rest,key,badLLkey,aux,ende);
item = check_symbol_non_constant(item,S(function));
Car(*lalist_save_) = item;
/* push Variable on STACK: */
check_STACK();
pushSTACK(item); pushSTACK(Fixnum_0); req_count++; var_count++;
}
opt: /* process &OPTIONAL-parameter, push on STACK and
put Init-Forms into the Closure: */
while(1) {
NEXT_ITEM(badLLkey,rest,key,badLLkey,aux,ende);
var object init_form;
/* Parse variable spezification in item:
var or (var [init [svar]])
push var and poss. svar on STACK, set in var poss.
the svar_bit. Returns also init (or NIL) in init_form. */
check_STACK();
if (atomp(item)) {
item = check_symbol_non_constant(item,S(function));
Car(*lalist_save_) = item;
/* push variable on STACK: */
pushSTACK(item); pushSTACK(Fixnum_0); opt_count++; var_count++;
init_form = NIL; /* Default-Init */
} else {
var object item_rest = item;
/* first list-element: var */
pushSTACK(item_rest);
item = check_symbol_non_constant(Car(item),S(function));
item_rest = popSTACK(); Car(item_rest) = item;
item_rest = Cdr(item_rest);
/* push variable on STACK: */
pushSTACK(item); pushSTACK(Fixnum_0); opt_count++; var_count++;
if (consp(item_rest)) {
init_form = Car(item_rest); /* second list-element: init */
item_rest = Cdr(item_rest);
if (consp(item_rest)) {
if (mconsp(Cdr(item_rest))) { /* varspec is too lang */
pushSTACK(item_rest); /* SOURCE-PROGRAM-ERROR slot DETAIL */
pushSTACK(*(closure_ STACKop -1)); /* entire Lambda-List */
pushSTACK(S(LLoptional)); pushSTACK(S(function));
fehler(source_program_error,
GETTEXT("~S: variable specification after ~S too long: ~S"));
}
/* third list-element: svar */
pushSTACK(init_form); pushSTACK(item_rest);
item = check_symbol_non_constant(Car(item_rest),S(function));
item_rest = popSTACK(); Car(item_rest) = item;
init_form = popSTACK();
/* set svar-bit for var: */
STACK_0 = fixnum_inc(STACK_0,bit(svar_bit));
/* push variable on STACK: */
pushSTACK(item); pushSTACK(Fixnum_0); var_count++;
}
} else
init_form = NIL; /* Default-Init */
}
/* push init_form in front of (clos_opt_inits closure) : */
pushSTACK(init_form);
{
var object new_cons = allocate_cons();
Car(new_cons) = popSTACK();
var object closure = *closure_;
Cdr(new_cons) = TheIclosure(closure)->clos_opt_inits;
TheIclosure(closure)->clos_opt_inits = new_cons;
}
}
rest: /* process &REST-parameter and push on Stack: */
NEXT_ITEM(badrest,badrest,badrest,badrest,badrest,badrest);
item = check_symbol_non_constant(item,S(function));
Car(*lalist_save_) = item;
/* push variable on STACK: */
pushSTACK(item); pushSTACK(Fixnum_0); var_count++;
/* set Rest-Flag to T: */
TheIclosure(*closure_)->clos_rest_flag = T;
NEXT_ITEM(badLLkey,badLLkey,key,badLLkey,aux,ende);
pushSTACK(item); /* SOURCE-PROGRAM-ERROR slot DETAIL */
pushSTACK(*(closure_ STACKop -1)); /* entire Lambda-List */
pushSTACK(S(LLaux)); pushSTACK(S(LLkey));
pushSTACK(S(LLrest)); pushSTACK(S(function));
fehler(source_program_error,
GETTEXT("~S: ~S var must be followed by ~S or ~S or end of list: ~S"));
badrest:
pushSTACK(*(closure_ STACKop -1)); /* entire Lambda-List */
pushSTACK(STACK_0); /* SOURCE-PROGRAM-ERROR slot DETAIL */
pushSTACK(S(LLrest)); pushSTACK(S(function));
fehler(source_program_error,
GETTEXT("~S: ~S must be followed by a variable: ~S"));
key: /* process &KEY-Parameter, push on STACK
and put Init-Forms in the Closure: */
TheIclosure(*closure_)->clos_keywords = NIL; /* keywords:=NIL */
while(1) {
NEXT_ITEM(badLLkey,badLLkey,badLLkey,allow,aux,ende);
var object keyword;
var object init_form;
/* Parse variable-spezification in item:
var or (var [init [svar]]) or ((key var) [init [svar]])
push var and poss. svar on STACK, set in var poss.
the svar_bit. Returns also the Keyword in keyword and
init (or NIL) in init_form. */
check_STACK();
if (atomp(item)) {
item = check_symbol_non_constant(item,S(function));
Car(*lalist_save_) = item;
/* push variable on STACK: */
pushSTACK(item); pushSTACK(Fixnum_0); key_count++; var_count++;
/* fetch Keyword: */
keyword = intern_keyword(Symbol_name(item));
/* Default-Init: */
init_form = NIL;
} else {
var object item_rest = item; /* (item [init [svar]]) */
item = Car(item); /* first list-element: var or (key var) */
pushSTACK(item_rest); /* save */
if (atomp(item)) {
item = check_symbol_non_constant(item,S(function)); /* item = var */
/* push variable on STACK: */
item_rest = popSTACK(); /* restore */
Car(item_rest) = item; item_rest = Cdr(item_rest); /*([init [svar]])*/
pushSTACK(item); pushSTACK(Fixnum_0); key_count++; var_count++;
/* fetch Keyword: */
pushSTACK(item_rest); /* save */
keyword = intern_keyword(Symbol_name(item));
item_rest = popSTACK(); /* restore */
} else {
pushSTACK(item);
/* item = (key var) */
keyword = check_symbol(Car(item)); /* key */
item = popSTACK(); Car(item) = keyword;
item = Cdr(item); /* (var) */
if (!(consp(item) && matomp(Cdr(item))))
goto fehler_keyspec;
pushSTACK(keyword); pushSTACK(item); /* save */
item = check_symbol_non_constant(Car(item),S(function)); /* var */
Car(popSTACK()) = item; keyword = popSTACK(); /* restore */
item_rest = popSTACK(); item_rest = Cdr(item_rest); /*([init [svar]])*/
/* push variable on STACK: */
pushSTACK(item); pushSTACK(Fixnum_0); key_count++; var_count++;
}
if (consp(item_rest)) {
init_form = Car(item_rest); /* second list-element: init */
item_rest = Cdr(item_rest); /* ([svar]) */
if (consp(item_rest)) {
if (mconsp(Cdr(item_rest)))
goto fehler_keyspec;
/* third list-element: svar */
pushSTACK(init_form); pushSTACK(keyword); pushSTACK(item_rest);
item = check_symbol_non_constant(Car(item_rest),S(function));
item_rest = popSTACK(); Car(item_rest) = item;
keyword = popSTACK(); init_form = popSTACK(); /* restore */
/* set svar-Bit in var: */
STACK_0 = fixnum_inc(STACK_0,bit(svar_bit));
/* push variable on STACK: */
pushSTACK(item); pushSTACK(Fixnum_0); var_count++;
}
} else
init_form = NIL; /* Default-Init */
}
/* push keyword in front of (clos_keywords closure) and
push init_form in front of (clos_key_inits closure) : */
pushSTACK(init_form); pushSTACK(keyword);
{
var object new_cons = allocate_cons();
Car(new_cons) = popSTACK();
var object closure = *closure_;
Cdr(new_cons) = TheIclosure(closure)->clos_keywords;
TheIclosure(closure)->clos_keywords = new_cons;
}
{
var object new_cons = allocate_cons();
Car(new_cons) = popSTACK();
var object closure = *closure_;
Cdr(new_cons) = TheIclosure(closure)->clos_key_inits;
TheIclosure(closure)->clos_key_inits = new_cons;
}
}
fehler_keyspec:
pushSTACK(*(closure_ STACKop -1)); /* entire Lambda-List */
pushSTACK(STACK_0); /* SOURCE-PROGRAM-ERROR slot DETAIL */
pushSTACK(S(LLkey)); pushSTACK(S(function));
fehler(source_program_error,
GETTEXT("~S: incorrect variable specification after ~S: ~S"));
allow: /* process &ALLOW-OTHER-KEYS: */
TheIclosure(*closure_)->clos_allow_flag = T; /* set Flag to T */
NEXT_ITEM(badLLkey,badLLkey,badLLkey,badLLkey,aux,ende);
pushSTACK(*(closure_ STACKop -1)); /* entire Lambda-List */
pushSTACK(STACK_0); /* SOURCE-PROGRAM-ERROR slot DETAIL */
pushSTACK(S(LLaux)); pushSTACK(S(LLallow_other_keys));
pushSTACK(S(function));
fehler(source_program_error,
GETTEXT("~S: ~S must be followed by ~S or end of list: ~S"));
aux: /* process &AUX-Parameter, push on STACK and
put Init-Forms in the Closure: */
while(1) {
NEXT_ITEM(badLLkey,badLLkey,badLLkey,badLLkey,badLLkey,ende);
var object init_form;
/* Parse variable-spezification in item:
var or (var [init])
push var on STACK.
Returns also init (or NIL) in init_form. */
check_STACK();
if (atomp(item)) {
item = check_symbol_non_constant(item,S(function));
Car(*lalist_save_) = item;
/* push variable on STACK: */
pushSTACK(item); pushSTACK(Fixnum_0); aux_count++; var_count++;
init_form = NIL; /* Default-Init */
} else {
var object item_rest = item; pushSTACK(item_rest);
/* first list-element: var */
item = check_symbol_non_constant(Car(item),S(function));
item_rest = popSTACK(); Car(item_rest) = item; item_rest = Cdr(item_rest);
/* push variable on STACK: */
pushSTACK(item); pushSTACK(Fixnum_0); aux_count++; var_count++;
if (consp(item_rest)) {
init_form = Car(item_rest); /* second list-element: init */
if (mconsp(Cdr(item_rest))) { /* varspec too long */
pushSTACK(item_rest); /* SOURCE-PROGRAM-ERROR slot DETAIL */
pushSTACK(*(closure_ STACKop -1)); /* entire Lambda-List */
pushSTACK(S(LLaux)); pushSTACK(S(function));
fehler(source_program_error,
GETTEXT("~S: variable specification after ~S too long : ~S"));
}
} else
init_form = NIL; /* Default-Init */
}
/* push init_form in front of (clos_aux_inits closure) : */
pushSTACK(init_form);
{
var object new_cons = allocate_cons();
Car(new_cons) = popSTACK();
var object closure = *closure_;
Cdr(new_cons) = TheIclosure(closure)->clos_aux_inits;
TheIclosure(closure)->clos_aux_inits = new_cons;
}
}
/* Collected error messages: */
badLLkey:
pushSTACK(item); /* SOURCE-PROGRAM-ERROR slot DETAIL */
pushSTACK(*(closure_ STACKop -1)); /* entire Lambda-List */
pushSTACK(item); pushSTACK(S(function));
fehler(source_program_error,
GETTEXT("~S: badly placed lambda-list keyword ~S: ~S"));
ende: /* reached list-end */
#undef NEXT_ITEM
if (((uintL)~(uintL)0 > lp_limit_1) && (var_count > lp_limit_1)) {
/* too many parameters? */
pushSTACK(*(closure_ STACKop -1)); /* entire Lambda-List */
pushSTACK(STACK_0); /* SOURCE-PROGRAM-ERROR slot DETAIL */
pushSTACK(S(function));
fehler(source_program_error,
GETTEXT("~S: too many parameters in the lambda-list ~S"));
}
/* var_count <= lp_limit_1, therefore all counts fit in an uintC. */
if (!nullp(*lalist_)) { /* is Lambda-List a Dotted List? */
pushSTACK(*lalist_); /* SOURCE-PROGRAM-ERROR slot DETAIL */
pushSTACK(*(closure_ STACKop -1)); /* entire Lambda-List */
pushSTACK(S(function));
fehler(source_program_error,
GETTEXT("~S: a dot in a lambda-list is allowed only for macros, not here: ~S"));
}
/* Collect variables into a vector and put it into the Closure,
Collect variable-flags into a Byte-Vector and put it into the Closure: */
pushSTACK(allocate_bit_vector(Atype_8Bit,var_count-spec_count)); /* create Byte-Vector */
var object vars = allocate_vector(var_count); /* create Vector */
var object varflags = popSTACK();
{ /* write variables in the Vector (last one to the back,
leading ones in front): */
var gcv_object_t* ptr = &TheSvector(vars)->data[var_count];
var uintB* ptrflags = &TheSbvector(varflags)->data[var_count-spec_count];
var uintC count = var_count-spec_count;
while (count--) {
*--ptrflags = (uintB)posfixnum_to_V(popSTACK());
*--ptr = popSTACK();
}
for (count = spec_count; count--;)
*--ptr = popSTACK();
}
var object closure = *closure_;
TheIclosure(closure)->clos_vars = vars;
TheIclosure(closure)->clos_varflags = varflags;
/* write counts in the Closure: */
TheIclosure(closure)->clos_spec_anz = fixnum(spec_count);
TheIclosure(closure)->clos_req_anz = fixnum(req_count);
TheIclosure(closure)->clos_opt_anz = fixnum(opt_count);
TheIclosure(closure)->clos_key_anz = fixnum(key_count);
TheIclosure(closure)->clos_aux_anz = fixnum(aux_count);
/* In the Variable-Vector the first spec_count variables are the
SPECIAL-declared ones. In each remaining variable the DYNAM_BIT is
set, if it occurs among the SPECIAL-declared one. */
if (spec_count) { /* loop over the remaining variables: */
if (var_count-spec_count > 0) {
var gcv_object_t* othervarptr = &TheSvector(vars)->data[spec_count];
var uintB* othervarflagsptr = &TheSbvector(varflags)->data[0];
var uintC count1 = var_count-spec_count;
do {
var object othervar = *othervarptr++; /* next variable */
{ /* Search for it among the SPECIAL-declared variables: */
var gcv_object_t* specvarptr = &TheSvector(vars)->data[0];
var uintC count2 = spec_count;
do {
if (eq(*specvarptr++,othervar)) { /* found? */
/* yes -> so the variable othervar is to be bound dynamically. */
*othervarflagsptr |= bit(dynam_bit); break;
}
} while (--count2);
}
othervarflagsptr++;
} while (--count1);
}
}
/* Finally reverse the accumulated lists in the Closure: */
nreverse(TheIclosure(closure)->clos_opt_inits);
nreverse(TheIclosure(closure)->clos_keywords);
nreverse(TheIclosure(closure)->clos_key_inits);
nreverse(TheIclosure(closure)->clos_aux_inits);
/* stack layout: closure, lambdalist, lalist-save, lalist-rest */
skipSTACK(4);
return closure;
}
# error, if symbol to be called is a special form.
# fehler_specialform(caller,funname); (transl.: error_specialfor(...);)
# > caller: caller (a symbol)
# > funname: a symbol
nonreturning_function(local, fehler_specialform, (object caller, object funname)) {
pushSTACK(funname); # CELL-ERROR slot NAME
pushSTACK(funname);
pushSTACK(caller);
fehler(undefined_function,
GETTEXT("~S: ~S is a special operator, not a function"));
}
# error, if symbol to be called is a macro.
# fehler_macro(caller,funname);
# > caller: caller (a symbol)
# > funname: a symbol
nonreturning_function(local, fehler_macro, (object caller, object funname)) {
pushSTACK(funname); # CELL-ERROR slot NAME
pushSTACK(funname);
pushSTACK(caller);
fehler(undefined_function,GETTEXT("~S: ~S is a macro, not a function"));
}
/* UP: Alters argument to a function.
coerce_function(obj)
> obj: object
< result: object as function (SUBR or Closure)
can trigger GC */
global maygc object coerce_function (object obj)
{
/* obj should be a symbol, a SUBR or a Closure. */
if (functionp(obj)) {
return obj; /* function is OK */
} else if (symbolp(obj)) {
var object fdef = Symbol_function(obj);
if (functionp(fdef))
return fdef;
else if (orecordp(fdef)) {
switch (Record_type(fdef)) {
case Rectype_Fsubr:
fehler_specialform(TheSubr(subr_self)->name,obj);
case Rectype_Macro:
fehler_macro(TheSubr(subr_self)->name,obj);
default: NOTREACHED;
}
} else
return check_fdefinition(obj,TheSubr(subr_self)->name);
} else if (funnamep(obj)) {
/* this could have be done easier but we inline the checks -
symbolp and functionp for performance reasons */
var object symbol = get(Car(Cdr(obj)),S(setf_function)); /* (get ... 'SYS::SETF-FUNCTION) */
if (!symbolp(symbol)) { /* should be symbol */
pushSTACK(obj); symbol = check_symbol(symbol); obj = popSTACK();
}
var object fdef = Symbol_function(symbol);
if (functionp(fdef))
return fdef;
else
return check_fdefinition(obj,TheSubr(subr_self)->name);
} else if (consp(obj) && eq(Car(obj),S(lambda))) { /* (LAMBDA . ...) ? */
fehler_lambda_expression(TheSubr(subr_self)->name,obj);
} else
return check_function(obj);
}
#ifdef DEBUG_EVAL
/* Emit some trace output for a function call, to *funcall-trace-output*.
trace_call(fun,type_of_call,caller_type);
> object fun: function being called, a SUBR/FSUBR/Closure
> uintB type_of_call: 'A' for apply, 'F' for funcall, 'B' for bytecode
> uintB caller_type: 'F' for fsubr, 'S' for subr,
'C' for cclosure, 'I' for iclosure
can trigger GC */
local maygc void trace_call (object fun, uintB type_of_call, uintB caller_type)
{
var object stream = Symbol_value(S(funcall_trace_output)); /* SYS::*FUNCALL-TRACE-OUTPUT* */
/* No output until *funcall-trace-output* has been initialized: */
if (!streamp(stream))
return;
pushSTACK(stream);
if (cclosurep(fun)) {
pushSTACK(Closure_name(fun));
write_ascii_char(&STACK_1,'c');
} else if (closurep(fun)) {
pushSTACK(TheIclosure(fun)->clos_name);
write_ascii_char(&STACK_1,'C');
} else if (subrp(fun)) {
pushSTACK(TheSubr(fun)->name);
write_ascii_char(&STACK_1,'S');
} else if (fsubrp(fun)) {
pushSTACK(TheFsubr(fun)->name);
write_ascii_char(&STACK_1,'F');
} else {
pushSTACK(NIL);
write_ascii_char(&STACK_1,'?');
}
write_ascii_char(&STACK_1,type_of_call); /* output type of call */
write_ascii_char(&STACK_1,caller_type); /* output caller */
write_ascii_char(&STACK_1,'[');
prin1(&STACK_1,STACK_0); /* output function name */
write_ascii_char(&STACK_1,']');
terpri(&STACK_1);
skipSTACK(2);
}
#define TRACE_CALL(fu,tc,ct) \
if (streamp(Symbol_value(S(funcall_trace_output)))) { \
pushSTACK(fu); trace_call(fu,tc,ct); fu = popSTACK(); \
}
#else
#define TRACE_CALL(fu,tc,ct)
#endif
# Test for illegal keywords
# check_for_illegal_keywords(allow_flag,fehler_statement);
# > uintC argcount: Number of Keyword/Value-pairs
# > gcv_object_t* rest_args_pointer: Pointer to the 2*argcount remaining arguments
# > bool allow_flag: Flag, if &ALLOW-OTHER-KEYS was specified
# > for_every_keyword: Macro, which loops over all Keywords and assigns
# them to 'keyword'.
# > fehler_statement: Statement, that reports, that bad_keyword is illegal.
#define check_for_illegal_keywords(allow_flag_expr,caller,fehler_statement) \
{ var gcv_object_t* argptr = rest_args_pointer; # Pointer to the arguments \
var object bad_keyword = nullobj; # first illegal keyword or nullobj \
var object bad_value = nullobj; /* its value */ \
var bool allow_flag = # Flag for allow-other-keys (if \
# &ALLOW-OTHER-KEYS was specified or ':ALLOW-OTHER-KEY T' occurred) \
(allow_flag_expr); \
# But ':ALLOW-OTHER-KEYS NIL' hides a subsequent ':ALLOW-OTHER-KEYS T' \
# (see CLHS 3.4.1.4.1.1). \
var bool allow_hidden = false; # true if seen ':ALLOW-OTHER-KEYS NIL' \
var uintC check_count=argcount; \
while (check_count--) { \
var object kw = NEXT(argptr); # next Argument \
var object val = NEXT(argptr); # and value for it \
# must be a symbol, should be a keyword: \
if (!symbolp(kw)) fehler_key_notkw(kw,caller); \
if (!allow_flag) { # other keywords allowed? yes -> ok \
if (eq(kw,S(Kallow_other_keys))) { \
if (!allow_hidden) { \
if (!nullp(val)) \
allow_flag = true; \
else \
allow_hidden = true; \
} \
} else { \
# up to now :ALLOW-OTHER-KEYS was not there, and NOALLOW \
if (eq(bad_keyword,nullobj)) { # all Keywords ok so far? \
# must test, if the keyword kw is allowed. \
for_every_keyword({ if (eq(keyword,kw)) goto kw_ok; }); \
# keyword kw was not allowed. \
bad_keyword = kw; \
bad_value = val; \
kw_ok: ; \
} \
} \
} \
}; \
if (!allow_flag) \
if (!eq(bad_keyword,nullobj)) { \
# wrong keyword occurred \
fehler_statement \
} \
}
# For a Keyword 'keyword' search the pair Key.Value:
# find_keyword_value( notfound_statement, found_statement );
# > keyword: Keyword
# > uintC argcount: Number of Keyword/Value-Pairs
# > gcv_object_t* rest_args_pointer: Pointer to the 2*argcount remaining Arguments
# > notfound_statement: what is to be done, if not found
# > found_statement: what is to be done, if value found
#define find_keyword_value(notfound_statement,found_statement) \
{ var gcv_object_t* argptr = rest_args_pointer; \
var uintC find_count; \
dotimesC(find_count,argcount, { \
if (eq(NEXT(argptr),keyword)) goto kw_found; # right keyword? \
NEXT(argptr); \
}); \
if (true) { \
# not found \
notfound_statement \
} else { \
kw_found: # found \
{var object value = NEXT(argptr); \
found_statement \
}} \
}
/* UP: Applies an interpreted closure to arguments.
funcall_iclosure(closure,args_pointer,argcount);
> closure: Closure
> args_pointer: Pointer to the arguments (in Stack)
> argcount: Number of Arguments
< mv_count/mv_space: values
< STACK: cleaned up, = args_pointer
can trigger GC */
local maygc Values funcall_iclosure (object closure, gcv_object_t* args_pointer,
uintC argcount)
{
/* 1st step: finish building of APPLY-frame: */
var sp_jmp_buf my_jmp_buf;
TRACE_CALL(closure,'F','I');
{
var gcv_object_t* top_of_frame = args_pointer; /* Pointer to frame */
pushSTACK(closure);
finish_entry_frame(APPLY,my_jmp_buf,,{
if (mv_count==0) { /* after reentry: pass form? */
closure = STACK_(frame_closure); /* try the same APPLY again */
args_pointer = topofframe(STACK_0);
argcount = STACK_item_count(STACK STACKop frame_args,args_pointer);
} else {
setSTACK(STACK = topofframe(STACK_0)); /* clean STACK ?or unwind()?*/
eval_noenv(value1); return; /* evaluate passed form */
}
});
}
var gcv_object_t* closure_ = &STACK_(frame_closure); /* &closure */
var gcv_object_t* frame_pointer; /* pointer to the frame */
var uintC spec_count = posfixnum_to_V(TheIclosure(closure)->clos_spec_anz);
var gcv_object_t *spec_ptr;
{ /* 2nd step: build variable-binding-frame: */
var gcv_object_t* top_of_frame = STACK; /* Pointer to Frame */
var object vars = TheIclosure(closure)->clos_vars; /* Vector of variable-names */
var uintL var_count = Svector_length(vars); /* number of variables */
get_space_on_STACK(var_count*varframe_binding_size*sizeof(gcv_object_t));
{
var gcv_object_t* varptr = &TheSvector(vars)->data[0]; /* Pointer to variables in vector */
var uintC count;
/* the special-references first: */
spec_ptr = args_end_pointer;
dotimesC(count,spec_count, {
pushSTACK(specdecl); /* SPECDECL as "value" */
pushSTACK_symbolwithflags(*varptr++,0); /* INactive */
});
frame_pointer = args_end_pointer;
if (var_count-spec_count > 0) {
var uintB* varflagsptr = &TheSbvector(TheIclosure(closure)->clos_varflags)->data[0];
dotimespC(count,var_count-spec_count, {
pushSTACK(NIL); /* NIL as preliminary value */
var object next_var = *varptr++; /* next variable */
var oint next_varflags = (oint)(*varflagsptr++)<<oint_symbolflags_shift; /* with poss. dynam_bit, svar_bit */
if (special_var_p(TheSymbol(next_var))) /* proclaimed SPECIAL? */
next_varflags |= wbit(dynam_bit_o); /* -> bind dynamically */
pushSTACK_symbolwithflags(next_var,next_varflags);
});
}
}
/* VAR_ENV of closure becomes NEXT_ENV in frame: */
pushSTACK(TheIclosure(closure)->clos_var_env);
pushSTACK(fake_gcv_object(var_count)); /* var_count bindungs, all still un-nested */
finish_frame(VAR);
}
/* STACK now points below the variable-binding-frame.
frame_pointer = Pointer in the variable-binding-frame, above the first
still inactive binding, below the already active SPECIAL-references. */
{ /* 3rd step: bind current environments: */
var object new_var_env = make_framepointer(STACK);
/* this frame will become the new VAR_ENV later. */
make_ENV5_frame();
/* activate the closure-environment: */
aktenv.var_env = new_var_env; /* variable-binding-frame */
aktenv.fun_env = TheIclosure(closure)->clos_fun_env;
aktenv.block_env = TheIclosure(closure)->clos_block_env;
aktenv.go_env = TheIclosure(closure)->clos_go_env;
aktenv.decl_env = TheIclosure(closure)->clos_decl_env;
}
/* stack layout: APPLY-frame, variable-binding-frame, ENV-frame */
{ /* 4th step: process parameters: */
check_SP();
/* Macro for binding of variables in variable-frame:
binds the next variable to value, decreases frame_pointer by 2 resp. 3.
(takes advantage of varframe_binding_mark = 0 !) */
#define bind_next_var(value,markptr_zuweisung) \
{ frame_pointer skipSTACKop -varframe_binding_size; \
{var gcv_object_t* markptr = markptr_zuweisung &Before(frame_pointer); \
if (as_oint(*markptr) & wbit(dynam_bit_o)) { \
/* activate dynamic Binding: */ \
var object sym = *(markptr STACKop varframe_binding_sym); /* var */ \
*(markptr STACKop varframe_binding_value) = /* old value in frame */ \
TheSymbolflagged(sym)->symvalue; \
/* new value in value-cell: */ \
TheSymbolflagged(sym)->symvalue = (value); \
activate_specdecl(sym,spec_ptr,spec_count); \
} else { /* activate static binding: */ \
/* new value in frame: */ \
*(markptr STACKop varframe_binding_value) = (value); \
} \
*markptr = SET_BIT(*markptr,active_bit_o);/* activate binding */ \
}}
{ /* process required parameters: fetch next argument and bind in stack */
var uintC count = posfixnum_to_V(TheIclosure(closure)->clos_req_anz);
if (count>0) {
if (argcount < count) {
pushSTACK(TheIclosure(closure)->clos_name);
/* ANSI CL 3.5.1.2. wants a PROGRAM-ERROR here. */
fehler(program_error,
GETTEXT("EVAL/APPLY: too few arguments given to ~S"));
}
argcount -= count;
dotimespC(count,count, {
var object next_arg = NEXT(args_pointer); /* next argument */
bind_next_var(next_arg,); /* bind next variable */
});
}
}
{ /* process optional parameters:
fetch next argument; if there is none,
execute an Init-form; then bind in stack. */
var uintC count = posfixnum_to_V(TheIclosure(closure)->clos_opt_anz);
if (count==0)
goto optional_ende;
{
var object inits = TheIclosure(closure)->clos_opt_inits; /*init forms*/
do {
if (argcount==0)
goto optional_aus;
argcount--;
var object next_arg = NEXT(args_pointer); /* next argument */
var gcv_object_t* optmarkptr;
bind_next_var(next_arg,optmarkptr=); /* bind next variable */
if (as_oint(*optmarkptr) & wbit(svar_bit_o)) {
/* supplied-p-Parameter follows? */
*optmarkptr = CLR_BIT(*optmarkptr,svar_bit_o);
bind_next_var(T,); /* yes -> bind to T */
}
inits = Cdr(inits); /* shorten Init-Forms-List */
count--;
} while (count);
goto optional_ende;
optional_aus: /* no more optional arguments here. */
pushSTACK(inits);
}
/* execute all Init-forms of the optional parameters here: */
dotimespC(count,count, {
var object inits = STACK_0; /* remaining Initforms */
STACK_0 = Cdr(inits);
inits = (eval(Car(inits)),value1); /* next Initform, evaluated */
var gcv_object_t* optmarkptr;
bind_next_var(inits,optmarkptr=); /* bind next variable */
if (as_oint(*optmarkptr) & wbit(svar_bit_o)) {
/* supplied-p-Parameter follows? */
*optmarkptr = CLR_BIT(*optmarkptr,svar_bit_o);
bind_next_var(NIL,); /* yes -> bind to NIL */
}
});
closure = *closure_;
/* initialize &REST-parameters without arguments: */
if (!nullp(TheIclosure(closure)->clos_rest_flag)) /* Rest-Flag? */
bind_next_var(NIL,); /* yes -> bind to NIL */
/* initialize &KEY-parameters without arguments : */
count = posfixnum_to_V(TheIclosure(closure)->clos_key_anz); /* number of Keyword-parameters */
if (count>0) {
STACK_0 = TheIclosure(closure)->clos_key_inits; /* their Init-forms */
dotimespC(count,count, {
var object inits = STACK_0; /* remaining Initforms */
STACK_0 = Cdr(inits);
inits = (eval(Car(inits)),value1); /* next Initform, evaluated */
var gcv_object_t* keymarkptr;
bind_next_var(inits,keymarkptr=); /* bind next Variable */
if (as_oint(*keymarkptr) & wbit(svar_bit_o)) {
/* supplied-p-Parameter follows? */
*keymarkptr = CLR_BIT(*keymarkptr,svar_bit_o);
bind_next_var(NIL,); /* yes -> bind to NIL */
}
});
closure = *closure_;
}
skipSTACK(1); /* remaining Init-forms forgotten */
goto aux; /* go to the AUX-variables */
}
optional_ende:
/* prepare &KEY-parameters and &REST-parameters: */
if (numberp(TheIclosure(closure)->clos_keywords) /* is keyword a number? */
&& nullp(TheIclosure(closure)->clos_rest_flag)) { /* and no Rest-parameter? */
/* yes -> neither &KEY nor &REST specified */
if (argcount>0) { /* still arguments there? -> Error */
pushSTACK(TheIclosure(closure)->clos_name);
/* ANSI CL 3.5.1.3. wants a PROGRAM-ERROR here. */
fehler(program_error,
GETTEXT("EVAL/APPLY: too many arguments given to ~S"));
}
} else { /* &KEY or &REST present. */
/* process &REST-parameters: */
if (!nullp(TheIclosure(closure)->clos_rest_flag)) { /* &rest? */
/* yes -> collect residual arguments in a list: */
pushSTACK(NIL); /* start of list */
if (argcount>0) {
var gcv_object_t* ptr = args_pointer STACKop -(uintP)argcount;
var uintC count;
dotimespC(count,argcount, {
var object new_cons = allocate_cons();
Car(new_cons) = BEFORE(ptr);
Cdr(new_cons) = STACK_0;
STACK_0 = new_cons;
});
closure = *closure_;
}
var object list = popSTACK(); /* entire list */
bind_next_var(list,); /* bind &REST-parameter to this list */
}
/* process &KEY-parameters: */
if (!numberp(TheIclosure(closure)->clos_keywords)) {
/* Keyword-parameters present */
var gcv_object_t* rest_args_pointer = args_pointer;
/* argcount = number of remaining arguments */
/* halve argcount --> number of pairs Key.Value: */
if (argcount%2) { /* number was odd -> not paired: */
var uintC count = 0;
while (count<argcount) pushSTACK(rest_args_pointer[count++]);
fehler_key_odd(argcount,TheIclosure(closure)->clos_name);
}
argcount = argcount/2;
{ /* test for illegal keywords: */
var object keywords = TheIclosure(closure)->clos_keywords;
#define for_every_keyword(statement) \
{ var object keywordsr = keywords; \
while (consp(keywordsr)) { \
var object keyword = Car(keywordsr); \
statement; \
keywordsr = Cdr(keywordsr); \
}}
check_for_illegal_keywords
(!nullp(TheIclosure(closure)->clos_allow_flag),
TheIclosure(closure)->clos_name,
{ fehler_key_badkw(TheIclosure(closure)->clos_name,
bad_keyword,bad_value,
TheIclosure(closure)->clos_keywords);});
#undef for_every_keyword
/* Now assign the Key-values and evaluate the Key-Inits: */
var uintC count = posfixnum_to_V(TheIclosure(closure)->clos_key_anz);
if (count > 0) {
var object key_inits = TheIclosure(closure)->clos_key_inits;
dotimespC(count,count, {
var object keyword = Car(keywords); /* Keyword */
var object var_value;
var object svar_value;
/* Find the pair Key.Value for Keyword: */
find_keyword_value({ /* not found, must evaluate the Init: */
pushSTACK(keywords); pushSTACK(key_inits);
var_value = (eval(Car(key_inits)),value1);
key_inits = popSTACK(); keywords = popSTACK();
svar_value = NIL; /* NIL for poss. supplied-p-Parameter */
},{ /* found -> take value: */
var_value = value;
svar_value = T; /* T for poss. supplied-p-Parameter */
});
{
var gcv_object_t* keymarkptr;
bind_next_var(var_value,keymarkptr=); /* bind keyword-var */
if (as_oint(*keymarkptr) & wbit(svar_bit_o)) { /* supplied-p-Parameter follows? */
*keymarkptr = CLR_BIT(*keymarkptr,svar_bit_o);
bind_next_var(svar_value,); /* yes -> bind to NIL resp. T */
}
}
keywords = Cdr(keywords);
key_inits = Cdr(key_inits);
});
}
}
closure = *closure_;
}
}
aux: { /* process &AUX-parameter: */
var uintC count = posfixnum_to_V(TheIclosure(closure)->clos_aux_anz);
if (count>0) {
pushSTACK(TheIclosure(closure)->clos_aux_inits); /* Init-forms for &AUX-variables */
dotimespC(count,count, {
var object inits = STACK_0;
STACK_0 = Cdr(inits);
inits = (eval(Car(inits)),value1); /* evaluate nnext Init */
bind_next_var(inits,); /* and bind next variable to it */
});
skipSTACK(1); /* forget remaining Init-forms */
closure = *closure_;
}
}
#undef bind_next_var
}
if (spec_count > 0) activate_specdecls(spec_ptr,spec_count);
/* 5th step: evaluate Body: */
implicit_progn(TheIclosure(closure)->clos_body,NIL);
unwind(); /* unwind ENV-frame */
unwind(); /* unwind variable-binding-frame */
unwind(); /* unwind APPLY-frame */
}
# UP: provides the assignment of the Key-arguments for SUBRs.
# call only, if key_flag /= subr_nokey.
# > fun: function, a SUBR
# > argcount: number of arguments after optional ones
# > STACK_(argcount-1),...,STACK_0: the argcount arguments after the optional ones
# > key_args_pointer: Pointer to the Key-parameters in the STACK
# > rest_args_pointer: Pointer to the remaining arguments in the STACK
# < STACK: set correctly
# changes STACK
local void match_subr_key (object fun, uintL argcount, gcv_object_t* key_args_pointer, gcv_object_t* rest_args_pointer)
{
/* halve argcount --> the number of pairs Key.Value: */
if (argcount%2) /* number was odd -> not paired: */
fehler_key_odd(argcount,TheSubr(fun)->name);
if (((uintL)~(uintL)0 > ca_limit_1) && (argcount > ca_limit_1))
fehler_too_many_args(unbound,fun,argcount,ca_limit_1);
# Due to argcount <= ca_limit_1, all count's fit in a uintC.
argcount = argcount/2;
# test for illegal Keywords:
{
var gcv_object_t* keywords_pointer = &TheSvector(TheSubr(fun)->keywords)->data[0];
var uintC key_anz = TheSubr(fun)->key_anz;
#define for_every_keyword(statement) \
if (key_anz > 0) { \
var gcv_object_t* keywordptr = keywords_pointer; \
var uintC count = key_anz; \
do { \
var object keyword = *keywordptr++; \
statement; \
} while (--count); \
}
check_for_illegal_keywords
(TheSubr(fun)->key_flag == subr_key_allow,TheSubr(fun)->name,
{ pushSTACK(bad_keyword); /* save bad keyword */
pushSTACK(bad_value); /* save bad value */
pushSTACK(fun); /* save the function */
# convert Keyword-Vector to a List:
# (SYS::COERCE-SEQUENCE kwvec 'LIST)
coerce_sequence(TheSubr(fun)->keywords,S(list),true);
fun = popSTACK(); bad_value = popSTACK();
bad_keyword = popSTACK();
fehler_key_badkw(TheSubr(fun)->name,bad_keyword,
bad_value,value1);
});
#undef for_every_keyword
# now assign Arguments and Parameters:
if (key_anz > 0) {
var gcv_object_t* keywordptr = keywords_pointer;
var gcv_object_t* key_args_ptr = key_args_pointer;
var uintC count;
dotimespC(count,key_anz, {
var object keyword = *keywordptr++; # Keyword
# find the pair Key.Value for this Keyword:
find_keyword_value(
# not found -> value remains #<UNBOUND> :
{ NEXT(key_args_ptr); },
# found -> save value:
{ NEXT(key_args_ptr) = value; }
);
});
}
}
# poss. process Rest-Parameters:
if (TheSubr(fun)->rest_flag == subr_norest) {
# SUBR without &REST-Flag: forget remaining Arguments:
set_args_end_pointer(rest_args_pointer);
}
# SUBR with &REST-Flag: leave remaining Arguments in Stack
}
# UP: provides the assignment between Argument-list and Keyword-parameters
# and poss. Rest-parameters of a compiled Closure.
# > closure: compiled Closure with &KEY-parameters
# > argcount: number of arguments after optional ones
# > STACK_(argcount-1),...,STACK_0: the argcount arguments after the optional ones
# > key_args_pointer: Pointer to the Key-parameters in the STACK
# (poss. also Pointer beneath the Rest-parameters in the STACK,
# which is #<UNBOUND>, if it is still to be supplied with)
# > rest_args_pointer: Pointer to the remaining Arguments in the STACK
# < STACK: set correctly
# < ergebnis: closure
# changes STACK
# can trigger GC
local maygc object match_cclosure_key (object closure, uintL argcount, gcv_object_t* key_args_pointer, gcv_object_t* rest_args_pointer)
{
/* halve argcount --> the number of pairs Key.Value: */
if (argcount%2) /* number was odd -> not paired: */
fehler_key_odd(argcount,Closure_name(closure));
if (((uintL)~(uintL)0 > ca_limit_1) && (argcount > ca_limit_1))
fehler_too_many_args(unbound,closure,argcount,ca_limit_1);
# Due to argcount <= ca_limit_1, all count's fit in a uintC.
argcount = argcount/2;
var object codevec = TheCclosure(closure)->clos_codevec; # Code-Vector
{
var uintC key_anz = TheCodevec(codevec)->ccv_numkey; # number of Keywords
var uintL keywords_offset = TheCodevec(codevec)->ccv_keyconsts; # Offset of Keywords in FUNC
var gcv_object_t* keywords_pointer = # points to the first Keyword
(TheCodevec(codevec)->ccv_flags & bit(4) # generic function?
? &TheSvector(TheCclosure(closure)->clos_consts[0])->data[keywords_offset]
: &TheCclosure(closure)->clos_consts[keywords_offset]
);
# test for illegal Keywords:
#define for_every_keyword(statement) \
if (key_anz > 0) { \
var gcv_object_t* keywordptr = keywords_pointer; \
var uintC count = key_anz; \
do { \
var object keyword = *keywordptr++; \
statement; \
} while (--count); \
}
check_for_illegal_keywords
(!((TheCodevec(codevec)->ccv_flags & bit(6)) == 0),
Closure_name(closure),
{ pushSTACK(bad_keyword); /* save */
pushSTACK(bad_value); /* save */
pushSTACK(closure); /* save the closure */
/* build list of legal Keywords: */
for_every_keyword( { pushSTACK(keyword); } );
{var object kwlist = listof(key_anz);
closure = popSTACK(); bad_value = popSTACK();
bad_keyword = popSTACK(); /* report errors: */
fehler_key_badkw(Closure_name(closure),
bad_keyword,bad_value,kwlist);}});
#undef for_every_keyword
# now assign Arguments and Parameters:
if (key_anz > 0) {
var gcv_object_t* keywordptr = keywords_pointer;
var gcv_object_t* key_args_ptr = key_args_pointer;
var uintC count;
dotimespC(count,key_anz, {
var object keyword = *keywordptr++; # Keyword
# find the pair Key.value for this keyword:
find_keyword_value(
# not found -> Wert remains #<UNBOUND> :
{ NEXT(key_args_ptr); },
# found -> save value:
{ NEXT(key_args_ptr) = value; }
);
});
}
}
# poss. process Rest-parameters:
if (TheCodevec(codevec)->ccv_flags & bit(0)) { # Rest-Flag?
# Closure with Keywords and &REST-Flag:
var gcv_object_t* rest_arg_ = &BEFORE(key_args_pointer); # Pointer to the REST-Parameter
if (!boundp(*rest_arg_)) {
# must still be filed: handicraft list
*rest_arg_ = closure; # save Closure
var object rest_arg = NIL;
until (args_end_pointer == rest_args_pointer) {
pushSTACK(rest_arg);
rest_arg = allocate_cons();
Cdr(rest_arg) = popSTACK();
Car(rest_arg) = popSTACK();
}
closure = *rest_arg_; # return Closure
*rest_arg_ = rest_arg;
} else {
# forget remaining arguments:
set_args_end_pointer(rest_args_pointer);
}
} else {
# Closure without &REST-Flag: forget remaining arguments:
set_args_end_pointer(rest_args_pointer);
}
return closure;
}
# ----------------------- E V A L -----------------------
# later:
local Values eval1 (object form);
local Values eval_fsubr (object fun, object args);
local Values eval_applyhook (object fun);
local Values eval_subr (object fun);
local Values eval_closure (object fun);
#ifdef DYNAMIC_FFI
local Values eval_ffunction (object fun);
#endif
# UP: evaluates a form in the current environment.
# eval(form);
# > form: form
# < mv_count/mv_space: values
# can trigger GC
global maygc Values eval (object form)
{
start:
# Test for Keyboard-Interrupt:
interruptp({
pushSTACK(form); # save form
pushSTACK(S(eval)); tast_break(); # call break-loop
form = popSTACK();
goto start;
});
var sp_jmp_buf my_jmp_buf;
# build EVAL-frame:
{
var gcv_object_t* top_of_frame = STACK; # Pointer to Frame
pushSTACK(form); # Form
finish_entry_frame(EVAL,my_jmp_buf,,
{
if (mv_count==0) { # after reentry: Form passed over?
form = STACK_(frame_form); # evaluate the same form again
} else {
form = STACK_(frame_form) = value1; # evaluate form passed over
}
});
}
# Test for *EVALHOOK*:
{
var object evalhook_value = Symbol_value(S(evalhookstern)); # *EVALHOOK*
if (nullp(evalhook_value)) { # *EVALHOOK* = NIL ?
# yes -> continue evaluation normally
pushSTACK(Symbol_value(S(applyhookstern))); eval1(form);
} else {
# bind *EVALHOOK*, *APPLYHOOK* to NIL:
bindhooks_NIL();
# execute (FUNCALL *EVALHOOK* form env) :
pushSTACK(form); # Form as 1. Argument
pushSTACK(evalhook_value); # save Function
var gcv_environment_t* stack_env = nest_aktenv(); # Environments in the Stack,
var object env = allocate_vector(5); # in newly allocated Vector
*(gcv_environment_t*)(&TheSvector(env)->data[0]) = *stack_env; # push in
skipSTACK(5);
evalhook_value = popSTACK(); # return Function
pushSTACK(env); # entire Environment as 2. Argument
funcall(evalhook_value,2);
# restore old values of *EVALHOOK*, *APPLYHOOK* :
unwind();
# unwind EVAL-Frame:
unwind();
}
}
}
# UP: evaluates a form in the current Environment. Does not take
# *EVALHOOK* and *APPLYHOOK* into consideration.
# eval_no_hooks(form);
# > form: Form
# < mv_count/mv_space: values
# can trigger GC
global maygc Values eval_no_hooks (object form) {
var sp_jmp_buf my_jmp_buf;
# build EVAL-Frame:
{
var gcv_object_t* top_of_frame = STACK; # Pointer to Frame
pushSTACK(form); # Form
finish_entry_frame(EVAL,my_jmp_buf,,
{
if (mv_count==0) { # after reentry: Form passed over?
form = STACK_(frame_form); # evaluate the same form again
} else {
form = STACK_(frame_form) = value1; # evaluate form passed over
}
});
}
# continue evaluation, consider *APPLYHOOK* as being NIL:
pushSTACK(NIL); eval1(form);
}
/* UP: evaluates a form in the current environment.
Does not take the value of *EVALHOOK* into consideration and expects the value of
*APPLYHOOK*.
the EVAL-frame must already have been built; it will then be unwound.
eval1(form);
> form: form
> STACK_3..STACK_1: EVAL-Frame, with form in STACK_3
> STACK_0: value of *APPLYHOOK*
< mv_count/mv_space: values
changes STACK
can trigger GC */
local maygc Values eval1 (object form)
{
if (atomp(form)) {
if (symbolp(form)) { /* Form is a Symbol */
/* value1 = value in the current Environment - not unbound! */
var object symbolmacro;
value1 = sym_value(form,aktenv.var_env,&symbolmacro);
if (!eq(symbolmacro,nullobj)) { /* Symbol-Macro? */
/* yes -> expand and evaluate again: */
skipSTACK(1); /* forget value of *APPLYHOOK* */
check_SP(); check_STACK();
eval(TheSymbolmacro(symbolmacro)->symbolmacro_expansion); /* evaluate Expansion */
unwind(); /* unwind EVAL-Frame */
} else {
if (!boundp(value1)) {
do {
pushSTACK(form); /* PLACE */
pushSTACK(form); /* CELL-ERROR slot NAME */
pushSTACK(form);
check_value(unbound_variable,GETTEXT("EVAL: variable ~S has no value"));
form = STACK_(frame_form+1);
} while (!boundp(value1));
if (!nullp(value2)) /* STORE-VALUE */
value1 = setq(form,value1);
}
mv_count=1; /* value1 as value */
skipSTACK(1);
unwind(); /* unwind EVAL-Frame */
}
} else {
/* self-evaluating form */
VALUES1(form);
skipSTACK(1);
unwind(); /* unwind EVAL-Frame */
}
} else { /* Form is a Cons */
eval_cons:
/* determine, if Macro-call, poss. expand: */
macroexp(form,aktenv.var_env,aktenv.fun_env); form = value1;
if (!nullp(value2)) { /* expanded ? */
/* now really evaluate: */
skipSTACK(1); /* forget value of *APPLYHOOK* */
check_SP(); check_STACK();
eval(form); /* evaluate expanded form */
unwind(); /* unwind EVAL-Frame */
} else {
var object fun = Car(form); /* function designation */
if (funnamep(fun)) {
/* fetch function-definition in the environment: */
fun = sym_function(fun,aktenv.fun_env);
fun_dispatch:
/* branch according to type of function:
unbound / SUBR/FSUBR/Closure / FunctionMacro / Macro */
#ifdef TYPECODES
switch (typecode(fun))
#else
if (immsubrp(fun))
goto case_subr;
else if (orecordp(fun))
goto case_orecord;
else
switch (0)
#endif
{
case_subr: /* SUBR */
pushSTACK(Cdr(form)); /* argument list */
if (!nullp(STACK_1))
goto applyhook;
eval_subr(fun);
break;
case_closure: /* closure */
pushSTACK(Cdr(form)); /* argument list */
closure: /* fun is a closure */
if (!nullp(STACK_1))
goto applyhook;
eval_closure(fun);
break;
applyhook: /* value of *APPLYHOOK* is /= NIL. */
eval_applyhook(fun);
break;
case_orecord:
switch (Record_type(fun)) {
case_Rectype_Closure_above;
case_Rectype_Subr_above;
case Rectype_Fsubr: /* Fsubr */
eval_fsubr(fun,Cdr(form));
break;
#ifdef DYNAMIC_FFI
case Rectype_Ffunction: /* Foreign-Function */
pushSTACK(Cdr(form)); /* argument list */
if (!nullp(STACK_1))
goto applyhook;
eval_ffunction(fun);
break;
#endif
case Rectype_FunctionMacro:
/* FunctionMacro -> treat like a function */
fun = TheFunctionMacro(fun)->functionmacro_function;
goto fun_dispatch;
default:
goto undef;
}
break;
default: undef: {
pushSTACK(form);
fun = check_fdefinition(Car(form),S(eval));
form = popSTACK();
goto fun_dispatch;
}
}
} else if (consp(fun) && eq(Car(fun),S(lambda))) {
/* lambda-expression? */
pushSTACK(Cdr(form)); /* Argument list */
fun = get_closure(Cdr(fun),S(Klambda),false,&aktenv); /* create closure in current environment */
goto closure; /* und apply it to the arguments, as above */
} else {
pushSTACK(Cdr(form));
fun = check_funname_replacement(source_program_error,S(eval),fun);
pushSTACK(fun);
form = allocate_cons();
Car(form) = popSTACK(); /* fun */
Cdr(form) = popSTACK(); /* Cdr(form) */
goto eval_cons;
}
}
}
}
# In EVAL: Applies a FSUBR to an argument-list, cleans up STACK
# and returns the values.
# eval_fsubr(fun,args);
# > fun: a FSUBR
# > args: argument-list
# > STACK-layout: EVAL-Frame, *APPLYHOOK*.
# < STACK: cleaned up
# < mv_count/mv_space: values
# changes STACK
# can trigger GC
local maygc Values eval_fsubr (object fun, object args)
{
skipSTACK(1); # forget value of *APPLYHOOK*
check_SP(); check_STACK();
#if STACKCHECKS
var gcv_object_t* STACKbefore = STACK;
#endif
# put arguments in the STACK:
switch ((uintW)posfixnum_to_V(TheFsubr(fun)->argtype)) {
# Macro for 1 required-Parameter:
#define REQ_PAR() \
{ if (atomp(args)) goto fehler_zuwenig; \
pushSTACK(Car(args)); # next parameter in the STACK \
args = Cdr(args); \
}
case (uintW)fsubr_argtype_2_0_nobody:
# FSUBR with 2 required-Parameters
REQ_PAR();
case (uintW)fsubr_argtype_1_0_nobody:
# FSUBR with 1 required-Parameter
REQ_PAR();
if (!nullp(args)) goto fehler_zuviel;
break;
case (uintW)fsubr_argtype_2_1_nobody:
# FSUBR with 2 required-Parameters and 1 optional-Parameter
REQ_PAR();
case (uintW)fsubr_argtype_1_1_nobody:
# FSUBR with 1 required-Parameter and 1 optional-Parameter
REQ_PAR();
if (consp(args)) {
pushSTACK(Car(args)); # optional parameter into STACK
args = Cdr(args);
if (!nullp(args)) goto fehler_zuviel;
} else {
pushSTACK(unbound); # unbound into STACK instead
if (!nullp(args)) goto fehler_dotted;
}
break;
case (uintW)fsubr_argtype_2_body:
# FSUBR with 2 required-Parameters and Body-Parameter
REQ_PAR();
case (uintW)fsubr_argtype_1_body:
# FSUBR with 1 required-Parameter and Body-Parameter
REQ_PAR();
case (uintW)fsubr_argtype_0_body:
# FSUBR with 0 required-Parameters and Body-Parameter
pushSTACK(args); # remaining body into STACK
break;
default: NOTREACHED;
fehler_zuwenig: # argument-list args is an atom, prematurely
if (!nullp(args)) goto fehler_dotted;
# clean up STACK up to the calling EVAL-Frame:
until (framecode(STACK_0) & bit(frame_bit_t)) {
skipSTACK(1);
}
{
var object form = STACK_(frame_form); # Form from EVAL-Frame
pushSTACK(form); /* SOURCE-PROGRAM-ERROR slot DETAIL */
pushSTACK(form); pushSTACK(Car(form));
fehler(source_program_error,
GETTEXT("EVAL: too few parameters for special operator ~S: ~S"));
}
fehler_zuviel: # argument-list args is not NIL at the tail
if (atomp(args)) goto fehler_dotted;
# clean up STACK up to the calling EVAL-Frame:
until (framecode(STACK_0) & bit(frame_bit_t)) {
skipSTACK(1);
}
{
var object form = STACK_(frame_form); # Form from EVAL-Frame
pushSTACK(form); /* SOURCE-PROGRAM-ERROR slot DETAIL */
pushSTACK(form); pushSTACK(Car(form));
fehler(source_program_error,
GETTEXT("EVAL: too many parameters for special operator ~S: ~S"));
}
fehler_dotted: # argument-list args ends with Atom /= NIL
# clean up STACK up to the calling EVAL-Frame:
until (framecode(STACK_0) & bit(frame_bit_t)) {
skipSTACK(1);
}
{
var object form = STACK_(frame_form); # Form from EVAL-Frame
pushSTACK(form); /* SOURCE-PROGRAM-ERROR slot DETAIL */
pushSTACK(form); pushSTACK(Car(form));
fehler(source_program_error,
GETTEXT("EVAL: dotted parameter list for special operator ~S: ~S"));
}
#undef REQ_PAR
}
# Now STACK = STACKbefore STACKop - (req + opt + (body-flag ? 1 : 0)).
# Call FSUBR:
with_saved_back_trace_fsubr(fun,
(*(fsubr_function_t*)(TheFsubr(fun)->function))(); );
#if STACKCHECKS
if (!(STACK == STACKbefore)) # STACK as before?
abort(); # no -> go to Debugger
#endif
unwind(); # unwind EVAL-Frame
}
# In EVAL: Applies *APPLYHOOK* to a function (SUBR or Closure) and
# an argument-list, cleans up the STACK and returns the values.
# eval_applyhook(fun);
# > fun: function, a SUBR or a closure
# > STACK-layout: EVAL-Frame, *APPLYHOOK* (/= NIL), argument-list.
# < STACK: cleaned up
# < mv_count/mv_space: values
# changes STACK
# can trigger GC
local maygc Values eval_applyhook(object fun) {
var object args = popSTACK(); # argument-list
var object applyhook_value = popSTACK(); # value of *APPLYHOOK*
check_SP();
# bind *EVALHOOK*, *APPLYHOOK* to NIL:
bindhooks_NIL();
#ifndef X3J13_005
# execute (FUNCALL *APPLYHOOK* fun args env) :
pushSTACK(fun); # Funktion as 1. Argument
pushSTACK(args); # argument-list as 2. Argument
pushSTACK(applyhook_value); # save function
{
var gcv_environment_t* stack_env = nest_aktenv(); # Environments into Stack,
var object env = allocate_vector(5); # in newly allocated Vector
*(gcv_environment_t*)(&TheSvector(env)->data[0]) = *stack_env; # push in
skipSTACK(5);
}
applyhook_value = popSTACK(); # function back
pushSTACK(env); # entire Environment as 3. Argument
funcall(applyhook_value,3);
#else
# execute (FUNCALL *APPLYHOOK* fun args) :
pushSTACK(fun); # function as 1. Argument
pushSTACK(args); # argument-list as 2. Argument
funcall(applyhook_value,2);
#endif
# old values of *EVALHOOK*, *APPLYHOOK* back:
unwind();
# unwind EVAL-Frame:
unwind();
}
# In EVAL: error, if too few arguments
nonreturning_function(local, fehler_eval_zuwenig, (object fun)) {
var object form = STACK_(frame_form); # Form
pushSTACK(form); /* SOURCE-PROGRAM-ERROR slot DETAIL */
pushSTACK(form); pushSTACK(fun);
/* ANSI CL 3.5.1.2. wants a PROGRAM-ERROR here. */
fehler(source_program_error,
GETTEXT("EVAL: too few arguments given to ~S: ~S"));
}
# In EVAL: error, if too many arguments
nonreturning_function(local, fehler_eval_zuviel, (object fun)) {
var object form = STACK_(frame_form); # Form
pushSTACK(form); /* SOURCE-PROGRAM-ERROR slot DETAIL */
pushSTACK(form); pushSTACK(fun);
/* ANSI CL 3.5.1.3. wants a PROGRAM-ERROR here. */
fehler(source_program_error,
GETTEXT("EVAL: too many arguments given to ~S: ~S"));
}
# In EVAL: error, if dotted argument-list
nonreturning_function(local, fehler_eval_dotted, (object fun)) {
var object form = STACK_(frame_form); # Form
pushSTACK(form); /* SOURCE-PROGRAM-ERROR slot DETAIL */
pushSTACK(form); pushSTACK(fun);
fehler(source_program_error,
GETTEXT("EVAL: argument list given to ~S is dotted: ~S"));
}
# In EVAL: Applies an SUBR to an argument-list, cleans up STACK
# and returns the values.
# eval_subr(fun);
# > fun: function, a SUBR
# > STACK-layout: EVAL-Frame, *APPLYHOOK*, argument-list.
# < STACK: cleaned up
# < mv_count/mv_space: values
# changes STACK
# can trigger GC
local maygc Values eval_subr (object fun)
{
var object args = popSTACK(); # argument-list
skipSTACK(1); # forget value of *APPLYHOOK*
check_SP(); check_STACK();
var gcv_object_t* args_pointer = args_end_pointer; # Pointer to the arguments
var gcv_object_t* rest_args_pointer; # Pointer to the remaining arguments
var uintL argcount; # number of remaining arguments
# push arguments evaluated in the STACK:
# first a Dispatch for most important cases:
switch (TheSubr(fun)->argtype) {
# Macro for a required-argument:
#define REQ_ARG() \
{ if (atomp(args)) goto fehler_zuwenig; \
pushSTACK(Cdr(args)); # remaining arguments \
eval(Car(args)); # evaluate next argument \
args = STACK_0; STACK_0 = value1; # and into STACK \
}
# Macro for the n-th last optional-argument:
#define OPT_ARG(n) \
{ if (atomp(args)) goto unbound_optional_##n ; \
pushSTACK(Cdr(args)); # remaining arguments \
eval(Car(args)); # evaluate next argument \
args = STACK_0; STACK_0 = value1; # and into STACK \
}
case (uintW)subr_argtype_6_0:
# SUBR with 6 required-Arguments
REQ_ARG();
case (uintW)subr_argtype_5_0:
# SUBR with 5 required-Arguments
REQ_ARG();
case (uintW)subr_argtype_4_0:
# SUBR with 4 required-Arguments
REQ_ARG();
case (uintW)subr_argtype_3_0:
# SUBR with 3 required-Arguments
REQ_ARG();
case (uintW)subr_argtype_2_0:
# SUBR with 2 required-Arguments
REQ_ARG();
case (uintW)subr_argtype_1_0:
# SUBR with 1 required-Argument
REQ_ARG();
case (uintW)subr_argtype_0_0:
# SUBR without Arguments
if (!nullp(args)) goto fehler_zuviel;
goto apply_subr_norest;
case (uintW)subr_argtype_4_1:
# SUBR with 4 required-Arguments and 1 optional-Argument
REQ_ARG();
case (uintW)subr_argtype_3_1:
# SUBR with 3 required-Arguments and 1 optional-Argument
REQ_ARG();
case (uintW)subr_argtype_2_1:
# SUBR with 2 required-Arguments and 1 optional-Argument
REQ_ARG();
case (uintW)subr_argtype_1_1:
# SUBR with 1 required-Argument and 1 optional-Argument
REQ_ARG();
case (uintW)subr_argtype_0_1:
# SUBR with 1 optional-Argument
OPT_ARG(1);
if (!nullp(args)) goto fehler_zuviel;
goto apply_subr_norest;
case (uintW)subr_argtype_3_2:
# SUBR with 3 required-Arguments and 2 optional-Arguments
REQ_ARG();
case (uintW)subr_argtype_2_2:
# SUBR with 2 required-Arguments and 2 optional-Arguments
REQ_ARG();
case (uintW)subr_argtype_1_2:
# SUBR with 1 required-Argument and 2 optional-Arguments
REQ_ARG();
case (uintW)subr_argtype_0_2:
# SUBR with 2 optional-Arguments
OPT_ARG(2);
OPT_ARG(1);
if (!nullp(args)) goto fehler_zuviel;
goto apply_subr_norest;
case (uintW)subr_argtype_2_3:
# SUBR with 2 required-Arguments and 3 optional-Arguments
REQ_ARG();
case (uintW)subr_argtype_1_3:
# SUBR with 1 required-Argument and 3 optional-Arguments
REQ_ARG();
case (uintW)subr_argtype_0_3:
# SUBR with 3 optional-Arguments
OPT_ARG(3);
OPT_ARG(2);
OPT_ARG(1);
if (!nullp(args)) goto fehler_zuviel;
goto apply_subr_norest;
case (uintW)subr_argtype_0_5:
# SUBR with 5 optional-Arguments
OPT_ARG(5);
case (uintW)subr_argtype_0_4:
# SUBR with 4 optional-Arguments
OPT_ARG(4);
OPT_ARG(3);
OPT_ARG(2);
OPT_ARG(1);
if (!nullp(args)) goto fehler_zuviel;
goto apply_subr_norest;
unbound_optional_5: # Still 5 optional Arguments, but atomp(args)
pushSTACK(unbound);
unbound_optional_4: # Still 4 optional Arguments, but atomp(args)
pushSTACK(unbound);
unbound_optional_3: # Still 3 optional Arguments, but atomp(args)
pushSTACK(unbound);
unbound_optional_2: # Still 2 optional Arguments, but atomp(args)
pushSTACK(unbound);
unbound_optional_1: # Still 1 optional Argument, but atomp(args)
pushSTACK(unbound);
if (!nullp(args)) goto fehler_dotted;
goto apply_subr_norest;
case (uintW)subr_argtype_3_0_rest:
# SUBR with 3 required-Arguments and further Arguments
REQ_ARG();
case (uintW)subr_argtype_2_0_rest:
# SUBR with 2 required-Arguments and further Arguments
REQ_ARG();
case (uintW)subr_argtype_1_0_rest:
# SUBR with 1 required-Argument and further Arguments
REQ_ARG();
case (uintW)subr_argtype_0_0_rest:
# SUBR with further Arguments
rest_args_pointer = args_end_pointer; # Pointer to the remaining arguments
# evaluate all further arguments and into Stack:
argcount = 0; # counter for the remaining arguments
while (consp(args)) {
check_STACK();
pushSTACK(Cdr(args)); # remaining arguments
eval(Car(args)); # evaluate next argument
args = STACK_0; STACK_0 = value1; # and into STACK
argcount++;
}
goto apply_subr_rest;
case (uintW)subr_argtype_4_0_key:
# SUBR with 4 required-Arguments and Keyword-Arguments
REQ_ARG();
case (uintW)subr_argtype_3_0_key:
# SUBR with 3 required-Arguments and Keyword-Arguments
REQ_ARG();
case (uintW)subr_argtype_2_0_key:
# SUBR with 2 required-Arguments and Keyword-Arguments
REQ_ARG();
case (uintW)subr_argtype_1_0_key:
# SUBR with 1 required-Argument and Keyword-Arguments
REQ_ARG();
case (uintW)subr_argtype_0_0_key:
# SUBR with Keyword-Arguments
if (atomp(args)) goto unbound_optional_key_0;
goto apply_subr_key;
case (uintW)subr_argtype_1_1_key:
# SUBR with 1 required-Argument, 1 optional-Argument and Keyword-Arguments
REQ_ARG();
case (uintW)subr_argtype_0_1_key:
# SUBR with 1 optional-Argument and Keyword-Arguments
OPT_ARG(key_1);
if (atomp(args)) goto unbound_optional_key_0;
goto apply_subr_key;
case (uintW)subr_argtype_1_2_key:
# SUBR with 1 required-Argument, 2 optional-Arguments and Keyword-Arguments
REQ_ARG();
OPT_ARG(key_2);
OPT_ARG(key_1);
if (atomp(args)) goto unbound_optional_key_0;
goto apply_subr_key;
unbound_optional_key_2: # Silll 2 optional Arguments, but atomp(args)
pushSTACK(unbound);
unbound_optional_key_1: # Still 1 optional Argument, but atomp(args)
pushSTACK(unbound);
unbound_optional_key_0: # Before the keywords is atomp(args)
{
var uintC count;
dotimesC(count,TheSubr(fun)->key_anz, { pushSTACK(unbound); } );
}
if (!nullp(args)) goto fehler_dotted;
goto apply_subr_norest;
default: NOTREACHED;
#undef OPT_ARG
#undef REQ_ARG
}
# Now the general Version:
# reserve space on the STACK:
get_space_on_STACK(sizeof(gcv_object_t) *
(uintL)(TheSubr(fun)->req_anz +
TheSubr(fun)->opt_anz +
TheSubr(fun)->key_anz));
# evaluate required parameters and push into Stack:
{
var uintC count;
dotimesC(count,TheSubr(fun)->req_anz, {
if (atomp(args)) goto fehler_zuwenig; # at the end of argument-list?
pushSTACK(Cdr(args)); # remaining argument-list
eval(Car(args)); # evaluate next argument
args = STACK_0; STACK_0 = value1; # and into Stack
});
}
{ /* evaluate optional parameters and push into Stack: */
var uintC count = TheSubr(fun)->opt_anz;
while (!atomp(args)) { /* argument-list not finished? */
if (count==0) # all optional parameters supplied with?
goto optionals_ok;
count--;
pushSTACK(Cdr(args)); # remaining argument-list
eval(Car(args)); # evaluate next argument
args = STACK_0; STACK_0 = value1; # and into Stack
}
# argument-list finished.
# All further count optional parameters get the "value"
# #<UNBOUND>, the same for the Keyword-parameters:
dotimesC(count,count + TheSubr(fun)->key_anz, { pushSTACK(unbound); } );
if (TheSubr(fun)->rest_flag == subr_rest) { # &REST-Flag?
# yes -> 0 additional arguments:
argcount = 0; rest_args_pointer = args_end_pointer;
}
# no -> nothing to do
goto los;
}
optionals_ok:
# process Rest- and Keyword-parameters.
# args = remaining argument-list (not yet finished)
if (TheSubr(fun)->key_flag == subr_nokey) {
# SUBR without KEY
if (TheSubr(fun)->rest_flag == subr_norest) {
# SUBR without REST or KEY -> argument-list should be finished
goto fehler_zuviel;
} else {
# SUBR with only REST, without KEY: treatment of remaining arguments
rest_args_pointer = args_end_pointer;
argcount = 0; # counter for the remaining arguments
do {
check_STACK();
pushSTACK(Cdr(args)); # remaining argument-list
eval(Car(args)); # evaluate next argument
args = STACK_0; STACK_0 = value1; # and into Stack
argcount++;
} while (consp(args));
if (((uintL)~(uintL)0 > ca_limit_1) && (argcount > ca_limit_1))
goto fehler_zuviel;
}
} else
apply_subr_key: { /* SUBR with Keywords. */
# args = remaining argument-list (not yet finished)
# First initialize the Keyword-parameters with #<UNBOUND> , then
# evaluate the remaining arguments and push into Stack, then
# assign the Keywords:
var gcv_object_t* key_args_pointer = args_end_pointer; # Pointer to Keyword-parameters
# initialize all Keyword-parameters with #<UNBOUND> :
{
var uintC count;
dotimesC(count,TheSubr(fun)->key_anz, { pushSTACK(unbound); } );
}
rest_args_pointer = args_end_pointer; # Pointer to the remaining arguments
# evaluate all further arguments and into Stack:
argcount = 0; # counter for the remaining arguments
do {
check_STACK();
pushSTACK(Cdr(args)); # remaining argument-list
eval(Car(args)); # evaluate next argument
args = STACK_0; STACK_0 = value1; # and into Stack
argcount++;
} while (consp(args));
if (((uintL)~(uintL)0 > ca_limit_1) && (argcount > ca_limit_1))
goto fehler_zuviel;
# assign Keywords and poss. discard remaining arguments:
match_subr_key(fun,argcount,key_args_pointer,rest_args_pointer);
}
los: # call function
# remaining argument-list must be NIL :
if (!nullp(args)) goto fehler_dotted;
if (TheSubr(fun)->rest_flag == subr_norest) {
# SUBR without &REST-Flag:
apply_subr_norest:
with_saved_back_trace_subr(fun,STACK,-1,
(*(subr_norest_function_t*)(TheSubr(fun)->function))(); );
} else {
# SUBR with &REST-Flag:
apply_subr_rest:
with_saved_back_trace_subr(fun,STACK,
TheSubr(fun)->req_anz + TheSubr(fun)->opt_anz + argcount,
(*(subr_rest_function_t*)(TheSubr(fun)->function))(argcount,rest_args_pointer); );
}
#if STACKCHECKS
if (!(args_pointer == args_end_pointer)) # Stack cleaned up?
abort(); # no -> leave to Debugger
#endif
unwind(); # unwind EVAL-Frame
return; # finished
# Gathered error-messages:
fehler_zuwenig: # Argument-List args is prematurely an Atom
if (!nullp(args)) goto fehler_dotted;
set_args_end_pointer(args_pointer); # clean up STACK
fehler_eval_zuwenig(TheSubr(fun)->name);
fehler_zuviel: # Argument-List args is not NIL at the end
if (atomp(args)) goto fehler_dotted;
set_args_end_pointer(args_pointer); # clean up STACK
fehler_eval_zuviel(TheSubr(fun)->name);
fehler_dotted: # Argument-List args ends with Atom /= NIL
set_args_end_pointer(args_pointer); # clean up STACK
fehler_eval_dotted(TheSubr(fun)->name);
}
# In EVAL: Applies a Closure to an argument-list, cleans up the STACK
# and returns the values.
# eval_closure(fun);
# > fun: function, a Closure
# > STACK-layout: EVAL-Frame, *APPLYHOOK*, argument-list.
# < STACK: cleaned up
# < mv_count/mv_space: values
# changes STACK
# can trigger GC
local maygc Values eval_closure (object closure)
{
var object args = popSTACK(); # argument-list
skipSTACK(1); # forget value of *APPLYHOOK*
# STACK-layout: EVAL-Frame.
check_SP(); check_STACK();
pushSTACK(closure); # save Closure
var gcv_object_t* closure_ = &STACK_0; # and memorize, where it is
var gcv_object_t* STACKbefore = STACK;
if (simple_bit_vector_p(Atype_8Bit,TheClosure(closure)->clos_codevec)) {
# closure is a compiled Closure
var object codevec = TheCclosure(closure)->clos_codevec; # Code-Vector
# push arguments evaluated into STACK:
# first a dispatch for the most important cases:
switch (TheCodevec(codevec)->ccv_signature) {
# Macro for a required-argument:
#define REQ_ARG() \
{ if (atomp(args)) goto fehler_zuwenig; \
pushSTACK(Cdr(args)); # remaining arguments \
eval(Car(args)); # evaluate next argument \
args = STACK_0; STACK_0 = value1; # and into STACK \
}
# Macro for the n-last optional-argument:
#define OPT_ARG(n) \
{ if (atomp(args)) goto unbound_optional_##n ; \
pushSTACK(Cdr(args)); # remaining arguments \
eval(Car(args)); # evaluate next argument \
args = STACK_0; STACK_0 = value1; # and into STACK \
}
case (uintB)cclos_argtype_5_0:
# 5 required-Arguments
REQ_ARG();
case (uintB)cclos_argtype_4_0:
# 4 required-Arguments
REQ_ARG();
case (uintB)cclos_argtype_3_0:
# 3 required-Arguments
REQ_ARG();
case (uintB)cclos_argtype_2_0:
# 2 required-Arguments
REQ_ARG();
case (uintB)cclos_argtype_1_0:
# 1 required-Argument
REQ_ARG();
case (uintB)cclos_argtype_0_0:
# no Arguments
noch_0_opt_args:
if (!nullp(args)) goto fehler_zuviel;
goto apply_cclosure_nokey;
case (uintB)cclos_argtype_4_1:
# 4 required-Arguments and 1 optional-Argument
REQ_ARG();
case (uintB)cclos_argtype_3_1:
# 3 required-Arguments and 1 optional-Argument
REQ_ARG();
case (uintB)cclos_argtype_2_1:
# 2 required-Arguments and 1 optional-Argument
REQ_ARG();
case (uintB)cclos_argtype_1_1:
# 1 required-Argument and 1 optional-Argument
REQ_ARG();
case (uintB)cclos_argtype_0_1:
# 1 optional-Argument
noch_1_opt_args:
OPT_ARG(1);
goto noch_0_opt_args;
case (uintB)cclos_argtype_3_2:
# 3 required-Arguments and 2 optional-Arguments
REQ_ARG();
case (uintB)cclos_argtype_2_2:
# 2 required-Arguments and 2 optional-Arguments
REQ_ARG();
case (uintB)cclos_argtype_1_2:
# 1 required-Argument and 2 optional-Arguments
REQ_ARG();
case (uintB)cclos_argtype_0_2:
# 2 optional-Arguments
noch_2_opt_args:
OPT_ARG(2);
goto noch_1_opt_args;
case (uintB)cclos_argtype_2_3:
# 2 required-Arguments and 3 optional-Arguments
REQ_ARG();
case (uintB)cclos_argtype_1_3:
# 1 required-Argument and 3 optional-Arguments
REQ_ARG();
case (uintB)cclos_argtype_0_3:
# 3 optional-Arguments
noch_3_opt_args:
OPT_ARG(3);
goto noch_2_opt_args;
case (uintB)cclos_argtype_1_4:
# 1 required-Argument and 4 optional-Arguments
REQ_ARG();
case (uintB)cclos_argtype_0_4:
# 4 optional-Arguments
noch_4_opt_args:
OPT_ARG(4);
goto noch_3_opt_args;
case (uintB)cclos_argtype_0_5:
# 5 optional-Arguments
OPT_ARG(5);
goto noch_4_opt_args;
unbound_optional_5: # Still 5 optional Arguments, but atomp(args)
pushSTACK(unbound);
unbound_optional_4: # Still 4 optional Arguments, but atomp(args)
pushSTACK(unbound);
unbound_optional_3: # Still 3 optional Arguments, but atomp(args)
pushSTACK(unbound);
unbound_optional_2: # Still 2 optional Arguments, but atomp(args)
pushSTACK(unbound);
unbound_optional_1: # Still 1 optional Argument, but atomp(args)
pushSTACK(unbound);
if (!nullp(args)) goto fehler_dotted;
goto apply_cclosure_nokey;
case (uintB)cclos_argtype_4_0_rest:
# 4 required-Arguments, Rest-Parameter
REQ_ARG();
case (uintB)cclos_argtype_3_0_rest:
# 3 required-Arguments, Rest-Parameter
REQ_ARG();
case (uintB)cclos_argtype_2_0_rest:
# 2 required-Arguments, Rest-Parameter
REQ_ARG();
case (uintB)cclos_argtype_1_0_rest:
# 1 required-Argument, Rest-Parameter
REQ_ARG();
case (uintB)cclos_argtype_0_0_rest:
# no Arguments, Rest-Parameter
if (consp(args)) goto apply_cclosure_rest_nokey;
if (!nullp(args)) goto fehler_dotted;
pushSTACK(NIL); # Rest-Parameter := NIL
goto apply_cclosure_nokey;
case (uintB)cclos_argtype_4_0_key:
# 4 required-Arguments, Keyword-Arguments
REQ_ARG();
case (uintB)cclos_argtype_3_0_key:
# 3 required-Arguments, Keyword-Arguments
REQ_ARG();
case (uintB)cclos_argtype_2_0_key:
# 2 required-Arguments, Keyword-Arguments
REQ_ARG();
case (uintB)cclos_argtype_1_0_key:
# 1 required-Argument, Keyword-Arguments
REQ_ARG();
noch_0_opt_args_key:
closure = *closure_; codevec = TheCclosure(closure)->clos_codevec;
case (uintB)cclos_argtype_0_0_key:
# only Keyword-Arguments
if (atomp(args)) goto unbound_optional_key_0;
goto apply_cclosure_key;
case (uintB)cclos_argtype_3_1_key:
# 3 required-Arguments and 1 optional-Argument, Keyword-Arguments
REQ_ARG();
case (uintB)cclos_argtype_2_1_key:
# 2 required-Arguments and 1 optional-Argument, Keyword-Arguments
REQ_ARG();
case (uintB)cclos_argtype_1_1_key:
# 1 required-Argument and 1 optional-Argument, Keyword-Arguments
REQ_ARG();
case (uintB)cclos_argtype_0_1_key:
# 1 optional-Argument, Keyword-Arguments
noch_1_opt_args_key:
OPT_ARG(key_1);
goto noch_0_opt_args_key;
case (uintB)cclos_argtype_2_2_key:
# 2 required-Arguments and 2 optional-Arguments, Keyword-Arguments
REQ_ARG();
case (uintB)cclos_argtype_1_2_key:
# 1 required-Argument and 2 optional-Arguments, Keyword-Arguments
REQ_ARG();
case (uintB)cclos_argtype_0_2_key:
# 2 optional-Arguments, Keyword-Arguments
noch_2_opt_args_key:
OPT_ARG(key_2);
goto noch_1_opt_args_key;
case (uintB)cclos_argtype_1_3_key:
# 1 required-Argument and 3 optional-Arguments, Keyword-Arguments
REQ_ARG();
case (uintB)cclos_argtype_0_3_key:
# 3 optional-Arguments, Keyword-Arguments
noch_3_opt_args_key:
OPT_ARG(key_3);
goto noch_2_opt_args_key;
case (uintB)cclos_argtype_0_4_key:
# 4 optional-Arguments, Keyword-Arguments
OPT_ARG(key_4);
goto noch_3_opt_args_key;
unbound_optional_key_4: # Still 4 optional Arguments, but atomp(args)
pushSTACK(unbound);
unbound_optional_key_3: # Still 3 optional Arguments, but atomp(args)
pushSTACK(unbound);
unbound_optional_key_2: # Still 2 optional Arguments, but atomp(args)
pushSTACK(unbound);
unbound_optional_key_1: # Still 1 optional Argument, but atomp(args)
pushSTACK(unbound);
unbound_optional_key_0: # Before the Keywords is atomp(args)
if (!nullp(args)) goto fehler_dotted;
goto apply_cclosure_key_noargs;
case (uintB)cclos_argtype_default:
# General Version
break;
default: NOTREACHED;
#undef OPT_ARG
#undef REQ_ARG
}
# Now the general Version:
{
var uintL req_anz = TheCodevec(codevec)->ccv_numreq; # number of required parameters
var uintL opt_anz = TheCodevec(codevec)->ccv_numopt; # number of optional parameters
var uintB flags = TheCodevec(codevec)->ccv_flags; # Flags
# reserve space on STACK:
get_space_on_STACK(sizeof(gcv_object_t) * (req_anz+opt_anz));
# evaluate required parameters and push into Stack:
{
var uintC count;
dotimesC(count,req_anz, {
if (atomp(args)) goto fehler_zuwenig; # argument-list finished?
pushSTACK(Cdr(args)); # remaining argument-list
eval(Car(args)); # evaluate nnext argument
args = STACK_0; STACK_0 = value1; # and into Stack
});
}
{ /* evaluate optional parameters and push into Stack: */
var uintC count = opt_anz;
while (!atomp(args)) { /* argument-list not finished? */
if (count==0) # all optional parameters supplied with?
goto optionals_ok;
count--;
pushSTACK(Cdr(args)); # remaining argument-list
eval(Car(args)); # evaluate next argument
args = STACK_0; STACK_0 = value1; # and into Stack
}
# argument-list finished.
if (!nullp(args)) goto fehler_dotted;
# All further count optional parameters get the "value"
# #<UNBOUND>, the &REST-parameter gets the value NIL,
# the Keyword-parameter gets the value #<UNBOUND> :
dotimesC(count,count, { pushSTACK(unbound); } );
}
closure = *closure_; codevec = TheCclosure(closure)->clos_codevec;
if (flags & bit(0)) # &REST-Flag?
pushSTACK(NIL); # yes -> initialize with NIL
if (flags & bit(7)) # &KEY-Flag?
goto apply_cclosure_key_noargs;
else
goto apply_cclosure_nokey_;
optionals_ok:
# process Rest- and Keyword-parameters.
# args = remaining argument-list (not yet finished)
closure = *closure_; codevec = TheCclosure(closure)->clos_codevec;
if (flags == 0)
# Closure without REST or KEY -> argument-list should be finished
goto fehler_zuviel;
elif (flags & bit(7)) { # Key-Flag?
# Closure with Keywords.
# args = remaining argument-list (not yet finished)
# First initialize the Keyword-parameters with #<UNBOUND> , then
# evaluate the remaining arguments and push into Stack, then
# assign the Keywords:
# poss. initialize the Rest-Parameter:
if (flags & bit(0))
pushSTACK(unbound);
goto apply_cclosure_key;
} else
goto apply_cclosure_rest_nokey;
}
apply_cclosure_key_noargs:
{
var uintC count = TheCodevec(codevec)->ccv_numkey; # number of Keyword-parameters
dotimesC(count,count, { pushSTACK(unbound); } ); # initialize with #<UNBOUND>
interpret_bytecode(closure,codevec,CCV_START_KEY); # interprete bytecode starting at Byte 12
}
goto done;
apply_cclosure_key: # jump to Closure only with &KEY:
{
var gcv_object_t* key_args_pointer = args_end_pointer; # Pointer to Keyword-Parameter
# initialize all Keyword-parameters with #<UNBOUND> :
{
var uintC count = TheCodevec(codevec)->ccv_numkey;
dotimesC(count,count, { pushSTACK(unbound); } );
}
var gcv_object_t* rest_args_pointer = args_end_pointer; # Pointer to the remaining arguments
# evaluate all further arguments and push into Stack:
var uintL argcount = 0; # counter for the remaining arguments
do {
check_STACK();
pushSTACK(Cdr(args)); # remaining argument-list
eval(Car(args)); # evaluate next argument
args = STACK_0; STACK_0 = value1; # and into Stack
argcount++;
} while (consp(args));
# argument-list finished.
if (!nullp(args)) goto fehler_dotted;
# assign Keywords, build Rest-Parameter
# and poss. discard remaining arguments:
closure = match_cclosure_key(*closure_,argcount,key_args_pointer,rest_args_pointer);
codevec = TheCclosure(closure)->clos_codevec;
interpret_bytecode(closure,codevec,CCV_START_KEY); # interprete bytecode starting at Byte 12
}
goto done;
apply_cclosure_rest_nokey:
# Closure with only REST, without KEY:
# evaluate remaining arguments one by on, put into list
# args = remaining argument-list (not yet finished)
pushSTACK(NIL); # so far evaluated remaining arguments
pushSTACK(args); # remaining arguments, unevaluated
do {
args = STACK_0; STACK_0 = Cdr(args);
eval(Car(args)); # evaluate next argument
pushSTACK(value1);
# and cons onto the list:
var object new_cons = allocate_cons();
Car(new_cons) = popSTACK();
Cdr(new_cons) = STACK_1;
STACK_1 = new_cons;
} while (mconsp(STACK_0));
args = popSTACK();
# reverse list STACK_0 and use as REST-parameter:
nreverse(STACK_0);
# argument-list finished.
if (!nullp(args)) goto fehler_dotted;
apply_cclosure_nokey: # jump to Closure without &KEY :
closure = *closure_; codevec = TheCclosure(closure)->clos_codevec;
apply_cclosure_nokey_:
interpret_bytecode(closure,codevec,CCV_START_NONKEY); # interprete bytecode starting at Byte 8
done:
#if STACKCHECKC
if (!(STACK == STACKbefore)) # STACK as before?
abort(); # no -> go to Debugger
#endif
skipSTACK(1); # discard Closure
unwind(); # unwind EVAL-Frame
return; # finished
} else {
# closure is an interpreted Closure
var gcv_object_t* args_pointer = args_end_pointer; # Pointer to the arguments
var uintC args_on_stack = 0; # Anzahl der Argumente
while (consp(args)) {
pushSTACK(Cdr(args)); # save rest of list
eval(Car(args)); # evaluate next element
args = STACK_0; STACK_0 = value1; # result into STACK
args_on_stack += 1;
if (((uintL)~(uintL)0 > ca_limit_1) && (args_on_stack > ca_limit_1))
goto fehler_zuviel;
}
with_saved_back_trace_iclosure(*closure_,args_pointer,args_on_stack,
funcall_iclosure(*closure_,args_pointer,args_on_stack); );
skipSTACK(1); # discard Closure
unwind(); # unwind EVAL-Frame
return; # finished
}
# Gathered errormessages:
fehler_zuwenig: # Argument-list args is prematurely an Atom
if (!nullp(args)) goto fehler_dotted;
setSTACK(STACK = STACKbefore); # clean up STACK
closure = popSTACK();
fehler_eval_zuwenig(Closure_name(closure));
fehler_zuviel: # Argument-list args is not NIL at the end
if (atomp(args)) goto fehler_dotted;
setSTACK(STACK = STACKbefore); # clean up STACK
closure = popSTACK();
fehler_eval_zuviel(Closure_name(closure));
fehler_dotted: # Argument-list args ends with Atom /= NIL
setSTACK(STACK = STACKbefore); # clean up STACK
closure = popSTACK();
fehler_eval_dotted(Closure_name(closure));
}
#ifdef DYNAMIC_FFI
# In EVAL: Applies a Foreign-Function to an argument-list,
# cleans up STACK and returns the values.
# eval_ffunction(fun);
# > fun: function, a Foreign-Function
# > STACK-layout: EVAL-Frame, *APPLYHOOK*, argument-list.
# < STACK: cleaned up
# < mv_count/mv_space: values
# changes STACK
# can trigger GC
local maygc Values eval_ffunction(object ffun) {
var object args = popSTACK(); # Argument-list
skipSTACK(1); # skip value of *APPLYHOOK*
# STACK-layout: EVAL-Frame.
# (ffun arg ...) --> (FFI::FOREIGN-CALL-OUT ffun arg ...)
check_SP(); check_STACK();
pushSTACK(ffun); # Foreign-Function as 1. Argument
{
var gcv_object_t* args_pointer = args_end_pointer; # Pointer to the arguments
var uintC args_on_stack = 1; # number of arguments
while (consp(args)) {
pushSTACK(Cdr(args)); # save list-rest
eval(Car(args)); # evaluate next element
args = STACK_0; STACK_0 = value1; # result into STACK
args_on_stack += 1;
if (((uintL)~(uintL)0 > ca_limit_1) && (args_on_stack > ca_limit_1)) {
set_args_end_pointer(args_pointer);
fehler_eval_zuviel(popSTACK());
}
}
funcall(L(foreign_call_out),args_on_stack);
}
unwind(); # unwind EVAL-Frame
return; # finished
}
#endif
# ----------------------- A P P L Y -----------------------
# later:
local Values apply_subr (object fun, uintC args_on_stack, object other_args);
local Values apply_closure(object fun, uintC args_on_stack, object other_args);
/* UP: Applies a function to its arguments.
apply(function,args_on_stack,other_args);
> function: function
> arguments: args_on_stack arguments on the STACK,
remaining argument-list in other_args
< STACK: cleaned up (i.e. STACK is increased by args_on_stack)
< mv_count/mv_space: values
changes STACK, can trigger GC */
global maygc Values apply (object fun, uintC args_on_stack, object other_args)
{
apply_restart:
/* fun must be a SUBR or a Closure or a Cons (LAMBDA ...) : */
if (subrp(fun)) { /* SUBR ? */
return_Values apply_subr(fun,args_on_stack,other_args);
} else if (closurep(fun)) { /* Closure ? */
return_Values apply_closure(fun,args_on_stack,other_args);
} else if (symbolp(fun)) { /* Symbol ? */
/* apply Symbol: global Definition Symbol_function(fun) applies. */
var object fdef = Symbol_function(fun);
if (subrp(fdef)) { /* SUBR -> apply */
return_Values apply_subr(fdef,args_on_stack,other_args);
} else if (closurep(fdef)) { /* Closure -> apply */
return_Values apply_closure(fdef,args_on_stack,other_args);
} else if (orecordp(fdef)) {
#ifdef DYNAMIC_FFI
if (ffunctionp(fdef)) { /* Foreign-Function ? */
fun = fdef; goto call_ffunction;
}
#endif
switch (Record_type(fdef)) {
case Rectype_Fsubr:
fehler_specialform(S(apply),fun);
case Rectype_Macro:
fehler_macro(S(apply),fun);
default: NOTREACHED;
}
} else
/* if no SUBR, no Closure, no FSUBR, no Macro:
Symbol_function(fun) must be #<UNBOUND> . */
goto undef;
} else if (funnamep(fun)) { /* List (SETF symbol) ? */
/* global Definition (symbol-function (get-setf-symbol symbol)) applies. */
var object symbol = get(Car(Cdr(fun)),S(setf_function)); /* (get ... 'SYS::SETF-FUNCTION) */
if (!symbolp(symbol)) /* should be (uninterned) Symbol */
goto undef; /* else undefined */
var object fdef = Symbol_function(symbol);
if (closurep(fdef)) { /* Closure -> apply */
return_Values apply_closure(fdef,args_on_stack,other_args);
} else if (subrp(fdef)) { /* SUBR -> apply */
return_Values apply_subr(fdef,args_on_stack,other_args);
}
#ifdef DYNAMIC_FFI
else if (ffunctionp(fdef)) { /* Foreign-Function ? */
fun = fdef; goto call_ffunction;
}
#endif
else
/* Such function-names cannot denote FSUBRs or Macros.
fdef is presumably #<UNBOUND> . */
goto undef;
}
#ifdef DYNAMIC_FFI
else if (ffunctionp(fun)) /* Foreign-Function ? */
call_ffunction: { /* call (SYS::FOREIGN-CALL-OUT foreign-function . args) */
/* Therefore first shift down the arguments in Stack by 1. */
var uintC count;
var gcv_object_t* ptr = &STACK_0;
dotimesC(count,args_on_stack, {
*(ptr STACKop -1) = *ptr; ptr skipSTACKop 1;
});
*(ptr STACKop -1) = fun;
skipSTACK(-1);
return_Values apply_subr(L(foreign_call_out),args_on_stack+1,other_args);
}
#endif
else if (consp(fun) && eq(Car(fun),S(lambda))) /* Cons (LAMBDA ...) ? */
fehler_lambda_expression(S(apply),fun);
else {
pushSTACK(other_args);
fun = check_funname_replacement(type_error,S(apply),fun);
other_args = popSTACK();
goto apply_restart;
}
return;
undef:
pushSTACK(other_args);
fun = check_fdefinition(fun,S(apply));
other_args = popSTACK();
goto apply_restart;
}
# Error because of dotted argument-list
# > name: name of function
nonreturning_function(local, fehler_apply_dotted, (object name, object end)) {
pushSTACK(end);
pushSTACK(name);
pushSTACK(S(apply));
fehler(program_error,GETTEXT("~S: argument list given to ~S is dotted (terminated by ~S)"));
}
# Error because of too many arguments
# > name: name of function
nonreturning_function(local, fehler_apply_zuviel, (object name)) {
pushSTACK(name);
/* ANSI CL 3.5.1.3. wants a PROGRAM-ERROR here. */
fehler(program_error,GETTEXT("APPLY: too many arguments given to ~S"));
}
# Error because of too few arguments
# > name: name of function
# > tail: atom at the end of the argument list
nonreturning_function(local, fehler_apply_zuwenig, (object name, object tail)) {
if (!nullp(tail)) {
pushSTACK(tail); /* ARGUMENT-LIST-DOTTED slot DATUM */
pushSTACK(tail); pushSTACK(name);
fehler(argument_list_dotted,
GETTEXT("APPLY: dotted argument list given to ~S : ~S"));
} else {
pushSTACK(name);
/* ANSI CL 3.5.1.2. wants a PROGRAM-ERROR here. */
fehler(program_error,GETTEXT("APPLY: too few arguments given to ~S"));
}
}
# Error because of too many arguments for a SUBR
# > fun: function, a SUBR
nonreturning_function(local, fehler_subr_zuviel, (object fun));
#define fehler_subr_zuviel(fun) fehler_apply_zuviel(TheSubr(fun)->name)
# Error because of too few arguments for a SUBR
# > fun: function, a SUBR
# > tail: atom at the end of the argument list
nonreturning_function(local, fehler_subr_zuwenig, (object fun, object tail));
#define fehler_subr_zuwenig(fun,tail) \
fehler_apply_zuwenig(TheSubr(fun)->name,tail)
# In APPLY: Applies a SUBR to an argument-list, cleans up STACK
# and returns the values.
# apply_subr(fun,args_on_stack,other_args);
# > fun: function, a SUBR
# > Arguments: args_on_stack Arguments on STACK,
# remaining argument-list in other_args
# < STACK: cleaned up (i.e. STACK is increased by args_on_stack)
# < mv_count/mv_space: values
# changes STACK, can trigger GC
local maygc Values apply_subr (object fun, uintC args_on_stack, object args)
{
#if STACKCHECKS
var gcv_object_t* args_pointer = args_end_pointer STACKop args_on_stack; # Pointer to the arguments
#endif
var gcv_object_t* key_args_pointer; # Pointer to the Keyword-Arguments
var gcv_object_t* rest_args_pointer; # Pointer to the remaining Arguments
var uintL argcount; # number of remaining Arguments
TRACE_CALL(fun,'A','S');
# push Arguments on STACK:
# first a Dispatch for the most important cases:
switch (TheSubr(fun)->argtype) {
# Macro for a required-Argument:
#define REQ_ARG() \
{ if (args_on_stack>0) { args_on_stack--; } \
elif (consp(args)) { pushSTACK(Car(args)); args = Cdr(args); } \
else goto fehler_zuwenig; \
}
# Macro for the n-last optional-Argument:
#define OPT_ARG(n) \
{ if (args_on_stack>0) { args_on_stack--; } \
elif (consp(args)) { pushSTACK(Car(args)); args = Cdr(args); } \
else goto unbound_optional_##n; \
}
case (uintW)subr_argtype_6_0:
# SUBR with 6 required-Arguments
REQ_ARG();
case (uintW)subr_argtype_5_0:
# SUBR with 5 required-Arguments
REQ_ARG();
case (uintW)subr_argtype_4_0:
# SUBR with 4 required-Arguments
REQ_ARG();
case (uintW)subr_argtype_3_0:
# SUBR with 3 required-Arguments
REQ_ARG();
case (uintW)subr_argtype_2_0:
# SUBR with 2 required-Arguments
REQ_ARG();
case (uintW)subr_argtype_1_0:
# SUBR with 1 required-Argument
REQ_ARG();
case (uintW)subr_argtype_0_0:
# SUBR without Arguments
if ((args_on_stack>0) || consp(args)) goto fehler_zuviel;
goto apply_subr_norest;
case (uintW)subr_argtype_4_1:
# SUBR with 4 required-Arguments and 1 optional-Argument
REQ_ARG();
case (uintW)subr_argtype_3_1:
# SUBR with 3 required-Arguments and 1 optional-Argument
REQ_ARG();
case (uintW)subr_argtype_2_1:
# SUBR with 2 required-Arguments and 1 optional-Argument
REQ_ARG();
case (uintW)subr_argtype_1_1:
# SUBR with 1 required-Argument and 1 optional-Argument
REQ_ARG();
case (uintW)subr_argtype_0_1:
# SUBR with 1 optional-Argument
OPT_ARG(1);
if ((args_on_stack>0) || consp(args)) goto fehler_zuviel;
goto apply_subr_norest;
case (uintW)subr_argtype_3_2:
# SUBR with 3 required-Arguments and 2 optional-Arguments
REQ_ARG();
case (uintW)subr_argtype_2_2:
# SUBR with 2 required-Arguments and 2 optional-Arguments
REQ_ARG();
case (uintW)subr_argtype_1_2:
# SUBR with 1 required-Argument and 2 optional-Arguments
REQ_ARG();
case (uintW)subr_argtype_0_2:
# SUBR with 2 optional-Arguments
OPT_ARG(2);
OPT_ARG(1);
if ((args_on_stack>0) || consp(args)) goto fehler_zuviel;
goto apply_subr_norest;
case (uintW)subr_argtype_2_3:
# SUBR with 2 required-Arguments and 3 optional-Arguments
REQ_ARG();
case (uintW)subr_argtype_1_3:
# SUBR with 1 required-Argument and 3 optional-Arguments
REQ_ARG();
case (uintW)subr_argtype_0_3:
# SUBR with 3 optional-Arguments
OPT_ARG(3);
OPT_ARG(2);
OPT_ARG(1);
if ((args_on_stack>0) || consp(args)) goto fehler_zuviel;
goto apply_subr_norest;
case (uintW)subr_argtype_0_5:
# SUBR with 5 optional-Arguments
OPT_ARG(5);
case (uintW)subr_argtype_0_4:
# SUBR with 4 optional-Arguments
OPT_ARG(4);
OPT_ARG(3);
OPT_ARG(2);
OPT_ARG(1);
if ((args_on_stack>0) || consp(args)) goto fehler_zuviel;
goto apply_subr_norest;
unbound_optional_5: # Still 5 optional Arguments, but args_on_stack=0 and atomp(args)
pushSTACK(unbound);
unbound_optional_4: # Still 4 optional Arguments, but args_on_stack=0 and atomp(args)
pushSTACK(unbound);
unbound_optional_3: # Still 3 optional Arguments, but args_on_stack=0 and atomp(args)
pushSTACK(unbound);
unbound_optional_2: # Still 2 optional Arguments, but args_on_stack=0 and atomp(args)
pushSTACK(unbound);
unbound_optional_1: # Still 1 optionals Argument, but args_on_stack=0 and atomp(args)
pushSTACK(unbound);
goto apply_subr_norest;
case (uintW)subr_argtype_3_0_rest:
# SUBR with 3 required-Arguments and further Arguments
REQ_ARG();
case (uintW)subr_argtype_2_0_rest:
# SUBR with 2 required-Arguments and further Arguments
REQ_ARG();
case (uintW)subr_argtype_1_0_rest:
# SUBR with 1 required-Argument and further Arguments
REQ_ARG();
case (uintW)subr_argtype_0_0_rest:
# SUBR with further Arguments
if (args_on_stack==0)
goto apply_subr_rest_onlylist;
else
goto apply_subr_rest_withlist;
case (uintW)subr_argtype_4_0_key:
# SUBR with 4 required-Arguments and Keyword-Arguments
REQ_ARG();
case (uintW)subr_argtype_3_0_key:
# SUBR with 3 required-Arguments and Keyword-Arguments
REQ_ARG();
case (uintW)subr_argtype_2_0_key:
# SUBR with 2 required-Arguments and Keyword-Arguments
REQ_ARG();
case (uintW)subr_argtype_1_0_key:
# SUBR with 1 required-Argument and Keyword-Arguments
REQ_ARG();
case (uintW)subr_argtype_0_0_key:
# SUBR with Keyword-Arguments
if ((args_on_stack==0) && atomp(args)) goto unbound_optional_key_0;
goto apply_subr_key;
case (uintW)subr_argtype_1_1_key:
# SUBR with 1 required-Argument, 1 optional-Argument and Keyword-Arguments
REQ_ARG();
case (uintW)subr_argtype_0_1_key:
# SUBR with 1 optional-Argument and Keyword-Arguments
OPT_ARG(key_1);
if ((args_on_stack==0) && atomp(args)) goto unbound_optional_key_0;
goto apply_subr_key;
case (uintW)subr_argtype_1_2_key:
# SUBR with 1 required-Argument, 2 optional-Arguments and Keyword-Arguments
REQ_ARG();
OPT_ARG(key_2);
OPT_ARG(key_1);
if ((args_on_stack==0) && atomp(args)) goto unbound_optional_key_0;
goto apply_subr_key;
unbound_optional_key_2: # Still 2 optional Arguments, but args_on_stack=0 and atomp(args)
pushSTACK(unbound);
unbound_optional_key_1: # Still 1 optional Argument, but args_on_stack=0 and atomp(args)
pushSTACK(unbound);
unbound_optional_key_0: # Before the Keywords is args_on_stack=0 and atomp(args)
{
var uintC count;
dotimesC(count,TheSubr(fun)->key_anz, { pushSTACK(unbound); } );
}
goto apply_subr_norest;
default: NOTREACHED;
#undef OPT_ARG
#undef REQ_ARG
}
# Now the general Version:
{
var uintC key_anz;
{
var uintC req_anz = TheSubr(fun)->req_anz;
var uintC opt_anz = TheSubr(fun)->opt_anz;
key_anz = TheSubr(fun)->key_anz;
if (args_on_stack < req_anz) {
# fewer Arguments there than demanded
req_anz = req_anz - args_on_stack; # as many as these must go on STACK
# reserve space on STACK:
get_space_on_STACK(sizeof(gcv_object_t) * (uintL)(req_anz + opt_anz + key_anz));
# store required Parameter in Stack:
{
var uintC count;
dotimespC(count,req_anz, {
if (atomp(args))
goto fehler_zuwenig;
pushSTACK(Car(args)); # store next Argument
args = Cdr(args);
});
}
goto optionals_from_list;
}
args_on_stack -= req_anz; # remaining number
if (args_on_stack < opt_anz) {
# Arguments in Stack don't last for the optional ones
opt_anz = opt_anz - args_on_stack; # as many as these must go on STACK
# reserve space on STACK:
get_space_on_STACK(sizeof(gcv_object_t) * (uintL)(opt_anz + key_anz));
optionals_from_list:
{ /* store optional Parameters on Stack: */
var uintC count = opt_anz;
while (!atomp(args)) { /* argument-list not finished? */
if (count==0) # all optional Parameters supplied with?
goto optionals_ok;
count--;
pushSTACK(Car(args)); # store next Argument
args = Cdr(args);
}
# Argument-list finished.
# All further count optional Parameters receive the "value"
# #<UNBOUND>, including the Keyword-Parameters:
dotimesC(count,count + key_anz, { pushSTACK(unbound); } );
if (TheSubr(fun)->rest_flag == subr_rest) { # &REST-Flag?
# yes -> 0 additional Arguments:
argcount = 0; rest_args_pointer = args_end_pointer;
goto apply_subr_rest;
} else {
# no -> nothing to do
goto apply_subr_norest;
}
}
optionals_ok: # optional Argument OK, continue processing (non-empty) list
if (TheSubr(fun)->key_flag == subr_nokey) {
# SUBR without KEY
if (TheSubr(fun)->rest_flag == subr_norest)
# SUBR without REST or KEY
fehler_subr_zuviel(fun); # too many Arguments
else
# SUBR with only REST, without KEY
goto apply_subr_rest_onlylist;
} else {
# SUBR with KEY
key_args_pointer = args_end_pointer;
{
var uintC count;
dotimesC(count,key_anz, { pushSTACK(unbound); } );
}
rest_args_pointer = args_end_pointer;
argcount = 0;
goto key_from_list;
}
}
args_on_stack -= opt_anz; # remaining number
if (TheSubr(fun)->key_flag == subr_nokey) {
# SUBR without KEY
if (TheSubr(fun)->rest_flag == subr_norest) {
# SUBR without REST or KEY
if ((args_on_stack>0) || consp(args)) # still Arguments?
fehler_subr_zuviel(fun);
goto apply_subr_norest;
} else
# SUBR with only REST, without KEY
goto apply_subr_rest_withlist;
} else
# SUBR with Keywords.
goto apply_subr_key_;
}
apply_subr_key:
key_anz = TheSubr(fun)->key_anz;
apply_subr_key_:
# shift down remaining Arguments on STACK and thus
# create room for the Keyword-Parameters:
argcount = args_on_stack;
get_space_on_STACK(sizeof(gcv_object_t) * (uintL)key_anz);
{
var gcv_object_t* new_args_end_pointer = args_end_pointer STACKop -(uintP)key_anz;
var gcv_object_t* ptr1 = args_end_pointer;
var gcv_object_t* ptr2 = new_args_end_pointer;
var uintC count;
dotimesC(count,args_on_stack, { BEFORE(ptr2) = BEFORE(ptr1); } );
key_args_pointer = ptr1;
rest_args_pointer = ptr2;
dotimesC(count,key_anz, { NEXT(ptr1) = unbound; } );
set_args_end_pointer(new_args_end_pointer);
}
key_from_list: # take remaining Arguments for Keywords from list
while (consp(args)) {
check_STACK(); pushSTACK(Car(args)); # push next argument onto Stack
args = Cdr(args);
argcount++;
}
# assign Keywords and poss. discard remaining arguments:
match_subr_key(fun,argcount,key_args_pointer,rest_args_pointer);
if (TheSubr(fun)->rest_flag != subr_norest)
# SUBR with &REST-Flag:
goto apply_subr_rest;
else
# SUBR without &REST-Flag:
goto apply_subr_norest;
}
apply_subr_rest_onlylist:
argcount = 0; rest_args_pointer = args_end_pointer;
goto rest_from_list;
apply_subr_rest_withlist:
argcount = args_on_stack;
rest_args_pointer = args_end_pointer STACKop argcount;
rest_from_list: # take remaining Arguments from list
while (consp(args)) {
check_STACK(); pushSTACK(Car(args)); # next argument onto Stack
args = Cdr(args);
argcount++;
}
if (((uintL)~(uintL)0 > ca_limit_1) && (argcount > ca_limit_1)) # too many arguments?
goto fehler_zuviel;
apply_subr_rest:
if (!nullp(args))
goto fehler_dotted;
with_saved_back_trace_subr(fun,STACK,
TheSubr(fun)->req_anz + TheSubr(fun)->opt_anz + argcount,
(*(subr_rest_function_t*)(TheSubr(fun)->function))(argcount,rest_args_pointer); );
goto done;
apply_subr_norest:
if (!nullp(args))
goto fehler_dotted;
with_saved_back_trace_subr(fun,STACK,-1,
(*(subr_norest_function_t*)(TheSubr(fun)->function))(); );
done:
#if STACKCHECKS
if (!(args_pointer == args_end_pointer)) # Stack cleaned up?
abort(); # no -> go to Debugger
#endif
return; # finished
# gathered error messages:
fehler_zuwenig: fehler_subr_zuwenig(fun,args);
fehler_zuviel: fehler_subr_zuviel(fun);
fehler_dotted: fehler_apply_dotted(TheSubr(fun)->name,args);
}
# Error because of too many arguments for a Closure
# > closure: function, a Closure
nonreturning_function(local, fehler_closure_zuviel, (object closure));
#define fehler_closure_zuviel(closure) fehler_apply_zuviel(closure)
# Error because of too few arguments for a Closure
# > closure: function, a Closure
# > tail: atom at the end of the argument list
nonreturning_function(local, fehler_closure_zuwenig, (object closure, object tail));
#define fehler_closure_zuwenig(closure,tail) fehler_apply_zuwenig(closure,tail)
# In APPLY: Applies a Closure to an argument-list, cleans up STACK
# and returns the values.
# apply_closure(fun,args_on_stack,other_args);
# > fun: function, a Closure
# > Argumente: args_on_stack arguments on STACK,
# remaining argument-list in other_args
# < STACK: cleaned up (i.e. STACK is increased by args_on_stack)
# < mv_count/mv_space: values
# changes STACK, can trigger GC
local maygc Values apply_closure (object closure, uintC args_on_stack, object args)
{
TRACE_CALL(closure,'A','C');
if (simple_bit_vector_p(Atype_8Bit,TheClosure(closure)->clos_codevec)) {
# closure is a compiled Closure
#if STACKCHECKC
var gcv_object_t* args_pointer = args_end_pointer STACKop args_on_stack; # Pointer to the arguments
#endif
var object codevec = TheCclosure(closure)->clos_codevec; # Code-Vector
var gcv_object_t* key_args_pointer; # Pointer to the Keyword-arguments
var gcv_object_t* rest_args_pointer; # Pointer to the remaining arguments
var uintL argcount; # number of remaining arguments
check_SP(); check_STACK();
# put argumente in STACK:
# first a Dispatch for the most important cases:
switch (TheCodevec(codevec)->ccv_signature) {
# Macro for a required-argument:
#define REQ_ARG() \
{ if (args_on_stack>0) { args_on_stack--; } \
elif (consp(args)) { pushSTACK(Car(args)); args = Cdr(args); } \
else goto fehler_zuwenig; \
}
# Macro for the n-last optional-argument:
#define OPT_ARG(n) \
{ if (args_on_stack>0) { args_on_stack--; } \
elif (consp(args)) { pushSTACK(Car(args)); args = Cdr(args); } \
else goto unbound_optional_##n; \
}
case (uintB)cclos_argtype_5_0:
# 5 required-Arguments
REQ_ARG();
case (uintB)cclos_argtype_4_0:
# 4 required-Arguments
REQ_ARG();
case (uintB)cclos_argtype_3_0:
# 3 required-Arguments
REQ_ARG();
case (uintB)cclos_argtype_2_0:
# 2 required-Arguments
REQ_ARG();
case (uintB)cclos_argtype_1_0:
# 1 required-Argument
REQ_ARG();
case (uintB)cclos_argtype_0_0:
# no Arguments
noch_0_opt_args:
if (args_on_stack>0) goto fehler_zuviel;
if (!nullp(args)) {
if (consp(args))
goto fehler_zuviel;
else
goto fehler_dotted;
}
goto apply_cclosure_nokey;
case (uintB)cclos_argtype_4_1:
# 4 required-Arguments and 1 optional-Argument
REQ_ARG();
case (uintB)cclos_argtype_3_1:
# 3 required-Arguments and 1 optional-Argument
REQ_ARG();
case (uintB)cclos_argtype_2_1:
# 2 required-Arguments and 1 optional-Argument
REQ_ARG();
case (uintB)cclos_argtype_1_1:
# 1 required-Argument and 1 optional-Argument
REQ_ARG();
case (uintB)cclos_argtype_0_1:
# 1 optional-Argument
noch_1_opt_args:
OPT_ARG(1);
goto noch_0_opt_args;
case (uintB)cclos_argtype_3_2:
# 3 required-Arguments and 2 optional-Arguments
REQ_ARG();
case (uintB)cclos_argtype_2_2:
# 2 required-Arguments and 2 optional-Arguments
REQ_ARG();
case (uintB)cclos_argtype_1_2:
# 1 required-Argument and 2 optional-Arguments
REQ_ARG();
case (uintB)cclos_argtype_0_2:
# 2 optional-Arguments
noch_2_opt_args:
OPT_ARG(2);
goto noch_1_opt_args;
case (uintB)cclos_argtype_2_3:
# 2 required-Arguments and 3 optional-Arguments
REQ_ARG();
case (uintB)cclos_argtype_1_3:
# 1 required-Argument and 3 optional-Arguments
REQ_ARG();
case (uintB)cclos_argtype_0_3:
# 3 optional-Arguments
noch_3_opt_args:
OPT_ARG(3);
goto noch_2_opt_args;
case (uintB)cclos_argtype_1_4:
# 1 required-Argument and 4 optional-Arguments
REQ_ARG();
case (uintB)cclos_argtype_0_4:
# 4 optional-Arguments
noch_4_opt_args:
OPT_ARG(4);
goto noch_3_opt_args;
case (uintB)cclos_argtype_0_5:
# 5 optional-Arguments
OPT_ARG(5);
goto noch_4_opt_args;
unbound_optional_5: # Still 5 optional Arguments, but args_on_stack=0 and atomp(args)
pushSTACK(unbound);
unbound_optional_4: # Still 4 optional Arguments, but args_on_stack=0 and atomp(args)
pushSTACK(unbound);
unbound_optional_3: # Still 3 optional Arguments, but args_on_stack=0 and atomp(args)
pushSTACK(unbound);
unbound_optional_2: # Still 2 optional Arguments, but args_on_stack=0 and atomp(args)
pushSTACK(unbound);
unbound_optional_1: # Still 1 optional Argument, but args_on_stack=0 and atomp(args)
pushSTACK(unbound);
if (!nullp(args)) goto fehler_dotted;
goto apply_cclosure_nokey;
case (uintB)cclos_argtype_4_0_rest:
# 4 required-Arguments, Rest-Parameter
REQ_ARG();
case (uintB)cclos_argtype_3_0_rest:
# 3 required-Arguments, Rest-Parameter
REQ_ARG();
case (uintB)cclos_argtype_2_0_rest:
# 2 required-Arguments, Rest-Parameter
REQ_ARG();
case (uintB)cclos_argtype_1_0_rest:
# 1 required-Argument, Rest-Parameter
REQ_ARG();
case (uintB)cclos_argtype_0_0_rest:
# no Arguments, Rest-Parameter
goto apply_cclosure_rest_nokey;
case (uintB)cclos_argtype_4_0_key:
# 4 required-Arguments, Keyword-Arguments
REQ_ARG();
case (uintB)cclos_argtype_3_0_key:
# 3 required-Arguments, Keyword-Arguments
REQ_ARG();
case (uintB)cclos_argtype_2_0_key:
# 2 required-Arguments, Keyword-Arguments
REQ_ARG();
case (uintB)cclos_argtype_1_0_key:
# 1 required-Argument, Keyword-Arguments
REQ_ARG();
noch_0_opt_args_key:
case (uintB)cclos_argtype_0_0_key:
# only Keyword-Arguments
if ((args_on_stack==0) && atomp(args)) goto unbound_optional_key_0;
goto apply_cclosure_key_withlist;
case (uintB)cclos_argtype_3_1_key:
# 3 required-Arguments and 1 optional-Argument, Keyword-Arguments
REQ_ARG();
case (uintB)cclos_argtype_2_1_key:
# 2 required-Arguments and 1 optional-Argument, Keyword-Arguments
REQ_ARG();
case (uintB)cclos_argtype_1_1_key:
# 1 required-Argument and 1 optional-Argument, Keyword-Arguments
REQ_ARG();
case (uintB)cclos_argtype_0_1_key:
# 1 optional-Argument, Keyword-Arguments
noch_1_opt_args_key:
OPT_ARG(key_1);
goto noch_0_opt_args_key;
case (uintB)cclos_argtype_2_2_key:
# 2 required-Arguments and 2 optional-Arguments, Keyword-Arguments
REQ_ARG();
case (uintB)cclos_argtype_1_2_key:
# 1 required-Argument and 2 optional-Arguments, Keyword-Arguments
REQ_ARG();
case (uintB)cclos_argtype_0_2_key:
# 2 optional-Arguments, Keyword-Arguments
noch_2_opt_args_key:
OPT_ARG(key_2);
goto noch_1_opt_args_key;
case (uintB)cclos_argtype_1_3_key:
# 1 required-Argument and 3 optional-Arguments, Keyword-Arguments
REQ_ARG();
case (uintB)cclos_argtype_0_3_key:
# 3 optional-Arguments, Keyword-Arguments
noch_3_opt_args_key:
OPT_ARG(key_3);
goto noch_2_opt_args_key;
case (uintB)cclos_argtype_0_4_key:
# 4 optional-Arguments, Keyword-Arguments
OPT_ARG(key_4);
goto noch_3_opt_args_key;
unbound_optional_key_4: # Still 4 optional Arguments, but args_on_stack=0 and atomp(args)
pushSTACK(unbound);
unbound_optional_key_3: # Still 3 optional Arguments, but args_on_stack=0 and atomp(args)
pushSTACK(unbound);
unbound_optional_key_2: # Still 2 optional Arguments, but args_on_stack=0 and atomp(args)
pushSTACK(unbound);
unbound_optional_key_1: # Still 1 optional Argument, but args_on_stack=0 and atomp(args)
pushSTACK(unbound);
unbound_optional_key_0: # Before the Keywords is args_on_stack=0 and atomp(args)
if (!nullp(args)) goto fehler_dotted;
goto apply_cclosure_key_noargs;
case (uintB)cclos_argtype_default:
# General Version
break;
default: NOTREACHED;
#undef OPT_ARG
#undef REQ_ARG
}
# Now the general Version:
{
var uintB flags;
{
var uintC req_anz = TheCodevec(codevec)->ccv_numreq; # number of required Parameters
var uintC opt_anz = TheCodevec(codevec)->ccv_numopt; # number of optional Parameters
flags = TheCodevec(codevec)->ccv_flags; # Flags
if (args_on_stack < req_anz) {
# fewer Arguments than demanded
req_anz = req_anz - args_on_stack; # as many as these must on STACK
# reserve space on STACK:
get_space_on_STACK(sizeof(gcv_object_t) * (uintL)(req_anz + opt_anz));
# store required Parameters on Stack:
{
var uintC count;
dotimespC(count,req_anz, {
if (atomp(args))
goto fehler_zuwenig;
pushSTACK(Car(args)); # store next argument
args = Cdr(args);
});
}
goto optionals_from_list;
}
args_on_stack -= req_anz; # remaining number
if (args_on_stack < opt_anz) {
# Argumente in Stack don't last for the optional ones
opt_anz = opt_anz - args_on_stack; # as many as these must go on STACK
# reserve space on STACK:
get_space_on_STACK(sizeof(gcv_object_t) * (uintL)opt_anz);
optionals_from_list:
{ /* store optional parameters on Stack: */
var uintC count = opt_anz;
while (!atomp(args)) { /* argument-list not finished? */
if (count==0) # all optional parameters supplied with?
goto optionals_ok;
count--;
pushSTACK(Car(args)); # store next argument
args = Cdr(args);
}
# argument-list finished.
if (!nullp(args)) goto fehler_dotted;
# All further count optional parameters receive the "value"
# #<UNBOUND>, the &REST-parameter receives NIL,
# the Keyword-parameters receive the value #<UNBOUND> :
dotimesC(count,count, { pushSTACK(unbound); } );
}
if (flags & bit(0)) # &REST-Flag?
pushSTACK(NIL); # yes -> initialize with NIL
if (flags & bit(7)) # &KEY-Flag?
goto apply_cclosure_key_noargs;
else
goto apply_cclosure_nokey;
optionals_ok:
# process Rest- and Keyword-parameters.
# args = remaining argument-list (not yet finished)
if (flags == 0)
# Closure without REST or KEY -> argument-list should be finished
goto fehler_zuviel;
# poss. fill the Rest-parameter:
if (flags & bit(0))
pushSTACK(args);
if (flags & bit(7)) { # Key-Flag?
# Closure with Keywords.
# args = remaining argument-list (not yet finished)
# First initialize the Keyword-parameters with #<UNBOUND> ,
# the store the remaining arguments in Stack,
# then assign the Keywords:
key_args_pointer = args_end_pointer; # Pointer to the Keyword-parameters
# initialize all Keyword-parameters with #<UNBOUND> :
{
var uintC count = TheCodevec(codevec)->ccv_numkey;
dotimesC(count,count, { pushSTACK(unbound); } );
}
rest_args_pointer = args_end_pointer; # Pointer to the remaining arguments
argcount = 0; # counter for the remaining arguments
goto key_from_list;
} else
# Closure with only REST, without KEY:
goto apply_cclosure_nokey;
}
args_on_stack -= opt_anz; # remaining number
if (flags & bit(7)) # Key-Flag?
goto apply_cclosure_key_withlist_;
elif (flags & bit(0))
goto apply_cclosure_rest_nokey;
else {
# Closure without REST or KEY
if ((args_on_stack>0) || consp(args)) # still arguments?
goto fehler_zuviel;
goto apply_cclosure_nokey;
}
}
apply_cclosure_key_noargs:
{
var uintC key_anz = TheCodevec(codevec)->ccv_numkey; # number of Keyword-parameters
if (key_anz > 0) {
get_space_on_STACK(sizeof(gcv_object_t) * (uintL)key_anz);
var uintC count;
dotimespC(count,key_anz, { pushSTACK(unbound); } ); # initialize with #<UNBOUND>
}
goto apply_cclosure_key;
}
apply_cclosure_key_withlist:
flags = TheCodevec(codevec)->ccv_flags; # initialize flags!
apply_cclosure_key_withlist_:
# Closure with Keywords
{
var uintC key_anz = TheCodevec(codevec)->ccv_numkey; # number of Keyword-parameters
# shift down remaining arguments in STACK and thus
# create room for the Keyword-parameters
# (and poss. Rest-parameters):
var uintL shift = key_anz;
if (flags & bit(0))
shift++; # poss. 1 more for Rest-Parameter
argcount = args_on_stack;
get_space_on_STACK(sizeof(gcv_object_t) * shift);
var gcv_object_t* new_args_end_pointer = args_end_pointer STACKop -(uintP)shift;
var gcv_object_t* ptr1 = args_end_pointer;
var gcv_object_t* ptr2 = new_args_end_pointer;
var uintC count;
dotimesC(count,args_on_stack, { BEFORE(ptr2) = BEFORE(ptr1); } );
if (flags & bit(0))
NEXT(ptr1) = args; # Rest-Parameter (preliminary)
key_args_pointer = ptr1;
rest_args_pointer = ptr2;
dotimesC(count,key_anz, { NEXT(ptr1) = unbound; } );
set_args_end_pointer(new_args_end_pointer);
if (flags & bit(0))
# fill Rest-Parameter, less effort than with match_cclosure_key:
if (args_on_stack > 0) {
var gcv_object_t* ptr3 = new_args_end_pointer;
pushSTACK(closure); # save Closure
pushSTACK(args); # save args
dotimespC(count,args_on_stack, {
var object new_cons = allocate_cons();
Car(new_cons) = BEFORE(ptr3);
Cdr(new_cons) = Before(key_args_pointer);
Before(key_args_pointer) = new_cons;
});
args = popSTACK();
closure = popSTACK();
}
}
key_from_list: # remove remaining arguments for Keywords from list
while (consp(args)) {
check_STACK(); pushSTACK(Car(args)); # store next argument in Stack
args = Cdr(args);
argcount++;
}
# argument-list finished.
if (!nullp(args)) goto fehler_dotted;
# assign Keywords, build Rest-parameter
# and poss. discard remaining arguments:
closure = match_cclosure_key(closure,argcount,key_args_pointer,rest_args_pointer);
codevec = TheCclosure(closure)->clos_codevec;
apply_cclosure_key:
interpret_bytecode(closure,codevec,CCV_START_KEY); # process Bytecode starting at Byte 12
goto done;
}
apply_cclosure_rest_nokey:
# Closure with only REST, without KEY:
# still has to cons args_on_stack Arguments from Stack to args:
pushSTACK(args);
if (args_on_stack > 0) {
pushSTACK(closure); # Closure must be saved
dotimespC(args_on_stack,args_on_stack, {
var object new_cons = allocate_cons();
Cdr(new_cons) = STACK_1;
Car(new_cons) = STACK_2; # cons next argument to it
STACK_2 = new_cons;
STACK_1 = STACK_0; skipSTACK(1);
});
closure = popSTACK(); codevec = TheCclosure(closure)->clos_codevec;
}
goto apply_cclosure_nokey;
apply_cclosure_nokey: # jump to Closure without &KEY:
interpret_bytecode(closure,codevec,CCV_START_NONKEY); # process Bytecode starting at Byte 8
done:
#if STACKCHECKC
if (!(args_pointer == args_end_pointer)) # Stack cleaned up?
abort(); # no -> go to Debugger
#endif
return; # finished
} else {
# closure is an interpreted Closure
# reserve space on STACK:
get_space_on_STACK(sizeof(gcv_object_t) * llength(args));
while (consp(args)) { # Still Arguments in list?
pushSTACK(Car(args)); # push next Element in STACK
args = Cdr(args);
args_on_stack += 1;
if (((uintL)~(uintL)0 > ca_limit_1) && (args_on_stack > ca_limit_1))
goto fehler_zuviel;
}
var gcv_object_t* args_pointer = args_end_pointer STACKop args_on_stack;
with_saved_back_trace_iclosure(closure,args_pointer,args_on_stack,
funcall_iclosure(closure,args_pointer,args_on_stack); );
return; # finished
}
# Gathered error-messages:
fehler_zuwenig: fehler_closure_zuwenig(closure,args);
fehler_zuviel: fehler_closure_zuviel(closure);
fehler_dotted: fehler_apply_dotted(closure,args);
}
# ----------------------- F U N C A L L -----------------------
# later:
local Values funcall_subr (object fun, uintC args_on_stack);
local Values funcall_closure (object fun, uintC args_on_stack);
/* UP: Applies a function to its arguments.
funcall(function,argcount);
> function: function
> Argumente: argcount arguments on STACK
< STACK: cleaned up (i.e. STACK is increased by argcount)
< mv_count/mv_space: values
changes STACK, can trigger GC */
global maygc Values funcall (object fun, uintC args_on_stack)
{
funcall_restart:
/* fun must be a SUBR or a Closure or a Cons (LAMBDA ...) : */
if (subrp(fun)) { /* SUBR ? */
return_Values funcall_subr(fun,args_on_stack);
} else if (closurep(fun)) { /* Closure ? */
return_Values funcall_closure(fun,args_on_stack);
} else if (symbolp(fun)) { /* Symbol ? */
/* apply Symbol: global Definition Symbol_function(fun) applies. */
var object fdef = Symbol_function(fun);
if (subrp(fdef)) { /* SUBR -> apply */
return_Values funcall_subr(fdef,args_on_stack);
} else if (closurep(fdef)) { /* Closure -> apply */
return_Values funcall_closure(fdef,args_on_stack);
} else if (orecordp(fdef)) {
#ifdef DYNAMIC_FFI
if (ffunctionp(fdef)) { /* Foreign-Function ? */
fun = fdef; goto call_ffunction;
}
#endif
switch (Record_type(fdef)) {
case Rectype_Fsubr:
fehler_specialform(S(funcall),fun);
case Rectype_Macro:
fehler_macro(S(funcall),fun);
default: NOTREACHED;
}
} else
/* if no SUBR, no Closure, no FSUBR, no Macro:
Symbol_function(fun) must be #<UNBOUND> . */
goto undef;
} else if (funnamep(fun)) { /* list (SETF symbol) ? */
/* global definition (symbol-function (get-setf-symbol symbol)) applies. */
var object symbol = get(Car(Cdr(fun)),S(setf_function)); /* (get ... 'SYS::SETF-FUNCTION) */
if (!symbolp(symbol)) /* should be (uninterned) symbol */
goto undef; /* else undefed */
var object fdef = Symbol_function(symbol);
if (closurep(fdef)) { /* Closure -> apply */
return_Values funcall_closure(fdef,args_on_stack);
} else if (subrp(fdef)) { /* SUBR -> apply */
return_Values funcall_subr(fdef,args_on_stack);
}
#ifdef DYNAMIC_FFI
else if (ffunctionp(fdef)) { /* Foreign-Function ? */
fun = fdef; goto call_ffunction;
}
#endif
else
/* Such function-names cannot denote FSUBRs or Macros.
fdef is presumable #<UNBOUND> . */
goto undef;
}
#ifdef DYNAMIC_FFI
else if (ffunctionp(fun)) /* Foreign-Function ? */
call_ffunction: { /* call (SYS::FOREIGN-CALL-OUT foreign-function . args) */
/* First shift down the arguments in Stack by 1. */
var uintC count;
var gcv_object_t* ptr = &STACK_0;
dotimesC(count,args_on_stack, {
*(ptr STACKop -1) = *ptr; ptr skipSTACKop 1;
});
*(ptr STACKop -1) = fun;
skipSTACK(-1);
return_Values funcall_subr(L(foreign_call_out),args_on_stack+1);
}
#endif
else if (consp(fun) && eq(Car(fun),S(lambda))) /* Cons (LAMBDA ...) ? */
fehler_lambda_expression(S(funcall),fun);
else {
fun = check_funname_replacement(type_error,S(funcall),fun);
goto funcall_restart;
}
return;
undef:
fun = check_fdefinition(fun,S(funcall));
goto funcall_restart;
}
# In FUNCALL: Applies a SUBR to arguments, cleans up STACK
# and returns the values.
# funcall_subr(fun,args_on_stack);
# > fun: function, a SUBR
# > Arguments: args_on_stack arguments on STACK
# < STACK: cleaned up (i.e. STACK is increased by args_on_stack)
# < mv_count/mv_space: values
# changes STACK, can trigger GC
local maygc Values funcall_subr (object fun, uintC args_on_stack)
{
#if STACKCHECKS
var gcv_object_t* args_pointer = args_end_pointer STACKop args_on_stack; # Pointer to the arguments
#endif
var gcv_object_t* key_args_pointer; # Pointer to the Keyword-arguments
var gcv_object_t* rest_args_pointer; # Pointer to the remaining arguments
var uintL argcount; # number of remaining arguments
TRACE_CALL(fun,'F','S');
# store arguments in STACK:
# First a Dispatch for the most important cases:
switch (TheSubr(fun)->argtype) {
case (uintW)subr_argtype_0_0:
# SUBR without Arguments
if (!(args_on_stack==0)) goto fehler_zuviel;
goto apply_subr_norest;
case (uintW)subr_argtype_1_0:
# SUBR with 1 required-Argument
if (!(args_on_stack==1)) goto fehler_anzahl;
goto apply_subr_norest;
case (uintW)subr_argtype_2_0:
# SUBR with 2 required-Arguments
if (!(args_on_stack==2)) goto fehler_anzahl;
goto apply_subr_norest;
case (uintW)subr_argtype_3_0:
# SUBR with 3 required-Arguments
if (!(args_on_stack==3)) goto fehler_anzahl;
goto apply_subr_norest;
case (uintW)subr_argtype_4_0:
# SUBR with 4 required-Arguments
if (!(args_on_stack==4)) goto fehler_anzahl;
goto apply_subr_norest;
case (uintW)subr_argtype_5_0:
# SUBR with 5 required-Arguments
if (!(args_on_stack==5)) goto fehler_anzahl;
goto apply_subr_norest;
case (uintW)subr_argtype_6_0:
# SUBR with 6 required-Arguments
if (!(args_on_stack==6)) goto fehler_anzahl;
goto apply_subr_norest;
case (uintW)subr_argtype_0_1:
# SUBR with 1 optional-Argument
if (args_on_stack==1) goto apply_subr_norest;
elif (args_on_stack>1) goto fehler_zuviel;
else { pushSTACK(unbound); goto apply_subr_norest; }
case (uintW)subr_argtype_1_1:
# SUBR with 1 required-Argument and 1 optional-Argument
if (args_on_stack==2) goto apply_subr_norest;
elif (args_on_stack>2) goto fehler_zuviel;
elif (args_on_stack==0) goto fehler_zuwenig;
else { pushSTACK(unbound); goto apply_subr_norest; }
case (uintW)subr_argtype_2_1:
# SUBR with 2 required-Arguments and 1 optional-Argument
if (args_on_stack==3) goto apply_subr_norest;
elif (args_on_stack>3) goto fehler_zuviel;
elif (args_on_stack<2) goto fehler_zuwenig;
else { pushSTACK(unbound); goto apply_subr_norest; }
case (uintW)subr_argtype_3_1:
# SUBR with 3 required-Arguments and 1 optional-Argument
if (args_on_stack==4) goto apply_subr_norest;
elif (args_on_stack>4) goto fehler_zuviel;
elif (args_on_stack<3) goto fehler_zuwenig;
else { pushSTACK(unbound); goto apply_subr_norest; }
case (uintW)subr_argtype_4_1:
# SUBR with 4 required-Arguments and 1 optional-Argument
if (args_on_stack==5) goto apply_subr_norest;
elif (args_on_stack>5) goto fehler_zuviel;
elif (args_on_stack<4) goto fehler_zuwenig;
else { pushSTACK(unbound); goto apply_subr_norest; }
case (uintW)subr_argtype_0_2:
# SUBR with 2 optional-Arguments
switch (args_on_stack) {
case 0: pushSTACK(unbound);
case 1: pushSTACK(unbound);
case 2: goto apply_subr_norest;
default: goto fehler_zuviel;
}
case (uintW)subr_argtype_1_2:
# SUBR with 1 required-Argument and 2 optional-Arguments
switch (args_on_stack) {
case 0: goto fehler_zuwenig;
case 1: pushSTACK(unbound);
case 2: pushSTACK(unbound);
case 3: goto apply_subr_norest;
default: goto fehler_zuviel;
}
case (uintW)subr_argtype_2_2:
# SUBR with 2 required-Arguments and 2 optional-Arguments
switch (args_on_stack) {
case 0: goto fehler_zuwenig;
case 1: goto fehler_zuwenig;
case 2: pushSTACK(unbound);
case 3: pushSTACK(unbound);
case 4: goto apply_subr_norest;
default: goto fehler_zuviel;
}
case (uintW)subr_argtype_3_2:
# SUBR with 3 required-Arguments and 2 optional-Arguments
switch (args_on_stack) {
case 0: goto fehler_zuwenig;
case 1: goto fehler_zuwenig;
case 2: goto fehler_zuwenig;
case 3: pushSTACK(unbound);
case 4: pushSTACK(unbound);
case 5: goto apply_subr_norest;
default: goto fehler_zuviel;
}
case (uintW)subr_argtype_0_3:
# SUBR with 3 optional-Arguments
switch (args_on_stack) {
case 0: pushSTACK(unbound);
case 1: pushSTACK(unbound);
case 2: pushSTACK(unbound);
case 3: goto apply_subr_norest;
default: goto fehler_zuviel;
}
case (uintW)subr_argtype_1_3:
# SUBR with 1 required-Argument and 3 optional-Arguments
switch (args_on_stack) {
case 0: goto fehler_zuwenig;
case 1: pushSTACK(unbound);
case 2: pushSTACK(unbound);
case 3: pushSTACK(unbound);
case 4: goto apply_subr_norest;
default: goto fehler_zuviel;
}
case (uintW)subr_argtype_2_3:
# SUBR with 2 required-Arguments and 3 optional-Arguments
switch (args_on_stack) {
case 0: goto fehler_zuwenig;
case 1: goto fehler_zuwenig;
case 2: pushSTACK(unbound);
case 3: pushSTACK(unbound);
case 4: pushSTACK(unbound);
case 5: goto apply_subr_norest;
default: goto fehler_zuviel;
}
case (uintW)subr_argtype_0_4:
# SUBR with 4 optional-Arguments
switch (args_on_stack) {
case 0: pushSTACK(unbound);
case 1: pushSTACK(unbound);
case 2: pushSTACK(unbound);
case 3: pushSTACK(unbound);
case 4: goto apply_subr_norest;
default: goto fehler_zuviel;
}
case (uintW)subr_argtype_0_5:
# SUBR with 5 optional-Arguments
switch (args_on_stack) {
case 0: pushSTACK(unbound);
case 1: pushSTACK(unbound);
case 2: pushSTACK(unbound);
case 3: pushSTACK(unbound);
case 4: pushSTACK(unbound);
case 5: goto apply_subr_norest;
default: goto fehler_zuviel;
}
case (uintW)subr_argtype_0_0_rest:
# SUBR with further Arguments
goto apply_subr_rest_ok;
case (uintW)subr_argtype_1_0_rest:
# SUBR with 1 required-Argument and further Arguments
if (args_on_stack==0) goto fehler_zuwenig;
args_on_stack -= 1;
goto apply_subr_rest_ok;
case (uintW)subr_argtype_2_0_rest:
# SUBR with 2 required-Argumenten and further Arguments
if (args_on_stack<2) goto fehler_zuwenig;
args_on_stack -= 2;
goto apply_subr_rest_ok;
case (uintW)subr_argtype_3_0_rest:
# SUBR with 3 required-Argumenten and further Arguments
if (args_on_stack<3) goto fehler_zuwenig;
args_on_stack -= 3;
goto apply_subr_rest_ok;
case (uintW)subr_argtype_0_0_key:
# SUBR with Keyword-Arguments
if (args_on_stack==0) goto unbound_optional_key_0;
else goto apply_subr_key;
case (uintW)subr_argtype_1_0_key:
# SUBR with 1 required-Argument and Keyword-Arguments
if (args_on_stack==1) goto unbound_optional_key_0;
elif (args_on_stack<1) goto fehler_zuwenig;
else { args_on_stack -= 1; goto apply_subr_key; }
case (uintW)subr_argtype_2_0_key:
# SUBR with 2 required-Arguments and Keyword-Arguments
if (args_on_stack==2) goto unbound_optional_key_0;
elif (args_on_stack<2) goto fehler_zuwenig;
else { args_on_stack -= 2; goto apply_subr_key; }
case (uintW)subr_argtype_3_0_key:
# SUBR with 3 required-Arguments and Keyword-Arguments
if (args_on_stack==3) goto unbound_optional_key_0;
elif (args_on_stack<3) goto fehler_zuwenig;
else { args_on_stack -= 3; goto apply_subr_key; }
case (uintW)subr_argtype_4_0_key:
# SUBR with 4 required-Arguments and Keyword-Arguments
if (args_on_stack==4) goto unbound_optional_key_0;
elif (args_on_stack<4) goto fehler_zuwenig;
else { args_on_stack -= 4; goto apply_subr_key; }
case (uintW)subr_argtype_0_1_key:
# SUBR with 1 optional-Argument and Keyword-Arguments
switch (args_on_stack) {
case 0: goto unbound_optional_key_1;
case 1: goto unbound_optional_key_0;
default: args_on_stack -= 1; goto apply_subr_key;
}
case (uintW)subr_argtype_1_1_key:
# SUBR with 1 required-Argument, 1 optional-Argument and Keyword-Arguments
switch (args_on_stack) {
case 0: goto fehler_zuwenig;
case 1: goto unbound_optional_key_1;
case 2: goto unbound_optional_key_0;
default: args_on_stack -= 2; goto apply_subr_key;
}
case (uintW)subr_argtype_1_2_key:
# SUBR with 1 required-Argument, 2 optional-Arguments and Keyword-Arguments
switch (args_on_stack) {
case 0: goto fehler_zuwenig;
case 1: goto unbound_optional_key_2;
case 2: goto unbound_optional_key_1;
case 3: goto unbound_optional_key_0;
default: args_on_stack -= 3; goto apply_subr_key;
}
unbound_optional_key_2: # Still 2 optional Arguments, but args_on_stack=0
pushSTACK(unbound);
unbound_optional_key_1: # Still 1 optional Argument, but args_on_stack=0
pushSTACK(unbound);
unbound_optional_key_0: # Before the Keywords is args_on_stack=0
{
var uintC count;
dotimesC(count,TheSubr(fun)->key_anz, { pushSTACK(unbound); } );
}
goto apply_subr_norest;
default: NOTREACHED;
#undef OPT_ARG
#undef REQ_ARG
}
# Now the general Version:
{
var uintC key_anz;
{
var uintC req_anz = TheSubr(fun)->req_anz;
var uintC opt_anz = TheSubr(fun)->opt_anz;
key_anz = TheSubr(fun)->key_anz;
if (args_on_stack < req_anz)
# fewer Arguments than demanded
goto fehler_zuwenig;
args_on_stack -= req_anz; # remaining number
if (args_on_stack <= opt_anz) {
# Arguments in Stack don't last for the optional ones
opt_anz = opt_anz - args_on_stack; # as many as these must go on STACK
if (opt_anz + key_anz > 0) {
# reserve space on STACK:
get_space_on_STACK(sizeof(gcv_object_t) * (uintL)(opt_anz + key_anz));
# All further count optional parameters receive the "value"
# #<UNBOUND>, including the Keyword-parameters:
var uintC count;
dotimespC(count,opt_anz + key_anz, { pushSTACK(unbound); } );
}
if (TheSubr(fun)->rest_flag == subr_rest) { # &REST-Flag?
# yes -> 0 additional Arguments:
argcount = 0; rest_args_pointer = args_end_pointer;
goto apply_subr_rest;
} else {
# no -> nothing to do
goto apply_subr_norest;
}
}
args_on_stack -= opt_anz; # remaining number (> 0)
if (TheSubr(fun)->key_flag == subr_nokey) {
# SUBR without KEY
if (TheSubr(fun)->rest_flag == subr_norest)
# SUBR without REST or KEY
goto fehler_zuviel; # still Arguments!
else
# SUBR with only REST, without KEY
goto apply_subr_rest_ok;
} else
# SUBR with Keywords.
goto apply_subr_key_;
}
apply_subr_key:
key_anz = TheSubr(fun)->key_anz;
apply_subr_key_:
# shift down remaining arguments in STACK and thus
# create room for the Keyword-parameters:
argcount = args_on_stack; # (> 0)
get_space_on_STACK(sizeof(gcv_object_t) * (uintL)key_anz);
{
var gcv_object_t* new_args_end_pointer = args_end_pointer STACKop -(uintP)key_anz;
var gcv_object_t* ptr1 = args_end_pointer;
var gcv_object_t* ptr2 = new_args_end_pointer;
var uintC count;
dotimespC(count,args_on_stack, { BEFORE(ptr2) = BEFORE(ptr1); } );
key_args_pointer = ptr1;
rest_args_pointer = ptr2;
dotimesC(count,key_anz, { NEXT(ptr1) = unbound; } );
set_args_end_pointer(new_args_end_pointer);
}
# assign Keywords and poss. discard remaining Arguments:
match_subr_key(fun,argcount,key_args_pointer,rest_args_pointer);
if (TheSubr(fun)->rest_flag != subr_norest)
# SUBR with &REST-Flag:
goto apply_subr_rest;
else
# SUBR without &REST-Flag:
goto apply_subr_norest;
}
apply_subr_rest_ok:
argcount = args_on_stack;
rest_args_pointer = args_end_pointer STACKop argcount;
apply_subr_rest:
with_saved_back_trace_subr(fun,STACK,
TheSubr(fun)->req_anz + TheSubr(fun)->opt_anz + argcount,
(*(subr_rest_function_t*)(TheSubr(fun)->function))(argcount,rest_args_pointer); );
goto done;
apply_subr_norest:
with_saved_back_trace_subr(fun,STACK,args_on_stack,
(*(subr_norest_function_t*)(TheSubr(fun)->function))(); );
done:
#if STACKCHECKS
if (!(args_pointer == args_end_pointer)) # Stack cleaned up?
abort(); # no -> go to Debugger
#endif
return; # finished
# Gathered error-messages:
fehler_anzahl:
if (args_on_stack < TheSubr(fun)->req_anz)
goto fehler_zuwenig; # too few Arguments
else
goto fehler_zuviel; # too many Arguments
fehler_zuwenig: fehler_subr_zuwenig(fun,NIL);
fehler_zuviel: fehler_subr_zuviel(fun);
}
# In FUNCALL: Applies a Closure to Arguments, cleans up STACK
# and returns the values.
# funcall_closure(fun,args_on_stack);
# > fun: function, a Closure
# > Argumente: args_on_stack Arguments on STACK
# < STACK: cleaned up (i.e. STACK is increased by args_on_stack)
# < mv_count/mv_space: values
# changes STACK, can trigger GC
local maygc Values funcall_closure (object closure, uintC args_on_stack)
{
TRACE_CALL(closure,'F','C');
if (simple_bit_vector_p(Atype_8Bit,TheClosure(closure)->clos_codevec)) {
# closure is a compiled Closure
#if STACKCHECKC
var gcv_object_t* args_pointer = args_end_pointer STACKop args_on_stack; # Pointer to the Arguments
#endif
var object codevec = TheCclosure(closure)->clos_codevec; # Code-Vector
var gcv_object_t* key_args_pointer; # Pointer to the Keyword-Arguments
var gcv_object_t* rest_args_pointer; # Pointer to the remaining Arguments
var uintL argcount; # number of remaining Arguments
check_SP(); check_STACK();
# store arguments in STACK:
# First a Dispatch for the most important cases:
switch (TheCodevec(codevec)->ccv_signature) {
case (uintB)cclos_argtype_0_0:
# no Arguments
if (!(args_on_stack==0)) goto fehler_zuviel;
goto apply_cclosure_nokey;
case (uintB)cclos_argtype_1_0:
# 1 required-Argument
if (!(args_on_stack==1)) goto fehler_anzahl;
goto apply_cclosure_nokey;
case (uintB)cclos_argtype_2_0:
# 2 required-Arguments
if (!(args_on_stack==2)) goto fehler_anzahl;
goto apply_cclosure_nokey;
case (uintB)cclos_argtype_3_0:
# 3 required-Arguments
if (!(args_on_stack==3)) goto fehler_anzahl;
goto apply_cclosure_nokey;
case (uintB)cclos_argtype_4_0:
# 4 required-Arguments
if (!(args_on_stack==4)) goto fehler_anzahl;
goto apply_cclosure_nokey;
case (uintB)cclos_argtype_5_0:
# 5 required-Arguments
if (!(args_on_stack==5)) goto fehler_anzahl;
goto apply_cclosure_nokey;
case (uintB)cclos_argtype_0_1:
# 1 optional-Argument
if (args_on_stack==1) goto apply_cclosure_nokey;
elif (args_on_stack>1) goto fehler_zuviel;
else { pushSTACK(unbound); goto apply_cclosure_nokey; }
case (uintB)cclos_argtype_1_1:
# 1 required-Argument and 1 optional-Argument
if (args_on_stack==2) goto apply_cclosure_nokey;
elif (args_on_stack>2) goto fehler_zuviel;
elif (args_on_stack==0) goto fehler_zuwenig;
else { pushSTACK(unbound); goto apply_cclosure_nokey; }
case (uintB)cclos_argtype_2_1:
# 2 required-Arguments and 1 optional-Argument
if (args_on_stack==3) goto apply_cclosure_nokey;
elif (args_on_stack>3) goto fehler_zuviel;
elif (args_on_stack<2) goto fehler_zuwenig;
else { pushSTACK(unbound); goto apply_cclosure_nokey; }
case (uintB)cclos_argtype_3_1:
# 3 required-Arguments and 1 optional-Argument
if (args_on_stack==4) goto apply_cclosure_nokey;
elif (args_on_stack>4) goto fehler_zuviel;
elif (args_on_stack<3) goto fehler_zuwenig;
else { pushSTACK(unbound); goto apply_cclosure_nokey; }
case (uintB)cclos_argtype_4_1:
# 4 required-Arguments and 1 optional-Argument
if (args_on_stack==5) goto apply_cclosure_nokey;
elif (args_on_stack>5) goto fehler_zuviel;
elif (args_on_stack<4) goto fehler_zuwenig;
else { pushSTACK(unbound); goto apply_cclosure_nokey; }
case (uintB)cclos_argtype_0_2:
# 2 optional-Arguments
switch (args_on_stack) {
case 0: pushSTACK(unbound);
case 1: pushSTACK(unbound);
case 2: goto apply_cclosure_nokey;
default: goto fehler_zuviel;
}
case (uintB)cclos_argtype_1_2:
# 1 required-Argument and 2 optional-Arguments
switch (args_on_stack) {
case 0: goto fehler_zuwenig;
case 1: pushSTACK(unbound);
case 2: pushSTACK(unbound);
case 3: goto apply_cclosure_nokey;
default: goto fehler_zuviel;
}
case (uintB)cclos_argtype_2_2:
# 2 required-Arguments and 2 optional-Arguments
switch (args_on_stack) {
case 0: case 1: goto fehler_zuwenig;
case 2: pushSTACK(unbound);
case 3: pushSTACK(unbound);
case 4: goto apply_cclosure_nokey;
default: goto fehler_zuviel;
}
case (uintB)cclos_argtype_3_2:
# 3 required-Arguments and 2 optional-Arguments
switch (args_on_stack) {
case 0: case 1: case 2: goto fehler_zuwenig;
case 3: pushSTACK(unbound);
case 4: pushSTACK(unbound);
case 5: goto apply_cclosure_nokey;
default: goto fehler_zuviel;
}
case (uintB)cclos_argtype_0_3:
# 3 optional-Arguments
switch (args_on_stack) {
case 0: pushSTACK(unbound);
case 1: pushSTACK(unbound);
case 2: pushSTACK(unbound);
case 3: goto apply_cclosure_nokey;
default: goto fehler_zuviel;
}
case (uintB)cclos_argtype_1_3:
# 1 required-Argument and 3 optional-Arguments
switch (args_on_stack) {
case 0: goto fehler_zuwenig;
case 1: pushSTACK(unbound);
case 2: pushSTACK(unbound);
case 3: pushSTACK(unbound);
case 4: goto apply_cclosure_nokey;
default: goto fehler_zuviel;
}
case (uintB)cclos_argtype_2_3:
# 2 required-Arguments and 3 optional-Arguments
switch (args_on_stack) {
case 0: case 1: goto fehler_zuwenig;
case 2: pushSTACK(unbound);
case 3: pushSTACK(unbound);
case 4: pushSTACK(unbound);
case 5: goto apply_cclosure_nokey;
default: goto fehler_zuviel;
}
case (uintB)cclos_argtype_0_4:
# 4 optional-Arguments
switch (args_on_stack) {
case 0: pushSTACK(unbound);
case 1: pushSTACK(unbound);
case 2: pushSTACK(unbound);
case 3: pushSTACK(unbound);
case 4: goto apply_cclosure_nokey;
default: goto fehler_zuviel;
}
case (uintB)cclos_argtype_1_4:
# 1 required-Argument and 4 optional-Arguments
switch (args_on_stack) {
case 0: goto fehler_zuwenig;
case 1: pushSTACK(unbound);
case 2: pushSTACK(unbound);
case 3: pushSTACK(unbound);
case 4: pushSTACK(unbound);
case 5: goto apply_cclosure_nokey;
default: goto fehler_zuviel;
}
case (uintB)cclos_argtype_0_5:
# 5 optional-Arguments
switch (args_on_stack) {
case 0: pushSTACK(unbound);
case 1: pushSTACK(unbound);
case 2: pushSTACK(unbound);
case 3: pushSTACK(unbound);
case 4: pushSTACK(unbound);
case 5: goto apply_cclosure_nokey;
default: goto fehler_zuviel;
}
case (uintB)cclos_argtype_0_0_rest:
# no Arguments, Rest-Parameter
goto apply_cclosure_rest_nokey;
case (uintB)cclos_argtype_1_0_rest:
# 1 required-Argument, Rest-Parameter
if (args_on_stack==0) goto fehler_zuwenig;
args_on_stack -= 1;
goto apply_cclosure_rest_nokey;
case (uintB)cclos_argtype_2_0_rest:
# 2 required-Arguments, Rest-Parameter
if (args_on_stack<2) goto fehler_zuwenig;
args_on_stack -= 2;
goto apply_cclosure_rest_nokey;
case (uintB)cclos_argtype_3_0_rest:
# 3 required-Arguments, Rest-Parameter
if (args_on_stack<3) goto fehler_zuwenig;
args_on_stack -= 3;
goto apply_cclosure_rest_nokey;
case (uintB)cclos_argtype_4_0_rest:
# 4 required-Arguments, Rest-Parameter
if (args_on_stack<4) goto fehler_zuwenig;
args_on_stack -= 4;
goto apply_cclosure_rest_nokey;
case (uintB)cclos_argtype_0_0_key:
# only Keyword-Arguments
if (args_on_stack==0) goto unbound_optional_key_0;
else goto apply_cclosure_key_withargs;
case (uintB)cclos_argtype_1_0_key:
# 1 required-Argument, Keyword-Arguments
if (args_on_stack==1) goto unbound_optional_key_0;
elif (args_on_stack<1) goto fehler_zuwenig;
else { args_on_stack -= 1; goto apply_cclosure_key_withargs; }
case (uintB)cclos_argtype_2_0_key:
# 2 required-Arguments, Keyword-Arguments
if (args_on_stack==2) goto unbound_optional_key_0;
elif (args_on_stack<2) goto fehler_zuwenig;
else { args_on_stack -= 2; goto apply_cclosure_key_withargs; }
case (uintB)cclos_argtype_3_0_key:
# 3 required-Arguments, Keyword-Arguments
if (args_on_stack==3) goto unbound_optional_key_0;
elif (args_on_stack<3) goto fehler_zuwenig;
else { args_on_stack -= 3; goto apply_cclosure_key_withargs; }
case (uintB)cclos_argtype_4_0_key:
# 4 required-Arguments, Keyword-Arguments
if (args_on_stack==4) goto unbound_optional_key_0;
elif (args_on_stack<4) goto fehler_zuwenig;
else { args_on_stack -= 4; goto apply_cclosure_key_withargs; }
case (uintB)cclos_argtype_0_1_key:
# 1 optional-Argument, Keyword-Arguments
switch (args_on_stack) {
case 0: goto unbound_optional_key_1;
case 1: goto unbound_optional_key_0;
default: args_on_stack -= 1; goto apply_cclosure_key_withargs;
}
case (uintB)cclos_argtype_1_1_key:
# 1 required-Argument and 1 optional-Argument, Keyword-Arguments
switch (args_on_stack) {
case 0: goto fehler_zuwenig;
case 1: goto unbound_optional_key_1;
case 2: goto unbound_optional_key_0;
default: args_on_stack -= 2; goto apply_cclosure_key_withargs;
}
case (uintB)cclos_argtype_2_1_key:
# 2 required-Arguments and 1 optional-Argument, Keyword-Arguments
switch (args_on_stack) {
case 0: case 1: goto fehler_zuwenig;
case 2: goto unbound_optional_key_1;
case 3: goto unbound_optional_key_0;
default: args_on_stack -= 3; goto apply_cclosure_key_withargs;
}
case (uintB)cclos_argtype_3_1_key:
# 3 required-Arguments and 1 optional-Argument, Keyword-Arguments
switch (args_on_stack) {
case 0: case 1: case 2: goto fehler_zuwenig;
case 3: goto unbound_optional_key_1;
case 4: goto unbound_optional_key_0;
default: args_on_stack -= 4; goto apply_cclosure_key_withargs;
}
case (uintB)cclos_argtype_0_2_key:
# 2 optional-Arguments, Keyword-Arguments
switch (args_on_stack) {
case 0: goto unbound_optional_key_2;
case 1: goto unbound_optional_key_1;
case 2: goto unbound_optional_key_0;
default: args_on_stack -= 2; goto apply_cclosure_key_withargs;
}
case (uintB)cclos_argtype_1_2_key:
# 1 required-Argument and 2 optional-Arguments, Keyword-Arguments
switch (args_on_stack) {
case 0: goto fehler_zuwenig;
case 1: goto unbound_optional_key_2;
case 2: goto unbound_optional_key_1;
case 3: goto unbound_optional_key_0;
default: args_on_stack -= 3; goto apply_cclosure_key_withargs;
}
case (uintB)cclos_argtype_2_2_key:
# 2 required-Arguments and 2 optional-Arguments, Keyword-Arguments
switch (args_on_stack) {
case 0: case 1: goto fehler_zuwenig;
case 2: goto unbound_optional_key_2;
case 3: goto unbound_optional_key_1;
case 4: goto unbound_optional_key_0;
default: args_on_stack -= 4; goto apply_cclosure_key_withargs;
}
case (uintB)cclos_argtype_0_3_key:
# 3 optional-Arguments, Keyword-Arguments
switch (args_on_stack) {
case 0: goto unbound_optional_key_3;
case 1: goto unbound_optional_key_2;
case 2: goto unbound_optional_key_1;
case 3: goto unbound_optional_key_0;
default: args_on_stack -= 3; goto apply_cclosure_key_withargs;
}
case (uintB)cclos_argtype_1_3_key:
# 1 required-Argument and 3 optional-Arguments, Keyword-Arguments
switch (args_on_stack) {
case 0: goto fehler_zuwenig;
case 1: goto unbound_optional_key_3;
case 2: goto unbound_optional_key_2;
case 3: goto unbound_optional_key_1;
case 4: goto unbound_optional_key_0;
default: args_on_stack -= 4; goto apply_cclosure_key_withargs;
}
case (uintB)cclos_argtype_0_4_key:
# 4 optional-Arguments, Keyword-Arguments
switch (args_on_stack) {
case 0: goto unbound_optional_key_4;
case 1: goto unbound_optional_key_3;
case 2: goto unbound_optional_key_2;
case 3: goto unbound_optional_key_1;
case 4: goto unbound_optional_key_0;
default: args_on_stack -= 4; goto apply_cclosure_key_withargs;
}
unbound_optional_key_4: # Still 4 optional Arguments, but args_on_stack=0
pushSTACK(unbound);
unbound_optional_key_3: # Still 3 optional Arguments, but args_on_stack=0
pushSTACK(unbound);
unbound_optional_key_2: # Still 2 optional Arguments, but args_on_stack=0
pushSTACK(unbound);
unbound_optional_key_1: # Still 1 optional Argument, but args_on_stack=0
pushSTACK(unbound);
unbound_optional_key_0: # Before the Keywords is args_on_stack=0
goto apply_cclosure_key_noargs;
case (uintB)cclos_argtype_default:
# General Version
break;
default: NOTREACHED;
}
# Now the general version:
{
var uintB flags;
{
var uintC req_anz = TheCodevec(codevec)->ccv_numreq; # number of required Parameters
var uintC opt_anz = TheCodevec(codevec)->ccv_numopt; # number of optional Parameters
flags = TheCodevec(codevec)->ccv_flags; # Flags
if (args_on_stack < req_anz)
# fewer Arguments than demanded
goto fehler_zuwenig;
args_on_stack -= req_anz; # remaining number
if (args_on_stack <= opt_anz) {
# Arguments in Stack don't last for the optional ones
opt_anz = opt_anz - args_on_stack; # as many as these must go on STACK
if (opt_anz > 0) {
# reserve space on STACK:
get_space_on_STACK(sizeof(gcv_object_t) * (uintL)opt_anz);
# All further count optional parameters receive the "value"
# #<UNBOUND>, the &REST-parameter receives NIL,
# the Keyword-parameters receive the value #<UNBOUND> :
var uintC count;
dotimespC(count,opt_anz, { pushSTACK(unbound); } );
}
if (flags & bit(0)) # &REST-Flag?
pushSTACK(NIL); # yes -> initialize with NIL
if (flags & bit(7)) # &KEY-Flag?
goto apply_cclosure_key_noargs;
else
goto apply_cclosure_nokey;
}
args_on_stack -= opt_anz; # remaining number
if (flags & bit(7)) # Key-Flag?
goto apply_cclosure_key_withargs_;
elif (flags & bit(0))
goto apply_cclosure_rest_nokey;
else {
# Closure without REST or KEY
if (args_on_stack>0) # still arguments?
goto fehler_zuviel;
goto apply_cclosure_nokey;
}
}
apply_cclosure_key_noargs:
{
var uintC key_anz = TheCodevec(codevec)->ccv_numkey; # number of Keyword-Parameters
if (key_anz > 0) {
get_space_on_STACK(sizeof(gcv_object_t) * (uintL)key_anz);
var uintC count;
dotimespC(count,key_anz, { pushSTACK(unbound); } ); # initialize with #<UNBOUND>
}
goto apply_cclosure_key;
}
apply_cclosure_key_withargs:
flags = TheCodevec(codevec)->ccv_flags; # initialize Flags!
apply_cclosure_key_withargs_:
# Closure with Keywords
{
var uintC key_anz = TheCodevec(codevec)->ccv_numkey; # number of Keyword-Parameters
# shift down remaining arguments in STACK and thus
# create room for the Keyword-parameters
# (and poss. Rest-parameters):
var uintL shift = key_anz;
if (flags & bit(0))
shift++; # poss. 1 more for Rest-Parameter
argcount = args_on_stack;
get_space_on_STACK(sizeof(gcv_object_t) * shift);
var gcv_object_t* new_args_end_pointer = args_end_pointer STACKop -(uintP)shift;
var gcv_object_t* ptr1 = args_end_pointer;
var gcv_object_t* ptr2 = new_args_end_pointer;
var uintC count;
dotimesC(count,args_on_stack, { BEFORE(ptr2) = BEFORE(ptr1); } );
if (flags & bit(0))
NEXT(ptr1) = unbound; # Rest-Parameter
key_args_pointer = ptr1;
rest_args_pointer = ptr2;
dotimesC(count,key_anz, { NEXT(ptr1) = unbound; } );
set_args_end_pointer(new_args_end_pointer);
}
# assign Keywords, build Rest-Parameter
# and poss. discard remaining arguments:
closure = match_cclosure_key(closure,argcount,key_args_pointer,rest_args_pointer);
codevec = TheCclosure(closure)->clos_codevec;
apply_cclosure_key:
interpret_bytecode(closure,codevec,CCV_START_KEY); # process Bytecode starting at Byte 12
goto done;
}
apply_cclosure_rest_nokey:
# Closure with only REST, without KEY:
# still must cons args_on_stack arguments from stack Stack:
pushSTACK(NIL);
if (args_on_stack > 0) {
pushSTACK(closure); # Closure must be saved
dotimesC(args_on_stack,args_on_stack, {
var object new_cons = allocate_cons();
Cdr(new_cons) = STACK_1;
Car(new_cons) = STACK_2; # cons next argument to it
STACK_2 = new_cons;
STACK_1 = STACK_0; skipSTACK(1);
});
closure = popSTACK(); codevec = TheCclosure(closure)->clos_codevec;
}
apply_cclosure_nokey: # jump to Closure without &KEY:
interpret_bytecode(closure,codevec,CCV_START_NONKEY); # process Bytecode starting at Byte 8
done:
#if STACKCHECKC
if (!(args_pointer == args_end_pointer)) # Stack cleaned up?
abort(); # no -> go to Debugger
#endif
return; # finished
# Gathered error-messages:
fehler_anzahl:
if (args_on_stack < TheCodevec(codevec)->ccv_numreq)
goto fehler_zuwenig; # too few arguments
else
goto fehler_zuviel; # too many arguments
fehler_zuwenig: fehler_closure_zuwenig(closure,NIL);
fehler_zuviel: fehler_closure_zuviel(closure);
} else {
/* closure is an interpreted Closure */
var gcv_object_t* args_pointer = args_end_pointer STACKop args_on_stack;
with_saved_back_trace_iclosure(closure,args_pointer,args_on_stack,
funcall_iclosure(closure,args_pointer,args_on_stack); );
}
}
# ---------------------- BYTECODE-INTERPRETER ----------------------
# Interpretes the bytecode of a compiled Closure.
# interpret_bytecode_(closure,codeptr,byteptr);
# > closure: compiled closure
# > codeptr: its Codevector, a Simple-Bit-Vector, pointable
# > byteptr: Start-Bytecodepointer
# < mv_count/mv_space: values
# changes STACK, can trigger GC
# Syntax of local labels in GNU-C assembler-statements:
#if (defined(GNU) || defined(INTEL)) && !defined(NO_ASM)
# LD(x) defines Label with number x
# LR(x,f) references label with number x forwards
# LR(x,b) references label with number x backwards
# The scope of the labels is only one assembler-statement.
#if defined(I80386) && !defined(UNIX_NEXTSTEP)
#ifdef ASM_UNDERSCORE
#define LD(nr) "LASM%=X" STRING(nr)
#define LR(nr,fb) "LASM%=X" STRING(nr)
#else
#define LD(nr) ".LASM%=X" STRING(nr)
#define LR(nr,fb) ".LASM%=X" STRING(nr)
#endif
#elif defined(ARM)
#define LD(nr) "LASM%=X" STRING(nr)
#define LR(nr,fb) "LASM%=X" STRING(nr)
#else
#define LD(nr) STRING(nr)
#define LR(nr,fb) STRING(nr) STRING(fb)
#endif
#endif
# Persuade GNU-C, to keep closure and byteptr in registers:
#ifdef GNU
#ifdef MC680X0
#define closure_register "a2"
#define byteptr_register "a3"
#endif
#ifdef SPARC
#define closure_register "%l0"
#define byteptr_register "%l1"
#endif
#ifdef I80386
#if (__GNUC__ >= 2) # The register-names have changed
#define byteptr_register "%edi"
#else
#define byteptr_register "di"
#endif
#endif
#ifdef ARM
# Code is better without defining registers for closure and byteptr,
# says Peter Burwood.
# not define closure_register "%r6"
# not define byteptr_register "%r7"
# We have assembler macros below, but if they are used with gcc-2.7.2.1,
# (setf cdddr) is miscompiled. So here we temporarily disable them.
#ifndef NO_ASM
#define NO_ASM
#endif
#endif
#ifdef DECALPHA
#define byteptr_register "$14"
#endif
#if defined(WIDE) && !defined(WIDE_HARD)
# An `object' does not fit into a single register, GCC is overcharged.
#undef closure_register
#endif
#endif
#ifndef closure_register
#define closure_in closure
#endif
#ifndef byteptr_register
#define byteptr_in byteptr
#endif
#ifdef DEBUG_BYTECODE
#define GOTO_ERROR(label) \
do { \
fprintf(stderr,"\n[%s:%d] ",__FILE__,__LINE__); \
goto label; \
} while(0)
#define DEBUG_CHECK_BYTEPTR(nb) do { \
var const uintL b = nb - codeptr->data; \
if ((b < byteptr_min) || (b > byteptr_max)) { \
var uintL bp = byteptr - codeptr->data; \
fprintf(stderr,"\n[%s:%d] ",__FILE__,__LINE__); \
byteptr_bad_jump = b - bp; \
/*nobject_out(stderr,closure);*/ \
/*fprintf(stderr," jump by %d takes %d outside [%d;%d]",byteptr_bad_jump,bp,byteptr_min,byteptr_max);*/ \
goto fehler_byteptr; \
}} while(0)
#else
#define GOTO_ERROR(label) goto label
#define DEBUG_CHECK_BYTEPTR(b) do{}while(0)
#endif
local /*maygc*/ Values interpret_bytecode_ (object closure_in, Sbvector codeptr, const uintB* byteptr_in)
{
GCTRIGGER_IF(true, {
if (*byteptr_in == cod_handler_begin_push)
GCTRIGGER3(closure_in,handler_args.condition,handler_args.spdepth);
else
GCTRIGGER1(closure_in);
});
#if STACKCHECKC || defined(DEBUG_BYTECODE)
var const uintL byteptr_min = ((Codevec)codeptr)->ccv_flags & bit(7)
? CCV_START_KEY : CCV_START_NONKEY;
#endif
#ifdef DEBUG_BYTECODE
var const uintL byteptr_max = sbvector_length(codeptr)-1;
var sintL byteptr_bad_jump;
#endif
# situate argument closure in register:
#ifdef closure_register
var object closure __asm__(closure_register);
closure = closure_in;
#endif
# situate argument byteptr in register:
#ifdef byteptr_register
var register const uintB* byteptr __asm__(byteptr_register);
byteptr = byteptr_in;
#endif
TRACE_CALL(closure,'B','C');
# situate closure in STACK, below the arguments:
var gcv_object_t* closureptr = (pushSTACK(closure), &STACK_0);
#ifndef FAST_SP
# If there is no fast SP-Access, one has to introduce
# an extra pointer:
var uintL private_SP_length =
(uintL)(((Codevec)codeptr)->ccv_spdepth_1)
+ jmpbufsize * (uintL)(((Codevec)codeptr)->ccv_spdepth_jmpbufsize);
var DYNAMIC_ARRAY(private_SP_space,SPint,private_SP_length);
var SPint* private_SP = &private_SP_space[private_SP_length];
#undef SP_
#undef _SP_
#undef skipSP
#undef pushSP
#undef popSP
#define SP_(n) (private_SP[n])
#define _SP_(n) &SP_(n)
#define skipSP(n) (private_SP += (n))
#define pushSP(item) (*--private_SP = (item))
#define popSP(item_zuweisung) (item_zuweisung *private_SP++)
#endif
# var JMPBUF_on_SP(name); allocates a sp_jmp_buf in SP.
# FREE_JMPBUF_on_SP(); deallocates it.
# finish_entry_frame_1(frametype,returner,reentry_statement); is like
# finish_entry_frame(frametype,returner,,reentry_statement); but
# also private_SP is saved.
#ifndef FAST_SP
#define JMPBUF_on_SP(name) \
sp_jmp_buf* name = (sp_jmp_buf*)(private_SP -= jmpbufsize);
#define FREE_JMPBUF_on_SP() \
private_SP += jmpbufsize;
#define finish_entry_frame_1(frametype,returner,reentry_statement) \
finish_entry_frame(frametype,*returner, # On entry: returner = private_SP \
returner = (sp_jmp_buf*) , # returner is set again on return \
{ private_SP = (SPint*)returner; reentry_statement } # and private_SP is reconstructed \
)
#else
#ifdef SP_DOWN
#define JMPBUF_on_SP(name) \
sp_jmp_buf* name; \
{var SPint* sp = (SPint*)SP(); \
sp -= jmpbufsize; \
setSP(sp); \
name = (sp_jmp_buf*)&sp[SPoffset]; \
}
#endif
#ifdef SP_UP
#define JMPBUF_on_SP(name) \
sp_jmp_buf* name; \
{var SPint* sp = (SPint*)SP(); \
name = (sp_jmp_buf*)&sp[SPoffset+1]; \
sp += jmpbufsize; \
setSP(sp); \
}
#endif
#define FREE_JMPBUF_on_SP() \
skipSP(jmpbufsize);
#define finish_entry_frame_1(frametype,returner,reentry_statement) \
finish_entry_frame(frametype,*returner,,reentry_statement)
#endif
#
#ifdef FAST_DISPATCH
static void* const cod_labels[] = {
#define BYTECODE(code) &&code,
#include "bytecode.c"
#undef BYTECODE
};
#endif
#
# next Byte to be interpreted
# > mv_count/mv_space: current values
# > closureptr: pointer to the compiled closure on Stack
# > closure: compiled closure
# > codeptr: its codevector, a Simple-Bit-Vektor, pointable
# (no LISP-object, but nevertheless endangered by GC!)
# > byteptr: pointer to the next byte in code
# (no LISP-object, but nevertheless endangered by GC!)
next_byte:
# definition by cases, according to byte to be interpreted byte
#ifndef FAST_DISPATCH
switch (*byteptr++)
#define CASE case (uintB)
#else # FAST_DISPATCH
# This is faster by about 2%, because the index-check is dropped.
goto *cod_labels[*byteptr++];
#define CASE
#ifdef FAST_DISPATCH_THREADED
# The jump-statement goto next_byte; can be omitted:
#define next_byte *cod_labels[*byteptr++]
#endif
#endif
{
# Operand-Fetch:
# next Byte:
# Bit 7 = 0 --> Bits 6..0 are the Operand (7 Bits).
# Bit 7 = 1 --> Bits 6..0 and next Byte form the
# Operand (15 Bits).
# For jump-distances: Should this be =0, the next
# 4 Bytes form the Operand
# (32 Bits).
#
# Macro B_operand(where);
# moves the next Operand (a Byte as Unsigned Integer)
# to (uintL)where and advances bytecodepointer.
#define B_operand(where) \
{ where = *byteptr++; }
#
# Macro U_operand(where);
# moves the next Operand (an Unsigned Integer)
# to (uintL)where or (uintC)where
# and advances the Bytecodepointer.
#define U_operand(where) \
{ where = *byteptr++; # read first Byte \
if ((uintB)where & bit(7)) # Bit 7 set? \
{ where &= ~bit(7); # yes -> delete \
where = where << 8; \
where |= *byteptr++; # and read next Byte \
} }
#if defined(GNU) && defined(MC680X0) && !defined(NO_ASM)
#undef U_operand
#define U_operand(where) \
__asm__( \
"moveq #0,%0" "\n\t" \
"moveb %1@+,%0" "\n\t" \
"bpl 1f" "\n\t" \
"addb %0,%0" "\n\t" \
"lslw #7,%0" "\n\t" \
"moveb %1@+,%0" "\n" \
"1:" \
: "=d" (where), "=a" (byteptr) : "1" (byteptr) )
#endif
#if defined(GNU) && defined(SPARC) && !defined(NO_ASM)
#undef U_operand
#define U_operand(where) \
{ var uintL dummy; \
__asm__( \
"ldub [%1],%0" "\n\t" \
"andcc %0,0x80,%%g0" "\n\t" \
"be 1f" "\n\t" \
" add %1,1,%1" "\n\t" \
"sll %0,25,%2" "\n\t" \
"ldub [%1],%0" "\n\t" \
"srl %2,17,%2" "\n\t" \
"add %1,1,%1" "\n\t" \
"or %0,%2,%0" "\n" \
"1:" \
: "=r" (where), "=r" (byteptr), "=r" (dummy) : "1" (byteptr) : "ccr" ); \
}
#endif
#if (defined(GNU) || defined(INTEL)) && defined(I80386) && !defined(NO_ASM)
#if 0
# In earlier times, the GNU assembler assembled
# "testb %edx,%edx" as "testb %dl,%dl". This made possible to
# produce the output in any register.
#define OUT_EAX "=q"
#define EAX "%0"
#define AL "%0"
#else
# Now "testb %edx,%edx" is invalid everywhere. The macros must
# put their result in %eax.
#define OUT_EAX "=a"
#define EAX "%%eax"
#define AL "%%al"
#endif
#undef U_operand
#define U_operand(where) \
__asm__( \
"movzbl (%1),"EAX "\n\t" \
"incl %1" "\n\t" \
"testb "AL","AL "\n\t" \
"jge "LR(1,f) "\n\t" \
"andb $127,"AL "\n\t" \
"sall $8,"EAX "\n\t" \
"movb (%1),"AL "\n\t" \
"incl %1" "\n" \
LD(1)":" \
: OUT_EAX (where), "=r" (byteptr) : "1" (byteptr) );
# Caution: 1. Der Sun-Assembler doesn't know this Syntax for local labels.
# That's why we generate our local labels ourselves.
# Caution: 2. ccr is changed. How is this to be declared??
#endif
#if defined(GNU) && defined(ARM) && !defined(NO_ASM)
# Macros written by Peter Burwood.
# Two versions. Which one to choose?
# instructions short case long case
# v1: 5 2 + 3 skipped 5
# v2: 5 3 + 2 skipped 4 + 1 skipped
# Let's choose the first one. 1-byte operands are most frequent.
#undef U_operand
#define U_operand(where) # (v1) \
{ var uintL dummy; \
__asm__( \
"ldrb %0,[%1],#1" "\n\t" \
"tst %0,#0x80" "\n\t" \
"bicne %0,%0,#0x80" "\n\t" \
"ldrneb %2,[%1],#1" "\n\t" \
"orrne %0,%2,%0,LSL#8" \
: "=r" (where), "=r" (byteptr), "=r" (dummy) : "1" (byteptr) : "cc" ); \
}
#if 0
#undef U_operand
#define U_operand(where) # (v2) \
{ var uintL dummy; \
__asm__( \
"ldrb %0,[%1],#1" "\n\t" \
"movs %0,%0,LSL#25" "\n\t" \
"movcc %0,%0,LSR#25" "\n\t" \
"ldrcsb %2,[%1],#1" "\n\t" \
"orrcs %0,%2,%0,LSR#17" \
: "=r" (where), "=r" (byteptr), "=r" (dummy) : "1" (byteptr) : "cc" ); \
}
#endif
#endif
#
# Macro S_operand(where);
# moves the next Operand (a Signed Integer)
# to (uintL)where and advances the bytecodepointer.
#define S_operand(where) \
{ where = *byteptr++; # read first byte \
if ((uintB)where & bit(7)) \
# Bit 7 was set \
{ where = where << 8; \
where |= *byteptr++; # subjoin next Byte \
# Sign-Extend from 15 to 32 Bits: \
where = (sintL)((sintL)(sintWL)((sintWL)where << (intWLsize-15)) >> (intWLsize-15)); \
if (where == 0) \
# special case: 2-Byte-Operand = 0 -> 6-Byte-Operand \
{ where = (uintL)( ((uintWL)(byteptr[0]) << 8) \
| (uintWL)(byteptr[1]) \
) << 16 \
| (uintL)( ((uintWL)(byteptr[2]) << 8) \
| (uintWL)(byteptr[3]) \
); \
byteptr += 4; \
} } \
else \
# Bit 7 was deleted \
{ # Sign-Extend from 7 to 32 Bits: \
where = (sintL)((sintL)(sintBWL)((sintBWL)where << (intBWLsize-7)) >> (intBWLsize-7)); \
} \
}
#if defined(GNU) && defined(MC680X0) && !defined(NO_ASM)
#undef S_operand
#define S_operand(where) \
__asm__( \
"moveb %1@+,%0" "\n\t" \
"bpl 1f" "\n\t" \
"lslw #8,%0" "\n\t" \
"moveb %1@+,%0" "\n\t" \
"addw %0,%0" "\n\t" \
"asrw #1,%0" "\n\t" \
"bne 2f" "\n\t" \
"moveb %1@(2),%0" "\n\t" \
"swap %0" "\n\t" \
"moveb %1@+,%0" "\n\t" \
"lsll #8,%0" "\n\t" \
"moveb %1@,%0" "\n\t" \
"swap %0" "\n\t" \
"addql #2,%0" "\n\t" \
"moveb %1@+,%0" "\n\t" \
"jra 3f" "\n" \
"1:" "\t" \
"addb %0,%0" "\n\t" \
"asrb #1,%0" "\n\t" \
"extw %0" "\n" \
"2:" "\t" \
"extl %0" "\n" \
"3:" \
: "=d" (where), "=a" (byteptr) : "1" (byteptr) )
#endif
#if defined(GNU) && defined(SPARC) && !defined(NO_ASM)
#undef S_operand
#define S_operand(where) \
{ var uintL dummy; \
__asm__( \
"ldub [%1],%0" "\n\t" \
"andcc %0,0x80,%%g0" "\n\t" \
"be 2f" "\n\t" \
" add %1,1,%1" "\n\t" \
"sll %0,25,%2" "\n\t" \
"ldub [%1],%0" "\n\t" \
"sra %2,17,%2" "\n\t" \
"orcc %2,%0,%0" "\n\t" \
"bne 3f" "\n\t" \
" add %1,1,%1" "\n\t" \
"ldub [%1],%0" "\n\t" \
"sll %0,24,%2" "\n\t" \
"ldub [%1+1],%0" "\n\t" \
"sll %0,16,%0" "\n\t" \
"or %2,%0,%2" "\n\t" \
"ldub [%1+2],%0" "\n\t" \
"sll %0,8,%0" "\n\t" \
"or %2,%0,%2" "\n\t" \
"ldub [%1+3],%0" "\n\t" \
"or %2,%0,%0" "\n\t" \
"b 3f" "\n\t" \
" add %1,4,%1" "\n" \
"2:" "\t" \
"sll %0,25,%0" "\n\t" \
"sra %0,25,%0" "\n" \
"3:" "\t" \
: "=r" (where), "=r" (byteptr), "=r" (dummy) : "1" (byteptr) : "ccr" ); \
}
#endif
#if (defined(GNU) || defined(INTEL)) && defined(I80386) && !defined(NO_ASM)
#undef S_operand
#define S_operand(where) \
__asm__( \
"movzbl (%1),"EAX "\n\t" \
"incl %1" "\n\t" \
"testb "AL","AL "\n\t" \
"jge "LR(1,f) "\n\t" \
"sall $8,"EAX "\n\t" \
"movb (%1),"AL "\n\t" \
"incl %1" "\n\t" \
"sall $17,"EAX "\n\t" \
"sarl $17,"EAX "\n\t" \
"jne "LR(2,f) "\n\t" \
"movb (%1),"AL "\n\t" \
"sall $8,"EAX "\n\t" \
"movb 1(%1),"AL "\n\t" \
"sall $8,"EAX "\n\t" \
"movb 2(%1),"AL "\n\t" \
"sall $8,"EAX "\n\t" \
"movb 3(%1),"AL "\n\t" \
"addl $4,"EAX "\n\t" \
"jmp "LR(2,f) "\n" \
LD(1)":" "\t" \
"sall $25,"EAX "\n\t" \
"sarl $25,"EAX "\n" \
LD(2)":" \
: OUT_EAX (where), "=r" (byteptr) : "1" (byteptr) );
#endif
#if defined(GNU) && defined(ARM) && !defined(NO_ASM)
# Macro written by Peter Burwood.
#undef S_operand
#define S_operand(where) \
{ var uintL dummy; \
__asm__( \
"ldrb %0,[%1],#1" "\n\t" \
"movs %0,%0,LSL#25" "\n\t" \
"movcc %0,%0,ASR#25" "\n\t" \
"bcc "LR(1,f) "\n\t" \
"ldrb %2,[%1],#1" "\n\t" \
"orr %0,%0,%2,LSL#17" "\n\t" \
"movs %0,%0,ASR#17" "\n\t" \
"bne "LR(1,f) "\n\t" \
"ldrb %0,[%1],#1" "\n\t" \
"ldrb %2,[%1],#1" "\n\t" \
"orr %0,%2,%0,LSL#8" "\n\t" \
"ldrb %2,[%1],#1" "\n\t" \
"orr %0,%2,%0,LSL#8" "\n\t" \
"ldrb %2,[%1],#1" "\n\t" \
"orr %0,%2,%0,LSL#8" "\n" \
LD(1)":" \
: "=r" (where), "=r" (byteptr), "=r" (dummy) : "1" (byteptr) : "cc" ); \
}
#endif
#
# Macro S_operand_ignore();
# skips the next Operand (a Signed Integer)
# and advances the bytecodepointer.
#define S_operand_ignore() \
{ var uintB where = *byteptr++; # read first byte \
if ((uintB)where & bit(7)) \
# Bit 7 war gesetzt \
{ if ((uintB)((where<<1) | *byteptr++) == 0) # next Byte \
# special case: 2-Byte-Operand = 0 -> 6-Byte-Operand \
{ byteptr += 4; } \
} }
#if defined(GNU) && defined(MC680X0) && !defined(NO_ASM)
#undef S_operand_ignore
#define S_operand_ignore() \
{ var uintB where; \
__asm__( \
"moveb %1@+,%0" "\n\t" \
"bpl 1f" "\n\t" \
"addb %0,%0" "\n\t" \
"orb %1@+,%0" "\n\t" \
"bne 1f" "\n\t" \
"addql #4,%1" "\n" \
"1:" \
: "=d" (where), "=a" (byteptr) : "1" (byteptr) ); \
}
#endif
#if defined(GNU) && defined(SPARC) && !defined(NO_ASM)
#undef S_operand_ignore
#define S_operand_ignore() \
{ var uintL where; \
var uintL dummy; \
__asm__( \
"ldub [%1],%0" "\n\t" \
"andcc %0,0x80,%%g0" "\n\t" \
"be 1f" "\n\t" \
" add %1,1,%1" "\n\t" \
"sll %0,1,%2" "\n\t" \
"ldub [%1],%0" "\n\t" \
"orcc %2,%0,%0" "\n\t" \
"bne 1f" "\n\t" \
" add %1,1,%1" "\n\t" \
"add %1,4,%1" "\n" \
"1:" \
: "=r" (where), "=r" (byteptr), "=r" (dummy) : "1" (byteptr) : "ccr" ); \
}
#endif
#if defined(GNU) && defined(ARM) && !defined(NO_ASM)
# Macro written by Peter Burwood.
#undef S_operand_ignore
#define S_operand_ignore() \
{ var uintL where; \
var uintL dummy; \
__asm__( \
"ldrb %0,[%1],#1" "\n\t" \
"movs %0,%0,LSL#25" "\n\t" \
"bcc "LR(1,f) "\n\t" \
"ldrb %2,[%1],#1" "\n\t" \
"orrs %0,%2,%0,LSR#24" "\n\t" \
"addeq %1,%1,#4" "\n" \
LD(1)":" \
: "=r" (where), "=r" (byteptr), "=r" (dummy) : "1" (byteptr) : "cc" ); \
}
#endif
#
# Macro L_operand(where);
# moves the next Operand (a Label)
# to (uintB*)where and advances the bytecodepointer.
#define L_operand(Lwhere) \
{ var uintL where; # variable for the displacement \
S_operand(where); # Displacement \
Lwhere = byteptr + (sintL)where; # add \
}
#
# Macro L_operand_ignore();
# skips the next Operand (a Label)
# and advances the Bytecodepointer.
#define L_operand_ignore() S_operand_ignore()
#
# Each of the bytecodes is interpreted:
# for the most part: mv_count/mv_space = values,
# closureptr = pointer to the compiled closure in Stack,
# closure = compiled closure,
# codeptr = pointer to its codevector,
# byteptr = pointer to the next Byte in code.
# (byteptr is no LISP-object, but nevertheless endangered by GC!
# To make it GC-invariant, substract CODEPTR from it.
# If one then adds Fixnum_0 to it,
# one receives the bytenumber as Fixnum.)
#if 0
#define CODEPTR (&codeptr->data[0])
#else # returns more efficient Code
#define CODEPTR (uintB*)(codeptr)
#endif
#
# store context-information:
# If sth. is called, that can trigger a GC, this must be framed within
# with_saved_context( ... ) .
#define with_saved_context(statement) \
{ var uintL index = byteptr - CODEPTR; \
statement; \
closure = *closureptr; # fetch Closure from Stack \
codeptr = TheSbvector(TheCclosure(closure)->clos_codevec); \
byteptr = CODEPTR + index; \
}
#
# ------------------- (1) Constants -----------------------
CASE cod_nil: # (NIL)
code_nil:
VALUES1(NIL);
goto next_byte;
CASE cod_nil_push: # (NIL&PUSH)
pushSTACK(NIL);
goto next_byte;
CASE cod_push_nil: # (PUSH-NIL n)
{
var uintC n;
U_operand(n);
dotimesC(n,n, { pushSTACK(NIL); } );
}
goto next_byte;
CASE cod_t: # (T)
code_t:
VALUES1(T);
goto next_byte;
CASE cod_t_push: # (T&PUSH)
pushSTACK(T);
goto next_byte;
CASE cod_const: # (CONST n)
{
var uintL n;
U_operand(n);
VALUES1(TheCclosure(closure)->clos_consts[n]);
}
goto next_byte;
CASE cod_const_push: # (CONST&PUSH n)
{
var uintL n;
U_operand(n);
pushSTACK(TheCclosure(closure)->clos_consts[n]);
}
goto next_byte;
# ------------------- (2) static Variables -----------------------
CASE cod_load: # (LOAD n)
{
var uintL n;
U_operand(n);
VALUES1(STACK_(n));
}
goto next_byte;
CASE cod_load_push: # (LOAD&PUSH n)
{
var uintL n;
U_operand(n);
pushSTACK(STACK_(n));
}
goto next_byte;
CASE cod_loadi: # (LOADI k1 k2 n)
{
var uintL k1;
var uintL k2;
var uintL n;
U_operand(k1);
U_operand(k2);
U_operand(n);
var gcv_object_t* FRAME = (gcv_object_t*) SP_(k1+jmpbufsize*k2);
VALUES1(FRAME_(n));
}
goto next_byte;
CASE cod_loadi_push: # (LOADI&PUSH k1 k2 n)
{
var uintL k1;
var uintL k2;
var uintL n;
U_operand(k1);
U_operand(k2);
U_operand(n);
var gcv_object_t* FRAME = (gcv_object_t*) SP_(k1+jmpbufsize*k2);
pushSTACK(FRAME_(n));
}
goto next_byte;
CASE cod_loadc: # (LOADC n m)
{
var uintL n;
var uintL m;
U_operand(n);
U_operand(m);
VALUES1(TheSvector(STACK_(n))->data[1+m]);
}
goto next_byte;
CASE cod_loadc_push: # (LOADC&PUSH n m)
{
var uintL n;
var uintL m;
U_operand(n);
U_operand(m);
pushSTACK(TheSvector(STACK_(n))->data[1+m]);
}
goto next_byte;
CASE cod_loadv: # (LOADV k m)
{
var uintC k;
var uintL m;
U_operand(k);
U_operand(m);
var object venv = TheCclosure(closure)->clos_venv; # VenvConst
# take (svref ... 0) k times:
dotimesC(k,k, { venv = TheSvector(venv)->data[0]; } );
# fetch (svref ... m) :
VALUES1(TheSvector(venv)->data[m]);
}
goto next_byte;
CASE cod_loadv_push: # (LOADV&PUSH k m)
{
var uintC k;
var uintL m;
U_operand(k);
U_operand(m);
var object venv = TheCclosure(closure)->clos_venv; # VenvConst
# take (svref ... 0) k times:
dotimesC(k,k, { venv = TheSvector(venv)->data[0]; } );
# fetch (svref ... m) :
pushSTACK(TheSvector(venv)->data[m]);
}
goto next_byte;
CASE cod_loadic: # (LOADIC k1 k2 n m)
{
var uintL k1;
var uintL k2;
var uintL n;
var uintL m;
U_operand(k1);
U_operand(k2);
U_operand(n);
U_operand(m);
var gcv_object_t* FRAME = (gcv_object_t*) SP_(k1+jmpbufsize*k2);
VALUES1(TheSvector(FRAME_(n))->data[1+m]);
}
goto next_byte;
CASE cod_store: store: # (STORE n)
{
var uintL n;
U_operand(n);
VALUES1(STACK_(n) = value1);
}
goto next_byte;
CASE cod_pop_store: # (POP&STORE n)
{
var uintL n;
U_operand(n);
var object obj = popSTACK();
VALUES1(STACK_(n) = obj);
}
goto next_byte;
CASE cod_storei: # (STOREI k1 k2 n)
{
var uintL k1;
var uintL k2;
var uintL n;
U_operand(k1);
U_operand(k2);
U_operand(n);
var gcv_object_t* FRAME = (gcv_object_t*) SP_(k1+jmpbufsize*k2);
VALUES1(FRAME_(n) = value1);
}
goto next_byte;
CASE cod_load_storec: # (LOAD&STOREC k m n)
{
var uintL k;
U_operand(k);
value1 = STACK_(k);
}
CASE cod_storec: # (STOREC n m)
{
var uintL n;
var uintL m;
U_operand(n);
U_operand(m);
TheSvector(STACK_(n))->data[1+m] = value1; mv_count=1;
}
goto next_byte;
CASE cod_storev: # (STOREV k m)
{
var uintC k;
var uintL m;
U_operand(k);
U_operand(m);
var object venv = TheCclosure(closure)->clos_venv; # VenvConst
# take (svref ... 0) k times:
dotimesC(k,k, { venv = TheSvector(venv)->data[0]; } );
# save (svref ... m) :
TheSvector(venv)->data[m] = value1; mv_count=1;
}
goto next_byte;
CASE cod_storeic: # (STOREIC k1 k2 n m)
{
var uintL k1;
var uintL k2;
var uintL n;
var uintL m;
U_operand(k1);
U_operand(k2);
U_operand(n);
U_operand(m);
var gcv_object_t* FRAME = (gcv_object_t*) SP_(k1+jmpbufsize*k2);
TheSvector(FRAME_(n))->data[1+m] = value1; mv_count=1;
}
goto next_byte;
# ------------------- (3) dynamic Variables -----------------------
CASE cod_getvalue: # (GETVALUE n)
{
var uintL n;
U_operand(n);
var object symbol = TheCclosure(closure)->clos_consts[n];
# The Compiler has already checked, that it's a Symbol.
if (!boundp(Symbol_value(symbol))) {
pushSTACK(symbol); # CELL-ERROR slot NAME
pushSTACK(symbol); pushSTACK(Closure_name(closure));
fehler(unbound_variable,GETTEXT("~S: symbol ~S has no value"));
}
VALUES1(Symbol_value(symbol));
}
goto next_byte;
CASE cod_getvalue_push: # (GETVALUE&PUSH n)
{
var uintL n;
U_operand(n);
var object symbol = TheCclosure(closure)->clos_consts[n];
# The Compiler has already checked, that it's a Symbol.
if (!boundp(Symbol_value(symbol))) {
pushSTACK(symbol); # CELL-ERROR slot NAME
pushSTACK(symbol); pushSTACK(Closure_name(closure));
fehler(unbound_variable,GETTEXT("~S: symbol ~S has no value"));
}
pushSTACK(Symbol_value(symbol));
}
goto next_byte;
CASE cod_setvalue: # (SETVALUE n)
{
var uintL n;
U_operand(n);
var object symbol = TheCclosure(closure)->clos_consts[n];
# The Compiler has already checked, that it's a Symbol.
if (constant_var_p(TheSymbol(symbol))) {
pushSTACK(symbol); pushSTACK(Closure_name(closure));
fehler(error,GETTEXT("~S: assignment to constant symbol ~S is impossible"));
}
Symbol_value(symbol) = value1; mv_count=1;
}
goto next_byte;
CASE cod_bind: # (BIND n)
{
var uintL n;
U_operand(n);
dynamic_bind(TheCclosure(closure)->clos_consts[n],value1);
}
goto next_byte;
CASE cod_unbind1: # (UNBIND1)
#if STACKCHECKC
if (!(framecode(STACK_0) == DYNBIND_frame_info))
GOTO_ERROR(fehler_STACK_putt);
#endif
# unwind variable-binding-frame:
{
var gcv_object_t* new_STACK = topofframe(STACK_0); # pointer above frame
var gcv_object_t* frame_end = STACKpointable(new_STACK);
var gcv_object_t* bindingptr = &STACK_1; # begin of bindings
# bindingptr loops upwards through the bindings
until (bindingptr == frame_end) {
# write back old value:
Symbol_value(*(bindingptr STACKop 0)) = *(bindingptr STACKop 1);
bindingptr skipSTACKop 2; # next binding
}
# set STACK newly, thus unwind frame:
setSTACK(STACK = new_STACK);
}
goto next_byte;
CASE cod_unbind: # (UNBIND n)
{
var uintC n;
U_operand(n); # n>0
var gcv_object_t* FRAME = STACK;
do {
#if STACKCHECKC
if (!(framecode(FRAME_(0)) == DYNBIND_frame_info))
GOTO_ERROR(fehler_STACK_putt);
#endif
# unwind variable-binding-frame:
var gcv_object_t* new_FRAME = topofframe(FRAME_(0)); # pointer above frame
var gcv_object_t* frame_end = STACKpointable(new_FRAME);
var gcv_object_t* bindingptr = &FRAME_(1); # begin of the bindings
# bindingptr loops upwards through the bindings
until (bindingptr == frame_end) {
# write back old value:
Symbol_value(*(bindingptr STACKop 0)) = *(bindingptr STACKop 1);
bindingptr skipSTACKop 2; # next binding
}
FRAME = new_FRAME;
} until (--n == 0);
setSTACK(STACK = FRAME); # set STACK newly
}
goto next_byte;
CASE cod_progv: # (PROGV)
{
var object vallist = value1; # value-list
var object symlist = popSTACK(); # symbol-list
pushSP((aint)STACK); # push STACK into SP
with_saved_context( progv(symlist,vallist); ); # build frame
}
goto next_byte;
# ------------------- (4) Stackoperations -----------------------
CASE cod_push: # (PUSH)
pushSTACK(value1);
goto next_byte;
CASE cod_pop: # (POP)
VALUES1(popSTACK());
goto next_byte;
CASE cod_skip: # (SKIP n)
{
var uintL n;
U_operand(n);
skipSTACK(n);
}
goto next_byte;
CASE cod_skipi: # (SKIPI k1 k2 n)
{
var uintL k1;
var uintL k2;
var uintL n;
U_operand(k1);
U_operand(k2);
U_operand(n);
skipSP(k1+jmpbufsize*k2);
var gcv_object_t* newSTACK;
popSP( newSTACK = (gcv_object_t*) );
setSTACK(STACK = newSTACK STACKop n);
}
goto next_byte;
CASE cod_skipsp: # (SKIPSP k1 k2)
{
var uintL k1;
var uintL k2;
U_operand(k1);
U_operand(k2);
skipSP(k1+jmpbufsize*k2);
}
goto next_byte;
# ------------------- (5) Control Flow and Jumps -----------------------
CASE cod_skip_ret: # (SKIP&RET n)
{
var uintL n;
U_operand(n);
skipSTACK(n);
goto finished; # return (jump) to caller
}
CASE cod_skip_retgf: # (SKIP&RETGF n)
{
var uintL n;
U_operand(n);
if (((Codevec)codeptr)->ccv_flags & bit(3)) { # call inhibition?
skipSTACK(n);
mv_count=1;
goto finished; # return (jump) to caller
}
# It is known (refer to clos.lisp), that this function
# has no optional parameters, but poss. Rest-parameters.
# If there's no Rest-parameter: (FUNCALL value1 arg1 ... argr)
# If there's a Rest-Parameter: (APPLY value1 arg1 ... argr restarg)
var uintL r = ((Codevec)codeptr)->ccv_numreq;
n -= r;
if (((Codevec)codeptr)->ccv_flags & bit(0)) {
skipSTACK(n-1); apply(value1,r,popSTACK());
} else {
skipSTACK(n); funcall(value1,r);
}
goto finished; # return (jump) to caller
}
#define JMP() \
{ var const uintB* label_byteptr; \
L_operand(label_byteptr); \
DEBUG_CHECK_BYTEPTR(label_byteptr); \
byteptr = label_byteptr; \
goto next_byte; \
}
#define NOTJMP() \
{ L_operand_ignore(); goto next_byte; }
jmp1: mv_count=1;
CASE cod_jmp: jmp: # (JMP label)
JMP();
CASE cod_jmpif: # (JMPIF label)
if (!nullp(value1)) goto jmp;
notjmp:
NOTJMP();
CASE cod_jmpifnot: # (JMPIFNOT label)
if (nullp(value1)) goto jmp;
NOTJMP();
CASE cod_jmpif1: # (JMPIF1 label)
if (!nullp(value1)) goto jmp1;
NOTJMP();
CASE cod_jmpifnot1: # (JMPIFNOT1 label)
if (nullp(value1)) goto jmp1;
NOTJMP();
CASE cod_jmpifatom: # (JMPIFATOM label)
if (atomp(value1)) goto jmp;
NOTJMP();
CASE cod_jmpifconsp: # (JMPIFCONSP label)
if (consp(value1)) goto jmp;
NOTJMP();
CASE cod_jmpifeq: # (JMPIFEQ label)
if (eq(popSTACK(),value1)) goto jmp;
NOTJMP();
CASE cod_jmpifnoteq: # (JMPIFNOTEQ label)
if (!eq(popSTACK(),value1)) goto jmp;
NOTJMP();
CASE cod_jmpifeqto: # (JMPIFEQTO n label)
{
var uintL n;
U_operand(n);
if (eq(popSTACK(),TheCclosure(closure)->clos_consts[n])) goto jmp;
}
NOTJMP();
CASE cod_jmpifnoteqto: # (JMPIFNOTEQTO n label)
{
var uintL n;
U_operand(n);
if (!eq(popSTACK(),TheCclosure(closure)->clos_consts[n])) goto jmp;
}
NOTJMP();
CASE cod_jmphash: # (JMPHASH n label)
{
var uintL n;
U_operand(n);
var object hashvalue = # search value1 in the Hash-table
gethash(value1,TheCclosure(closure)->clos_consts[n],false);
if (eq(hashvalue,nullobj))
goto jmp; # not found -> jump to label
else { /* interpret found Fixnum as label: */
DEBUG_CHECK_BYTEPTR(byteptr + fixnum_to_V(hashvalue));
byteptr += fixnum_to_V(hashvalue);
}
}
goto next_byte;
CASE cod_jmphashv: # (JMPHASHV n label)
{
var uintL n;
U_operand(n);
var object hashvalue = # search value1 in the Hash-table
gethash(value1,TheSvector(TheCclosure(closure)->clos_consts[0])->data[n],false);
if (eq(hashvalue,nullobj))
goto jmp; # not found -> jump to label
else { /* interpret found Fixnum as label: */
DEBUG_CHECK_BYTEPTR(byteptr + fixnum_to_V(hashvalue));
byteptr += fixnum_to_V(hashvalue);
}
}
goto next_byte;
# executes a (JSR label)-command.
#define JSR() \
check_STACK(); check_SP(); \
{ var const uintB* label_byteptr; \
L_operand(label_byteptr); \
with_saved_context( \
with_saved_back_trace_cclosure(closure, \
interpret_bytecode_(closure,codeptr,label_byteptr); \
)); \
}
CASE cod_jsr: # (JSR label)
JSR();
goto next_byte;
CASE cod_jsr_push: # (JSR&PUSH label)
JSR(); pushSTACK(value1);
goto next_byte;
CASE cod_jmptail: # (JMPTAIL m n label)
{
var uintL m;
var uintL n;
U_operand(m);
U_operand(n);
# It is n>=m. Copy m stack-entries upwards by n-m :
var gcv_object_t* ptr1 = STACK STACKop m;
var gcv_object_t* ptr2 = STACK STACKop n;
var uintC count;
dotimesC(count,m, { NEXT(ptr2) = NEXT(ptr1); } );
# Now ptr1 = STACK and ptr2 = STACK STACKop (n-m).
*(closureptr = &NEXT(ptr2)) = closure; # store closure in stack
setSTACK(STACK = ptr2); # shorten STACK
}
JMP(); # jump to label
# ------------------- (6) Environments and Closures -----------------------
CASE cod_venv: # (VENV)
# fetch VenvConst from the closure:
VALUES1(TheCclosure(closure)->clos_venv);
goto next_byte;
CASE cod_make_vector1_push: # (MAKE-VECTOR1&PUSH n)
{
var uintL n;
U_operand(n);
pushSTACK(value1);
# create vector:
var object vec;
with_saved_context( { vec = allocate_vector(n+1); } );
# fill first element:
TheSvector(vec)->data[0] = STACK_0;
STACK_0 = vec;
}
goto next_byte;
CASE cod_copy_closure: # (COPY-CLOSURE m n)
{
var object oldclos;
# fetch closure to be copied:
{
var uintL m;
U_operand(m);
oldclos = TheCclosure(closure)->clos_consts[m];
}
# allocate closure of equal length:
var object newclos;
pushSTACK(oldclos);
with_saved_context(
newclos = allocate_cclosure_copy(oldclos);
);
oldclos = popSTACK();
# copy contents of the old closure into the new one:
do_cclosure_copy(newclos,oldclos);
# copy stack content into the new closure:
{
var uintL n;
U_operand(n);
var gcv_object_t* newptr = &TheCclosure(newclos)->clos_consts[n];
dotimespL(n,n, { *--newptr = popSTACK(); } );
}
VALUES1(newclos);
}
goto next_byte;
CASE cod_copy_closure_push: # (COPY-CLOSURE&PUSH m n)
{
var object oldclos;
# fetch closure to be copied:
{
var uintL m;
U_operand(m);
oldclos = TheCclosure(closure)->clos_consts[m];
}
# allocate closure of equal length:
var object newclos;
pushSTACK(oldclos);
with_saved_context(
newclos = allocate_cclosure_copy(oldclos);
);
oldclos = popSTACK();
# copy contents of the old closure into the new one:
do_cclosure_copy(newclos,oldclos);
# copy stack content into the new closure:
{
var uintL n;
U_operand(n);
var gcv_object_t* newptr = &TheCclosure(newclos)->clos_consts[n];
dotimespL(n,n, { *--newptr = popSTACK(); } );
}
pushSTACK(newclos);
}
goto next_byte;
# ------------------- (7) Function Calls -----------------------
# executes (CALL k n)-command.
#define CALL() \
{ var uintC k; # number of arguments \
var uintL n; \
U_operand(k); \
U_operand(n); \
with_saved_context( \
funcall(TheCclosure(closure)->clos_consts[n],k); \
); \
}
# executes (CALL0 n)-command.
#define CALL0() \
{ var uintL n; \
U_operand(n); \
with_saved_context( \
funcall(TheCclosure(closure)->clos_consts[n],0); \
); \
}
# executes (CALL1 n)-command.
#define CALL1() \
{ var uintL n; \
U_operand(n); \
with_saved_context( \
funcall(TheCclosure(closure)->clos_consts[n],1); \
); \
}
# executes (CALL2 n)-command.
#define CALL2() \
{ var uintL n; \
U_operand(n); \
with_saved_context( \
funcall(TheCclosure(closure)->clos_consts[n],2); \
); \
}
# executes (CALLS1 n)-command.
#define CALLS1() \
{ var uintL n; \
B_operand(n); \
# The compiler has already done the argument-check. \
{var Subr fun = FUNTAB1[n]; \
with_saved_context( \
with_saved_back_trace_subr(subr_tab_ptr_as_object(fun),STACK,-1, \
(*(subr_norest_function_t*)(fun->function))(); \
)); \
}}
# executes (CALLS2 n)-command.
#define CALLS2() \
{ var uintL n; \
B_operand(n); \
# The compiler has already done the argument-check. \
{var Subr fun = FUNTAB2[n]; \
with_saved_context( \
with_saved_back_trace_subr(subr_tab_ptr_as_object(fun),STACK,-1, \
(*(subr_norest_function_t*)(fun->function))(); \
)); \
}}
# executes (CALLSR m n)-command.
#define CALLSR() \
{ var uintL m; \
var uintL n; \
U_operand(m); \
B_operand(n); \
# The compiler has already done the argument-check. \
{var Subr fun = FUNTABR[n]; \
with_saved_context( \
with_saved_back_trace_subr(subr_tab_ptr_as_object(fun),STACK,-1, \
(*(subr_rest_function_t*)(fun->function))(m,args_end_pointer STACKop m); \
)); \
}}
CASE cod_call: # (CALL k n)
CALL();
goto next_byte;
CASE cod_call_push: # (CALL&PUSH k n)
CALL(); pushSTACK(value1);
goto next_byte;
CASE cod_call0: # (CALL0 n)
CALL0();
goto next_byte;
CASE cod_call1: # (CALL1 n)
CALL1();
goto next_byte;
CASE cod_call1_push: # (CALL1&PUSH n)
CALL1(); pushSTACK(value1);
goto next_byte;
CASE cod_call2: # (CALL2 n)
CALL2();
goto next_byte;
CASE cod_call2_push: # (CALL2&PUSH n)
CALL2(); pushSTACK(value1);
goto next_byte;
CASE cod_calls1: # (CALLS1 n)
CALLS1();
goto next_byte;
CASE cod_calls1_push: # (CALLS1&PUSH n)
CALLS1(); pushSTACK(value1);
goto next_byte;
CASE cod_calls2: # (CALLS2 n)
CALLS2();
goto next_byte;
CASE cod_calls2_push: # (CALLS2&PUSH n)
CALLS2(); pushSTACK(value1);
goto next_byte;
CASE cod_callsr: # (CALLSR m n)
CALLSR();
goto next_byte;
CASE cod_callsr_push: # (CALLSR&PUSH m n)
CALLSR(); pushSTACK(value1);
goto next_byte;
# executes a (CALLC)-command.
#define CALLC() \
{ check_STACK(); check_SP(); # check STACK and SP \
with_saved_context( \
# interprete compiled closure starting at Byte 8 \
interpret_bytecode(value1,TheCclosure(value1)->clos_codevec,CCV_START_NONKEY); \
); \
}
# executes a (CALLCKEY)-command.
#define CALLCKEY() \
{ check_STACK(); check_SP(); # check STACK and SP \
with_saved_context( \
# interprete compiled closure starting at Byte 12: \
interpret_bytecode(value1,TheCclosure(value1)->clos_codevec,CCV_START_KEY); \
); \
}
CASE cod_callc: # (CALLC)
CALLC();
goto next_byte;
CASE cod_callc_push: # (CALLC&PUSH)
CALLC(); pushSTACK(value1);
goto next_byte;
CASE cod_callckey: # (CALLCKEY)
CALLCKEY();
goto next_byte;
CASE cod_callckey_push: # (CALLCKEY&PUSH)
CALLCKEY(); pushSTACK(value1);
goto next_byte;
CASE cod_funcall: # (FUNCALL n)
{
var uintL n;
U_operand(n);
var object fun = STACK_(n); # Function
with_saved_context( funcall(fun,n); ); # call Function
skipSTACK(1); # discard function from Stack
}
goto next_byte;
CASE cod_funcall_push: # (FUNCALL&PUSH n)
{
var uintL n;
U_operand(n);
var object fun = STACK_(n); # Function
with_saved_context( funcall(fun,n); ); # call Function
STACK_0 = value1; # replace Function in Stack by value
}
goto next_byte;
CASE cod_apply: # (APPLY n)
{
var uintL n;
U_operand(n);
var object fun = STACK_(n); # Function
with_saved_context( apply(fun,n,value1); ); # call Function
skipSTACK(1); # discard Function from Stack
}
goto next_byte;
CASE cod_apply_push: # (APPLY&PUSH n)
{
var uintL n;
U_operand(n);
var object fun = STACK_(n); # Function
with_saved_context( apply(fun,n,value1); ); # call Function
STACK_0 = value1; # replace Function in Stack by value
}
goto next_byte;
# ------------------- (8) optional and Keyword-arguments -----------------------
CASE cod_push_unbound: # (PUSH-UNBOUND n)
{
var uintC n;
U_operand(n);
dotimesC(n,n, { pushSTACK(unbound); } );
}
goto next_byte;
CASE cod_unlist: # (UNLIST n m)
{
var uintC n;
var uintC m;
U_operand(n);
U_operand(m);
var object l = value1;
if (n > 0)
do {
if (atomp(l)) goto unlist_unbound;
pushSTACK(Car(l)); l = Cdr(l);
} until (--n == 0);
if (atomp(l))
goto next_byte;
else
fehler_apply_zuviel(S(lambda));
unlist_unbound:
if (n > m) fehler_apply_zuwenig(S(lambda),l);
do { pushSTACK(unbound); } until (--n == 0);
goto next_byte;
}
CASE cod_unliststern: # (UNLIST* n m)
{
var uintC n;
var uintC m;
U_operand(n);
U_operand(m);
var object l = value1;
do {
if (atomp(l)) goto unliststern_unbound;
pushSTACK(Car(l)); l = Cdr(l);
} until (--n == 0);
pushSTACK(l);
goto next_byte;
unliststern_unbound:
if (n > m) fehler_apply_zuwenig(S(lambda),l);
do { pushSTACK(unbound); } until (--n == 0);
pushSTACK(NIL);
goto next_byte;
}
CASE cod_jmpifboundp: # (JMPIFBOUNDP n label)
{
var uintL n;
U_operand(n);
var object obj = STACK_(n);
if (!boundp(obj)) goto notjmp;
VALUES1(obj); JMP();
}
CASE cod_boundp: # (BOUNDP n)
{
var uintL n;
U_operand(n);
var object obj = STACK_(n);
if (!boundp(obj)) goto code_nil; else goto code_t;
}
CASE cod_unbound_nil: # (UNBOUND->NIL n)
{
var uintL n;
U_operand(n);
if (!boundp(STACK_(n))) { STACK_(n) = NIL; }
}
goto next_byte;
# ------------------- (9) Treatment of multiple values -----------------------
CASE cod_values0: # (VALUES0)
VALUES0;
goto next_byte;
CASE cod_values1: # (VALUES1)
mv_count = 1;
goto next_byte;
CASE cod_stack_to_mv: # (STACK-TO-MV n)
{
var uintL n;
U_operand(n);
if (n >= mv_limit) GOTO_ERROR(fehler_zuviele_werte);
STACK_to_mv(n);
}
goto next_byte;
CASE cod_mv_to_stack: # (MV-TO-STACK)
mv_to_STACK(); # push values on Stack
goto next_byte;
CASE cod_nv_to_stack: # (NV-TO-STACK n)
{
var uintL n;
U_operand(n);
# test for Stack-Overflow:
get_space_on_STACK(n*sizeof(gcv_object_t));
# push n values in the Stack:
var uintC count = mv_count;
if (n==0) goto nv_to_stack_end; # no value desired -> finished
# at least 1 value desired
pushSTACK(value1);
n--; if (n==0) goto nv_to_stack_end; # only 1 value desired -> finished
if (count<=1) goto nv_to_stack_fill; # only 1 value present -> fill with NILs
count--;
# at least 2 values desired and present
{
var object* mvp = &mv_space[1];
loop {
pushSTACK(*mvp++);
n--; if (n==0) goto nv_to_stack_end; # no further value desired -> finished
count--; if (count==0) goto nv_to_stack_fill; # no further value present -> fill with NILs
}
}
nv_to_stack_fill: # fill up with n>0 NILs as additional values:
dotimespL(n,n, { pushSTACK(NIL); } );
nv_to_stack_end: ;
}
goto next_byte;
CASE cod_mv_to_list: # (MV-TO-LIST)
with_saved_context(
# push values on Stack and handicraft list out of it:
mv_to_list();
);
VALUES1(popSTACK());
goto next_byte;
CASE cod_list_to_mv: # (LIST-TO-MV)
list_to_mv(value1, GOTO_ERROR(fehler_zuviele_werte));
goto next_byte;
CASE cod_mvcallp: # (MVCALLP)
pushSP((aint)STACK); # save STACK
pushSTACK(value1); # save function to be executed
goto next_byte;
CASE cod_mvcall: # (MVCALL)
{
var gcv_object_t* FRAME; popSP( FRAME = (gcv_object_t*) ); # Pointer to Arguments and Function
var object fun = NEXT(FRAME); # Function
with_saved_context({
var uintL argcount = # number of arguments on stack
STACK_item_count(STACK,FRAME);
if (((uintL)~(uintL)0 > ca_limit_1) && (argcount > ca_limit_1)) {
pushSTACK(fun);
pushSTACK(S(multiple_value_call));
/* ANSI CL 3.5.1.3. wants a PROGRAM-ERROR here. */
fehler(program_error,
GETTEXT("~S: too many arguments given to ~S"));
}
# apply Function, lift Stack until below the Function:
funcall(fun,argcount);
skipSTACK(1); # discard Function from STACK
});
}
goto next_byte;
# ------------------- (10) BLOCK -----------------------
CASE cod_block_open: # (BLOCK-OPEN n label)
# occupies 3 STACK-entries and 1 SP-jmp_buf-entry and 2 SP-entries
{
var uintL n;
var sintL label_dist;
U_operand(n);
S_operand(label_dist);
# create Block_Cons:
var object block_cons;
with_saved_context(
block_cons = allocate_cons();
label_dist += index; # CODEPTR+label_dist is the jump destination
);
# fill Block-Cons: (CONST n) as CAR
Car(block_cons) = TheCclosure(closure)->clos_consts[n];
# jump destination into SP:
pushSP(label_dist); pushSP((aint)closureptr);
# build up CBLOCK-Frame:
{
var gcv_object_t* top_of_frame = STACK; # Pointer above Frame
pushSTACK(block_cons); # Cons ( (CONST n) . ...)
var JMPBUF_on_SP(returner); # memorize return-point
finish_entry_frame_1(CBLOCK,returner, goto block_return; );
}
# store Framepointer in Block-Cons:
Cdr(block_cons) = make_framepointer(STACK);
}
goto next_byte;
block_return: # jump to this label takes place, if the previously
# built CBLOCK-Frame has catched a RETURN-FROM.
{
FREE_JMPBUF_on_SP();
skipSTACK(2); # unwind CBLOCK-Frame and mark
Cdr(popSTACK()) = disabled; # Block-Cons as Disabled
var uintL index;
# get closure back, byteptr:=label_byteptr :
popSP(closureptr = (gcv_object_t*) ); popSP(index = );
closure = *closureptr; # fetch Closure from Stack
codeptr = TheSbvector(TheCclosure(closure)->clos_codevec);
DEBUG_CHECK_BYTEPTR(CODEPTR + index);
byteptr = CODEPTR + index;
}
goto next_byte; # continue interpretation at Label
CASE cod_block_close: # (BLOCK-CLOSE)
# unwind CBLOCK-Frame:
#if STACKCHECKC
if (!(framecode(STACK_0) == CBLOCK_frame_info))
GOTO_ERROR(fehler_STACK_putt);
#endif
{
FREE_JMPBUF_on_SP();
skipSTACK(2); # unwind CBLOCK-Frame and mark
Cdr(popSTACK()) = disabled; # Block-Cons as Disabled
skipSP(2); # we know Destination-Closureptr and Destination-Label
}
goto next_byte; # at Label continue interpretation
CASE cod_return_from: # (RETURN-FROM n)
{
var uintL n;
U_operand(n);
var object block_cons = TheCclosure(closure)->clos_consts[n];
if (eq(Cdr(block_cons),disabled))
fehler_block_left(Car(block_cons));
# unwind upto Block-Frame, then jump to its routine for freeing:
#ifndef FAST_SP
FREE_DYNAMIC_ARRAY(private_SP_space);
#endif
unwind_upto(uTheFramepointer(Cdr(block_cons)));
}
CASE cod_return_from_i: # (RETURN-FROM-I k1 k2 n)
{
var uintL k1;
var uintL k2;
var uintL n;
U_operand(k1);
U_operand(k2);
U_operand(n);
var gcv_object_t* FRAME = (gcv_object_t*) SP_(k1+jmpbufsize*k2);
var object block_cons = FRAME_(n);
if (eq(Cdr(block_cons),disabled))
fehler_block_left(Car(block_cons));
# unwind upto Block-Frame, then jump to its routine for freeing:
#ifndef FAST_SP
FREE_DYNAMIC_ARRAY(private_SP_space);
#endif
unwind_upto(uTheFramepointer(Cdr(block_cons)));
}
# ------------------- (11) TAGBODY -----------------------
CASE cod_tagbody_open: # (TAGBODY-OPEN n label1 ... labelm)
# occupies 3+m STACK-Entries and 1 SP-jmp_buf-Entry and 1 SP-Entry
{
var uintL n;
U_operand(n);
# create Tagbody-Cons:
var object tagbody_cons;
with_saved_context(
tagbody_cons = allocate_cons();
);
# fill Tagbody-Cons: Tag-Vector (CONST n) as CAR
{
var object tag_vector = TheCclosure(closure)->clos_consts[n];
var uintL m = Svector_length(tag_vector);
Car(tagbody_cons) = tag_vector;
get_space_on_STACK(m*sizeof(gcv_object_t)); # allocate space
# push all labeli as Fixnums on the STACK:
var uintL count;
dotimespL(count,m, {
var const uintB* label_byteptr;
L_operand(label_byteptr);
pushSTACK(fixnum(label_byteptr - CODEPTR));
});
}
# jump destination in the SP:
pushSP((aint)closureptr);
# build upCTAGBODY-Frame:
{
var gcv_object_t* top_of_frame = STACK; # Pointer above Frame
pushSTACK(tagbody_cons); # Cons ( (CONST n) . ...)
var JMPBUF_on_SP(returner); # memorize return-point
finish_entry_frame_1(CTAGBODY,returner, goto tagbody_go; );
}
# store Framepointer in Tagbody-Cons:
Cdr(tagbody_cons) = make_framepointer(STACK);
}
goto next_byte;
tagbody_go: # jump to this label takes place, if the previously
# built CTAGBODY-Frame has catched a GO to Label nr. i.
{
var uintL m = Svector_length(Car(STACK_2)); # Number of Labels
# (I could also declare the m above as 'auto' and use it here.)
var uintL i = posfixnum_to_V(value1); # Number of Labels
var uintL index = posfixnum_to_V(STACK_((m-i)+3)); # labeli
# get closure back, byteptr:=labeli_byteptr :
closureptr = (gcv_object_t*) SP_(jmpbufsize+0);
closure = *closureptr; # fetch Closure from Stack
codeptr = TheSbvector(TheCclosure(closure)->clos_codevec);
DEBUG_CHECK_BYTEPTR(CODEPTR + index);
byteptr = CODEPTR + index;
}
goto next_byte; # continue interpretation at Label i
CASE cod_tagbody_close_nil: # (TAGBODY-CLOSE-NIL)
VALUES1(NIL); /* value of Tagbody is NIL */
CASE cod_tagbody_close: # (TAGBODY-CLOSE)
# unwind CTAGBODY-Frame:
#if STACKCHECKC
if (!(framecode(STACK_0) == CTAGBODY_frame_info))
GOTO_ERROR(fehler_STACK_putt);
#endif
{
FREE_JMPBUF_on_SP();
var object tagbody_cons = STACK_2; # Tagbody-Cons
Cdr(tagbody_cons) = disabled; # mark as Disabled
skipSTACK(3+Svector_length(Car(tagbody_cons)));
skipSP(1);
}
goto next_byte;
CASE cod_go: # (GO n l)
{
var uintL n;
var uintL l;
U_operand(n);
U_operand(l);
var object tagbody_cons = # (CONST n)
TheCclosure(closure)->clos_consts[n];
if (eq(Cdr(tagbody_cons),disabled)) {
var object tag_vector = Car(tagbody_cons);
pushSTACK(tag_vector);
pushSTACK(TheSvector(tag_vector)->data[l]); # label l
pushSTACK(S(go));
fehler(control_error,
GETTEXT("(~S ~S): the tagbody of the tags ~S has already been left"));
}
# value passed to the Tagbody:
# For CTAGBODY-Frames: 1+l as Fixnum,
# For ITAGBODY-Frames: the form-list for Tag nr. l.
var gcv_object_t* FRAME = uTheFramepointer(Cdr(tagbody_cons));
VALUES1(framecode(FRAME_(0)) == CTAGBODY_frame_info
? fixnum(1+l)
: (object)FRAME_(frame_bindings+2*l+1));
# unwind upto Tagbody-Frame, then jump to its Routine,
# which then jumps to Label l:
#ifndef FAST_SP
FREE_DYNAMIC_ARRAY(private_SP_space);
#endif
unwind_upto(FRAME);
}
CASE cod_go_i: # (GO-I k1 k2 n l)
{
var uintL k1;
var uintL k2;
var uintL n;
var uintL l;
U_operand(k1);
U_operand(k2);
U_operand(n);
U_operand(l);
var gcv_object_t* FRAME = (gcv_object_t*) SP_(k1+jmpbufsize*k2);
var object tagbody_cons = FRAME_(n);
if (eq(Cdr(tagbody_cons),disabled)) {
var object tag_vector = Car(tagbody_cons);
pushSTACK(tag_vector);
pushSTACK(TheSvector(tag_vector)->data[l]); # label l
pushSTACK(S(go));
fehler(control_error,
GETTEXT("(~S ~S): the tagbody of the tags ~S has already been left"));
}
# value passed to Tagbody:
# For CTAGBODY-Frames 1+l as Fixnum.
FRAME = uTheFramepointer(Cdr(tagbody_cons));
VALUES1(fixnum(1+l));
# unwind upto Tagbody-Frame, then jump to its Routine,
# which then jumps to Label l:
#ifndef FAST_SP
FREE_DYNAMIC_ARRAY(private_SP_space);
#endif
unwind_upto(FRAME);
}
# ------------------- (12) CATCH and THROW -----------------------
CASE cod_catch_open: # (CATCH-OPEN label)
# occupies 3 STACK-Entries and 1 SP-jmp_buf-Entry and 2 SP-Entries
{
var const uintB* label_byteptr;
L_operand(label_byteptr);
# save closureptr, label_byteptr:
pushSP(label_byteptr - CODEPTR); pushSP((aint)closureptr);
}
# build up Frame:
{
var gcv_object_t* top_of_frame = STACK;
pushSTACK(value1); # Tag
var JMPBUF_on_SP(returner); # memorize return-point
finish_entry_frame_1(CATCH,returner, goto catch_return; );
}
goto next_byte;
catch_return: # jump to this label takes place, if the previoulsy
# built Catch-Frame has catched a Throw.
{
FREE_JMPBUF_on_SP();
skipSTACK(3); # unwind CATCH-Frame
var uintL index;
# get closure back, byteptr:=label_byteptr :
popSP(closureptr = (gcv_object_t*) ); popSP(index = );
closure = *closureptr; # fetch Closure from Stack
codeptr = TheSbvector(TheCclosure(closure)->clos_codevec);
DEBUG_CHECK_BYTEPTR(CODEPTR + index);
byteptr = CODEPTR + index;
}
goto next_byte; # continue interpretation at Label
CASE cod_catch_close: # (CATCH-CLOSE)
# a CATCH-Frame has to come:
#if STACKCHECKC
if (!(framecode(STACK_0) == CATCH_frame_info))
GOTO_ERROR(fehler_STACK_putt);
#endif
FREE_JMPBUF_on_SP();
#if STACKCHECKC
if (!(closureptr == (gcv_object_t*)SP_(0))) # that Closureptr must be the current one
GOTO_ERROR(fehler_STACK_putt);
#endif
skipSP(2); skipSTACK(3); # unwind CATCH-Frame
goto next_byte;
CASE cod_throw: # (THROW)
{
var object tag = popSTACK();
throw_to(tag);
pushSTACK(tag);
pushSTACK(S(throw));
fehler(control_error,
GETTEXT("~S: there is no CATCHer for tag ~S"));
}
# ------------------- (13) UNWIND-PROTECT -----------------------
CASE cod_uwp_open: # (UNWIND-PROTECT-OPEN label)
# occupies 2 STACK-Entries and 1 SP-jmp_buf-Entry and 2 SP-Entries
{
var const uintB* label_byteptr;
L_operand(label_byteptr);
# save closureptr, label_byteptr:
pushSP(label_byteptr - CODEPTR); pushSP((aint)closureptr);
}
# build Frame:
{
var gcv_object_t* top_of_frame = STACK;
var JMPBUF_on_SP(returner); # memorize return-point
finish_entry_frame_1(UNWIND_PROTECT,returner, goto throw_save; );
}
goto next_byte;
throw_save: # jump to this label takes place, if the previously
# built Unwind-Protect-Frame has stopped a Throw.
# unwind_protect_to_save is to be saved and jumped to at the end.
#if STACKCHECKC
if (!(framecode(STACK_0) == UNWIND_PROTECT_frame_info)) {
fehler(serious_condition,GETTEXT("STACK corrupted"));
}
#endif
# unwind Frame:
FREE_JMPBUF_on_SP();
skipSTACK(2);
{
var uintL index;
# get closure back, byteptr:=label_byteptr :
popSP(closureptr = (gcv_object_t*) );
popSP(index = );
# save unwind_protect_to_save:
pushSP((aint)unwind_protect_to_save.fun);
pushSP((aint)unwind_protect_to_save.upto_frame);
pushSP((aint)STACK); # push Pointer above Frame additionally on the SP
# move all values to the Stack:
mv_to_STACK();
# execute Cleanup-Forms:
closure = *closureptr; # fetch Closure from Stack
codeptr = TheSbvector(TheCclosure(closure)->clos_codevec);
DEBUG_CHECK_BYTEPTR(CODEPTR + index);
byteptr = CODEPTR + index;
}
goto next_byte;
CASE cod_uwp_normal_exit: # (UNWIND-PROTECT-NORMAL-EXIT)
#if STACKCHECKC
if (!(framecode(STACK_0) == UNWIND_PROTECT_frame_info))
GOTO_ERROR(fehler_STACK_putt);
if (!(closureptr == (gcv_object_t*)SP_(jmpbufsize+0))) # that Closureptr must be the current one
GOTO_ERROR(fehler_STACK_putt);
#endif
# unwind Frame:
# nothing to do, because closure and byteptr stay unmodified.
FREE_JMPBUF_on_SP(); skipSP(2);
skipSTACK(2);
# dummy value for 'unwind_protect_to_save':
pushSP((aint)NULL); pushSP((aint)NULL); # NULL,NULL -> uwp_continue
pushSP((aint)STACK); # push Pointer above Frame additionally on the SP
# move all values to the Stack:
mv_to_STACK();
# execute Cleanup-Forms:
goto next_byte;
CASE cod_uwp_close: # (UNWIND-PROTECT-CLOSE)
# jump to this label takes place at the end of the Cleanup-Forms.
{
var gcv_object_t* oldSTACK; # value of STACK before saveing the values
popSP( oldSTACK = (gcv_object_t*) );
var uintL mvcount = # number of saved values on Stack
STACK_item_count(STACK,oldSTACK);
if (mvcount >= mv_limit) GOTO_ERROR(fehler_zuviele_werte);
STACK_to_mv(mvcount);
}
{ /* return to the saved unwind_protect_to_save.fun : */
var restartf_t fun;
var gcv_object_t* arg;
popSP( arg = (gcv_object_t*) ); popSP( fun = (restartf_t) );
# return to uwp_continue or uwp_jmpback or unwind_upto:
if (fun != NULL) {
(*fun)(arg); # return to unwind_upto or similar.
NOTREACHED;
}
if (arg == (gcv_object_t*)NULL) {
# uwp_continue:
# jump to this label takes place, if after the execution of
# the Cleanup-Forms simply interpretation shall continue.
goto next_byte;
} else {
# uwp_jmpback:
# jump to this label takes place, if after the execution of
# the Cleanup-Forms interpretation shall continue at the old
# location in the same Closure.
DEBUG_CHECK_BYTEPTR(CODEPTR + (uintP)arg);
byteptr = CODEPTR + (uintP)arg;
goto next_byte;
}
}
CASE cod_uwp_cleanup: # (UNWIND-PROTECT-CLEANUP)
# this is executed, if within the same Closure an execution
# of the Cleanup-Code is necessary.
#if STACKCHECKC
if (!(framecode(STACK_0) == UNWIND_PROTECT_frame_info))
GOTO_ERROR(fehler_STACK_putt);
if (!(closureptr == (gcv_object_t*)SP_(jmpbufsize+0))) # that Closureptr must be the current one
GOTO_ERROR(fehler_STACK_putt);
#endif
# closure remains, byteptr:=label_byteptr :
{
var uintL index = SP_(jmpbufsize+1);
# unwind Frame:
FREE_JMPBUF_on_SP(); skipSP(2);
skipSTACK(2);
# Dummy-values for 'unwind_protect_to_save':
pushSP((aint)NULL); # NULL -> uwp_jmpback
pushSP(byteptr - CODEPTR);
pushSP((aint)STACK); # push Pointer above Frame additionally on the SP
# move all values to the Stack:
mv_to_STACK();
# execute Cleanup-Forms:
DEBUG_CHECK_BYTEPTR(CODEPTR + index);
byteptr = CODEPTR + index;
}
goto next_byte;
# ------------------- (14) HANDLER-BIND -----------------------
CASE cod_handler_open: # (HANDLER-OPEN n)
# occupies 4 STACK-Entries
{
var uintL n;
U_operand(n);
# build up Frame:
var gcv_object_t* top_of_frame = STACK; # Pointer above Frame
pushSTACK(TheCclosure(closure)->clos_consts[n]);
pushSTACK(closure);
pushSTACK(fake_gcv_object((aint)(_SP_(0))));
finish_frame(HANDLER);
}
goto next_byte;
CASE cod_handler_begin_push: # (HANDLER-BEGIN&PUSH)
# builds up SP newly, occupies 1 SP-Entry and
# starts a new STACK-Region.
{
var uintL count = (uintL)posfixnum_to_V(Car(handler_args.spdepth))
+ jmpbufsize * (uintL)posfixnum_to_V(Cdr(handler_args.spdepth));
if (count > 0) {
var SPint* oldsp = handler_args.sp; # was formerly &SP_(0)
# copy oldsp[0..count-1] to the current SP:
oldsp skipSPop count;
dotimespL(count,count, { oldsp skipSPop -1; pushSP(*oldsp); } );
}
}
pushSP((aint)handler_args.stack); # Pointer above Handler-Frame
VALUES1(handler_args.condition);
pushSTACK(value1);
goto next_byte;
# ------------------- (15) a few Functions -----------------------
CASE cod_not: # (NOT)
if (nullp(value1)) goto code_t; else goto code_nil;
CASE cod_eq: # (EQ)
if (!eq(value1,popSTACK())) goto code_nil; else goto code_t;
CASE cod_car: # (CAR)
{
var object arg = value1;
if (consp(arg)) {
value1 = Car(arg); # CAR of a Cons
} else if (nullp(arg)) {
# (CAR NIL) = NIL: value1 remains NIL
} else
with_saved_back_trace_subr(L(car),STACK STACKop -1,-1,
fehler_list(arg); );
mv_count=1;
}
goto next_byte;
CASE cod_car_push: # (CAR&PUSH)
{
var object arg = value1;
if (consp(arg)) {
pushSTACK(Car(arg)); # CAR of a Cons
} else if (nullp(arg)) {
pushSTACK(arg); # (CAR NIL) = NIL
} else
with_saved_back_trace_subr(L(car),STACK STACKop -1,-1,
fehler_list(arg); );
}
goto next_byte;
CASE cod_load_car_push: # (LOAD&CAR&PUSH n)
{
var uintL n;
U_operand(n);
var object arg = STACK_(n);
if (consp(arg)) {
pushSTACK(Car(arg)); # CAR of a Cons
} else if (nullp(arg)) {
pushSTACK(arg); # (CAR NIL) = NIL
} else
with_saved_back_trace_subr(L(car),STACK STACKop -1,-1,
fehler_list(arg); );
}
goto next_byte;
CASE cod_load_car_store: # (LOAD&CAR&STORE m n)
{
var uintL m;
var uintL n;
U_operand(m);
U_operand(n);
var object arg = STACK_(m);
if (consp(arg)) {
STACK_(n) = value1 = Car(arg); # CAR of a Cons
} else if (nullp(arg)) {
STACK_(n) = value1 = arg; # (CAR NIL) = NIL
} else
with_saved_back_trace_subr(L(car),STACK STACKop -1,-1,
fehler_list(arg); );
mv_count=1;
}
goto next_byte;
CASE cod_cdr: # (CDR)
{
var object arg = value1;
if (consp(arg)) {
value1 = Cdr(arg); # CDR of a Cons
} else if (nullp(arg)) {
# (CDR NIL) = NIL: value1 remains NIL
} else
with_saved_back_trace_subr(L(cdr),STACK STACKop -1,-1,
fehler_list(arg); );
mv_count=1;
}
goto next_byte;
CASE cod_cdr_push: # (CDR&PUSH)
{
var object arg = value1;
if (consp(arg)) {
pushSTACK(Cdr(arg)); # CDR of a Cons
} else if (nullp(arg)) {
pushSTACK(arg); # (CDR NIL) = NIL
} else
with_saved_back_trace_subr(L(cdr),STACK STACKop -1,-1,
fehler_list(arg); );
}
goto next_byte;
CASE cod_load_cdr_push: # (LOAD&CDR&PUSH n)
{
var uintL n;
U_operand(n);
var object arg = STACK_(n);
if (consp(arg)) {
pushSTACK(Cdr(arg)); # CDR of a Cons
} else if (nullp(arg)) {
pushSTACK(arg); # (CDR NIL) = NIL
} else
with_saved_back_trace_subr(L(cdr),STACK STACKop -1,-1,
fehler_list(arg); );
}
goto next_byte;
CASE cod_load_cdr_store: # (LOAD&CDR&STORE n)
{
var uintL n;
U_operand(n);
var gcv_object_t* arg_ = &STACK_(n);
var object arg = *arg_;
if (consp(arg)) {
*arg_ = value1 = Cdr(arg); # CDR of a Cons
} else if (nullp(arg)) {
value1 = arg; # (CDR NIL) = NIL
} else
with_saved_back_trace_subr(L(cdr),STACK STACKop -1,-1,
fehler_list(arg); );
mv_count=1;
}
goto next_byte;
CASE cod_cons: # (CONS)
{
pushSTACK(value1);
# request Cons:
var object new_cons;
with_saved_context( { new_cons = allocate_cons(); } );
# fill Cons:
Cdr(new_cons) = popSTACK();
Car(new_cons) = popSTACK();
VALUES1(new_cons);
}
goto next_byte;
CASE cod_cons_push: # (CONS&PUSH)
{
pushSTACK(value1);
# request Cons:
var object new_cons;
with_saved_context( { new_cons = allocate_cons(); } );
# fill Cons:
Cdr(new_cons) = popSTACK();
Car(new_cons) = STACK_0;
STACK_0 = new_cons;
}
goto next_byte;
CASE cod_load_cons_store: # (LOAD&CONS&STORE n)
{
var uintL n;
U_operand(n);
# request Cons:
var object new_cons;
with_saved_context( { new_cons = allocate_cons(); } );
# fill Cons:
Car(new_cons) = popSTACK();
var gcv_object_t* arg_ = &STACK_(n);
Cdr(new_cons) = *arg_;
VALUES1(*arg_ = new_cons);
}
goto next_byte;
{var object symbol;
var object fdef;
#define CHECK_FDEF() \
if (!symbolp(symbol)) \
with_saved_back_trace_subr(L(symbol_function),STACK STACKop -1,-1, \
symbol = check_symbol(symbol); ); \
fdef = Symbol_function(symbol); \
if (!boundp(fdef)) \
/* (symbol may be not the actual function-name, for e.g. \
(FUNCTION (SETF FOO)) shows as (SYMBOL-FUNCTION '#:|(SETF FOO)|),\
but that should be enough for the error message.) */ \
fdef = check_fdefinition(symbol,S(symbol_function))
CASE cod_symbol_function: # (SYMBOL-FUNCTION)
symbol = value1;
CHECK_FDEF();
VALUES1(fdef);
goto next_byte;
CASE cod_const_symbol_function: # (CONST&SYMBOL-FUNCTION n)
{
var uintL n;
U_operand(n);
symbol = TheCclosure(closure)->clos_consts[n];
}
CHECK_FDEF();
VALUES1(fdef);
goto next_byte;
CASE cod_const_symbol_function_push: # (CONST&SYMBOL-FUNCTION&PUSH n)
{
var uintL n;
U_operand(n);
symbol = TheCclosure(closure)->clos_consts[n];
}
CHECK_FDEF();
pushSTACK(fdef);
goto next_byte;
CASE cod_const_symbol_function_store: # (CONST&SYMBOL-FUNCTION&STORE n k)
{
var uintL n;
U_operand(n);
symbol = TheCclosure(closure)->clos_consts[n];
}
CHECK_FDEF();
{
var uintL k;
U_operand(k);
STACK_(k) = value1 = fdef; mv_count=1;
}
goto next_byte;
}
{var object vec; var object index;
CASE cod_svref: # (SVREF)
# STACK_0 must be a Simple-Vector:
if (!simple_vector_p(STACK_0)) goto svref_kein_svector;
vec = popSTACK(); # Simple-Vector
index = value1;
# and the Index must be Fixnum >= 0, < length(vec) :
{
var uintV i;
if (!(posfixnump(index)
&& ((i = posfixnum_to_V(index)) < Svector_length(vec))))
goto svref_kein_index;
VALUES1(TheSvector(vec)->data[i]); # indexed Element as value
}
goto next_byte;
CASE cod_svset: # (SVSET)
# STACK_0 must be a Simple-Vector:
if (!simple_vector_p(STACK_0)) goto svref_kein_svector;
vec = popSTACK(); # Simple-Vector
index = value1;
# and the Index must be a Fixnum >=0, <Length(vec) :
{
var uintV i;
if (!(posfixnump(index)
&& ((i = posfixnum_to_V(index)) < Svector_length(vec))))
goto svref_kein_index;
value1 = TheSvector(vec)->data[i] = popSTACK(); # put in new element
mv_count = 1;
}
goto next_byte;
svref_kein_svector: # Non-Simple-Vector in STACK_0
fehler_kein_svector(S(svref),STACK_0);
svref_kein_index: # unsuitable Index in index, for Vector vec
pushSTACK(vec);
pushSTACK(index);
pushSTACK(index); # TYPE-ERROR slot DATUM
{
var object tmp;
pushSTACK(S(integer)); pushSTACK(Fixnum_0); pushSTACK(UL_to_I(Svector_length(vec)));
tmp = listof(1); pushSTACK(tmp); tmp = listof(3);
pushSTACK(tmp); # TYPE-ERROR slot EXPECTED-TYPE
}
pushSTACK(STACK_(1+2)); # vec
pushSTACK(STACK_(0+3)); # index
pushSTACK(S(svref));
fehler(type_error,GETTEXT("~S: ~S is not a correct index into ~S"));
}
CASE cod_list: # (LIST n)
{
var uintC n;
U_operand(n);
with_saved_context( { value1 = listof(n); mv_count=1; } );
}
goto next_byte;
CASE cod_list_push: # (LIST&PUSH n)
{
var uintC n;
U_operand(n);
with_saved_context( { object res = listof(n); pushSTACK(res); } );
}
goto next_byte;
CASE cod_liststern: # (LIST* n)
{
var uintC n;
U_operand(n);
with_saved_context({
pushSTACK(value1);
dotimespC(n,n, {
var object new_cons = allocate_cons();
Cdr(new_cons) = popSTACK();
Car(new_cons) = STACK_0;
STACK_0 = new_cons;
});
value1 = popSTACK(); mv_count=1;
});
}
goto next_byte;
CASE cod_liststern_push: # (LIST*&PUSH n)
{
var uintC n;
U_operand(n);
with_saved_context({
pushSTACK(value1);
dotimespC(n,n, {
var object new_cons = allocate_cons();
Cdr(new_cons) = popSTACK();
Car(new_cons) = STACK_0;
STACK_0 = new_cons;
});
});
}
goto next_byte;
# ------------------- (16) combined Operations -----------------------
CASE cod_nil_store: # (NIL&STORE n)
{
var uintL n;
U_operand(n);
STACK_(n) = value1 = NIL; mv_count=1;
}
goto next_byte;
CASE cod_t_store: # (T&STORE n)
{
var uintL n;
U_operand(n);
STACK_(n) = value1 = T; mv_count=1;
}
goto next_byte;
CASE cod_calls1_store: # (CALLS1&STORE n k)
CALLS1();
goto store;
CASE cod_calls2_store: # (CALLS2&STORE n k)
CALLS2();
goto store;
CASE cod_callsr_store: # (CALLSR&STORE m n k)
CALLSR();
goto store;
# Increment. Optimized specifically for Fixnums >=0.
#define INC(arg,statement) \
{ if (posfixnump(arg) # Fixnum >= 0 and < most-positive-fixnum ? \
&& !eq(arg,fixnum(vbitm(oint_data_len)-1))) { \
arg = fixnum_inc(arg,1); statement; \
} else { \
with_saved_context( \
/* funcall(L(einsplus),1): */ \
pushSTACK(arg); \
with_saved_back_trace_subr(L(einsplus),STACK,1, \
{ C_einsplus(); }); \
); \
arg = value1; \
} \
}
# Decrement. Optimized specifically for Fixnums >=0.
#define DEC(arg,statement) \
{ if (posfixnump(arg) && !eq(arg,Fixnum_0)) { # Fixnum > 0 ? \
arg = fixnum_inc(arg,-1); statement; \
} else { \
with_saved_context( \
/* funcall(L(einsminus),1): */ \
pushSTACK(arg); \
with_saved_back_trace_subr(L(einsminus),STACK,1, \
{ C_einsminus(); }); \
); \
arg = value1; \
} \
}
CASE cod_load_inc_push: # (LOAD&INC&PUSH n)
{
var uintL n;
U_operand(n);
var object arg = STACK_(n);
INC(arg,); # increment
pushSTACK(arg);
}
goto next_byte;
CASE cod_load_inc_store: # (LOAD&INC&STORE n)
{
var uintL n;
U_operand(n);
var gcv_object_t* arg_ = &STACK_(n);
var object arg = *arg_;
INC(arg,mv_count=1); # increment, one value
value1 = *arg_ = arg;
}
goto next_byte;
CASE cod_load_dec_push: # (LOAD&DEC&PUSH n)
{
var uintL n;
U_operand(n);
var object arg = STACK_(n);
DEC(arg,); # decrement
pushSTACK(arg);
}
goto next_byte;
CASE cod_load_dec_store: # (LOAD&DEC&STORE n)
{
var uintL n;
U_operand(n);
var gcv_object_t* arg_ = &STACK_(n);
var object arg = *arg_;
DEC(arg,mv_count=1); # decrement, one value
value1 = *arg_ = arg;
}
goto next_byte;
CASE cod_call1_jmpif: # (CALL1&JMPIF n label)
CALL1();
if (!nullp(value1)) goto jmp; else goto notjmp;
CASE cod_call1_jmpifnot: # (CALL1&JMPIFNOT n label)
CALL1();
if (nullp(value1)) goto jmp; else goto notjmp;
CASE cod_call2_jmpif: # (CALL2&JMPIF n label)
CALL2();
if (!nullp(value1)) goto jmp; else goto notjmp;
CASE cod_call2_jmpifnot: # (CALL2&JMPIFNOT n label)
CALL2();
if (nullp(value1)) goto jmp; else goto notjmp;
CASE cod_calls1_jmpif: # (CALLS1&JMPIF n label)
CALLS1();
if (!nullp(value1)) goto jmp; else goto notjmp;
CASE cod_calls1_jmpifnot: # (CALLS1&JMPIFNOT n label)
CALLS1();
if (nullp(value1)) goto jmp; else goto notjmp;
CASE cod_calls2_jmpif: # (CALLS2&JMPIF n label)
CALLS2();
if (!nullp(value1)) goto jmp; else goto notjmp;
CASE cod_calls2_jmpifnot: # (CALLS2&JMPIFNOT n label)
CALLS2();
if (nullp(value1)) goto jmp; else goto notjmp;
CASE cod_callsr_jmpif: # (CALLSR&JMPIF m n label)
CALLSR();
if (!nullp(value1)) goto jmp; else goto notjmp;
CASE cod_callsr_jmpifnot: # (CALLSR&JMPIFNOT m n label)
CALLSR();
if (nullp(value1)) goto jmp; else goto notjmp;
CASE cod_load_jmpif: # (LOAD&JMPIF n label)
{
var uintL n;
U_operand(n);
mv_count=1;
if (!nullp(value1 = STACK_(n))) goto jmp; else goto notjmp;
}
CASE cod_load_jmpifnot: # (LOAD&JMPIFNOT n label)
{
var uintL n;
U_operand(n);
mv_count=1;
if (nullp(value1 = STACK_(n))) goto jmp; else goto notjmp;
}
CASE cod_apply_skip_ret: # (APPLY&SKIP&RET n k)
{
var uintL n;
var uintL k;
U_operand(n);
U_operand(k);
var object fun = STACK_(n); # Function
with_saved_context({
apply(fun,n,value1); # call Function
skipSTACK(k+1); # discard Function and others from Stack
goto finished; # return (jump) to caller
}); # the context is not restored
}
CASE cod_funcall_skip_retgf: # (FUNCALL&SKIP&RETGF n k)
{
var uintL n;
var uintL k;
U_operand(n);
U_operand(k);
var object fun = STACK_(n); # Function
var uintL r = ((Codevec)codeptr)->ccv_numreq;
var uintB flags = ((Codevec)codeptr)->ccv_flags;
with_saved_context({
funcall(fun,n); # call Function
if (flags & bit(3)) { # call inhibition?
skipSTACK(k+1);
mv_count=1;
goto finished; # return (jump) to caller
}
k -= r;
if (flags & bit(0)) {
skipSTACK(k); apply(value1,r,popSTACK());
} else {
skipSTACK(k+1); funcall(value1,r);
}
goto finished; # return (jump) to caller
}); # the context is not restored
}
# ------------------- (17) short codes -----------------------
CASE cod_load0: # (LOAD.S 0)
VALUES1(STACK_(0));
goto next_byte;
CASE cod_load1: # (LOAD.S 1)
VALUES1(STACK_(1));
goto next_byte;
CASE cod_load2: # (LOAD.S 2)
VALUES1(STACK_(2));
goto next_byte;
CASE cod_load3: # (LOAD.S 3)
VALUES1(STACK_(3));
goto next_byte;
CASE cod_load4: # (LOAD.S 4)
VALUES1(STACK_(4));
goto next_byte;
CASE cod_load5: # (LOAD.S 5)
VALUES1(STACK_(5));
goto next_byte;
CASE cod_load6: # (LOAD.S 6)
VALUES1(STACK_(6));
goto next_byte;
CASE cod_load7: # (LOAD.S 7)
VALUES1(STACK_(7));
goto next_byte;
CASE cod_load8: # (LOAD.S 8)
VALUES1(STACK_(8));
goto next_byte;
CASE cod_load9: # (LOAD.S 9)
VALUES1(STACK_(9));
goto next_byte;
CASE cod_load10: # (LOAD.S 10)
VALUES1(STACK_(10));
goto next_byte;
CASE cod_load11: # (LOAD.S 11)
VALUES1(STACK_(11));
goto next_byte;
CASE cod_load12: # (LOAD.S 12)
VALUES1(STACK_(12));
goto next_byte;
CASE cod_load13: # (LOAD.S 13)
VALUES1(STACK_(13));
goto next_byte;
CASE cod_load14: # (LOAD.S 14)
VALUES1(STACK_(14));
goto next_byte;
#if 0
CASE cod_load15: # (LOAD.S 15)
VALUES1(STACK_(15));
goto next_byte;
CASE cod_load16: # (LOAD.S 16)
VALUES1(STACK_(16));
goto next_byte;
CASE cod_load17: # (LOAD.S 17)
VALUES1(STACK_(17));
goto next_byte;
CASE cod_load18: # (LOAD.S 18)
VALUES1(STACK_(18));
goto next_byte;
CASE cod_load19: # (LOAD.S 19)
VALUES1(STACK_(19));
goto next_byte;
CASE cod_load20: # (LOAD.S 20)
VALUES1(STACK_(20));
goto next_byte;
CASE cod_load21: # (LOAD.S 21)
VALUES1(STACK_(21));
goto next_byte;
#endif
CASE cod_load_push0: # (LOAD&PUSH.S 0)
pushSTACK(STACK_(0));
goto next_byte;
CASE cod_load_push1: # (LOAD&PUSH.S 1)
pushSTACK(STACK_(1));
goto next_byte;
CASE cod_load_push2: # (LOAD&PUSH.S 2)
pushSTACK(STACK_(2));
goto next_byte;
CASE cod_load_push3: # (LOAD&PUSH.S 3)
pushSTACK(STACK_(3));
goto next_byte;
CASE cod_load_push4: # (LOAD&PUSH.S 4)
pushSTACK(STACK_(4));
goto next_byte;
CASE cod_load_push5: # (LOAD&PUSH.S 5)
pushSTACK(STACK_(5));
goto next_byte;
CASE cod_load_push6: # (LOAD&PUSH.S 6)
pushSTACK(STACK_(6));
goto next_byte;
CASE cod_load_push7: # (LOAD&PUSH.S 7)
pushSTACK(STACK_(7));
goto next_byte;
CASE cod_load_push8: # (LOAD&PUSH.S 8)
pushSTACK(STACK_(8));
goto next_byte;
CASE cod_load_push9: # (LOAD&PUSH.S 9)
pushSTACK(STACK_(9));
goto next_byte;
CASE cod_load_push10: # (LOAD&PUSH.S 10)
pushSTACK(STACK_(10));
goto next_byte;
CASE cod_load_push11: # (LOAD&PUSH.S 11)
pushSTACK(STACK_(11));
goto next_byte;
CASE cod_load_push12: # (LOAD&PUSH.S 12)
pushSTACK(STACK_(12));
goto next_byte;
CASE cod_load_push13: # (LOAD&PUSH.S 13)
pushSTACK(STACK_(13));
goto next_byte;
CASE cod_load_push14: # (LOAD&PUSH.S 14)
pushSTACK(STACK_(14));
goto next_byte;
CASE cod_load_push15: # (LOAD&PUSH.S 15)
pushSTACK(STACK_(15));
goto next_byte;
CASE cod_load_push16: # (LOAD&PUSH.S 16)
pushSTACK(STACK_(16));
goto next_byte;
CASE cod_load_push17: # (LOAD&PUSH.S 17)
pushSTACK(STACK_(17));
goto next_byte;
CASE cod_load_push18: # (LOAD&PUSH.S 18)
pushSTACK(STACK_(18));
goto next_byte;
CASE cod_load_push19: # (LOAD&PUSH.S 19)
pushSTACK(STACK_(19));
goto next_byte;
CASE cod_load_push20: # (LOAD&PUSH.S 20)
pushSTACK(STACK_(20));
goto next_byte;
CASE cod_load_push21: # (LOAD&PUSH.S 21)
pushSTACK(STACK_(21));
goto next_byte;
CASE cod_load_push22: # (LOAD&PUSH.S 22)
pushSTACK(STACK_(22));
goto next_byte;
CASE cod_load_push23: # (LOAD&PUSH.S 23)
pushSTACK(STACK_(23));
goto next_byte;
CASE cod_load_push24: # (LOAD&PUSH.S 24)
pushSTACK(STACK_(24));
goto next_byte;
CASE cod_const0: # (CONST.S 0)
VALUES1(TheCclosure(closure)->clos_consts[0]);
goto next_byte;
CASE cod_const1: # (CONST.S 1)
VALUES1(TheCclosure(closure)->clos_consts[1]);
goto next_byte;
CASE cod_const2: # (CONST.S 2)
VALUES1(TheCclosure(closure)->clos_consts[2]);
goto next_byte;
CASE cod_const3: # (CONST.S 3)
VALUES1(TheCclosure(closure)->clos_consts[3]);
goto next_byte;
CASE cod_const4: # (CONST.S 4)
VALUES1(TheCclosure(closure)->clos_consts[4]);
goto next_byte;
CASE cod_const5: # (CONST.S 5)
VALUES1(TheCclosure(closure)->clos_consts[5]);
goto next_byte;
CASE cod_const6: # (CONST.S 6)
VALUES1(TheCclosure(closure)->clos_consts[6]);
goto next_byte;
CASE cod_const7: # (CONST.S 7)
VALUES1(TheCclosure(closure)->clos_consts[7]);
goto next_byte;
CASE cod_const8: # (CONST.S 8)
VALUES1(TheCclosure(closure)->clos_consts[8]);
goto next_byte;
CASE cod_const9: # (CONST.S 9)
VALUES1(TheCclosure(closure)->clos_consts[9]);
goto next_byte;
CASE cod_const10: # (CONST.S 10)
VALUES1(TheCclosure(closure)->clos_consts[10]);
goto next_byte;
CASE cod_const11: # (CONST.S 11)
VALUES1(TheCclosure(closure)->clos_consts[11]);
goto next_byte;
CASE cod_const12: # (CONST.S 12)
VALUES1(TheCclosure(closure)->clos_consts[12]);
goto next_byte;
CASE cod_const13: # (CONST.S 13)
VALUES1(TheCclosure(closure)->clos_consts[13]);
goto next_byte;
CASE cod_const14: # (CONST.S 14)
VALUES1(TheCclosure(closure)->clos_consts[14]);
goto next_byte;
CASE cod_const15: # (CONST.S 15)
VALUES1(TheCclosure(closure)->clos_consts[15]);
goto next_byte;
CASE cod_const16: # (CONST.S 16)
VALUES1(TheCclosure(closure)->clos_consts[16]);
goto next_byte;
CASE cod_const17: # (CONST.S 17)
VALUES1(TheCclosure(closure)->clos_consts[17]);
goto next_byte;
CASE cod_const18: # (CONST.S 18)
VALUES1(TheCclosure(closure)->clos_consts[18]);
goto next_byte;
CASE cod_const19: # (CONST.S 19)
VALUES1(TheCclosure(closure)->clos_consts[19]);
goto next_byte;
CASE cod_const20: # (CONST.S 20)
VALUES1(TheCclosure(closure)->clos_consts[20]);
goto next_byte;
#if 0
CASE cod_const21: # (CONST.S 21)
VALUES1(TheCclosure(closure)->clos_consts[21]);
goto next_byte;
CASE cod_const22: # (CONST.S 22)
VALUES1(TheCclosure(closure)->clos_consts[22]);
goto next_byte;
CASE cod_const23: # (CONST.S 23)
VALUES1(TheCclosure(closure)->clos_consts[23]);
goto next_byte;
CASE cod_const24: # (CONST.S 24)
VALUES1(TheCclosure(closure)->clos_consts[24]);
goto next_byte;
#endif
CASE cod_const_push0: # (CONST&PUSH.S 0)
pushSTACK(TheCclosure(closure)->clos_consts[0]);
goto next_byte;
CASE cod_const_push1: # (CONST&PUSH.S 1)
pushSTACK(TheCclosure(closure)->clos_consts[1]);
goto next_byte;
CASE cod_const_push2: # (CONST&PUSH.S 2)
pushSTACK(TheCclosure(closure)->clos_consts[2]);
goto next_byte;
CASE cod_const_push3: # (CONST&PUSH.S 3)
pushSTACK(TheCclosure(closure)->clos_consts[3]);
goto next_byte;
CASE cod_const_push4: # (CONST&PUSH.S 4)
pushSTACK(TheCclosure(closure)->clos_consts[4]);
goto next_byte;
CASE cod_const_push5: # (CONST&PUSH.S 5)
pushSTACK(TheCclosure(closure)->clos_consts[5]);
goto next_byte;
CASE cod_const_push6: # (CONST&PUSH.S 6)
pushSTACK(TheCclosure(closure)->clos_consts[6]);
goto next_byte;
CASE cod_const_push7: # (CONST&PUSH.S 7)
pushSTACK(TheCclosure(closure)->clos_consts[7]);
goto next_byte;
CASE cod_const_push8: # (CONST&PUSH.S 8)
pushSTACK(TheCclosure(closure)->clos_consts[8]);
goto next_byte;
CASE cod_const_push9: # (CONST&PUSH.S 9)
pushSTACK(TheCclosure(closure)->clos_consts[9]);
goto next_byte;
CASE cod_const_push10: # (CONST&PUSH.S 10)
pushSTACK(TheCclosure(closure)->clos_consts[10]);
goto next_byte;
CASE cod_const_push11: # (CONST&PUSH.S 11)
pushSTACK(TheCclosure(closure)->clos_consts[11]);
goto next_byte;
CASE cod_const_push12: # (CONST&PUSH.S 12)
pushSTACK(TheCclosure(closure)->clos_consts[12]);
goto next_byte;
CASE cod_const_push13: # (CONST&PUSH.S 13)
pushSTACK(TheCclosure(closure)->clos_consts[13]);
goto next_byte;
CASE cod_const_push14: # (CONST&PUSH.S 14)
pushSTACK(TheCclosure(closure)->clos_consts[14]);
goto next_byte;
CASE cod_const_push15: # (CONST&PUSH.S 15)
pushSTACK(TheCclosure(closure)->clos_consts[15]);
goto next_byte;
CASE cod_const_push16: # (CONST&PUSH.S 16)
pushSTACK(TheCclosure(closure)->clos_consts[16]);
goto next_byte;
CASE cod_const_push17: # (CONST&PUSH.S 17)
pushSTACK(TheCclosure(closure)->clos_consts[17]);
goto next_byte;
CASE cod_const_push18: # (CONST&PUSH.S 18)
pushSTACK(TheCclosure(closure)->clos_consts[18]);
goto next_byte;
CASE cod_const_push19: # (CONST&PUSH.S 19)
pushSTACK(TheCclosure(closure)->clos_consts[19]);
goto next_byte;
CASE cod_const_push20: # (CONST&PUSH.S 20)
pushSTACK(TheCclosure(closure)->clos_consts[20]);
goto next_byte;
CASE cod_const_push21: # (CONST&PUSH.S 21)
pushSTACK(TheCclosure(closure)->clos_consts[21]);
goto next_byte;
CASE cod_const_push22: # (CONST&PUSH.S 22)
pushSTACK(TheCclosure(closure)->clos_consts[22]);
goto next_byte;
CASE cod_const_push23: # (CONST&PUSH.S 23)
pushSTACK(TheCclosure(closure)->clos_consts[23]);
goto next_byte;
CASE cod_const_push24: # (CONST&PUSH.S 24)
pushSTACK(TheCclosure(closure)->clos_consts[24]);
goto next_byte;
CASE cod_const_push25: # (CONST&PUSH.S 25)
pushSTACK(TheCclosure(closure)->clos_consts[25]);
goto next_byte;
CASE cod_const_push26: # (CONST&PUSH.S 26)
pushSTACK(TheCclosure(closure)->clos_consts[26]);
goto next_byte;
CASE cod_const_push27: # (CONST&PUSH.S 27)
pushSTACK(TheCclosure(closure)->clos_consts[27]);
goto next_byte;
CASE cod_const_push28: # (CONST&PUSH.S 28)
pushSTACK(TheCclosure(closure)->clos_consts[28]);
goto next_byte;
CASE cod_const_push29: # (CONST&PUSH.S 29)
pushSTACK(TheCclosure(closure)->clos_consts[29]);
goto next_byte;
#if 0
CASE cod_const_push30: # (CONST&PUSH.S 30)
pushSTACK(TheCclosure(closure)->clos_consts[30]);
goto next_byte;
CASE cod_const_push31: # (CONST&PUSH.S 31)
pushSTACK(TheCclosure(closure)->clos_consts[31]);
goto next_byte;
CASE cod_const_push32: # (CONST&PUSH.S 32)
pushSTACK(TheCclosure(closure)->clos_consts[32]);
goto next_byte;
#endif
CASE cod_store0: # (STORE.S 0)
STACK_(0) = value1; mv_count=1;
goto next_byte;
CASE cod_store1: # (STORE.S 1)
STACK_(1) = value1; mv_count=1;
goto next_byte;
CASE cod_store2: # (STORE.S 2)
STACK_(2) = value1; mv_count=1;
goto next_byte;
CASE cod_store3: # (STORE.S 3)
STACK_(3) = value1; mv_count=1;
goto next_byte;
CASE cod_store4: # (STORE.S 4)
STACK_(4) = value1; mv_count=1;
goto next_byte;
CASE cod_store5: # (STORE.S 5)
STACK_(5) = value1; mv_count=1;
goto next_byte;
CASE cod_store6: # (STORE.S 6)
STACK_(6) = value1; mv_count=1;
goto next_byte;
CASE cod_store7: # (STORE.S 7)
STACK_(7) = value1; mv_count=1;
goto next_byte;
#if 0
CASE cod_store8: # (STORE.S 8)
STACK_(8) = value1; mv_count=1;
goto next_byte;
CASE cod_store9: # (STORE.S 9)
STACK_(9) = value1; mv_count=1;
goto next_byte;
CASE cod_store10: # (STORE.S 10)
STACK_(10) = value1; mv_count=1;
goto next_byte;
CASE cod_store11: # (STORE.S 11)
STACK_(11) = value1; mv_count=1;
goto next_byte;
CASE cod_store12: # (STORE.S 12)
STACK_(12) = value1; mv_count=1;
goto next_byte;
CASE cod_store13: # (STORE.S 13)
STACK_(13) = value1; mv_count=1;
goto next_byte;
CASE cod_store14: # (STORE.S 14)
STACK_(14) = value1; mv_count=1;
goto next_byte;
CASE cod_store15: # (STORE.S 15)
STACK_(15) = value1; mv_count=1;
goto next_byte;
CASE cod_store16: # (STORE.S 16)
STACK_(16) = value1; mv_count=1;
goto next_byte;
CASE cod_store17: # (STORE.S 17)
STACK_(17) = value1; mv_count=1;
goto next_byte;
CASE cod_store18: # (STORE.S 18)
STACK_(18) = value1; mv_count=1;
goto next_byte;
CASE cod_store19: # (STORE.S 19)
STACK_(19) = value1; mv_count=1;
goto next_byte;
CASE cod_store20: # (STORE.S 20)
STACK_(20) = value1; mv_count=1;
goto next_byte;
CASE cod_store21: # (STORE.S 21)
STACK_(21) = value1; mv_count=1;
goto next_byte;
#endif
# ------------------- miscellaneous -----------------------
#ifndef FAST_DISPATCH
default:
#endif
/* undefined Code */
#if defined(GNU) && defined(FAST_SP)
/* Undo the effect of -fomit-frame-pointer for this function,
hereby allowing utilization of %sp resp. %esp as private_SP: */
alloca(1);
#endif
pushSTACK(fixnum(byteptr-&codeptr->data[0]-1)); /* bad byte number */
pushSTACK(closure); # Closure
fehler(serious_condition,
GETTEXT("undefined bytecode in ~S at byte ~S"));
#undef L_operand
#undef S_operand
#undef U_operand
#undef B_operand
#undef CASE
}
#if DEBUG_BYTECODE
fehler_byteptr:
pushSTACK(fixnum(byteptr_max));
pushSTACK(fixnum(byteptr_min));
pushSTACK(fixnum(byteptr - codeptr->data));
pushSTACK(sfixnum(byteptr_bad_jump));
pushSTACK(closure);
fehler(error,GETTEXT("~S: jump by ~S takes ~S outside [~S;~S]"));
#endif
fehler_zuviele_werte:
pushSTACK(closure);
fehler(error,GETTEXT("~S: too many return values"));
#if STACKCHECKC
fehler_STACK_putt:
pushSTACK(fixnum(byteptr - codeptr->data - byteptr_min)); /* PC */
pushSTACK(closure); /* FUNC */
fehler(serious_condition,GETTEXT("Corrupted STACK in ~S at byte ~S"));
#endif
finished:
#undef FREE_JMPBUF_on_SP
#undef JMPBUF_on_SP
#ifndef FAST_SP
FREE_DYNAMIC_ARRAY(private_SP_space);
#endif
return;
}
/* UP: initialize hand-made compiled closures
init_cclosures();
can trigger GC */
global maygc void init_cclosures (void) {
# Build #13Y(00 00 00 00 00 00 00 00 00 01 C5 19 01) ; (CONST 0) (SKIP&RET 1)
{
var object codevec = allocate_bit_vector(Atype_8Bit,CCV_START_NONKEY+3);
TheCodevec(codevec)->ccv_spdepth_1 = 0;
TheCodevec(codevec)->ccv_spdepth_jmpbufsize = 0;
TheCodevec(codevec)->ccv_numreq = 0;
TheCodevec(codevec)->ccv_numopt = 0;
TheCodevec(codevec)->ccv_flags = 0;
TheCodevec(codevec)->ccv_signature = cclos_argtype_0_0;
TheSbvector(codevec)->data[CCV_START_NONKEY+0] = cod_const0;
TheSbvector(codevec)->data[CCV_START_NONKEY+1] = cod_skip_ret;
TheSbvector(codevec)->data[CCV_START_NONKEY+2] = 1;
O(constant_initfunction_code) = codevec;
}
# Build #12Y(00 00 00 00 00 00 00 00 11 16 1B 7E) ; L0 (JMP L0)
{
var object codevec = allocate_bit_vector(Atype_8Bit,CCV_START_NONKEY+2);
TheCodevec(codevec)->ccv_spdepth_1 = 0;
TheCodevec(codevec)->ccv_spdepth_jmpbufsize = 0;
TheCodevec(codevec)->ccv_numreq = 0;
TheCodevec(codevec)->ccv_numopt = 0;
TheCodevec(codevec)->ccv_flags = bit(4)|bit(0);
TheCodevec(codevec)->ccv_signature = cclos_argtype_0_0_rest;
TheSbvector(codevec)->data[CCV_START_NONKEY+0] = cod_jmp;
TheSbvector(codevec)->data[CCV_START_NONKEY+1] = 128 - 2;
O(endless_loop_code) = codevec;
}
}
# where is check_SP() or check_STACK() to be inserted??
# is nest_env supposed to receive its target-environment as parameter??
# register-allocation in eval_subr and eval_cclosure etc.??
# eliminate subr_self??
|