jaclang 0.4.7__py3-none-any.whl → 0.5.0__py3-none-any.whl

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.

Potentially problematic release.


This version of jaclang might be problematic. Click here for more details.

Files changed (152) hide show
  1. jaclang/__init__.py +5 -2
  2. jaclang/cli/cli.py +56 -8
  3. jaclang/cli/cmdreg.py +16 -9
  4. jaclang/compiler/__jac_gen__/jac_parser.py +11 -15
  5. jaclang/compiler/absyntree.py +53 -19
  6. jaclang/compiler/codeloc.py +3 -1
  7. jaclang/compiler/{transpiler.py → compile.py} +3 -2
  8. jaclang/compiler/constant.py +4 -0
  9. jaclang/compiler/parser.py +156 -108
  10. jaclang/compiler/passes/ir_pass.py +1 -0
  11. jaclang/compiler/passes/main/__init__.py +2 -1
  12. jaclang/compiler/passes/main/def_impl_match_pass.py +1 -0
  13. jaclang/compiler/passes/main/def_use_pass.py +1 -0
  14. jaclang/compiler/passes/main/import_pass.py +18 -18
  15. jaclang/compiler/passes/main/pyast_gen_pass.py +1228 -853
  16. jaclang/compiler/passes/main/pyast_load_pass.py +3 -1
  17. jaclang/compiler/passes/main/pybc_gen_pass.py +46 -0
  18. jaclang/compiler/passes/main/pyout_pass.py +6 -7
  19. jaclang/compiler/passes/main/schedules.py +5 -9
  20. jaclang/compiler/passes/main/sub_node_tab_pass.py +1 -0
  21. jaclang/compiler/passes/main/sym_tab_build_pass.py +21 -9
  22. jaclang/compiler/passes/main/tests/test_decl_def_match_pass.py +2 -1
  23. jaclang/compiler/passes/main/tests/test_def_use_pass.py +2 -1
  24. jaclang/compiler/passes/main/tests/test_import_pass.py +2 -1
  25. jaclang/compiler/passes/main/tests/test_pyast_build_pass.py +1 -0
  26. jaclang/compiler/passes/main/tests/test_pyast_gen_pass.py +15 -38
  27. jaclang/compiler/passes/main/tests/test_pybc_gen_pass.py +25 -0
  28. jaclang/compiler/passes/main/tests/test_sub_node_pass.py +1 -1
  29. jaclang/compiler/passes/main/tests/test_sym_tab_build_pass.py +2 -1
  30. jaclang/compiler/passes/main/tests/test_type_check_pass.py +17 -1
  31. jaclang/compiler/passes/main/type_check_pass.py +9 -6
  32. jaclang/compiler/passes/tool/__init__.py +1 -0
  33. jaclang/compiler/passes/tool/ast_printer_pass.py +1 -0
  34. jaclang/compiler/passes/tool/fuse_comments_pass.py +1 -1
  35. jaclang/compiler/passes/tool/jac_formatter_pass.py +69 -32
  36. jaclang/compiler/passes/tool/schedules.py +1 -0
  37. jaclang/compiler/passes/tool/sym_tab_printer_pass.py +1 -0
  38. jaclang/compiler/passes/tool/tests/test_ast_print_pass.py +2 -1
  39. jaclang/compiler/passes/tool/tests/test_fuse_comments_pass.py +1 -0
  40. jaclang/compiler/passes/tool/tests/test_jac_format_pass.py +4 -3
  41. jaclang/compiler/passes/tool/tests/test_symtab_print_pass.py +2 -1
  42. jaclang/compiler/passes/transform.py +1 -0
  43. jaclang/compiler/passes/utils/mypy_ast_build.py +203 -17
  44. jaclang/compiler/symtable.py +1 -0
  45. jaclang/compiler/tests/test_importer.py +3 -2
  46. jaclang/compiler/tests/test_parser.py +1 -0
  47. jaclang/compiler/tests/test_workspace.py +1 -0
  48. jaclang/compiler/workspace.py +18 -5
  49. jaclang/core/construct.py +9 -32
  50. jaclang/{compiler → core}/importer.py +95 -85
  51. jaclang/core/utils.py +17 -12
  52. jaclang/plugin/__init__.py +1 -0
  53. jaclang/plugin/default.py +145 -43
  54. jaclang/plugin/feature.py +65 -19
  55. jaclang/plugin/spec.py +56 -34
  56. jaclang/plugin/tests/test_features.py +9 -0
  57. jaclang/utils/helpers.py +1 -0
  58. jaclang/utils/lang_tools.py +13 -19
  59. jaclang/utils/tests/test_lang_tools.py +2 -1
  60. jaclang/utils/treeprinter.py +2 -1
  61. jaclang/vendor/lark/common.py +3 -1
  62. jaclang/vendor/lark/lexer.py +6 -12
  63. jaclang/vendor/lark/parsers/lalr_parser.py +1 -0
  64. jaclang/vendor/mypy/applytype.py +2 -1
  65. jaclang/vendor/mypy/binder.py +1 -1
  66. jaclang/vendor/mypy/build.py +7 -9
  67. jaclang/vendor/mypy/checker.py +57 -33
  68. jaclang/vendor/mypy/checkexpr.py +42 -29
  69. jaclang/vendor/mypy/checkmember.py +13 -1
  70. jaclang/vendor/mypy/checkpattern.py +1 -1
  71. jaclang/vendor/mypy/checkstrformat.py +2 -4
  72. jaclang/vendor/mypy/constraints.py +10 -5
  73. jaclang/vendor/mypy/dmypy_server.py +3 -3
  74. jaclang/vendor/mypy/dmypy_util.py +62 -3
  75. jaclang/vendor/mypy/errors.py +1 -1
  76. jaclang/vendor/mypy/evalexpr.py +1 -0
  77. jaclang/vendor/mypy/expandtype.py +29 -29
  78. jaclang/vendor/mypy/fastparse.py +51 -31
  79. jaclang/vendor/mypy/inspections.py +5 -3
  80. jaclang/vendor/mypy/join.py +4 -4
  81. jaclang/vendor/mypy/main.py +6 -6
  82. jaclang/vendor/mypy/message_registry.py +1 -2
  83. jaclang/vendor/mypy/messages.py +31 -23
  84. jaclang/vendor/mypy/metastore.py +1 -2
  85. jaclang/vendor/mypy/modulefinder.py +2 -22
  86. jaclang/vendor/mypy/nodes.py +22 -20
  87. jaclang/vendor/mypy/options.py +4 -0
  88. jaclang/vendor/mypy/parse.py +6 -2
  89. jaclang/vendor/mypy/patterns.py +6 -6
  90. jaclang/vendor/mypy/plugin.py +3 -1
  91. jaclang/vendor/mypy/plugins/attrs.py +52 -10
  92. jaclang/vendor/mypy/plugins/common.py +2 -1
  93. jaclang/vendor/mypy/plugins/enums.py +3 -2
  94. jaclang/vendor/mypy/plugins/functools.py +1 -0
  95. jaclang/vendor/mypy/renaming.py +1 -1
  96. jaclang/vendor/mypy/report.py +15 -15
  97. jaclang/vendor/mypy/semanal.py +22 -13
  98. jaclang/vendor/mypy/semanal_enum.py +1 -1
  99. jaclang/vendor/mypy/semanal_namedtuple.py +1 -2
  100. jaclang/vendor/mypy/semanal_shared.py +3 -6
  101. jaclang/vendor/mypy/semanal_typeddict.py +16 -5
  102. jaclang/vendor/mypy/server/astdiff.py +15 -9
  103. jaclang/vendor/mypy/server/astmerge.py +5 -5
  104. jaclang/vendor/mypy/stats.py +0 -5
  105. jaclang/vendor/mypy/stubdoc.py +1 -1
  106. jaclang/vendor/mypy/stubgen.py +12 -21
  107. jaclang/vendor/mypy/stubgenc.py +16 -8
  108. jaclang/vendor/mypy/stubtest.py +57 -48
  109. jaclang/vendor/mypy/stubutil.py +28 -15
  110. jaclang/vendor/mypy/subtypes.py +4 -4
  111. jaclang/vendor/mypy/test/helpers.py +2 -2
  112. jaclang/vendor/mypy/test/meta/test_parse_data.py +1 -0
  113. jaclang/vendor/mypy/test/meta/test_update_data.py +1 -0
  114. jaclang/vendor/mypy/test/testargs.py +1 -0
  115. jaclang/vendor/mypy/test/testcheck.py +4 -1
  116. jaclang/vendor/mypy/test/testconstraints.py +25 -7
  117. jaclang/vendor/mypy/test/testerrorstream.py +1 -0
  118. jaclang/vendor/mypy/test/testformatter.py +2 -2
  119. jaclang/vendor/mypy/test/testparse.py +6 -4
  120. jaclang/vendor/mypy/test/testpythoneval.py +1 -0
  121. jaclang/vendor/mypy/test/testreports.py +1 -0
  122. jaclang/vendor/mypy/test/teststubgen.py +1 -2
  123. jaclang/vendor/mypy/test/teststubtest.py +98 -4
  124. jaclang/vendor/mypy/test/testtypes.py +1 -1
  125. jaclang/vendor/mypy/test/testutil.py +22 -0
  126. jaclang/vendor/mypy/typeanal.py +302 -158
  127. jaclang/vendor/mypy/typeops.py +22 -13
  128. jaclang/vendor/mypy/types.py +33 -34
  129. jaclang/vendor/mypy/typestate.py +2 -2
  130. jaclang/vendor/mypy/util.py +7 -6
  131. jaclang/vendor/mypy/version.py +1 -1
  132. jaclang/vendor/mypyc/analysis/ircheck.py +1 -0
  133. jaclang/vendor/mypyc/codegen/emitfunc.py +5 -3
  134. jaclang/vendor/mypyc/codegen/emitmodule.py +12 -12
  135. jaclang/vendor/mypyc/codegen/emitwrapper.py +2 -2
  136. jaclang/vendor/mypyc/ir/class_ir.py +10 -6
  137. jaclang/vendor/mypyc/irbuild/builder.py +3 -4
  138. jaclang/vendor/mypyc/irbuild/function.py +5 -3
  139. jaclang/vendor/mypyc/irbuild/nonlocalcontrol.py +1 -2
  140. jaclang/vendor/mypyc/irbuild/prepare.py +6 -6
  141. jaclang/vendor/mypyc/primitives/registry.py +15 -5
  142. jaclang/vendor/mypyc/test/test_run.py +1 -2
  143. jaclang/vendor/mypyc/transform/uninit.py +3 -3
  144. jaclang/vendor/pluggy/_callers.py +1 -0
  145. jaclang/vendor/pluggy/_hooks.py +6 -10
  146. jaclang/vendor/pluggy/_result.py +1 -0
  147. jaclang/vendor/pluggy/_tracing.py +1 -0
  148. {jaclang-0.4.7.dist-info → jaclang-0.5.0.dist-info}/METADATA +1 -1
  149. {jaclang-0.4.7.dist-info → jaclang-0.5.0.dist-info}/RECORD +152 -150
  150. {jaclang-0.4.7.dist-info → jaclang-0.5.0.dist-info}/WHEEL +0 -0
  151. {jaclang-0.4.7.dist-info → jaclang-0.5.0.dist-info}/entry_points.txt +0 -0
  152. {jaclang-0.4.7.dist-info → jaclang-0.5.0.dist-info}/top_level.txt +0 -0
