plum

#treesitter#compiler#wasm

git clone https://git.pyrossh.dev/plum

A statically typed, imperative programming language inspired by rust, python


bf629a2Peter John 2026-09-03T19:47:08+05:30
feat(plum): trait conformance checking, Stringable->ToStr, finish str.plum
Cargo.lock CHANGED
@@ -89,7 +89,7 @@ version = "1.1.5"
89
89
  source = "registry+https://github.com/rust-lang/crates.io-index"
90
90
  checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc"
91
91
  dependencies = [
92
- "windows-sys",
92
+ "windows-sys 0.61.2",
93
93
  ]
94
94
 
95
95
  [[package]]
@@ -100,7 +100,7 @@ checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d"
100
100
  dependencies = [
101
101
  "anstyle",
102
102
  "once_cell_polyfill",
103
- "windows-sys",
103
+ "windows-sys 0.61.2",
104
104
  ]
105
105
 
106
106
  [[package]]
@@ -135,7 +135,7 @@ dependencies = [
135
135
  "addr2line 0.25.1",
136
136
  "cfg-if",
137
137
  "libc",
138
- "miniz_oxide",
138
+ "miniz_oxide 0.8.9",
139
139
  "object 0.37.3",
140
140
  "rustc-demangle",
141
141
  "windows-link",
@@ -507,6 +507,17 @@ dependencies = [
507
507
  "winapi",
508
508
  ]
509
509
 
510
+ [[package]]
511
+ name = "displaydoc"
512
+ version = "0.2.7"
513
+ source = "registry+https://github.com/rust-lang/crates.io-index"
514
+ checksum = "c6232dd377dcc64799954cbd3a9bb882e9cdc1308ccd87b1c098f1fb2eaf82a8"
515
+ dependencies = [
516
+ "proc-macro2",
517
+ "quote",
518
+ "syn 3.0.0",
519
+ ]
520
+
510
521
  [[package]]
511
522
  name = "either"
512
523
  version = "1.16.0"
@@ -547,7 +558,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
547
558
  checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
548
559
  dependencies = [
549
560
  "libc",
550
- "windows-sys",
561
+ "windows-sys 0.61.2",
551
562
  ]
552
563
 
553
564
  [[package]]
@@ -568,6 +579,17 @@ version = "0.4.2"
568
579
  source = "registry+https://github.com/rust-lang/crates.io-index"
569
580
  checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80"
570
581
 
582
+ [[package]]
583
+ name = "flate2"
584
+ version = "1.1.10"
585
+ source = "registry+https://github.com/rust-lang/crates.io-index"
586
+ checksum = "6e634e2e0ebac1ee034020da1ca582e17ffe4e0f5e985823721e168928136dcb"
587
+ dependencies = [
588
+ "crc32fast",
589
+ "miniz_oxide 0.9.1",
590
+ "zlib-rs",
591
+ ]
592
+
571
593
  [[package]]
572
594
  name = "fnv"
573
595
  version = "1.0.7"
@@ -580,6 +602,15 @@ version = "0.2.0"
580
602
  source = "registry+https://github.com/rust-lang/crates.io-index"
581
603
  checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb"
582
604
 
605
+ [[package]]
606
+ name = "form_urlencoded"
607
+ version = "1.2.2"
608
+ source = "registry+https://github.com/rust-lang/crates.io-index"
609
+ checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf"
610
+ dependencies = [
611
+ "percent-encoding",
612
+ ]
613
+
583
614
  [[package]]
584
615
  name = "futures"
585
616
  version = "0.3.33"
@@ -765,12 +796,116 @@ version = "0.5.0"
765
796
  source = "registry+https://github.com/rust-lang/crates.io-index"
766
797
  checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
767
798
 
799
+ [[package]]
800
+ name = "icu_collections"
801
+ version = "2.3.0"
802
+ source = "registry+https://github.com/rust-lang/crates.io-index"
803
+ checksum = "fa68d21081c4a05d5a901a1c62add574c77048b6a1c67be3b50ce0b60d4ca513"
804
+ dependencies = [
805
+ "displaydoc",
806
+ "potential_utf",
807
+ "utf8_iter",
808
+ "yoke",
809
+ "zerofrom",
810
+ "zerovec",
811
+ ]
812
+
813
+ [[package]]
814
+ name = "icu_locale_core"
815
+ version = "2.3.0"
816
+ source = "registry+https://github.com/rust-lang/crates.io-index"
817
+ checksum = "d56e28588da92eee5c3201a6eff33fabdd49b62269c8938d4ff050ce4d900deb"
818
+ dependencies = [
819
+ "displaydoc",
820
+ "litemap",
821
+ "tinystr",
822
+ "writeable",
823
+ "zerovec",
824
+ ]
825
+
826
+ [[package]]
827
+ name = "icu_normalizer"
828
+ version = "2.3.0"
829
+ source = "registry+https://github.com/rust-lang/crates.io-index"
830
+ checksum = "12f9cf5f235641ed274641dd81c3f28d870e276763d0797aeeab72317b1c646f"
831
+ dependencies = [
832
+ "icu_collections",
833
+ "icu_normalizer_data",
834
+ "icu_properties",
835
+ "icu_provider",
836
+ "smallvec",
837
+ "zerovec",
838
+ ]
839
+
840
+ [[package]]
841
+ name = "icu_normalizer_data"
842
+ version = "2.3.0"
843
+ source = "registry+https://github.com/rust-lang/crates.io-index"
844
+ checksum = "1563da1ed3e0b3bf3d74c9b85917ac9c56464d2f57242270c09c9e752f8021a0"
845
+
846
+ [[package]]
847
+ name = "icu_properties"
848
+ version = "2.3.0"
849
+ source = "registry+https://github.com/rust-lang/crates.io-index"
850
+ checksum = "7e7ca276ad3145661a65914e6daf131ca5120cd3dcee8f8f3214b8875184a148"
851
+ dependencies = [
852
+ "displaydoc",
853
+ "icu_collections",
854
+ "icu_locale_core",
855
+ "icu_properties_data",
856
+ "icu_provider",
857
+ "zerotrie",
858
+ "zerovec",
859
+ ]
860
+
861
+ [[package]]
862
+ name = "icu_properties_data"
863
+ version = "2.3.0"
864
+ source = "registry+https://github.com/rust-lang/crates.io-index"
865
+ checksum = "e590f038c1464a96894fd6d10127e90a8be4509f56ff7ecef851b15cee0b7caa"
866
+
867
+ [[package]]
868
+ name = "icu_provider"
869
+ version = "2.3.1"
870
+ source = "registry+https://github.com/rust-lang/crates.io-index"
871
+ checksum = "d27bbb9d3abbefac45d55f647c9de1d44aafcd1186eb91879afef17c396c3e73"
872
+ dependencies = [
873
+ "displaydoc",
874
+ "icu_locale_core",
875
+ "writeable",
876
+ "yoke",
877
+ "zerofrom",
878
+ "zerotrie",
879
+ "zerovec",
880
+ ]
881
+
768
882
  [[package]]
769
883
  name = "id-arena"
770
884
  version = "2.3.0"
771
885
  source = "registry+https://github.com/rust-lang/crates.io-index"
772
886
  checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954"
773
887
 
888
+ [[package]]
889
+ name = "idna"
890
+ version = "1.1.0"
891
+ source = "registry+https://github.com/rust-lang/crates.io-index"
892
+ checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de"
893
+ dependencies = [
894
+ "idna_adapter",
895
+ "smallvec",
896
+ "utf8_iter",
897
+ ]
898
+
899
+ [[package]]
900
+ name = "idna_adapter"
901
+ version = "1.2.2"
902
+ source = "registry+https://github.com/rust-lang/crates.io-index"
903
+ checksum = "cb68373c0d6620ef8105e855e7745e18b0d00d3bdb07fb532e434244cdb9a714"
904
+ dependencies = [
905
+ "icu_normalizer",
906
+ "icu_properties",
907
+ ]
908
+
774
909
  [[package]]
775
910
  name = "indexmap"
776
911
  version = "2.14.0"
@@ -898,6 +1033,12 @@ version = "0.12.1"
898
1033
  source = "registry+https://github.com/rust-lang/crates.io-index"
899
1034
  checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53"
900
1035
 
1036
+ [[package]]
1037
+ name = "litemap"
1038
+ version = "0.8.3"
1039
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1040
+ checksum = "47d9d19d1d6efa0109d2f65ff4c85cddd50bd572e5a00127ab10987290bcefae"
1041
+
901
1042
  [[package]]
902
1043
  name = "log"
903
1044
  version = "0.4.33"
@@ -964,6 +1105,16 @@ dependencies = [
964
1105
  "adler2",
965
1106
  ]
966
1107
 
1108
+ [[package]]
1109
+ name = "miniz_oxide"
1110
+ version = "0.9.1"
1111
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1112
+ checksum = "b63fbc4a50860e98e7b2aa7804ded1db5cbc3aff9193adaff57a6931bf7c4b4c"
1113
+ dependencies = [
1114
+ "adler2",
1115
+ "simd-adler32",
1116
+ ]
1117
+
967
1118
  [[package]]
968
1119
  name = "object"
969
1120
  version = "0.37.3"
@@ -1003,6 +1154,12 @@ version = "4.3.0"
1003
1154
  source = "registry+https://github.com/rust-lang/crates.io-index"
1004
1155
  checksum = "d211803b9b6b570f68772237e415a029d5a50c65d382910b879fb19d3271f94d"
1005
1156
 
1157
+ [[package]]
1158
+ name = "percent-encoding"
1159
+ version = "2.3.2"
1160
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1161
+ checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220"
1162
+
1006
1163
  [[package]]
1007
1164
  name = "petgraph"
1008
1165
  version = "0.6.5"
@@ -1046,6 +1203,7 @@ dependencies = [
1046
1203
  "toml_edit",
1047
1204
  "tree-sitter",
1048
1205
  "tree-sitter-plum",
1206
+ "ureq",
1049
1207
  "wasmtime",
1050
1208
  ]
1051
1209
 
@@ -1085,6 +1243,15 @@ dependencies = [
1085
1243
  "serde",
1086
1244
  ]
1087
1245
 
1246
+ [[package]]
1247
+ name = "potential_utf"
1248
+ version = "0.1.6"
1249
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1250
+ checksum = "d83eb9bc6d8e5cf568e7a1101d60ee05e81ed50ea106026f3d18deeb046d7661"
1251
+ dependencies = [
1252
+ "zerovec",
1253
+ ]
1254
+
1088
1255
  [[package]]
1089
1256
  name = "pretty_assertions"
1090
1257
  version = "1.4.1"
@@ -1226,6 +1393,20 @@ version = "0.8.11"
1226
1393
  source = "registry+https://github.com/rust-lang/crates.io-index"
1227
1394
  checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4"
1228
1395
 
1396
+ [[package]]
1397
+ name = "ring"
1398
+ version = "0.17.14"
1399
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1400
+ checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7"
1401
+ dependencies = [
1402
+ "cc",
1403
+ "cfg-if",
1404
+ "getrandom 0.2.17",
1405
+ "libc",
1406
+ "untrusted",
1407
+ "windows-sys 0.52.0",
1408
+ ]
1409
+
1229
1410
  [[package]]
1230
1411
  name = "rustc-demangle"
1231
1412
  version = "0.1.28"
@@ -1248,7 +1429,42 @@ dependencies = [
1248
1429
  "errno",
1249
1430
  "libc",
1250
1431
  "linux-raw-sys",
1251
- "windows-sys",
1432
+ "windows-sys 0.61.2",
1433
+ ]
1434
+
1435
+ [[package]]
1436
+ name = "rustls"
1437
+ version = "0.23.43"
1438
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1439
+ checksum = "0283386ce02abc0151e1761d08802dfe86c173b0b494af5cbc086574e453da06"
1440
+ dependencies = [
1441
+ "log",
1442
+ "once_cell",
1443
+ "ring",
1444
+ "rustls-pki-types",
1445
+ "rustls-webpki",
1446
+ "subtle",
1447
+ "zeroize",
1448
+ ]
1449
+
1450
+ [[package]]
1451
+ name = "rustls-pki-types"
1452
+ version = "1.15.1"
1453
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1454
+ checksum = "2f4925028c7eb5d1fcdaf196971378ed9d2c1c4efc7dc5d011256f76c99c0a96"
1455
+ dependencies = [
1456
+ "zeroize",
1457
+ ]
1458
+
1459
+ [[package]]
1460
+ name = "rustls-webpki"
1461
+ version = "0.103.15"
1462
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1463
+ checksum = "f3c3cf1d8b1e7d4927e2d154c3fcb02979afb9939629c62cd9048d4f07b60ac2"
1464
+ dependencies = [
1465
+ "ring",
1466
+ "rustls-pki-types",
1467
+ "untrusted",
1252
1468
  ]
1253
1469
 
1254
1470
  [[package]]
@@ -1337,6 +1553,12 @@ version = "2.0.1"
1337
1553
  source = "registry+https://github.com/rust-lang/crates.io-index"
1338
1554
  checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
1339
1555
 
1556
+ [[package]]
1557
+ name = "simd-adler32"
1558
+ version = "0.3.10"
1559
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1560
+ checksum = "3a219298ac11a56ea9a6d2120044824d6f01aeb034955e7af7bc16858527deea"
1561
+
1340
1562
  [[package]]
1341
1563
  name = "slab"
1342
1564
  version = "0.4.12"
@@ -1370,6 +1592,12 @@ version = "0.11.1"
1370
1592
  source = "registry+https://github.com/rust-lang/crates.io-index"
1371
1593
  checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
1372
1594
 
1595
+ [[package]]
1596
+ name = "subtle"
1597
+ version = "2.6.1"
1598
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1599
+ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
1600
+
1373
1601
  [[package]]
1374
1602
  name = "supports-color"
1375
1603
  version = "3.0.2"
@@ -1413,6 +1641,17 @@ dependencies = [
1413
1641
  "unicode-ident",
1414
1642
  ]
1415
1643
 
1644
+ [[package]]
1645
+ name = "synstructure"
1646
+ version = "0.13.2"
1647
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1648
+ checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2"
1649
+ dependencies = [
1650
+ "proc-macro2",
1651
+ "quote",
1652
+ "syn 2.0.119",
1653
+ ]
1654
+
1416
1655
  [[package]]
1417
1656
  name = "target-lexicon"
1418
1657
  version = "0.13.5"
@@ -1429,7 +1668,7 @@ dependencies = [
1429
1668
  "getrandom 0.4.3",
1430
1669
  "once_cell",
1431
1670
  "rustix",
1432
- "windows-sys",
1671
+ "windows-sys 0.61.2",
1433
1672
  ]
1434
1673
 
1435
1674
  [[package]]
@@ -1448,7 +1687,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1448
1687
  checksum = "230a1b821ccbd75b185820a1f1ff7b14d21da1e442e22c0863ea5f08771a8874"
1449
1688
  dependencies = [
1450
1689
  "rustix",
1451
- "windows-sys",
1690
+ "windows-sys 0.61.2",
1452
1691
  ]
1453
1692
 
1454
1693
  [[package]]
@@ -1501,6 +1740,16 @@ dependencies = [
1501
1740
  "syn 3.0.0",
1502
1741
  ]
1503
1742
 
1743
+ [[package]]
1744
+ name = "tinystr"
1745
+ version = "0.8.4"
1746
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1747
+ checksum = "b1e27c91459209c2986af3dcf603a5a74a4368754ce37414f59acc971167f643"
1748
+ dependencies = [
1749
+ "displaydoc",
1750
+ "zerovec",
1751
+ ]
1752
+
1504
1753
  [[package]]
1505
1754
  name = "tokio"
1506
1755
  version = "1.53.0"
@@ -1694,6 +1943,46 @@ version = "0.2.2"
1694
1943
  source = "registry+https://github.com/rust-lang/crates.io-index"
1695
1944
  checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254"
1696
1945
 
1946
+ [[package]]
1947
+ name = "untrusted"
1948
+ version = "0.9.0"
1949
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1950
+ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1"
1951
+
1952
+ [[package]]
1953
+ name = "ureq"
1954
+ version = "2.12.1"
1955
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1956
+ checksum = "02d1a66277ed75f640d608235660df48c8e3c19f3b4edb6a263315626cc3c01d"
1957
+ dependencies = [
1958
+ "base64",
1959
+ "flate2",
1960
+ "log",
1961
+ "once_cell",
1962
+ "rustls",
1963
+ "rustls-pki-types",
1964
+ "url",
1965
+ "webpki-roots 0.26.11",
1966
+ ]
1967
+
1968
+ [[package]]
1969
+ name = "url"
1970
+ version = "2.5.8"
1971
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1972
+ checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed"
1973
+ dependencies = [
1974
+ "form_urlencoded",
1975
+ "idna",
1976
+ "percent-encoding",
1977
+ "serde",
1978
+ ]
1979
+
1980
+ [[package]]
1981
+ name = "utf8_iter"
1982
+ version = "1.0.4"
1983
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1984
+ checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
1985
+
1697
1986
  [[package]]
1698
1987
  name = "utf8parse"
1699
1988
  version = "0.2.2"
@@ -1938,7 +2227,7 @@ dependencies = [
1938
2227
  "wasmtime-internal-unwinder",
1939
2228
  "wasmtime-internal-versioned-export-macros",
1940
2229
  "wat",
1941
- "windows-sys",
2230
+ "windows-sys 0.61.2",
1942
2231
  "wit-parser",
1943
2232
  ]
1944
2233
 
@@ -1989,7 +2278,7 @@ dependencies = [
1989
2278
  "sha2",
1990
2279
  "toml",
1991
2280
  "wasmtime-environ",
1992
- "windows-sys",
2281
+ "windows-sys 0.61.2",
1993
2282
  "zstd",
1994
2283
  ]
1995
2284
 
@@ -2065,7 +2354,7 @@ dependencies = [
2065
2354
  "rustix",
2066
2355
  "wasmtime-environ",
2067
2356
  "wasmtime-internal-versioned-export-macros",
2068
- "windows-sys",
2357
+ "windows-sys 0.61.2",
2069
2358
  ]
2070
2359
 
2071
2360
  [[package]]
@@ -2089,7 +2378,7 @@ dependencies = [
2089
2378
  "cfg-if",
2090
2379
  "libc",
2091
2380
  "wasmtime-internal-core",
2092
- "windows-sys",
2381
+ "windows-sys 0.61.2",
2093
2382
  ]
2094
2383
 
2095
2384
  [[package]]
@@ -2161,6 +2450,24 @@ dependencies = [
2161
2450
  "wasm-bindgen",
2162
2451
  ]
2163
2452
 
2453
+ [[package]]
2454
+ name = "webpki-roots"
2455
+ version = "0.26.11"
2456
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2457
+ checksum = "521bc38abb08001b01866da9f51eb7c5d647a19260e00054a8c7fd5f9e57f7a9"
2458
+ dependencies = [
2459
+ "webpki-roots 1.0.9",
2460
+ ]
2461
+
2462
+ [[package]]
2463
+ name = "webpki-roots"
2464
+ version = "1.0.9"
2465
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2466
+ checksum = "7dcd9d09a39985f5344844e66b0c530a33843579125f23e21e9f0f220850f22a"
2467
+ dependencies = [
2468
+ "rustls-pki-types",
2469
+ ]
2470
+
2164
2471
  [[package]]
2165
2472
  name = "winapi"
2166
2473
  version = "0.3.9"
@@ -2183,7 +2490,7 @@ version = "0.1.11"
2183
2490
  source = "registry+https://github.com/rust-lang/crates.io-index"
2184
2491
  checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
2185
2492
  dependencies = [
2186
- "windows-sys",
2493
+ "windows-sys 0.61.2",
2187
2494
  ]
2188
2495
 
2189
2496
  [[package]]
@@ -2198,6 +2505,15 @@ version = "0.2.1"
2198
2505
  source = "registry+https://github.com/rust-lang/crates.io-index"
2199
2506
  checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
2200
2507
 
2508
+ [[package]]
2509
+ name = "windows-sys"
2510
+ version = "0.52.0"
2511
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2512
+ checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
2513
+ dependencies = [
2514
+ "windows-targets",
2515
+ ]
2516
+
2201
2517
  [[package]]
2202
2518
  name = "windows-sys"
2203
2519
  version = "0.61.2"
@@ -2207,6 +2523,70 @@ dependencies = [
2207
2523
  "windows-link",
2208
2524
  ]
2209
2525
 
2526
+ [[package]]
2527
+ name = "windows-targets"
2528
+ version = "0.52.6"
2529
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2530
+ checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
2531
+ dependencies = [
2532
+ "windows_aarch64_gnullvm",
2533
+ "windows_aarch64_msvc",
2534
+ "windows_i686_gnu",
2535
+ "windows_i686_gnullvm",
2536
+ "windows_i686_msvc",
2537
+ "windows_x86_64_gnu",
2538
+ "windows_x86_64_gnullvm",
2539
+ "windows_x86_64_msvc",
2540
+ ]
2541
+
2542
+ [[package]]
2543
+ name = "windows_aarch64_gnullvm"
2544
+ version = "0.52.6"
2545
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2546
+ checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
2547
+
2548
+ [[package]]
2549
+ name = "windows_aarch64_msvc"
2550
+ version = "0.52.6"
2551
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2552
+ checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
2553
+
2554
+ [[package]]
2555
+ name = "windows_i686_gnu"
2556
+ version = "0.52.6"
2557
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2558
+ checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
2559
+
2560
+ [[package]]
2561
+ name = "windows_i686_gnullvm"
2562
+ version = "0.52.6"
2563
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2564
+ checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
2565
+
2566
+ [[package]]
2567
+ name = "windows_i686_msvc"
2568
+ version = "0.52.6"
2569
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2570
+ checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
2571
+
2572
+ [[package]]
2573
+ name = "windows_x86_64_gnu"
2574
+ version = "0.52.6"
2575
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2576
+ checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
2577
+
2578
+ [[package]]
2579
+ name = "windows_x86_64_gnullvm"
2580
+ version = "0.52.6"
2581
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2582
+ checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
2583
+
2584
+ [[package]]
2585
+ name = "windows_x86_64_msvc"
2586
+ version = "0.52.6"
2587
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2588
+ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
2589
+
2210
2590
  [[package]]
2211
2591
  name = "winnow"
2212
2592
  version = "0.7.15"
@@ -2241,12 +2621,41 @@ dependencies = [
2241
2621
  "wasmparser 0.252.0",
2242
2622
  ]
2243
2623
 
2624
+ [[package]]
2625
+ name = "writeable"
2626
+ version = "0.6.4"
2627
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2628
+ checksum = "3ad82d2a33cdc9674dc7465672f271e096168fcdbe0f799d9e6db8c5892679dc"
2629
+
2244
2630
  [[package]]
2245
2631
  name = "yansi"
2246
2632
  version = "1.0.1"
2247
2633
  source = "registry+https://github.com/rust-lang/crates.io-index"
2248
2634
  checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049"
2249
2635
 
2636
+ [[package]]
2637
+ name = "yoke"
2638
+ version = "0.8.3"
2639
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2640
+ checksum = "709fe23a0424b6a435d82152b1bd3fdfb0833487d5fa90d05d42762a9891fef5"
2641
+ dependencies = [
2642
+ "stable_deref_trait",
2643
+ "yoke-derive",
2644
+ "zerofrom",
2645
+ ]
2646
+
2647
+ [[package]]
2648
+ name = "yoke-derive"
2649
+ version = "0.8.2"
2650
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2651
+ checksum = "de844c262c8848816172cef550288e7dc6c7b7814b4ee56b3e1553f275f1858e"
2652
+ dependencies = [
2653
+ "proc-macro2",
2654
+ "quote",
2655
+ "syn 2.0.119",
2656
+ "synstructure",
2657
+ ]
2658
+
2250
2659
  [[package]]
2251
2660
  name = "zerocopy"
2252
2661
  version = "0.8.54"
@@ -2267,6 +2676,72 @@ dependencies = [
2267
2676
  "syn 2.0.119",
2268
2677
  ]
2269
2678
 
2679
+ [[package]]
2680
+ name = "zerofrom"
2681
+ version = "0.1.8"
2682
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2683
+ checksum = "0ec05a11813ea801ff6d75110ad09cd0824ddba17dfe17128ea0d5f68e6c5272"
2684
+ dependencies = [
2685
+ "zerofrom-derive",
2686
+ ]
2687
+
2688
+ [[package]]
2689
+ name = "zerofrom-derive"
2690
+ version = "0.1.7"
2691
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2692
+ checksum = "11532158c46691caf0f2593ea8358fed6bbf68a0315e80aae9bd41fbade684a1"
2693
+ dependencies = [
2694
+ "proc-macro2",
2695
+ "quote",
2696
+ "syn 2.0.119",
2697
+ "synstructure",
2698
+ ]
2699
+
2700
+ [[package]]
2701
+ name = "zeroize"
2702
+ version = "1.9.0"
2703
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2704
+ checksum = "e13c156562582aa81c60cb29407084cdb54c4164760106ab78e6c5b0858cf64e"
2705
+
2706
+ [[package]]
2707
+ name = "zerotrie"
2708
+ version = "0.2.5"
2709
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2710
+ checksum = "4ea269c3bd32f0a32c321907a2ae912ba6f4649bb0fc764a15627e99a7095a3f"
2711
+ dependencies = [
2712
+ "displaydoc",
2713
+ "yoke",
2714
+ "zerofrom",
2715
+ ]
2716
+
2717
+ [[package]]
2718
+ name = "zerovec"
2719
+ version = "0.11.8"
2720
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2721
+ checksum = "bb0464e17806c1d976d5cba29399c7f08e516e279e2ba493f63123b5fca67dd8"
2722
+ dependencies = [
2723
+ "yoke",
2724
+ "zerofrom",
2725
+ "zerovec-derive",
2726
+ ]
2727
+
2728
+ [[package]]
2729
+ name = "zerovec-derive"
2730
+ version = "0.11.6"
2731
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2732
+ checksum = "34df6fc39dbd26ddc9c10e6a2984476e13acce22e64e4487636ef494369225da"
2733
+ dependencies = [
2734
+ "proc-macro2",
2735
+ "quote",
2736
+ "syn 3.0.0",
2737
+ ]
2738
+
2739
+ [[package]]
2740
+ name = "zlib-rs"
2741
+ version = "0.6.7"
2742
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2743
+ checksum = "34b31d188d9d685a4f9c7b46d6e36631b07058d2cfe190267adce54dc230bf12"
2744
+
2270
2745
  [[package]]
2271
2746
  name = "zmij"
2272
2747
  version = "1.0.23"
README.md CHANGED
@@ -234,7 +234,7 @@ type Point =
234
234
  x: Int
235
235
  y: Int
236
236
 
237
- type Named(Stringable) = # implements Stringable
237
+ type Named(ToStr) = # implements ToStr
238
238
  name: Str
239
239
 
240
240
  trait Shape =
@@ -253,6 +253,8 @@ enum Option =
253
253
 
254
254
  Full example: [`examples/types.plum`](examples/types.plum).
255
255
 
256
+ `type X(TraitName, ...) = ...`'s trait claims are checked: `plum-checker` verifies `X` actually defines every method `TraitName` declares, with a matching param count/types and return type (a return/param type the trait itself can't parameterize, like `Err`'s `cause() -> Option`, matches any concrete instantiation an implementer declares, e.g. `Option[MyError]`). A trait name that isn't actually declared anywhere (`Comparable`/`Readable`/`Writable` are used this way in a few places in `libs/std` today) is silently unenforced rather than an error, since there's nothing real yet to check it against.
257
+
256
258
  ### Generics
257
259
 
258
260
  Generic type parameters are single letters only: `a`, `b`, `c`, `d`.
@@ -389,7 +391,8 @@ hello, world!
389
391
  Some things parse and type-check but don't compile to wasm yet — `plum-wasm-codegen` reports a clear error rather than silently producing wrong code:
390
392
 
391
393
  - interpolating a `Float` value in a string (`Str`/`Int`/`Bool` interpolation, and plain non-interpolated literals, all compile) — correct decimal formatting of a float is a substantial separate undertaking (something like Grisu/Ryu), scoped out for now
392
- - The generic-field-type gap that used to block `libs/std`'s real `List[T]`/`Node[T]` from compiling at all (a class/enum-variant field declared with a concrete instantiation of another generic type, e.g. `Node.next: Option[Node]`) is fixed — `List[T]`'s methods (`get`/`length`/`add`/`set`/`removeAt`/`remove`/`clear`/`reverse`/`each`/`map`/`reduce`/`sort`/`join`, including its `Stringable`-bounded dispatch) are exercised directly, at their real generic type, by the `test` blocks at the bottom of [`libs/std/list.plum`](libs/std/list.plum) itself (run via `plum test libs/std/list.plum`) — not a non-generic stand-in.
394
+ - The generic-field-type gap that used to block `libs/std`'s real `List[T]`/`Node[T]` from compiling at all (a class/enum-variant field declared with a concrete instantiation of another generic type, e.g. `Node.next: Option[Node]`) is fixed — `List[T]`'s methods (`get`/`length`/`add`/`set`/`removeAt`/`remove`/`clear`/`reverse`/`each`/`map`/`reduce`/`sort`/`join`, including its `ToStr`-bounded dispatch) are exercised directly, at their real generic type, by the `test` blocks at the bottom of [`libs/std/list.plum`](libs/std/list.plum) itself (run via `plum test libs/std/list.plum`) — not a non-generic stand-in.
393
395
  - `Map[K, V]` previously hit a *different* bug here: a top-level function whose own declared return type was a fully-concrete generic instantiation (e.g. `fun makeMap() -> Map[Str, Int] = ...`) caused monomorphization to eagerly (and incorrectly) attempt to specialize an unrelated generic type's method (`Option.filter`) at an unresolved type variable, producing a spurious `expected Option, found Option$V` type error even though `filter` was never called anywhere in the program. Root cause: `maybeRewriteReturn` (in `plum-checker/src/monomorphize.rs`) treated ANY return type merely NAMING a known generic class/enum as still-unresolved and in need of rewriting from the body's inferred tail type — even when that name already carried concrete type args (`List[Str]`, `Map[Str, Int]`), clobbering an already-correct declared return type with a stale, unmangled one inferred through tables monomorphization hadn't finished refreshing yet. Fixed by only treating a BARE reference (no `[...]` at all, e.g. `-> Box`) as needing that rewrite; a companion fix pre-resolves every ordinary (non-generic) fn/method's signature into the type tables before any body rewriting begins, so cross-file call order no longer matters. `Option.andThen`/`Result.map`/`Result.mapErr` (a single extra generic, possibly nested inside a closure's return type) are now implemented and working. `Map.map` (needing TWO new generic params nested inside a closure's return type, on a class rather than an enum) is now implemented too, once `specializeFn` was fixed to also substitute a method's own extra generics inside its BODY (not just its params/return) — an explicit bracketed construction like `Map[X, Y](items: ...)` written directly in a method's own body previously kept the literal letters "X"/"Y" forever, silently minting bogus specializations that corrupted unrelated template compilation elsewhere in the program. A second, narrower gap remains: a closure-literal argument whose body does field access on its own param (`|p| cb(p.key, p.val)`) still can't type-check once more than one specialization of the same generic class shares that field name (e.g. both `Pair$Str$Int` and `Pair$Str$Str` declare `key`/`val`) — the checker's field-usage heuristic for inferring a closure param's class becomes ambiguous and gives up; `Map.map`'s own body sidesteps this by using a manual linked-list walk (matching `keys`/`values`/`each`'s existing style) instead of `List.map` with a field-accessing closure
394
396
  - A generic class/enum method whose return type nests that SAME class/enum inside itself (`List[T].chunk(self) -> List[List[T]]`) used to stack-overflow the compiler for every program merely importing the class, whether or not anything called the method — fixed; `List.chunk`/`List.partition` now ship and work as a working example of the pattern (build any inner `List[T]` value via an EXISTING ordinary method, e.g. `self.sublist(...)`, never a second bare `List(...)` construction in the same body, which is ambiguous with the method's own return-type fallback)
395
397
  - A ternary as a closure's own inline body (`|n| cond ? a : b`) used to parse as an OUTER ternary wrapping the whole closure instead (`(|n| cond) ? a : b`) — a grammar shift/reduce ambiguity where `closure`'s default precedence (0) beat `ternary_expression`'s deliberately-low `PREC.conditional` (-1) at the point the parser decides whether to keep extending the closure's body or reduce it as already-complete. Fixed by giving `closure` its own even-lower precedence (`PREC.closure = -2`, `tooling/tree-sitter-plum/grammar.js`) so the parser now always prefers letting a ternary (or anything else valid there) keep extending the closure's inline body — see `examples/closures.plum`'s `"closure with an inline ternary body runs correctly"` test.
398
+ - `libs/std/str.plum` is otherwise complete (including `endsWith`/`pad`/`truncate`, filled in alongside the `ToStr`-conformance work below), but three methods remain deliberately unimplemented `todo` stubs (they compile fine and trap at runtime if actually called, rather than failing to compile — a different flavor of gap than the rest of this section): `test`/`matchPattern`/`matchAll`/`replace`/`replaceAll`/`search` all need a real `Regex` type/engine, which doesn't exist anywhere in `libs/std` yet; `deburr` (diacritic stripping, `é` -> `e`) needs a full Unicode decomposition table; `template` (lodash's `_.template`) needs the ability to compile and run Plum source from a `Str` value at runtime — there's no `eval`/dynamic-codegen capability in the language to build it on.
examples/types.plum CHANGED
@@ -2,7 +2,7 @@ type Point =
2
2
  x: Int
3
3
  y: Int
4
4
 
5
- type Named(Stringable) =
5
+ type Named(ToStr) =
6
6
  name: Str
7
7
 
8
8
  type Box[T] =
libs/std/buffer.plum CHANGED
@@ -12,7 +12,7 @@ import std/str
12
12
  # `bytes.Buffer`'s asymptotic behavior — unlike the previous `Str`-backed
13
13
  # version of this type, which recopied everything written so far on every
14
14
  # write.
15
- type Buffer(Stringable) =
15
+ type Buffer(ToStr) =
16
16
  data: []Byte
17
17
  len: Int
18
18
 
libs/std/http.plum CHANGED
@@ -1,28 +1,162 @@
1
1
  module std
2
2
 
3
+ import std/buffer
4
+ import std/json
5
+ import std/list
3
- import std/path
6
+ import std/map
7
+ import std/option
8
+ import std/result
4
- import std/os
9
+ import std/str
5
- import std/http/content_type
6
10
 
11
+ # An HTTP response: status code, response headers, and the raw response
12
+ # body as a `Str` (a byte array, so binary bodies round-trip intact).
7
13
  type Response =
8
- headers: Map(Str, Str)
9
- body: Buffer
10
14
  status: Int
15
+ headers: Map[Str, Str]
16
+ body: Str
11
17
 
18
+ # 2xx status codes are success; everything else (redirects, 4xx, 5xx) is
19
+ # surfaced here rather than as an `Err` from `request` — a non-2xx
12
- # builds a Response by reading the file at `file_path` and inferring its content type.
20
+ # response is still a complete, well-formed HTTP exchange, not a failed
13
- # NOTE: the original used a `Response::create()` fluent builder chain
14
- # (`.header(...).contentType(...).body(...).status(...)`), but this language has
15
- # no "::" static-call syntax and no mutating "with"-style builder methods, so
16
- # this constructs the Response directly instead.
17
- fun createFileResponse(file_path: Str) -> Response =
21
+ # one (`request` itself only fails for transport-level problems like a
18
- content := content_type.fromExt(file_path.ext())
19
- data := os.readFile(file_path)
22
+ # DNS/connection error).
20
- Response(headers: Map(), body: data, status: 200)
21
-
22
- fun index() -> Response =
23
+ fun ok(self) -> Bool =
24
+ self.status >= 200 && self.status < 300
25
+
26
+ # Parses `body` as JSON. Fails the same way `Json.fromStr` does for a
27
+ # response body that isn't valid JSON.
28
+ fun json(self) -> Result[Json, JsonParseError] =
29
+ return Json.fromStr(self.body)
30
+
31
+ fun emptyHeaders() -> Map[Str, Str] =
32
+ return Map[Str, Str](items: List[Pair[Str, Str]](head: None, tail: None, size: 0))
33
+
34
+ # A single blocking network round trip — this VM has no async/event-loop
35
+ # mechanism, so `rawHttpRequest` runs to completion before returning (same
36
+ # idea as `libs/std/os.plum`'s `rawReadFile`). `headers` is `"Key: Value"`
37
+ # lines joined by `\n` (`""` for none). The result packs an outcome flag,
38
+ # then either the status code and response headers (success) or an error
39
+ # message (failure), as fields joined by `\x01`, up to the first `\x00` —
40
+ # everything after that byte is the raw response body. `\x00`/`\x01` can
41
+ # never occur in the metadata fields themselves (the flag/status are
42
+ # decimal digits, header names/values and the error message are always
43
+ # plain text), so they safely mark where the opaque body bytes start even
44
+ # when the body itself is arbitrary binary data.
45
+ extern fun rawHttpRequest(method: Str, url: Str, headers: Str, body: Str) -> Str
46
+
47
+ # Packs `headers` into the `"Key: Value"`-per-line format `rawHttpRequest`
48
+ # expects for its own `headers` argument.
49
+ fun encodeHeaders(headers: Map[Str, Str]) -> Str =
50
+ buf := Buffer()
51
+ headers.each(|k, v|
52
+ if buf.length() > 0
23
- createFileResponse("index.html")
53
+ buf.write("\n")
24
-
54
+ buf.write(k)
55
+ buf.write(": ")
56
+ buf.write(v))
57
+ return buf.toStr()
58
+
59
+ # The reverse of `encodeHeaders`, for the response headers `rawHttpRequest`
60
+ # packs into its result.
25
- fun serveFile(file_path: Str) -> Response =
61
+ fun decodeHeaders(raw: Str) -> Map[Str, Str] =
62
+ result := emptyHeaders()
63
+ if raw == ""
64
+ return result
65
+ raw.split("\n", 0).each(|line|
66
+ idx := line.indexOf(": ")
67
+ if idx >= 0
68
+ key := line.sub(0, idx)
69
+ val := line.sub(idx + 2, line.length())
70
+ result.set(key, val))
71
+ return result
72
+
73
+ # Performs a single HTTP request and waits for the full response. Fails
74
+ # only for a transport-level problem (DNS failure, connection refused, TLS
75
+ # error, ...) — an HTTP-level error status (404, 500, ...) is still a
76
+ # successful round trip, returned as `Ok(Response(...))` with that status
77
+ # (check `Response.ok()`).
78
+ fun request(method: Str, url: Str, headers: Map[Str, Str], body: Str) -> Result[Response, Str] =
79
+ raw := rawHttpRequest(method, url, encodeHeaders(headers), body)
80
+ sep := raw.indexOf("\x00")
81
+ meta := sep >= 0 ? raw.sub(0, sep) : raw
82
+ resp_body := sep >= 0 ? raw.sub(sep + 1, raw.length()) : ""
83
+ parts := meta.split("\x01", 3)
84
+ flag := parts.get(0).unwrapOr("")
85
+ if flag != "1"
86
+ return Err(parts.get(2).unwrapOr("http request failed"))
87
+ match Int.fromStr(parts.get(1).unwrapOr(""))
88
+ Ok(status) =>
89
+ return Ok(Response(status: status, headers: decodeHeaders(parts.get(2).unwrapOr("")), body: resp_body))
90
+ Err(e) =>
91
+ return Err("invalid status code in http response: {e}")
92
+
93
+ fun get(url: Str, headers: Map[Str, Str]) -> Result[Response, Str] =
94
+ return request("GET", url, headers, "")
95
+
96
+ fun head(url: Str, headers: Map[Str, Str]) -> Result[Response, Str] =
97
+ return request("HEAD", url, headers, "")
98
+
99
+ fun delete(url: Str, headers: Map[Str, Str]) -> Result[Response, Str] =
100
+ return request("DELETE", url, headers, "")
101
+
102
+ fun post(url: Str, headers: Map[Str, Str], body: Str) -> Result[Response, Str] =
103
+ return request("POST", url, headers, body)
104
+
105
+ fun put(url: Str, headers: Map[Str, Str], body: Str) -> Result[Response, Str] =
106
+ return request("PUT", url, headers, body)
107
+
108
+ fun patch(url: Str, headers: Map[Str, Str], body: Str) -> Result[Response, Str] =
109
+ return request("PATCH", url, headers, body)
110
+
111
+ # Convenience wrapper: sends `body` as a JSON `Str`, adding a
112
+ # `Content-Type: application/json` header, and parses the response back as
113
+ # JSON via `Response.json()`.
114
+ fun postJson(url: Str, headers: Map[Str, Str], body: Json) -> Result[Response, Str] =
115
+ headers.set("Content-Type", "application/json")
116
+ return post(url, headers, body.toStr())
117
+
118
+ test "encodeHeaders/decodeHeaders round-trip a header map"
119
+ h := emptyHeaders()
120
+ h.set("Content-Type", "application/json")
121
+ h.set("Accept", "*/*")
26
- content := content_type.fromExt(file_path.ext())
122
+ decoded := decodeHeaders(encodeHeaders(h))
123
+ expect decoded.get("Content-Type").unwrap() == "application/json"
124
+ expect decoded.get("Accept").unwrap() == "*/*"
125
+
27
- data := os.readFile(file_path)
126
+ test "decodeHeaders returns an empty map for an empty string"
28
- Response(headers: Map(), body: data, status: 200)
127
+ expect decodeHeaders("").isEmpty() == True
128
+
129
+ test "get performs a real HTTP round trip"
130
+ match get("https://httpbin.org/get", emptyHeaders())
131
+ Ok(resp) =>
132
+ expect resp.ok() == True
133
+ expect resp.status == 200
134
+ Err(_) =>
135
+ expect True == False
136
+
137
+ test "get reports a non-2xx status without failing the request"
138
+ match get("https://httpbin.org/status/404", emptyHeaders())
139
+ Ok(resp) =>
140
+ expect resp.ok() == False
141
+ expect resp.status == 404
142
+ Err(_) =>
143
+ expect True == False
144
+
145
+ test "post sends a body and the server echoes it back"
146
+ match post("https://httpbin.org/post", emptyHeaders(), "hello world")
147
+ Ok(resp) =>
148
+ expect resp.ok() == True
149
+ match resp.json()
150
+ Ok(j) =>
151
+ expect j.asMap().unwrap().get("data").unwrap().asStr().unwrap() == "hello world"
152
+ Err(_) =>
153
+ expect True == False
154
+ Err(_) =>
155
+ expect True == False
156
+
157
+ test "request fails for an unreachable host"
158
+ match get("http://this-host-does-not-exist.invalid/", emptyHeaders())
159
+ Ok(_) =>
160
+ expect True == False
161
+ Err(_) =>
162
+ expect True == True
libs/std/list.plum CHANGED
@@ -12,7 +12,7 @@ type Node[T] =
12
12
 
13
13
  # A list is a data structure describing a contiguous section of an array stored separately from the slice variable itself.
14
14
  # It contains the pointers to the start and end nodes (head, tail) and maintains the size as well
15
- type List[T: Stringable](Stringable) =
15
+ type List[T: ToStr](ToStr) =
16
16
  head: Option[Node[T]]
17
17
  tail: Option[Node[T]]
18
18
  size: Int
@@ -460,7 +460,7 @@ type List[T: Stringable](Stringable) =
460
460
  break
461
461
  res.toStr()
462
462
 
463
- # `List[T: Stringable](Stringable)` declared implementing `Stringable`
463
+ # `List[T: ToStr](ToStr)` declared implementing `ToStr`
464
464
  # from the start but never actually defined `toStr` — harmless for a
465
465
  # PLAIN `List[Int]`/`List[Str]`/etc (nothing needs to call `.toStr()` on
466
466
  # the LIST ITSELF, just on its elements, which `join` above already
libs/std/map.plum CHANGED
@@ -7,11 +7,11 @@ import std/option
7
7
  # `toStr` (unlike `Option`'s — see `libs/std/option.plum`'s note on
8
8
  # `toOptionStr`) IS safe as an ordinary method here: `Pair[K, V]` is only
9
9
  # ever used as `List[Pair[K, V]]`'s element type inside `Map[K, V]`, and
10
- # `List[T: Stringable]` already requires its own `T` to support `toStr` —
10
+ # `List[T: ToStr]` already requires its own `T` to support `toStr` —
11
- # so a `Pair` used as a `List` element always has `K`/`V: Stringable` too,
11
+ # so a `Pair` used as a `List` element always has `K`/`V: ToStr` too,
12
12
  # and `List`'s own eagerly-compiled `join`/`toStr` (which call `.toStr()` on
13
13
  # every element) need this to exist for every `Map` specialization anyway.
14
- type Pair[K, V](Stringable) =
14
+ type Pair[K, V](ToStr) =
15
15
  key: K
16
16
  val: V
17
17
 
libs/std/option.plum CHANGED
@@ -112,7 +112,7 @@ enum Option =
112
112
  # `toStr` — so an `Option.toStr` calling `.toStr()` on the wrapped value
113
113
  # would fail to compile for THAT specialization even though nothing ever
114
114
  # actually calls `.toStr()` on an `Option[Node[Int]]`. Use `toOptionStr`
115
- # below (an explicit stringifier callback, not an implicit `T: Stringable`
115
+ # below (an explicit stringifier callback, not an implicit `T: ToStr`
116
116
  # bound) wherever printing an `Option` is needed.
117
117
  fun toOptionStr(self, valueToStr: fn(T) -> Str) -> Str =
118
118
  match self
libs/std/result.plum CHANGED
@@ -116,7 +116,7 @@ enum Result =
116
116
 
117
117
  # No implicit `toStr(self) -> Str` — see the identical note on
118
118
  # `Option.toOptionStr` in `libs/std/option.plum`: a method that assumes
119
- # `T`/`E: Stringable` gets compiled for EVERY specialization of `Result`
119
+ # `T`/`E: ToStr` gets compiled for EVERY specialization of `Result`
120
120
  # anywhere in the program (there's no lazy/on-demand method compilation),
121
121
  # so an implicit bound like this can break an unrelated specialization
122
122
  # whose payload doesn't support it. Explicit stringifier callbacks instead.
libs/std/str.plum CHANGED
@@ -3,13 +3,13 @@ module std
3
3
  import std/list
4
4
 
5
5
  # Any type that can be converted to a str needs to implement this trait
6
- trait Stringable =
6
+ trait ToStr =
7
7
  toStr() -> Str
8
8
 
9
9
  # A Str is an array of contiguous data stored in memory with a null termination using hex 0x00 or ASCII 0x00.
10
10
  # It is immutable and cannot be modified. It is copied for any changes and saved to a new memory location.
11
11
  # The previous str is freed if its reference count is 0 within the block.
12
- type Str(Comparable, Stringable, Readable, Writable) =
12
+ type Str(Comparable, ToStr, Readable, Writable) =
13
13
  data: Buffer
14
14
 
15
15
  # Number of bytes in the string. Every other method below is built on top of
@@ -104,6 +104,9 @@ type Str(Comparable, Stringable, Readable, Writable) =
104
104
  fun startsWith(self, search: Str) -> Bool =
105
105
  matchesAt(self, search, 0, search.length())
106
106
 
107
+ fun endsWith(self, search: Str) -> Bool =
108
+ matchesAt(self, search, self.length() - search.length(), search.length())
109
+
107
110
  fun concat(self, other: Str) -> Str =
108
111
  self + other
109
112
 
@@ -247,9 +250,28 @@ type Str(Comparable, Stringable, Readable, Writable) =
247
250
  fun escapeRegExp(self) -> Str =
248
251
  escapeRegExpFrom(self, 0, self.length())
249
252
 
253
+ # Pads BOTH sides of `self` with repeated copies of `sub` until its length
254
+ # is at least `count`, split as evenly as possible between the two sides
255
+ # (the left side gets any odd byte of the remainder, matching lodash's
256
+ # `_.pad`). Inherits `padStart`/`padEnd`'s own overshoot behavior when
257
+ # `sub` doesn't evenly divide the needed amount on either side.
250
- fun pad(self) -> Str =
258
+ fun pad(self, sub: Str, count: Int) -> Str =
259
+ len := self.length()
260
+ if len >= count || sub.length() == 0
261
+ return self
262
+ total := count - len
263
+ left := total / 2
264
+ right := total - left
265
+ return self.padStart(sub, len + left).padEnd(sub, len + left + right)
266
+
267
+ # `template` (lodash's `_.template`) compiles a string containing
268
+ # `<%= expr %>`-style placeholders into a REUSABLE function that renders it
269
+ # against different data each call — that needs the ability to compile and
270
+ # run Plum source AT RUNTIME (from a `Str` value, not a `.plum` file), which
271
+ # the language has no way to do (no `eval`, no dynamic codegen from within
272
+ # a running program). Left as a known gap rather than a fundamentally
273
+ # different, simpler feature (e.g. a one-shot find/replace) under the same
251
- todo
274
+ # name.
252
-
253
275
  fun template(self) -> Str =
254
276
  todo
255
277
 
@@ -262,8 +284,17 @@ type Str(Comparable, Stringable, Readable, Writable) =
262
284
  fun trimStart(self) -> Str =
263
285
  trimStartFrom(self, 0, self.length())
264
286
 
287
+ # Truncates `self` to at most `length` bytes (INCLUDING the "..." suffix,
288
+ # lodash's default `omission` string) if it's longer than `length`; returns
289
+ # `self` unchanged otherwise. `length` too small to fit the full "..."
290
+ # itself just returns as many of its leading bytes as fit.
265
- fun truncate(self) -> Str =
291
+ fun truncate(self, length: Int) -> Str =
292
+ if self.length() <= length
266
- todo
293
+ return self
294
+ omission := "..."
295
+ if length <= omission.length()
296
+ return omission.sub(0, length)
297
+ return self.sub(0, length - omission.length()) + omission
267
298
 
268
299
  fun unescape(self) -> Str =
269
300
  unescapeFrom(self, 0, self.length())
@@ -526,3 +557,61 @@ test "string interpolation supports a method call taking a closure literal"
526
557
  test "string interpolation supports a ternary expression"
527
558
  n := 5
528
559
  expect "{n > 0 ? "positive" : "non-positive"}" == "positive"
560
+
561
+ # ---- Str method regression tests ----
562
+
563
+ test "endsWith matches a real suffix and rejects a non-suffix or an over-long search"
564
+ expect "hello.plum".endsWith(".plum") == True
565
+ expect "hello.plum".endsWith(".rs") == False
566
+ expect "hi".endsWith("hello") == False
567
+
568
+ test "startsWith/endsWith/contains/indexOf agree on a shared example"
569
+ s := "the quick brown fox"
570
+ expect s.startsWith("the") == True
571
+ expect s.endsWith("fox") == True
572
+ expect s.contains("quick") == True
573
+ expect s.indexOf("brown") == 10
574
+ expect s.indexOf("missing") == -1
575
+
576
+ test "trim/trimStart/trimEnd strip only leading/trailing whitespace"
577
+ expect " hi ".trim() == "hi"
578
+ expect " hi ".trimStart() == "hi "
579
+ expect " hi ".trimEnd() == " hi"
580
+ expect "hi".trim() == "hi"
581
+
582
+ test "repeat concatenates self count times, and is empty for count <= 0"
583
+ expect "ab".repeat(3) == "ababab"
584
+ expect "ab".repeat(0) == ""
585
+ expect "ab".repeat(-1) == ""
586
+
587
+ test "padStart/padEnd/pad grow a string to at least the target length"
588
+ expect "5".padStart("0", 3) == "005"
589
+ expect "5".padEnd("0", 3) == "500"
590
+ expect "hi".pad("-", 6) == "--hi--"
591
+ expect "hi".pad("-", 5) == "-hi--"
592
+ expect "hello".pad("-", 3) == "hello"
593
+
594
+ test "truncate shortens a too-long string with a trailing ellipsis"
595
+ expect "hello world".truncate(8) == "hello..."
596
+ expect "hi".truncate(8) == "hi"
597
+ expect "hello world".truncate(2) == ".."
598
+
599
+ test "toLower/upperCase/capitalize/lowerFirst/upperFirst case-convert as expected"
600
+ expect "Hello World".toLower() == "hello world"
601
+ expect "Hello World".upperCase() == "HELLO WORLD"
602
+ expect "hello".capitalize() == "Hello"
603
+ expect "Hello".lowerFirst() == "hello"
604
+ expect "hello".upperFirst() == "Hello"
605
+
606
+ test "camelCase/snakeCase/kebabCase/startCase convert a multi-word phrase"
607
+ expect "foo bar baz".camelCase() == "fooBarBaz"
608
+ expect "foo bar baz".snakeCase() == "foo_bar_baz"
609
+ expect "foo bar baz".kebabCase() == "foo-bar-baz"
610
+ expect "foo bar baz".startCase() == "Foo Bar Baz"
611
+
612
+ test "reverse reverses by character, not by raw byte"
613
+ expect "hello".reverse() == "olleh"
614
+
615
+ test "escape/unescape round-trip HTML-sensitive characters"
616
+ expect "<a href=\"x\">&'</a>".escape() == "&lt;a href=&quot;x&quot;&gt;&amp;&#39;&lt;/a&gt;"
617
+ expect "&lt;a href=&quot;x&quot;&gt;&amp;&#39;&lt;/a&gt;".unescape() == "<a href=\"x\">&'</a>"
libs/std/time.plum CHANGED
@@ -6,7 +6,7 @@ import std/str
6
6
  extern fun rawNowMillis() -> Int
7
7
 
8
8
  # A single point in time, stored as milliseconds since the Unix epoch.
9
- type Time(Stringable) =
9
+ type Time(ToStr) =
10
10
  value: Int
11
11
 
12
12
  fun toMillis(self) -> Int =
libs/std/uuid.plum CHANGED
@@ -5,7 +5,7 @@ import std/str
5
5
 
6
6
  # A UUID, stored as its canonical 36-character
7
7
  # `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx` text form.
8
- type Uuid(Stringable) =
8
+ type Uuid(ToStr) =
9
9
  value: Str
10
10
 
11
11
  fun toStr(self) -> Str =
plum-checker/src/lib.rs CHANGED
@@ -260,9 +260,111 @@ pub fn buildGlobalTables(source: &ast::Source) -> (TypeEnv, ClassEnv, MethodEnv,
260
260
  (global_env, classes, methods, enum_variants, enum_params)
261
261
  }
262
262
 
263
+ /// A `Type`'s name for comparison purposes only — deliberately ignores `.generics`
264
+ /// entirely (on both sides), so a trait's bare return/param type (`cause() ->
265
+ /// Option`, unable to name a concrete payload since a trait has no instance to
266
+ /// infer one from) is treated as compatible with ANY instantiation an implementer
267
+ /// declares (`cause(self) -> Option[JsonParseError]`) — a real but deliberately
268
+ /// coarse check (arity + base type names), not full structural/generic equality.
269
+ fn paramTypeCompareName(pt: &ast::ParamType) -> Option<&str> {
270
+ match pt {
271
+ ast::ParamType::Type(t) => Some(t.name.as_str()),
272
+ ast::ParamType::Variadic(t) => Some(t.name.as_str()),
273
+ // A function-value param type has no single "name" to compare — never
274
+ // matches a trait method's plain `Type` param either way, but no real
275
+ // trait in `libs/std` declares one today, so this never actually fires.
276
+ ast::ParamType::Fn(_, _) => None,
277
+ }
278
+ }
279
+
280
+ /// Verifies every `type X(TraitName, ...) = ...` claim against `TraitName`'s own
281
+ /// declared methods — until now, `implements` was pure documentation with zero
282
+ /// enforcement (a class could claim any trait, real or not, and never define a
283
+ /// single one of its methods, with nothing ever catching it). A `TraitName` that
284
+ /// doesn't resolve to any declared `trait` in this source (e.g. `Comparable`,
285
+ /// `Readable`, `Writable` — used across `libs/std` but never actually declared
286
+ /// anywhere) is silently SKIPPED rather than an error: those names are still
287
+ /// purely aspirational today, and erroring on them would break every existing
288
+ /// type that names one, for reasons unrelated to whether it actually implements
289
+ /// its REAL trait claims. Runs on the pre-monomorphization source deliberately —
290
+ /// a generic class's own methods (and a real trait's own declared signatures,
291
+ /// which are never specialized at all) read naturally here, before mangling
292
+ /// folds a method's concrete return/param types into new, unrelated-looking
293
+ /// names (`Option[JsonParseError]` -> `Option$JsonParseError`).
294
+ fn checkTraitConformance(source: &ast::Source) -> Vec<CheckError> {
295
+ let mut errors = Vec::new();
296
+ let traits: BTreeMap<&str, &ast::Trait> = source.items.iter()
297
+ .filter_map(|i| match i { ast::Item::Trait(t) => Some((t.name.as_str(), t)), _ => None })
298
+ .collect();
299
+ let methods_by_receiver: BTreeMap<(&str, &str), &ast::Fn> = source.items.iter()
300
+ .filter_map(|i| match i {
301
+ ast::Item::Fn(f) => f.type_param.as_deref().map(|recv| ((recv, f.name.as_str()), f)),
302
+ _ => None,
303
+ })
304
+ .collect();
305
+
306
+ for item in &source.items {
307
+ let ast::Item::Class(c) = item else { continue };
308
+ for trait_name in &c.implements {
309
+ let Some(tr) = traits.get(trait_name.as_str()) else { continue };
310
+ for tm in &tr.methods {
311
+ let Some(f) = methods_by_receiver.get(&(c.name.as_str(), tm.name.as_str())) else {
312
+ errors.push(CheckError {
313
+ message: format!("class '{}' claims to implement trait '{}' but is missing method '{}'", c.name, trait_name, tm.name),
314
+ });
315
+ continue;
316
+ };
317
+ if f.params.len() != tm.params.len() {
318
+ errors.push(CheckError {
319
+ message: format!(
320
+ "class '{}' method '{}' (implementing trait '{}'): expected {} param(s), got {}",
321
+ c.name, tm.name, trait_name, tm.params.len(), f.params.len()
322
+ ),
323
+ });
324
+ continue;
325
+ }
326
+ for (i, (fp, tp)) in f.params.iter().zip(tm.params.iter()).enumerate() {
327
+ let (actual, expected) = (paramTypeCompareName(&fp.ty), paramTypeCompareName(&tp.ty));
328
+ if actual != expected {
329
+ errors.push(CheckError {
330
+ message: format!(
331
+ "class '{}' method '{}' (implementing trait '{}'): param {} ('{}'): expected type '{}', got '{}'",
332
+ c.name, tm.name, trait_name, i, tp.name,
333
+ expected.unwrap_or("<fn>"), actual.unwrap_or("<fn>")
334
+ ),
335
+ });
336
+ }
337
+ }
338
+ match (&f.returns, &tm.returns) {
339
+ (Some(ft), Some(tt)) if ft.name != tt.name => {
340
+ errors.push(CheckError {
341
+ message: format!(
342
+ "class '{}' method '{}' (implementing trait '{}'): expected return type '{}', got '{}'",
343
+ c.name, tm.name, trait_name, tt.name, ft.name
344
+ ),
345
+ });
346
+ }
347
+ (None, Some(tt)) => {
348
+ errors.push(CheckError {
349
+ message: format!(
350
+ "class '{}' method '{}' (implementing trait '{}'): expected return type '{}', got none",
351
+ c.name, tm.name, trait_name, tt.name
352
+ ),
353
+ });
354
+ }
355
+ _ => {}
356
+ }
357
+ }
358
+ }
359
+ }
360
+ errors
361
+ }
362
+
263
363
  pub fn checkSource(source: &ast::Source) -> CheckResult<()> {
364
+ // Runs against the ORIGINAL (pre-monomorphization) source, deliberately —
365
+ // see `checkTraitConformance`'s own doc comment for why.
366
+ let mut errors: Vec<CheckError> = checkTraitConformance(source);
264
367
  let source = monomorphize::monomorphizeSource(source).map_err(|e| vec![CheckError { message: e }])?;
265
- let mut errors: Vec<CheckError> = Vec::new();
266
368
  let (global_env, classes, methods, enum_variants, enum_params) = buildGlobalTables(&source);
267
369
  let min_required = buildMinRequiredArgs(&source);
268
370
  let ctx = CheckCtx { classes: &classes, methods: &methods, enum_variants: &enum_variants, enum_params: &enum_params, min_required: &min_required };
@@ -1099,7 +1201,17 @@ pub fn inferExpr(expr: &ast::Expr, env: &TypeEnv, ctx: &CheckCtx) -> Result<Plum
1099
1201
  None => Ok(PlumType::TVar("_".to_string())),
1100
1202
  },
1101
1203
  },
1204
+ // An unresolved generic method return (e.g. `Result[T, E].unwrap()`'s
1205
+ // bare `T`, which this checker's `PlumType` erases entirely — see
1206
+ // `types.rs`'s `TNamed` having no type-argument slot) reaches here as
1207
+ // a plain `TVar`, not a real "wrong type". Field access on it is
1208
+ // "unmodeled" the same way an unknown enum's fields already are just
1209
+ // above (`ctx.enum_params.get` returning `None`) — allow it and let
1210
+ // codegen (which DOES track concrete monomorphized types) catch a
1211
+ // genuine mismatch. Only a definitely-wrong concrete type (`Int`,
1212
+ // `Str`, ...) still hard-errors here.
1213
+ PlumType::TVar(_) => Ok(PlumType::TVar("_".to_string())),
1102
- _ => Err(format!("cannot access field '{}' on non-class type {}", field_name, obj_ty)),
1214
+ other => Err(format!("cannot access field '{}' on non-class type {}", field_name, other)),
1103
1215
  },
