jaclang 0.2.4__py3-none-any.whl → 0.3.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 (82) hide show
  1. jaclang/__init__.py +9 -3
  2. jaclang/cli/__init__.py +0 -1
  3. jaclang/cli/__jac_gen__/cli.py +6 -6
  4. jaclang/cli/__jac_gen__/cli_impl.py +2 -2
  5. jaclang/cli/__jac_gen__/cmds.py +2 -3
  6. jaclang/cli/__jac_gen__/cmds_impl.py +2 -3
  7. jaclang/cli/cmds.jac +1 -1
  8. jaclang/cli/cmds_impl.jac +2 -3
  9. jaclang/core/__init__.py +5 -11
  10. jaclang/core/__jac_gen__/corelib.py +289 -0
  11. jaclang/core/__jac_gen__/corelib_impl.py +220 -0
  12. jaclang/core/corelib.jac +21 -34
  13. jaclang/core/corelib_impl.jac +317 -0
  14. jaclang/jac/__init__.py +1 -0
  15. jaclang/jac/__jac_gen__/jac_parser.py +2 -2
  16. jaclang/jac/absyntree.py +32 -62
  17. jaclang/jac/constant.py +3 -7
  18. jaclang/jac/importer.py +1 -1
  19. jaclang/jac/parser.py +14 -10
  20. jaclang/jac/passes/main/__init__.py +2 -0
  21. jaclang/jac/passes/main/def_use_pass.py +4 -7
  22. jaclang/jac/passes/main/pyast_gen_pass.py +116 -35
  23. jaclang/jac/passes/main/schedules.py +6 -0
  24. jaclang/jac/passes/main/sym_tab_build_pass.py +40 -19
  25. jaclang/jac/passes/main/tests/test_jac_format_pass.py +22 -4
  26. jaclang/jac/passes/main/tests/test_pyast_gen_pass.py +3 -1
  27. jaclang/jac/passes/main/tests/test_type_check_pass.py +42 -0
  28. jaclang/jac/passes/main/type_check_pass.py +103 -0
  29. jaclang/jac/passes/tool/ast_printer_pass.py +8 -2
  30. jaclang/jac/passes/tool/fuse_comments_pass.py +57 -39
  31. jaclang/jac/passes/tool/jac_formatter_pass.py +419 -192
  32. jaclang/jac/passes/tool/sym_tab_printer_pass.py +10 -93
  33. jaclang/jac/passes/tool/tests/test_ast_print_pass.py +2 -1
  34. jaclang/jac/passes/transform.py +0 -39
  35. jaclang/jac/passes/utils/__init__.py +1 -0
  36. jaclang/jac/passes/utils/mypy_ast_build.py +302 -0
  37. jaclang/jac/plugin/__init__.py +5 -2
  38. jaclang/jac/plugin/default.py +20 -4
  39. jaclang/jac/plugin/feature.py +16 -7
  40. jaclang/jac/plugin/spec.py +34 -6
  41. jaclang/jac/symtable.py +6 -0
  42. jaclang/jac/tests/test_workspace.py +55 -1
  43. jaclang/jac/transpiler.py +4 -9
  44. jaclang/utils/helpers.py +0 -33
  45. jaclang/utils/lang_tools.py +3 -0
  46. jaclang/utils/test.py +3 -1
  47. jaclang/utils/treeprinter.py +171 -0
  48. jaclang/vendor/lark/py.typed +0 -0
  49. jaclang/vendor/mypy/checker.py +19 -12
  50. jaclang/vendor/mypy/checkexpr.py +31 -10
  51. jaclang/vendor/mypy/constraints.py +56 -38
  52. jaclang/vendor/mypy/expandtype.py +1 -0
  53. jaclang/vendor/mypy/meet.py +10 -1
  54. jaclang/vendor/mypy/messages.py +16 -4
  55. jaclang/vendor/mypy/moduleinspect.py +10 -4
  56. jaclang/vendor/mypy/py.typed +1 -0
  57. jaclang/vendor/mypy/semanal.py +18 -17
  58. jaclang/vendor/mypy/semanal_enum.py +7 -4
  59. jaclang/vendor/mypy/semanal_namedtuple.py +11 -1
  60. jaclang/vendor/mypy/semanal_typeddict.py +25 -11
  61. jaclang/vendor/mypy/stubdoc.py +18 -4
  62. jaclang/vendor/mypy/stubgen.py +80 -1
  63. jaclang/vendor/mypy/stubgenc.py +47 -5
  64. jaclang/vendor/mypy/stubtest.py +53 -3
  65. jaclang/vendor/mypy/stubutil.py +9 -9
  66. jaclang/vendor/mypy/test/testipc.py +16 -7
  67. jaclang/vendor/mypy/test/teststubtest.py +20 -2
  68. jaclang/vendor/mypy/types.py +1 -1
  69. jaclang/vendor/mypyc/irbuild/prebuildvisitor.py +2 -1
  70. jaclang/vendor/mypyc/test/test_run.py +2 -4
  71. jaclang/vendor/pluggy/py.typed +0 -0
  72. {jaclang-0.2.4.dist-info → jaclang-0.3.0.dist-info}/METADATA +1 -1
  73. {jaclang-0.2.4.dist-info → jaclang-0.3.0.dist-info}/RECORD +77 -71
  74. {jaclang-0.2.4.dist-info → jaclang-0.3.0.dist-info}/WHEEL +1 -1
  75. {jaclang-0.2.4.dist-info → jaclang-0.3.0.dist-info}/entry_points.txt +3 -0
  76. jaclang/core/arch_impl.jac +0 -131
  77. jaclang/core/element_impl.jac +0 -109
  78. jaclang/core/exec_ctx_impl.jac +0 -14
  79. jaclang/core/memory_impl.jac +0 -57
  80. jaclang/jac/tests/fixtures/__jac_gen__/hello_world.py +0 -5
  81. /jaclang/{jac/tests/fixtures → core}/__jac_gen__/__init__.py +0 -0
  82. {jaclang-0.2.4.dist-info → jaclang-0.3.0.dist-info}/top_level.txt +0 -0
