jaclang 0.4.6__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 +57 -10
  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.6.dist-info → jaclang-0.5.0.dist-info}/METADATA +1 -1
  149. {jaclang-0.4.6.dist-info → jaclang-0.5.0.dist-info}/RECORD +152 -150
  150. {jaclang-0.4.6.dist-info → jaclang-0.5.0.dist-info}/WHEEL +0 -0
  151. {jaclang-0.4.6.dist-info → jaclang-0.5.0.dist-info}/entry_points.txt +0 -0
  152. {jaclang-0.4.6.dist-info → jaclang-0.5.0.dist-info}/top_level.txt +0 -0
@@ -1,4 +1,5 @@
1
1
  """Abstract class for IR Passes for Jac."""
2
+
2
3
  from __future__ import annotations
3
4
 
4
5
  import ast as ast3
@@ -99,6 +100,13 @@ class AstNode:
99
100
  """Print ast."""
100
101
  return dotgen_ast_tree(self)
101
102
 
103
+ def flatten(self) -> list[AstNode]:
104
+ """Flatten ast."""
105
+ ret = [self]
106
+ for k in self.kid:
107
+ ret += k.flatten()
108
+ return ret
109
+
102
110
 
103
111
  class AstSymbolNode(AstNode):
104
112
  """Nodes that have link to a symbol in symbol table."""
@@ -127,9 +135,11 @@ class AstAccessNode(AstNode):
127
135
  return (
128
136
  SymbolAccess.PRIVATE
129
137
  if self.access and self.access.tag.value == Tok.KW_PRIV
130
- else SymbolAccess.PROTECTED
131
- if self.access and self.access.tag.value == Tok.KW_PROT
132
- else SymbolAccess.PUBLIC
138
+ else (
139
+ SymbolAccess.PROTECTED
140
+ if self.access and self.access.tag.value == Tok.KW_PROT
141
+ else SymbolAccess.PUBLIC
142
+ )
133
143
  )
134
144
 
135
145
 
@@ -387,19 +397,17 @@ class Import(ElementStmt, CodeBlockStmt):
387
397
  def __init__(
388
398
  self,
389
399
  lang: SubTag[Name],
390
- path: ModulePath,
400
+ paths: list[ModulePath],
391
401
  items: Optional[SubNodeList[ModuleItem]],
392
402
  is_absorb: bool, # For includes
393
403
  kid: Sequence[AstNode],
394
404
  doc: Optional[String] = None,
395
- sub_module: Optional[Module] = None,
396
405
  ) -> None:
397
406
  """Initialize import node."""
398
407
  self.lang = lang
399
- self.path = path
408
+ self.paths = paths
400
409
  self.items = items
401
410
  self.is_absorb = is_absorb
402
- self.sub_module = sub_module
403
411
  AstNode.__init__(self, kid=kid)
404
412
  AstDocNode.__init__(self, doc=doc)
405
413
 
@@ -412,10 +420,12 @@ class ModulePath(AstSymbolNode):
412
420
  path: Sequence[Token],
413
421
  alias: Optional[Name],
414
422
  kid: Sequence[AstNode],
423
+ sub_module: Optional[Module] = None,
415
424
  ) -> None:
416
425
  """Initialize module path node."""
417
426
  self.path = path
418
427
  self.alias = alias
428
+ self.sub_module = sub_module
419
429
  self.path_str: str = "".join([p.value for p in path])
420
430
  AstNode.__init__(self, kid=kid)
421
431
  AstSymbolNode.__init__(
@@ -472,21 +482,39 @@ class Architype(ArchSpec, AstAccessNode, ArchBlockStmt):
472
482
  self,
473
483
  sym_name=name.value,
474
484
  sym_name_node=name,
475
- sym_type=SymbolType.OBJECT_ARCH
476
- if arch_type.name == Tok.KW_OBJECT
477
- else SymbolType.NODE_ARCH
478
- if arch_type.name == Tok.KW_NODE
479
- else SymbolType.EDGE_ARCH
480
- if arch_type.name == Tok.KW_EDGE
481
- else SymbolType.WALKER_ARCH
482
- if arch_type.name == Tok.KW_WALKER
483
- else SymbolType.TYPE,
485
+ sym_type=(
486
+ SymbolType.OBJECT_ARCH
487
+ if arch_type.name == Tok.KW_OBJECT
488
+ else (
489
+ SymbolType.NODE_ARCH
490
+ if arch_type.name == Tok.KW_NODE
491
+ else (
492
+ SymbolType.EDGE_ARCH
493
+ if arch_type.name == Tok.KW_EDGE
494
+ else (
495
+ SymbolType.WALKER_ARCH
496
+ if arch_type.name == Tok.KW_WALKER
497
+ else SymbolType.TYPE
498
+ )
499
+ )
500
+ )
501
+ ),
484
502
  )
485
503
  AstAccessNode.__init__(self, access=access)
486
504
  AstDocNode.__init__(self, doc=doc)
487
505
  AstSemStrNode.__init__(self, semstr=semstr)
488
506
  ArchSpec.__init__(self, decorators=decorators)
489
507
 
508
+ @property
509
+ def is_abstract(self) -> bool:
510
+ """Check if has an abstract method."""
511
+ body = (
512
+ self.body.items
513
+ if isinstance(self.body, SubNodeList)
514
+ else self.body.body.items if isinstance(self.body, ArchDef) else []
515
+ )
516
+ return any(isinstance(i, Ability) and i.is_abstract for i in body)
517
+
490
518
 
