jaclang 0.5.6__py3-none-any.whl → 0.5.8__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 (51) hide show
  1. jaclang/__init__.py +6 -1
  2. jaclang/cli/cli.py +63 -20
  3. jaclang/cli/cmdreg.py +42 -12
  4. jaclang/compiler/__init__.py +6 -3
  5. jaclang/compiler/__jac_gen__/jac_parser.py +2 -2
  6. jaclang/compiler/absyntree.py +1740 -61
  7. jaclang/compiler/codeloc.py +7 -0
  8. jaclang/compiler/compile.py +4 -5
  9. jaclang/compiler/constant.py +52 -6
  10. jaclang/compiler/parser.py +220 -129
  11. jaclang/compiler/passes/main/def_impl_match_pass.py +19 -3
  12. jaclang/compiler/passes/main/def_use_pass.py +1 -1
  13. jaclang/compiler/passes/main/fuse_typeinfo_pass.py +357 -0
  14. jaclang/compiler/passes/main/import_pass.py +7 -3
  15. jaclang/compiler/passes/main/pyast_gen_pass.py +333 -93
  16. jaclang/compiler/passes/main/pyast_load_pass.py +1779 -206
  17. jaclang/compiler/passes/main/pyout_pass.py +2 -2
  18. jaclang/compiler/passes/main/schedules.py +2 -1
  19. jaclang/compiler/passes/main/sym_tab_build_pass.py +20 -28
  20. jaclang/compiler/passes/main/tests/test_decl_def_match_pass.py +4 -4
  21. jaclang/compiler/passes/main/tests/test_pyast_build_pass.py +14 -5
  22. jaclang/compiler/passes/main/tests/test_sym_tab_build_pass.py +8 -8
  23. jaclang/compiler/passes/main/tests/test_typeinfo_pass.py +7 -0
  24. jaclang/compiler/passes/main/type_check_pass.py +0 -1
  25. jaclang/compiler/passes/tool/jac_formatter_pass.py +8 -17
  26. jaclang/compiler/passes/tool/tests/test_unparse_validate.py +43 -0
  27. jaclang/compiler/passes/utils/mypy_ast_build.py +28 -14
  28. jaclang/compiler/symtable.py +23 -2
  29. jaclang/compiler/tests/test_parser.py +53 -0
  30. jaclang/compiler/workspace.py +52 -26
  31. jaclang/core/aott.py +68 -0
  32. jaclang/core/construct.py +58 -6
  33. jaclang/core/importer.py +9 -10
  34. jaclang/core/utils.py +65 -3
  35. jaclang/plugin/builtin.py +42 -0
  36. jaclang/plugin/default.py +163 -18
  37. jaclang/plugin/feature.py +38 -10
  38. jaclang/plugin/spec.py +33 -6
  39. jaclang/utils/helpers.py +25 -0
  40. jaclang/utils/lang_tools.py +4 -1
  41. jaclang/utils/test.py +1 -0
  42. jaclang/utils/tests/test_lang_tools.py +12 -15
  43. jaclang/utils/treeprinter.py +10 -2
  44. {jaclang-0.5.6.dist-info → jaclang-0.5.8.dist-info}/METADATA +1 -1
  45. {jaclang-0.5.6.dist-info → jaclang-0.5.8.dist-info}/RECORD +48 -46
  46. {jaclang-0.5.6.dist-info → jaclang-0.5.8.dist-info}/WHEEL +1 -1
  47. jaclang/compiler/tests/fixtures/__jac_gen__/__init__.py +0 -0
  48. jaclang/compiler/tests/fixtures/__jac_gen__/hello_world.py +0 -5
  49. jaclang/core/jacbuiltins.py +0 -10
  50. {jaclang-0.5.6.dist-info → jaclang-0.5.8.dist-info}/entry_points.txt +0 -0
  51. {jaclang-0.5.6.dist-info → jaclang-0.5.8.dist-info}/top_level.txt +0 -0
jaclang/__init__.py CHANGED
@@ -5,7 +5,11 @@ import sys
5
5
 
6
6
  sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "vendor"))
7
7
 
8
- from jaclang.plugin.default import JacCmdDefaults, JacFeatureDefaults # noqa: E402
8
+ from jaclang.plugin.default import ( # noqa: E402
9
+ JacBuiltin,
10
+ JacCmdDefaults,
11
+ JacFeatureDefaults,
12
+ )
9
13
  from jaclang.plugin.feature import JacFeature, pm # noqa: E402
10
14
  from jaclang.vendor import lark # noqa: E402
11
15
  from jaclang.vendor import mypy # noqa: E402
@@ -20,5 +24,6 @@ __all__ = [
20
24
  "pluggy",
21
25
  ]
22
26
  pm.register(JacFeatureDefaults)
27
+ pm.register(JacBuiltin)
23
28
  pm.register(JacCmdDefaults)
24
29
  pm.load_setuptools_entrypoints("jac")