jaclang/jac/absyntree.py CHANGED
@@ -2,13 +2,13 @@
2
2
  from __future__ import annotations
3
3
 
4
4
  import ast as ast3
5
- import pprint
6
5
  from typing import Any, Callable, Generic, Optional, Sequence, Type, TypeVar
7
6
 
8
7
  from jaclang.jac.codeloc import CodeGenTarget, CodeLocInfo
9
8
  from jaclang.jac.constant import Constants as Con, EdgeDir
10
9
  from jaclang.jac.constant import Tokens as Tok
11
10
  from jaclang.jac.symtable import Symbol, SymbolAccess, SymbolTable, SymbolType
11
+ from jaclang.utils.treeprinter import print_ast_tree
12
12
 
13
13
 
14
14
  class AstNode:
@@ -91,12 +91,9 @@ class AstNode:
91
91
  ret["value"] = self.value
92
92
  return ret
93
93
 
94
- def print(self, use_pp: bool = False, depth: Optional[int] = None) -> None:
94
+ def pp(self, depth: Optional[int] = None) -> str:
95
95
  """Print ast."""
96
- if use_pp:
97
- pprint.PrettyPrinter(depth=depth).pprint(self.to_dict())
98
- else:
99
- print_tree(self)
96
+ return print_ast_tree(self, max_depth=depth)
100
97
 
101
98
 
102
99
  class AstSymbolNode(AstNode):
@@ -175,6 +172,10 @@ class WalkerStmtOnlyNode(AstNode):
175
172
  class AstImplOnlyNode(AstNode):
176
173
  """ImplOnly node type for Jac Ast."""
177
174
 
175
+ def __init__(self, decl_link: Optional[AstNode]) -> None:
176
+ """Initialize impl only node."""
177
+ self.decl_link = decl_link
178
+
178
179
 
179
180
  class Expr(AstNode):
180
181
  """Expr node type for Jac Ast."""
@@ -317,6 +318,7 @@ class Test(AstSymbolNode, ElementStmt):
317
318
  kid=name.kid,
318
319
  )
319
320
  )
321
+ self.name.parent = self
320
322
  # kid[0] = self.name # Index is 0 since Doc string is inserted after init
321
323
  self.body = body
322
324
  AstNode.__init__(self, kid=kid)
@@ -483,7 +485,6 @@ class ArchDef(ArchSpec, AstImplOnlyNode):
483
485
  """Initialize arch def node."""
484
486
  self.target = target
485
487
  self.body = body
486
- self.decl_link = decl_link
487
488
  AstNode.__init__(self, kid=kid)
488
489
  AstSymbolNode.__init__(
489
490
  self,
@@ -493,6 +494,7 @@ class ArchDef(ArchSpec, AstImplOnlyNode):
493
494
  )
494
495
  AstDocNode.__init__(self, doc=doc)
495
496
  ArchSpec.__init__(self, decorators=decorators)
497
+ AstImplOnlyNode.__init__(self, decl_link=decl_link)
496
498
 
497
499
 
498
500
  class Enum(ArchSpec, AstAccessNode):
