jaclang 0.5.7__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 (41) hide show
  1. jaclang/cli/cli.py +55 -7
  2. jaclang/cli/cmdreg.py +12 -0
  3. jaclang/compiler/__init__.py +6 -3
  4. jaclang/compiler/__jac_gen__/jac_parser.py +2 -2
  5. jaclang/compiler/absyntree.py +1725 -55
  6. jaclang/compiler/codeloc.py +7 -0
  7. jaclang/compiler/compile.py +1 -1
  8. jaclang/compiler/constant.py +17 -0
  9. jaclang/compiler/parser.py +131 -112
  10. jaclang/compiler/passes/main/def_impl_match_pass.py +19 -3
  11. jaclang/compiler/passes/main/def_use_pass.py +1 -1
  12. jaclang/compiler/passes/main/fuse_typeinfo_pass.py +357 -0
  13. jaclang/compiler/passes/main/import_pass.py +7 -3
  14. jaclang/compiler/passes/main/pyast_gen_pass.py +112 -76
  15. jaclang/compiler/passes/main/pyast_load_pass.py +1779 -206
  16. jaclang/compiler/passes/main/schedules.py +2 -1
  17. jaclang/compiler/passes/main/sym_tab_build_pass.py +20 -28
  18. jaclang/compiler/passes/main/tests/test_pyast_build_pass.py +14 -5
  19. jaclang/compiler/passes/main/tests/test_sym_tab_build_pass.py +8 -8
  20. jaclang/compiler/passes/main/tests/test_typeinfo_pass.py +7 -0
  21. jaclang/compiler/passes/main/type_check_pass.py +0 -1
  22. jaclang/compiler/passes/tool/jac_formatter_pass.py +8 -17
  23. jaclang/compiler/passes/tool/tests/test_unparse_validate.py +43 -0
  24. jaclang/compiler/passes/utils/mypy_ast_build.py +28 -14
  25. jaclang/compiler/symtable.py +23 -2
  26. jaclang/compiler/tests/test_parser.py +53 -0
  27. jaclang/compiler/workspace.py +52 -26
  28. jaclang/core/construct.py +54 -2
  29. jaclang/plugin/default.py +51 -13
  30. jaclang/plugin/feature.py +16 -2
  31. jaclang/plugin/spec.py +9 -5
  32. jaclang/utils/helpers.py +25 -0
  33. jaclang/utils/lang_tools.py +4 -1
  34. jaclang/utils/test.py +1 -0
  35. jaclang/utils/tests/test_lang_tools.py +11 -14
  36. jaclang/utils/treeprinter.py +10 -2
  37. {jaclang-0.5.7.dist-info → jaclang-0.5.8.dist-info}/METADATA +1 -1
  38. {jaclang-0.5.7.dist-info → jaclang-0.5.8.dist-info}/RECORD +41 -38
  39. {jaclang-0.5.7.dist-info → jaclang-0.5.8.dist-info}/WHEEL +1 -1
  40. {jaclang-0.5.7.dist-info → jaclang-0.5.8.dist-info}/entry_points.txt +0 -0
  41. {jaclang-0.5.7.dist-info → jaclang-0.5.8.dist-info}/top_level.txt +0 -0
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
 
@@ -90,8 +93,7 @@ def build(filename: str) -> None:
90
93
  warnings = len(out.warnings_had)
91
94
  print(f"Errors: {errs}, Warnings: {warnings}")
92
95
  for i in out.ir.flatten():
93
- i.gen.mypy_ast = []
94
- i.gen.py = ""
96
+ i.gen.clean()
95
97
  with open(filename[:-4] + ".jir", "wb") as f:
96
98
  pickle.dump(out.ir, f)
97
99
  else:
@@ -141,12 +143,33 @@ def enter(filename: str, entrypoint: str, args: list) -> None:
141
143
 
142
144
 
143
145
  @cmd_registry.register
144
- 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:
145
154
  """Run the test suite in the specified .jac file.
146
155
 
147
- :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 .
148
164
  """
149
- 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
+ )
150
173
 
151
174
 
152
175
  @cmd_registry.register
@@ -162,8 +185,9 @@ def tool(tool: str, args: Optional[list] = None) -> None:
162
185
  print(getattr(AstTool(), tool)(args))
163
186
  else:
164
187
  print(getattr(AstTool(), tool)())
165
- except Exception:
166
- 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
167
191
  else:
168
192
  print(f"Ast tool {tool} not found.")
169
193
 
@@ -184,6 +208,30 @@ def clean() -> None:
184
208
  print("Done cleaning.")
185
209
 
186
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
+
187
235
  def start_cli() -> None:
188
236
  """
189
237
  Start the command line interface.
jaclang/cli/cmdreg.py CHANGED
@@ -50,6 +50,18 @@ class CommandRegistry:
50
50
  arg_msg = f"type: {param.annotation.__name__}"
51
51
  if param_name == "args":
52
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
+ )
53
65
  elif param.default is param.empty:
54
66
  if first:
55
67
  first = False
@@ -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"]