1104
1216
  ast::AttrKind::Method(call) => match methodReceiverName(&obj_ty) {
1105
1217
  Some(class_name) => match ctx.methods.get(&(class_name.clone(), call.name.clone())) {
plum-checker/src/monomorphize.rs CHANGED
@@ -1622,12 +1622,28 @@ impl<'a> Monomorphizer<'a> {
1622
1622
  fn fnBareGenericRefs(&self, f: &ast::Fn) -> Vec<String> {
1623
1623
  let mut names: Vec<String> = Vec::new();
1624
1624
  for p in &f.params {
1625
- let n = match &p.ty {
1625
+ let t = match &p.ty {
1626
- ast::ParamType::Type(t) => &t.name,
1626
+ ast::ParamType::Type(t) => t,
1627
- ast::ParamType::Variadic(t) => &t.name,
1627
+ ast::ParamType::Variadic(t) => t,
1628
1628
  // TODO: fn-value params don't yet participate in bare-generic resolution.
1629
1629
  ast::ParamType::Fn(_, _) => continue,
1630
1630
  };
1631
+ // A param already fully instantiated with concrete type arguments
1632
+ // (`headers: Map[Str, Str]`) is NOT a bare reference to the generic
1633
+ // template — only the truly bare spelling (`headers: Map`, no `[...]`
1634
+ // at all) needs this function's own per-call-site specialization.
1635
+ // Without this check, ANY function taking an already-concrete
1636
+ // generic-typed param (however unrelated to its own logic) was
1637
+ // wrongly routed through `fns_bare_generic`'s worklist instead of
1638
+ // the ordinary per-item pass, silently dropping it from `m.produced`
1639
+ // under its original name — the caller's own inferred return type
1640
+ // (via `fn_return_generic_enum`, which doesn't consult this
1641
+ // classification at all) still looked correct, masking the missing
1642
+ // function until codegen.
1643
+ if !t.generics.is_empty() {
1644
+ continue;
1645
+ }
1646
+ let n = &t.name;
1631
1647
  if (self.classes_generic.contains_key(n.as_str()) || self.enums_generic_by_name.contains_key(n.as_str()))
1632
1648
  && !names.iter().any(|x| x == n)
1633
1649
  {
plum-checker/tests/checker_tests.rs CHANGED
@@ -906,3 +906,129 @@ fun bad(nums: ...Int) -> Int =
906
906
  let source = parse(src);
907
907
  assert!(checkSource(&source).is_err());
908
908
  }
909
+
910
+ #[test]
911
+ fn classImplementingTraitWithMatchingMethodPasses() {
912
+ let src = "\
913
+ trait Greeter =
914
+ greet(name: Str) -> Str
915
+
916
+ type Robot(Greeter) =
917
+ id: Int
918
+
919
+ fun greet(self, name: Str) -> Str =
920
+ \"beep {name}\"
921
+ ";
922
+ let source = parse(src);
923
+ assert!(checkSource(&source).is_ok(), "expected Ok, got: {:?}", checkSource(&source));
924
+ }
925
+
926
+ #[test]
927
+ fn classClaimingTraitButMissingMethodIsError() {
928
+ let src = "\
929
+ trait Greeter =
930
+ greet(name: Str) -> Str
931
+
932
+ type Robot(Greeter) =
933
+ id: Int
934
+ ";
935
+ let source = parse(src);
936
+ let result = checkSource(&source);
937
+ assert!(result.is_err());
938
+ let errs = result.unwrap_err();
939
+ assert!(errs.iter().any(|e| e.message.contains("missing method 'greet'")), "got: {:?}", errs);
940
+ }
941
+
942
+ #[test]
943
+ fn classClaimingTraitWithWrongParamCountIsError() {
944
+ let src = "\
945
+ trait Greeter =
946
+ greet(name: Str) -> Str
947
+
948
+ type Robot(Greeter) =
949
+ id: Int
950
+
951
+ fun greet(self) -> Str =
952
+ \"beep\"
953
+ ";
954
+ let source = parse(src);
955
+ let result = checkSource(&source);
956
+ assert!(result.is_err());
957
+ let errs = result.unwrap_err();
958
+ assert!(errs.iter().any(|e| e.message.contains("expected 1 param(s), got 0")), "got: {:?}", errs);
959
+ }
960
+
961
+ #[test]
962
+ fn classClaimingTraitWithWrongParamTypeIsError() {
963
+ let src = "\
964
+ trait Greeter =
965
+ greet(name: Str) -> Str
966
+
967
+ type Robot(Greeter) =
968
+ id: Int
969
+
970
+ fun greet(self, name: Int) -> Str =
971
+ \"beep\"
972
+ ";
973
+ let source = parse(src);
974
+ let result = checkSource(&source);
975
+ assert!(result.is_err());
976
+ let errs = result.unwrap_err();
977
+ assert!(errs.iter().any(|e| e.message.contains("expected type 'Str', got 'Int'")), "got: {:?}", errs);
978
+ }
979
+
980
+ #[test]
981
+ fn classClaimingTraitWithWrongReturnTypeIsError() {
982
+ let src = "\
983
+ trait Greeter =
984
+ greet(name: Str) -> Str
985
+
986
+ type Robot(Greeter) =
987
+ id: Int
988
+
989
+ fun greet(self, name: Str) -> Int =
990
+ 0
991
+ ";
992
+ let source = parse(src);
993
+ let result = checkSource(&source);
994
+ assert!(result.is_err());
995
+ let errs = result.unwrap_err();
996
+ assert!(errs.iter().any(|e| e.message.contains("expected return type 'Str', got 'Int'")), "got: {:?}", errs);
997
+ }
998
+
999
+ #[test]
1000
+ fn classClaimingUndeclaredTraitNameIsNotEnforced() {
1001
+ // `Comparable`/`Readable`/`Writable`-style names used across `libs/std` but
1002
+ // never declared as a real `trait` anywhere — silently unenforced, not an
1003
+ // error, since there is nothing real to check it against.
1004
+ let src = "\
1005
+ type Robot(NotARealTrait) =
1006
+ id: Int
1007
+ ";
1008
+ let source = parse(src);
1009
+ assert!(checkSource(&source).is_ok(), "expected Ok, got: {:?}", checkSource(&source));
1010
+ }
1011
+
1012
+ #[test]
1013
+ fn classImplementingTraitWithGenericReturnTypeMismatchIsPermitted() {
1014
+ // A trait method's own return type can never name a concrete payload (it
1015
+ // has no instance to infer one from) — an implementer instantiating that
1016
+ // same generic type with a concrete arg is still a match (base type name
1017
+ // only; see `checkTraitConformance`'s doc comment).
1018
+ let src = "\
1019
+ enum Option[T] =
1020
+ | Some[T]
1021
+ | None
1022
+
1023
+ trait Err =
1024
+ cause() -> Option
1025
+
1026
+ type MyErr(Err) =
1027
+ pos: Int
1028
+
1029
+ fun cause(self) -> Option[MyErr] =
1030
+ None
1031
+ ";
1032
+ let source = parse(src);
1033
+ assert!(checkSource(&source).is_ok(), "expected Ok, got: {:?}", checkSource(&source));
1034
+ }
plum-cli/Cargo.toml CHANGED
@@ -17,3 +17,4 @@ tree-sitter = "0.26"
17
17
  tree-sitter-plum = { path = "../tooling/tree-sitter-plum" }
18
18
  toml_edit = "0.22"
19
19
  wasmtime = "47"
20
+ ureq = "2.10"
plum-cli/src/main.rs CHANGED
@@ -389,11 +389,59 @@ fn hostImports(store: &mut wasmtime::Store<()>, module: &wasmtime::Module) -> Re
389
389
  Ok(())
390
390
  })))
391
391
  }
392
+ ("plum", "rawHttpRequest") => {
393
+ let func_ty = imp.ty().func().cloned()
394
+ .ok_or_else(|| anyhow::anyhow!("plum::rawHttpRequest import must be a function"))?;
395
+ Ok(wasmtime::Extern::Func(wasmtime::Func::new(&mut *store, func_ty.clone(), move |mut caller, params, results| {
396
+ let method = readStrArg(&mut caller, &params[0])?;
397
+ let url = readStrArg(&mut caller, &params[1])?;
398
+ let headers = readStrArg(&mut caller, &params[2])?;
399
+ let body = readStrArg(&mut caller, &params[3])?;
400
+ let raw = performHttpRequest(&method, &url, &headers, &body);
401
+ results[0] = wasmtime::Val::AnyRef(Some(makeStrResult(&mut caller, &func_ty, raw.as_bytes())?));
402
+ Ok(())
403
+ })))
404
+ }
392
405
  (m, n) => anyhow::bail!("unsupported host import {m}::{n}"),
393
406
  }