@@ -539,7 +541,6 @@ class EnumDef(ArchSpec, AstImplOnlyNode):
539
541
  """Initialize arch def node."""
540
542
  self.target = target
541
543
  self.body = body
542
- self.decl_link = decl_link
543
544
  AstNode.__init__(self, kid=kid)
544
545
  AstSymbolNode.__init__(
545
546
  self,
@@ -549,6 +550,7 @@ class EnumDef(ArchSpec, AstImplOnlyNode):
549
550
  )
550
551
  AstDocNode.__init__(self, doc=doc)
551
552
  ArchSpec.__init__(self, decorators=decorators)
553
+ AstImplOnlyNode.__init__(self, decl_link=decl_link)
552
554
 
553
555
 
554
556
  class Ability(
@@ -632,7 +634,6 @@ class AbilityDef(AstSymbolNode, ElementStmt, AstImplOnlyNode, CodeBlockStmt):
632
634
  self.signature = signature
633
635
  self.body = body
634
636
  self.decorators = decorators
635
- self.decl_link = decl_link
636
637
  AstNode.__init__(self, kid=kid)
637
638
  AstSymbolNode.__init__(
638
639
  self,
@@ -641,6 +642,15 @@ class AbilityDef(AstSymbolNode, ElementStmt, AstImplOnlyNode, CodeBlockStmt):
641
642
  sym_type=SymbolType.IMPL,
642
643
  )
643
644
  AstDocNode.__init__(self, doc=doc)
645
+ AstImplOnlyNode.__init__(self, decl_link=decl_link)
646
+
647
+ @property
648
+ def is_method(self) -> bool:
649
+ """Check if is method."""
650
+ return (
651
+ len(self.target.archs) > 1
652
+ and self.target.archs[-2].arch.name != Tok.ABILITY_OP
653
+ )
644
654
 
645
655
 
646
656
  class FuncSignature(AstNode):
@@ -660,13 +670,18 @@ class FuncSignature(AstNode):
660
670
  @property
661
671
  def is_method(self) -> bool:
662
672
  """Check if is method."""
663
- if (isinstance(self.parent, Ability) and self.parent.is_method) or (
673
+ return (isinstance(self.parent, Ability) and self.parent.is_method) or (
674
+ isinstance(self.parent, AbilityDef) and self.parent.is_method
675
+ )
676
+
677
+ @property
678
+ def is_static(self) -> bool:
679
+ """Check if is static."""
680
+ return (isinstance(self.parent, Ability) and self.parent.is_static) or (
664
681
  isinstance(self.parent, AbilityDef)
665
682
  and isinstance(self.parent.decl_link, Ability)
666
- and self.parent.decl_link.is_method
667
- ):
668
- return True
669
- return False
683
+ and self.parent.decl_link.is_static
684
+ )
670
685
 
671
686
 
672
687
  class EventSignature(AstNode):
@@ -1632,6 +1647,8 @@ class SpecialVarRef(NameSpec):
1632
1647
  return Con.HERE.value
1633
1648
  elif self.var.name == Tok.INIT_OP:
1634
1649
  return "__init__"
1650
+ elif self.var.name == Tok.POST_INIT_OP:
1651
+ return "__post_init__"
1635
1652
  else:
1636
1653
  raise NotImplementedError("ICE: Special var reference not implemented")
1637
1654
 
@@ -2047,7 +2064,7 @@ class TokenSymbol(Token, AstSymbolNode):
2047
2064
  )
2048
2065
 
2049
2066
 
2050
- class BuiltinType(Name, Literal):
2067
+ class BuiltinType(Name, Literal, NameSpec):
2051
2068
  """Type node type for Jac Ast."""
2052
2069
 
2053
2070
  SYMBOL_TYPE = SymbolType.VAR
@@ -2206,50 +2223,3 @@ class PythonModuleAst(EmptyToken):
2206
2223
  super().__init__()
2207
2224
  self.ast = ast
2208
2225
  self.file_path = mod_path