491
519
  class ArchDef(ArchSpec, AstImplOnlyNode):
492
520
  """ArchDef node type for Jac Ast."""
@@ -589,6 +617,7 @@ class Ability(
589
617
  name_ref: NameSpec,
590
618
  is_func: bool,
591
619
  is_async: bool,
620
+ is_override: bool,
592
621
  is_static: bool,
593
622
  is_abstract: bool,
594
623
  access: Optional[SubTag[Token]],
@@ -602,6 +631,7 @@ class Ability(
602
631
  """Initialize func arch node."""
603
632
  self.name_ref = name_ref
604
633
  self.is_func = is_func
634
+ self.is_override = is_override
605
635
  self.is_static = is_static
606
636
  self.is_abstract = is_abstract
607
637
  self.decorators = decorators
@@ -755,7 +785,11 @@ class ArchRefChain(AstNode):
755
785
  """Resolve name."""
756
786
 
757
787
  def get_tag(x: ArchRef) -> str:
758
- return x.arch.value[1] if x.arch.value != "enum" else "en"
788
+ return (
789
+ "en"
790
+ if x.arch.value == "enum"
791
+ else "cls" if x.arch.value == "class" else x.arch.value[1]
792
+ )
759
793
 
760
794
  return ".".join([f"({get_tag(x)}){x.py_resolve_name()}" for x in self.archs])
761
795
 
@@ -1449,7 +1483,7 @@ class KVPair(AstNode):
1449
1483
 
1450
1484
  def __init__(
1451
1485
  self,
1452
- key: Expr,
1486
+ key: Optional[Expr], # is **key if blank
1453
1487
  value: Expr,
1454
1488
  kid: Sequence[AstNode],
1455
1489
  ) -> None:
@@ -1464,7 +1498,7 @@ class KWPair(AstNode):
1464
1498
 
1465
1499
  def __init__(
1466
1500
  self,
1467
- key: NameSpec,
1501
+ key: Optional[NameSpec], # is **value if blank
1468
1502
  value: Expr,
1469
1503
  kid: Sequence[AstNode],
1470
1504
  ) -> None:
@@ -1,4 +1,5 @@
1
1
  """Code location info for AST nodes."""
2
+
2
3
  from __future__ import annotations
3
4
 
4
5
  import ast as ast3
@@ -17,8 +18,9 @@ class CodeGenTarget:
17
18
 
18
19
  py: str = ""
19
20
  jac: str = ""
20
- py_ast: Optional[ast3.AST | list[ast3.AST]] = None
21
+ py_ast: list[ast3.AST] = field(default_factory=lambda: [])
21
22
  mypy_ast: list[MypyNode] = field(default_factory=lambda: [])
23
+ py_bytecode: Optional[bytes] = None
22
24
 
23
25
 
24
26
  class CodeLocInfo:
@@ -1,4 +1,5 @@
1
1
  """Transpilation functions."""
2
+
2
3
  from typing import Optional, Type
3
4
 
4
5
  import jaclang.compiler.absyntree as ast
@@ -10,8 +11,8 @@ from jaclang.compiler.passes.tool.schedules import format_pass
10
11
  from jaclang.compiler.passes.transform import Alert
11
12
 
12
13
 
13
- def transpile_jac(file_path: str) -> list[Alert]:
14
- """Transpiler Jac file and return python code as string."""
14
+ def compile_jac(file_path: str) -> list[Alert]:
15
+ """Start Compile for Jac file and return python code as string."""
15
16
  code = jac_file_to_pass(
16
17
  file_path=file_path,
17
18
  schedule=pass_schedule,
@@ -1,4 +1,5 @@
1
1
  """Constants across the project."""
2
+
2
3
  from enum import Enum
3
4
 
4
5
 
@@ -78,6 +79,7 @@ class Tokens(str, Enum):
78
79
  KW_LET = "KW_LET"
79
80
  KW_ABSTRACT = "KW_ABSTRACT"
80
81
  KW_OBJECT = "KW_OBJECT"
82
+ KW_CLASS = "KW_CLASS"
81
83
  KW_ENUM = "KW_ENUM"
82
84
  KW_NODE = "KW_NODE"
83
85
  KW_IGNORE = "KW_IGNORE"
@@ -162,6 +164,7 @@ class Tokens(str, Enum):
162
164
  COMMA = "COMMA"
163
165
  KW_CAN = "KW_CAN"
164
166
  KW_STATIC = "KW_STATIC"
167
+ KW_OVERRIDE = "KW_OVERRIDE"
165
168
  KW_MATCH = "KW_MATCH"
166
169
  KW_CASE = "KW_CASE"
167
170
  PLUS = "PLUS"
@@ -205,6 +208,7 @@ class Tokens(str, Enum):
205
208
  WALKER_OP = "WALKER_OP"
206
209
  NODE_OP = "NODE_OP"
207
210
  EDGE_OP = "EDGE_OP"
211
+ CLASS_OP = "CLASS_OP"
208
212
  OBJECT_OP = "OBJECT_OP"
209
213
  TYPE_OP = "TYPE_OP"
210
214
  ENUM_OP = "ENUM_OP"