394
407
  }).collect()
395
408
  }
396
409
 
410
+ /// Performs one blocking HTTP round trip for `plum::rawHttpRequest` and packs
411
+ /// the outcome into the wire format `libs/std/http.plum`'s `request` expects
412
+ /// (see that extern's doc comment): `"1\x01<status>\x01<headers>\x00<body>"`
413
+ /// on success, `"0\x01\x01<message>\x00"` for a transport-level failure. A
414
+ /// non-2xx HTTP status (404, 500, ...) is NOT a failure here — it's still a
415
+ /// complete response, so it goes through the success branch with its own
416
+ /// status code.
417
+ fn performHttpRequest(method: &str, url: &str, headers: &str, body: &str) -> String {
418
+ let agent = ureq::Agent::new();
419
+ let mut req = agent.request(method, url);
420
+ for line in headers.split('\n') {
421
+ if let Some((k, v)) = line.split_once(": ") {
422
+ req = req.set(k, v);
423
+ }
424
+ }
425
+ let result = if body.is_empty() { req.call() } else { req.send_string(body) };
426
+ match result {
427
+ Ok(resp) | Err(ureq::Error::Status(_, resp)) => {
428
+ let status = resp.status();
429
+ let mut header_lines = String::new();
430
+ for name in resp.headers_names() {
431
+ if let Some(v) = resp.header(&name) {
432
+ if !header_lines.is_empty() {
433
+ header_lines.push('\n');
434
+ }
435
+ header_lines.push_str(&format!("{name}: {v}"));
436
+ }
437
+ }
438
+ let body_text = resp.into_string().unwrap_or_default();
439
+ format!("1\x01{status}\x01{header_lines}\x00{body_text}")
440
+ }
441
+ Err(e) => format!("0\x01\x01{e}\x00"),
442
+ }
443
+ }
444
+
397
445
  /// A pseudo-random `i64` seeded from the wall clock — `xorshift64*`, cheap and