2209
-
2210
-
2211
- # ----------------
2212
-
2213
-
2214
- def print_tree(
2215
- root: AstNode,
2216
- marker: str = "+-- ",
2217
- level_markers: Optional[list[bool]] = None,
2218
- output_file: Optional[str] = None,
2219
- ) -> None:
2220
- """Recursive function that prints the hierarchical structure of a tree."""
2221
-
2222
- def __node_repr_in_tree(node: AstNode) -> str:
2223
- if isinstance(node, Token):
2224
- return f"{node.__class__.__name__} - {node.value}"
2225
- # return f"{node.__class__.__name__}({node.name}, {node.value})"
2226
- else:
2227
- return node.__class__.__name__
2228
-
2229
- if root is None:
2230
- return
2231
-
2232
- empty_str = " " * len(marker)
2233
- connection_str = "|" + empty_str[:-1]
2234
- if not level_markers:
2235
- level_markers = []
2236
- level = len(level_markers) # recursion level
2237
-
2238
- def mapper(draw: bool) -> str:
2239
- return connection_str if draw else empty_str
2240
-
2241
- markers = "".join(map(mapper, level_markers[:-1]))
2242
- markers += marker if level > 0 else ""
2243
- if output_file:
2244
- with open(output_file, "a+") as f:
2245
- print(f"{markers}{__node_repr_in_tree(root)}", file=f)
2246
- else:
2247
- print(f"{markers}{__node_repr_in_tree(root)}")
2248
- # After root has been printed, recurse down (depth-first) the child nodes.
2249
- for i, child in enumerate(root.kid):
2250
- # The last child will not need connection markers on the current level
2251
- # (see example above)
2252
- is_last = i == len(root.kid) - 1
2253
- print_tree(
2254
- child, marker, [*level_markers, not is_last], output_file=output_file
2255
- )
jaclang/jac/constant.py CHANGED
@@ -6,14 +6,9 @@ class Constants(str, Enum):
6
6
  """Token constants for Jac."""
7
7
 
8
8
  JAC_LANG_IMP = "jac"
9
- JAC_DEBUG_SPLITTER = "JAC DEBUG INFO"
10
- JAC_ERROR_PREAMBLE = "Jac error originates from..."
11
- PATCH = "PATCH"
12
-
13
- JAC_TMP = "_jac_tmp"
14
- EXEC_CONTEXT = "_jac_exec_ctx_"
15
9
  HERE = "_jac_here_"
16
- ROOT = f"{EXEC_CONTEXT}.get_root()"
10
+ JAC_FEATURE = "_JacFeature"
11
+ ROOT = f"{JAC_FEATURE}.get_root()"
17
12
  EDGES_TO_NODE = "_jac_.edges_to_nodes"
18
13
  EDGE_REF = "_jac_.edge_ref"
19
14
  CONNECT_NODE = "_jac_.connect_node"
@@ -204,6 +199,7 @@ class Tokens(str, Enum):
204
199
  HERE_OP = "HERE_OP"
205
200
  SELF_OP = "SELF_OP"
206
201
  INIT_OP = "INIT_OP"
202
+ POST_INIT_OP = "POST_INIT_OP"
207
203
  SUPER_OP = "SUPER_OP"
208
204
  ROOT_OP = "ROOT_OP"
209
205
  WALKER_OP = "WALKER_OP"
