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
|
# 07jun12abu
# (c) Software Lab. Alexander Burger
# Close file descriptor
(code 'closeAX)
cc close(A)
nul4 # OK?
jz Ret # Yes
ld E A # Get file descriptor
shl E 4 # Make short number
or E CNT
jmp closeErrEX
# Lock/unlock file
(code 'unLockFileAC)
st2 (Flock) # 'l_type'
ld (Flock L_START) 0 # Start position ('l_whence' is SEEK_SET)
shr A 16 # Get length
ld (Flock L_LEN) A # Length
cc fcntl(C F_SETLK Flock) # Try to unlock
ret
(code 'wrLockFileC)
ld A F_WRLCK # Write lock, length 0
jmp lockFileAC
(code 'rdLockFileC)
ld A F_RDLCK # Read lock, length 0
(code 'lockFileAC)
st2 (Flock) # 'l_type'
ld (Flock L_START) 0 # Start position ('l_whence' is SEEK_SET)
shr A 16 # Get length
ld (Flock L_LEN) A # Length
do
cc fcntl(C F_SETLKW Flock) # Try to lock
nul4 # OK?
jns Ret # Yes
call errno_A
cmp A EINTR # Interrupted?
jne lockErr # No
loop
# Set the close-on-exec flag
(code 'closeOnExecAX)
cc fcntl(A F_SETFD FD_CLOEXEC)
nul4 # OK?
jns Ret # Yes
ld Y SetFD
jmp errnoEXY
# Set file descriptor to non-blocking / blocking
(code 'nonblockingA_A)
push C
ld C A # Keep fd
cc fcntl(C F_GETFL 0) # Get file status flags
push A # Save flags
or A O_NONBLOCK
cc fcntl(C F_SETFL A) # Set file status flags
pop A # Return old flags
pop C
ret
# Initialize input file
(code 'initInFileA_A) # E
ld C 0 # No name
: initInFileAC_A
xchg A C
: initInFileCA_A
push A # Save 'name'
push C # and 'fd'
shl C 3 # Vector index
cmp C (InFDs) # 'fd' >= 'InFDs'?
if ge # Yes
push X
ld X (InFDs) # Keep old 'InFDs'
ld E C # Get vector index
add E I # Plus 1
ld (InFDs) E # Store new 'InFDs'
ld A (InFiles) # Get vector
call allocAE_A # Extend vector
ld (InFiles) A
add X A # X on beg
add A E # A on end
do
ld (X) 0 # Clear new range
add X I
cmp X A
until eq
pop X
end
add C (InFiles) # Get vector
ld A (C) # Old inFile (should be NULL!)
ld E (+ VII BUFSIZ) # sizeof(inFile)
call allocAE_A
ld (C) A # New inFile
pop (A) # Set 'fd'
ld (A I) 0 # Clear 'ix'
ld (A II) 0 # Clear 'cnt'
ld (A III) 0 # Clear 'next'
ld C 1
ld (A IV) C # line = 1
ld (A V) C # src = 1
pop (A VI) # Set filename
ret
# Initialize output file
(code 'initOutFileA_A)
ld C A
push A # Save 'fd'
cc isatty(A)
push A # Save 'tty' flag
shl C 3 # Vector index
cmp C (OutFDs) # 'fd' >= 'OutFDs'?
if ge # Yes
push X
ld X (OutFDs) # Keep old 'OutFDs'
ld E C # Get vector index
add E I # Plus 1
ld (OutFDs) E # Store new 'OutFDs'
ld A (OutFiles) # Get vector
call allocAE_A # Extend vector
ld (OutFiles) A
add X A # X on beg
add A E # A on end
do
ld (X) 0 # Clear new range
add X I
cmp X A
until eq
pop X
end
add C (OutFiles) # Get vector
ld A (C) # Old outFile (should be NULL!)
ld E (+ III BUFSIZ) # sizeof(outFile)
call allocAE_A
ld (C) A # New outFile
pop (A II) # Set 'tty'
ld (A I) 0 # Clear 'ix'
pop (A) # Set 'fd'
ret
# Close input file
(code 'closeInFileA)
shl A 3 # Vector index
cmp A (InFDs) # 'fd' < 'InFDs'?
if lt # Yes
push X
add A (InFiles) # Get vector
ld X (A)
null X # Any?
if nz # Yes
cmp X (InFile) # Current Infile?
if eq # Yes
ld (InFile) 0 # Clear it
end
ld (A) 0 # Clear slot
cc free((X VI)) # Free filename
cc free(X) # And inFile
end
pop X
end
ret
# Close output file
(code 'closeOutFileA)
shl A 3 # Vector index
cmp A (OutFDs) # 'fd' < 'OutFDs'?
if lt # Yes
push X
add A (OutFiles) # Get vector
ld X (A)
null X # Any?
if nz # Yes
cmp A (OutFile) # Current Outfile?
if eq # Yes
ld (OutFile) 0 # Clear it
end
ld (A) 0 # Clear slot
cc free(X) # And inFile
end
pop X
end
ret
# Interruptible read
(code 'slowZ_F)
ld (Z I) 0 # Clear 'ix'
ld (Z II) 0 # Clear 'cnt'
do
cc read((Z) &(Z VII) BUFSIZ) # Read into buffer
null A # OK?
if ns # Yes
ld (Z II) A # Set new 'cnt'
ret # Return 'ge'
end
call errno_A
cmp A EINTR # Interrupted?
if ne # No
setz # Return 'z'
ret
end
null (Signal) # Signal?
if nz # Yes
call sighandler0
end
loop
(code 'slowNbC_FA)
ld (C I) 0 # Clear 'ix'
ld (C II) 0 # Clear 'cnt'
do
ld A (C) # Set non-blocking
call nonblockingA_A
push A # Save old file status flags
cc read((C) &(C VII) BUFSIZ) # Read into buffer
xchg A (S)
cc fcntl((C) F_SETFL A) # Restore file status flags
pop A # Get 'read' return value
null A # OK?
if nsz # Yes
ld (C II) A # Set new 'cnt'
ret # Return 'ge'
end
if z # Closed
dec (C I) # 'ix' = 'cnt' = -1
dec (C II)
ret # z
end
call errno_A
cmp A EAGAIN # No data available?
if eq # Yes
clrz # Return 'lt'
setc
ret
end
cmp A EINTR # Interrupted?
if ne # No
setz # Return 'z'
ret
end
null (Signal) # Signal?
if nz # Yes
call sighandler0
end
loop
(code 'rdBytesCEX_F)
do
do
cc read(C X E) # Read into buffer
null A # OK?
while sz # No
jz Ret # EOF
call errno_A
cmp A EINTR # Interrupted?
jne Retz # No: Return 'z'
null (Signal) # Signal?
if nz # Yes
call sighandler0
end
loop
add X A # Increment buffer pointer
sub E A # Decrement count
until z
null A # 'nsz'
ret
(code 'rdBytesNbCEX_F)
do
ld A C # Set non-blocking
call nonblockingA_A
push A # Save old file status flags
cc read(C X E) # Read into buffer
xchg A (S)
cc fcntl(C F_SETFL A) # Restore file status flags
pop A # Get 'read' return value
null A # OK?
if nsz # Yes
do
sub E A # Decrement count
if z # Got all
null A # Return 'gt' (A is non-zero)
ret
end
add X A # Increment buffer pointer
do
cc read(C X E) # Read into buffer
null A # OK?
while sz # No
jz Ret # EOF
call errno_A
cmp A EINTR # Interrupted?
jne Retz # No: Return 'z'
null (Signal) # Signal?
if nz # Yes
call sighandler0
end
loop
loop
end
jz Ret # EOF
call errno_A
cmp A EAGAIN # No data available?
if eq # Yes
clrz # Return 'lt'
setc
ret
end
cmp A EINTR # Interrupted?
jne Retz # No: Return 'z'
null (Signal) # Signal?
if nz # Yes
call sighandler0
end
loop
(code 'wrBytesCEX_F)
do
cc write(C X E) # Write buffer
null A # OK?
if ns # Yes
sub E A # Decrement count
jz Ret # Return 'z' if OK
add X A # Increment buffer pointer
else
call errno_A
cmp A EBADF # Bad file number?
jeq retnz # Return 'nz'
cmp A EPIPE # Broken pipe?
jeq retnz # Return 'nz'
cmp A ECONNRESET # Connection reset by peer?
jeq retnz # Return 'nz'
cmp A EINTR # Interrupted?
jne wrBytesErr # No
null (Signal) # Signal?
if nz # Yes
call sighandler0
end
end
loop
(code 'clsChildY 0)
cmp (Y) (Talking) # Currently active?
if eq # Yes
ld (Talking) 0 # Clear
end
ld (Y) 0 # Clear 'pid'
cc close((Y I)) # Close 'hear'
cc close((Y II)) # and 'tell'
cc free((Y V)) # Free buffer
ret
(code 'wrChildCXY) # E
ld E (Y IV) # Get buffer count
null E # Any?
if z # No
do
cc write((Y II) X C) # Write buffer to 'tell' pipe
null A # OK?
if ns # Yes
sub C A # Decrement count
jz Ret # Done
add X A # Increment buffer pointer
else
call errno_A
cmp A EAGAIN # Would block?
break eq # Yes
cmp A EPIPE # Broken pipe?
jeq clsChildY # Close child
cmp A ECONNRESET # Connection reset by peer?
jeq clsChildY # Close child
cmp A EINTR # Interrupted?
jne wrChildErr # No
end
loop
end
ld A (Y V) # Get buffer
add E C # Increment count
add E 4 # plus count size
call allocAE_A # Extend buffer
ld (Y V) A # Store
ld E (Y IV) # Get buffer count again
add E A # Point to new count
ld A C # Store new
st4 (E)
add E 4 # Point to new data
movn (E) (X) C # Copy data
add C 4 # Total new size
add (Y IV) C # Add to buffer count
ret
(code 'flushA_F 0)
null A # Output file?
if nz # Yes
push E
ld E (A I) # Get 'ix'
null E # Any?
if nz # Yes
push C
push X
ld (A I) 0 # Clear 'ix'
ld C (A) # Get 'fd'
lea X (A III) # Buffer pointer
call wrBytesCEX_F # Write buffer
pop X
pop C
end
pop E
end
ret # Return 'z' if OK
(code 'flushAll) # C
ld C 0 # Iterate output files
do
cmp C (OutFDs) # 'fd' < 'OutFDs'?
while lt
ld A C # Get vector index
add A (OutFiles) # Get OutFile
ld A (A)
call flushA_F # Flush it
add C I # Increment vector index
loop
ret
### Low level I/O ###
(code 'stdinByte_A)
push Z
ld Z ((InFiles)) # Get stdin
null Z # Open?
if nz # Yes
call getBinaryZ_FB # Get byte
if nc
zxt
pop Z
ret
end
end
cc isatty(0) # STDIN
nul4 # on a tty?
if z # No
ld A -1 # Return EOF
pop Z
ret
end
ld E 0 # Exit OK
jmp byeE
(code 'getBinaryZ_FB 0)
ld A (Z I) # Get 'ix'
cmp A (Z II) # Equals 'cnt'?
if eq # Yes
null A # Closed?
js retc # Yes
call slowZ_F # Read into buffer
jz retc # EOF (c)
ld A 0 # 'ix'
end
inc (Z I) # Increment 'ix'
add A Z # Fetch byte (nc)
ld B (A VII) # from buffer
ret # nc
# Add next byte to a number
(code 'byteNumBCX_CX 0)
zxt
big X # Big number?
if z # No: Direct buffer pointer
# xxxxx.xxxxxxx.xxxxxxx.xxxxxxx.xxxxxxx.xxxxxxx.xxxxxxx.xxxxxxS010
# 59 51 43 35 27 19 11 3
cmp C 59 # Short digit full?
if ne # No
shl A C # Shift byte to character position
or (X) A # Combine with short number
add C 8 # Increment position
ret
end
ld C (X) # Get short number
shr C 3 # De-normalize, keep sign bit
shl A 56 # Combine byte with digit
or C A
call boxNum_A # Box number
ld (A DIG) C
ld (X) A
ld X A
ld C 0 # Start new digit
ret
end
null C # Last bit of big digit?
if z # Yes
ld C (X DIG)
shr A 1 # Get lowest bit
rcr C 1 # into highest bit of big digit
ld (X DIG) C
rcl A 1 # Get sign bit into A
shl A 3 # Normalize with sign
or A CNT # Make short number
ld (X BIG) A
ld C 11 # Set up for second byte
ret
end
cmp C 59 # Short digit full?
if ne # No
shl A C # Shift byte to character position
or (X BIG) A # Combine with name digit
add C 8 # Increment position
ret
end
ld C (X BIG) # Get short number
shr C 3 # De-normalize, keep sign bit
shl A 56 # Combine byte with digit
or C A
call boxNum_A # Box number
ld (A DIG) C
ld (X BIG) A
ld X A
ld C 0 # Start new digit
ret
# Read binary expression
(code 'binReadZ_FE)
call (GetBinZ_FB) # Tag byte?
jc ret # No
nul B # NIX?
jz retNil # Return NIL
zxt
test B (hex "FC") # Atomic?
if z # No
ld E A
cmp B BEG # Begin a list?
jne retnc # No: Return DOT or END (also in B)
call binReadZ_FE # Else read list
jc ret
push X
call consE_X # First cell
ld (X) E
ld (X CDR) Nil
link
push X # <L I> Save it
link
do
call binReadZ_FE # Next item
jc 10 # EOF
cmp E END # Any?
while ne # Yes
cmp E DOT # Dotted pair?
if eq
cmp B DOT # Only if B is also DOT (to distinguish from Zero)
if eq # Yes
call binReadZ_FE # Get CDR
if c # EOF
10 drop
pop X
ret # Return 'c'
end
cmp E END # Circular list?
ldz E (L I) # Yes: Get first cell
ld (X CDR) E # Store in last cell
break T # 'nc' (E > END)
end
end
call consE_C # Append next cell
ld (C) E
ld (C CDR) Nil
ld (X CDR) C
ld X C
loop
ld E (L I) # Return list
drop # Return 'nc'
pop X
ret
end
push X
link
push ZERO # <L I> Result
ld X S
link
ld E A # Get tag byte
shr E 2 # Count
and A 3 # Tag
if z # NUMBER
ld C 3 # Build signed number
cmp E 63 # More than one chunk?
if eq # Yes
do
do
call (GetBinZ_FB) # Next byte?
jc 90 # No
call byteNumBCX_CX
dec E # Decrement count
until z
call (GetBinZ_FB) # Next count?
jc 90 # No
zxt
ld E A
cmp B 255 # Another chunk?
until ne # No
or B B # Empty?
jz 20 # Yes
end
do
call (GetBinZ_FB) # Next byte?
jc 90 # No
call byteNumBCX_CX # (B is zero (not DOT) if Zero)
dec E # Decrement count
until z
20 ld E (L I) # Get result
big X # Big number?
if nz # Yes
ld A (X BIG) # Get last short
and A SIGN # Sign bit
off (X BIG) SIGN
or E A # Set sign bit in result
end
else # INTERN, TRANSIENT or EXTERN
push A # Tag
ld C 4 # Build name
cmp E 63 # More than one chunk?
if eq # Yes
do
do
call (GetBinZ_FB) # Next byte?
jc 90 # No
call byteSymBCX_CX
dec E # Decrement count
until z
call (GetBinZ_FB) # Next count?
jc 90 # No
zxt
ld E A
cmp B 255 # Another chunk?
until ne # No
or B B # Empty?
jz 30 # Yes
end
do
call (GetBinZ_FB) # Next byte?
jc 90 # No
call byteSymBCX_CX
dec E # Decrement count
until z
30 ld X (L I) # Get name
pop A # Get tag
cmp A TRANSIENT # Transient?
if eq # Yes
call consSymX_E # Build symbol
else
cmp A INTERN # Internal?
if eq # Yes
push Y
call findSymX_E # Find or create it
pop Y
else # External
null (Extn) # External symbol offset?
if nz # Yes
ld A X # Get file number
shr A 24 # Lower 8 bits
ld C A # into C
and C (hex "FF")
shr A 12 # Upper 8 bits
and A (hex "FF00")
or A C
add A (Extn) # Add external symbol offset
shl A 24
ld C A # Lower result bits
shl A 12
or A C
and A (hex "000FF000FF000000") # Mask file number
and X (hex "FFF00FFF00FFFFFF") # Mask object ID
or X A # Combine
end
call externX_E # New external symbol
end
end
end
clrc
90 drop
pop X
ret
# Binary print next byte from a number
(code 'prByteCEXY 0)
null C # New round?
if z # Yes
cnt X # Short number?
if z # No
ld E (X DIG) # Next digit
ld X (X BIG)
else
ld E X # Get short
shr E 4 # Normalize
end
shr Y 1 # Get overflow bit
rcl E 1 # Shift into digit
rcl Y 1 # Keep new overflow bit
ld C 8 # Init count
end
ld A E # Output next byte
call (PutBinBZ)
shr E 8 # Shift to next
dec C # Decrement count
ret
# Binary print short number
(code 'prCntCE 0)
ld A E
do
shr A 8 # More bytes?
while nz # Yes
add C 4 # Increment count
loop
ld A C # Output tag byte
call (PutBinBZ)
shr C 2 # Discard tag bits
do
ld A E # Next data byte
shr E 8
call (PutBinBZ) # Output data byte
dec C # More?
until z # No
ret
# Binary print expression
(code 'prTellEZ 0)
ld (PutBinBZ) putTellBZ # Set binary print function
ld (Extn) 0 # Set external symbol offset to zero
call binPrintEZ
ret
(code 'prE)
ld (PutBinBZ) putStdoutB # Set binary print function
(code 'binPrintEZ)
cnt E # Short number?
if nz # Yes
ld C 4 # Count significant bytes (adjusted to tag)
shr E 3 # Normalize
jmp prCntCE # Output 'cnt'
end
big E # Big number?
if nz # Yes
push X
push Y
push E # Save signed number
off E SIGN # Make positive
ld X E # Keep in X
ld A 8 # Count 8 significant bytes
do
ld C (E DIG) # Keep digit
ld E (E BIG) # More cells?
cnt E
while z # Yes
add A 8 # Increment count by 8
loop
shr E 4 # Normalize short
shl C 1 # Get most significant bit of last digit
addc E E # Any significant bits in short number?
if nz # Yes
do
inc A # Increment count
shr E 8 # More bytes?
until z # No
end
pop Y # Get sign
shr Y 3 # into lowest bit
ld C 0 # Init byte count
cmp A 63 # Single chunk?
if lt # Yes
push A # <S> Count
shl A 2 # Adjust to tag byte
call (PutBinBZ) # Output tag byte
do
call prByteCEXY # Output next data byte
dec (S) # More?
until z # No
else
sub A 63 # Adjust count
push A # <S I> Count
ld B (* 4 63) # Output first tag byte
call (PutBinBZ)
push 63 # <S> and first 63 data bytes
do
call prByteCEXY # Output next data byte
dec (S) # More?
until z # No
do
cmp (S I) 255 # Count greater or equal 255?
while ge # Yes
ld A 255 # Next chunk
ld (S) A # and the next 255 data bytes
call (PutBinBZ) # Output count byte
do
call prByteCEXY # Output next data byte
dec (S) # More?
until z # No
sub (S I) 255 # Decrement counter
loop
add S I # Drop second count
ld A (S) # Retrieve count
call (PutBinBZ) # Output last count
do
sub (S) 1 # More?
while ge # Yes
call prByteCEXY # Output next data byte
loop
end
add S I # Drop count
pop Y
pop X
ret
end
sym E # Symbol?
if nz # Yes
cmp E Nil # NIL?
if eq # Yes
ld B NIX # Output NIX
jmp (PutBinBZ)
end
sym (E TAIL) # External symbol?
if nz # Yes
ld E (E TAIL)
call nameE_E # Get name
null (Extn) # External symbol offset?
if nz # Yes
ld A E # Get file number
shr A 24 # Lower 8 bits
ld C A # into C
and C (hex "FF")
shr A 12 # Upper 8 bits
and A (hex "FF00")
or A C
sub A (Extn) # Subtract external symbol offset
shl A 24
ld C A # Lower result bits
shl A 12
or A C
and A (hex "000FF000FF000000") # Mask file number
and E (hex "FFF00FFF00FFFFFF") # Mask object ID
or E A # Combine
end
shl E 2 # Strip status bits
shr E 6 # Normalize
ld C (+ 4 EXTERN) # Count significant bytes (adjusted to tag)
jmp prCntCE # Output external name
end
push X
push Y
ld X (E TAIL)
call nameX_X # Get name
cmp X ZERO # Any?
if eq # No
ld B NIX # Output NIX
call (PutBinBZ)
else
ld Y ((EnvIntern))
call isInternEXY_F # Internal symbol?
ld C INTERN # Yes
ldnz C TRANSIENT # No
cnt X # Short name?
if nz # Yes
add C 4 # Count significant bytes (adjusted to tag)
ld E X # Get name
shr E 4 # Normalize
call prCntCE # Output internal or transient name
else # Long name
ld E X # Into E
ld A 8 # Count significant bytes
do
ld E (E BIG) # More cells?
cnt E
while z # Yes
add A 8 # Increment count
loop
shr E 4 # Any significant bits in short name?
if nz # Yes
do
inc A # Increment count
shr E 8 # More bytes?
until z # No
end
ld E A # Keep count in E
cmp A 63 # Single chunk?
if lt # Yes
shl A 2 # Adjust to tag byte
or A C # Combine with tag
call (PutBinBZ) # Output tag byte
ld C 0
do
call symByteCX_FACX # Next data byte
call (PutBinBZ) # Output it
dec E # More?
until z # No
else
ld B (* 4 63) # Output first tag byte
or A C # Combine with tag
call (PutBinBZ)
sub E 63 # Adjust count
push E # <S> Count
ld E 63 # and first 63 data bytes
ld C 0
do
call symByteCX_FACX # Next data byte
call (PutBinBZ) # Output it
dec E # More?
until z # No
do
cmp (S) 255 # Count greater or equal 255?
while ge # Yes
ld A 255 # Next chunk
ld E A # and the next 255 data bytes
call (PutBinBZ) # Output count byte
do
call symByteCX_FACX # Next data byte
call (PutBinBZ) # Output it
dec E # More?
until z # No
sub (S) 255 # Decrement counter
loop
pop E # Retrieve count
ld A E
call (PutBinBZ) # Output last count
do
sub E 1 # More?
while ge # Yes
call symByteCX_FACX # Next data byte
call (PutBinBZ) # Output it
loop
end
end
end
pop Y
pop X
ret
end
push X
push Y
ld B BEG # Begin list
call (PutBinBZ)
ld X E # Keep list in X
call circE_YF # Circular?
if nz # No
do
ld E (X) # Next item
call binPrintEZ
ld X (X CDR) # NIL-terminated?
cmp X Nil
while ne # No
atom X # Atomic tail?
if nz # Yes
ld B DOT # Output dotted pair
call (PutBinBZ)
ld E X # Output atom
call binPrintEZ
pop Y # Return
pop X
ret
end
loop
else
cmp X Y # Fully circular?
if eq # Yes
do
ld E (X) # Output CAR
call binPrintEZ
ld X (X CDR) # Done?
cmp X Y
until eq # Yes
ld B DOT # Output dotted pair
call (PutBinBZ)
else
do # Non-circular part
ld E (X) # Output CAR
call binPrintEZ
ld X (X CDR) # Done?
cmp X Y
until eq # Yes
ld B DOT # Output DOT+BEG
call (PutBinBZ)
ld B BEG
call (PutBinBZ)
do # Circular part
ld E (X) # Output CAR
call binPrintEZ
ld X (X CDR) # Done?
cmp X Y
until eq # Yes
ld B DOT # Output DOT+END
call (PutBinBZ)
ld B END
call (PutBinBZ)
end
end
pop Y
pop X
ld B END # End list
jmp (PutBinBZ)
# Family IPC
(code 'putTellBZ 0)
ld (Z) B # Store byte
inc Z # Increment pointer
lea A ((TellBuf) (- PIPE_BUF 1)) # Reached (TellBuf + PIPE_BUF - 1)?
cmp Z A
jeq tellErr # Yes
ret
(code 'tellBegZ_Z 0)
ld (TellBuf) Z # Set global buffer
add Z 4 # 4 bytes space (PID and count)
set (Z) BEG # Begin a list
inc Z
ret
(code 'tellEndAZ)
push X
push Y
set (Z) END # Close list
inc Z
ld X (TellBuf) # Get buffer
st2 (X) # Store PID
push A # <S I> PID
ld E Z # Calculate total size
sub E X
ld A E # Size in A
sub A 4 # without PID and count
st2 (X 2) # Store in buffer count
push A # <S> Size
ld C (Tell) # File descriptor
null C # Any?
if nz # Yes
call wrBytesCEX_F # Write buffer to pipe
if nz # Not successful
cc close(C) # Close 'Tell'
ld (Tell) 0 # Clear 'Tell'
end
end
ld Y (Child) # Iterate children
ld Z (Children) # Count
do
sub Z VI # More?
while ge # Yes
null (Y) # 'pid'?
if nz # Yes
ld A (S I) # Get PID
null A # Any?
jz 10 # Yes
cmp A (Y) # Same as 'pid'?
if eq # Yes
10 ld C (S) # Get size
lea X ((TellBuf) 4) # and data
call wrChildCXY # Write to child
end
end
add Y VI # Increment by sizeof(child)
loop
add S II # Drop size and PID
pop Y
pop X
ret
(code 'unsync 0) # X
ld C (Tell) # File descriptor
null C # Any?
if nz # Yes
push 0 # Send zero
ld X S # Get buffer
ld E 4 # Size (PID and count)
call wrBytesCEX_F # Write buffer to pipe
if nz # Not successful
cc close(C) # Close 'Tell'
ld (Tell) 0 # Clear 'Tell'
end
add S I # Drop buffer
end
set (Sync) 0 # Clear sync flag
ret
(code 'rdHear_FE)
push Z
ld A (Hear) # Get 'hear' fd
shl A 3 # Vector index
add A (InFiles) # Get vector
ld Z (A) # Input file
ld (GetBinZ_FB) getBinaryZ_FB # Set binary read function
ld (Extn) 0 # Set external symbol offset to zero
call binReadZ_FE # Read item
pop Z
ret
# Return next byte from symbol name
(code 'symByteCX_FACX 0)
null C # New round?
if z # Yes
cmp X ZERO # Done?
jeq ret # Yes: Return 'z'
cnt X # Short?
if nz # Yes
ld C X # Get short
shr C 4 # Normalize
ld X ZERO # Clear for next round
else
ld C (X DIG) # Get next digit
ld X (X BIG)
end
end
ld A C # Get byte
shr C 8 # Shift out
or B B # Return B
zxt
ret
(code 'symCharCX_FACX 0) # Return next char from symbol name
call symByteCX_FACX # First byte
jz ret # Return 'z' if none
cmp B (hex "FF") # Special?
if ne # No
cmp B 128 # Single byte?
if ge # No
test B (hex "20") # Two bytes?
if z # Yes
and B (hex "1F") # First byte 110xxxxx
shl A 6 # xxxxx000000
push A
else # Three bytes
and B (hex "F") # First byte 1110xxxx
shl A 6 # xxxx000000
push A
call symByteCX_FACX # Second byte
and B (hex "3F") # 10xxxxxx
or A (S) # Combine
shl A 6 # xxxxxxxxxx000000
ld (S) A
end
call symByteCX_FACX # Last byte
and B (hex "3F") # 10xxxxxx
or (S) A # Combine
pop A # Get result
end
ret
end
ld A TOP # Return special "top" character
or A A
ret
(code 'bufStringE_SZ 0)
ld Z S # 8-byte-buffer
push (Z) # Save return address
push X # and X
cmp E Nil # Empty?
if ne # No
ld X (E TAIL)
call nameX_X # Get name
ld C 0
do
call symByteCX_FACX
while nz
ld (Z) B # Store next byte
inc Z
test Z 7 # Buffer full?
if z # Yes
sub S 8 # Extend buffer
cmp S (StkLimit) # Stack check
jlt stkErr
movm (S) (S 8) (Z)
sub Z 8 # Reset buffer pointer
end
loop
end
set (Z) 0 # Null byte
add Z 8 # Round up
off Z 7
pop X
ret
(code 'pathStringE_SZ 0)
ld Z S # 8-byte-buffer
push (Z) # Save return address
push X # and X
cmp E Nil # Empty?
if ne # No
ld X (E TAIL)
call nameX_X # Get name
ld C 0
call symByteCX_FACX # First byte
if nz
cmp B (char "+") # Plus?
if eq
ld (Z) B # Store "+"
inc Z
call symByteCX_FACX # Second byte
end
cmp B (char "@") # Home path?
if ne # No
do
ld (Z) B # Store byte
inc Z
test Z 7 # Buffer full?
if z # Yes
sub S 8 # Extend buffer
movm (S) (S 8) (Z)
sub Z 8 # Reset buffer pointer
end
call symByteCX_FACX # Next byte?
until z # No
else
push E
ld E (Home) # Home directory?
null E
if nz # Yes
do
ld B (E)
ld (Z) B # Store next byte
inc Z
test Z 7 # Buffer full?
if z # Yes
sub S 8 # Extend buffer
movm (S) (S 8) (Z)
sub Z 8 # Reset buffer pointer
end
inc E
nul (E) # More?
until z # No
end
pop E
do
call symByteCX_FACX
while nz
ld (Z) B # Store next byte
inc Z
test Z 7 # Buffer full?
if z # Yes
sub S 8 # Extend buffer
movm (S) (S 8) (Z)
sub Z 8 # Reset buffer pointer
end
loop
end
end
end
set (Z) 0 # Null byte
add Z 8 # Round up
off Z 7
pop X
ret
# (path 'any) -> sym
(code 'doPath 2)
push Z
ld E ((E CDR)) # Get arg
call evSymE_E # Evaluate to a symbol
call pathStringE_SZ # Write to stack buffer
ld E S # Make transient symbol
call mkStrE_E
ld S Z # Drop buffer
pop Z
ret
# Add next char to symbol name
(code 'charSymACX_CX 0)
cmp A (hex "80") # ASCII??
jlt byteSymBCX_CX # Yes: 0xxxxxxx
cmp A (hex "800") # Double-byte?
if lt # Yes
push A # 110xxxxx 10xxxxxx
shr A 6 # Upper five bits
and B (hex "1F")
or B (hex "C0")
call byteSymBCX_CX # Add first byte
pop A
and B (hex "3F") # Lower 6 bits
or B (hex "80")
jmp byteSymBCX_CX # Add second byte
end
cmp A TOP # Special "top" character?
if eq # Yes
ld B (hex "FF")
jmp byteSymBCX_CX
end
push A # 1110xxxx 10xxxxxx 10xxxxxx
shr A 12 # Hightest four bits
and B (hex "0F")
or B (hex "E0")
call byteSymBCX_CX # Add first byte
ld A (S)
shr A 6 # Middle six bits
and B (hex "3F")
or B (hex "80")
call byteSymBCX_CX # Add second byte
pop A
and B (hex "3F") # Lowest 6 bits
or B (hex "80") # Add third byte
# Add next byte to symbol name
(code 'byteSymBCX_CX 0)
zxt
big X # Long name?
if z # No: Direct buffer pointer
# 0000.xxxxxxx.xxxxxxx.xxxxxxx.xxxxxxx.xxxxxxx.xxxxxxx.xxxxxxx0010
# 60 52 44 36 28 20 12 4
cmp C 60 # Short digit full?
if ne # No
shl A C # Shift byte to character position
or (X) A # Combine with name digit
add C 8 # Increment position
ret
end
ld C (X) # Get short number
shr C 4 # De-normalize
shl A 56 # Combine byte with digit
or C A
call boxNum_A # Box number
ld (A DIG) C
ld (X) A
ld X A
ld C 4 # Start new digit
ret
end
cmp C 60 # Short digit full?
if ne # No
shl A C # Shift byte to character position
or (X BIG) A # Combine with name digit
add C 8 # Increment position
ret
end
ld C (X BIG) # Get short number
shr C 4 # De-normalize
shl A 56 # Combine byte with digit
or C A
call boxNum_A # Box number
ld (A DIG) C
ld (X BIG) A
ld X A
ld C 4 # Start new digit
ret
(code 'currFdX_C 0)
ld C (EnvInFrames) # InFrames or OutFrames?
or C (EnvOutFrames)
jz noFdErrX # No
(code 'currFd_C)
ld C (EnvOutFrames) # OutFrames?
null C
if z # No
ld C (EnvInFrames) # Use InFrames
else
null (EnvInFrames) # InFrames?
if nz # Both
cmp C (EnvInFrames) # OutFrames > InFrames?
if gt # Yes
ld C (EnvInFrames) # Take InFrames
end
end
end
ld C (C I) # Get 'fd'
ret
(code 'rdOpenEXY)
cmp E Nil # Standard input?
if eq # Yes
ld (Y I) 0 # fd = stdin
ld (Y II) 0 # pid = 0
else
num E # Descriptor?
if nz # Yes
cnt E # Need short
jz cntErrEX
ld (Y II) 0 # pid = 0
ld A E # Get fd
shr A 4 # Normalize
if c # Negative
ld C (EnvInFrames) # Fetch from input frames
do
ld C (C) # Next frame
null C # Any?
jz badFdErrEX # No
dec A # Found frame?
until z # Yes
ld A (C I) # Get fd from frame
end
ld (Y I) A # Store 'fd'
shl A 3 # Vector index
cmp A (InFDs) # 'fd' >= 'InFDs'?
jge badFdErrEX # Yes
add A (InFiles) # Get vector
ld A (A) # Input file
null A # Any?
jz badFdErrEX # No
else
push Z
sym E # File name?
if nz # Yes
ld (Y II) 1 # pid = 1
call pathStringE_SZ
do
ld B (S) # First char
cmp B (char "+") # Plus?
if eq # Yes
cc open(&(S 1) (| O_APPEND O_CREAT O_RDWR) (oct "0666"))
else
cc open(S O_RDONLY)
end
nul4 # OK?
while s # No
call errno_A
cmp A EINTR # Interrupted?
jne openErrEX # No
null (Signal) # Signal?
if nz # Yes
call sighandlerX
end
loop
ld (Y I) A # Save 'fd'
ld B (S) # First char
cmp B (char "+") # Plus?
if eq # Yes
cc strdup(&(S 1)) # Duplicate name
else
cc strdup(S) # Duplicate name
end
ld C (Y I) # Get 'fd'
call initInFileCA_A
ld A (Y I) # Get fd
call closeOnExecAX
ld S Z # Drop buffer
else # Else pipe
push X
push 0 # End-of-buffers marker
ld X E # Get list
ld E (X) # Pathname
call xSymE_E # Make symbol
call pathStringE_SZ # Write to stack buffer
do
ld X (X CDR) # Arguments?
atom X
while z # Yes
push Z # Buffer chain
ld E (X) # Next argument
call xSymE_E # Make symbol
call bufStringE_SZ # Write to stack buffer
loop
push Z
ld Z S # Point to chain
ld X Z
push 0 # NULL terminator
do
lea A (X I) # Buffer pointer
push A # Push to vector
ld X (X) # Follow chain
null (X) # Done?
until z # Yes
ld X (X I) # Retrieve X
push A # Create 'pipe' structure
cc pipe(S) # Open pipe
nul4 # OK?
jnz pipeErrX
ld4 (S) # Get pfd[0]
call closeOnExecAX
ld4 (S 4) # Get pfd[1]
call closeOnExecAX
cc fork() # Fork child process
ld (Y II) A # Set 'pid'
nul4 # In child?
js forkErrX
if z # Yes
cc setpgid(0 0) # Set process group
ld4 (S) # Close read pipe
call closeAX
ld4 (S 4) # Get write pipe
cmp A 1 # STDOUT_FILENO?
if ne # No
cc dup2(A 1) # Dup to STDOUT_FILENO
ld4 (S 4) # Close write pipe
call closeAX
end
add S I # Drop 'pipe' structure
cc execvp((S) S) # Execute program
jmp execErrS # Error if failed
end
cc setpgid(A 0) # Set process group
ld4 (S 4) # Close write pipe
call closeAX
ld4 (S) # Get read pipe
ld (Y I) A # Set 'fd'
call initInFileA_A
add S I # Drop 'pipe' structure
do
ld S Z # Clean up buffers
pop Z # Chain
null Z # End?
until z # Yes
pop X
end
pop Z
end
end
ret
(code 'wrOpenEXY)
cmp E Nil # Standard output?
if eq # Yes
ld (Y I) 1 # fd = stdout
ld (Y II) 0 # pid = 0
else
num E # Descriptor?
if nz # Yes
cnt E # Need short
jz cntErrEX
ld (Y II) 0 # pid = 0
ld A E # Get fd
shr A 4 # Normalize
if c # Negative
ld C (EnvOutFrames) # Fetch from output frames
do
ld C (C) # Next frame
null C # Any?
jz badFdErrEX # No
dec A # Found frame?
until z # Yes
ld A (C I) # Get fd from frame
end
ld (Y I) A # Store 'fd'
shl A 3 # Vector index
cmp A (OutFDs) # 'fd' >= 'OutFDs'?
jge badFdErrEX # Yes
add A (OutFiles) # Get vector
ld A (A) # Slot?
null A # Any?
jz badFdErrEX # No
else
push Z
sym E # File name?
if nz # Yes
ld (Y II) 1 # pid = 1
call pathStringE_SZ
do
ld B (S) # First char
cmp B (char "+") # Plus?
if eq # Yes
cc open(&(S 1) (| O_APPEND O_CREAT O_WRONLY) (oct "0666"))
else
cc open(S (| O_CREAT O_TRUNC O_WRONLY) (oct "0666"))
end
nul4 # OK?
while s # No
call errno_A
cmp A EINTR # Interrupted?
jne openErrEX # No
null (Signal) # Signal?
if nz # Yes
call sighandlerX
end
loop
ld (Y I) A # Save 'fd'
call initOutFileA_A
ld A (Y I) # Get fd
call closeOnExecAX
ld S Z # Drop buffer
else # Else pipe
push X
push 0 # End-of-buffers marker
ld X E # Get list
ld E (X) # Pathname
call xSymE_E # Make symbol
call pathStringE_SZ # Write to stack buffer
do
ld X (X CDR) # Arguments?
atom X
while z # Yes
push Z # Buffer chain
ld E (X) # Next argument
call xSymE_E # Make symbol
call bufStringE_SZ # Write to stack buffer
loop
push Z
ld Z S # Point to chain
ld X Z
push 0 # NULL terminator
do
lea A (X I) # Buffer pointer
push A # Push to vector
ld X (X) # Follow chain
null (X) # Done?
until z # Yes
ld X (X I) # Retrieve X
push A # Create 'pipe' structure
cc pipe(S) # Open pipe
nul4 # OK?
jnz pipeErrX
ld4 (S) # Get pfd[0]
call closeOnExecAX
ld4 (S 4) # Get pfd[1]
call closeOnExecAX
cc fork() # Fork child process
ld (Y II) A # Set 'pid'
nul4 # In child?
js forkErrX
if z # Yes
cc setpgid(0 0) # Set process group
ld4 (S 4) # Close write pipe
call closeAX
ld4 (S) # Get read pipe
null A # STDIN_FILENO?
if ne # No
cc dup2(A 0) # Dup to STDIN_FILENO
ld4 (S) # Close read pipe
call closeAX
end
add S I # Drop 'pipe' structure
cc execvp((S) S) # Execute program
jmp execErrS # Error if failed
end
cc setpgid(A 0) # Set process group
ld4 (S) # Close read pipe
call closeAX
ld4 (S 4) # Get write pipe
ld (Y I) A # Set 'fd'
call initOutFileA_A
add S I # Drop 'pipe' structure
do
ld S Z # Clean up buffers
pop Z # Chain
null Z # End?
until z # Yes
pop X
end
pop Z
end
end
ret
(code 'erOpenEXY)
num E # Need symbol
jnz symErrEX
sym E
jz symErrEX
cc dup(2) # Duplicate current stderr
ld (Y I) A # Save it
cmp E Nil # Use current output channel?
if eq # Yes
cc dup(((OutFile))) # Duplicate 'fd'
ld C A # Keep in C
else
push Z
call pathStringE_SZ # File name
do
ld B (S) # First char
cmp B (char "+") # Plus?
if eq # Yes
cc open(&(S 1) (| O_APPEND O_CREAT O_WRONLY) (oct "0666"))
else
cc open(S (| O_CREAT O_TRUNC O_WRONLY) (oct "0666"))
end
nul4 # OK?
while s # No
call errno_A
cmp A EINTR # Interrupted?
jne openErrEX # No
null (Signal) # Signal?
if nz # Yes
call sighandlerX
end
loop
ld S Z # Drop buffer
pop Z
ld C A # Keep 'fd' in C
call closeOnExecAX
end
cc dup2(C 2) # Dup 'fd' to STDERR_FILENO
ld A C
call closeAX
ret
(code 'ctOpenEXY)
num E # Need symbol
jnz symErrEX
sym E
jz symErrEX
cmp E Nil # Shared lock on current I/O channel?
if eq # Yes
ld (Y I) -1 # 'fd'
call currFdX_C # Get current fd
call rdLockFileC
else
cmp E TSym # Exclusive lock on current I/O channel?
if eq # Yes
ld (Y I) -1 # 'fd'
call currFdX_C # Get current fd
call wrLockFileC
else
push Z
call pathStringE_SZ # File name
do
ld B (S) # First char
cmp B (char "+") # Plus?
if eq # Yes
cc open(&(S 1) (| O_CREAT O_RDWR) (oct "0666"))
else
cc open(S (| O_CREAT O_RDWR) (oct "0666"))
end
nul4 # OK?
while s # No
call errno_A
cmp A EINTR # Interrupted?
jne openErrEX # No
null (Signal) # Signal?
if nz # Yes
call sighandlerX
end
loop
ld S Z # Drop buffer
pop Z
ld (Y I) A # Save 'fd'
ld C A # Keep in C
ld B (S) # First char
cmp B (char "+") # Plus?
if eq # Yes
call rdLockFileC # Read lock
else
call wrLockFileC # Write lock
end
ld A (Y I) # Get fd
call closeOnExecAX
end
end
ret
(code 'getStdin_A 0)
push Z
ld Z (InFile) # Current InFile
null Z # Any?
if nz # Yes
cmp Z ((InFiles)) # On stdin?
if ne # No
ld A (Z I) # Get 'ix'
cmp A (Z II) # Equals 'cnt'?
if eq # Yes
null A # Closed?
js 90 # Return -1
call slowZ_F # Read into buffer
jz 90 # Return -1
ld A 0 # 'ix'
end
inc (Z I) # Increment 'ix'
add A Z # Fetch byte
ld B (A VII) # from buffer
cmp B 10 # Newline?
if eq # Yes
inc (Z IV) # Increment line
end
zxt # Extend into A
else
push C
push E
push X
atom (Led) # Line editor?
if nz # No
ld C 0 # Standard input
ld E -1 # No timeout
ld X 0 # Runtime expression
call waitFdCEX_A # Wait for events
call stdinByte_A # Get byte
else
ld C (LineC)
null C # First call?
if ns # No
ld X (LineX) # Get line status
else
ld E (Led) # Run line editor
call runE_E
cmp E Nil # NIL
if eq # Yes
ld X ZERO # Empty
else
ld X (E TAIL)
call nameX_X # Get name
end
ld C 0
end
call symByteCX_FACX # Extract next byte
if z # None
ld A 10 # Default to linefeed
ld C -1
end
ld (LineX) X # Save line status
ld (LineC) C
end
pop X
pop E
pop C
end
else
90 ld A -1 # Return EOF
end
ld (Chr) A
pop Z
ret
(code 'getParse_A 0)
push C
push X
ld X (EnvParseX) # Get parser status
ld C (EnvParseC)
call symByteCX_FACX # Extract next byte
if z # Done
ld A (EnvParseEOF) # Get parser trail bytes
shr A 8 # More bytes?
ld (EnvParseEOF) A
if nz # Yes
zxt # Return next byte
else
dec A # Return -1
end
end
ld (Chr) A
ld (EnvParseX) X # Save status
ld (EnvParseC) C
pop X
pop C
ret
(code 'pushInFilesY)
ld A (InFile) # Current InFile?
null A
if nz # Yes
ld (A III) (Chr) # Save Chr in next
end
ld A (Y I) # Get 'fd'
shl A 3 # Vector index
add A (InFiles) # Get InFile
ld A (A)
ld (InFile) A # Store new
null A # Any?
if nz # Yes
ld A (A III) # Get 'next'
else
ld A -1
end
ld (Chr) A # Save in 'Chr'
ld (Y III) (Get_A) # Save 'get'
ld (Get_A) getStdin_A # Set new
ld (Y) (EnvInFrames) # Set link
ld (EnvInFrames) Y # Link frame
ret
(code 'pushOutFilesY)
ld A (Y I) # Get 'fd'
shl A 3 # Vector index
add A (OutFiles) # Get OutFile
ld (OutFile) (A) # Store new
ld (Y III) (PutB) # Save 'put'
ld (PutB) putStdoutB # Set new
ld (Y) (EnvOutFrames) # Set link
ld (EnvOutFrames) Y # Link frame
ret
(code 'pushErrFilesY)
ld (Y) (EnvErrFrames) # Set link
ld (EnvErrFrames) Y # Link frame
ret
(code 'pushCtlFilesY)
ld (Y) (EnvCtlFrames) # Set link
ld (EnvCtlFrames) Y # Link frame
ret
(code 'popInFiles) # C
ld C (EnvInFrames) # Get InFrames
null (C II) # 'pid'?
if nz # Yes
cc close((C I)) # Close 'fd'
ld A (C I) # Close input file
call closeInFileA
cmp (C II) 1 # 'pid' > 1?
if gt # Yes
do
cc waitpid((C II) 0 0) # Wait for pipe process
nul4 # OK?
while s # No
call errno_A
cmp A EINTR # Interrupted?
jne closeErrX
null (Signal) # Signal?
if nz # Yes
call sighandler0
end
loop
end
else
ld A (InFile) # Current InFile?
null A
if nz # Yes
ld (A III) (Chr) # Save Chr in next
end
end
ld (Get_A) (C III) # Retrieve 'get'
ld C (C) # Get link
ld (EnvInFrames) C # Restore InFrames
null C # Any?
if z # No
ld A ((InFiles)) # InFiles[0] (stdin)
else
ld A (C I) # Get 'fd'
shl A 3 # Vector index
add A (InFiles)
ld A (A) # Get previous InFile
end
ld (InFile) A # Set InFile
null A # Any?
if nz # Yes
ld A (A III) # Get 'next'
else
ld A -1
end
ld (Chr) A # Save in 'Chr'
ret
(code 'popOutFiles) # C
ld A (OutFile) # Flush OutFile
call flushA_F
ld C (EnvOutFrames) # Get OutFrames
null (C II) # 'pid'?
if nz # Yes
cc close((C I)) # Close 'fd'
ld A (C I) # Close input file
call closeOutFileA
cmp (C II) 1 # 'pid' > 1?
if gt # Yes
do
cc waitpid((C II) 0 0) # Wait for pipe process
nul4 # OK?
while s # No
call errno_A
cmp A EINTR # Interrupted?
jne closeErrX
null (Signal) # Signal?
if nz # Yes
call sighandler0
end
loop
end
end
ld (PutB) (C III) # Retrieve 'put'
ld C (C) # Get link
ld (EnvOutFrames) C # Restore OutFrames
null C # Any?
if z # No
ld A ((OutFiles) I) # OutFiles[1] (stdout)
else
ld A (C I) # Get 'fd'
shl A 3 # Vector index
add A (OutFiles)
ld A (A) # Get previous OutFile
end
ld (OutFile) A # Set OutFile
ret
(code 'popErrFiles) # C
ld C (EnvErrFrames) # Get ErrFrames
cc dup2((C I) 2) # Restore stderr
cc close((C I)) # Close 'fd'
ld (EnvErrFrames) ((EnvErrFrames)) # Restore ErrFrames
ret
(code 'popCtlFiles) # C
ld C (EnvCtlFrames) # Get CtlFrames
null (C I) # 'fd' >= 0?
if ns # Yes
cc close((C I)) # Close 'fd'
else
call currFd_C # Get current fd
ld A (| F_UNLCK (hex "00000")) # Unlock, length 0
call unLockFileAC # Unlock
end
ld (EnvCtlFrames) ((EnvCtlFrames)) # Restore CtlFrames
ret
# Get full char from input channel
(code 'getChar_A 0)
ld A (Chr) # Get look ahead
cmp B (hex "FF") # Special "top" character?
if ne # No
cmp B 128 # Single byte?
if ge # No
test B (hex "20") # Two bytes?
if z # Yes
and B (hex "1F") # First byte 110xxxxx
shl A 6 # xxxxx000000
push A
else # Three bytes
and B (hex "F") # First byte 1110xxxx
shl A 6 # xxxx000000
push A
call (Get_A) # Get second byte
and B (hex "3F") # 10xxxxxx
or A (S) # Combine
shl A 6 # xxxxxxxxxx000000
ld (S) A
end
call (Get_A) # Get last byte
and B (hex "3F") # 10xxxxxx
or (S) A # Combine
pop A # Get result
end
ret
end
ld A TOP
ret
# Skip White Space and Comments
(code 'skipC_A 0)
ld A (Chr)
do
null A # EOF?
while ns # No
do
cmp B 32 # White space?
while le # Yes
call (Get_A) # Get next
null A # EOF?
js ret # Yes
loop
cmp A C # Comment char?
while eq # Yes
call (Get_A)
cmp C (char "#") # Block comment?
jne 10 # No
cmp B (char "{")
if ne # No
10 do
cmp B 10 # Linefeed?
while ne #No
null A # EOF?
js ret # Yes
call (Get_A)
loop
else # Block comment
do
call (Get_A)
null A # EOF?
js ret # Yes
cmp B (char "}") # End of block comment?
if eq
call (Get_A)
cmp B (char "#")
break eq # Yes
end
loop
end
call (Get_A)
loop
ret
(code 'testEscA_F 0)
do
null A # EOF?
if s # Yes
clrc # Return NO
ret
end
cmp B (char "\^") # Caret?
if eq # Yes
call (Get_A) # Skip '^'
cmp B (char "@") # At-mark?
jeq badInputErrB # Yes
cmp B (char "?") # Question-mark?
if eq # Yes
ld B 127 # DEL
else
and B 31 # Control-character
end
10 setc # Return YES
ret
end
cmp B (char "\\") # Backslash?
jnz 10 # No
call (Get_A) # Skip '\'
cmp B 10 # Newline?
jnz 10 # No
do
call (Get_A) # Skip white space
cmp B 32
continue eq
cmp B 9
until ne
loop
(code 'anonymousX_FE 0)
ld C 0
call symByteCX_FACX # First byte
cmp B (char "$") # Starting with '$'?
jne Ret # No
call symByteCX_FACX # Second byte
cmp B (char "1") # >= '1'?
if ge # Yes
cmp B (char "7") # <= '7'?
if le # Yes
sub B (char "0") # Digit
ld E A # Calculate number
call symByteCX_FACX # Third byte
do
cmp B (char "0") # >= '0'?
while ge # Yes
cmp B (char "7") # <= '7'?
while le # Yes
shl E 3 # Times 8
sub B (char "0") # Digit
add E A # Add to result
call symByteCX_FACX # Next byte?
if z # No
shl E 4 # Make symbol pointer
or E SYM
setz
ret
end
loop
end
end
ret
(code 'rdAtomBY_E) # X
link
push (EnvIntern) # <L II> Current symbol namespace
push ZERO # <L I> Result
ld C 4 # Build name
ld X S
link
call byteSymBCX_CX # Pack first char
ld A Y # Get second
do
null A # EOF?
while ns # No
cmp B (char "~") # Tilde?
if eq # Yes
ld X (L I) # Get name so far
call findSymX_E # Find or create symbol
ld X 0 # Clear error context
atom (E) # Value must be a pair
jnz symNsErrEX
ld (EnvIntern) E # Switch symbol namespace
ld C 4 # Build new name
lea X (L I) # Safe
ld (X) ZERO
call (Get_A) # Get next char
continue T
end
memb Delim "(DelimEnd-Delim)" # Delimiter?
break eq # Yes
cmp B (char "\\") # Backslash?
if eq # Yes
call (Get_A) # Get next char
end
call byteSymBCX_CX # Pack char
call (Get_A) # Get next
loop
ld X (L I) # Get name
ld A (Scl) # Scale
shr A 4 # Normalize
ld (Sep3) 0 # Thousand separator
ld (Sep0) (char ".") # Decimal separator
call symToNumXA_FE # Legal number?
if nc # No
ld X (L I) # Get name
call anonymousX_FE # Anonymous symbol?
if ne # No
ld X (L I) # Get name
call findSymX_E # Find or create symbol
end
end
ld (EnvIntern) (L II) # Restore current symbol namespace
drop
ret
(code 'rdList_E)
cmp S (StkLimit) # Stack check
jlt stkErr
call (Get_A) # Skip paren
do
ld C (char "#")
call skipC_A # and white space
cmp B (char ")") # Empty list?
if eq # Yes
call (Get_A) # Skip paren
ld E Nil # Return NIL
ret
end
cmp B (char "]") # Empty list?
jz retNil # Yes
cmp B (char "~") # Tilde?
if ne # No
ld A 0
call readA_E # Read expression
call consE_A # Make a pair
ld (A) E
ld (A CDR) Nil
link
push A # <L I> Save it
link
ld E A # Keep last cell in E
jmp 10 # Exit
end
call (Get_A) # Skip tilde
ld A 0
call readA_E # Read expression
link
push E # <L I> Save it
link
eval # Evaluate
ld (L I) E # Save again
atom E # Pair?
if z # Yes
do
atom (E CDR) # Find last cell
while z
ld E (E CDR)
loop
jmp 10 # Exit
end
drop # Continue
loop
10 do
ld C (char "#")
call skipC_A # Skip white space
cmp B (char ")") # Done?
if eq # Yes
call (Get_A) # Skip paren
jmp 90 # Done
end
cmp B (char "]") # Done?
jz 90 # Yes
cmp B (char ".") # Dotted pair?
if eq # Yes
call (Get_A) # Skip dot
memb Delim "(DelimEnd-Delim)" # Delimiter?
if eq # Yes
ld C (char "#")
call skipC_A # and white space
cmp B (char ")") # Circular list?
jz 20 # Yes
cmp B (char "]")
if eq # Yes
20 ld (E CDR) (L I) # Store list in CDR
else
push E
ld A 0
call readA_E # Read expression
ld A E
pop E
ld (E CDR) A # Store in CDR
end
ld C (char "#")
call skipC_A # Skip white space
cmp B (char ")") # Done?
if eq # Yes
call (Get_A) # Skip paren
jmp 90 # Done
end
cmp B (char "]")
jz 90 # Done
ld E (L I) # Else bad dottet pair
jmp badDotErrE
end
push X
push Y
push E
ld Y A # Save first char
ld B (char ".") # Restore dot
call rdAtomBY_E # Read atom
call consE_A # Make a pair
ld (A) E
ld (A CDR) Nil
pop E
ld (E CDR) A # Store in last cell
ld E A
pop Y
pop X
else
cmp B (char "~") # Tilde?
if ne # No
push E
ld A 0
call readA_E # Read expression
call consE_A # Make a pair
ld (A) E
ld (A CDR) Nil
pop E
ld (E CDR) A # Store in last cell
ld E A
else
call (Get_A) # Skip tilde
push E
ld A 0
call readA_E # Read expression
ld A (S)
ld (A CDR) E # Save in last cell
eval # Evaluate
pop A
ld (A CDR) E # Store in last cell
ld E A
do
atom (E CDR) # Pair?
while z # Yes
ld E (E CDR) # Find last cell
loop
end
end
loop
90 ld E (L I) # Return list
drop
ret
(code 'readA_E)
push X
push Y
push A # <S> Top flag
ld C (char "#")
call skipC_A
null A # EOF?
if s # Yes
null (S) # Top?
jz eofErr # No: Error
ld E Nil # Yes: Return NIL
jmp 99
end
null (S) # Top?
if nz # Yes
ld C (InFile) # And reading file?
null C
if nz # Yes
ld (C V) (C IV) # src = line
end
end
cmp B (char "(") # Opening a list?
if eq # Yes
call rdList_E # Read it
null (S) # Top?
if nz # Yes
cmp (Chr) (char "]") # And super-parentheses?
if eq # Yes
call (Get_A) # Skip ']'
end
end
jmp 99 # Return list
end
cmp B (char "[") # Opening super-list?
if eq # Yes
call rdList_E # Read it
cmp (Chr) (char "]") # Matching super-parentheses?
jnz suparErrE # Yes: Error
call (Get_A) # Else skip ']'
jmp 99
end
cmp B (char "'") # Quote?
if eq # Yes
call (Get_A) # Skip "'"
ld A 0
call readA_E # Read expression
ld C E
call consC_E # Cons with 'quote'
ld (E) Quote
ld (E CDR) C
jmp 99
end
cmp B (char ",") # Comma?
if eq # Yes
call (Get_A) # Skip ','
ld A 0
call readA_E # Read expression
ld X Uni # Maintain '*Uni' index
cmp (X) TSym # Disabled?
jeq 99 # Yes
link
push E # Else save expression
link
ld Y E
call idxPutXY_E
atom E # Pair?
if z # Yes
ld E (E) # Return index entry
else
ld E Y # 'read' value
end
drop
jmp 99
end
cmp B (char "`") # Backquote?
if eq # Yes
call (Get_A) # Skip '`'
ld A 0
call readA_E # Read expression
link
push E # Save it
link
eval # Evaluate
drop
jmp 99
end
cmp B (char "\"") # String?
if eq # Yes
call (Get_A) # Skip '"'
cmp B (char "\"") # Empty string?
if eq # Yes
call (Get_A) # Skip '"'
ld E Nil # Return NIL
jmp 99
end
call testEscA_F
jnc eofErr
link
push ZERO # <L I> Result
ld C 4 # Build name
ld X S
link
do
call byteSymBCX_CX # Pack char
call (Get_A) # Get next
cmp B (char "\"") # Done?
while ne
call testEscA_F
jnc eofErr
loop
call (Get_A) # Skip '"'
ld X (L I) # Get name
ld Y Transient
ld E 0 # No symbol yet
call internEXY_FE # Check transient symbol
drop
jmp 99
end
cmp B (char "{") # External symbol?
if eq # Yes
call (Get_A) # Skip '{'
cmp B (char "}") # Empty?
if eq # Yes
call (Get_A) # Skip '}'
call cons_E # New symbol
ld (E) ZERO # anonymous
or E SYM
ld (E) Nil # Set to NIL
jmp 99
end
ld E 0 # Init file number
do
cmp B (char "@") # File done?
while ge # No
cmp B (char "O") # In A-O range?
jgt badInputErrB # Yes
sub B (char "@")
shl E 4 # Add to file number
add E A
call (Get_A) # Get next char
loop
cmp B (char "0") # Octal digit?
jlt badInputErrB
cmp B (char "7")
jgt badInputErrB # No
sub B (char "0")
zxt
ld C A # Init object ID
do
call (Get_A) # Get next char
cmp B (char "}") # Done?
while ne # No
cmp B (char "0") # Octal digit?
jlt badInputErrB
cmp B (char "7")
jgt badInputErrB # No
sub B (char "0")
shl C 3 # Add to object ID
add C A
loop
call (Get_A) # Skip '}'
call extNmCE_X # Build external symbol name
call externX_E # New external symbol
jmp 99
end
cmp B (char ")") # Closing paren?
jeq badInputErrB # Yes
cmp B (char "]")
jeq badInputErrB
cmp B (char "~") # Tilde?
jeq badInputErrB # Yes
cmp B (char "\\") # Backslash?
if eq # Yes
call (Get_A) # Get next char
end
ld Y A # Save in Y
call (Get_A) # Next char
xchg A Y # Get first char
call rdAtomBY_E # Read atom
99 pop A
pop Y
pop X
ret
(code 'readC_E)
null (Chr) # Empty channel?
if z # Yes
call (Get_A) # Fill 'Chr'
end
cmp C (Chr) # Terminator?
if eq # Yes
ld E Nil # Return 'NIL'
else
ld A 1 # Top level
call readA_E # Read expression
push E
ld A (Chr)
do
null A # EOF?
while nsz # No
cmp B 32 # Space?
jz 10
cmp B 9 # Tab?
jz 10
cmp B (char ")") # or closing parens?
jz 10
cmp B (char "]")
while eq # Yes
10 call (Get_A)
loop
pop E
end
ret
(code 'tokenCE_E) # X
null (Chr) # Look ahead char?
if z # No
call (Get_A) # Get next
end
call skipC_A # Skip white space and comments
null A # EOF?
js retNull # Yes
cmp B (char "\"") # String?
if eq # Yes
call (Get_A) # Skip '"'
cmp B (char "\"") # Empty string?
if eq # Yes
call (Get_A) # Skip '"'
ld E Nil # Return NIL
ret
end
call testEscA_F
jnc retNil
link
push ZERO # <L I> Result
ld C 4 # Build name
ld X S
link
do
call byteSymBCX_CX # Pack char
call (Get_A) # Get next
cmp B (char "\"") # Done?
if eq # Yes
call (Get_A) # Skip '"'
break T
end
call testEscA_F
until nc
ld X (L I) # Get name
drop
jmp consSymX_E # Make transient symbol
end
cmp B (char "0") # Digit?
if ge
cmp B (char "9")
if le # Yes
link
push ZERO # <L I> Result
ld C 4 # Build digit string
ld X S
link
do
call byteSymBCX_CX # Pack char
call (Get_A) # Get next
cmp B (char ".") # Dot?
continue eq # Yes
cmp B (char "0") # Or digit?
while ge
cmp B (char "9")
until gt # No
ld X (L I) # Get name
ld A (Scl) # Scale
shr A 4 # Normalize
drop
ld (Sep3) 0 # Thousand separator
ld (Sep0) (char ".") # Decimal separator
jmp symToNumXA_FE # Convert to number
end
end
push Y
push Z
ld Y A # Keep char in Y
call bufStringE_SZ # <S I/IV> Stack buffer
push A # <S /III> String length
slen (S) (S I)
ld A Y # Restore char
cmp B (char "a") # Lower case letter?
if ge
cmp B (char "z")
jle 10 # Yes
end
cmp B (char "A") # Upper case letter?
if ge
cmp B (char "Z")
jle 10 # Yes
end
cmp B (char "\\") # Backslash?
if eq # Yes
call (Get_A) # Use next char
jmp 10
end
memb (S I) (S) # Member of character set?
if eq # Yes
10 link
push ZERO # <L I> Result
ld C 4 # Build name
ld X S
link
do
call byteSymBCX_CX # Pack char
call (Get_A) # Get next
cmp B (char "a") # Lower case letter?
if ge
cmp B (char "z")
continue le # Yes
end
cmp B (char "A") # Upper case letter?
if ge
cmp B (char "Z")
continue le # Yes
end
cmp B (char "0") # Digit?
if ge
cmp B (char "9")
continue le # Yes
end
cmp B (char "\\") # Backslash?
if eq # Yes
call (Get_A) # Use next char
continue T
end
memb (S IV) (S III) # Member of character set?
until ne # No
ld X (L I) # Get name
call findSymX_E # Find or create symbol
drop
else
call getChar_A
call mkCharA_A # Return char
ld E A
call (Get_A) # Skip it
end
ld S Z # Drop buffer
pop Z
pop Y
ret
# (read ['sym1 ['sym2]]) -> any
(code 'doRead 2)
atom (E CDR) # Arg?
if nz # No
ld C 0 # No terminator
call readC_E # Read item
else
push X
ld X (E CDR) # Args
ld E (X) # Eval 'sym1'
eval
sym E # Need symbol
jz symErrEX
link
push E # <L I> Safe
link
ld E ((X CDR)) # Eval 'sym2'
eval
sym E # Need symbol
jz symErrEX
call firstCharE_A # Get first character
ld C A # as comment char
ld E (L I) # Get Set of characters
call tokenCE_E # Read token
null E # Any?
ldz E Nil # No
drop
pop X
end
cmp (Chr) 10 # Hit linefeed?
if eq # Yes
cmp (InFile) ((InFiles)) # Current InFile on stdin?
if eq # Yes
ld (Chr) 0 # Clear it
end
end
ret
# Check if input channel has data
(code 'inReadyC_F 0)
ld A C
shl A 3 # Vector index
cmp A (InFDs) # 'fd' >= 'InFDs'?
jge ret # No
add A (InFiles) # Get vector
ld A (A) # Slot?
null A # Any?
jz ret # No
cmp (A I) (A II) # Data in buffer ('ix' < 'cnt')?
ret # Yes: Return 'c'
(code 'fdSetCL_X 0)
ld X C # Get fd
and C 7 # Shift count
ld B 1 # Bit mask
shl B C # Shift it
shr X 3 # Offset
? (not *LittleEndian)
xor X 7 # Invert byte offset
=
add X L # Point to byte
ret
(code 'fdRdSetCZL 0) # X
cmp Z C # Maintain maximum
ldc Z C
call fdSetCL_X
or (X (- (+ V FD_SET))) B # FD_SET in RdSet
ret
(code 'fdWrSetCZL 0) # X
cmp Z C # Maintain maximum
ldc Z C
call fdSetCL_X
or (X (- (+ V FD_SET FD_SET))) B # FD_SET in WrSet
ret
(code 'rdSetCL_F 0) # X
call fdSetCL_X
test (X (- (+ V FD_SET))) B # FD_SET in RdSet
ret # Return 'nz'
(code 'wrSetCL_F 0) # X
call fdSetCL_X
test (X (- (+ V FD_SET FD_SET))) B # FD_SET in WrSet
ret # Return 'nz'
(code 'rdSetRdyCL_F 0) # X
ld A C
shl A 3 # Vector index
cmp A (InFDs) # 'fd' >= 'InFDs'?
jge rdSetCL_F # Yes
add A (InFiles) # Get vector
ld A (A) # Slot?
null A # Any?
jz rdSetCL_F # No
cmp (A I) (A II) # Data in buffer ('ix' < 'cnt')?
if z # No
push A
call rdSetCL_F
pop C
if nz # Yes
call slowNbC_FA # Try non-blocking read
jge retnz
setz
end
end
ret
(code 'waitFdCEX_A)
push Y
push Z
push (EnvTask) # <L IV> Save task list
link
push (At) # <L II> '@'
push ZERO # <L I> '*Run'
link
push C # <L -I> File descriptor
push E # <L -II> Milliseconds
push E # <L -III> Timeout
sub S (+ II FD_SET FD_SET) # <L -IV> Microseconds
# <L -V> Seconds
# <L - (V + FD_SET)> RdSet
# <L - (V + FD_SET - FD_SET)> WrSet
cmp S (StkLimit) # Stack check
jlt stkErrX
do
ld B 0 # Zero fd sets
mset (S) (+ FD_SET FD_SET)
push X # Save context
ld Z 0 # Maximum fd
ld C (L -I) # File descriptor
null C # Positive?
if ns # Yes
call inReadyC_F # Ready?
if c # Yes
ld (L -III) 0 # Timeout = 0
else
call fdRdSetCZL
end
end
ld Y (Run) # Get '*Run'
ld (L I) Y # Save it
ld (EnvTask) Y
do
atom Y # '*Run' elements?
while z # Yes
ld E (Y) # Next element
ld A (L IV) # memq in saved tasklist?
do
atom A # End of tasklist?
while z # No
cmp E (A) # Member?
jeq 10 # Yes: Skip
ld A (A CDR)
loop
ld C (E) # Get fd or timeout value
shr C 4 # Negative?
if c # Yes
ld A ((E CDR)) # Get CADR
shr A 4 # Normalize
cmp A (L -III) # Less than current timeout?
if lt # Yes
ld (L -III) A # Set new timeout
end
else
cmp C (L -I) # Different from argument-fd?
if ne # Yes
call inReadyC_F # Ready?
if c # Yes
ld (L -III) 0 # Timeout = 0
else
call fdRdSetCZL
end
end
end
10 ld Y (Y CDR)
loop
ld C (Hear) # RPC listener?
null C
if nz # Yes
cmp C (L -I) # Different from argument-fd?
if ne # Yes
ld A C # Still open?
shl A 3 # Vector index
add A (InFiles) # Get vector
ld A (A) # Slot?
null A # Any?
if nz # Yes
cmp (A I) (A II) # Data in buffer ('ix' < 'cnt')?
if nz # Yes
ld (L -III) 0 # Timeout = 0
else
call fdRdSetCZL
end
end
end
end
ld C (Spkr) # Speaker open?
null C
if nz # Yes
call fdRdSetCZL
ld Y (Child) # Iterate children
ld E (Children) # Count
do
sub E VI # More?
while ge # Yes
null (Y) # 'pid'?
if nz # Yes
ld C (Y I) # Child's 'hear' fd
call fdRdSetCZL
null (Y IV) # Child's buffer count?
if nz # Yes
ld C (Y II) # Child's 'tell' fd
call fdWrSetCZL
end
end
add Y VI # Increment by sizeof(child)
loop
end
pop X # Restore context
inc Z # Maximum fd + 1
ld C 0 # Timeval structure pointer
ld A (L -III) # Timeout value?
null A
if ns # Yes
div 1000 # Calculate seconds (C is zero)
ld (L -V) A
ld A C # and microseconds
mul 1000
ld (L -IV) A
lea C (L -V)
end
call msec_A # Get milliseconds
ld E A # into E
do
cc select(Z &(S FD_SET) S 0 C) # Wait for event or timeout
nul4 # OK?
while s # No
call errno_A
cmp A EINTR # Interrupted?
if ne # No
ld (Run) Nil # Clear '*Run'
jmp selectErrX
end
null (Signal) # Signal?
if nz # Yes
call sighandlerX
end
loop
call msec_A # Get milliseconds
sub A E # Time difference
ld (L -III) A # Save it
push X # Save context again
null (Spkr) # Speaker open?
if nz # Yes
inc (EnvProtect) # Protect child communication
ld Y (Child) # Iterate children
ld Z (Children) # Count
do
sub Z VI # More?
while ge # Yes
null (Y) # 'pid'?
if nz # Yes
push Z # Outer loop count
ld C (Y I) # Get child's 'hear' fd
call rdSetCL_F # Ready?
if nz # Yes
ld C (Y I) # Get 'hear' fd again
ld E 4 # Size of PID and count
ld X Buf # Buffer pointer
call rdBytesNbCEX_F # Read count?
if ge # Yes
if z
call clsChildY # Close child
jmp 20 # Continue
end
ld4 (Buf) # PID and size?
null A
if z # No
cmp (Y) (Talking) # Currently active?
if eq # Yes
ld (Talking) 0 # Clear
end
else
sub S PIPE_BUF # <S I> Pipe buffer
push Y # <S> Outer child index
ld C (Y I) # Get 'hear' fd again
ld2 (Buf 2) # Get size
ld E A
lea X (S I) # Buffer pointer
call rdBytesCEX_F # Read data?
if nz # Yes
ld Y (Child) # Iterate children
ld Z (Children) # Count
do
cmp Y (S) # Same as outer loop child?
if ne # No
null (Y) # 'pid'?
if nz # Yes
ld2 (Buf) # Get PID
null A # Any?
jz 15 # Yes
cmp A (Y) # Same as 'pid'?
if eq # Yes
15 ld2 (Buf 2) # Get size
ld C A
lea X (S I) # and data
call wrChildCXY # Write to child
end
end
end
add Y VI # Increment by sizeof(child)
sub Z VI # More?
until z # No
else
call clsChildY # Close child
pop Y
add S PIPE_BUF # Drop 'tell' buffer
jmp 20 # Continue
end
pop Y
add S PIPE_BUF # Drop 'tell' buffer
end
end
end
ld C (Y II) # Get child's 'tell' fd
call wrSetCL_F # Ready?
if nz # Yes
ld C (Y II) # Get 'tell' fd again
ld X (Y V) # Get buffer pointer
add X (Y III) # plus buffer offset
ld4 (X) # Get size
ld E A
add X 4 # Point to data (beyond size)
push E # Keep size
call wrBytesCEX_F # Write data?
pop E
if z # Yes
add E (Y III) # Add size to buffer offset
add E 4 # plus size of size
ld (Y III) E # New buffer offset
add E E # Twice the offset
cmp E (Y IV) # greater or equal to buffer count?
if ge # Yes
sub (Y IV) (Y III) # Decrement count by offset
if nz
ld X (Y V) # Get buffer pointer
add X (Y III) # Add buffer offset
movn ((Y V)) (X) (Y IV) # Copy data
ld A (Y V) # Get buffer pointer
ld E (Y IV) # and new count
call allocAE_A # Shrink buffer
ld (Y V) A # Store
end
ld (Y III) 0 # Clear buffer offset
end
else
call clsChildY # Close child
end
end
20 pop Z
end
add Y VI # Increment by sizeof(child)
loop
null (Talking) # Ready to sync?
if z # Yes
ld C (Spkr) # Get speaker
call rdSetCL_F # Anybody?
if nz # Yes
ld C (Spkr) # Get fd
ld E I # Size of slot
ld X Buf # Buffer pointer
call rdBytesNbCEX_F # Read slot?
if gt # Yes
ld Y (Child) # Get child
add Y (Buf) # in slot
ld A (Y) # 'pid'?
null A
if nz # Yes
ld (Talking) A # Set to talking
ld C 2 # Size of 'TBuf'
ld X TBuf # Buffer pointer
call wrChildCXY # Write to child
end
end
end
end
dec (EnvProtect)
end
ld C (Hear) # RPC listener?
null C
if nz # Yes
cmp C (L -I) # Different from argument-fd?
if ne # Yes
call rdSetRdyCL_F # Ready?
if nz # Yes
call rdHear_FE # Read expression?
if nc # Yes
cmp E TSym # Read 'T'?
if eq # Yes
set (Sync) 1 # Set sync flag
else
link
push E # Save expression
link
call evListE_E # Execute it
drop
end
else
ld A (Hear)
call closeAX # Close 'Hear'
ld A (Hear)
call closeInFileA
ld A (Hear)
call closeOutFileA
ld (Hear) 0 # Clear value
end
end
end
end
ld Y (L I) # Get '*Run'
do
atom Y # More elements?
while z # Yes
ld E (Y) # Next element
ld A (L IV) # memq in saved tasklist?
do
atom A # End of tasklist?
while z # No
cmp E (A) # Member?
jeq 30 # Yes: Skip
ld A (A CDR)
loop
ld C (E) # Get fd or timeout value
shr C 4 # Negative?
if c # Yes
ld C (E CDR) # Get CDR
ld A (C) # and CADR
shr A 4 # Normalize
sub A (L -III) # Subtract time difference
if nc # Not yet timed out
shl A 4 # Make short number
or A CNT
ld (C) A # Store in '*Run'
else # Timed out
ld A (E) # Timeout value
ld (C) A # Store in '*Run'
ld (At) (E) # Set to CAR
ld Z (C CDR) # Run body
prog Z
end
else
cmp C (L -I) # Different from argument-fd?
if ne # Yes
call rdSetRdyCL_F # Ready?
if nz # Yes
ld (At) (E) # Set to fd
ld Z (E CDR) # Run body
prog Z
end
end
end
30 ld Y (Y CDR)
loop
pop X # Restore context
null (Signal) # Signal?
if nz # Yes
call sighandlerX
end
ld A (L -II) # Milliseconds
or A A
if nsz # Greater zero
sub A (L -III) # Subtract time difference
if s # < 0
xor A A # Set to zero, 'z'
end
ld (L -II) A
end
while nz # Milliseconds non-zero
ld (L -III) A # Set timeout
ld C (L -I) # File descriptor
null C # Positive?
while ns # Yes
call rdSetRdyCL_F # Ready?
until nz # Yes
ld (At) (L II) # Restore '@'
ld A (L -II) # Return milliseconds
drop
pop (EnvTask)
pop Z
pop Y
ret
# (wait ['cnt] . prg) -> any
(code 'doWait 2)
push X
push Y
push Z
ld X E
ld Y (E CDR) # Y on args
ld E (Y) # Eval 'cnt'
eval
cmp E Nil # None?
if eq # Yes
push -1 # Wait infinite
else
call xCntEX_FE # Get 'cnt'
push E # <S> Milliseconds
end
ld Y (Y CDR) # Y on 'prg'
do
ld Z Y # Run 'prg'
prog Z
cmp E Nil # NIL?
while eq # Yes
ld C -1 # No file descriptor
ld E (S) # Milliseconds
call waitFdCEX_A # Wait for events
null A # Timeout?
if z # Yes
prog Y # Run 'prg'
break T
end
ld (S) A # New milliseconds
loop
add S I # Drop milliseconds
pop Z
pop Y
pop X
ret
# (sync) -> flg
(code 'doSync 2)
null (Mic) # No 'mic' channel?
jz retNil # Yes
null (Hear) # No 'hear' channel?
jz retNil # Yes
nul (Sync) # Already synchronized?
jnz retT # Yes
push X
ld X E
ld E Slot # Buffer pointer
ld C I # Count
do
cc write((Mic) E C) # Write 'Slot' to 'Mic'
null A # OK?
if ns # Yes
sub C A # Decrement count
break z # Done
add E A # Increment buffer pointer
else
call errno_A
cmp A EINTR # Interrupted?
jne wrSyncErrX # No
null (Signal) # Signal?
if nz # Yes
call sighandlerX
end
end
loop
set (Sync) 0 # Clear sync flag
do
ld C -1 # No file descriptor
ld E C # Wait infinite
call waitFdCEX_A # Wait for events
nul (Sync) # Synchronized?
until nz # Yes
ld E TSym # Return T
pop X
ret
# (hear 'cnt) -> cnt
(code 'doHear 2)
push X
ld X E
ld E ((E CDR)) # E on arg
eval # Eval it
cnt E # # Short number?
jz cntErrEX # No
ld C E # Get fd
shr C 4 # Normalize
jc badFdErrEX # Negative
ld A C # Keep 'fd' in C
shl A 3 # Vector index
cmp A (InFDs) # 'fd' >= 'InFDs'?
jge badFdErrEX # Yes
add A (InFiles) # Get vector
ld A (A) # Slot?
null A # Any?
jz badFdErrEX # No
ld A (Hear) # Current value?
null A
if nz # Yes
call closeAX # Close 'Hear'
ld A (Hear)
call closeInFileA
ld A (Hear)
call closeOutFileA
end
ld (Hear) C # Set new value
pop X
ret
# (tell ['cnt] 'sym ['any ..]) -> any
(code 'doTell 2)
ld A (Tell) # RPC?
or A (Children)
jz retNil # No
push X
push Y
push Z
ld X (E CDR) # Args
atom X # Any?
if nz # No
call unsync # Release sync
ld E Nil # Return NIL
else
push (TellBuf) # Save current 'tell' env
sub S PIPE_BUF # New 'tell' buffer
ld Z S # Buffer pointer
ld E (X) # Eval first argument
eval
num E # PID argument?
if z # No
push 0 # Send to all
else
shr E 4 # Normalize PID
push E # Save it
ld X (X CDR) # Next arg
ld E (X) # Eval
eval
end
call tellBegZ_Z # Start 'tell' message
do
ld Y E # Keep result
call prTellEZ # Print to 'tell'
ld X (X CDR) # More args?
atom X
while z # Yes
ld E (X) # Eval next
eval
loop
pop A # Get PID
call tellEndAZ # Close 'tell'
add S PIPE_BUF # Drop 'tell' buffer
pop (TellBuf)
ld E Y # Get result
end
pop Z
pop Y
pop X
ret
(code 'fdSetC_Y 0)
ld Y (C) # Get fd
and Y 7 # Shift count
ld B 1 # Bit mask
shl B Y # Shift it
ld Y (C) # Get fd again
shr Y 3 # Offset
add Y S # Pointer to byte minus I
ret
# (poll 'cnt) -> cnt | NIL
(code 'doPoll 2)
push X
ld X E
ld E ((E CDR)) # E on arg
eval # Eval it
ld A E # Keep
call xCntEX_FE # Get fd
xchg A E
null A # fd < 0?
js badFdErrEX # Yes
ld C A
shl C 3 # Vector index
cmp C (InFDs) # 'fd' >= 'InFDs'?
jge badFdErrEX # Yes
ld C A # Readable input file?
shl C 3 # Vector index
add C (InFiles) # Get vector
ld C (C) # Slot?
null C # Any?
ldz E Nil # No: Return NIL
if nz
push Y
sub S (+ II FD_SET) # <S FD_SET> Timeval, <S> RdSet
do
cmp (C I) (C II) # Data in buffer ('ix' < 'cnt')?
while z # No
ld B 0 # Zero fd set and timeval
mset (S) (+ II FD_SET)
call fdSetC_Y
or (Y I) B # FD_SET in RdSet
ld Y (C) # fd + 1
inc Y
do
cc select(Y S 0 0 &(S FD_SET)) # Check
nul4 # OK?
while s # No
call errno_A
cmp A EINTR # Interrupted?
if ne # No
ld (Run) Nil # Clear '*Run'
jmp selectErrX
end
loop
call fdSetC_Y
test (Y I) B # FD_SET in RdSet
ldz E Nil # No: Return NIL
while nz
call slowNbC_FA # Try non-blocking read
until ge
add S (+ II FD_SET)
pop Y
end
pop X
ret
# (key ['cnt]) -> sym
(code 'doKey 2)
push X
ld X E
ld E ((E CDR)) # E on arg
eval # Eval it
cmp E Nil # None?
if eq # Yes
ld E -1 # Wait infinite
else
call xCntEX_FE # Get milliseconds
end
call flushAll # Flush all output channels
call setRaw # Set terminal to raw mode
ld C 0 # Standard input
call waitFdCEX_A # Wait for events
null A # Timeout?
if nz # No
call stdinByte_A # Read first byte
cmp B (hex "FF") # Special "top" character?
if ne # No
cmp B 128 # Single byte?
if ge # No
test B (hex "20") # Two bytes?
if z # Yes
and B (hex "1F") # First byte 110xxxxx
shl A 6 # xxxxx000000
push A
else # Three bytes
and B (hex "F") # First byte 1110xxxx
shl A 6 # xxxx000000
push A
call stdinByte_A # Read second byte
and B (hex "3F") # 10xxxxxx
or A (S) # Combine
shl A 6 # xxxxxxxxxx000000
ld (S) A
end
call stdinByte_A # Read last byte
and B (hex "3F") # 10xxxxxx
or (S) A # Combine
pop A # Get result
end
else
ld A TOP
end
call mkCharA_A # Return char
ld E A
pop X
ret
end
ld E Nil
pop X
ret
# (peek) -> sym
(code 'doPeek 2)
ld A (Chr) # Look ahead char?
null A
if z # No
call (Get_A) # Get next
end
null A # EOF?
js retNil # Yes
call mkCharA_A # Return char
ld E A
ret
# (char) -> sym
# (char 'cnt) -> sym
# (char T) -> sym
# (char 'sym) -> cnt
(code 'doChar 2)
push X
ld X E
ld E (E CDR) # Any args?
atom E
if nz # No
ld A (Chr) # Look ahead char?
null A
if z # No
call (Get_A) # Get next
end
null A # EOF?
if ns # No
call getChar_A
call mkCharA_A # Make char
ld E A
call (Get_A) # Get next
else
ld E Nil
end
pop X
ret
end
ld E (E)
eval # Eval arg
cnt E # 'cnt'?
if nz # Yes
ld A E # Get 'cnt'
shr A 4 # Normalize
if nz
call mkCharA_A # Make char
ld E A
else
ld E Nil
end
pop X
ret
end
sym E # 'sym'?
jz atomErrEX # No
cmp E TSym # T?
if ne
call firstCharE_A
shl A 4 # Make short number
or A CNT
else
ld A TOP # Special "top" character
call mkCharA_A
end
ld E A
pop X
ret
# (skip ['any]) -> sym
(code 'doSkip 2)
ld E ((E CDR)) # Get arg
call evSymE_E # Evaluate to a symbol
call firstCharE_A # Get first character
ld C A # Use as comment char
call skipC_A # Skip white space and comments
null A # EOF?
js retNil # Yes
ld A (Chr) # Return 'Chr'
call mkCharA_A # Return char
ld E A
ret
# (eol) -> flg
(code 'doEol 2)
cmp (Chr) 10 # Linefeed?
jeq retT # Yes
null (Chr) # Chr <= 0?
jsz retT # Yes
ld E Nil # Return NIL
ret
# (eof ['flg]) -> flg
(code 'doEof 2)
ld E ((E CDR)) # Get arg
eval # Eval it
cmp E Nil # NIL?
if eq # Yes
ld A (Chr) # Look ahead char?
null A
if z # No
call (Get_A) # Get next
end
null A # EOF?
jns RetNil # No
else
ld (Chr) -1 # Set EOF
end
ld E TSym # Return T
ret
# (from 'any ..) -> sym
(code 'doFrom 2)
push X
push Z
ld X (E CDR) # X on args
push 0 # End-of-buffers marker
do
call evSymX_E # Next argument
call bufStringE_SZ # <S V> Stack buffer
push 0 # <S IV> Index
link
push E # <S II> Symbol
link
push Z # <S> Buffer chain
ld X (X CDR) # More arguments?
atom X
until nz # No
ld A (Chr) # Look ahead char?
null A
if z # No
call (Get_A) # Get next
end
do
null A # EOF?
while ns # No
ld Z S # Buffer chain
do
do
lea C (Z V) # Stack buffer
add C (Z IV) # Index
cmp B (C) # Bytes match?
if eq # Yes
inc (Z IV) # Increment index
nul (C 1) # End of string?
break nz # No
call (Get_A) # Skip next input byte
ld E (Z II) # Return matched symbol
jmp 90
end
null (Z IV) # Still at beginning of string?
break z # Yes
lea C (Z (+ V 1)) # Offset pointer to second byte
do
dec (Z IV) # Decrement index
while nz
cmpn (Z V) (C) (Z IV) # Compare stack buffer
while nz
inc C # Increment offset
loop
loop
ld Z (Z) # Next in chain
null (Z) # Any?
until z # No
call (Get_A) # Get next input byte
loop
ld E Nil # Return NIL
90 pop Z # Clean up buffers
do
drop
ld S Z
pop Z
null Z # End?
until z # Yes
pop Z
pop X
ret
# (till 'any ['flg]) -> lst|sym
(code 'doTill 2)
push X
push Z
ld X (E CDR) # Args
call evSymX_E # Evaluate to a symbol
call bufStringE_SZ # <S I/IV> Stack buffer
push A # <S /III> String length
slen (S) (S I)
ld A (Chr) # Look ahead char?
null A
if z # No
call (Get_A) # Get next
end
null A # EOF?
if ns # No
memb (S I) (S) # Matched first char?
if ne # No
ld E ((X CDR)) # Eval 'flg'
eval
cmp E Nil # NIL?
if eq # Yes
call getChar_A # Get first character
call mkCharA_A # Make char
call consA_X # Build first cell
ld (X) A
ld (X CDR) Nil
link
push X # <L I> Result list
link
do
call (Get_A) # Get next
null A # EOF?
while nsz # No
memb (S IV) (S III) # Matched char?
while ne # No
call getChar_A # Get next character
call mkCharA_A
call consA_C # Build next cell
ld (C) A
ld (C CDR) Nil
ld (X CDR) C # Append to sublist
ld X C
loop
ld E (L I) # Get result list
else
link
push ZERO # <L I> Result
ld X S
link
ld C 4 # Build name
do
call getChar_A # Get next character
call charSymACX_CX # Insert
call (Get_A) # Get next
null A # EOF?
while nsz # No
memb (S IV) (S III) # Matched char?
until eq # Yes
ld X (L I) # Get result name
call consSymX_E
end
drop
ld S Z # Drop buffer
pop Z
pop X
ret
end
end
ld E Nil # Return NIL
ld S Z # Drop buffer
pop Z
pop X
ret
(code 'eolA_F 0)
null A # EOF?
js retz # Yes
cmp A 10 # Linefeed?
if ne # No
cmp A 13 # Return?
jne Ret # No
call (Get_A) # Get next
cmp A 10 # Linefeed?
jnz retz
end
ld (Chr) 0 # Clear look ahead
ret # 'z'
# (line 'flg ['cnt ..]) -> lst|sym
(code 'doLine 2)
ld A (Chr) # Look ahead char?
null A
if z # No
call (Get_A) # Get next
end
call eolA_F # End of line?
jeq retNil # Yes
push X
push Y
push Z
ld Y (E CDR) # Y on args
ld E (Y) # Eval 'flg'
eval
cmp E Nil # 'flg' was non-NIL?
if ne # Yes: Pack
ld Y (Y CDR) # More args?
atom Y
if nz # No
link
push ZERO # <L I> Result
ld X S
link
ld C 4 # Build name
do
call getChar_A # Get next character
call charSymACX_CX # Insert
call (Get_A) # Get next
call eolA_F # End of line?
until eq # Yes
ld X (L I) # Get result name
call consSymX_E
else
call cons_Z # First cell of top list
ld (Z) ZERO
ld (Z CDR) Nil
link
push Z # <L I> Result
link
do
ld C 4 # Build name
ld X Z
call getChar_A # Get next character
call charSymACX_CX # Insert first char
push C
ld E (Y)
eval # Eval next arg
pop C
shr E 4 # Normalize
do
dec E # Decrement count
while nz
call (Get_A) # Get next
call eolA_F # End of line?
if eq # Yes
ld X (Z) # Get last sub-result
call consSymX_E
ld (Z) E
jmp 20
end
call getChar_A # Get next character
call charSymACX_CX # Insert
loop
ld X (Z) # Get last sub-result
call consSymX_E
ld (Z) E
ld Y (Y CDR) # More args?
atom Y
jnz 10 # No
call (Get_A) # Get next
call eolA_F # End of line?
jeq 20 # Yes
call cons_A # New cell to top list
ld (A) ZERO
ld (A CDR) Nil
ld (Z CDR) A
ld Z A
loop
end
else
call getChar_A # Get first character
call mkCharA_A # Make char
call consA_Z # Build first cell
ld (Z) A
ld (Z CDR) Nil
link
push Z # <L I> Result
link
ld Y (Y CDR) # More args?
atom Y
if z # Yes
ld X Z # Current sublist
call cons_Z # First cell of top list
ld (Z) X
ld (Z CDR) Nil
ld (L I) Z # New result
do
ld E (Y)
eval # Eval next arg
shr E 4 # Normalize
do
dec E # Decrement count
while nz
call (Get_A) # Get next
call eolA_F # End of line?
jeq 20 # Yes
call getChar_A # Get next character
call mkCharA_A
call consA_C # Build next cell
ld (C) A
ld (C CDR) Nil
ld (X CDR) C # Append to sublist
ld X C
loop
ld Y (Y CDR) # More args?
atom Y
while z # Yes
call (Get_A) # Get next
call eolA_F # End of line?
jeq 20 # Yes
call getChar_A # Get next character
call mkCharA_A
call consA_X # Build new sublist
ld (X) A
ld (X CDR) Nil
call consX_A # Append to top list
ld (A) X
ld (A CDR) Nil
ld (Z CDR) A
ld Z A
loop
end
10 do
call (Get_A) # Get next
call eolA_F # End of line?
while ne # No
call getChar_A # Get next character
call mkCharA_A
call consA_C # Build next cell
ld (C) A
ld (C CDR) Nil
ld (Z CDR) C # Append
ld Z C
loop
20 ld E (L I) # Get result
end
drop
pop Z
pop Y
pop X
ret
# (lines 'any ..) -> cnt
(code 'doLines 2)
push X
push Y
push Z
ld X (E CDR) # Args
ld Y 0 # Result
do
atom X # More args?
while z # Yes
call evSymX_E # Evaluate next file name
call pathStringE_SZ # Write to stack buffer
cc fopen(S _r_) # Open file
ld S Z # Drop buffer
null A # OK?
if nz # Yes
ld E A # File pointer
null Y # First hit?
if z # Yes
ld Y ZERO # Init short number
end
do
cc getc_unlocked(E) # Next char
nul4 # EOF?
while ns # No
cmp A 10 # Linefeed?
if eq # Yes
add Y (hex "10") # Increment count
end
loop
cc fclose(E) # Close file pointer
end
ld X (X CDR)
loop
null Y # Result?
ld E Y # Yes
ldz E Nil # No
pop Z
pop Y
pop X
ret
(code 'parseBCE_E)
push (EnvParseX) # Save old parser status
push (EnvParseC)
push (EnvParseEOF)
push (Get_A) # Save 'get' status
push (Chr)
ld E (E TAIL)
call nameE_E # Get name
link
push E # Save it
link
ld (EnvParseX) E # Set new parser status
ld (EnvParseC) 0
ld E 0
null C # Token?
if z # No
ld E (hex "5D0A00") # linefeed, ']', EOF
end
ld (EnvParseEOF) E
ld (Get_A) getParse_A # Set 'get' status
ld (Chr) 0
or B B # Skip?
if nz # Yes
call getParse_A # Skip first char
end
null C # Token?
if z # No
call rdList_E # Read a list
else
push X
push C # <S III> Set of characters
ld E C # in E
ld C 0 # No comment char
call tokenCE_E # Read token
null E # Any?
ldz E Nil
if nz # Yes
call consE_X # Build first result cell
ld (X) E
ld (X CDR) Nil
link
push X # <L I> Result
link
do
ld C 0 # No comment char
ld E (S III) # Get set of characters
push X
call tokenCE_E # Next token?
pop X
null E
while nz # Yes
call consE_A # Build next result cell
ld (A) E
ld (A CDR) Nil
ld (X CDR) A
ld X A
loop
ld E (L I) # Get result
drop
end
add S I # Drop set
pop X
end
drop
pop (Chr) # Retrieve 'get' status
pop (Get_A)
pop (EnvParseEOF) # Restore old parser status
pop (EnvParseC)
pop (EnvParseX)
ret
# (any 'sym) -> any
(code 'doAny 2)
push X
ld X E
ld E ((E CDR)) # E on arg
eval # Eval it
num E # Need symbol
jnz symErrEX
sym E
jz symErrEX
cmp E Nil # NIL?
if ne # No
push (EnvParseX) # Save old parser status
push (EnvParseC)
push (EnvParseEOF)
push (Get_A) # Save 'get' status
push (Chr)
ld E (E TAIL)
call nameE_E # Get name
link
push E # Save it
link
ld (EnvParseX) E # Set new parser status
ld (EnvParseC) 0
ld (EnvParseEOF) (hex "2000") # Blank, EOF
ld (Get_A) getParse_A # Set 'get' status
ld (Chr) 0
call getParse_A # Skip first char
ld A 1 # Top level
call readA_E # Read expression
drop
pop (Chr) # Retrieve 'get' status
pop (Get_A)
pop (EnvParseEOF) # Restore old parser status
pop (EnvParseC)
pop (EnvParseX)
end
pop X
ret
# (sym 'any) -> sym
(code 'doSym 2)
ld E ((E CDR)) # Eval arg
eval
link
push E # Save
link
call begString # Start string
call printE # Print to string
call endString_E # Retrieve result
drop
ret
# (str 'sym ['sym1]) -> lst
# (str 'lst) -> sym
(code 'doStr 2)
push X
push Y
ld X E
ld Y (E CDR) # Y on args
ld E (Y) # Eval first
eval
cmp E Nil # NIL?
if ne # No
num E # Number?
jnz argErrEX # Yes
sym E # Symbol?
if nz # Yes
link
push E # <L II> 'sym'
link
ld X (Y CDR) # Second arg?
atom X
if nz # No
ld C 0 # No token
else
call evSymX_E # Eval 'sym1'
tuck E # Save
link
ld C E # Get token
ld E (L II) # and 'sym'
end
ld B 0 # Don't skip
call parseBCE_E # Parse
drop
else
link
push E # Save 'lst'
link
call begString # Start string
ld X E # 'lst'
do
ld E (X) # Get CAR
call printE # Print to string
ld X (X CDR) # More items?
atom X
while z # Yes
call space
loop
call endString_E # Retrieve result
drop
end
end
pop Y
pop X
ret
# Read-Eval-Print loop
(code 'loadBEX_E)
ld C A # Save prompt in C
sym E # Symbolic argument?
if nz # Yes
ld A (E TAIL)
call firstByteA_B # starting with "-"?
cmp B (char "-")
if eq # Yes
ld C 0 # No token
call parseBCE_E # Parse executable list
link
push E # Save expression
link
call evListE_E # Execute it
drop
ret
end
end
push Y
link
push (EnvIntern) # <L III> Keep current namespace
push ZERO # <L II>
push ZERO # <L I>
link
push C # <L -I> Prompt
sub S IV # InFrame
ld Y S
call rdOpenEXY
call pushInFilesY
ld E Nil # Close transient scope
call doHide
do
cmp ((InFiles)) (InFile) # Reading from file?
if ne # Yes
ld C 0 # No terminator
call readC_E # Read expression
else
null (L -I) # Prompt?
if nz # Yes
null (Chr)
if z
ld E (Prompt) # Output prompt prefix
call runE_E # Execute
call prinE_E
ld A (L -I) # Output prompt
call (PutB)
call space
call flushAll
end
end
ld C 10 # Linefeed terminator
cc isatty(0) # STDIN
nul4 # on a tty?
ldz C 0 # No
call readC_E # Read expression
cmp (Chr) 10 # Hit linefeed?
if eq # Yes
ld (Chr) 0 # Clear it
end
end
cmp E Nil
while ne
ld (L I) E # Save read expression
cmp ((InFiles)) (InFile) # Reading from file?
if nz # Yes
10 eval # Evaluate
else
null (Chr) # Line?
jnz 10 # Yes
ld A (L -I)
or B B # Prompt?
jz 10 # No
call flushAll
ld (L II) (At) # Save '@'
eval # Evaluate
ld (At) E # Save result
ld (At3) (At2)
ld (At2) (L II) # Retrieve previous '@'
ld C Arrow
call outStringC
call flushAll
call printE_E
call newline
end
ld (L I) E # Save result
loop
null ((InFile) VI) # File?
if nz # Yes
ld (EnvIntern) (L III) # Restore namespace
end
call popInFiles
ld E Nil # Close transient scope
call doHide
ld E (L I)
drop
pop Y
ret
# (load 'any ..) -> any
(code 'doLoad 2)
push X
push Y
ld X E
ld Y (E CDR) # Y on args
do
ld E (Y) # Eval arg
eval
cmp E TSym # Load remaining command line args?
if ne # No
ld B (char ">") # Prompt
call loadBEX_E
else
call loadAllX_E
end
ld Y (Y CDR) # More args?
atom Y
until nz # No
pop Y
pop X
ret
# (in 'any . prg) -> any
(code 'doIn 2)
push X
push Y
ld X E # Expression in X
ld E (E CDR)
ld E (E) # Eval 'any'
eval
sub S IV # InFrame
ld Y S
call rdOpenEXY
call pushInFilesY
ld X ((X CDR) CDR) # Get 'prg'
prog X
call popInFiles
add S IV # Drop InFrame
pop Y
pop X
ret
# (out 'any . prg) -> any
(code 'doOut 2)
push X
push Y
ld X E # Expression in X
ld E (E CDR)
ld E (E) # Eval 'any'
eval
sub S IV # OutFrame
ld Y S
call wrOpenEXY
call pushOutFilesY
ld X ((X CDR) CDR) # Get 'prg'
prog X
call popOutFiles
add S IV # Drop InFrame
pop Y
pop X
ret
# (err 'sym . prg) -> any
(code 'doErr 2)
push X
push Y
ld X E # Expression in X
ld E (E CDR)
ld E (E) # Eval 'any'
eval
sub S II # ErrFrame
ld Y S
call erOpenEXY
call pushErrFilesY
ld X ((X CDR) CDR) # Get 'prg'
prog X
call popErrFiles
add S II # Drop ErrFrame
pop Y
pop X
ret
# (ctl 'sym . prg) -> any
(code 'doCtl 2)
push X
push Y
ld X E # Expression in X
ld E (E CDR)
ld E (E) # Eval 'any'
eval
sub S II # CtlFrame
ld Y S
call ctOpenEXY
call pushCtlFilesY
ld X ((X CDR) CDR) # Get 'prg'
prog X
call popCtlFiles
add S II # Drop CtlFrame
pop Y
pop X
ret
# (pipe exe) -> cnt
# (pipe exe . prg) -> any
(code 'doPipe 2)
push X
push Y
ld X E # Expression in X
sub S IV # In/OutFrame
ld Y S
push A # Create 'pipe' structure
cc pipe(S) # Open pipe
nul4 # OK?
jnz pipeErrX
ld4 (S) # Get pfd[0]
call closeOnExecAX
ld4 (S 4) # Get pfd[1]
call closeOnExecAX
call forkLispX_FE # Fork child process
if c # In child
atom ((X CDR) CDR) # 'prg'?
if z # Yes
cc setpgid(0 0) # Set process group
end
ld4 (S) # Close read pipe
call closeAX
ld4 (S 4) # Get write pipe
cmp A 1 # STDOUT_FILENO?
if ne # No
cc dup2(A 1) # Dup to STDOUT_FILENO
ld4 (S 4) # Close write pipe
call closeAX
end
ld E Nil # Standard output
call wrOpenEXY
call pushOutFilesY
ld ((OutFile) II) 0 # Clear 'tty'
ld (Run) Nil # Switch off all tasks
ld E ((X CDR)) # Get 'exe'
eval # Evaluate it
ld E 0 # Exit OK
jmp byeE
end
ld (Y II) E # Set 'pid'
ld4 (S 4) # Close write pipe
call closeAX
ld4 (S) # Get read pipe
call initInFileA_A
ld E (A) # Get file descriptor
ld X ((X CDR) CDR) # Get 'prg'
atom X # Any?
if nz # No
shl E 4 # In parent
or E CNT # Return PID
else
ld (Y I) E # Save 'fd'
cc setpgid((Y II) 0) # Set process group
call pushInFilesY
prog X
call popInFiles
end
add S (+ 8 IV) # Drop 'pipe' structure and In/OutFrame
pop Y
pop X
ret
# (open 'any ['flg]) -> cnt | NIL
(code 'doOpen 2)
push X
push Z
ld X E
ld E ((E CDR)) # Get arg
call evSymE_E # Evaluate to a symbol
call pathStringE_SZ # Write to stack buffer
ld E (((X CDR) CDR)) # Get flg
eval
cmp E Nil # Read-only?
ldnz E O_RDONLY # Yes
ldz E (| O_CREAT O_RDWR) # No
do
cc open(S E (oct "0666")) # Try to open
nul4 # OK?
while s # No
call errno_A
cmp A EINTR # Interrupted?
if ne # No
ld E Nil # Return NIL
jmp 90
end
null (Signal) # Signal?
if nz # Yes
call sighandlerX
end
loop
ld X A # Keep 'fd'
call closeOnExecAX
ld C X # 'fd'
cc strdup(S) # Duplicate name
call initInFileCA_A # Init input file structure
ld A X # 'fd' again
call initOutFileA_A # Init output file structure
ld E X # Return 'fd'
shl E 4 # Make short number
or E CNT
90 ld S Z # Drop buffer
pop Z
pop X
ret
# (close 'cnt) -> cnt | NIL
(code 'doClose 2)
push X
ld X E
ld E ((E CDR)) # Eval 'cnt'
eval
ld C E # Keep in E
call xCntCX_FC # Get fd
do
cc close(C) # Close it
nul4 # OK?
while nz # No
call errno_A
cmp A EINTR # Interrupted?
if ne # No
ld E Nil # Return NIL
pop X
ret
end
null (Signal) # Signal?
if nz # Yes
call sighandlerX
end
loop
ld A C # Close InFile
call closeInFileA
ld A C # Close OutFile
call closeOutFileA
pop X
ret
# (echo ['cnt ['cnt]] | ['sym ..]) -> sym
(code 'doEcho 2)
push X
push Y
ld X E
ld Y (E CDR) # Y on args
ld E (Y) # Eval first
eval
ld Y (Y CDR) # Next arg
ld A (Chr) # Look ahead char?
null A
if z # No
call (Get_A) # Get next
end
cmp E Nil # Empty arg?
if eq # Yes
atom Y # No further args?
if nz # Yes
do
null A # EOF?
while ns # No
call (PutB) # Output byte
call (Get_A) # Get next
loop
ld E TSym # Return T
pop Y
pop X
ret
end
end
num E # Number?
if nz # Yes
call xCntEX_FE # Get 'cnt'
atom Y # Second 'cnt' arg?
if z # Yes
ld Y (Y) # Get second 'cnt'
xchg Y E # First 'cnt' in Y
call evCntEX_FE # Evaluate second
ld A (Chr) # Get Chr again
do
dec Y # Decrement first 'cnt'
while ns
null A # EOF?
if s # Yes
ld E Nil # Return NIL
pop Y
pop X
ret
end
call (Get_A) # Get next
loop
end
null E # 'cnt'?
if nsz # Yes
do
null A # EOF?
if s # Yes
ld E Nil # Return NIL
pop Y
pop X
ret
end
call (PutB) # Output byte
dec E # Decrement 'cnt'
while nz
call (Get_A) # Get next
loop
end
ld (Chr) 0 # Clear look ahead
ld E TSym # Return T
pop Y
pop X
ret
end
sym E # Need symbol
jz argErrEX
push Z
push 0 # End-of-buffers marker
do
call bufStringE_SZ # <S V> Stack buffer
push 0 # <S IV> Index
link
push E # <S II> Symbol
link
push Z # <S> Buffer chain
atom Y # More arguments?
while z # Yes
call evSymY_E # Next argument
ld Y (Y CDR)
loop
ld X 0 # Clear current max
ld A (Chr) # Look ahead char
do
null A # EOF?
while ns # No
ld Y X # Output max
null Y # Any?
if nz # Yes
ld E (Y IV) # Set output index
end
ld Z S # Buffer chain
do
do
lea C (Z V) # Stack buffer
add C (Z IV) # Index
cmp B (C) # Bytes match?
if eq # Yes
inc (Z IV) # Increment index
nul (C 1) # End of string?
if nz # No
null X # Current max?
if z # No
ld X Z
else
cmp (X IV) (Z IV) # Smaller than index?
ldc X Z # Yes
end
break T
end
null Y # Output max?
if nz # Yes
lea C (Y V) # Buffer of output max
sub E (Z IV) # Diff to current index
do # Done?
while ge # No
ld B (C)
call (PutB) # Output bytes
inc C
sub E 1
loop
end
ld (Chr) 0 # Clear look ahead
ld E (Z II) # Return matched symbol
jmp 90
end
null (Z IV) # Still at beginning of string?
break z # Yes
lea C (Z (+ V 1)) # Offset pointer to second byte
do
dec (Z IV) # Decrement index
while nz
cmpn (Z V) (C) (Z IV) # Compare stack buffer
while nz
inc C # Increment offset
loop
cmp X Z # On current max?
if eq # Yes
ld X 0 # Clear current max
ld C S # Buffer chain
do
null (C IV) # Index?
if nz # Yes
null X # Current max?
if z # No
ld X C
else
cmp (X IV) (C IV) # Smaller than index?
ldc X C # Yes
end
end
ld C (C) # Next in chain
null (C) # Any?
until z # No
end
loop
ld Z (Z) # Next in chain
null (Z) # Any?
until z # No
null X # Current max?
if z # No
null Y # Output max?
if nz
push A # Save current byte
push E # and output index
lea C (Y V) # Buffer of output max
do
ld B (C)
call (PutB) # Output bytes
inc C
dec E # Done?
until z # Yes
pop E
pop A
end
call (PutB) # Output current byte
else
null Y # Output max?
if nz
lea C (Y V) # Buffer of output max
sub E (X IV) # Diff to current max index
do # Done?
while ge # No
ld B (C)
call (PutB) # Output bytes
inc C
sub E 1
loop
end
end
call (Get_A) # Get next input byte
loop
ld E Nil # Return NIL
90 pop Z # Clean up buffers
do
drop
ld S Z
pop Z
null Z # End?
until z # Yes
pop Z
pop Y
pop X
ret
(code 'putStdoutB 0)
push Y
ld Y (OutFile) # OutFile?
null Y
if nz # Yes
push E
push X
ld E (Y I) # Get 'ix'
lea X (Y III) # Buffer pointer
cmp E BUFSIZ # Reached end of buffer?
if eq # Yes
push A
push C
ld (Y I) 0 # Clear 'ix'
ld C (Y) # Get 'fd'
call wrBytesCEX_F # Write buffer
ld E 0 # Get 'ix'
lea X (Y III) # Buffer pointer
pop C
pop A
end
add X E # Buffer index
ld (X) B # Store byte
inc E # Increment ix
ld (Y I) E # Store 'ix'
cmp B 10 # Linefeed?
if eq # Yes
null (Y II) # and 'tty'?
if nz # Yes
push C
ld (Y I) 0 # Clear 'ix'
ld C (Y) # Get 'fd'
lea X (Y III) # Buffer pointer
call wrBytesCEX_F # Write buffer
pop C
end
end
pop X
pop E
end
pop Y
ret
(code 'newline)
ld B 10
jmp (PutB)
(code 'space)
ld B 32
jmp (PutB)
# Output decimal number
(code 'outNumE)
shr E 4 # Normalize
if c # Sign
ld B (char "-") # Output sign
call (PutB)
end
ld A E
(code 'outWordA)
cmp A 9 # Single digit?
if gt # No
ld C 0 # Divide by 10
div 10
push C # Save remainder
call outWordA # Recurse
pop A
end
add B (char "0") # Make ASCII digit
jmp (PutB)
(code 'prExtNmX)
call fileObjX_AC # Get file and object ID
null A # File?
if nz # Yes
call outAoA # Output file number
end
ld A C # Get object ID
# Output octal number
(code 'outOctA 0)
cmp A 7 # Single digit?
if gt # No
push A # Save
shr A 3 # Divide by 8
call outOctA # Recurse
pop A
and B 7 # Get remainder
end
add B (char "0") # Make ASCII digit
jmp (PutB)
# Output A-O encoding
(code 'outAoA 0)
cmp A 15 # Single digit?
if gt # No
push A # Save
shr A 4 # Divide by 16
call outAoA # Recurse
pop A
and B 15 # Get remainder
end
add B (char "@") # Make ASCII letter
jmp (PutB)
(code 'outStringS) # C
lea C (S I) # Buffer above return address
(code 'outStringC)
do
ld B (C) # Next char
inc C
or B B # Null?
while ne # No
call (PutB)
loop
ret
(code 'outNameE)
push X
ld X (E TAIL)
call nameX_X # Get name
call prNameX # Print it
pop X
ret
(code 'prNameX)
ld C 0
do
call symByteCX_FACX # Next byte
while nz
call (PutB) # Output byte
loop
ret
# Print one expression
(code 'printE_E)
link
push E # <L I> Save expression
link
call printE # Print it
ld E (L I) # Restore
drop
ret
(code 'printE 0)
cmp S (StkLimit) # Stack check
jlt stkErr
null (Signal) # Signal?
if nz # Yes
call sighandler0
end
cnt E # Short number?
jnz outNumE # Yes
big E # Bignum?
if nz # Yes
ld A -1 # Scale
jmp fmtNum0AE_E # Print it
end
push X
sym E # Symbol?
if nz # Yes
ld X (E TAIL)
call nameX_X # Get name
cmp X ZERO # Any?
if eq # No
ld B (char "$") # $xxxxxx
call (PutB)
shr E 4 # Normalize symbol pointer
ld A E
call outOctA
pop X
ret
end
sym (E TAIL) # External symbol?
if nz # Yes
ld B (char "{") # {AB123}
call (PutB)
call prExtNmX # Print it
ld B (char "}")
call (PutB)
pop X
ret
end
push Y
ld Y ((EnvIntern))
call isInternEXY_F # Internal symbol?
if eq # Yes
cmp X (hex "2E2") # Dot?
if eq # Yes
ld B (char "\\") # Print backslash
call (PutB)
ld B (char ".") # Print dot
call (PutB)
else
ld C 0
call symByteCX_FACX # Get first byte
do
cmp B (char "\\") # Backslash?
jeq 10 # Yes
memb Delim "(DelimEnd-Delim)" # Delimiter?
if eq # Yes
10 push A # Save char
ld B (char "\\") # Print backslash
call (PutB)
pop A
end
call (PutB) # Put byte
call symByteCX_FACX # Next byte
until z # Done
end
else # Else transient symbol
ld Y 0 # 'tsm' flag in Y
atom (Tsm) # Transient symbol markup?
if z # Yes
cmp (PutB) putStdoutB # to stdout?
if eq # No
ld Y ((OutFile) II) # and 'tty'? -> Y
end
end
null Y # Transient symbol markup?
if z # No
ld B (char "\"")
call (PutB)
else
ld E ((Tsm)) # Get CAR
call outNameE # Write transient symbol markup
end
ld C 0
call symByteCX_FACX # Get first byte
do
cmp B (char "\\") # Backslash?
jeq 20
cmp B (char "\^") # Caret?
jeq 20
null Y # Transient symbol markup?
jnz 30 # Yes
cmp B (char "\"") # Double quote?
if eq # Yes
20 push A # Save char
ld B (char "\\") # Escape with backslash
call (PutB)
pop A
else
30 cmp B 127 # DEL?
if eq # Yes
ld B (char "\^") # Print ^?
call (PutB)
ld B (char "?")
else
cmp B 32 # White space?
if lt # Yes
push A # Save char
ld B (char "\^") # Escape with caret
call (PutB)
pop A
or A 64 # Make printable
end
end
end
call (PutB) # Put byte
call symByteCX_FACX # Next byte
until z # Done
null Y # Transient symbol markup?
if z # No
ld B (char "\"") # Final double quote
call (PutB)
else
ld E ((Tsm) CDR) # Get CDR
call outNameE # Write transient symbol markup
end
end
pop Y
pop X
ret
end
# Print list
cmp (E) Quote # CAR 'quote'?
if eq # Yes
cmp E (E CDR) # Circular?
if ne # No
ld B (char "'") # Print single quote
call (PutB)
ld E (E CDR) # And CDR
call printE
pop X
ret
end
end
push Y
ld B (char "(") # Open paren
call (PutB)
ld X E # Keep list in X
call circE_YF # Circular?
if nz # No
do
ld E (X) # Print CAR
call printE
ld X (X CDR) # NIL-terminated?
cmp X Nil
while ne # No
atom X # Atomic tail?
if nz # Yes
call space # Print " . "
ld B (char ".")
call (PutB)
call space
ld E X # and the atom
call printE
break T
end
call space # Print space
loop
else
cmp X Y # Fully circular?
if eq # Yes
do
ld E (X) # Print CAR
call printE
call space # and space
ld X (X CDR) # Done?
cmp X Y
until eq # Yes
ld B (char ".") # Print "."
call (PutB)
else
do # Non-circular part
ld E (X) # Print CAR
call printE
call space # and space
ld X (X CDR) # Done?
cmp X Y
until eq # Yes
ld B (char ".") # Print ". ("
call (PutB)
call space
ld B (char "(")
call (PutB)
do # Circular part
ld E (X) # Print CAR
call printE
call space # and space
ld X (X CDR) # Done?
cmp X Y
until eq # Yes
ld B (char ".") # Print ".)"
call (PutB)
ld B (char ")")
call (PutB)
end
end
ld B (char ")") # Closing paren
call (PutB)
pop Y
pop X
ret
# Print string representation
(code 'prinE_E 0)
link
push E # <L I> Save expression
link
call prinE # Print it
ld E (L I) # Restore
drop
ret
(code 'prinE 0)
cmp S (StkLimit) # Stack check
jlt stkErr
null (Signal) # Signal?
if nz # Yes
call sighandler0
end
cmp E Nil # NIL?
if ne # No
cnt E # Short number?
jnz outNumE # Yes
big E # Bignum?
if nz # Yes
ld A -1 # Scale
jmp fmtNum0AE_E # Print it
end
push X
sym E # Symbol?
if nz # Yes
ld X (E TAIL)
call nameX_X # Get name
cmp X ZERO # Any?
if ne # Yes
sym (E TAIL) # External symbol?
if z # No
call prNameX
else
ld B (char "{") # {AB123}
call (PutB)
call prExtNmX # Print it
ld B (char "}")
call (PutB)
end
end
else
ld X E # Get list in X
do
ld E (X) # Prin CAR
call prinE
ld X (X CDR) # Next
cmp X Nil # NIL-terminated?
while ne # No
atom X # Done?
if nz # Yes
ld E X # Print atomic rest
call prinE
break T
end
loop
end
pop X
end
ret
# (prin 'any ..) -> any
(code 'doPrin 2)
push X
ld X (E CDR) # Get arguments
do
ld E (X)
eval # Eval next arg
call prinE_E # Print string representation
ld X (X CDR) # More arguments?
atom X
until nz # No
pop X
ret
# (prinl 'any ..) -> any
(code 'doPrinl 2)
call doPrin # Print arguments
jmp newline
(code 'doSpace 2)
push X
ld X E
ld E ((E CDR)) # Eval 'cnt'
eval
cmp E Nil # NIL?
if eq # Yes
call space # Output single space
ld E ONE # Return 1
else
ld C E # Keep in E
call xCntCX_FC # Get cnt
do
dec C # 'cnt' times
while ns
call space # Output spaces
loop
end
pop X
ret
# (print 'any ..) -> any
(code 'doPrint 2)
push X
ld X (E CDR) # Get arguments
do
ld E (X)
eval # Eval next arg
call printE_E # Print it
ld X (X CDR) # More arguments?
atom X
while z # Yes
call space # Print space
loop
pop X
ret
# (printsp 'any ..) -> any
(code 'doPrintsp 2)
push X
ld X (E CDR) # Get arguments
do
ld E (X)
eval # Eval next arg
call printE_E # Print it
call space # Print space
ld X (X CDR) # More arguments?
atom X
until nz # No
pop X
ret
# (println 'any ..) -> any
(code 'doPrintln 2)
call doPrint # Print arguments
jmp newline
# (flush) -> flg
(code 'doFlush 2)
ld A (OutFile) # Flush OutFile
call flushA_F # OK?
ld E TSym # Yes
ldnz E Nil
ret
# (rewind) -> flg
(code 'doRewind 2)
ld E Nil # Preload return value
ld C (OutFile) # OutFile?
null C
if nz # Yes
ld (C I) 0 # Clear 'ix'
cc lseek((C) 0 SEEK_SET) # Seek to beginning of file
null A # OK?
if z # Yes
cc ftruncate((C) 0) # Truncate file
nul4 # OK?
ldz E TSym # Return T
end
end
ret
# (ext 'cnt . prg) -> any
(code 'doExt 2)
push X
push Y
ld X E
ld Y (E CDR) # Y on args
call evCntXY_FE # Eval 'cnt'
push (ExtN) # Save external symbol offset
ld (ExtN) E # Set new
ld X (Y CDR) # Run 'prg'
prog X
pop (ExtN) # Restore external symbol offset
pop Y
pop X
ret
# (rd ['sym]) -> any
# (rd 'cnt) -> num | NIL
(code 'doRd 2)
push X
push Z
link
push ZERO # <L I> Result
link
ld E ((E CDR)) # Get arg
eval # Eval it
ld Z (InFile) # Current InFile?
null Z
if nz # Yes
cnt E # Read raw bytes?
if z # No
ld (L I) E # EOF
ld (GetBinZ_FB) getBinaryZ_FB # Set binary read function
ld (Extn) (ExtN) # Set external symbol offset
call binReadZ_FE # Read item?
ldc E (L I) # No: Return EOF
else
shr E 4 # Normalize
jz 90 # Zero
if c # Little endian
lea X (L I) # X on result
ld C 3 # Build signed number
do
call getBinaryZ_FB # Enough bytes?
jc 90 # No
call byteNumBCX_CX # Add next byte to number
dec E # Done?
until z # Yes
ld A (L I) # Double result
call twiceA_A
else
ld X E # Count in X
do
call getBinaryZ_FB # Enough bytes?
jc 90 # No
zxt
push A # Save byte
ld A (L I) # Multiply number by 256
ld E (hex "1002")
call muluAE_A
ld (L I) A # Save digit
pop E # Get digit
shl E 4 # Make short number
or E CNT
call adduAE_A # Add to number
ld (L I) A # Save again
dec X # Done?
until z # Yes
end
big A # Bignum?
if nz # Yes
call zapZeroA_A # Remove leading zeroes
end
ld E A # Get result
end
else
90 ld E Nil # Return NIL
end
drop
pop Z
pop X
ret
# (pr 'any ..) -> any
(code 'doPr 2)
push X
ld X (E CDR) # Get arguments
do
ld E (X)
eval # Eval next arg
push E # Keep
ld (Extn) (ExtN) # Set external symbol offset
call prE # Print binary
pop E
ld X (X CDR) # More arguments?
atom X
until nz # No
pop X
ret
# (wr 'cnt ..) -> cnt
(code 'doWr 2)
push X
ld X (E CDR) # Args
do
ld E (X) # Eval next
eval
ld A E # Get byte
shr A 4 # Normalize
call putStdoutB # Output
ld X (X CDR) # X on rest
atom X # Done?
until nz # Yes
pop X
ret
# vi:et:ts=3:sw=3
|