398
446
  /// dependency-free (no `rand` crate in this workspace). Not cryptographically
399
447
  /// secure; fine for `Int.random`/`List.shuffle`/`Uuid.v4`, none of which need
plum-runtime/Cargo.lock CHANGED
@@ -11,6 +11,12 @@ dependencies = [
11
11
  "gimli",
12
12
  ]
13
13
 
14
+ [[package]]
15
+ name = "adler2"
16
+ version = "2.0.1"
17
+ source = "registry+https://github.com/rust-lang/crates.io-index"
18
+ checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
19
+
14
20
  [[package]]
15
21
  name = "allocator-api2"
16
22
  version = "0.2.21"
@@ -345,6 +351,17 @@ dependencies = [
345
351
  "winapi",
346
352
  ]
347
353
 
354
+ [[package]]
355
+ name = "displaydoc"
356
+ version = "0.2.7"
357
+ source = "registry+https://github.com/rust-lang/crates.io-index"
358
+ checksum = "c6232dd377dcc64799954cbd3a9bb882e9cdc1308ccd87b1c098f1fb2eaf82a8"
359
+ dependencies = [
360
+ "proc-macro2",
361
+ "quote",
362
+ "syn 3.0.3",
363
+ ]
364
+
348
365
  [[package]]
349
366
  name = "either"
