@mintplayer/polyglot-target-python 0.8.1 → 0.9.1

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 +155 -12
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mintplayer/polyglot-target-python",
3
- "version": "0.8.1",
3
+ "version": "0.9.1",
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",
@@ -294,17 +294,44 @@
294
294
  }
295
295
  },
296
296
  "Index": {
297
- "tmpl": [
298
- {
299
- "emitChild": "node.receiver",
300
- "side": "recv"
301
- },
302
- "[",
303
- {
304
- "emit": "node.index"
305
- },
306
- "]"
307
- ]
297
+ "case": {
298
+ "when": [
299
+ [
300
+ {
301
+ "eq": [
302
+ "node.receiverHasIndexer",
303
+ "true"
304
+ ]
305
+ },
306
+ {
307
+ "tmpl": [
308
+ {
309
+ "emitChild": "node.receiver",
310
+ "side": "recv"
311
+ },
312
+ ".get(",
313
+ {
314
+ "emit": "node.index"
315
+ },
316
+ ")"
317
+ ]
318
+ }
319
+ ]
320
+ ],
321
+ "else": {
322
+ "tmpl": [
323
+ {
324
+ "emitChild": "node.receiver",
325
+ "side": "recv"
326
+ },
327
+ "[",
328
+ {
329
+ "emit": "node.index"
330
+ },
331
+ "]"
332
+ ]
333
+ }
334
+ }
308
335
  },
309
336
  "Cond": {
310
337
  "tmpl": [
@@ -991,6 +1018,29 @@
991
1018
  }
992
1019
  }
993
1020
  },
1021
+ {
1022
+ "case": {
1023
+ "when": [
1024
+ [
1025
+ {
1026
+ "not": {
1027
+ "eq": [
1028
+ "module.interfaces.count",
1029
+ "0"
1030
+ ]
1031
+ }
1032
+ },
1033
+ {
1034
+ "line": "import abc"
1035
+ }
1036
+ ]
1037
+ ]
1038
+ }
1039
+ },
1040
+ {
1041
+ "mapMembers": "module.interfaces",
1042
+ "rule": "InterfaceDecl"
1043
+ },
994
1044
  {
995
1045
  "mapMembers": "module.enums",
996
1046
  "rule": "EnumDecl"
@@ -1303,6 +1353,93 @@
1303
1353
  }
1304
1354
  ]
1305
1355
  },
1356
+ "InterfaceDecl": {
1357
+ "block": {
1358
+ "head": {
1359
+ "tmpl": [
1360
+ "class ",
1361
+ {
1362
+ "fn": "ident",
1363
+ "args": [
1364
+ {
1365
+ "get": "decl.name"
1366
+ }
1367
+ ]
1368
+ },
1369
+ "(",
1370
+ {
1371
+ "case": {
1372
+ "when": [
1373
+ [
1374
+ {
1375
+ "eq": [
1376
+ "decl.bases.count",
1377
+ "0"
1378
+ ]
1379
+ },
1380
+ ""
1381
+ ]
1382
+ ],
1383
+ "else": {
1384
+ "tmpl": [
1385
+ {
1386
+ "map": "decl.bases",
1387
+ "sep": ", ",
1388
+ "item": {
1389
+ "type": "item"
1390
+ }
1391
+ },
1392
+ ", "
1393
+ ]
1394
+ }
1395
+ }
1396
+ },
1397
+ "abc.ABC)"
1398
+ ]
1399
+ },
1400
+ "body": [
1401
+ {
1402
+ "mapDecl": "decl.methods",
1403
+ "each": {
1404
+ "seq": [
1405
+ {
1406
+ "line": "@abc.abstractmethod"
1407
+ },
1408
+ {
1409
+ "line": {
1410
+ "tmpl": [
1411
+ "def ",
1412
+ {
1413
+ "fn": "ident",
1414
+ "args": [
1415
+ {
1416
+ "get": "item.name"
1417
+ }
1418
+ ]
1419
+ },
1420
+ "(self",
1421
+ {
1422
+ "map": "item.params",
1423
+ "sep": "",
1424
+ "item": {
1425
+ "tmpl": [
1426
+ ", ",
1427
+ {
1428
+ "call": "pyParam"
1429
+ }
1430
+ ]
1431
+ }
1432
+ },
1433
+ "): ..."
1434
+ ]
1435
+ }
1436
+ }
1437
+ ]
1438
+ }
1439
+ }
1440
+ ]
1441
+ }
1442
+ },
1306
1443
  "ClassDecl": {
1307
1444
  "block": {
1308
1445
  "head": {
@@ -2732,7 +2869,12 @@
2732
2869
  "List.removeAt": "$this.pop($0)"
2733
2870
  },
2734
2871
  "std.io": {
2735
- "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))"
2872
+ "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))",
2873
+ "readText": "__import__('pathlib').Path(path).read_text()",
2874
+ "writeText": "__import__('pathlib').Path(path).write_text(content)",
2875
+ "appendText": "open(path, 'a').write(content)",
2876
+ "fileExists": "__import__('os').path.exists(path)",
2877
+ "deleteFile": "__import__('os').remove(path)"
2736
2878
  },
2737
2879
  "std.math": {
2738
2880
  "Math.PI": "__import__('math').pi",
@@ -2773,6 +2915,7 @@
2773
2915
  "string.toUpper": "$this.upper()",
2774
2916
  "string.toLower": "$this.lower()",
2775
2917
  "string.charAt": "$this[$0]",
2918
+ "string.codePointAt": "ord($this[$0])",
2776
2919
  "string.codePoints": "list($this)",
2777
2920
  "string.toI32": "int($this)"
2778
2921
  },