jaclang/cli/cli.py CHANGED
@@ -1,8 +1,10 @@
1
1
  """Command line interface tool for the Jac language."""
2
2
 
3
+ import marshal
3
4
  import os
4
5
  import pickle
5
6
  import shutil
7
+ import types
6
8
  from typing import Optional
7
9
 
8
10
  from jaclang import jac_import
@@ -13,6 +15,7 @@ from jaclang.compiler.passes.main.schedules import py_code_gen_typed
13
15
  from jaclang.compiler.passes.tool.schedules import format_pass
14
16
  from jaclang.plugin.feature import JacCmd as Cmd
15
17
  from jaclang.plugin.feature import JacFeature as Jac
18
+ from jaclang.utils.helpers import debugger as db
16
19
  from jaclang.utils.lang_tools import AstTool
17
20
 
18
21
 
@@ -21,12 +24,7 @@ Cmd.create_cmd()
21
24
 
22
25
  @cmd_registry.register
23
26
  def format(path: str, outfile: str = "", debug: bool = False) -> None:
24
- """Run the specified .jac file or format all .jac files in a given directory.
25
-
26
- :param path: The path to the .jac file or directory containing .jac files.
27
- :param outfile: The output file path (only applies when formatting a single file).
28
- :param debug: If True, print debug information.
29
- """
27
+ """Run the specified .jac file or format all .jac files in a given directory."""
30
28
 
31
29
  def format_file(filename: str) -> None:
32
30
  code_gen_format = jac_file_to_pass(filename, schedule=format_pass)
@@ -60,18 +58,17 @@ def format(path: str, outfile: str = "", debug: bool = False) -> None:
60
58
 
61
59
 
62
60
  @cmd_registry.register
63
- def run(filename: str, main: bool = True) -> None:
64
- """Run the specified .jac file.
65
-
66
- :param filename: The path to the .jac file.
67
- :param main: If True, use '__main__' as the module name, else use the actual module name.
68
- """
61
+ def run(filename: str, main: bool = True, cache: bool = True) -> None:
62
+ """Run the specified .jac file."""
69
63
  base, mod = os.path.split(filename)
70
64
  base = base if base else "./"
71
65
  mod = mod[:-4]
72
66
  if filename.endswith(".jac"):
73
67
  jac_import(
74
- target=mod, base_path=base, override_name="__main__" if main else None
68
+ target=mod,
69
+ base_path=base,
70
+ cachable=cache,
71
+ override_name="__main__" if main else None,
75
72
  )
76
73
  elif filename.endswith(".jir"):
77
74
  with open(filename, "rb") as f:
@@ -79,6 +76,7 @@ def run(filename: str, main: bool = True) -> None:
79
76
  jac_import(
80
77
  target=mod,
81
78
  base_path=base,
79
+ cachable=cache,
82
80
  override_name="__main__" if main else None,
83
81
  mod_bundle=ir,
84
82
  )
@@ -95,8 +93,7 @@ def build(filename: str) -> None:
95
93
  warnings = len(out.warnings_had)
96
94
  print(f"Errors: {errs}, Warnings: {warnings}")
97
95
  for i in out.ir.flatten():
98
- i.gen.mypy_ast = []
99
- i.gen.py = ""
96
+ i.gen.clean()
100
97
  with open(filename[:-4] + ".jir", "wb") as f:
101
98
  pickle.dump(out.ir, f)
102
99
  else:
@@ -146,12 +143,33 @@ def enter(filename: str, entrypoint: str, args: list) -> None:
146
143
 
147
144
 
148
145
  @cmd_registry.register
149
- def test(filename: str) -> None:
146
+ def test(
147
+ filepath: str,
148
+ filter: str = "",
149
+ xit: bool = False,
150
+ maxfail: int = None, # type:ignore
151
+ directory: str = "",
152
+ verbose: bool = False,
153
+ ) -> None:
150
154
  """Run the test suite in the specified .jac file.
151
155
 
152
- :param filename: The path to the .jac file.
156
+ :param filepath: Path/to/file.jac
157
+ :param filter: Filter the files using Unix shell style conventions.
158
+ :param xit(exit): Stop(exit) running tests as soon as finds an error.
159
+ :param maxfail: Stop running tests after n failures.
160
+ :param directory: Run tests from the specified directory.
161
+ :param verbose: Show more info.
162
+
163
+ jac test => jac test -d .
153
164
  """
154
- Jac.run_test(filename)
165
+ Jac.run_test(
166
+ filepath=filepath,
167
+ filter=filter,
168
+ xit=xit,
169
+ maxfail=maxfail,
170
+ directory=directory,
171
+ verbose=verbose,
172
+ )
155
173
 
156
174
 
157
175
  @cmd_registry.register
@@ -167,8 +185,9 @@ def tool(tool: str, args: Optional[list] = None) -> None:
167
185
  print(getattr(AstTool(), tool)(args))
168
186
  else:
169
187
  print(getattr(AstTool(), tool)())