@@ -1,10 +1,11 @@
1
1
  """Lark parser for Jac Lang."""
2
+
2
3
  from __future__ import annotations
3
4
 
4
5
 
5
6
  import logging
6
7
  import os
7
- from typing import Callable, TypeAlias
8
+ from typing import Callable, TypeAlias, cast
8
9
 
9
10
 
10
11
  import jaclang.compiler.absyntree as ast
@@ -281,26 +282,20 @@ class JacParser(Pass):
281
282
  """Grammar rule.
282
283
 
283
284
  import_stmt: KW_IMPORT sub_name KW_FROM import_path COMMA import_items SEMI
284
- | KW_IMPORT sub_name import_path SEMI
285
+ | KW_IMPORT sub_name import_path (COMMA import_path)* SEMI
285
286
  """
286
287
  lang = kid[1]
287
- path = kid[3] if isinstance(kid[3], ast.ModulePath) else kid[2]
288
+ paths = [i for i in kid if isinstance(i, ast.ModulePath)]
288
289
 
289
- items = (
290
- kid[-2]
291
- if len(kid) > 4 and isinstance(kid[-2], ast.SubNodeList)
292
- else None
293
- )
290
+ items = kid[-2] if isinstance(kid[-2], ast.SubNodeList) else None
294
291
  is_absorb = False