350
367
  version = "1.17.0"
@@ -385,7 +402,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
385
402
  checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
386
403
  dependencies = [
387
404
  "libc",
388
- "windows-sys",
405
+ "windows-sys 0.61.2",
389
406
  ]
390
407
 
391
408
  [[package]]
@@ -406,6 +423,17 @@ version = "0.4.2"
406
423
  source = "registry+https://github.com/rust-lang/crates.io-index"
407
424
  checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80"
408
425
 
426
+ [[package]]
427
+ name = "flate2"
428
+ version = "1.1.10"
429
+ source = "registry+https://github.com/rust-lang/crates.io-index"
430
+ checksum = "6e634e2e0ebac1ee034020da1ca582e17ffe4e0f5e985823721e168928136dcb"
431
+ dependencies = [
432
+ "crc32fast",
433
+ "miniz_oxide",
434
+ "zlib-rs",
435
+ ]
436
+
409
437
  [[package]]
410
438
  name = "fnv"
411
439
  version = "1.0.7"
@@ -418,6 +446,15 @@ version = "0.2.0"
418
446
  source = "registry+https://github.com/rust-lang/crates.io-index"
419
447
  checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb"
420
448
 
449
+ [[package]]
450
+ name = "form_urlencoded"
451
+ version = "1.2.2"
452
+ source = "registry+https://github.com/rust-lang/crates.io-index"
453
+ checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf"
454
+ dependencies = [
455
+ "percent-encoding",
456
+ ]
457
+
421
458
  [[package]]