170
- except Exception:
171
- print(f"Error while running ast tool {tool}, check args.")
188
+ except Exception as e:
189
+ print(f"Error while running ast tool {tool}, check args: {e}")
190
+ raise e
172
191
  else:
173
192
  print(f"Ast tool {tool} not found.")
174
193
 
@@ -189,6 +208,30 @@ def clean() -> None:
189
208
  print("Done cleaning.")
190
209
 
191
210
 
211
+ @cmd_registry.register
212
+ def debug(filename: str, main: bool = True, cache: bool = False) -> None:
213
+ """Debug the specified .jac file using pdb."""
214
+ base, mod = os.path.split(filename)
215
+ base = base if base else "./"
216
+ mod = mod[:-4]
217
+ if filename.endswith(".jac"):
218
+ bytecode = jac_file_to_pass(filename).ir.gen.py_bytecode
219
+ if bytecode:
220
+ code = marshal.loads(bytecode)
221
+ if db.has_breakpoint(bytecode):
222
+ run(filename, main, cache)
223
+ else:
224
+ func = types.FunctionType(code, globals())
225
+
226
+ print("Debugging with Jac debugger.\n")
227
+ db.runcall(func)
228
+ print("Done debugging.")
229
+ else:
230
+ print(f"Error while generating bytecode in {filename}.")
231
+ else:
232
+ print("Not a .jac file.")
233
+
234
+
192
235
  def start_cli() -> None:
193
236
  """
194
237
  Start the command line interface.
jaclang/cli/cmdreg.py CHANGED
@@ -42,12 +42,26 @@ class CommandRegistry:
42
42
  name = func.__name__
43
43
  cmd = Command(func)
44
44
  self.registry[name] = cmd
45
- cmd_parser = self.sub_parsers.add_parser(name, description=func.__doc__)
45
+ cmd_parser: argparse.ArgumentParser = self.sub_parsers.add_parser(
46
+ name, description=func.__doc__
47
+ )
46
48
  first = True
47
49
  for param_name, param in cmd.sig.parameters.items():
48
50
  arg_msg = f"type: {param.annotation.__name__}"
49
51
  if param_name == "args":
50
52
  cmd_parser.add_argument("args", nargs=argparse.REMAINDER, help=arg_msg)
53
+ elif param_name == "filepath":
54
+ first = False
55
+ cmd_parser.add_argument(
56
+ f"{param_name}",
57
+ type=(
58
+ eval(param.annotation)
59
+ if isinstance(param.annotation, str)
60
+ else param.annotation
61
+ ),
62
+ help=arg_msg,
63
+ nargs="?",
64
+ )
51
65
  elif param.default is param.empty:
52
66
  if first:
53
67
  first = False
@@ -83,17 +97,33 @@ class CommandRegistry:
83
97
  )
84
98
  else:
85
99
  arg_msg += f", default: {param.default}"
86
- cmd_parser.add_argument(
87
- f"-{param_name[:1]}",
88
- f"--{param_name}",
89
- default=param.default,
90
- help=arg_msg,
91
- type=(
92
- eval(param.annotation)
93
- if isinstance(param.annotation, str)
94
- else param.annotation
95
- ),
96
- )
100
+ if param.annotation == bool:
101
+ cmd_parser.add_argument(
102
+ f"-{param_name[:1]}",
103
+ f"--{param_name}",
104
+ default=param.default,
105
+ action="store_true",
106
+ help=arg_msg,
107
+ )
108
+ cmd_parser.add_argument(
109
+ f"-n{param_name[:1]}",
110
+ f"--no-{param_name}",
111
+ dest=param_name,
112
+ action="store_false",
113
+ help=f"Compliment of {arg_msg}",
114
+ )
115
+ else:
116
+ cmd_parser.add_argument(
117
+ f"-{param_name[:1]}",
118
+ f"--{param_name}",
119
+ default=param.default,
120
+ help=arg_msg,
121
+ type=(
122
+ eval(param.annotation)
123
+ if isinstance(param.annotation, str)
124
+ else param.annotation
125
+ ),
126
+ )
97
127
  return func
98
128
 
99
129
  def get(self, name: str) -> Optional[Command]:
@@ -1,5 +1,5 @@
1
- # type: ignore
2
1
  """Jac compiler tools."""
2
+
3
3
  import contextlib
4
4
  import logging
5
5
  import os
@@ -28,5 +28,8 @@ from .__jac_gen__ import jac_parser as jac_lark # noqa: E402
28
28
 
29
29
  jac_lark.logger.setLevel(logging.DEBUG)
30
30
  contextlib.suppress(AttributeError)
31
-
32
- __all__ = ["jac_lark"]
31
+ TOKEN_MAP = {
32
+ x.name: x.pattern.value
33
+ for x in jac_lark.Lark_StandAlone().parser.lexer_conf.terminals
34
+ }
35
+ __all__ = ["jac_lark", "TOKEN_MAP"]