@mintplayer/polyglot-target-csharp 0.9.7 → 0.9.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/polyglot-plugin.json +432 -66
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mintplayer/polyglot-target-csharp",
3
- "version": "0.9.7",
3
+ "version": "0.9.9",
4
4
  "description": "MintPlayer Polyglot C# / .NET target — a pure-JSON language plugin (spec + emission rules + capabilities + std bindings) for the polyglot transpiler.",
5
5
  "keywords": [
6
6
  "polyglot",
@@ -78,6 +78,10 @@
78
78
  "trueLit": "true",
79
79
  "falseLit": "false",
80
80
  "nullLit": "null",
81
+ "constArrayOpen": "new[] {",
82
+ "constArrayClose": "}",
83
+ "linksWithoutImports": true,
84
+ "forbidsShadowedLocals": true,
81
85
  "escapes": {
82
86
  "interp": {
83
87
  "\"": "\\\"",
@@ -622,6 +626,20 @@
622
626
  ")"
623
627
  ]
624
628
  },
629
+ "IsTest": {
630
+ "tmpl": [
631
+ { "emitChild": "node.operand", "side": "recv" },
632
+ " is ",
633
+ { "type": "node.testType" }
634
+ ]
635
+ },
636
+ "AsCast": {
637
+ "tmpl": [
638
+ { "emitChild": "node.operand", "side": "recv" },
639
+ " as ",
640
+ { "type": "node.castType" }
641
+ ]
642
+ },
625
643
  "Unary": {
626
644
  "tmpl": [
627
645
  {
@@ -1139,6 +1157,26 @@
1139
1157
  },
1140
1158
  "csParam": {
1141
1159
  "tmpl": [
1160
+ {
1161
+ "case": {
1162
+ "when": [
1163
+ [
1164
+ {
1165
+ "has": "item.attrInline"
1166
+ },
1167
+ {
1168
+ "tmpl": [
1169
+ {
1170
+ "get": "item.attrInline"
1171
+ },
1172
+ " "
1173
+ ]
1174
+ }
1175
+ ]
1176
+ ],
1177
+ "else": ""
1178
+ }
1179
+ },
1142
1180
  {
1143
1181
  "type": "item.type"
1144
1182
  },
@@ -1389,9 +1427,18 @@
1389
1427
  "line": {
1390
1428
  "tmpl": [
1391
1429
  "public ",
1392
- { "type": "decl.returnType" },
1430
+ {
1431
+ "type": "decl.returnType"
1432
+ },
1393
1433
  " ",
1394
- { "fn": "ident", "args": [ { "get": "decl.name" } ] },
1434
+ {
1435
+ "fn": "ident",
1436
+ "args": [
1437
+ {
1438
+ "get": "decl.name"
1439
+ }
1440
+ ]
1441
+ },
1395
1442
  " {"
1396
1443
  ]
1397
1444
  }
@@ -1402,27 +1449,59 @@
1402
1449
  "case": {
1403
1450
  "when": [
1404
1451
  [
1405
- { "eq": [ "decl.exprBodied", "true" ] },
1406
- { "line": { "tmpl": [ "get => ", { "emit": "decl.exprBody" }, ";" ] } }
1452
+ {
1453
+ "eq": [
1454
+ "decl.exprBodied",
1455
+ "true"
1456
+ ]
1457
+ },
1458
+ {
1459
+ "line": {
1460
+ "tmpl": [
1461
+ "get => ",
1462
+ {
1463
+ "emit": "decl.exprBody"
1464
+ },
1465
+ ";"
1466
+ ]
1467
+ }
1468
+ }
1407
1469
  ]
1408
1470
  ],
1409
1471
  "else": {
1410
1472
  "seq": [
1411
- { "line": "get {" },
1412
- { "indent": [ { "stmts": "decl.body" } ] },
1413
- { "line": "}" }
1473
+ {
1474
+ "line": "get {"
1475
+ },
1476
+ {
1477
+ "indent": [
1478
+ {
1479
+ "stmts": "decl.body"
1480
+ }
1481
+ ]
1482
+ },
1483
+ {
1484
+ "line": "}"
1485
+ }
1414
1486
  ]
1415
1487
  }
1416
1488
  }
1417
1489
  },
1418
- { "line": "set {" },
1490
+ {
1491
+ "line": "set {"
1492
+ },
1419
1493
  {
1420
1494
  "indent": [
1421
1495
  {
1422
1496
  "case": {
1423
1497
  "when": [
1424
1498
  [
1425
- { "eq": [ "decl.propSetterParam", "value" ] },
1499
+ {
1500
+ "eq": [
1501
+ "decl.propSetterParam",
1502
+ "value"
1503
+ ]
1504
+ },
1426
1505
  ""
1427
1506
  ]
1428
1507
  ],
@@ -1430,34 +1509,63 @@
1430
1509
  "line": {
1431
1510
  "tmpl": [
1432
1511
  "var ",
1433
- { "fn": "ident", "args": [ { "get": "decl.propSetterParam" } ] },
1512
+ {
1513
+ "fn": "ident",
1514
+ "args": [
1515
+ {
1516
+ "get": "decl.propSetterParam"
1517
+ }
1518
+ ]
1519
+ },
1434
1520
  " = value;"
1435
1521
  ]
1436
1522
  }
1437
1523
  }
1438
1524
  }
1439
1525
  },
1440
- { "stmts": "decl.propSetterBody" }
1526
+ {
1527
+ "stmts": "decl.propSetterBody"
1528
+ }
1441
1529
  ]
1442
1530
  },
1443
- { "line": "}" }
1531
+ {
1532
+ "line": "}"
1533
+ }
1444
1534
  ]
1445
1535
  },
1446
- { "line": "}" }
1536
+ {
1537
+ "line": "}"
1538
+ }
1447
1539
  ]
