@mintplayer/polyglot-target-python 0.1.0 → 0.3.0

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mintplayer/polyglot-target-python",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "MintPlayer Polyglot Python target — a pure-JSON language plugin (spec + emission rules + capabilities + std bindings) for the polyglot transpiler.",
5
5
  "keywords": [
6
6
  "polyglot",
@@ -38,7 +38,8 @@
38
38
  "rethrow": "raise",
39
39
  "preludes": {
40
40
  "asyncEntry": "import asyncio\n",
41
- "idiv": "def _pg_idiv(a, b):\n q = a // b\n return q + 1 if (q < 0 and q * b != a) else q\ndef _pg_irem(a, b):\n return a - _pg_idiv(a, b) * b\n"
41
+ "idiv": "def _pg_idiv(a, b):\n q = a // b\n return q + 1 if (q < 0 and q * b != a) else q\ndef _pg_irem(a, b):\n return a - _pg_idiv(a, b) * b\n",
42
+ "fstr": "def _pg_str(x):\n if isinstance(x, bool):\n return \"true\" if x else \"false\"\n if isinstance(x, float) and x.is_integer() and abs(x) < 1e16:\n return str(int(x))\n return str(x)\n"
42
43
  },
43
44
  "tables": {
44
45
  "localDecl": {
@@ -970,6 +971,26 @@
970
971
  },
971
972
  "Program": {
972
973
  "seq": [
974
+ {
975
+ "mapDecl": "module.imports",
976
+ "each": {
977
+ "line": {
978
+ "case": {
979
+ "when": [
980
+ [
981
+ { "eq": [ "item.isNamespace", "true" ] },
982
+ { "tmpl": [ "import ", { "get": "item.path" }, " as ", { "get": "item.ns" } ] }
983
+ ],
984
+ [
985
+ { "not": { "eq": [ "item.names", "" ] } },
986
+ { "tmpl": [ "from ", { "get": "item.path" }, " import ", { "get": "item.names" } ] }
987
+ ]
988
+ ],
989
+ "else": { "tmpl": [ "import ", { "get": "item.path" } ] }
990
+ }
991
+ }
992
+ }
993
+ },
973
994
  {
974
995
  "mapMembers": "module.enums",
975
996
  "rule": "EnumDecl"
@@ -2035,7 +2056,13 @@
2035
2056
  },
2036
2057
  "hole": {
2037
2058
  "tmpl": [
2038
- " + str(",
2059
+ {
2060
+ "fn": "require",
2061
+ "args": [
2062
+ "fstr"
2063
+ ]
2064
+ },
2065
+ " + _pg_str(",
2039
2066
  {
2040
2067
  "emit": "item"
2041
2068
  },
@@ -2678,13 +2705,29 @@
2678
2705
  "List.removeAt": "$this.pop($0)"
2679
2706
  },
2680
2707
  "std.io": {
2681
- "print": "__builtins__.print(str(x).lower() if isinstance(x, bool) else x)"
2708
+ "print": "__builtins__.print((\"true\" if x else \"false\") if isinstance(x, bool) else (str(int(x)) if isinstance(x, float) and x.is_integer() and abs(x) < 1e16 else x))"
2682
2709
  },
2683
2710
  "std.math": {
2684
2711
  "Math.PI": "__import__('math').pi",
2685
2712
  "Math.E": "__import__('math').e",
2686
2713
  "Math.sqrt": "__import__('math').sqrt($0)",
2687
2714
  "Math.ln": "__import__('math').log($0)",
2715
+ "Math.log": "__import__('math').log($0)",
2716
+ "Math.log2": "__import__('math').log2($0)",
2717
+ "Math.log10": "__import__('math').log10($0)",
2718
+ "Math.exp": "__import__('math').exp($0)",
2719
+ "Math.pow": "__import__('math').pow($0, $1)",
2720
+ "Math.sin": "__import__('math').sin($0)",
2721
+ "Math.cos": "__import__('math').cos($0)",
2722
+ "Math.tan": "__import__('math').tan($0)",
2723
+ "Math.asin": "__import__('math').asin($0)",
2724
+ "Math.acos": "__import__('math').acos($0)",
2725
+ "Math.atan": "__import__('math').atan($0)",
2726
+ "Math.atan2": "__import__('math').atan2($0, $1)",
2727
+ "Math.sinh": "__import__('math').sinh($0)",
2728
+ "Math.cosh": "__import__('math').cosh($0)",
2729
+ "Math.tanh": "__import__('math').tanh($0)",
2730
+ "Math.trunc": "float(__import__('math').trunc($0))",
2688
2731
  "Math.floor": "float(__import__('math').floor($0))",
2689
2732
  "Math.ceil": "float(__import__('math').ceil($0))",
2690
2733
  "Math.min": "min($0, $1)",