422
459
  name = "futures"
423
460
  version = "0.3.33"
@@ -563,12 +600,116 @@ version = "0.5.0"
563
600
  source = "registry+https://github.com/rust-lang/crates.io-index"
564
601
  checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
565
602
 
603
+ [[package]]
604
+ name = "icu_collections"
605
+ version = "2.3.0"
606
+ source = "registry+https://github.com/rust-lang/crates.io-index"
607
+ checksum = "fa68d21081c4a05d5a901a1c62add574c77048b6a1c67be3b50ce0b60d4ca513"
608
+ dependencies = [
609
+ "displaydoc",
610
+ "potential_utf",
611
+ "utf8_iter",
612
+ "yoke",
613
+ "zerofrom",
614
+ "zerovec",
615
+ ]
616
+
617
+ [[package]]
618
+ name = "icu_locale_core"
619
+ version = "2.3.0"
620
+ source = "registry+https://github.com/rust-lang/crates.io-index"
621
+ checksum = "d56e28588da92eee5c3201a6eff33fabdd49b62269c8938d4ff050ce4d900deb"
622
+ dependencies = [
623
+ "displaydoc",
624
+ "litemap",
625
+ "tinystr",
626
+ "writeable",
627
+ "zerovec",
628
+ ]
629
+
630
+ [[package]]
631
+ name = "icu_normalizer"
632
+ version = "2.3.0"
633
+ source = "registry+https://github.com/rust-lang/crates.io-index"
634
+ checksum = "12f9cf5f235641ed274641dd81c3f28d870e276763d0797aeeab72317b1c646f"
635
+ dependencies = [
636
+ "icu_collections",
637
+ "icu_normalizer_data",
638
+ "icu_properties",
639
+ "icu_provider",
640
+ "smallvec",
641
+ "zerovec",
642
+ ]
643
+
644
+ [[package]]
645
+ name = "icu_normalizer_data"
646
+ version = "2.3.0"
647
+ source = "registry+https://github.com/rust-lang/crates.io-index"
648
+ checksum = "1563da1ed3e0b3bf3d74c9b85917ac9c56464d2f57242270c09c9e752f8021a0"
649
+
650
+ [[package]]
651
+ name = "icu_properties"
652
+ version = "2.3.0"
653
+ source = "registry+https://github.com/rust-lang/crates.io-index"
654
+ checksum = "7e7ca276ad3145661a65914e6daf131ca5120cd3dcee8f8f3214b8875184a148"
655
+ dependencies = [
656
+ "displaydoc",
657
+ "icu_collections",
658
+ "icu_locale_core",
659
+ "icu_properties_data",
660
+ "icu_provider",
661
+ "zerotrie",
662
+ "zerovec",
663
+ ]
664
+
665
+ [[package]]
666
+ name = "icu_properties_data"
667
+ version = "2.3.0"
668
+ source = "registry+https://github.com/rust-lang/crates.io-index"
669
+ checksum = "e590f038c1464a96894fd6d10127e90a8be4509f56ff7ecef851b15cee0b7caa"
670
+
671
+ [[package]]
672
+ name = "icu_provider"
673
+ version = "2.3.1"
674
+ source = "registry+https://github.com/rust-lang/crates.io-index"
675
+ checksum = "d27bbb9d3abbefac45d55f647c9de1d44aafcd1186eb91879afef17c396c3e73"
676
+ dependencies = [
677
+ "displaydoc",
678
+ "icu_locale_core",
679
+ "writeable",
680
+ "yoke",
681
+ "zerofrom",
682
+ "zerotrie",
683
+ "zerovec",
684
+ ]
685
+
566
686
  [[package]]