1448
1540
  }
1449
1541
  ],
1450
1542
  [
1451
- { "eq": [ "decl.exprBodied", "true" ] },
1543
+ {
1544
+ "eq": [
1545
+ "decl.exprBodied",
1546
+ "true"
1547
+ ]
1548
+ },
1452
1549
  {
1453
1550
  "line": {
1454
1551
  "tmpl": [
1455
1552
  "public ",
1456
- { "type": "decl.returnType" },
1553
+ {
1554
+ "type": "decl.returnType"
1555
+ },
1457
1556
  " ",
1458
- { "fn": "ident", "args": [ { "get": "decl.name" } ] },
1557
+ {
1558
+ "fn": "ident",
1559
+ "args": [
1560
+ {
1561
+ "get": "decl.name"
1562
+ }
1563
+ ]
1564
+ },
1459
1565
  " => ",
1460
- { "emit": "decl.exprBody" },
1566
+ {
1567
+ "emit": "decl.exprBody"
1568
+ },
1461
1569
  ";"
1462
1570
  ]
1463
1571
  }
@@ -1470,15 +1578,42 @@
1470
1578
  "line": {
1471
1579
  "tmpl": [
1472
1580
  "public ",
1473
- { "type": "decl.returnType" },
1581
+ {
1582
+ "type": "decl.returnType"
1583
+ },
1474
1584
  " ",
1475
- { "fn": "ident", "args": [ { "get": "decl.name" } ] },
1585
+ {
1586
+ "fn": "ident",
1587
+ "args": [
1588
+ {
1589
+ "get": "decl.name"
1590
+ }
1591
+ ]
1592
+ },
1476
1593
  " {"
1477
1594
  ]
1478
1595
  }
1479
1596
  },
1480
- { "indent": [ { "line": "get {" }, { "indent": [ { "stmts": "decl.body" } ] }, { "line": "}" } ] },
1481
- { "line": "}" }
1597
+ {
1598
+ "indent": [
1599
+ {
1600
+ "line": "get {"
1601
+ },
1602
+ {
1603
+ "indent": [
1604
+ {
1605
+ "stmts": "decl.body"
1606
+ }
1607
+ ]
1608
+ },
1609
+ {
1610
+ "line": "}"
1611
+ }
1612
+ ]
1613
+ },
1614
+ {
1615
+ "line": "}"
1616
+ }
1482
1617
  ]
1483
1618
  }
1484
1619
  }
@@ -1697,58 +1832,220 @@
1697
1832
  ]
1698
1833
  },