295
- if (
296
- isinstance(lang, ast.SubTag)
297
- and isinstance(path, ast.ModulePath)
298
- and (isinstance(items, ast.SubNodeList) or items is None)
292
+ if isinstance(lang, ast.SubTag) and (
293
+ isinstance(items, ast.SubNodeList) or items is None
299
294
  ):
300
295
  return self.nu(
301
296
  ast.Import(
302
297
  lang=lang,
303
- path=path,
298
+ paths=paths,
304
299
  items=items,
305
300
  is_absorb=is_absorb,
306
301
  kid=kid,
@@ -316,13 +311,13 @@ class JacParser(Pass):
316
311
  include_stmt: KW_INCLUDE sub_name import_path SEMI
317
312
  """
318
313
  lang = kid[1]
319
- path = kid[3] if isinstance(kid[3], ast.ModulePath) else kid[2]
314
+ paths = [i for i in kid if isinstance(i, ast.ModulePath)]
320
315
  is_absorb = True
321
- if isinstance(lang, ast.SubTag) and isinstance(path, ast.ModulePath):
316
+ if isinstance(lang, ast.SubTag):
322
317
  return self.nu(
323
318
  ast.Import(
324
319
  lang=lang,
325
- path=path,
320
+ paths=paths,
326
321
  items=None,
327
322
  is_absorb=is_absorb,
328
323
  kid=kid,
@@ -418,16 +413,12 @@ class JacParser(Pass):
418
413
  semstr = (
419
414
  kid[2]
420
415
  if (access and isinstance(kid[2], ast.String))
421
- else kid[1]
422
- if isinstance(kid[1], ast.String)
423
- else None
416
+ else kid[1] if isinstance(kid[1], ast.String) else None
424
417
  )
425
418
  name = (
426
419
  kid[3]
427
420
  if (access and semstr)
428
- else kid[2]
429
- if (access or semstr)
430
- else kid[1]
421
+ else kid[2] if (access or semstr) else kid[1]
431
422
  )
432
423
  inh = kid[-2] if isinstance(kid[-2], ast.SubNodeList) else None
433
424
  body = kid[-1] if isinstance(kid[-1], ast.SubNodeList) else None
@@ -584,16 +575,12 @@ class JacParser(Pass):
584
575
  semstr = (
585
576
  kid[2]
586
577
  if (access and isinstance(kid[2], ast.String))
587
- else kid[1]
588
- if isinstance(kid[1], ast.String)
589
- else None
578
+ else kid[1] if isinstance(kid[1], ast.String) else None
590
579
  )
591
580
  name = (
592
581
  kid[3]
593
582
  if (access and semstr)
594
- else kid[2]
595
- if (access or semstr)
596
- else kid[1]
583
+ else kid[2] if (access or semstr) else kid[1]
597
584
  )
598
585
  inh = kid[-2] if isinstance(kid[-2], ast.SubNodeList) else None
599
586
  body = kid[-1] if isinstance(kid[-1], ast.SubNodeList) else None
@@ -673,37 +660,49 @@ class JacParser(Pass):
673
660
  """Grammar rule.
674
661
 
675
662
  ability: decorators? ability_def
676
- | decorators? KW_ASYNC ability_decl
677
- | decorators? ability_decl
663
+ | decorators? KW_ASYNC? ability_decl
678
664
  """
679
- if isinstance(kid[0], ast.SubNodeList):
680
- if isinstance(kid[1], (ast.Ability, ast.AbilityDef)):
681
- for dec in kid[0].items:
682
- if (
683
- isinstance(dec, ast.NameSpec)
684
- and dec.sym_name == "staticmethod"
685
- and isinstance(kid[1], (ast.Ability))
686
- ):
687
- kid[1].is_static = True
688
- kid[0].items.remove(dec) # noqa: B038
689
- break
690
- if len(kid[0].items):
691
- kid[1].decorators = kid[0]
692
- kid[1].add_kids_left([kid[0]])
693
- return self.nu(kid[1])
694
- else:
695
- raise self.ice()
696
- elif isinstance(kid[0], (ast.Ability, ast.AbilityDef)):
697
- return self.nu(kid[0])
698
- else:
699
- raise self.ice()
665
+ chomp = [*kid]
666
+ decorators = chomp[0] if isinstance(chomp[0], ast.SubNodeList) else None
667
+ chomp = chomp[1:] if decorators else chomp
668
+ is_async = (
669
+ chomp[0]
670
+ if isinstance(chomp[0], ast.Token) and chomp[0].name == Tok.KW_ASYNC
671
+ else None
672
+ )
673
+ ability = chomp[1] if is_async else chomp[0]
674
+ if not isinstance(ability, (ast.Ability, ast.AbilityDef)):
675
+ raise self.ice()
676
+ if is_async and isinstance(ability, ast.Ability):
677
+ ability.is_async = True
678
+ ability.add_kids_left([is_async])
679
+ if isinstance(decorators, ast.SubNodeList):
680
+ for dec in decorators.items:
681
+ if (
682
+ isinstance(dec, ast.NameSpec)
683
+ and dec.sym_name == "staticmethod"
684
+ and isinstance(ability, (ast.Ability))
685
+ ):
686
+ ability.is_static = True
687
+ decorators.items.remove(dec) # noqa: B038
688
+ break
689
+ if len(decorators.items):
690
+ ability.decorators = decorators
691
+ ability.add_kids_left([decorators])
692
+ return self.nu(ability)
693
+ return self.nu(ability)
700
694
 
701
695
  def ability_decl(self, kid: list[ast.AstNode]) -> ast.Ability:
702
696
  """Grammar rule.
703
697
 
704
- ability_decl: KW_STATIC? KW_CAN access_tag? STRING? any_ref (func_decl | event_clause) (code_block | SEMI)
698
+ ability_decl: KW_OVERRIDE? KW_STATIC? KW_CAN access_tag? STRING?
699
+ any_ref (func_decl | event_clause) (code_block | SEMI)
705
700
  """
706
701
  chomp = [*kid]
702
+ is_override = (
703
+ isinstance(chomp[0], ast.Token) and chomp[0].name == Tok.KW_OVERRIDE
704
+ )
705
+ chomp = chomp[1:] if is_override else chomp
707
706
  is_static = (
708
707
  isinstance(chomp[0], ast.Token) and chomp[0].name == Tok.KW_STATIC
709
708
  )
@@ -726,6 +725,7 @@ class JacParser(Pass):
726
725
  name_ref=name,
727
726
  is_func=is_func,
728
727
  is_async=False,
728
+ is_override=is_override,
729
729
  is_static=is_static,
730
730
  is_abstract=False,
731
731
  access=access,
@@ -762,29 +762,23 @@ class JacParser(Pass):
762
762
  def abstract_ability(self, kid: list[ast.AstNode]) -> ast.Ability:
763
763
  """Grammar rule.
764
764
 
765
- abstract_ability: KW_STATIC? KW_CAN access_tag? STRING? any_ref (func_decl | event_clause) KW_ABSTRACT SEMI
765
+ abstract_ability: KW_OVERRIDE? KW_STATIC? KW_CAN access_tag? STRING?
766
+ any_ref (func_decl | event_clause) KW_ABSTRACT SEMI
766
767
  """
767
768
  chomp = [*kid]
769
+ is_override = (
770
+ isinstance(chomp[0], ast.Token) and chomp[0].name == Tok.KW_OVERRIDE
771
+ )
772
+ chomp = chomp[1:] if is_override else chomp
768
773
  is_static = (
769
774
  isinstance(chomp[0], ast.Token) and chomp[0].name == Tok.KW_STATIC
770
775
  )
771
776
  chomp = chomp[1:] if is_static else chomp
772
777
  chomp = chomp[1:]
773
778
  access = chomp[0] if isinstance(chomp[0], ast.SubTag) else None
774
- semstr = (
775
- chomp[1]
776
- if access and isinstance(chomp[1], ast.String)
777
- else chomp[0]
778
- if access or isinstance(chomp[1], ast.String)
779
- else None
780
- )
781
- chomp = (
782
- chomp[2:]
783
- if access and semstr
784
- else chomp[1:]
785
- if access or semstr
786
- else chomp
787
- )
779
+ chomp = chomp[1:] if access else chomp
780
+ semstr = chomp[0] if isinstance(chomp[0], ast.String) else None
781
+ chomp = chomp[1:] if semstr else chomp
788
782
  name = chomp[0]
789
783
  chomp = chomp[1:]
790
784
  is_func = isinstance(chomp[0], ast.FuncSignature)
@@ -798,6 +792,7 @@ class JacParser(Pass):
798
792
  name_ref=name,
799
793
  is_func=is_func,
800
794
  is_async=False,
795
+ is_override=is_override,
801
796
  is_static=is_static,
802
797
  is_abstract=True,
803
798
  access=access,
@@ -892,9 +887,7 @@ class JacParser(Pass):
892
887
  semstr = (
893
888
  kid[1]
894
889
  if (star and isinstance(kid[1], ast.String))
895
- else kid[0]
896
- if isinstance(kid[0], ast.String)
897
- else None
890
+ else kid[0] if isinstance(kid[0], ast.String) else None
898
891
  )
899
892
  name = (
900
893
  kid[2] if (star and semstr) else kid[1] if (star or semstr) else kid[0]
@@ -1182,10 +1175,12 @@ class JacParser(Pass):
1182
1175
  ast.IfStmt(
1183
1176
  condition=kid[1],
1184
1177
  body=kid[2],
1185
- else_body=kid[3]
1186
- if len(kid) > 3
1187
- and isinstance(kid[3], (ast.ElseStmt, ast.ElseIf))
1188
- else None,
1178
+ else_body=(
1179
+ kid[3]
1180
+ if len(kid) > 3
1181
+ and isinstance(kid[3], (ast.ElseStmt, ast.ElseIf))
1182
+ else None
1183
+ ),
1189
1184
  kid=kid,
1190
1185
  )
1191
1186
  )
@@ -1202,10 +1197,12 @@ class JacParser(Pass):
1202
1197
  ast.ElseIf(
1203
1198
  condition=kid[1],
1204
1199
  body=kid[2],
1205
- else_body=kid[3]
1206
- if len(kid) > 3
1207
- and isinstance(kid[3], (ast.ElseStmt, ast.ElseIf))
1208
- else None,
1200
+ else_body=(
1201
+ kid[3]
1202
+ if len(kid) > 3
1203
+ and isinstance(kid[3], (ast.ElseStmt, ast.ElseIf))
1204
+ else None
1205
+ ),
1209
1206
  kid=kid,
1210
1207
  )
1211
1208
  )
@@ -1339,9 +1336,11 @@ class JacParser(Pass):
1339
1336
  condition=chomp[3],
1340
1337
  count_by=chomp[5],
1341
1338
  body=chomp[6],
1342
- else_body=chomp[-1]
1343
- if isinstance(chomp[-1], ast.ElseStmt)
1344
- else None,
1339
+ else_body=(
1340
+ chomp[-1]
1341
+ if isinstance(chomp[-1], ast.ElseStmt)
1342
+ else None
1343
+ ),
1345
1344
  kid=kid,
1346
1345
  )
1347
1346
  )
@@ -1357,9 +1356,11 @@ class JacParser(Pass):
1357
1356
  target=chomp[1],
1358
1357
  collection=chomp[3],
1359
1358
  body=chomp[4],
1360
- else_body=chomp[-1]
1361
- if isinstance(chomp[-1], ast.ElseStmt)
1362
- else None,
1359
+ else_body=(
1360
+ chomp[-1]
1361
+ if isinstance(chomp[-1], ast.ElseStmt)
1362
+ else None
1363
+ ),
1363
1364
  kid=kid,
1364
1365
  )
1365
1366
  )
@@ -1471,9 +1472,9 @@ class JacParser(Pass):
1471
1472
  return self.nu(
1472
1473
  ast.AssertStmt(
1473
1474
  condition=condition,
1474
- error_msg=error_msg
1475
- if isinstance(error_msg, ast.Expr)
1476
- else None,
1475
+ error_msg=(
1476
+ error_msg if isinstance(error_msg, ast.Expr) else None
1477
+ ),
1477
1478
  kid=kid,
1478
1479
  )
1479
1480
  )
@@ -2035,9 +2036,7 @@ class JacParser(Pass):
2035
2036
  def unpack(self, kid: list[ast.AstNode]) -> ast.Expr:
2036
2037
  """Grammar rule.
2037
2038
 
2038
- unpack: ref
2039
- | STAR_MUL unpack
2040
- | STAR_POW unpack
2039
+ unpack: STAR_MUL? ref
2041
2040
  """
2042
2041
  if len(kid) == 2:
2043
2042
  if isinstance(kid[0], ast.Token) and isinstance(kid[1], ast.Expr):
@@ -2203,7 +2202,8 @@ class JacParser(Pass):
2203
2202
  elif len(kid[0].values.items) == 1:
2204
2203
  expr = kid[0].values.items[0] # TODO: Loses braces
2205
2204
  else:
2206
- expr = ast.TupleVal(values=kid[0].values, kid=kid[0].kid)
2205
+ vals = cast("ast.SubNodeList[ast.Expr|ast.KWPair]", kid[0].values)
2206
+ expr = ast.TupleVal(values=vals, kid=kid[0].kid)
2207
2207
  if expr is None:
2208
2208
  raise self.ice()
2209
2209
  return self.nu(
@@ -2388,9 +2388,11 @@ class JacParser(Pass):
2388
2388
  fstr_parts: (FSTR_PIECE | FSTR_BESC | LBRACE expression RBRACE | fstring)*
2389
2389
  """
2390
2390
  valid_parts: list[ast.String | ast.ExprStmt] = [
2391
- i
2392
- if isinstance(i, ast.String)
2393
- else ast.ExprStmt(expr=i, in_fstring=True, kid=[i])
2391
+ (
2392
+ i
2393
+ if isinstance(i, ast.String)
2394
+ else ast.ExprStmt(expr=i, in_fstring=True, kid=[i])
2395
+ )
2394
2396
  for i in kid
2395
2397
  if isinstance(i, ast.Expr)
2396
2398
  ]
@@ -2409,9 +2411,11 @@ class JacParser(Pass):
2409
2411
  fstr_sq_parts: (FSTR_SQ_PIECE | FSTR_BESC | LBRACE expression RBRACE )*
2410
2412
  """
2411
2413
  valid_parts: list[ast.String | ast.ExprStmt] = [
2412
- i
2413
- if isinstance(i, ast.String)
2414
- else ast.ExprStmt(expr=i, in_fstring=True, kid=[i])
2414
+ (
2415
+ i
2416
+ if isinstance(i, ast.String)
2417
+ else ast.ExprStmt(expr=i, in_fstring=True, kid=[i])
2418
+ )
2415
2419
  for i in kid
2416
2420
  if isinstance(i, ast.Expr)
2417
2421
  ]
@@ -2539,9 +2543,13 @@ class JacParser(Pass):
2539
2543
  def kw_expr(self, kid: list[ast.AstNode]) -> ast.KWPair:
2540
2544
  """Grammar rule.
2541
2545
 
2542
- kw_expr: any_ref EQ expression
2546
+ kw_expr: any_ref EQ expression | STAR_POW expression
2543
2547
  """
2544
- if isinstance(kid[0], ast.NameSpec) and isinstance(kid[2], ast.Expr):
2548
+ if (
2549
+ len(kid) == 3
2550
+ and isinstance(kid[0], ast.NameSpec)
2551
+ and isinstance(kid[2], ast.Expr)
2552
+ ):
2545
2553
  return self.nu(
2546
2554
  ast.KWPair(
2547
2555
  key=kid[0],
@@ -2549,6 +2557,14 @@ class JacParser(Pass):
2549
2557
  kid=kid,
2550
2558
  )
2551
2559
  )
2560
+ elif len(kid) == 2 and isinstance(kid[1], ast.Expr):
2561
+ return self.nu(
2562
+ ast.KWPair(
2563
+ key=None,
2564
+ value=kid[1],
2565
+ kid=kid,
2566
+ )
2567
+ )
2552
2568
  else:
2553
2569
  raise self.ice()
2554
2570
 
@@ -2625,9 +2641,13 @@ class JacParser(Pass):
2625
2641
  def kv_pair(self, kid: list[ast.AstNode]) -> ast.KVPair:
2626
2642
  """Grammar rule.
2627
2643
 
2628
- kv_pair: expression COLON expression
2644
+ kv_pair: expression COLON expression | STAR_POW expression
2629
2645
  """
2630
- if isinstance(kid[0], ast.Expr) and isinstance(kid[2], ast.Expr):
2646
+ if (
2647
+ len(kid) == 3
2648
+ and isinstance(kid[0], ast.Expr)
2649
+ and isinstance(kid[2], ast.Expr)
2650
+ ):
2631
2651
  return self.nu(
2632
2652
  ast.KVPair(
2633
2653
  key=kid[0],
@@ -2635,6 +2655,14 @@ class JacParser(Pass):
2635
2655
  kid=kid,
2636
2656
  )
2637
2657
  )
2658
+ elif len(kid) == 2 and isinstance(kid[1], ast.Expr):
2659
+ return self.nu(
2660
+ ast.KVPair(
2661
+ key=None,
2662
+ value=kid[1],
2663
+ kid=kid,
2664
+ )
2665
+ )
2638
2666
  else:
2639
2667
  raise self.ice()
2640
2668
 
@@ -2723,9 +2751,11 @@ class JacParser(Pass):
2723
2751
  is_async=is_async,
2724
2752
  target=chomp[0],
2725
2753
  collection=chomp[2],
2726
- conditional=chomp[4]
2727
- if len(chomp) > 4 and isinstance(chomp[4], ast.Expr)
2728
- else None,
2754
+ conditional=(
2755
+ chomp[4]
2756
+ if len(chomp) > 4 and isinstance(chomp[4], ast.Expr)
2757
+ else None
2758
+ ),
2729
2759
  kid=chomp,
2730
2760
  )
2731
2761
  )
@@ -2853,6 +2883,22 @@ class JacParser(Pass):
2853
2883
  else:
2854
2884
  raise self.ice()
2855
2885
 
2886
+ def class_ref(self, kid: list[ast.AstNode]) -> ast.ArchRef:
2887
+ """Grammar rule.
2888
+
2889
+ class_ref: CLASS_OP name_ref
2890
+ """
2891
+ if isinstance(kid[0], ast.Token) and isinstance(kid[1], ast.NameSpec):
2892
+ return self.nu(
2893
+ ast.ArchRef(
2894
+ arch=kid[0],
2895
+ name_ref=kid[1],
2896
+ kid=kid,
2897
+ )
2898
+ )
2899
+ else:
2900
+ raise self.ice()
2901
+
2856
2902
  def object_ref(self, kid: list[ast.AstNode]) -> ast.ArchRef:
2857
2903
  """Grammar rule.
2858
2904
 
@@ -3512,10 +3558,12 @@ class JacParser(Pass):
3512
3558
  second
3513
3559
  if isinstance(second, ast.SubNodeList)
3514
3560
  and isinstance(second.items[0], ast.MatchKVPair)
3515
- else first
3516
- if isinstance(first, ast.SubNodeList)
3517
- and isinstance(first.items[0], ast.MatchKVPair)
3518
- else None
3561
+ else (
3562
+ first
3563
+ if isinstance(first, ast.SubNodeList)
3564
+ and isinstance(first.items[0], ast.MatchKVPair)
3565
+ else None
3566
+ )
3519
3567
  )
3520
3568
  if isinstance(name, ast.NameSpec):
3521
3569
  return self.nu(
@@ -1,4 +1,5 @@
1
1
  """Abstract class for IR Passes for Jac."""
2
+
2
3
  from typing import Optional, Type
3
4
 
4
5
  import jaclang.compiler.absyntree as ast
@@ -1,11 +1,12 @@
1
1
  """Collection of passes for Jac IR."""
2
+
2
3
  from .sub_node_tab_pass import SubNodeTabPass
3
4
  from .import_pass import ImportPass # noqa: I100
4
5
  from .sym_tab_build_pass import SymTabBuildPass # noqa: I100
5
6
  from .def_impl_match_pass import DeclDefMatchPass # noqa: I100
6
7
  from .def_use_pass import DefUsePass # noqa: I100
7
8
  from .pyout_pass import PyOutPass # noqa: I100
8
- from .pyast_load_pass import PyastBuildPass # noqa: I100
9
+ from .pyast_load_pass import PyastBuildPass # type: ignore # noqa: I100
9
10
  from .pyast_gen_pass import PyastGenPass # noqa: I100
10
11
  from .schedules import py_code_gen # noqa: I100
11
12
  from .type_check_pass import JacTypeCheckPass # noqa: I100
@@ -5,6 +5,7 @@ that are separate from their implementations (Defs). This pass creates a link
5
5
  in the ast between the Decls and Defs of Architypes and Abilities through the
6
6
  body field.
7
7
  """
8
+
8
9
  import jaclang.compiler.absyntree as ast
9
10
  from jaclang.compiler.passes import Pass
10
11
  from jaclang.compiler.passes.main import SubNodeTabPass
@@ -5,6 +5,7 @@ symbol table. This includes assignments, parameters, arch ref chains,
5
5
  and more. This pass also links the symbols in the AST to their corresponding
6
6
  sybmols in the symbol table (including uses).
7
7
  """
8
+
8
9
  import ast as ast3
9
10
 
10
11
  import jaclang.compiler.absyntree as ast
@@ -4,6 +4,7 @@ This pass statically imports all modules used in import statements in the
4
4
  current module. This pass is run before the def/decl pass to ensure that all
5
5
  symbols are available for matching.
6
6
  """
7
+
7
8
  import ast as py_ast
8
9
  import importlib.util
9
10
  import sys
@@ -32,9 +33,9 @@ class ImportPass(Pass):
32
33
  self.run_again = True
33
34
  while self.run_again:
34
35
  self.run_again = False
35
- all_imports = self.get_all_sub_nodes(node, ast.Import)
36
+ all_imports = self.get_all_sub_nodes(node, ast.ModulePath)
36
37
  for i in all_imports:
37
- if i.lang.tag.value == "jac" and not i.sub_module:
38
+ if i.parent.lang.tag.value == "jac" and not i.sub_module:
38
39
  self.run_again = True
39
40
  mod = self.import_module(
40
41
  node=i,
@@ -48,7 +49,7 @@ class ImportPass(Pass):
48
49
  i.add_kids_right([mod], pos_update=False)
49
50
  # elif i.lang.tag.value == "py":
50
51
  # self.import_py_module(node=i, mod_path=node.loc.mod_path)
51
- self.enter_import(i)
52
+ self.enter_module_path(i)
52
53
  SubNodeTabPass(prior=self, input_ir=node)
53
54
  self.annex_impl(node)
54
55
  node.mod_deps = self.import_table
@@ -74,34 +75,31 @@ class ImportPass(Pass):
74
75
  node.add_kids_right([mod], pos_update=False)
75
76
  mod.parent = node
76
77
 
77
- def enter_import(self, node: ast.Import) -> None:
78
+ def enter_module_path(self, node: ast.ModulePath) -> None:
78
79
  """Sub objects.
79
80
 
80
- lang: Name,
81
- path: ModulePath,
81
+ path: Sequence[Token],
82
82
  alias: Optional[Name],
83
- items: Optional[ModuleItems], # Items matched during def/decl pass
84
- is_absorb: bool,
85
- self.sub_module = None
83
+ sub_module: Optional[Module] = None,
86
84
  """
87
- if node.path.alias and node.sub_module:
88
- node.sub_module.name = node.path.alias.value
85
+ if node.alias and node.sub_module:
86
+ node.sub_module.name = node.alias.value
89
87
  # Items matched during def/decl pass
90
88
 
91
89
  # Utility functions
92
90
  # -----------------
93
91
 
94
- def import_module(self, node: ast.Import, mod_path: str) -> ast.Module | None:
92
+ def import_module(self, node: ast.ModulePath, mod_path: str) -> ast.Module | None:
95
93
  """Import a module."""
96
94
  self.cur_node = node # impacts error reporting
97
95
  target = import_target_to_relative_path(
98
- node.path.path_str, path.dirname(node.loc.mod_path)
96
+ node.path_str, path.dirname(node.loc.mod_path)
99
97
  )
100
98
  return self.import_mod_from_file(target)
101
99
 
102
100
  def import_mod_from_file(self, target: str) -> ast.Module | None:
103
101
  """Import a module from a file."""
104
- from jaclang.compiler.transpiler import jac_file_to_pass
102
+ from jaclang.compiler.compile import jac_file_to_pass
105
103
  from jaclang.compiler.passes.main import SubNodeTabPass
106
104
 
107
105
  if not path.exists(target):
@@ -125,7 +123,9 @@ class ImportPass(Pass):
125
123
  self.error(f"Module {target} is not a valid Jac module.")
126
124
  return None
127
125
 
128
- def import_py_module(self, node: ast.Import, mod_path: str) -> Optional[ast.Module]:
126
+ def import_py_module(
127
+ self, node: ast.ModulePath, mod_path: str
128
+ ) -> Optional[ast.Module]:
129
129
  """Import a module."""
130
130
  from jaclang.compiler.passes.main import PyastBuildPass
131
131
 
@@ -134,7 +134,7 @@ class ImportPass(Pass):
134
134
 
135
135
  try:
136
136
  # Dynamically import the module
137
- spec = importlib.util.find_spec(node.path.path_str)
137
+ spec = importlib.util.find_spec(node.path_str)
138
138
  sys.path.remove(base_dir)
139
139
  if spec and spec.origin and spec.origin not in {None, "built-in", "frozen"}:
140
140
  if spec.origin in self.import_table:
@@ -150,11 +150,11 @@ class ImportPass(Pass):
150
150
  return mod
151
151
  else:
152
152
  raise self.ice(
153
- f"Failed to import python module {node.path.path_str}: {spec.origin}"
153
+ f"Failed to import python module {node.path_str}: {spec.origin}"
154
154
  )
155
155
  except Exception as e:
156
156
  self.error(
157
- f"Failed to import python module {node.path.path_str}: {e}",
157
+ f"Failed to import python module {node.path_str}: {e}",
158
158
  node_override=node,
159
159
  )
160
160
  return None