567
687
  name = "id-arena"
568
688
  version = "2.3.0"
569
689
  source = "registry+https://github.com/rust-lang/crates.io-index"
570
690
  checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954"
571
691
 
692
+ [[package]]
693
+ name = "idna"
694
+ version = "1.1.0"
695
+ source = "registry+https://github.com/rust-lang/crates.io-index"
696
+ checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de"
697
+ dependencies = [
698
+ "idna_adapter",
699
+ "smallvec",
700
+ "utf8_iter",
701
+ ]
702
+
703
+ [[package]]
704
+ name = "idna_adapter"
705
+ version = "1.2.2"
706
+ source = "registry+https://github.com/rust-lang/crates.io-index"
707
+ checksum = "cb68373c0d6620ef8105e855e7745e18b0d00d3bdb07fb532e434244cdb9a714"
708
+ dependencies = [
709
+ "icu_normalizer",
710
+ "icu_properties",
711
+ ]
712
+
572
713
  [[package]]
573
714
  name = "indexmap"
574
715
  version = "2.14.0"
@@ -670,6 +811,12 @@ version = "0.12.1"
670
811
  source = "registry+https://github.com/rust-lang/crates.io-index"
671
812
  checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53"
672
813
 
814
+ [[package]]
815
+ name = "litemap"
816
+ version = "0.8.3"
817
+ source = "registry+https://github.com/rust-lang/crates.io-index"
818
+ checksum = "47d9d19d1d6efa0109d2f65ff4c85cddd50bd572e5a00127ab10987290bcefae"
819
+
673
820
  [[package]]
674
821
  name = "log"
675
822
  version = "0.4.33"
@@ -697,6 +844,16 @@ dependencies = [
697
844
  "rustix",
698
845
  ]
699
846
 
847
+ [[package]]
848
+ name = "miniz_oxide"
849
+ version = "0.9.1"
850
+ source = "registry+https://github.com/rust-lang/crates.io-index"
851
+ checksum = "b63fbc4a50860e98e7b2aa7804ded1db5cbc3aff9193adaff57a6931bf7c4b4c"
852
+ dependencies = [
853
+ "adler2",
854
+ "simd-adler32",
855
+ ]
856
+
700
857
  [[package]]
701
858
  name = "object"
702
859
  version = "0.39.1"
@@ -715,6 +872,12 @@ version = "1.21.4"
715
872
  source = "registry+https://github.com/rust-lang/crates.io-index"
716
873
  checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
717
874
 
875
+ [[package]]
876
+ name = "percent-encoding"
877
+ version = "2.3.2"
878
+ source = "registry+https://github.com/rust-lang/crates.io-index"
879
+ checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220"
880
+
718
881
  [[package]]
719
882
  name = "petgraph"
720
883
  version = "0.6.5"
@@ -741,6 +904,7 @@ checksum = "19f132c84eca552bf34cab8ec81f1c1dcc229b811638f9d283dceabe58c5569e"
741
904
  name = "plum-runtime"
742
905
  version = "0.1.0"
743
906
  dependencies = [
907
+ "ureq",
744
908
  "wasmtime",
745
909
  ]
746
910
 
@@ -756,6 +920,15 @@ dependencies = [
756
920
  "serde",
757
921
  ]
758
922
 
923
+ [[package]]
924
+ name = "potential_utf"
925
+ version = "0.1.6"
926
+ source = "registry+https://github.com/rust-lang/crates.io-index"
927
+ checksum = "d83eb9bc6d8e5cf568e7a1101d60ee05e81ed50ea106026f3d18deeb046d7661"
928
+ dependencies = [
929
+ "zerovec",
930
+ ]
931
+
759
932
  [[package]]
760
933
  name = "proc-macro2"
761
934
  version = "1.0.107"
@@ -849,6 +1022,20 @@ dependencies = [
849
1022
  "smallvec",
850
1023
  ]
851
1024
 
1025
+ [[package]]
1026
+ name = "ring"
1027
+ version = "0.17.14"
1028
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1029
+ checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7"
1030
+ dependencies = [
1031
+ "cc",
1032
+ "cfg-if",
1033
+ "getrandom 0.2.17",
1034
+ "libc",
1035
+ "untrusted",
1036
+ "windows-sys 0.52.0",
1037
+ ]
1038
+
852
1039
  [[package]]
853
1040
  name = "rustc-demangle"
854
1041
  version = "0.1.28"
@@ -871,7 +1058,42 @@ dependencies = [
871
1058
  "errno",
872
1059
  "libc",
873
1060
  "linux-raw-sys",
874
- "windows-sys",
1061
+ "windows-sys 0.61.2",
1062
+ ]
1063
+
1064
+ [[package]]
1065
+ name = "rustls"
1066
+ version = "0.23.43"
1067
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1068
+ checksum = "0283386ce02abc0151e1761d08802dfe86c173b0b494af5cbc086574e453da06"
1069
+ dependencies = [
1070
+ "log",
1071
+ "once_cell",
1072
+ "ring",
1073
+ "rustls-pki-types",
1074
+ "rustls-webpki",
1075
+ "subtle",
1076
+ "zeroize",
1077
+ ]
1078
+
1079
+ [[package]]
1080
+ name = "rustls-pki-types"
1081
+ version = "1.15.1"
1082
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1083
+ checksum = "2f4925028c7eb5d1fcdaf196971378ed9d2c1c4efc7dc5d011256f76c99c0a96"
1084
+ dependencies = [
1085
+ "zeroize",
1086
+ ]
1087
+
1088
+ [[package]]
1089
+ name = "rustls-webpki"
1090
+ version = "0.103.15"
1091
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1092
+ checksum = "f3c3cf1d8b1e7d4927e2d154c3fcb02979afb9939629c62cd9048d4f07b60ac2"
1093
+ dependencies = [
1094
+ "ring",
1095
+ "rustls-pki-types",
1096
+ "untrusted",
875
1097
  ]
876
1098
 
877
1099
  [[package]]
@@ -959,6 +1181,12 @@ version = "2.0.1"
959
1181
  source = "registry+https://github.com/rust-lang/crates.io-index"
960
1182
  checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
961
1183
 
1184
+ [[package]]
1185
+ name = "simd-adler32"
1186
+ version = "0.3.10"
1187
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1188
+ checksum = "3a219298ac11a56ea9a6d2120044824d6f01aeb034955e7af7bc16858527deea"
1189
+
962
1190
  [[package]]
963
1191
  name = "slab"
964
1192
  version = "0.4.12"
@@ -980,6 +1208,12 @@ version = "1.2.1"
980
1208
  source = "registry+https://github.com/rust-lang/crates.io-index"
981
1209
  checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596"
982
1210
 
1211
+ [[package]]
1212
+ name = "subtle"
1213
+ version = "2.6.1"
1214
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1215
+ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
1216
+
983
1217
  [[package]]
984
1218
  name = "syn"
985
1219
  version = "2.0.119"
@@ -1002,6 +1236,17 @@ dependencies = [
1002
1236
  "unicode-ident",
1003
1237
  ]
1004
1238
 
1239
+ [[package]]
1240
+ name = "synstructure"
1241
+ version = "0.13.2"
1242
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1243
+ checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2"
1244
+ dependencies = [
1245
+ "proc-macro2",
1246
+ "quote",
1247
+ "syn 2.0.119",
1248
+ ]
1249
+
1005
1250
  [[package]]
1006
1251
  name = "target-lexicon"
1007
1252
  version = "0.13.5"
@@ -1018,7 +1263,7 @@ dependencies = [
1018
1263
  "getrandom 0.4.3",
1019
1264
  "once_cell",
1020
1265
  "rustix",
1021
- "windows-sys",
1266
+ "windows-sys 0.61.2",
1022
1267
  ]
1023
1268
 
1024
1269
  [[package]]
@@ -1070,6 +1315,16 @@ dependencies = [
1070
1315
  "syn 3.0.3",
1071
1316
  ]
1072
1317
 
1318
+ [[package]]
1319
+ name = "tinystr"
1320
+ version = "0.8.4"
1321
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1322
+ checksum = "b1e27c91459209c2986af3dcf603a5a74a4368754ce37414f59acc971167f643"
1323
+ dependencies = [
1324
+ "displaydoc",
1325
+ "zerovec",
1326
+ ]
1327
+
1073
1328
  [[package]]
1074
1329
  name = "toml"
1075
1330
  version = "0.9.12+spec-1.1.0"
@@ -1127,6 +1382,46 @@ version = "0.2.2"
1127
1382
  source = "registry+https://github.com/rust-lang/crates.io-index"
1128
1383
  checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254"
1129
1384
 
1385
+ [[package]]
1386
+ name = "untrusted"
1387
+ version = "0.9.0"
1388
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1389
+ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1"
1390
+
1391
+ [[package]]
1392
+ name = "ureq"
1393
+ version = "2.12.1"
1394
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1395
+ checksum = "02d1a66277ed75f640d608235660df48c8e3c19f3b4edb6a263315626cc3c01d"
1396
+ dependencies = [
1397
+ "base64",
1398
+ "flate2",
1399
+ "log",
1400
+ "once_cell",
1401
+ "rustls",
1402
+ "rustls-pki-types",
1403
+ "url",
1404
+ "webpki-roots 0.26.11",
1405
+ ]
1406
+
1407
+ [[package]]
1408
+ name = "url"
1409
+ version = "2.5.8"
1410
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1411
+ checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed"
1412
+ dependencies = [
1413
+ "form_urlencoded",
1414
+ "idna",
1415
+ "percent-encoding",
1416
+ "serde",
1417
+ ]
1418
+
1419
+ [[package]]
1420
+ name = "utf8_iter"
1421
+ version = "1.0.4"
1422
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1423
+ checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
1424
+
1130
1425
  [[package]]
1131
1426
  name = "uuid"
1132
1427
  version = "1.24.0"
@@ -1315,7 +1610,7 @@ dependencies = [
1315
1610
  "wasmtime-internal-unwinder",
1316
1611
  "wasmtime-internal-versioned-export-macros",
1317
1612
  "wat",
1318
- "windows-sys",
1613
+ "windows-sys 0.61.2",
1319
1614
  "wit-parser",
1320
1615
  ]
1321
1616
 
@@ -1366,7 +1661,7 @@ dependencies = [
1366
1661
  "sha2",
1367
1662
  "toml",
1368
1663
  "wasmtime-environ",
1369
- "windows-sys",
1664
+ "windows-sys 0.61.2",
1370
1665
  "zstd",
1371
1666
  ]
1372
1667
 
@@ -1442,7 +1737,7 @@ dependencies = [
1442
1737
  "rustix",
1443
1738
  "wasmtime-environ",
1444
1739
  "wasmtime-internal-versioned-export-macros",
1445
- "windows-sys",
1740
+ "windows-sys 0.61.2",
1446
1741
  ]
1447
1742
 
1448
1743
  [[package]]