1699
1834
  {
1700
- "case": {
1701
- "when": [
1702
- [
1703
- {
1704
- "eq": [
1705
- "decl.exprBodied",
1706
- "true"
1835
+ "seq": [
1836
+ {
1837
+ "case": {
1838
+ "when": [
1839
+ [
1840
+ {
1841
+ "eq": [
1842
+ "decl.exprBodied",
1843
+ "true"
1844
+ ]
1845
+ },
1846
+ {
1847
+ "line": {
1848
+ "tmpl": [
1849
+ "public virtual bool Equals(",
1850
+ {
1851
+ "map": "decl.params",
1852
+ "sep": ", ",
1853
+ "item": {
1854
+ "call": "csParam"
1855
+ }
1856
+ },
1857
+ ") => ",
1858
+ {
1859
+ "emit": "decl.exprBody"
1860
+ },
1861
+ ";"
1862
+ ]
1863
+ }
1864
+ }
1707
1865
  ]
1708
- },
1709
- {
1710
- "line": {
1711
- "tmpl": [
1712
- "public virtual bool Equals(",
1713
- {
1714
- "map": "decl.params",
1715
- "sep": ", ",
1716
- "item": {
1717
- "call": "csParam"
1718
- }
1719
- },
1720
- ") => ",
1866
+ ],
1867
+ "else": {
1868
+ "block": {
1869
+ "head": {
1870
+ "tmpl": [
1871
+ "public virtual bool Equals(",
1872
+ {
1873
+ "map": "decl.params",
1874
+ "sep": ", ",
1875
+ "item": {
1876
+ "call": "csParam"
1877
+ }
1878
+ },
1879
+ ")"
1880
+ ]
1881
+ },
1882
+ "body": [
1721
1883
  {
1722
- "emit": "decl.exprBody"
1723
- },
1724
- ";"
1884
+ "stmts": "decl.body"
1885
+ }
1725
1886
  ]
1726
1887
  }
1727
1888
  }
1728
- ]
1729
- ],
1730
- "else": {
1731
- "block": {
1732
- "head": {
1733
- "tmpl": [
1734
- "public virtual bool Equals(",
1889
+ }
1890
+ },
1891
+ {
1892
+ "case": {
1893
+ "when": [
1894
+ [
1735
1895
  {
1736
- "map": "decl.params",
1737
- "sep": ", ",
1738
- "item": {
1739
- "call": "csParam"
1740
- }
1896
+ "eq": [
1897
+ "decl.ownerIsRecord",
1898
+ "false"
1899
+ ]
1741
1900
  },
1742
- ")"
1901
+ {
1902
+ "seq": [
1903
+ {
1904
+ "line": {
1905
+ "tmpl": [
1906
+ "public static bool operator ==(",
1907
+ {
1908
+ "fn": "ident",
1909
+ "args": [
1910
+ {
1911
+ "get": "decl.owner"
1912
+ }
1913
+ ]
1914
+ },
1915
+ " a, ",
1916
+ {
1917
+ "fn": "ident",
1918
+ "args": [
1919
+ {
1920
+ "get": "decl.owner"
1921
+ }
1922
+ ]
1923
+ },
1924
+ " b) => a is null || b is null ? ReferenceEquals(a, b) : a.Equals(b);"
1925
+ ]
1926
+ }
1927
+ },
1928
+ {
1929
+ "line": {
1930
+ "tmpl": [
1931
+ "public static bool operator !=(",
1932
+ {
1933
+ "fn": "ident",
1934
+ "args": [
1935
+ {
1936
+ "get": "decl.owner"
1937
+ }
1938
+ ]
1939
+ },
1940
+ " a, ",
1941
+ {
1942
+ "fn": "ident",
1943
+ "args": [
1944
+ {
1945
+ "get": "decl.owner"
1946
+ }
1947
+ ]
1948
+ },
1949
+ " b) => !(a == b);"
1950
+ ]
1951
+ }
1952
+ },
1953
+ {
1954
+ "line": {
1955
+ "tmpl": [
1956
+ "public override bool Equals(object? o) => o is ",
1957
+ {
1958
+ "fn": "ident",
1959
+ "args": [
1960
+ {
1961
+ "get": "decl.owner"
1962
+ }
1963
+ ]
1964
+ },
1965
+ " __o && this.Equals(__o);"
1966
+ ]
1967
+ }
1968
+ },
1969
+ {
1970
+ "line": "public override int GetHashCode() => 0;"
1971
+ }
1972
+ ]
1973
+ }
1743
1974
  ]
1975
+ ],
1976
+ "else": ""
1977
+ }
1978
+ }
1979
+ ]
1980
+ }
1981
+ ],
1982
+ [
1983
+ {
1984
+ "and": [
1985
+ {
1986
+ "eq": [
1987
+ "decl.kind",
1988
+ "operator"
1989
+ ]
1990
+ },
1991
+ {
1992
+ "eq": [
1993
+ "decl.opSymbol",
1994
+ "explicit"
1995
+ ]
1996
+ }
1997
+ ]
1998
+ },
1999
+ {
2000
+ "block": {
2001
+ "head": {
2002
+ "tmpl": [
2003
+ "public static explicit operator ",
2004
+ {
2005
+ "type": "decl.returnType"
1744
2006
  },
1745
- "body": [
1746
- {
2007
+ "(",
2008
+ {
2009
+ "fn": "ident",
2010
+ "args": [
2011
+ {
2012
+ "get": "decl.owner"
2013
+ }
2014
+ ]
2015
+ },
2016
+ " lhs)"
2017
+ ]
2018
+ },
2019
+ "body": [
2020
+ {
2021
+ "case": {
2022
+ "when": [
2023
+ [
2024
+ {
2025
+ "eq": [
2026
+ "decl.exprBodied",
2027
+ "true"
2028
+ ]
2029
+ },
2030
+ {
2031
+ "line": {
2032
+ "tmpl": [
2033
+ "return ",
2034
+ {
2035
+ "emit": "decl.exprBody"
2036
+ },
2037
+ ";"
2038
+ ]
2039
+ }
2040
+ }
2041
+ ]
2042
+ ],
2043
+ "else": {
1747
2044
  "stmts": "decl.body"
1748
2045
  }
1749
- ]
2046
+ }
1750
2047
  }
1751
- }
2048
+ ]
1752
2049
  }
1753
2050
  }
1754
2051
  ],
@@ -2270,6 +2567,27 @@
2270
2567
  {
2271
2568
  "line": "#nullable enable"
2272
2569
  },
2570
+ {
2571
+ "case": {
2572
+ "when": [
2573
+ [
2574
+ {
2575
+ "not": {
2576
+ "eq": [
2577
+ "module.attrImportsBlock",
2578
+ ""
2579
+ ]
2580
+ }
2581
+ },
2582
+ {
2583
+ "line": {
2584
+ "get": "module.attrImportsBlock"
2585
+ }
2586
+ }
2587
+ ]
2588
+ ]
2589
+ }
2590
+ },
2273
2591
  {
2274
2592
  "case": {
2275
2593
  "when": [
@@ -2326,7 +2644,31 @@
2326
2644
  },
2327
2645
  {
2328
2646
  "block": {
2329
- "head": { "tmpl": [ { "fn": "access" }, "static ", { "case": { "when": [ [ { "eq": [ "module.linked", "true" ] }, "partial " ] ], "else": "" } }, "class PolyglotExtensions" ] },
2647
+ "head": {
2648
+ "tmpl": [
2649
+ {
2650
+ "fn": "access"
2651
+ },
2652
+ "static ",
2653
+ {
2654
+ "case": {
2655
+ "when": [
2656
+ [
2657
+ {
2658
+ "eq": [
2659
+ "module.linked",
2660
+ "true"
2661
+ ]
2662
+ },
2663
+ "partial "
2664
+ ]
2665
+ ],
2666
+ "else": ""
2667
+ }
2668
+ },
2669
+ "class PolyglotExtensions"
2670
+ ]
2671
+ },
2330
2672
  "body": [
2331
2673
  {
2332
2674
  "mapMembers": "module.extensions",
@@ -2396,7 +2738,31 @@
2396
2738
  },
2397
2739
  {
2398
2740
  "block": {
2399
- "head": { "tmpl": [ { "fn": "access" }, "static ", { "case": { "when": [ [ { "eq": [ "module.linked", "true" ] }, "partial " ] ], "else": "" } }, "class PolyglotProgram" ] },
2741
+ "head": {
2742
+ "tmpl": [
2743
+ {
2744
+ "fn": "access"
2745
+ },
2746
+ "static ",
2747
+ {
2748
+ "case": {
2749
+ "when": [
2750
+ [
2751
+ {
2752
+ "eq": [
2753
+ "module.linked",
2754
+ "true"
2755
+ ]
2756
+ },
2757
+ "partial "
2758
+ ]
2759
+ ],
2760
+ "else": ""
2761
+ }
2762
+ },
2763
+ "class PolyglotProgram"
2764
+ ]
2765
+ },
2400
2766
  "body": [
2401
2767
  {
2402
2768
  "mapDecl": "module.globals",
@@ -3281,7 +3647,7 @@
3281
3647
  "std": {
3282
3648
  "std.collections": {
3283
3649
  "List.type": "global::System.Collections.Generic.List<$0>",
3284
- "List.init": "new $T()",
3650
+ "List.constructor": "new $T()",
3285
3651
  "List.count": "$this.Count",
3286
3652
  "List.add": "$this.Add($0)",
3287
3653
  "List.clear": "$this.Clear()",
@@ -3341,11 +3707,11 @@
3341
3707
  },
3342
3708
  "std.core": {
3343
3709
  "Error.type": "global::System.Exception",
3344
- "Error.init": "new $T($0)",
3710
+ "Error.constructor": "new $T($0)",
3345
3711
  "Error.message": "$this.Message",
3346
3712
  "Iterable.type": "global::System.Collections.Generic.IEnumerable<$0>",
3347
3713
  "Array.type": "$0[]",
3348
- "Array.init": "global::System.Array.Empty<$0>()",
3714
+ "Array.constructor": "global::System.Array.Empty<$0>()",
3349
3715
  "Array.count": "$this.Length",
3350
3716
  "i8.parse": "sbyte.Parse($0)",
3351
3717
  "i16.parse": "short.Parse($0)",