jaclang/jac/importer.py CHANGED
@@ -62,6 +62,7 @@ def jac_import(
62
62
  with open(pyc_file_path, "rb") as f:
63
63
  codeobj = marshal.load(f)
64
64
 
65
+ module_name = override_name if override_name else module_name
65
66
  module = types.ModuleType(module_name)
66
67
  module.__file__ = full_target
67
68
  module.__name__ = module_name
@@ -78,7 +79,6 @@ def jac_import(
78
79
  else:
79
80
  sys.modules[module_name] = module
80
81
 
81
- module.__name__ = override_name if override_name else module.__name__
82
82
  exec(codeobj, module.__dict__)
83
83
 
84
84
  return module
jaclang/jac/parser.py CHANGED
@@ -4,11 +4,11 @@ from __future__ import annotations
4
4
 
5
5
  import logging
6
6
  import os
7
- from typing import Callable
7
+ from typing import Callable, TypeAlias
8
8
 
9
9
 
10
10
  import jaclang.jac.absyntree as ast
11
- from jaclang.jac import jac_lark as jl
11
+ from jaclang.jac import jac_lark as jl # type: ignore
12
12
  from jaclang.jac.constant import EdgeDir, Tokens as Tok
13
13
  from jaclang.jac.passes.ir_pass import Pass
14
14
  from jaclang.vendor.lark import Lark, Transformer, Tree, logger
@@ -98,7 +98,7 @@ class JacParser(Pass):
98
98
  comment_cache: list[jl.Token] = []
99
99
 
100
100
  parser = jl.Lark_StandAlone(lexer_callbacks={"COMMENT": _comment_callback}) # type: ignore
101
- JacTransformer = jl.Transformer[jl.Tree[str], ast.AstNode]
101
+ JacTransformer: TypeAlias = jl.Transformer[jl.Tree[str], ast.AstNode]
102
102
 
103
103
  class TreeToAST(JacTransformer):
104
104
  """Transform parse tree to AST."""
@@ -509,21 +509,22 @@ class JacParser(Pass):
509
509
  def any_ref(self, kid: list[ast.AstNode]) -> ast.NameSpec:
510
510
  """Grammar rule.
511
511
 
512
- any_ref: special_ref
513
- | named_ref
512
+ any_ref: named_ref
513
+ | arch_ref
514
514
  """
515
515
  if isinstance(kid[0], ast.NameSpec):
516
516
  return self.nu(kid[0])
517
517
  else:
518
518
  raise self.ice()
519
519
 
520
- def named_ref(self, kid: list[ast.AstNode]) -> ast.Name:
520
+ def named_ref(self, kid: list[ast.AstNode]) -> ast.NameSpec:
521
521
  """Grammar rule.
522
522
 
523
- named_ref: KWESC_NAME
523
+ named_ref: special_ref
524
+ | KWESC_NAME
524
525
  | NAME
525
526
  """
526
- if isinstance(kid[0], ast.Name):
527
+ if isinstance(kid[0], ast.NameSpec):
527
528
  return self.nu(kid[0])
528
529
  else:
529
530
  raise self.ice()
@@ -722,8 +723,11 @@ class JacParser(Pass):
722
723
  abstract_ability: KW_STATIC? KW_CAN access_tag? any_ref (func_decl | event_clause) KW_ABSTRACT SEMI
723
724
  """
724
725
  chomp = [*kid]
725
- is_static = isinstance(chomp[0], ast.Token)
726
+ is_static = (
727
+ isinstance(chomp[0], ast.Token) and chomp[0].name == Tok.KW_STATIC
728
+ )
726
729
  chomp = chomp[1:] if is_static else chomp
730
+ chomp = chomp[1:]
727
731
  access = chomp[0] if isinstance(chomp[0], ast.SubTag) else None
728
732
  chomp = chomp[1:] if access else chomp
729
733
  name = chomp[0]
@@ -2735,7 +2739,7 @@ class JacParser(Pass):
2735
2739
  def type_ref(self, kid: list[ast.AstNode]) -> ast.ArchRef:
2736
2740
  """Grammar rule.
2737
2741
 
2738
- object_ref: OBJECT_OP name_ref
2742
+ type_ref: TYPE_OP name_ref
2739
2743
  """
2740
2744
  if isinstance(kid[0], ast.Token) and isinstance(kid[1], ast.NameSpec):
2741
2745
  return self.nu(
@@ -8,6 +8,7 @@ from .pyout_pass import PyOutPass # noqa: I100
8
8
  from .pyast_load_pass import PyastBuildPass # noqa: I100
9
9
  from .pyast_gen_pass import PyastGenPass # noqa: I100
10
10
  from .schedules import py_code_gen # noqa: I100
11
+ from .type_check_pass import JacTypeCheckPass # noqa: I100
11
12
 
12
13
 
13
14
  pass_schedule = py_code_gen
@@ -21,4 +22,5 @@ __all__ = [
21
22
  "PyOutPass",
22
23
  "PyastBuildPass",
23
24
  "PyastGenPass",
25
+ "JacTypeCheckPass",
24
26
  ]
@@ -66,12 +66,7 @@ class DefUsePass(SymTabPass):
66
66
  type_tag: SubTag[ExprType],
67
67
  value: Optional[ExprType],
68
68
  """
69
- if (
70
- node.parent
71
- and node.parent.parent
72
- and isinstance(node.parent.parent, ast.Ability)
73
- ):
74
- self.def_insert(node, single_use="func param")
69
+ self.def_insert(node)
75
70
 
76
71
  def enter_has_var(self, node: ast.HasVar) -> None:
77
72
  """Sub objects.
@@ -130,7 +125,8 @@ class DefUsePass(SymTabPass):
130
125
  right: AtomType,
131
126
  is_scope_contained: bool,
132
127
  """
133
- self.chain_use_lookup(self.unwind_atom_trailer(node))
128
+ chain = self.unwind_atom_trailer(node)
129
+ self.chain_use_lookup(chain)
134
130
 
135
131
  def unwind_atom_trailer(self, node: ast.AtomTrailer) -> list[ast.AstSymbolNode]:
136
132
  """Sub objects.
@@ -176,6 +172,7 @@ class DefUsePass(SymTabPass):
176
172
 
177
173
  var: Token,
178
174
  """
175
+ self.use_lookup(node)
179
176
 
180
177
  def enter_edge_op_ref(self, node: ast.EdgeOpRef) -> None:
181
178
  """Sub objects.