@@ -1466,7 +1761,7 @@ dependencies = [
1466
1761
  "cfg-if",
1467
1762
  "libc",
1468
1763
  "wasmtime-internal-core",
1469
- "windows-sys",
1764
+ "windows-sys 0.61.2",
1470
1765
  ]
1471
1766
 
1472
1767
  [[package]]
@@ -1528,6 +1823,24 @@ dependencies = [
1528
1823
  "wast",
1529
1824
  ]
1530
1825
 
1826
+ [[package]]
1827
+ name = "webpki-roots"
1828
+ version = "0.26.11"
1829
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1830
+ checksum = "521bc38abb08001b01866da9f51eb7c5d647a19260e00054a8c7fd5f9e57f7a9"
1831
+ dependencies = [
1832
+ "webpki-roots 1.0.9",
1833
+ ]
1834
+
1835
+ [[package]]
1836
+ name = "webpki-roots"
1837
+ version = "1.0.9"
1838
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1839
+ checksum = "7dcd9d09a39985f5344844e66b0c530a33843579125f23e21e9f0f220850f22a"
1840
+ dependencies = [
1841
+ "rustls-pki-types",
1842
+ ]
1843
+
1531
1844
  [[package]]
1532
1845
  name = "winapi"
1533
1846
  version = "0.3.9"
@@ -1550,7 +1863,7 @@ version = "0.1.11"
1550
1863
  source = "registry+https://github.com/rust-lang/crates.io-index"
1551
1864
  checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
1552
1865
  dependencies = [
1553
- "windows-sys",
1866
+ "windows-sys 0.61.2",
1554
1867
  ]
1555
1868
 
1556
1869
  [[package]]
@@ -1565,6 +1878,15 @@ version = "0.2.1"
1565
1878
  source = "registry+https://github.com/rust-lang/crates.io-index"
1566
1879
  checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
1567
1880
 
1881
+ [[package]]
1882
+ name = "windows-sys"
1883
+ version = "0.52.0"
1884
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1885
+ checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
1886
+ dependencies = [
1887
+ "windows-targets",
1888
+ ]
1889
+
1568
1890
  [[package]]
1569
1891
  name = "windows-sys"
1570
1892
  version = "0.61.2"
@@ -1574,6 +1896,70 @@ dependencies = [
1574
1896
  "windows-link",
1575
1897
  ]
1576
1898
 
1899
+ [[package]]
1900
+ name = "windows-targets"
1901
+ version = "0.52.6"
1902
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1903
+ checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
1904
+ dependencies = [
1905
+ "windows_aarch64_gnullvm",
1906
+ "windows_aarch64_msvc",
1907
+ "windows_i686_gnu",
1908
+ "windows_i686_gnullvm",
1909
+ "windows_i686_msvc",
1910
+ "windows_x86_64_gnu",
1911
+ "windows_x86_64_gnullvm",
1912
+ "windows_x86_64_msvc",
1913
+ ]
1914
+
1915
+ [[package]]
1916
+ name = "windows_aarch64_gnullvm"
1917
+ version = "0.52.6"
1918
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1919
+ checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
1920
+
1921
+ [[package]]
1922
+ name = "windows_aarch64_msvc"
1923
+ version = "0.52.6"
1924
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1925
+ checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
1926
+
1927
+ [[package]]
1928
+ name = "windows_i686_gnu"
1929
+ version = "0.52.6"
1930
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1931
+ checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
1932
+
1933
+ [[package]]
1934
+ name = "windows_i686_gnullvm"
1935
+ version = "0.52.6"
1936
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1937
+ checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
1938
+
1939
+ [[package]]
1940
+ name = "windows_i686_msvc"
1941
+ version = "0.52.6"
1942
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1943
+ checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
1944
+
1945
+ [[package]]
1946
+ name = "windows_x86_64_gnu"
1947
+ version = "0.52.6"
1948
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1949
+ checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
1950
+
1951
+ [[package]]
1952
+ name = "windows_x86_64_gnullvm"
1953
+ version = "0.52.6"
1954
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1955
+ checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
1956
+
1957
+ [[package]]
1958
+ name = "windows_x86_64_msvc"
1959
+ version = "0.52.6"
1960
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1961
+ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
1962
+
1577
1963
  [[package]]
1578
1964
  name = "winnow"
1579
1965
  version = "0.7.15"
@@ -1605,6 +1991,101 @@ dependencies = [
1605
1991
  "wasmparser 0.252.0",
1606
1992
  ]
1607
1993
 
1994
+ [[package]]
1995
+ name = "writeable"
1996
+ version = "0.6.4"
1997
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1998
+ checksum = "3ad82d2a33cdc9674dc7465672f271e096168fcdbe0f799d9e6db8c5892679dc"
1999
+
2000
+ [[package]]
2001
+ name = "yoke"
2002
+ version = "0.8.3"
2003
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2004
+ checksum = "709fe23a0424b6a435d82152b1bd3fdfb0833487d5fa90d05d42762a9891fef5"
2005
+ dependencies = [
2006
+ "stable_deref_trait",
2007
+ "yoke-derive",
2008
+ "zerofrom",
2009
+ ]
2010
+
2011
+ [[package]]
2012
+ name = "yoke-derive"
2013
+ version = "0.8.2"
2014
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2015
+ checksum = "de844c262c8848816172cef550288e7dc6c7b7814b4ee56b3e1553f275f1858e"
2016
+ dependencies = [
2017
+ "proc-macro2",
2018
+ "quote",
2019
+ "syn 2.0.119",
2020
+ "synstructure",
2021
+ ]
2022
+
2023
+ [[package]]
2024
+ name = "zerofrom"
2025
+ version = "0.1.8"
2026
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2027
+ checksum = "0ec05a11813ea801ff6d75110ad09cd0824ddba17dfe17128ea0d5f68e6c5272"
2028
+ dependencies = [
2029
+ "zerofrom-derive",
2030
+ ]
2031
+
2032
+ [[package]]
2033
+ name = "zerofrom-derive"
2034
+ version = "0.1.7"
2035
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2036
+ checksum = "11532158c46691caf0f2593ea8358fed6bbf68a0315e80aae9bd41fbade684a1"
2037
+ dependencies = [
2038
+ "proc-macro2",
2039
+ "quote",
2040
+ "syn 2.0.119",
2041
+ "synstructure",
2042
+ ]
2043
+
2044
+ [[package]]
2045
+ name = "zeroize"
2046
+ version = "1.9.0"
2047
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2048
+ checksum = "e13c156562582aa81c60cb29407084cdb54c4164760106ab78e6c5b0858cf64e"
2049
+
2050
+ [[package]]
2051
+ name = "zerotrie"
2052
+ version = "0.2.5"
2053
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2054
+ checksum = "4ea269c3bd32f0a32c321907a2ae912ba6f4649bb0fc764a15627e99a7095a3f"
2055
+ dependencies = [
2056
+ "displaydoc",
2057
+ "yoke",
2058
+ "zerofrom",
2059
+ ]
2060
+
2061
+ [[package]]
2062
+ name = "zerovec"
2063
+ version = "0.11.8"
2064
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2065
+ checksum = "bb0464e17806c1d976d5cba29399c7f08e516e279e2ba493f63123b5fca67dd8"
2066
+ dependencies = [
2067
+ "yoke",
2068
+ "zerofrom",
2069
+ "zerovec-derive",
2070
+ ]
2071
+
2072
+ [[package]]
2073
+ name = "zerovec-derive"
2074
+ version = "0.11.6"
2075
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2076
+ checksum = "34df6fc39dbd26ddc9c10e6a2984476e13acce22e64e4487636ef494369225da"
2077
+ dependencies = [
2078
+ "proc-macro2",
2079
+ "quote",
2080
+ "syn 3.0.3",
2081
+ ]
2082
+
2083
+ [[package]]
2084
+ name = "zlib-rs"
2085
+ version = "0.6.7"
2086
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2087
+ checksum = "34b31d188d9d685a4f9c7b46d6e36631b07058d2cfe190267adce54dc230bf12"
2088
+
1608
2089
  [[package]]
1609
2090
  name = "zmij"
1610
2091
  version = "1.0.23"
plum-runtime/Cargo.toml CHANGED
@@ -11,6 +11,7 @@ path = "src/main.rs"
11
11
 
12
12
  [dependencies]
13
13
  wasmtime = "47"
14
+ ureq = "2.10"
14
15
 
15
16
  # Stand on its own rather than joining the parent directory's workspace: `plum
16
17
  # build` compiles this crate on demand with PLUM_WASM_PATH set, and it would
plum-runtime/src/main.rs CHANGED
@@ -193,11 +193,54 @@ fn hostImports(store: &mut wasmtime::Store<()>, module: &wasmtime::Module) -> Ve
193
193
  Ok(())
194
194
  }))
195
195
  }
196
+ ("plum", "rawHttpRequest") => {
197
+ let func_ty = imp.ty().func().cloned().expect("plum::rawHttpRequest import should be a function");
198
+ wasmtime::Extern::Func(wasmtime::Func::new(&mut *store, func_ty.clone(), move |mut caller, params, results| {
199
+ let method = readStrArg(&mut caller, &params[0])?;
200
+ let url = readStrArg(&mut caller, &params[1])?;
201
+ let headers = readStrArg(&mut caller, &params[2])?;
202
+ let body = readStrArg(&mut caller, &params[3])?;
203
+ let raw = performHttpRequest(&method, &url, &headers, &body);
204
+ results[0] = wasmtime::Val::AnyRef(Some(makeStrResult(&mut caller, &func_ty, raw.as_bytes())?));
205
+ Ok(())
206
+ }))
207
+ }
196
208
  (m, n) => panic!("unsupported host import {m}::{n}"),
197
209
  }
198
210
  }).collect()
199
211
  }
200
212
 
213
+ /// See the identical helper in `plum-cli/src/main.rs` — this crate is built
214
+ /// fresh per `plum build` invocation, not linked against `plum-cli`, so the
215
+ /// logic is duplicated rather than shared.
216
+ fn performHttpRequest(method: &str, url: &str, headers: &str, body: &str) -> String {
217
+ let agent = ureq::Agent::new();
218
+ let mut req = agent.request(method, url);
219
+ for line in headers.split('\n') {
220
+ if let Some((k, v)) = line.split_once(": ") {
221
+ req = req.set(k, v);
222
+ }
223
+ }
224
+ let result = if body.is_empty() { req.call() } else { req.send_string(body) };
225
+ match result {
226
+ Ok(resp) | Err(ureq::Error::Status(_, resp)) => {
227
+ let status = resp.status();
228
+ let mut header_lines = String::new();
229
+ for name in resp.headers_names() {
230
+ if let Some(v) = resp.header(&name) {
231
+ if !header_lines.is_empty() {
232
+ header_lines.push('\n');
233
+ }
234
+ header_lines.push_str(&format!("{name}: {v}"));
235
+ }
236
+ }
237
+ let body_text = resp.into_string().unwrap_or_default();
238
+ format!("1\x01{status}\x01{header_lines}\x00{body_text}")
239
+ }
240
+ Err(e) => format!("0\x01\x01{e}\x00"),
241
+ }
242
+ }
243
+
201
244
  /// See the identical helper in `plum-cli/src/main.rs` — this crate is built
202
245
  /// fresh per `plum build` invocation, not linked against `plum-cli`, so the
203
246
  /// logic is duplicated rather than shared.
test/sample.plum CHANGED
@@ -216,7 +216,7 @@ fun random() -> Float = # generate random number
216
216
  fun fromStr() -> Result(Int, Err) = # convert Str to Int
217
217
  Ok(0)
218
218
 
219
- type Int(Comparable, Stringable)
219
+ type Int(Comparable, ToStr)
220
220
 
221
221
  fun toFloat<Int>() -> Float = # convert Int to Float
222
222
  Float(self)
tooling/tree-sitter-plum/test/corpus/type.txt CHANGED
@@ -6,7 +6,7 @@ type Dog =
6
6
  name: Str
7
7
  age: B
8
8
 
9
- type Cat(Stringable) =
9
+ type Cat(ToStr) =
10
10
  name: Str
11
11
  age: Int
12
12
 
website/src/content/docs/declarations/enum.md CHANGED
@@ -6,7 +6,7 @@ description: These are basic types
6
6
  An Algebraic Data Type
7
7
 
8
8
  ```rs
9
- enum Ordering: Stringable {
9
+ enum Ordering: ToStr {
10
10
  LT
11
11
  EQ
12
12
  GT
website/src/content/docs/index.mdx CHANGED
@@ -55,11 +55,11 @@ fn toCelsius(f: float): float =
55
55
  fn addItems(items ...str) =
56
56
  list.add(items)
57
57
 
58
- trait Stringable where
58
+ trait ToStr where
59
59
  fn toStr(): str
60
60
 
61
61
  // `Cat is a speciecs of felidae
62
- struct Cat is Stringable, Equal, Comparable =
62
+ struct Cat is ToStr, Equal, Comparable =
63
63
  | name: str
64
64
  | age: int
65
65