Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Update to Practcl |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | practcl |
Files: | files | file ages | folders |
SHA3-256: |
4badff3c092f8adc6b659bd97c1cd032 |
User & Date: | hypnotoad 2019-04-08 16:09:40.461 |
Context
2019-07-26
| ||
13:14 | Updating to the latest practcl check-in: 149b1e1e5f user: hypnotoad tags: practcl | |
2019-04-08
| ||
16:09 | Update to Practcl check-in: 4badff3c09 user: hypnotoad tags: practcl | |
2018-12-05
| ||
15:31 | Updating Practcl from tcllib check-in: 8171d2845f user: hypnotoad tags: practcl | |
Changes
Changes to practcl.tcl.
1 2 3 4 5 6 | ### # Amalgamated package for practcl # Do not edit directly, tweak the source in src/ and rerun # build.tcl ### package require Tcl 8.6 | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | ### # Amalgamated package for practcl # Do not edit directly, tweak the source in src/ and rerun # build.tcl ### package require Tcl 8.6 package provide practcl 0.16.1 namespace eval ::practcl {} ### # START: httpwget/wget.tcl ### package provide http::wget 0.1 package require http |
︙ | ︙ | |||
53 54 55 56 57 58 59 60 61 62 63 64 65 66 | ### # END: httpwget/wget.tcl ### ### # START: clay/clay.tcl ### ### # END: clay/clay.tcl ### ### # START: setup.tcl ### | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 | ### # END: httpwget/wget.tcl ### ### # START: clay/clay.tcl ### package provide clay 0.7 namespace eval ::clay { } namespace eval ::clay { } set ::clay::trace 0 proc ::clay::PROC {name arglist body {ninja {}}} { if {[info commands $name] ne {}} return proc $name $arglist $body eval $ninja } if {[info commands ::PROC] eq {}} { namespace eval ::clay { namespace export PROC } namespace eval :: { namespace import ::clay::PROC } } proc ::clay::_ancestors {resultvar class} { upvar 1 $resultvar result if {$class in $result} { return } lappend result $class foreach aclass [::info class superclasses $class] { _ancestors result $aclass } } proc ::clay::ancestors {args} { set result {} set queue {} set metaclasses {} foreach class $args { set ancestors($class) {} _ancestors ancestors($class) $class } foreach class [lreverse $args] { foreach aclass $ancestors($class) { if {$aclass in $result} continue set skip 0 foreach bclass $args { if {$class eq $bclass} continue if {$aclass in $ancestors($bclass)} { set skip 1 break } } if {$skip} continue lappend result $aclass } } foreach class [lreverse $args] { foreach aclass $ancestors($class) { if {$aclass in $result} continue lappend result $aclass } } ### # Screen out classes that do not participate in clay # interactions ### set output {} foreach {item} $result { if {[catch {$item clay noop} err]} { continue } lappend output $item } return $output } proc ::clay::args_to_dict args { if {[llength $args]==1} { return [lindex $args 0] } return $args } proc ::clay::args_to_options args { set result {} foreach {var val} [args_to_dict {*}$args] { lappend result [string trim $var -:] $val } return $result } proc ::clay::dynamic_arguments {ensemble method arglist args} { set idx 0 set len [llength $args] if {$len > [llength $arglist]} { ### # Catch if the user supplies too many arguments ### set dargs 0 if {[lindex $arglist end] ni {args dictargs}} { return -code error -level 2 "Usage: $ensemble $method [string trim [dynamic_wrongargs_message $arglist]]" } } foreach argdef $arglist { if {$argdef eq "args"} { ### # Perform args processing in the style of tcl ### uplevel 1 [list set args [lrange $args $idx end]] break } if {$argdef eq "dictargs"} { ### # Perform args processing in the style of tcl ### uplevel 1 [list set args [lrange $args $idx end]] ### # Perform args processing in the style of clay ### set dictargs [::clay::args_to_options {*}[lrange $args $idx end]] uplevel 1 [list set dictargs $dictargs] break } if {$idx > $len} { ### # Catch if the user supplies too few arguments ### if {[llength $argdef]==1} { return -code error -level 2 "Usage: $ensemble $method [string trim [dynamic_wrongargs_message $arglist]]" } else { uplevel 1 [list set [lindex $argdef 0] [lindex $argdef 1]] } } else { uplevel 1 [list set [lindex $argdef 0] [lindex $args $idx]] } incr idx } } proc ::clay::dynamic_wrongargs_message {arglist} { set result "" set dargs 0 foreach argdef $arglist { if {$argdef in {args dictargs}} { set dargs 1 break } if {[llength $argdef]==1} { append result " $argdef" } else { append result " ?[lindex $argdef 0]?" } } if { $dargs } { append result " ?option value?..." } return $result } proc ::clay::is_dict { d } { # is it a dict, or can it be treated like one? if {[catch {::dict size $d} err]} { #::set ::errorInfo {} return 0 } return 1 } proc ::clay::is_null value { return [expr {$value in {{} NULL}}] } proc ::clay::leaf args { set marker [string index [lindex $args end] end] set result [path {*}${args}] if {$marker eq "/"} { return $result } return [list {*}[lrange $result 0 end-1] [string trim [string trim [lindex $result end]] /]] } proc ::clay::K {a b} {set a} if {[info commands ::K] eq {}} { namespace eval ::clay { namespace export K } namespace eval :: { namespace import ::clay::K } } proc ::clay::noop args {} if {[info commands ::noop] eq {}} { namespace eval ::clay { namespace export noop } namespace eval :: { namespace import ::clay::noop } } proc ::clay::path args { set result {} foreach item $args { set item [string trim $item :./] foreach subitem [split $item /] { lappend result [string trim ${subitem}]/ } } return $result } proc ::clay::putb {buffername args} { upvar 1 $buffername buffer switch [llength $args] { 1 { append buffer [lindex $args 0] \n } 2 { append buffer [string map {*}$args] \n } default { error "usage: putb buffername ?map? string" } } } if {[info command ::putb] eq {}} { namespace eval ::clay { namespace export putb } namespace eval :: { namespace import ::clay::putb } } proc ::clay::script_path {} { set path [file dirname [file join [pwd] [info script]]] return $path } proc ::clay::NSNormalize qualname { if {![string match ::* $qualname]} { set qualname ::clay::classes::$qualname } regsub -all {::+} $qualname "::" } proc ::clay::uuid_generate args { return [uuid generate] } namespace eval ::clay { variable option_class {} variable core_classes {::oo::class ::oo::object} } package require Tcl 8.6 ;# try in pipeline.tcl. Possibly other things. package require TclOO package require md5 2 ::namespace eval ::clay { } ::namespace eval ::clay::classes { } ::namespace eval ::clay::define { } ::namespace eval ::clay::tree { } ::namespace eval ::clay::dict { } ::namespace eval ::clay::list { } ::namespace eval ::clay::uuid { } package require Tcl 8.5 namespace eval ::clay::uuid { namespace export uuid variable uid if {![info exists uid]} { set uid 1 } } proc ::clay::uuid::generate_tcl_machinfo {} { variable machinfo if {[info exists machinfo]} { return $machinfo } lappend machinfo [clock seconds]; # timestamp lappend machinfo [clock clicks]; # system incrementing counter lappend machinfo [info hostname]; # spatial unique id (poor) lappend machinfo [pid]; # additional entropy lappend machinfo [array get ::tcl_platform] ### # If we have /dev/urandom just stream 128 bits from that ### if {[file exists /dev/urandom]} { set fin [open /dev/urandom r] binary scan [read $fin 128] H* machinfo close $fin } elseif {[catch {package require nettool}]} { # More spatial information -- better than hostname. # bug 1150714: opening a server socket may raise a warning messagebox # with WinXP firewall, using ipconfig will return all IP addresses # including ipv6 ones if available. ipconfig is OK on win98+ if {[string equal $::tcl_platform(platform) "windows"]} { catch {exec ipconfig} config lappend machinfo $config } else { catch { set s [socket -server void -myaddr [info hostname] 0] ::clay::K [fconfigure $s -sockname] [close $s] } r lappend machinfo $r } if {[package provide Tk] != {}} { lappend machinfo [winfo pointerxy .] lappend machinfo [winfo id .] } } else { ### # If the nettool package works on this platform # use the stream of hardware ids from it ### lappend machinfo {*}[::nettool::hwid_list] } return $machinfo } proc ::clay::uuid::generate {} { variable uid set tok [md5::MD5Init] md5::MD5Update $tok [incr uid]; # package incrementing counter foreach string [generate_tcl_machinfo] { md5::MD5Update $tok $string } set r [md5::MD5Final $tok] binary scan $r c* r # 3.4: set uuid versioning fields lset r 8 [expr {([lindex $r 8] & 0x3F) | 0x80}] lset r 6 [expr {([lindex $r 6] & 0x0F) | 0x40}] return [binary format c* $r] } proc ::clay::uuid::tostring {uuid} { binary scan $uuid H* s foreach {a b} {0 7 8 11 12 15 16 19 20 end} { append r [string range $s $a $b] - } return [string tolower [string trimright $r -]] } proc ::clay::uuid::fromstring {uuid} { return [binary format H* [string map {- {}} $uuid]] } proc ::clay::uuid::equal {left right} { set l [fromstring $left] set r [fromstring $right] return [string equal $l $r] } proc ::clay::uuid {cmd args} { switch -exact -- $cmd { generate { tailcall ::clay::uuid::tostring [::clay::uuid::generate] } equal { tailcall ::clay::uuid::equal {*}$args } default { return -code error "bad option \"$cmd\":\ must be generate or equal" } } } ::clay::PROC ::tcl::dict::getnull {dictionary args} { if {[exists $dictionary {*}$args]} { get $dictionary {*}$args } } { namespace ensemble configure dict -map [dict replace\ [namespace ensemble configure dict -map] getnull ::tcl::dict::getnull] } ::clay::PROC ::tcl::dict::is_dict { d } { # is it a dict, or can it be treated like one? if {[catch {dict size $d} err]} { #::set ::errorInfo {} return 0 } return 1 } { namespace ensemble configure dict -map [dict replace\ [namespace ensemble configure dict -map] is_dict ::tcl::dict::is_dict] } ::clay::PROC ::tcl::dict::rmerge {args} { ::set result [dict create . {}] # Merge b into a, and handle nested dicts appropriately ::foreach b $args { for { k v } $b { ::set field [string trim $k :/] if {![::clay::tree::is_branch $b $k]} { # Element names that end in ":" are assumed to be literals set result $k $v } elseif { [exists $result $k] } { # key exists in a and b? let's see if both values are dicts # both are dicts, so merge the dicts if { [is_dict [get $result $k]] && [is_dict $v] } { set result $k [rmerge [get $result $k] $v] } else { set result $k $v } } else { set result $k $v } } } return $result } { namespace ensemble configure dict -map [dict replace\ [namespace ensemble configure dict -map] rmerge ::tcl::dict::rmerge] } ::clay::PROC ::clay::tree::is_branch { dict path } { set field [lindex $path end] if {[string index $field end] eq ":"} { return 0 } if {[string index $field 0] eq "."} { return 0 } if {[string index $field end] eq "/"} { return 1 } return [dict exists $dict {*}$path .] } ::clay::PROC ::clay::tree::print {dict} { ::set result {} ::set level -1 ::clay::tree::_dictputb $level result $dict return $result } ::clay::PROC ::clay::tree::_dictputb {level varname dict} { upvar 1 $varname result incr level dict for {field value} $dict { if {$field eq "."} continue if {[clay::tree::is_branch $dict $field]} { putb result "[string repeat " " $level]$field \{" _dictputb $level result $value putb result "[string repeat " " $level]\}" } else { putb result "[string repeat " " $level][list $field $value]" } } } proc ::clay::tree::sanitize {dict} { ::set result {} ::set level -1 ::clay::tree::_sanitizeb {} result $dict return $result } proc ::clay::tree::_sanitizeb {path varname dict} { upvar 1 $varname result dict for {field value} $dict { if {$field eq "."} continue if {[clay::tree::is_branch $dict $field]} { _sanitizeb [list {*}$path $field] result $value } else { dict set result {*}$path $field $value } } } proc ::clay::tree::storage {rawpath} { set isleafvar 0 set path {} set tail [string index $rawpath end] foreach element $rawpath { set items [split [string trim $element /] /] foreach item $items { if {$item eq {}} continue lappend path $item } } return $path } proc ::clay::tree::dictset {varname args} { upvar 1 $varname result if {[llength $args] < 2} { error "Usage: ?path...? path value" } elseif {[llength $args]==2} { set rawpath [lindex $args 0] } else { set rawpath [lrange $args 0 end-1] } set value [lindex $args end] set path [storage $rawpath] set dot . set one {} dict set result $dot $one set dpath {} foreach item [lrange $path 0 end-1] { set field $item lappend dpath [string trim $item /] dict set result {*}$dpath $dot $one } set field [lindex $rawpath end] set ext [string index $field end] if {$ext eq {:} || ![dict is_dict $value]} { dict set result {*}$path $value return } if {$ext eq {/} && ![dict exists $result {*}$path $dot]} { dict set result {*}$path $dot $one } if {[dict exists $result {*}$path $dot]} { dict set result {*}$path [::clay::tree::merge [dict get $result {*}$path] $value] return } dict set result {*}$path $value } proc ::clay::tree::dictmerge {varname args} { upvar 1 $varname result set dot . set one {} dict set result $dot $one foreach dict $args { dict for {f v} $dict { set field [string trim $f /] set bbranch [clay::tree::is_branch $dict $f] if {![dict exists $result $field]} { dict set result $field $v if {$bbranch} { dict set result $field [clay::tree::merge $v] } else { dict set result $field $v } } elseif {[dict exists $result $field $dot]} { if {$bbranch} { dict set result $field [clay::tree::merge [dict get $result $field] $v] } else { dict set result $field $v } } } } return $result } proc ::clay::tree::merge {args} { ### # The result of a merge is always a dict with branches ### set dot . set one {} dict set result $dot $one set argument 0 foreach b $args { # Merge b into a, and handle nested dicts appropriately if {![dict is_dict $b]} { error "Element $b is not a dictionary" } dict for { k v } $b { if {$k eq $dot} { dict set result $dot $one continue } set bbranch [is_branch $b $k] set field [string trim $k /] if { ![dict exists $result $field] } { if {$bbranch} { dict set result $field [merge $v] } else { dict set result $field $v } } else { set abranch [dict exists $result $field $dot] if {$abranch && $bbranch} { dict set result $field [merge [dict get $result $field] $v] } else { dict set result $field $v if {$bbranch} { dict set result $field $dot $one } } } } } return $result } ::clay::PROC ::tcl::dict::isnull {dictionary args} { if {![exists $dictionary {*}$args]} {return 1} return [expr {[get $dictionary {*}$args] in {{} NULL null}}] } { namespace ensemble configure dict -map [dict replace\ [namespace ensemble configure dict -map] isnull ::tcl::dict::isnull] } ::clay::PROC ::clay::ladd {varname args} { upvar 1 $varname var if ![info exists var] { set var {} } foreach item $args { if {$item in $var} continue lappend var $item } return $var } ::clay::PROC ::clay::ldelete {varname args} { upvar 1 $varname var if ![info exists var] { return } foreach item [lsort -unique $args] { while {[set i [lsearch $var $item]]>=0} { set var [lreplace $var $i $i] } } return $var } ::clay::PROC ::clay::lrandom list { set len [llength $list] set idx [expr int(rand()*$len)] return [lindex $list $idx] } namespace eval ::dictargs { } if {[info commands ::dictargs::parse] eq {}} { proc ::dictargs::parse {argdef argdict} { set result {} dict for {field info} $argdef { if {![string is alnum [string index $field 0]]} { error "$field is not a simple variable name" } upvar 1 $field _var set aliases {} if {[dict exists $argdict $field]} { set _var [dict get $argdict $field] continue } if {[dict exists $info aliases:]} { set found 0 foreach {name} [dict get $info aliases:] { if {[dict exists $argdict $name]} { set _var [dict get $argdict $name] set found 1 break } } if {$found} continue } if {[dict exists $info default:]} { set _var [dict get $info default:] \n continue } set mandatory 1 if {[dict exists $info mandatory:]} { set mandatory [dict get $info mandatory:] } if {$mandatory} { error "$field is required" } } } } proc ::dictargs::proc {name argspec body} { set result {} append result "::dictargs::parse \{$argspec\} \$args" \; append result $body uplevel 1 [list ::proc $name [list [list args [list dictargs $argspec]]] $result] } proc ::dictargs::method {name argspec body} { set class [lindex [::info level -1] 1] set result {} append result "::dictargs::parse \{$argspec\} \$args" \; append result $body oo::define $class method $name [list [list args [list dictargs $argspec]]] $result } namespace eval ::clay::dialect { namespace export create foreach {flag test} { tip470 {package vsatisfies [package provide Tcl] 8.7} } { if {![info exists ::clay::dialect::has($flag)]} { set ::clay::dialect::has($flag) [eval $test] } } } proc ::clay::dialect::Push {class} { ::variable class_stack lappend class_stack $class } proc ::clay::dialect::Peek {} { ::variable class_stack return [lindex $class_stack end] } proc ::clay::dialect::Pop {} { ::variable class_stack set class_stack [lrange $class_stack 0 end-1] } if {$::clay::dialect::has(tip470)} { proc ::clay::dialect::current_class {} { return [uplevel 1 self] } } else { proc ::clay::dialect::current_class {} { tailcall Peek } } proc ::clay::dialect::create {name {parent ""}} { variable has set NSPACE [NSNormalize [uplevel 1 {namespace current}] $name] ::namespace eval $NSPACE {::namespace eval define {}} ### # Build the "define" namespace ### if {$parent eq ""} { ### # With no "parent" language, begin with all of the keywords in # oo::define ### foreach command [info commands ::oo::define::*] { set procname [namespace tail $command] interp alias {} ${NSPACE}::define::$procname {} \ ::clay::dialect::DefineThunk $procname } # Create an empty dynamic_methods proc proc ${NSPACE}::dynamic_methods {class} {} namespace eval $NSPACE { ::namespace export dynamic_methods ::namespace eval define {::namespace export *} } set ANCESTORS {} } else { ### # If we have a parent language, that language already has the # [oo::define] keywords as well as additional keywords and behaviors. # We should begin with that ### set pnspace [NSNormalize [uplevel 1 {namespace current}] $parent] apply [list parent { ::namespace export dynamic_methods ::namespace import -force ${parent}::dynamic_methods } $NSPACE] $pnspace apply [list parent { ::namespace import -force ${parent}::define::* ::namespace export * } ${NSPACE}::define] $pnspace set ANCESTORS [list ${pnspace}::object] } ### # Build our dialect template functions ### proc ${NSPACE}::define {oclass args} [string map [list %NSPACE% $NSPACE] { ### # To facilitate library reloading, allow # a dialect to create a class from DEFINE ### set class [::clay::dialect::NSNormalize [uplevel 1 {namespace current}] $oclass] if {[info commands $class] eq {}} { %NSPACE%::class create $class {*}${args} } else { ::clay::dialect::Define %NSPACE% $class {*}${args} } }] interp alias {} ${NSPACE}::define::current_class {} \ ::clay::dialect::current_class interp alias {} ${NSPACE}::define::aliases {} \ ::clay::dialect::Aliases $NSPACE interp alias {} ${NSPACE}::define::superclass {} \ ::clay::dialect::SuperClass $NSPACE if {[info command ${NSPACE}::class] ne {}} { ::rename ${NSPACE}::class {} } ### # Build the metaclass for our language ### ::oo::class create ${NSPACE}::class { superclass ::clay::dialect::MotherOfAllMetaClasses } # Wire up the create method to add in the extra argument we need; the # MotherOfAllMetaClasses will know what to do with it. ::oo::objdefine ${NSPACE}::class \ method create {name {definitionScript ""}} \ "next \$name [list ${NSPACE}::define] \$definitionScript" ### # Build the mother of all classes. Note that $ANCESTORS is already # guaranteed to be a list in canonical form. ### uplevel #0 [string map [list %NSPACE% [list $NSPACE] %name% [list $name] %ANCESTORS% $ANCESTORS] { %NSPACE%::class create %NSPACE%::object { superclass %ANCESTORS% # Put MOACish stuff in here } }] if { "${NSPACE}::class" ni $::clay::dialect::core_classes } { lappend ::clay::dialect::core_classes "${NSPACE}::class" } if { "${NSPACE}::object" ni $::clay::dialect::core_classes } { lappend ::clay::dialect::core_classes "${NSPACE}::object" } } proc ::clay::dialect::NSNormalize {namespace qualname} { if {![string match ::* $qualname]} { set qualname ${namespace}::$qualname } regsub -all {::+} $qualname "::" } proc ::clay::dialect::DefineThunk {target args} { tailcall ::oo::define [Peek] $target {*}$args } proc ::clay::dialect::Canonical {namespace NSpace class} { namespace upvar $namespace cname cname #if {[string match ::* $class]} { # return $class #} if {[info exists cname($class)]} { return $cname($class) } if {[info exists ::clay::dialect::cname($class)]} { return $::clay::dialect::cname($class) } if {[info exists ::clay::dialect::cname(${NSpace}::${class})]} { return $::clay::dialect::cname(${NSpace}::${class}) } foreach item [list "${NSpace}::$class" "::$class"] { if {[info commands $item] ne {}} { return $item } } return ${NSpace}::$class } proc ::clay::dialect::Define {namespace class args} { Push $class try { if {[llength $args]==1} { namespace eval ${namespace}::define [lindex $args 0] } else { ${namespace}::define::[lindex $args 0] {*}[lrange $args 1 end] } ${namespace}::dynamic_methods $class } finally { Pop } } proc ::clay::dialect::Aliases {namespace args} { set class [Peek] namespace upvar $namespace cname cname set NSpace [join [lrange [split $class ::] 1 end-2] ::] set cname($class) $class foreach name $args { set cname($name) $class #set alias $name set alias [NSNormalize $NSpace $name] # Add a local metaclass reference if {![info exists ::clay::dialect::cname($alias)]} { lappend ::clay::dialect::aliases($class) $alias ## # Add a global reference, first come, first served ## set ::clay::dialect::cname($alias) $class } } } proc ::clay::dialect::SuperClass {namespace args} { set class [Peek] namespace upvar $namespace class_info class_info dict set class_info($class) superclass 1 set ::clay::dialect::cname($class) $class set NSpace [join [lrange [split $class ::] 1 end-2] ::] set unique {} foreach item $args { set Item [Canonical $namespace $NSpace $item] dict set unique $Item $item } set root ${namespace}::object if {$class ne $root} { dict set unique $root $root } tailcall ::oo::define $class superclass {*}[dict keys $unique] } if {[info command ::clay::dialect::MotherOfAllMetaClasses] eq {}} { ::oo::class create ::clay::dialect::MotherOfAllMetaClasses { superclass ::oo::class constructor {define definitionScript} { $define [self] { superclass } $define [self] $definitionScript } method aliases {} { if {[info exists ::clay::dialect::aliases([self])]} { return $::clay::dialect::aliases([self]) } } } } namespace eval ::clay::dialect { variable core_classes {::oo::class ::oo::object} } namespace eval ::dictargs { } if {[info commands ::dictargs::parse] eq {}} { proc ::dictargs::parse {argdef argdict} { set result {} dict for {field info} $argdef { if {![string is alnum [string index $field 0]]} { error "$field is not a simple variable name" } upvar 1 $field _var set aliases {} if {[dict exists $argdict $field]} { set _var [dict get $argdict $field] continue } if {[dict exists $info aliases:]} { set found 0 foreach {name} [dict get $info aliases:] { if {[dict exists $argdict $name]} { set _var [dict get $argdict $name] set found 1 break } } if {$found} continue } if {[dict exists $info default:]} { set _var [dict get $info default:] \n continue } set mandatory 1 if {[dict exists $info mandatory:]} { set mandatory [dict get $info mandatory:] } if {$mandatory} { error "$field is required" } } } } proc ::dictargs::proc {name argspec body} { set result {} append result "::dictargs::parse \{$argspec\} \$args" \; append result $body uplevel 1 [list ::proc $name [list [list args [list dictargs $argspec]]] $result] } proc ::dictargs::method {name argspec body} { set class [lindex [::info level -1] 1] set result {} append result "::dictargs::parse \{$argspec\} \$args" \; append result $body oo::define $class method $name [list [list args [list dictargs $argspec]]] $result } ::clay::dialect::create ::clay proc ::clay::dynamic_methods class { foreach command [info commands [namespace current]::dynamic_methods_*] { $command $class } } proc ::clay::dynamic_methods_class {thisclass} { set methods {} set mdata [$thisclass clay find class_typemethod] foreach {method info} $mdata { if {$method eq {.}} continue set method [string trimright $method :/-] if {$method in $methods} continue lappend methods $method set arglist [dict getnull $info arglist] set body [dict getnull $info body] ::oo::objdefine $thisclass method $method $arglist $body } } proc ::clay::define::Array {name {values {}}} { set class [current_class] set name [string trim $name :/] $class clay branch array $name dict for {var val} $values { $class clay set array/ $name $var $val } } proc ::clay::define::Delegate {name info} { set class [current_class] foreach {field value} $info { $class clay set component/ [string trim $name :/]/ $field $value } } proc ::clay::define::constructor {arglist rawbody} { set body { my variable DestroyEvent set DestroyEvent 0 ::clay::object_create [self] [info object class [self]] # Initialize public variables and options my InitializePublic } append body $rawbody set class [current_class] ::oo::define $class constructor $arglist $body } proc ::clay::define::Class_Method {name arglist body} { set class [current_class] $class clay set class_typemethod/ [string trim $name :/] [dict create arglist $arglist body $body] } proc ::clay::define::class_method {name arglist body} { set class [current_class] $class clay set class_typemethod/ [string trim $name :/] [dict create arglist $arglist body $body] } proc ::clay::define::clay {args} { set class [current_class] if {[lindex $args 0] in "cget set branch"} { $class clay {*}$args } else { $class clay set {*}$args } } proc ::clay::define::destructor rawbody { set body { # Run the destructor once and only once set self [self] my variable DestroyEvent if {$DestroyEvent} return set DestroyEvent 1 ::clay::object_destroy $self } append body $rawbody ::oo::define [current_class] destructor $body } proc ::clay::define::Dict {name {values {}}} { set class [current_class] set name [string trim $name :/] $class clay branch dict $name foreach {var val} $values { $class clay set dict/ $name/ $var $val } } proc ::clay::define::Option {name args} { set class [current_class] set dictargs {default {}} foreach {var val} [::clay::args_to_dict {*}$args] { dict set dictargs [string trim $var -:/] $val } set name [string trimleft $name -] ### # Option Class handling ### set optclass [dict getnull $dictargs class] if {$optclass ne {}} { foreach {f v} [$class clay find option_class $optclass] { if {![dict exists $dictargs $f]} { dict set dictargs $f $v } } if {$optclass eq "variable"} { variable $name [dict getnull $dictargs default] } } foreach {f v} $dictargs { $class clay set option $name $f $v } } proc ::clay::define::Option_Class {name args} { set class [current_class] set dictargs {default {}} set name [string trimleft $name -:] foreach {f v} [::clay::args_to_dict {*}$args] { $class clay set option_class $name [string trim $f -/:] $v } } proc ::clay::define::Variable {name {default {}}} { set class [current_class] set name [string trimright $name :/] $class clay set variable/ $name $default } proc ::clay::object_create {objname {class {}}} { #if {$::clay::trace>0} { # puts [list $objname CREATE] #} } proc ::clay::object_rename {object newname} { if {$::clay::trace>0} { puts [list $object RENAME -> $newname] } } proc ::clay::object_destroy objname { if {$::clay::trace>0} { puts [list $objname DESTROY] } ::cron::object_destroy $objname } ::namespace eval ::clay::define { } proc ::clay::ensemble_methodbody {ensemble einfo} { set default standard set preamble {} set eswitch {} if {[dict exists $einfo default]} { set emethodinfo [dict get $einfo default] set arglist [dict getnull $emethodinfo arglist] set realbody [dict get $emethodinfo body] if {[llength $arglist]==1 && [lindex $arglist 0] in {{} args arglist}} { set body {} } else { set body "\n ::clay::dynamic_arguments $ensemble \$method [list $arglist] {*}\$args" } append body "\n " [string trim $realbody] " \n" set default $body dict unset einfo default } foreach {msubmethod esubmethodinfo} [lsort -dictionary -stride 2 $einfo] { set submethod [string trim $msubmethod :/-] if {$submethod eq "_body"} continue if {$submethod eq "_preamble"} { set preamble [dict getnull $esubmethodinfo body] continue } set arglist [dict getnull $esubmethodinfo arglist] set realbody [dict getnull $esubmethodinfo body] if {[string length [string trim $realbody]] eq {}} { dict set eswitch $submethod {} } else { if {[llength $arglist]==1 && [lindex $arglist 0] in {{} args arglist}} { set body {} } else { set body "\n ::clay::dynamic_arguments $ensemble \$method [list $arglist] {*}\$args" } append body "\n " [string trim $realbody] " \n" if {$submethod eq "default"} { set default $body } else { foreach alias [dict getnull $esubmethodinfo aliases] { dict set eswitch $alias - } dict set eswitch $submethod $body } } } set methodlist [lsort -dictionary [dict keys $eswitch]] if {![dict exists $eswitch <list>]} { dict set eswitch <list> {return $methodlist} } if {$default eq "standard"} { set default "error \"unknown method $ensemble \$method. Valid: \$methodlist\"" } dict set eswitch default $default set mbody {} append mbody $preamble \n append mbody \n [list set methodlist $methodlist] append mbody \n "set code \[catch {switch -- \$method [list $eswitch]} result opts\]" append mbody \n {return -options $opts $result} return $mbody } ::proc ::clay::define::Ensemble {rawmethod arglist body} { set class [current_class] #if {$::clay::trace>2} { # puts [list $class Ensemble $rawmethod $arglist $body] #} set mlist [split $rawmethod "::"] set ensemble [string trim [lindex $mlist 0] :/] set mensemble ${ensemble}/ if {[llength $mlist]==1 || [lindex $mlist 1] in "_body"} { set method _body ### # Simple method, needs no parsing, but we do need to record we have one ### $class clay set method_ensemble/ $mensemble _body [dict create arglist $arglist body $body] if {$::clay::trace>2} { puts [list $class clay set method_ensemble/ $mensemble _body ...] } set method $rawmethod if {$::clay::trace>2} { puts [list $class Ensemble $rawmethod $arglist $body] set rawbody $body set body {puts [list [self] $class [self method]]} append body \n $rawbody } ::oo::define $class method $rawmethod $arglist $body return } set method [join [lrange $mlist 2 end] "::"] $class clay set method_ensemble/ $mensemble [string trim [lindex $method 0] :/] [dict create arglist $arglist body $body] if {$::clay::trace>2} { puts [list $class clay set method_ensemble/ $mensemble [string trim $method :/] ...] } } ::oo::define ::clay::class { method clay {submethod args} { my variable clay if {![info exists clay]} { set clay {} } switch $submethod { ancestors { tailcall ::clay::ancestors [self] } branch { set path [::clay::tree::storage $args] if {![dict exists $clay {*}$path .]} { dict set clay {*}$path . {} } } exists { if {![info exists clay]} { return 0 } set path [::clay::tree::storage $args] if {[dict exists $clay {*}$path]} { return 1 } if {[dict exists $clay {*}[lrange $path 0 end-1] [lindex $path end]:]} { return 1 } return 0 } dump { return $clay } dget { if {![info exists clay]} { return {} } set path [::clay::tree::storage $args] if {[dict exists $clay {*}$path]} { return [dict get $clay {*}$path] } if {[dict exists $clay {*}[lrange $path 0 end-1] [lindex $path end]:]} { return [dict get $clay {*}[lrange $path 0 end-1] [lindex $path end]:] } return {} } is_branch { set path [::clay::tree::storage $args] return [dict exists $clay {*}$path .] } getnull - get { if {![info exists clay]} { return {} } set path [::clay::tree::storage $args] if {[llength $path]==0} { return $clay } if {[dict exists $clay {*}$path .]} { return [::clay::tree::sanitize [dict get $clay {*}$path]] } if {[dict exists $clay {*}$path]} { return [dict get $clay {*}$path] } if {[dict exists $clay {*}[lrange $path 0 end-1] [lindex $path end]:]} { return [dict get $clay {*}[lrange $path 0 end-1] [lindex $path end]:] } return {} } find { set path [::clay::tree::storage $args] if {![info exists clay]} { set clay {} } set clayorder [::clay::ancestors [self]] set found 0 if {[llength $path]==0} { set result [dict create . {}] foreach class $clayorder { ::clay::tree::dictmerge result [$class clay dump] } return [::clay::tree::sanitize $result] } foreach class $clayorder { if {[$class clay exists {*}$path .]} { # Found a branch break set found 1 break } if {[$class clay exists {*}$path]} { # Found a leaf. Return that value immediately return [$class clay get {*}$path] } if {[dict exists $clay {*}[lrange $path 0 end-1] [lindex $path end]:]} { return [dict get $clay {*}[lrange $path 0 end-1] [lindex $path end]:] } } if {!$found} { return {} } set result {} # Leaf searches return one data field at a time # Search in our local dict # Search in the in our list of classes for an answer foreach class [lreverse $clayorder] { ::clay::tree::dictmerge result [$class clay dget {*}$path] } return [::clay::tree::sanitize $result] } merge { foreach arg $args { ::clay::tree::dictmerge clay {*}$arg } } noop { # Do nothing. Used as a sign of clay savviness } search { foreach aclass [::clay::ancestors [self]] { if {[$aclass clay exists {*}$args]} { return [$aclass clay get {*}$args] } } } set { ::clay::tree::dictset clay {*}$args } unset { dict unset clay {*}$args } default { dict $submethod clay {*}$args } } } } ::oo::define ::clay::object { method clay {submethod args} { my variable clay claycache clayorder config option_canonical if {![info exists clay]} {set clay {}} if {![info exists claycache]} {set claycache {}} if {![info exists config]} {set config {}} if {![info exists clayorder] || [llength $clayorder]==0} { set clayorder [::clay::ancestors [info object class [self]] {*}[lreverse [info object mixins [self]]]] } switch $submethod { ancestors { return $clayorder } branch { set path [::clay::tree::storage $args] if {![dict exists $clay {*}$path .]} { dict set clay {*}$path . {} } } cget { # Leaf searches return one data field at a time # Search in our local dict if {[llength $args]==1} { set field [string trim [lindex $args 0] -:/] if {[info exists option_canonical($field)]} { set field $option_canonical($field) } if {[dict exists $config $field]} { return [dict get $config $field] } } set path [::clay::tree::storage $args] if {[dict exists $clay {*}$path]} { return [dict get $clay {*}$path] } # Search in our local cache if {[dict exists $claycache {*}$path]} { if {[dict exists $claycache {*}$path .]} { return [dict remove [dict get $claycache {*}$path] .] } else { return [dict get $claycache {*}$path] } } # Search in the in our list of classes for an answer foreach class $clayorder { if {[$class clay exists {*}$path]} { set value [$class clay get {*}$path] dict set claycache {*}$path $value return $value } if {[$class clay exists const {*}$path]} { set value [$class clay get const {*}$path] dict set claycache {*}$path $value return $value } if {[$class clay exists option {*}$path default]} { set value [$class clay get option {*}$path default] dict set claycache {*}$path $value return $value } } return {} } delegate { if {![dict exists $clay .delegate <class>]} { dict set clay .delegate <class> [info object class [self]] } if {[llength $args]==0} { return [dict get $clay .delegate] } if {[llength $args]==1} { set stub <[string trim [lindex $args 0] <>]> if {![dict exists $clay .delegate $stub]} { return {} } return [dict get $clay .delegate $stub] } if {([llength $args] % 2)} { error "Usage: delegate OR delegate stub OR delegate stub OBJECT ?stub OBJECT? ..." } foreach {stub object} $args { set stub <[string trim $stub <>]> dict set clay .delegate $stub $object oo::objdefine [self] forward ${stub} $object oo::objdefine [self] export ${stub} } } dump { # Do a full dump of clay data set result {} # Search in the in our list of classes for an answer foreach class $clayorder { ::clay::tree::dictmerge result [$class clay dump] } ::clay::tree::dictmerge result $clay return $result } ensemble_map { set ensemble [lindex $args 0] my variable claycache set mensemble [string trim $ensemble :/] if {[dict exists $claycache method_ensemble $mensemble]} { return [clay::tree::sanitize [dict get $claycache method_ensemble $mensemble]] } set emap [my clay dget method_ensemble $mensemble] dict set claycache method_ensemble $mensemble $emap return [clay::tree::sanitize $emap] } eval { set script [lindex $args 0] set buffer {} set thisline {} foreach line [split $script \n] { append thisline $line if {![info complete $thisline]} { append thisline \n continue } set thisline [string trim $thisline] if {[string index $thisline 0] eq "#"} continue if {[string length $thisline]==0} continue if {[lindex $thisline 0] eq "my"} { # Line already calls out "my", accept verbatim append buffer $thisline \n } elseif {[string range $thisline 0 2] eq "::"} { # Fully qualified commands accepted verbatim append buffer $thisline \n } elseif { append buffer "my $thisline" \n } set thisline {} } eval $buffer } evolve - initialize { my InitializePublic } exists { # Leaf searches return one data field at a time # Search in our local dict set path [::clay::tree::storage $args] if {[dict exists $clay {*}$path]} { return 1 } # Search in our local cache if {[dict exists $claycache {*}$path]} { return 2 } set count 2 # Search in the in our list of classes for an answer foreach class $clayorder { incr count if {[$class clay exists {*}$path]} { return $count } } return 0 } flush { set claycache {} set clayorder [::clay::ancestors [info object class [self]] {*}[lreverse [info object mixins [self]]]] } forward { oo::objdefine [self] forward {*}$args } dget { set path [::clay::tree::storage $args] if {[llength $path]==0} { # Do a full dump of clay data set result {} # Search in the in our list of classes for an answer foreach class $clayorder { ::clay::tree::dictmerge result [$class clay dump] } ::clay::tree::dictmerge result $clay return $result } # Search in our local cache if {[dict exists $claycache {*}$path .]} { return [dict get $claycache {*}$path] } if {[dict exists $claycache {*}$path]} { return [dict get $claycache {*}$path] } if {[dict exists $clay {*}$path] && ![dict exists $clay {*}$path .]} { # Path is a leaf return [dict get $clay {*}$path] } set found 0 set branch [dict exists $clay {*}$path .] foreach class $clayorder { if {[$class clay exists {*}$path .]} { set found 1 break } if {!$branch && [$class clay exists {*}$path]} { set result [$class clay dget {*}$path] dict set claycache {*}$path $result return $result } } # Path is a branch set result [dict getnull $clay {*}$path] foreach class $clayorder { if {![$class clay exists {*}$path .]} continue ::clay::tree::dictmerge result [$class clay dget {*}$path] } #if {[dict exists $clay {*}$path .]} { # ::clay::tree::dictmerge result #} dict set claycache {*}$path $result return $result } getnull - get { set path [::clay::tree::storage $args] if {[llength $path]==0} { # Do a full dump of clay data set result {} # Search in the in our list of classes for an answer foreach class $clayorder { ::clay::tree::dictmerge result [$class clay dump] } ::clay::tree::dictmerge result $clay return [::clay::tree::sanitize $result] } # Search in our local cache if {[dict exists $claycache {*}$path .]} { return [::clay::tree::sanitize [dict get $claycache {*}$path]] } if {[dict exists $claycache {*}$path]} { return [dict get $claycache {*}$path] } if {[dict exists $clay {*}$path] && ![dict exists $clay {*}$path .]} { # Path is a leaf return [dict get $clay {*}$path] } set found 0 set branch [dict exists $clay {*}$path .] foreach class $clayorder { if {[$class clay exists {*}$path .]} { set found 1 break } if {!$branch && [$class clay exists {*}$path]} { set result [$class clay dget {*}$path] dict set claycache {*}$path $result return $result } } # Path is a branch set result [dict getnull $clay {*}$path] #foreach class [lreverse $clayorder] { # if {![$class clay exists {*}$path .]} continue # ::clay::tree::dictmerge result [$class clay dget {*}$path] #} foreach class $clayorder { if {![$class clay exists {*}$path .]} continue ::clay::tree::dictmerge result [$class clay dget {*}$path] } #if {[dict exists $clay {*}$path .]} { # ::clay::tree::dictmerge result [dict get $clay {*}$path] #} dict set claycache {*}$path $result return [clay::tree::sanitize $result] } leaf { # Leaf searches return one data field at a time # Search in our local dict set path [::clay::tree::storage $args] if {[dict exists $clay {*}$path .]} { return [clay::tree::sanitize [dict get $clay {*}$path]] } if {[dict exists $clay {*}$path]} { return [dict get $clay {*}$path] } # Search in our local cache if {[dict exists $claycache {*}$path .]} { return [clay::tree::sanitize [dict get $claycache {*}$path]] } if {[dict exists $claycache {*}$path]} { return [dict get $claycache {*}$path] } # Search in the in our list of classes for an answer foreach class $clayorder { if {[$class clay exists {*}$path]} { set value [$class clay get {*}$path] dict set claycache {*}$path $value return $value } } } merge { foreach arg $args { ::clay::tree::dictmerge clay {*}$arg } } mixin { ### # Mix in the class ### set prior [info object mixins [self]] set newmixin {} foreach item $args { lappend newmixin ::[string trimleft $item :] } set newmap $args foreach class $prior { if {$class ni $newmixin} { set script [$class clay search mixin/ unmap-script] if {[string length $script]} { if {[catch $script err errdat]} { puts stderr "[self] MIXIN ERROR POPPING $class:\n[dict get $errdat -errorinfo]" } } } } ::oo::objdefine [self] mixin {*}$args ### # Build a compsite map of all ensembles defined by the object's current # class as well as all of the classes being mixed in ### my InitializePublic foreach class $newmixin { if {$class ni $prior} { set script [$class clay search mixin/ map-script] if {[string length $script]} { if {[catch $script err errdat]} { puts stderr "[self] MIXIN ERROR PUSHING $class:\n[dict get $errdat -errorinfo]" } } } } foreach class $newmixin { set script [$class clay search mixin/ react-script] if {[string length $script]} { if {[catch $script err errdat]} { puts stderr "[self] MIXIN ERROR PEEKING $class:\n[dict get $errdat -errorinfo]" } break } } } mixinmap { my variable clay if {![dict exists $clay .mixin]} { dict set clay .mixin {} } if {[llength $args]==0} { return [dict get $clay .mixin] } elseif {[llength $args]==1} { return [dict getnull $clay .mixin [lindex $args 0]] } else { dict for {slot classes} $args { dict set clay .mixin $slot $classes } set classlist {} dict for {item class} [dict get $clay .mixin] { if {$class ne {}} { lappend classlist $class } } my clay mixin {*}[lreverse $classlist] } } provenance { if {[dict exists $clay {*}$args]} { return self } foreach class $clayorder { if {[$class clay exists {*}$args]} { return $class } } return {} } replace { set clay [lindex $args 0] } source { source [lindex $args 0] } set { #puts [list [self] clay SET {*}$args] set claycache {} ::clay::tree::dictset clay {*}$args } default { dict $submethod clay {*}$args } } } method InitializePublic {} { my variable clayorder clay claycache config option_canonical set claycache {} set clayorder [::clay::ancestors [info object class [self]] {*}[lreverse [info object mixins [self]]]] if {![info exists clay]} { set clay {} } if {![info exists config]} { set config {} } dict for {var value} [my clay get variable] { if { $var in {. clay} } continue set var [string trim $var :/] my variable $var if {![info exists $var]} { if {$::clay::trace>2} {puts [list initialize variable $var $value]} set $var $value } } dict for {var value} [my clay get dict/] { if { $var in {. clay} } continue set var [string trim $var :/] my variable $var if {![info exists $var]} { set $var {} } foreach {f v} $value { if {$f eq "."} continue if {![dict exists ${var} $f]} { if {$::clay::trace>2} {puts [list initialize dict $var $f $v]} dict set ${var} $f $v } } } foreach {var value} [my clay get array/] { if { $var in {. clay} } continue set var [string trim $var :/] if { $var eq {clay} } continue my variable $var if {![info exists $var]} { array set $var {} } foreach {f v} $value { if {![array exists ${var}($f)]} { if {$f eq "."} continue if {$::clay::trace>2} {puts [list initialize array $var\($f\) $v]} set ${var}($f) $v } } } foreach {field info} [my clay get option/] { if { $field in {. clay} } continue set field [string trim $field -/:] foreach alias [dict getnull $info aliases] { set option_canonical($alias) $field } if {[dict exists $config $field]} continue set getcmd [dict getnull $info default-command] if {$getcmd ne {}} { set value [{*}[string map [list %field% $field %self% [namespace which my]] $getcmd]] } else { set value [dict getnull $info default] } dict set config $field $value set setcmd [dict getnull $info set-command] if {$setcmd ne {}} { {*}[string map [list %field% [list $field] %value% [list $value] %self% [namespace which my]] $setcmd] } } my variable clayorder clay claycache if {[info exists clay]} { set emap [dict getnull $clay method_ensemble] } else { set emap {} } foreach class [lreverse $clayorder] { ### # Build a compsite map of all ensembles defined by the object's current # class as well as all of the classes being mixed in ### dict for {mensemble einfo} [$class clay get method_ensemble] { if {$mensemble eq {.}} continue set ensemble [string trim $mensemble :/] if {$::clay::trace>2} {puts [list Defining $ensemble from $class]} dict for {method info} $einfo { if {$method eq {.}} continue if {![dict is_dict $info]} { puts [list WARNING: class: $class method: $method not dict: $info] continue } dict set info source $class if {$::clay::trace>2} {puts [list Defining $ensemble -> $method from $class - $info]} dict set emap $ensemble $method $info } } } foreach {ensemble einfo} $emap { #if {[dict exists $einfo _body]} continue set body [::clay::ensemble_methodbody $ensemble $einfo] if {$::clay::trace>2} { set rawbody $body set body {puts [list [self] <object> [self method]]} append body \n $rawbody } oo::objdefine [self] method $ensemble {{method default} args} $body } } } ::clay::object clay branch array ::clay::object clay branch mixin ::clay::object clay branch option ::clay::object clay branch dict clay ::clay::object clay set variable DestroyEvent 0 namespace eval ::clay { namespace export * } ### # END: clay/clay.tcl ### ### # START: setup.tcl ### |
︙ | ︙ | |||
1685 1686 1687 1688 1689 1690 1691 | set path_indexed($path) 0 } } else { puts [list WARNING: NO PATHS FOUND IN $base] } set path_indexed($base) 1 set path_indexed([file join $base boot tcl]) 1 | | | 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 | set path_indexed($path) 0 } } else { puts [list WARNING: NO PATHS FOUND IN $base] } set path_indexed($base) 1 set path_indexed([file join $base boot tcl]) 1 append buffer \n {# SINGLE FILE MODULES BEGIN} \n {set dir [lindex $::PATHSTACK end]} \n foreach path $paths { if {$path_indexed($path)} continue set thisdir [file_relative $base $path] set simpleIdx [_pkgindex_simpleIndex $path] if {[string length $simpleIdx]==0} continue incr path_indexed($path) if {[string length $simpleIdx]} { |
︙ | ︙ | |||
1788 1789 1790 1791 1792 1793 1794 | } set IdxTime [file mtime $pkgIndexFile] if {$latest<$IdxTime} return } ::practcl::dotclexec $buildscript } proc ::practcl::installModule {modpath DEST} { | < > > > > > > > > > > | < | | > | | | | > | 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 | } set IdxTime [file mtime $pkgIndexFile] if {$latest<$IdxTime} return } ::practcl::dotclexec $buildscript } proc ::practcl::installModule {modpath DEST} { set dpath [file join $DEST modules [file tail $modpath]] puts [list ::practcl::installModule $modpath -> $dpath] if {[file exists [file join $modpath index.tcl]]} { # IRM/Tao style modules non-amalgamated ::practcl::installDir $modpath $dpath return } if {[file exists [file join $modpath build build.tcl]]} { buildModule $modpath } set files [glob -nocomplain [file join $modpath *.tcl]] if {[llength $files]} { if {[llength $files]>1} { if {![file exists [file join $modpath pkgIndex.tcl]]} { pkg_mkIndex $modpath } } file delete -force $dpath file mkdir $dpath foreach file $files { file copy $file $dpath } } if {[file exists [file join $modpath htdocs]]} { ::practcl::copyDir [file join $modpath htdocs] [file join $dpath htdocs] } } ### |
︙ | ︙ | |||
2813 2814 2815 2816 2817 2818 2819 | if {$RCSRC eq {} || ![file exists $RCSRC]} { set RCSRC [file join $TKSRCDIR win rc wish.rc] } if {$RCMAN eq {} || ![file exists $RCMAN]} { set RCMAN [file join [$TKOBJ define get builddir] wish.exe.manifest] } if {$RCICO eq {} || ![file exists $RCICO]} { | | | 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 | if {$RCSRC eq {} || ![file exists $RCSRC]} { set RCSRC [file join $TKSRCDIR win rc wish.rc] } if {$RCMAN eq {} || ![file exists $RCMAN]} { set RCMAN [file join [$TKOBJ define get builddir] wish.exe.manifest] } if {$RCICO eq {} || ![file exists $RCICO]} { set RCICO [file join $TKSRCDIR win rc wish.ico] } set TKSRC [file normalize $TKSRCDIR] lappend cmd --include [::practcl::file_relative $path [file join $TKSRC generic]] \ --include [::practcl::file_relative $path [file join $TKSRC win]] \ --include [::practcl::file_relative $path [file join $TKSRC win rc]] } else { if {$RCSRC eq {} || ![file exists $RCSRC]} { |
︙ | ︙ | |||
5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 | foreach arg $args { ::practcl::copyDir $arg $vfspath } set fout [open [file join $vfspath pkgIndex.tcl] w] puts $fout [string map [list %platform% [my define get TEACUP_PROFILE]] {set ::tcl_teapot_profile {%platform%}}] puts $fout { set ::PKGIDXFILE [info script] set dir [file dirname $::PKGIDXFILE] if {$::tcl_platform(platform) eq "windows"} { | > | | | | 7341 7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 7363 | foreach arg $args { ::practcl::copyDir $arg $vfspath } set fout [open [file join $vfspath pkgIndex.tcl] w] puts $fout [string map [list %platform% [my define get TEACUP_PROFILE]] {set ::tcl_teapot_profile {%platform%}}] puts $fout { namespace eval ::starkit {} set ::PKGIDXFILE [info script] set dir [file dirname $::PKGIDXFILE] if {$::tcl_platform(platform) eq "windows"} { set ::starkit::localHome [file join [file normalize $::env(LOCALAPPDATA)] tcl] } else { set ::starkit::localHome [file normalize ~/tcl] } set ::tcl_teapot [file join $::starkit::localHome teapot $::tcl_teapot_profile] lappend ::auto_path $::tcl_teapot } puts $fout [list proc installDir [info args ::practcl::installDir] [info body ::practcl::installDir]] set buffer [::practcl::pkgindex_path $vfspath] puts $fout $buffer puts $fout { # Advertise statically linked packages |
︙ | ︙ |