@mintplayer/polyglot-target-python 0.1.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.
Files changed (2) hide show
  1. package/package.json +23 -0
  2. package/polyglot-plugin.json +2722 -0
@@ -0,0 +1,2722 @@
1
+ {
2
+ "schema": 1,
3
+ "name": "python",
4
+ "capabilities": {
5
+ "blockLambdas": false,
6
+ "interfaces": "emulated"
7
+ },
8
+ "spec": {
9
+ "name": "python",
10
+ "scalarType": {},
11
+ "intSuffix": {},
12
+ "delimited": {},
13
+ "binaryOp": {
14
+ "&&": "and",
15
+ "||": "or"
16
+ },
17
+ "wrapInt": {
18
+ "u8": "(($x) & 0xff)",
19
+ "u16": "(($x) & 0xffff)",
20
+ "u32": "(($x) & 0xffffffff)",
21
+ "u64": "(($x) & 0xffffffffffffffff)",
22
+ "i8": "(((($x) & 0xff) ^ 0x80) - 0x80)",
23
+ "i16": "(((($x) & 0xffff) ^ 0x8000) - 0x8000)",
24
+ "i32": "(((($x) & 0xffffffff) ^ 0x80000000) - 0x80000000)",
25
+ "i64": "(((($x) & 0xffffffffffffffff) ^ 0x8000000000000000) - 0x8000000000000000)"
26
+ },
27
+ "wrapAtom": {
28
+ "recv": [
29
+ "binary",
30
+ "unary",
31
+ "cond",
32
+ "cast"
33
+ ],
34
+ "unary": [
35
+ "binary"
36
+ ]
37
+ },
38
+ "rethrow": "raise",
39
+ "preludes": {
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"
42
+ },
43
+ "tables": {
44
+ "localDecl": {
45
+ "mutable": "$x",
46
+ "const": "$x"
47
+ },
48
+ "yield": {
49
+ "value": "yield $x",
50
+ "empty": "return"
51
+ }
52
+ },
53
+ "blockStyle": "colonIndent",
54
+ "stmtEnd": "",
55
+ "throwKeyword": "raise",
56
+ "trueLit": "True",
57
+ "falseLit": "False",
58
+ "nullLit": "None",
59
+ "identifiers": {
60
+ "keywords": [
61
+ "False",
62
+ "None",
63
+ "True",
64
+ "and",
65
+ "as",
66
+ "assert",
67
+ "async",
68
+ "await",
69
+ "break",
70
+ "class",
71
+ "continue",
72
+ "def",
73
+ "del",
74
+ "elif",
75
+ "else",
76
+ "except",
77
+ "finally",
78
+ "for",
79
+ "from",
80
+ "global",
81
+ "if",
82
+ "import",
83
+ "in",
84
+ "is",
85
+ "lambda",
86
+ "nonlocal",
87
+ "not",
88
+ "or",
89
+ "pass",
90
+ "raise",
91
+ "return",
92
+ "try",
93
+ "while",
94
+ "with",
95
+ "yield",
96
+ "match",
97
+ "case"
98
+ ],
99
+ "escape": {
100
+ "strategy": "suffix",
101
+ "with": "_"
102
+ },
103
+ "mangle": {
104
+ "replace": "$",
105
+ "with": "_"
106
+ },
107
+ "reserved": [
108
+ "_m",
109
+ "self",
110
+ "_pg_idiv",
111
+ "_pg_irem",
112
+ "__c*",
113
+ "__o*",
114
+ "__e",
115
+ "tag",
116
+ "__opt*",
117
+ "__w*"
118
+ ],
119
+ "globals": [
120
+ "str"
121
+ ]
122
+ }
123
+ },
124
+ "rules": {
125
+ "Int": {
126
+ "tmpl": [
127
+ {
128
+ "get": "node.text"
129
+ },
130
+ {
131
+ "fn": "intSuffix",
132
+ "args": [
133
+ {
134
+ "get": "node.type"
135
+ }
136
+ ]
137
+ }
138
+ ]
139
+ },
140
+ "Float": {
141
+ "get": "node.text"
142
+ },
143
+ "Bool": {
144
+ "case": {
145
+ "when": [
146
+ [
147
+ {
148
+ "eq": [
149
+ "node.value",
150
+ "true"
151
+ ]
152
+ },
153
+ {
154
+ "get": "spec.trueLit"
155
+ }
156
+ ]
157
+ ],
158
+ "else": {
159
+ "get": "spec.falseLit"
160
+ }
161
+ }
162
+ },
163
+ "Null": {
164
+ "get": "spec.nullLit"
165
+ },
166
+ "Str": {
167
+ "fn": "escapeString",
168
+ "args": [
169
+ {
170
+ "get": "node.value"
171
+ }
172
+ ]
173
+ },
174
+ "Var": {
175
+ "fn": "ident",
176
+ "args": [
177
+ {
178
+ "get": "node.name"
179
+ }
180
+ ]
181
+ },
182
+ "This": "self",
183
+ "Extern": {
184
+ "get": "node.code"
185
+ },
186
+ "Await": {
187
+ "tmpl": [
188
+ "await ",
189
+ {
190
+ "emitChild": "node.operand",
191
+ "side": "recv"
192
+ }
193
+ ]
194
+ },
195
+ "Call": {
196
+ "tmpl": [
197
+ {
198
+ "fn": "mangleName",
199
+ "args": [
200
+ {
201
+ "fn": "ident",
202
+ "args": [
203
+ {
204
+ "get": "node.mangledCallee"
205
+ }
206
+ ]
207
+ }
208
+ ]
209
+ },
210
+ "(",
211
+ {
212
+ "map": "node.args",
213
+ "sep": ", "
214
+ },
215
+ ")"
216
+ ]
217
+ },
218
+ "Member": {
219
+ "case": {
220
+ "when": [
221
+ [
222
+ {
223
+ "eq": [
224
+ "node.nullSafe",
225
+ "true"
226
+ ]
227
+ },
228
+ {
229
+ "fresh": {
230
+ "prefix": "__o",
231
+ "as": "t",
232
+ "in": {
233
+ "tmpl": [
234
+ "(",
235
+ {
236
+ "get": "t"
237
+ },
238
+ ".",
239
+ {
240
+ "fn": "ident",
241
+ "args": [
242
+ {
243
+ "get": "node.field"
244
+ }
245
+ ]
246
+ },
247
+ " if (",
248
+ {
249
+ "get": "t"
250
+ },
251
+ " := ",
252
+ {
253
+ "emit": "node.object"
254
+ },
255
+ ") is not None else None)"
256
+ ]
257
+ }
258
+ }
259
+ }
260
+ ]
261
+ ],
262
+ "else": {
263
+ "tmpl": [
264
+ {
265
+ "case": {
266
+ "when": [
267
+ [
268
+ {
269
+ "has": "node.staticType"
270
+ },
271
+ {
272
+ "get": "node.staticType"
273
+ }
274
+ ]
275
+ ],
276
+ "else": {
277
+ "emitChild": "node.object",
278
+ "side": "recv"
279
+ }
280
+ }
281
+ },
282
+ ".",
283
+ {
284
+ "fn": "ident",
285
+ "args": [
286
+ {
287
+ "get": "node.field"
288
+ }
289
+ ]
290
+ }
291
+ ]
292
+ }
293
+ }
294
+ },
295
+ "Index": {
296
+ "tmpl": [
297
+ {
298
+ "emitChild": "node.receiver",
299
+ "side": "recv"
300
+ },
301
+ "[",
302
+ {
303
+ "emit": "node.index"
304
+ },
305
+ "]"
306
+ ]
307
+ },
308
+ "Cond": {
309
+ "tmpl": [
310
+ "(",
311
+ {
312
+ "emit": "node.then"
313
+ },
314
+ " if ",
315
+ {
316
+ "emit": "node.cond"
317
+ },
318
+ " else ",
319
+ {
320
+ "emit": "node.els"
321
+ },
322
+ ")"
323
+ ]
324
+ },
325
+ "ListLit": {
326
+ "tmpl": [
327
+ "[",
328
+ {
329
+ "map": "node.elements",
330
+ "sep": ", "
331
+ },
332
+ "]"
333
+ ]
334
+ },
335
+ "Tuple": {
336
+ "case": {
337
+ "when": [
338
+ [
339
+ {
340
+ "eq": [
341
+ "node.elements.count",
342
+ "1"
343
+ ]
344
+ },
345
+ {
346
+ "tmpl": [
347
+ "(",
348
+ {
349
+ "emit": "node.elements.0"
350
+ },
351
+ ",)"
352
+ ]
353
+ }
354
+ ]
355
+ ],
356
+ "else": {
357
+ "tmpl": [
358
+ "(",
359
+ {
360
+ "map": "node.elements",
361
+ "sep": ", "
362
+ },
363
+ ")"
364
+ ]
365
+ }
366
+ }
367
+ },
368
+ "New": {
369
+ "tmpl": [
370
+ {
371
+ "fn": "ident",
372
+ "args": [
373
+ {
374
+ "get": "node.typeName"
375
+ }
376
+ ]
377
+ },
378
+ "(",
379
+ {
380
+ "map": "node.args",
381
+ "sep": ", "
382
+ },
383
+ ")"
384
+ ]
385
+ },
386
+ "Lambda": {
387
+ "tmpl": [
388
+ "lambda ",
389
+ {
390
+ "map": "node.params",
391
+ "sep": ", ",
392
+ "item": {
393
+ "fn": "ident",
394
+ "args": [
395
+ {
396
+ "get": "item.name"
397
+ }
398
+ ]
399
+ }
400
+ },
401
+ ": ",
402
+ {
403
+ "emit": "node.body"
404
+ }
405
+ ]
406
+ },
407
+ "Type": {
408
+ "case": {
409
+ "when": [
410
+ [
411
+ {
412
+ "has": "type.externTemplate"
413
+ },
414
+ {
415
+ "fn": "substExtern"
416
+ }
417
+ ]
418
+ ],
419
+ "else": {
420
+ "fn": "ident",
421
+ "args": [
422
+ {
423
+ "get": "type.name"
424
+ }
425
+ ]
426
+ }
427
+ }
428
+ },
429
+ "EnumDecl": {
430
+ "block": {
431
+ "head": {
432
+ "tmpl": [
433
+ "class ",
434
+ {
435
+ "fn": "ident",
436
+ "args": [
437
+ {
438
+ "get": "decl.name"
439
+ }
440
+ ]
441
+ }
442
+ ]
443
+ },
444
+ "body": [
445
+ {
446
+ "case": {
447
+ "when": [
448
+ [
449
+ {
450
+ "eq": [
451
+ "decl.cases.count",
452
+ "0"
453
+ ]
454
+ },
455
+ {
456
+ "line": "pass"
457
+ }
458
+ ]
459
+ ]
460
+ }
461
+ },
462
+ {
463
+ "mapDecl": "decl.cases",
464
+ "each": {
465
+ "line": {
466
+ "tmpl": [
467
+ {
468
+ "fn": "ident",
469
+ "args": [
470
+ {
471
+ "get": "item.name"
472
+ }
473
+ ]
474
+ },
475
+ " = ",
476
+ {
477
+ "get": "item.value"
478
+ }
479
+ ]
480
+ }
481
+ }
482
+ }
483
+ ]
484
+ }
485
+ },
486
+ "UnionDecl": {
487
+ "line": {
488
+ "tmpl": [
489
+ "# union ",
490
+ {
491
+ "fn": "ident",
492
+ "args": [
493
+ {
494
+ "get": "decl.name"
495
+ }
496
+ ]
497
+ },
498
+ " -> tagged dicts: {\"tag\": <case>, <field>: <value>, ...}"
499
+ ]
500
+ }
501
+ },
502
+ "RecordDecl": {
503
+ "block": {
504
+ "head": {
505
+ "tmpl": [
506
+ "class ",
507
+ {
508
+ "fn": "ident",
509
+ "args": [
510
+ {
511
+ "get": "decl.name"
512
+ }
513
+ ]
514
+ }
515
+ ]
516
+ },
517
+ "body": [
518
+ {
519
+ "block": {
520
+ "head": {
521
+ "tmpl": [
522
+ "def __init__(self",
523
+ {
524
+ "map": "decl.fields",
525
+ "sep": "",
526
+ "item": {
527
+ "tmpl": [
528
+ ", ",
529
+ {
530
+ "fn": "ident",
531
+ "args": [
532
+ {
533
+ "get": "item.name"
534
+ }
535
+ ]
536
+ }
537
+ ]
538
+ }
539
+ },
540
+ ")"
541
+ ]
542
+ },
543
+ "body": [
544
+ {
545
+ "case": {
546
+ "when": [
547
+ [
548
+ {
549
+ "eq": [
550
+ "decl.fields.count",
551
+ "0"
552
+ ]
553
+ },
554
+ {
555
+ "line": "pass"
556
+ }
557
+ ]
558
+ ]
559
+ }
560
+ },
561
+ {
562
+ "mapDecl": "decl.fields",
563
+ "each": {
564
+ "line": {
565
+ "tmpl": [
566
+ "self.",
567
+ {
568
+ "fn": "ident",
569
+ "args": [
570
+ {
571
+ "get": "item.name"
572
+ }
573
+ ]
574
+ },
575
+ " = ",
576
+ {
577
+ "fn": "ident",
578
+ "args": [
579
+ {
580
+ "get": "item.name"
581
+ }
582
+ ]
583
+ }
584
+ ]
585
+ }
586
+ }
587
+ }
588
+ ]
589
+ }
590
+ },
591
+ {
592
+ "block": {
593
+ "head": "def __eq__(self, other)",
594
+ "body": [
595
+ {
596
+ "case": {
597
+ "when": [
598
+ [
599
+ {
600
+ "eq": [
601
+ "decl.fields.count",
602
+ "0"
603
+ ]
604
+ },
605
+ {
606
+ "line": "return True"
607
+ }
608
+ ]
609
+ ],
610
+ "else": {
611
+ "line": {
612
+ "tmpl": [
613
+ "return ",
614
+ {
615
+ "map": "decl.fields",
616
+ "sep": " and ",
617
+ "item": {
618
+ "tmpl": [
619
+ "self.",
620
+ {
621
+ "fn": "ident",
622
+ "args": [
623
+ {
624
+ "get": "item.name"
625
+ }
626
+ ]
627
+ },
628
+ " == other.",
629
+ {
630
+ "fn": "ident",
631
+ "args": [
632
+ {
633
+ "get": "item.name"
634
+ }
635
+ ]
636
+ }
637
+ ]
638
+ }
639
+ }
640
+ ]
641
+ }
642
+ }
643
+ }
644
+ }
645
+ ]
646
+ }
647
+ },
648
+ {
649
+ "mapMembers": "decl.methods",
650
+ "rule": "MethodDecl"
651
+ }
652
+ ]
653
+ }
654
+ },
655
+ "pyStmtBody": {
656
+ "case": {
657
+ "when": [
658
+ [
659
+ {
660
+ "eq": [
661
+ "stmt.body.count",
662
+ "0"
663
+ ]
664
+ },
665
+ {
666
+ "line": "pass"
667
+ }
668
+ ]
669
+ ],
670
+ "else": {
671
+ "stmts": "stmt.body"
672
+ }
673
+ }
674
+ },
675
+ "pyItemBody": {
676
+ "case": {
677
+ "when": [
678
+ [
679
+ {
680
+ "eq": [
681
+ "item.body.count",
682
+ "0"
683
+ ]
684
+ },
685
+ {
686
+ "line": "pass"
687
+ }
688
+ ]
689
+ ],
690
+ "else": {
691
+ "stmts": "item.body"
692
+ }
693
+ }
694
+ },
695
+ "TryStmt": {
696
+ "seq": [
697
+ {
698
+ "block": {
699
+ "head": "try",
700
+ "body": [
701
+ {
702
+ "call": "pyStmtBody"
703
+ }
704
+ ]
705
+ }
706
+ },
707
+ {
708
+ "mapDecl": "stmt.catches",
709
+ "each": {
710
+ "block": {
711
+ "head": {
712
+ "tmpl": [
713
+ "except ",
714
+ {
715
+ "case": {
716
+ "when": [
717
+ [
718
+ {
719
+ "eq": [
720
+ "item.hasType",
721
+ "true"
722
+ ]
723
+ },
724
+ {
725
+ "type": "item.type"
726
+ }
727
+ ]
728
+ ],
729
+ "else": "Exception"
730
+ }
731
+ },
732
+ {
733
+ "case": {
734
+ "when": [
735
+ [
736
+ {
737
+ "eq": [
738
+ "item.hasBinding",
739
+ "true"
740
+ ]
741
+ },
742
+ {
743
+ "tmpl": [
744
+ " as ",
745
+ {
746
+ "fn": "ident",
747
+ "args": [
748
+ {
749
+ "get": "item.binding"
750
+ }
751
+ ]
752
+ }
753
+ ]
754
+ }
755
+ ]
756
+ ]
757
+ }
758
+ }
759
+ ]
760
+ },
761
+ "body": [
762
+ {
763
+ "case": {
764
+ "when": [
765
+ [
766
+ {
767
+ "eq": [
768
+ "item.hasGuard",
769
+ "true"
770
+ ]
771
+ },
772
+ {
773
+ "line": {
774
+ "tmpl": [
775
+ "if not (",
776
+ {
777
+ "emit": "item.guard"
778
+ },
779
+ "): raise"
780
+ ]
781
+ }
782
+ }
783
+ ]
784
+ ]
785
+ }
786
+ },
787
+ {
788
+ "call": "pyItemBody"
789
+ }
790
+ ]
791
+ }
792
+ }
793
+ },
794
+ {
795
+ "case": {
796
+ "when": [
797
+ [
798
+ {
799
+ "eq": [
800
+ "stmt.hasFinally",
801
+ "true"
802
+ ]
803
+ },
804
+ {
805
+ "block": {
806
+ "head": "finally",
807
+ "body": [
808
+ {
809
+ "case": {
810
+ "when": [
811
+ [
812
+ {
813
+ "eq": [
814
+ "stmt.finallyBody.count",
815
+ "0"
816
+ ]
817
+ },
818
+ {
819
+ "line": "pass"
820
+ }
821
+ ]
822
+ ],
823
+ "else": {
824
+ "stmts": "stmt.finallyBody"
825
+ }
826
+ }
827
+ }
828
+ ]
829
+ }
830
+ }
831
+ ]
832
+ ]
833
+ }
834
+ }
835
+ ]
836
+ },
837
+ "ForStmt": {
838
+ "case": {
839
+ "when": [
840
+ [
841
+ {
842
+ "eq": [
843
+ "stmt.isRange",
844
+ "true"
845
+ ]
846
+ },
847
+ {
848
+ "block": {
849
+ "head": {
850
+ "tmpl": [
851
+ "for ",
852
+ {
853
+ "fn": "ident",
854
+ "args": [
855
+ {
856
+ "get": "stmt.binding"
857
+ }
858
+ ]
859
+ },
860
+ " in range(",
861
+ {
862
+ "emit": "stmt.rangeStart"
863
+ },
864
+ ", ",
865
+ {
866
+ "case": {
867
+ "when": [
868
+ [
869
+ {
870
+ "eq": [
871
+ "stmt.inclusive",
872
+ "true"
873
+ ]
874
+ },
875
+ {
876
+ "tmpl": [
877
+ "(",
878
+ {
879
+ "emit": "stmt.rangeEnd"
880
+ },
881
+ ") + 1"
882
+ ]
883
+ }
884
+ ]
885
+ ],
886
+ "else": {
887
+ "emit": "stmt.rangeEnd"
888
+ }
889
+ }
890
+ },
891
+ ")"
892
+ ]
893
+ },
894
+ "body": [
895
+ {
896
+ "call": "pyStmtBody"
897
+ }
898
+ ]
899
+ }
900
+ }
901
+ ],
902
+ [
903
+ {
904
+ "not": {
905
+ "eq": [
906
+ "stmt.tupleBindings.count",
907
+ "0"
908
+ ]
909
+ }
910
+ },
911
+ {
912
+ "block": {
913
+ "head": {
914
+ "tmpl": [
915
+ "for ",
916
+ {
917
+ "map": "stmt.tupleBindings",
918
+ "sep": ", ",
919
+ "item": {
920
+ "fn": "ident",
921
+ "args": [
922
+ {
923
+ "get": "item"
924
+ }
925
+ ]
926
+ }
927
+ },
928
+ " in ",
929
+ {
930
+ "emit": "stmt.iterable"
931
+ }
932
+ ]
933
+ },
934
+ "body": [
935
+ {
936
+ "call": "pyStmtBody"
937
+ }
938
+ ]
939
+ }
940
+ }
941
+ ]
942
+ ],
943
+ "else": {
944
+ "block": {
945
+ "head": {
946
+ "tmpl": [
947
+ "for ",
948
+ {
949
+ "fn": "ident",
950
+ "args": [
951
+ {
952
+ "get": "stmt.binding"
953
+ }
954
+ ]
955
+ },
956
+ " in ",
957
+ {
958
+ "emit": "stmt.iterable"
959
+ }
960
+ ]
961
+ },
962
+ "body": [
963
+ {
964
+ "call": "pyStmtBody"
965
+ }
966
+ ]
967
+ }
968
+ }
969
+ }
970
+ },
971
+ "Program": {
972
+ "seq": [
973
+ {
974
+ "mapMembers": "module.enums",
975
+ "rule": "EnumDecl"
976
+ },
977
+ {
978
+ "mapMembers": "module.unions",
979
+ "rule": "UnionDecl"
980
+ },
981
+ {
982
+ "mapMembers": "module.records",
983
+ "rule": "RecordDecl"
984
+ },
985
+ {
986
+ "mapMembers": "module.classes",
987
+ "rule": "ClassDecl"
988
+ },
989
+ {
990
+ "mapDecl": "module.globals",
991
+ "each": {
992
+ "line": {
993
+ "tmpl": [
994
+ {
995
+ "fn": "ident",
996
+ "args": [
997
+ {
998
+ "get": "item.name"
999
+ }
1000
+ ]
1001
+ },
1002
+ " = ",
1003
+ {
1004
+ "case": {
1005
+ "when": [
1006
+ [
1007
+ {
1008
+ "eq": [
1009
+ "item.hasInit",
1010
+ "true"
1011
+ ]
1012
+ },
1013
+ {
1014
+ "emit": "item.init"
1015
+ }
1016
+ ]
1017
+ ],
1018
+ "else": "None"
1019
+ }
1020
+ }
1021
+ ]
1022
+ }
1023
+ }
1024
+ },
1025
+ {
1026
+ "mapMembers": "module.functions",
1027
+ "rule": "FunctionDecl"
1028
+ },
1029
+ {
1030
+ "mapMembers": "module.extensions",
1031
+ "rule": "FunctionDecl"
1032
+ },
1033
+ {
1034
+ "case": {
1035
+ "when": [
1036
+ [
1037
+ {
1038
+ "eq": [
1039
+ "module.hasEntry",
1040
+ "true"
1041
+ ]
1042
+ },
1043
+ {
1044
+ "case": {
1045
+ "when": [
1046
+ [
1047
+ {
1048
+ "eq": [
1049
+ "module.entry.isAsync",
1050
+ "true"
1051
+ ]
1052
+ },
1053
+ {
1054
+ "line": {
1055
+ "tmpl": [
1056
+ "asyncio.run(",
1057
+ {
1058
+ "fn": "mangle",
1059
+ "args": [
1060
+ {
1061
+ "get": "module.entry.mangledName"
1062
+ }
1063
+ ]
1064
+ },
1065
+ "())"
1066
+ ]
1067
+ }
1068
+ }
1069
+ ]
1070
+ ],
1071
+ "else": {
1072
+ "line": {
1073
+ "tmpl": [
1074
+ {
1075
+ "fn": "mangle",
1076
+ "args": [
1077
+ {
1078
+ "get": "module.entry.mangledName"
1079
+ }
1080
+ ]
1081
+ },
1082
+ "()"
1083
+ ]
1084
+ }
1085
+ }
1086
+ }
1087
+ }
1088
+ ]
1089
+ ]
1090
+ }
1091
+ }
1092
+ ]
1093
+ },
1094
+ "pyFnSig": {
1095
+ "tmpl": [
1096
+ {
1097
+ "case": {
1098
+ "when": [
1099
+ [
1100
+ {
1101
+ "eq": [
1102
+ "decl.isAsync",
1103
+ "true"
1104
+ ]
1105
+ },
1106
+ "async def "
1107
+ ]
1108
+ ],
1109
+ "else": "def "
1110
+ }
1111
+ },
1112
+ {
1113
+ "fn": "mangle",
1114
+ "args": [
1115
+ {
1116
+ "fn": "ident",
1117
+ "args": [
1118
+ {
1119
+ "get": "decl.emitName"
1120
+ }
1121
+ ]
1122
+ }
1123
+ ]
1124
+ },
1125
+ "(",
1126
+ {
1127
+ "map": "decl.params",
1128
+ "sep": ", ",
1129
+ "item": {
1130
+ "call": "pyParam"
1131
+ }
1132
+ },
1133
+ ")"
1134
+ ]
1135
+ },
1136
+ "FunctionDecl": {
1137
+ "case": {
1138
+ "when": [
1139
+ [
1140
+ {
1141
+ "eq": [
1142
+ "decl.exprBodied",
1143
+ "true"
1144
+ ]
1145
+ },
1146
+ {
1147
+ "block": {
1148
+ "head": {
1149
+ "call": "pyFnSig"
1150
+ },
1151
+ "body": [
1152
+ {
1153
+ "case": {
1154
+ "when": [
1155
+ [
1156
+ {
1157
+ "eq": [
1158
+ "decl.returnsUnit",
1159
+ "true"
1160
+ ]
1161
+ },
1162
+ {
1163
+ "line": {
1164
+ "emit": "decl.exprBody"
1165
+ }
1166
+ }
1167
+ ]
1168
+ ],
1169
+ "else": {
1170
+ "line": {
1171
+ "tmpl": [
1172
+ "return ",
1173
+ {
1174
+ "emit": "decl.exprBody"
1175
+ }
1176
+ ]
1177
+ }
1178
+ }
1179
+ }
1180
+ }
1181
+ ]
1182
+ }
1183
+ }
1184
+ ]
1185
+ ],
1186
+ "else": {
1187
+ "block": {
1188
+ "head": {
1189
+ "call": "pyFnSig"
1190
+ },
1191
+ "body": [
1192
+ {
1193
+ "case": {
1194
+ "when": [
1195
+ [
1196
+ {
1197
+ "eq": [
1198
+ "decl.body.count",
1199
+ "0"
1200
+ ]
1201
+ },
1202
+ {
1203
+ "line": "pass"
1204
+ }
1205
+ ]
1206
+ ],
1207
+ "else": {
1208
+ "stmts": "decl.body"
1209
+ }
1210
+ }
1211
+ }
1212
+ ]
1213
+ }
1214
+ }
1215
+ }
1216
+ },
1217
+ "pyClassHead": {
1218
+ "tmpl": [
1219
+ "class ",
1220
+ {
1221
+ "fn": "ident",
1222
+ "args": [
1223
+ {
1224
+ "get": "decl.name"
1225
+ }
1226
+ ]
1227
+ },
1228
+ {
1229
+ "case": {
1230
+ "when": [
1231
+ [
1232
+ {
1233
+ "eq": [
1234
+ "decl.bases.count",
1235
+ "0"
1236
+ ]
1237
+ },
1238
+ ""
1239
+ ]
1240
+ ],
1241
+ "else": {
1242
+ "tmpl": [
1243
+ "(",
1244
+ {
1245
+ "map": "decl.bases",
1246
+ "sep": ", ",
1247
+ "item": {
1248
+ "type": "item"
1249
+ }
1250
+ },
1251
+ ")"
1252
+ ]
1253
+ }
1254
+ }
1255
+ }
1256
+ ]
1257
+ },
1258
+ "ClassDecl": {
1259
+ "block": {
1260
+ "head": {
1261
+ "call": "pyClassHead"
1262
+ },
1263
+ "body": [
1264
+ {
1265
+ "mapDecl": "decl.staticInitFields",
1266
+ "each": {
1267
+ "line": {
1268
+ "tmpl": [
1269
+ {
1270
+ "fn": "ident",
1271
+ "args": [
1272
+ {
1273
+ "get": "item.name"
1274
+ }
1275
+ ]
1276
+ },
1277
+ " = ",
1278
+ {
1279
+ "emit": "item.init"
1280
+ }
1281
+ ]
1282
+ }
1283
+ }
1284
+ },
1285
+ {
1286
+ "case": {
1287
+ "when": [
1288
+ [
1289
+ {
1290
+ "eq": [
1291
+ "decl.needsCtor",
1292
+ "true"
1293
+ ]
1294
+ },
1295
+ {
1296
+ "block": {
1297
+ "head": {
1298
+ "tmpl": [
1299
+ "def __init__(self",
1300
+ {
1301
+ "map": "decl.initParams",
1302
+ "sep": "",
1303
+ "item": {
1304
+ "tmpl": [
1305
+ ", ",
1306
+ {
1307
+ "call": "pyParam"
1308
+ }
1309
+ ]
1310
+ }
1311
+ },
1312
+ ")"
1313
+ ]
1314
+ },
1315
+ "body": [
1316
+ {
1317
+ "case": {
1318
+ "when": [
1319
+ [
1320
+ {
1321
+ "eq": [
1322
+ "decl.hasSuper",
1323
+ "true"
1324
+ ]
1325
+ },
1326
+ {
1327
+ "line": {
1328
+ "tmpl": [
1329
+ "super().__init__(",
1330
+ {
1331
+ "map": "decl.superArgs",
1332
+ "sep": ", ",
1333
+ "item": {
1334
+ "emit": "item"
1335
+ }
1336
+ },
1337
+ ")"
1338
+ ]
1339
+ }
1340
+ }
1341
+ ]
1342
+ ]
1343
+ }
1344
+ },
1345
+ {
1346
+ "mapDecl": "decl.instanceInitFields",
1347
+ "each": {
1348
+ "line": {
1349
+ "tmpl": [
1350
+ "self.",
1351
+ {
1352
+ "fn": "ident",
1353
+ "args": [
1354
+ {
1355
+ "get": "item.name"
1356
+ }
1357
+ ]
1358
+ },
1359
+ " = ",
1360
+ {
1361
+ "emit": "item.init"
1362
+ }
1363
+ ]
1364
+ }
1365
+ }
1366
+ },
1367
+ {
1368
+ "stmts": "decl.initBody"
1369
+ },
1370
+ {
1371
+ "case": {
1372
+ "when": [
1373
+ [
1374
+ {
1375
+ "and": [
1376
+ {
1377
+ "eq": [
1378
+ "decl.hasSuper",
1379
+ "false"
1380
+ ]
1381
+ },
1382
+ {
1383
+ "eq": [
1384
+ "decl.instanceInitFields.count",
1385
+ "0"
1386
+ ]
1387
+ },
1388
+ {
1389
+ "eq": [
1390
+ "decl.initBody.count",
1391
+ "0"
1392
+ ]
1393
+ }
1394
+ ]
1395
+ },
1396
+ {
1397
+ "line": "pass"
1398
+ }
1399
+ ]
1400
+ ]
1401
+ }
1402
+ }
1403
+ ]
1404
+ }
1405
+ }
1406
+ ]
1407
+ ]
1408
+ }
1409
+ },
1410
+ {
1411
+ "mapMembers": "decl.methods",
1412
+ "rule": "MethodDecl"
1413
+ },
1414
+ {
1415
+ "case": {
1416
+ "when": [
1417
+ [
1418
+ {
1419
+ "and": [
1420
+ {
1421
+ "eq": [
1422
+ "decl.staticInitFields.count",
1423
+ "0"
1424
+ ]
1425
+ },
1426
+ {
1427
+ "eq": [
1428
+ "decl.needsCtor",
1429
+ "false"
1430
+ ]
1431
+ },
1432
+ {
1433
+ "eq": [
1434
+ "decl.methods.count",
1435
+ "0"
1436
+ ]
1437
+ }
1438
+ ]
1439
+ },
1440
+ {
1441
+ "line": "pass"
1442
+ }
1443
+ ]
1444
+ ]
1445
+ }
1446
+ }
1447
+ ]
1448
+ }
1449
+ },
1450
+ "pyParam": {
1451
+ "tmpl": [
1452
+ {
1453
+ "fn": "ident",
1454
+ "args": [
1455
+ {
1456
+ "get": "item.name"
1457
+ }
1458
+ ]
1459
+ },
1460
+ {
1461
+ "case": {
1462
+ "when": [
1463
+ [
1464
+ {
1465
+ "eq": [
1466
+ "item.hasDefault",
1467
+ "true"
1468
+ ]
1469
+ },
1470
+ {
1471
+ "tmpl": [
1472
+ " = ",
1473
+ {
1474
+ "emit": "item.default"
1475
+ }
1476
+ ]
1477
+ }
1478
+ ]
1479
+ ]
1480
+ }
1481
+ }
1482
+ ]
1483
+ },
1484
+ "pyDunder": {
1485
+ "case": {
1486
+ "when": [
1487
+ [
1488
+ {
1489
+ "eq": [
1490
+ "decl.opSymbol",
1491
+ "+"
1492
+ ]
1493
+ },
1494
+ "__add__"
1495
+ ],
1496
+ [
1497
+ {
1498
+ "eq": [
1499
+ "decl.opSymbol",
1500
+ "-"
1501
+ ]
1502
+ },
1503
+ "__sub__"
1504
+ ],
1505
+ [
1506
+ {
1507
+ "eq": [
1508
+ "decl.opSymbol",
1509
+ "*"
1510
+ ]
1511
+ },
1512
+ "__mul__"
1513
+ ],
1514
+ [
1515
+ {
1516
+ "eq": [
1517
+ "decl.opSymbol",
1518
+ "/"
1519
+ ]
1520
+ },
1521
+ "__truediv__"
1522
+ ],
1523
+ [
1524
+ {
1525
+ "eq": [
1526
+ "decl.opSymbol",
1527
+ "%"
1528
+ ]
1529
+ },
1530
+ "__mod__"
1531
+ ],
1532
+ [
1533
+ {
1534
+ "eq": [
1535
+ "decl.opSymbol",
1536
+ "=="
1537
+ ]
1538
+ },
1539
+ "__eq__"
1540
+ ],
1541
+ [
1542
+ {
1543
+ "eq": [
1544
+ "decl.opSymbol",
1545
+ "<"
1546
+ ]
1547
+ },
1548
+ "__lt__"
1549
+ ],
1550
+ [
1551
+ {
1552
+ "eq": [
1553
+ "decl.opSymbol",
1554
+ "<="
1555
+ ]
1556
+ },
1557
+ "__le__"
1558
+ ],
1559
+ [
1560
+ {
1561
+ "eq": [
1562
+ "decl.opSymbol",
1563
+ ">"
1564
+ ]
1565
+ },
1566
+ "__gt__"
1567
+ ],
1568
+ [
1569
+ {
1570
+ "eq": [
1571
+ "decl.opSymbol",
1572
+ ">="
1573
+ ]
1574
+ },
1575
+ "__ge__"
1576
+ ]
1577
+ ],
1578
+ "else": {
1579
+ "fn": "ident",
1580
+ "args": [
1581
+ {
1582
+ "get": "decl.name"
1583
+ }
1584
+ ]
1585
+ }
1586
+ }
1587
+ },
1588
+ "pyMethodSig": {
1589
+ "tmpl": [
1590
+ {
1591
+ "case": {
1592
+ "when": [
1593
+ [
1594
+ {
1595
+ "eq": [
1596
+ "decl.isAsync",
1597
+ "true"
1598
+ ]
1599
+ },
1600
+ "async def "
1601
+ ]
1602
+ ],
1603
+ "else": "def "
1604
+ }
1605
+ },
1606
+ {
1607
+ "case": {
1608
+ "when": [
1609
+ [
1610
+ {
1611
+ "eq": [
1612
+ "decl.kind",
1613
+ "operator"
1614
+ ]
1615
+ },
1616
+ {
1617
+ "call": "pyDunder"
1618
+ }
1619
+ ]
1620
+ ],
1621
+ "else": {
1622
+ "fn": "ident",
1623
+ "args": [
1624
+ {
1625
+ "get": "decl.name"
1626
+ }
1627
+ ]
1628
+ }
1629
+ }
1630
+ },
1631
+ "(",
1632
+ {
1633
+ "case": {
1634
+ "when": [
1635
+ [
1636
+ {
1637
+ "eq": [
1638
+ "decl.isStatic",
1639
+ "true"
1640
+ ]
1641
+ },
1642
+ ""
1643
+ ]
1644
+ ],
1645
+ "else": {
1646
+ "tmpl": [
1647
+ "self",
1648
+ {
1649
+ "case": {
1650
+ "when": [
1651
+ [
1652
+ {
1653
+ "eq": [
1654
+ "decl.params.count",
1655
+ "0"
1656
+ ]
1657
+ },
1658
+ ""
1659
+ ]
1660
+ ],
1661
+ "else": ", "
1662
+ }
1663
+ }
1664
+ ]
1665
+ }
1666
+ }
1667
+ },
1668
+ {
1669
+ "map": "decl.params",
1670
+ "sep": ", ",
1671
+ "item": {
1672
+ "call": "pyParam"
1673
+ }
1674
+ },
1675
+ ")"
1676
+ ]
1677
+ },
1678
+ "MethodDecl": {
1679
+ "seq": [
1680
+ {
1681
+ "case": {
1682
+ "when": [
1683
+ [
1684
+ {
1685
+ "eq": [
1686
+ "decl.kind",
1687
+ "property"
1688
+ ]
1689
+ },
1690
+ {
1691
+ "line": "@property"
1692
+ }
1693
+ ]
1694
+ ]
1695
+ }
1696
+ },
1697
+ {
1698
+ "case": {
1699
+ "when": [
1700
+ [
1701
+ {
1702
+ "eq": [
1703
+ "decl.isStatic",
1704
+ "true"
1705
+ ]
1706
+ },
1707
+ {
1708
+ "line": "@staticmethod"
1709
+ }
1710
+ ]
1711
+ ]
1712
+ }
1713
+ },
1714
+ {
1715
+ "case": {
1716
+ "when": [
1717
+ [
1718
+ {
1719
+ "eq": [
1720
+ "decl.exprBodied",
1721
+ "true"
1722
+ ]
1723
+ },
1724
+ {
1725
+ "block": {
1726
+ "head": {
1727
+ "call": "pyMethodSig"
1728
+ },
1729
+ "body": [
1730
+ {
1731
+ "case": {
1732
+ "when": [
1733
+ [
1734
+ {
1735
+ "eq": [
1736
+ "decl.returnsUnit",
1737
+ "true"
1738
+ ]
1739
+ },
1740
+ {
1741
+ "line": {
1742
+ "emit": "decl.exprBody"
1743
+ }
1744
+ }
1745
+ ]
1746
+ ],
1747
+ "else": {
1748
+ "line": {
1749
+ "tmpl": [
1750
+ "return ",
1751
+ {
1752
+ "emit": "decl.exprBody"
1753
+ }
1754
+ ]
1755
+ }
1756
+ }
1757
+ }
1758
+ }
1759
+ ]
1760
+ }
1761
+ }
1762
+ ]
1763
+ ],
1764
+ "else": {
1765
+ "block": {
1766
+ "head": {
1767
+ "call": "pyMethodSig"
1768
+ },
1769
+ "body": [
1770
+ {
1771
+ "case": {
1772
+ "when": [
1773
+ [
1774
+ {
1775
+ "eq": [
1776
+ "decl.body.count",
1777
+ "0"
1778
+ ]
1779
+ },
1780
+ {
1781
+ "line": "pass"
1782
+ }
1783
+ ]
1784
+ ],
1785
+ "else": {
1786
+ "stmts": "decl.body"
1787
+ }
1788
+ }
1789
+ }
1790
+ ]
1791
+ }
1792
+ }
1793
+ }
1794
+ }
1795
+ ]
1796
+ },
1797
+ "MakeCase": {
1798
+ "tmpl": [
1799
+ "{\"tag\": ",
1800
+ {
1801
+ "fn": "escapeString",
1802
+ "args": [
1803
+ {
1804
+ "get": "node.caseName"
1805
+ }
1806
+ ]
1807
+ },
1808
+ {
1809
+ "map": "node.fields",
1810
+ "sep": "",
1811
+ "item": {
1812
+ "tmpl": [
1813
+ ", ",
1814
+ {
1815
+ "fn": "escapeString",
1816
+ "args": [
1817
+ {
1818
+ "get": "item.name"
1819
+ }
1820
+ ]
1821
+ },
1822
+ ": ",
1823
+ {
1824
+ "emit": "item.value"
1825
+ }
1826
+ ]
1827
+ }
1828
+ },
1829
+ "}"
1830
+ ]
1831
+ },
1832
+ "Unary": {
1833
+ "case": {
1834
+ "when": [
1835
+ [
1836
+ {
1837
+ "and": [
1838
+ {
1839
+ "eq": [
1840
+ "node.op",
1841
+ "-"
1842
+ ]
1843
+ },
1844
+ {
1845
+ "eq": [
1846
+ "node.typeIsInt",
1847
+ "true"
1848
+ ]
1849
+ }
1850
+ ]
1851
+ },
1852
+ {
1853
+ "fn": "wrap",
1854
+ "args": [
1855
+ {
1856
+ "get": "node.type"
1857
+ },
1858
+ {
1859
+ "tmpl": [
1860
+ "-",
1861
+ {
1862
+ "emitChild": "node.operand",
1863
+ "side": "unary"
1864
+ }
1865
+ ]
1866
+ }
1867
+ ]
1868
+ }
1869
+ ],
1870
+ [
1871
+ {
1872
+ "eq": [
1873
+ "node.op",
1874
+ "!"
1875
+ ]
1876
+ },
1877
+ {
1878
+ "tmpl": [
1879
+ "not ",
1880
+ {
1881
+ "emitChild": "node.operand",
1882
+ "side": "unary"
1883
+ }
1884
+ ]
1885
+ }
1886
+ ]
1887
+ ],
1888
+ "else": {
1889
+ "tmpl": [
1890
+ {
1891
+ "get": "node.op"
1892
+ },
1893
+ {
1894
+ "emitChild": "node.operand",
1895
+ "side": "unary"
1896
+ }
1897
+ ]
1898
+ }
1899
+ }
1900
+ },
1901
+ "Cast": {
1902
+ "case": {
1903
+ "when": [
1904
+ [
1905
+ {
1906
+ "and": [
1907
+ {
1908
+ "eq": [
1909
+ "node.typeIsFloat",
1910
+ "true"
1911
+ ]
1912
+ },
1913
+ {
1914
+ "eq": [
1915
+ "node.fromIsInt",
1916
+ "true"
1917
+ ]
1918
+ }
1919
+ ]
1920
+ },
1921
+ {
1922
+ "tmpl": [
1923
+ "float(",
1924
+ {
1925
+ "emit": "node.operand"
1926
+ },
1927
+ ")"
1928
+ ]
1929
+ }
1930
+ ],
1931
+ [
1932
+ {
1933
+ "eq": [
1934
+ "node.typeIsFloat",
1935
+ "true"
1936
+ ]
1937
+ },
1938
+ {
1939
+ "emit": "node.operand"
1940
+ }
1941
+ ],
1942
+ [
1943
+ {
1944
+ "and": [
1945
+ {
1946
+ "eq": [
1947
+ "node.typeIsInt",
1948
+ "true"
1949
+ ]
1950
+ },
1951
+ {
1952
+ "eq": [
1953
+ "node.fromIsFloat",
1954
+ "true"
1955
+ ]
1956
+ }
1957
+ ]
1958
+ },
1959
+ {
1960
+ "tmpl": [
1961
+ "int(",
1962
+ {
1963
+ "emit": "node.operand"
1964
+ },
1965
+ ")"
1966
+ ]
1967
+ }
1968
+ ]
1969
+ ],
1970
+ "else": {
1971
+ "emit": "node.operand"
1972
+ }
1973
+ }
1974
+ },
1975
+ "With": {
1976
+ "case": {
1977
+ "when": [
1978
+ [
1979
+ {
1980
+ "eq": [
1981
+ "node.baseIsSimple",
1982
+ "true"
1983
+ ]
1984
+ },
1985
+ {
1986
+ "tmpl": [
1987
+ {
1988
+ "get": "node.type"
1989
+ },
1990
+ "(",
1991
+ {
1992
+ "map": "node.ctorArgs",
1993
+ "sep": ", "
1994
+ },
1995
+ ")"
1996
+ ]
1997
+ }
1998
+ ]
1999
+ ],
2000
+ "else": {
2001
+ "tmpl": [
2002
+ "(lambda ",
2003
+ {
2004
+ "get": "node.tempName"
2005
+ },
2006
+ ": ",
2007
+ {
2008
+ "get": "node.type"
2009
+ },
2010
+ "(",
2011
+ {
2012
+ "map": "node.ctorArgs",
2013
+ "sep": ", "
2014
+ },
2015
+ "))(",
2016
+ {
2017
+ "emit": "node.base"
2018
+ },
2019
+ ")"
2020
+ ]
2021
+ }
2022
+ }
2023
+ },
2024
+ "Interp": {
2025
+ "interleave": {
2026
+ "lits": "node.chunks",
2027
+ "holes": "node.holes",
2028
+ "lit": {
2029
+ "fn": "escapeString",
2030
+ "args": [
2031
+ {
2032
+ "get": "item"
2033
+ }
2034
+ ]
2035
+ },
2036
+ "hole": {
2037
+ "tmpl": [
2038
+ " + str(",
2039
+ {
2040
+ "emit": "item"
2041
+ },
2042
+ ") + "
2043
+ ]
2044
+ }
2045
+ }
2046
+ },
2047
+ "MethodCall": {
2048
+ "case": {
2049
+ "when": [
2050
+ [
2051
+ {
2052
+ "eq": [
2053
+ "node.isExtension",
2054
+ "true"
2055
+ ]
2056
+ },
2057
+ {
2058
+ "tmpl": [
2059
+ {
2060
+ "fn": "ident",
2061
+ "args": [
2062
+ {
2063
+ "get": "node.method"
2064
+ }
2065
+ ]
2066
+ },
2067
+ "(",
2068
+ {
2069
+ "emit": "node.object"
2070
+ },
2071
+ {
2072
+ "case": {
2073
+ "when": [
2074
+ [
2075
+ {
2076
+ "eq": [
2077
+ "node.args.count",
2078
+ "0"
2079
+ ]
2080
+ },
2081
+ ""
2082
+ ]
2083
+ ],
2084
+ "else": {
2085
+ "tmpl": [
2086
+ ", ",
2087
+ {
2088
+ "map": "node.args",
2089
+ "sep": ", "
2090
+ }
2091
+ ]
2092
+ }
2093
+ }
2094
+ },
2095
+ ")"
2096
+ ]
2097
+ }
2098
+ ]
2099
+ ],
2100
+ "else": {
2101
+ "tmpl": [
2102
+ {
2103
+ "case": {
2104
+ "when": [
2105
+ [
2106
+ {
2107
+ "has": "node.staticType"
2108
+ },
2109
+ {
2110
+ "get": "node.staticType"
2111
+ }
2112
+ ]
2113
+ ],
2114
+ "else": {
2115
+ "emitChild": "node.object",
2116
+ "side": "recv"
2117
+ }
2118
+ }
2119
+ },
2120
+ ".",
2121
+ {
2122
+ "fn": "ident",
2123
+ "args": [
2124
+ {
2125
+ "get": "node.method"
2126
+ }
2127
+ ]
2128
+ },
2129
+ "(",
2130
+ {
2131
+ "map": "node.args",
2132
+ "sep": ", "
2133
+ },
2134
+ ")"
2135
+ ]
2136
+ }
2137
+ }
2138
+ },
2139
+ "Match": {
2140
+ "tmpl": [
2141
+ "(lambda _m: ",
2142
+ {
2143
+ "fold": {
2144
+ "list": "node.arms",
2145
+ "seed": {
2146
+ "call": "pyArmValue"
2147
+ },
2148
+ "each": {
2149
+ "tmpl": [
2150
+ {
2151
+ "call": "pyArmValue"
2152
+ },
2153
+ " if ",
2154
+ {
2155
+ "call": "pyArmCond"
2156
+ },
2157
+ " else ",
2158
+ {
2159
+ "get": "acc"
2160
+ }
2161
+ ]
2162
+ }
2163
+ }
2164
+ },
2165
+ ")(",
2166
+ {
2167
+ "emit": "node.scrutinee"
2168
+ },
2169
+ ")"
2170
+ ]
2171
+ },
2172
+ "pyArmValue": {
2173
+ "case": {
2174
+ "when": [
2175
+ [
2176
+ {
2177
+ "eq": [
2178
+ "item.pattern.kind",
2179
+ "binding"
2180
+ ]
2181
+ },
2182
+ {
2183
+ "tmpl": [
2184
+ "(lambda ",
2185
+ {
2186
+ "fn": "ident",
2187
+ "args": [
2188
+ {
2189
+ "get": "item.pattern.binding"
2190
+ }
2191
+ ]
2192
+ },
2193
+ ": ",
2194
+ {
2195
+ "emit": "item.body"
2196
+ },
2197
+ ")(_m)"
2198
+ ]
2199
+ }
2200
+ ],
2201
+ [
2202
+ {
2203
+ "and": [
2204
+ {
2205
+ "eq": [
2206
+ "item.pattern.kind",
2207
+ "ctor"
2208
+ ]
2209
+ },
2210
+ {
2211
+ "not": {
2212
+ "eq": [
2213
+ "item.pattern.binders.count",
2214
+ "0"
2215
+ ]
2216
+ }
2217
+ }
2218
+ ]
2219
+ },
2220
+ {
2221
+ "tmpl": [
2222
+ "(lambda ",
2223
+ {
2224
+ "map": "item.pattern.binders",
2225
+ "sep": ", ",
2226
+ "item": {
2227
+ "fn": "ident",
2228
+ "args": [
2229
+ {
2230
+ "get": "item.binding"
2231
+ }
2232
+ ]
2233
+ }
2234
+ },
2235
+ ": ",
2236
+ {
2237
+ "emit": "item.body"
2238
+ },
2239
+ ")(",
2240
+ {
2241
+ "map": "item.pattern.binders",
2242
+ "sep": ", ",
2243
+ "item": {
2244
+ "tmpl": [
2245
+ "_m[\"",
2246
+ {
2247
+ "get": "item.field"
2248
+ },
2249
+ "\"]"
2250
+ ]
2251
+ }
2252
+ },
2253
+ ")"
2254
+ ]
2255
+ }
2256
+ ]
2257
+ ],
2258
+ "else": {
2259
+ "emit": "item.body"
2260
+ }
2261
+ }
2262
+ },
2263
+ "pyArmGuard": {
2264
+ "case": {
2265
+ "when": [
2266
+ [
2267
+ {
2268
+ "eq": [
2269
+ "item.pattern.kind",
2270
+ "binding"
2271
+ ]
2272
+ },
2273
+ {
2274
+ "tmpl": [
2275
+ "(lambda ",
2276
+ {
2277
+ "fn": "ident",
2278
+ "args": [
2279
+ {
2280
+ "get": "item.pattern.binding"
2281
+ }
2282
+ ]
2283
+ },
2284
+ ": ",
2285
+ {
2286
+ "emit": "item.guard"
2287
+ },
2288
+ ")(_m)"
2289
+ ]
2290
+ }
2291
+ ],
2292
+ [
2293
+ {
2294
+ "and": [
2295
+ {
2296
+ "eq": [
2297
+ "item.pattern.kind",
2298
+ "ctor"
2299
+ ]
2300
+ },
2301
+ {
2302
+ "not": {
2303
+ "eq": [
2304
+ "item.pattern.binders.count",
2305
+ "0"
2306
+ ]
2307
+ }
2308
+ }
2309
+ ]
2310
+ },
2311
+ {
2312
+ "tmpl": [
2313
+ "(lambda ",
2314
+ {
2315
+ "map": "item.pattern.binders",
2316
+ "sep": ", ",
2317
+ "item": {
2318
+ "fn": "ident",
2319
+ "args": [
2320
+ {
2321
+ "get": "item.binding"
2322
+ }
2323
+ ]
2324
+ }
2325
+ },
2326
+ ": ",
2327
+ {
2328
+ "emit": "item.guard"
2329
+ },
2330
+ ")(",
2331
+ {
2332
+ "map": "item.pattern.binders",
2333
+ "sep": ", ",
2334
+ "item": {
2335
+ "tmpl": [
2336
+ "_m[\"",
2337
+ {
2338
+ "get": "item.field"
2339
+ },
2340
+ "\"]"
2341
+ ]
2342
+ }
2343
+ },
2344
+ ")"
2345
+ ]
2346
+ }
2347
+ ]
2348
+ ],
2349
+ "else": {
2350
+ "emit": "item.guard"
2351
+ }
2352
+ }
2353
+ },
2354
+ "pyArmBase": {
2355
+ "case": {
2356
+ "when": [
2357
+ [
2358
+ {
2359
+ "eq": [
2360
+ "item.pattern.kind",
2361
+ "literal"
2362
+ ]
2363
+ },
2364
+ {
2365
+ "tmpl": [
2366
+ "_m == ",
2367
+ {
2368
+ "emit": "item.pattern.literal"
2369
+ }
2370
+ ]
2371
+ }
2372
+ ],
2373
+ [
2374
+ {
2375
+ "eq": [
2376
+ "item.pattern.kind",
2377
+ "enumCase"
2378
+ ]
2379
+ },
2380
+ {
2381
+ "tmpl": [
2382
+ "_m == ",
2383
+ {
2384
+ "get": "item.pattern.enumType"
2385
+ },
2386
+ ".",
2387
+ {
2388
+ "get": "item.pattern.enumCase"
2389
+ }
2390
+ ]
2391
+ }
2392
+ ],
2393
+ [
2394
+ {
2395
+ "eq": [
2396
+ "item.pattern.kind",
2397
+ "ctor"
2398
+ ]
2399
+ },
2400
+ {
2401
+ "tmpl": [
2402
+ "_m[\"tag\"] == ",
2403
+ {
2404
+ "fn": "escapeString",
2405
+ "args": [
2406
+ {
2407
+ "get": "item.pattern.ctorCase"
2408
+ }
2409
+ ]
2410
+ }
2411
+ ]
2412
+ }
2413
+ ]
2414
+ ],
2415
+ "else": "True"
2416
+ }
2417
+ },
2418
+ "pyArmCond": {
2419
+ "case": {
2420
+ "when": [
2421
+ [
2422
+ {
2423
+ "eq": [
2424
+ "item.hasGuard",
2425
+ "false"
2426
+ ]
2427
+ },
2428
+ {
2429
+ "call": "pyArmBase"
2430
+ }
2431
+ ],
2432
+ [
2433
+ {
2434
+ "or": [
2435
+ {
2436
+ "eq": [
2437
+ "item.pattern.kind",
2438
+ "wildcard"
2439
+ ]
2440
+ },
2441
+ {
2442
+ "eq": [
2443
+ "item.pattern.kind",
2444
+ "binding"
2445
+ ]
2446
+ }
2447
+ ]
2448
+ },
2449
+ {
2450
+ "call": "pyArmGuard"
2451
+ }
2452
+ ]
2453
+ ],
2454
+ "else": {
2455
+ "tmpl": [
2456
+ {
2457
+ "call": "pyArmBase"
2458
+ },
2459
+ " and ",
2460
+ {
2461
+ "call": "pyArmGuard"
2462
+ }
2463
+ ]
2464
+ }
2465
+ }
2466
+ },
2467
+ "Binary": {
2468
+ "case": {
2469
+ "when": [
2470
+ [
2471
+ {
2472
+ "eq": [
2473
+ "node.op",
2474
+ "??"
2475
+ ]
2476
+ },
2477
+ {
2478
+ "fresh": {
2479
+ "prefix": "__c",
2480
+ "as": "t",
2481
+ "in": {
2482
+ "tmpl": [
2483
+ "(",
2484
+ {
2485
+ "get": "t"
2486
+ },
2487
+ " if (",
2488
+ {
2489
+ "get": "t"
2490
+ },
2491
+ " := ",
2492
+ {
2493
+ "emit": "node.lhs"
2494
+ },
2495
+ ") is not None else ",
2496
+ {
2497
+ "emit": "node.rhs"
2498
+ },
2499
+ ")"
2500
+ ]
2501
+ }
2502
+ }
2503
+ }
2504
+ ],
2505
+ [
2506
+ {
2507
+ "and": [
2508
+ {
2509
+ "eq": [
2510
+ "node.typeIsInt",
2511
+ "true"
2512
+ ]
2513
+ },
2514
+ {
2515
+ "or": [
2516
+ {
2517
+ "eq": [
2518
+ "node.op",
2519
+ "+"
2520
+ ]
2521
+ },
2522
+ {
2523
+ "eq": [
2524
+ "node.op",
2525
+ "-"
2526
+ ]
2527
+ },
2528
+ {
2529
+ "eq": [
2530
+ "node.op",
2531
+ "*"
2532
+ ]
2533
+ },
2534
+ {
2535
+ "eq": [
2536
+ "node.op",
2537
+ "/"
2538
+ ]
2539
+ },
2540
+ {
2541
+ "eq": [
2542
+ "node.op",
2543
+ "%"
2544
+ ]
2545
+ }
2546
+ ]
2547
+ }
2548
+ ]
2549
+ },
2550
+ {
2551
+ "fn": "wrap",
2552
+ "args": [
2553
+ {
2554
+ "get": "node.type"
2555
+ },
2556
+ {
2557
+ "case": {
2558
+ "when": [
2559
+ [
2560
+ {
2561
+ "eq": [
2562
+ "node.op",
2563
+ "/"
2564
+ ]
2565
+ },
2566
+ {
2567
+ "tmpl": [
2568
+ {
2569
+ "fn": "require",
2570
+ "args": [
2571
+ "idiv"
2572
+ ]
2573
+ },
2574
+ "_pg_idiv(",
2575
+ {
2576
+ "emit": "node.lhs"
2577
+ },
2578
+ ", ",
2579
+ {
2580
+ "emit": "node.rhs"
2581
+ },
2582
+ ")"
2583
+ ]
2584
+ }
2585
+ ],
2586
+ [
2587
+ {
2588
+ "eq": [
2589
+ "node.op",
2590
+ "%"
2591
+ ]
2592
+ },
2593
+ {
2594
+ "tmpl": [
2595
+ {
2596
+ "fn": "require",
2597
+ "args": [
2598
+ "idiv"
2599
+ ]
2600
+ },
2601
+ "_pg_irem(",
2602
+ {
2603
+ "emit": "node.lhs"
2604
+ },
2605
+ ", ",
2606
+ {
2607
+ "emit": "node.rhs"
2608
+ },
2609
+ ")"
2610
+ ]
2611
+ }
2612
+ ]
2613
+ ],
2614
+ "else": {
2615
+ "tmpl": [
2616
+ {
2617
+ "emitChild": "node.lhs",
2618
+ "side": "l"
2619
+ },
2620
+ " ",
2621
+ {
2622
+ "get": "node.op"
2623
+ },
2624
+ " ",
2625
+ {
2626
+ "emitChild": "node.rhs",
2627
+ "side": "r"
2628
+ }
2629
+ ]
2630
+ }
2631
+ }
2632
+ }
2633
+ ]
2634
+ }
2635
+ ]
2636
+ ],
2637
+ "else": {
2638
+ "tmpl": [
2639
+ {
2640
+ "emitChild": "node.lhs",
2641
+ "side": "l"
2642
+ },
2643
+ " ",
2644
+ {
2645
+ "fn": "opSpelling",
2646
+ "args": [
2647
+ {
2648
+ "get": "node.op"
2649
+ }
2650
+ ]
2651
+ },
2652
+ " ",
2653
+ {
2654
+ "emitChild": "node.rhs",
2655
+ "side": "r"
2656
+ }
2657
+ ]
2658
+ }
2659
+ }
2660
+ },
2661
+ "Char": {
2662
+ "fn": "escapeString",
2663
+ "args": [
2664
+ {
2665
+ "get": "node.value"
2666
+ }
2667
+ ]
2668
+ }
2669
+ },
2670
+ "std": {
2671
+ "std.collections": {
2672
+ "List.type": "list",
2673
+ "List.init": "[]",
2674
+ "List.count": "len($this)",
2675
+ "List.add": "$this.append($0)",
2676
+ "List.clear": "$this = []",
2677
+ "List.removeAll": "$this = [__e for __e in $this if not (($0)(__e))]",
2678
+ "List.removeAt": "$this.pop($0)"
2679
+ },
2680
+ "std.io": {
2681
+ "print": "__builtins__.print(str(x).lower() if isinstance(x, bool) else x)"
2682
+ },
2683
+ "std.math": {
2684
+ "Math.PI": "__import__('math').pi",
2685
+ "Math.E": "__import__('math').e",
2686
+ "Math.sqrt": "__import__('math').sqrt($0)",
2687
+ "Math.ln": "__import__('math').log($0)",
2688
+ "Math.floor": "float(__import__('math').floor($0))",
2689
+ "Math.ceil": "float(__import__('math').ceil($0))",
2690
+ "Math.min": "min($0, $1)",
2691
+ "Math.max": "max($0, $1)",
2692
+ "Math.abs": "abs($0)",
2693
+ "Math.round": "float(round($0))"
2694
+ },
2695
+ "std.strings": {
2696
+ "string.isEmpty": "(len($this) == 0)",
2697
+ "string.len": "len($this)",
2698
+ "string.toUpper": "$this.upper()",
2699
+ "string.toLower": "$this.lower()",
2700
+ "string.charAt": "$this[$0]",
2701
+ "string.codePoints": "list($this)",
2702
+ "string.toI32": "int($this)"
2703
+ },
2704
+ "std.core": {
2705
+ "Error.type": "Exception",
2706
+ "Error.init": "$T($0)",
2707
+ "Error.message": "str($this)",
2708
+ "Iterable.type": "list",
2709
+ "i8.parse": "int($0)",
2710
+ "i16.parse": "int($0)",
2711
+ "i32.parse": "int($0)",
2712
+ "i64.parse": "int($0)",
2713
+ "u8.parse": "int($0)",
2714
+ "u16.parse": "int($0)",
2715
+ "u32.parse": "int($0)",
2716
+ "u64.parse": "int($0)",
2717
+ "f32.parse": "float($0)",
2718
+ "f64.parse": "float($0)"
2719
+ }
2720
+ },
2721
+ "fileExtension": ".py"
2722
+ }