jaclang 0.8.1__py3-none-any.whl → 0.8.2__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 (77) hide show
  1. jaclang/__init__.py +6 -0
  2. jaclang/cli/cli.py +21 -50
  3. jaclang/compiler/codeinfo.py +0 -1
  4. jaclang/compiler/jac.lark +12 -10
  5. jaclang/compiler/larkparse/jac_parser.py +2 -2
  6. jaclang/compiler/parser.py +18 -10
  7. jaclang/compiler/passes/main/__init__.py +0 -14
  8. jaclang/compiler/passes/main/annex_pass.py +2 -8
  9. jaclang/compiler/passes/main/cfg_build_pass.py +38 -12
  10. jaclang/compiler/passes/main/import_pass.py +3 -11
  11. jaclang/compiler/passes/main/pyast_gen_pass.py +243 -592
  12. jaclang/compiler/passes/main/sym_tab_link_pass.py +2 -5
  13. jaclang/compiler/passes/main/tests/test_cfg_build_pass.py +2 -8
  14. jaclang/compiler/passes/main/tests/test_decl_impl_match_pass.py +7 -8
  15. jaclang/compiler/passes/main/tests/test_import_pass.py +5 -18
  16. jaclang/compiler/passes/main/tests/test_pyast_gen_pass.py +2 -6
  17. jaclang/compiler/passes/main/tests/test_sub_node_pass.py +1 -3
  18. jaclang/compiler/passes/main/tests/test_sym_tab_link_pass.py +20 -17
  19. jaclang/compiler/passes/tool/doc_ir_gen_pass.py +237 -105
  20. jaclang/compiler/passes/tool/jac_formatter_pass.py +2 -0
  21. jaclang/compiler/passes/tool/tests/fixtures/archetype_frmt.jac +14 -0
  22. jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/triple_quoted_string.jac +5 -4
  23. jaclang/compiler/passes/tool/tests/fixtures/import_fmt.jac +6 -0
  24. jaclang/compiler/passes/tool/tests/fixtures/simple_walk_fmt.jac +3 -3
  25. jaclang/compiler/passes/tool/tests/fixtures/tagbreak.jac +9 -0
  26. jaclang/compiler/passes/tool/tests/test_jac_format_pass.py +18 -3
  27. jaclang/compiler/passes/tool/tests/test_unparse_validate.py +2 -2
  28. jaclang/compiler/program.py +21 -60
  29. jaclang/compiler/tests/fixtures/pkg_import_lib_py/__init__.py +2 -8
  30. jaclang/compiler/tests/fixtures/pkg_import_lib_py/sub/__init__.py +1 -5
  31. jaclang/compiler/tests/test_importer.py +10 -13
  32. jaclang/compiler/unitree.py +32 -16
  33. jaclang/langserve/__init__.jac +1 -1
  34. jaclang/langserve/engine.jac +113 -108
  35. jaclang/langserve/server.jac +17 -2
  36. jaclang/langserve/tests/server_test/test_lang_serve.py +138 -46
  37. jaclang/langserve/tests/server_test/utils.py +35 -9
  38. jaclang/langserve/tests/test_sem_tokens.py +1 -1
  39. jaclang/langserve/tests/test_server.py +3 -7
  40. jaclang/runtimelib/archetype.py +127 -5
  41. jaclang/runtimelib/importer.py +51 -94
  42. jaclang/runtimelib/machine.py +391 -268
  43. jaclang/runtimelib/meta_importer.py +86 -0
  44. jaclang/runtimelib/tests/fixtures/graph_purger.jac +24 -26
  45. jaclang/runtimelib/tests/fixtures/other_root_access.jac +25 -16
  46. jaclang/runtimelib/tests/test_jaseci.py +3 -1
  47. jaclang/tests/fixtures/arch_rel_import_creation.jac +23 -23
  48. jaclang/tests/fixtures/async_ability.jac +43 -10
  49. jaclang/tests/fixtures/async_function.jac +18 -0
  50. jaclang/tests/fixtures/async_walker.jac +17 -12
  51. jaclang/tests/fixtures/create_dynamic_archetype.jac +25 -28
  52. jaclang/tests/fixtures/deep/deeper/deep_outer_import.jac +7 -4
  53. jaclang/tests/fixtures/deep/deeper/snd_lev.jac +2 -2
  54. jaclang/tests/fixtures/deep/deeper/snd_lev_dup.jac +6 -0
  55. jaclang/tests/fixtures/deep/one_lev.jac +2 -2
  56. jaclang/tests/fixtures/deep/one_lev_dup.jac +4 -3
  57. jaclang/tests/fixtures/dynamic_archetype.jac +19 -12
  58. jaclang/tests/fixtures/foo.jac +14 -22
  59. jaclang/tests/fixtures/jac_from_py.py +1 -1
  60. jaclang/tests/fixtures/jp_importer.jac +6 -6
  61. jaclang/tests/fixtures/jp_importer_auto.jac +5 -3
  62. jaclang/tests/fixtures/unicode_strings.jac +24 -0
  63. jaclang/tests/fixtures/walker_update.jac +5 -7
  64. jaclang/tests/test_language.py +138 -140
  65. jaclang/tests/test_reference.py +9 -4
  66. jaclang/tests/test_typecheck.py +13 -26
  67. jaclang/utils/lang_tools.py +7 -5
  68. jaclang/utils/module_resolver.py +23 -0
  69. {jaclang-0.8.1.dist-info → jaclang-0.8.2.dist-info}/METADATA +1 -1
  70. {jaclang-0.8.1.dist-info → jaclang-0.8.2.dist-info}/RECORD +72 -70
  71. jaclang/compiler/passes/main/tests/fixtures/main_err.jac +0 -6
  72. jaclang/compiler/passes/main/tests/fixtures/second_err.jac +0 -4
  73. jaclang/compiler/passes/tool/tests/fixtures/corelib.jac +0 -644
  74. jaclang/compiler/passes/tool/tests/test_doc_ir_gen_pass.py +0 -29
  75. jaclang/tests/fixtures/deep/deeper/__init__.jac +0 -1
  76. {jaclang-0.8.1.dist-info → jaclang-0.8.2.dist-info}/WHEEL +0 -0
  77. {jaclang-0.8.1.dist-info → jaclang-0.8.2.dist-info}/entry_points.txt +0 -0
@@ -32,11 +32,8 @@ class SymTabLinkPass(Transform[uni.Module, uni.Module]):
32
32
  def transform(self, ir_in: uni.Module) -> uni.Module:
33
33
  """Link the symbol tables for all modules in the program."""
34
34
  # Process all modules in the program hub
35
- for mod in self.prog.mod.hub.values():
36
- module_paths = mod.get_all_sub_nodes(uni.ModulePath)
37
- for node in module_paths:
38
- self.process_module_path(mod, node)
39
-
35
+ for node in ir_in.get_all_sub_nodes(uni.ModulePath):
36
+ self.process_module_path(ir_in, node)
40
37
  return ir_in
41
38
 
42
39
  def process_module_path(self, mod: uni.Module, node: uni.ModulePath) -> None:
@@ -1,12 +1,10 @@
1
1
  """Test pass module."""
2
2
 
3
- from jaclang.compiler.passes.main import CompilerMode as CMode
4
3
  from jaclang.compiler.program import JacProgram
5
4
  from jaclang.utils.test import TestCase
6
5
  import unittest
7
6
 
8
7
 
9
- @unittest.skip("Skipping CFG build pass tests")
10
8
  class TestCFGBuildPass(TestCase):
11
9
  """Test FuseTypeInfoPass module."""
12
10
 
@@ -23,9 +21,7 @@ class TestCFGBuildPass(TestCase):
23
21
  with open(file_name, "r") as f:
24
22
  file_source = f.read()
25
23
 
26
- ir = (prog := JacProgram()).compile_from_str(
27
- source_str=file_source, file_path=file_name, mode=CMode.COMPILE
28
- )
24
+ ir = (prog := JacProgram()).compile(use_str=file_source, file_path=file_name)
29
25
 
30
26
  cfg_pass = CoalesceBBPass(
31
27
  ir_in=ir,
@@ -71,9 +67,7 @@ class TestCFGBuildPass(TestCase):
71
67
  with open(file_name, "r") as f:
72
68
  file_source = f.read()
73
69
 
74
- ir = (prog := JacProgram()).compile_from_str(
75
- source_str=file_source, file_path=file_name, mode=CMode.COMPILE
76
- )
70
+ ir = (prog := JacProgram()).compile(use_str=file_source, file_path=file_name)
77
71
 
78
72
  cfg_pass = CoalesceBBPass(
79
73
  ir_in=ir,
@@ -4,7 +4,7 @@ import io
4
4
  import sys
5
5
 
6
6
  import jaclang.compiler.unitree as uni
7
- from jaclang import JacMachineInterface as Jac, JacMachine
7
+ from jaclang import JacMachine as Jac
8
8
  from jaclang.cli import cli
9
9
  from jaclang.compiler.program import JacProgram
10
10
  from jaclang.utils.test import TestCase
@@ -15,9 +15,8 @@ class DeclImplMatchPassTests(TestCase):
15
15
 
16
16
  def setUp(self) -> None:
17
17
  """Set up test."""
18
- self.mach = JacMachine(self.fixture_abs_path("./"))
18
+ Jac.set_base_path(self.fixture_abs_path("./"))
19
19
  Jac.attach_program(
20
- self.mach,
21
20
  JacProgram(),
22
21
  )
23
22
  return super().setUp()
@@ -110,7 +109,7 @@ class DeclImplMatchPassTests(TestCase):
110
109
  """Test walking through edges and nodes."""
111
110
  captured_output = io.StringIO()
112
111
  sys.stdout = captured_output
113
- Jac.jac_import(self.mach, "mtest", base_path=self.fixture_abs_path("./"))
112
+ Jac.jac_import("mtest", base_path=self.fixture_abs_path("./"))
114
113
  sys.stdout = sys.__stdout__
115
114
  stdout_value = captured_output.getvalue()
116
115
  self.assertIn("2.0\n", stdout_value)
@@ -119,7 +118,7 @@ class DeclImplMatchPassTests(TestCase):
119
118
  """Test walking through edges."""
120
119
  captured_output = io.StringIO()
121
120
  sys.stdout = captured_output
122
- Jac.jac_import(self.mach, "impl_grab", base_path=self.fixture_abs_path("./"))
121
+ Jac.jac_import("impl_grab", base_path=self.fixture_abs_path("./"))
123
122
  sys.stdout = sys.__stdout__
124
123
  stdout_value = captured_output.getvalue()
125
124
  self.assertIn("1.414", stdout_value)
@@ -128,7 +127,7 @@ class DeclImplMatchPassTests(TestCase):
128
127
  """Test complex nested impls."""
129
128
  captured_output = io.StringIO()
130
129
  sys.stdout = captured_output
131
- Jac.jac_import(self.mach, "nested_impls", base_path=self.fixture_abs_path("./"))
130
+ Jac.jac_import("nested_impls", base_path=self.fixture_abs_path("./"))
132
131
  sys.stdout = sys.__stdout__
133
132
  stdout_value = captured_output.getvalue().split("\n")
134
133
  self.assertIn("Hello,from bar in kk", stdout_value[0])
@@ -142,7 +141,7 @@ class DeclImplMatchPassTests(TestCase):
142
141
  """Parse micro jac file."""
143
142
  captured_output = io.StringIO()
144
143
  sys.stdout = captured_output
145
- Jac.jac_import(self.mach, "atest", base_path=self.fixture_abs_path("./"))
144
+ Jac.jac_import("atest", base_path=self.fixture_abs_path("./"))
146
145
  sys.stdout = sys.__stdout__
147
146
  stdout_value = captured_output.getvalue()
148
147
  self.assertEqual(stdout_value, "42\n")
@@ -151,7 +150,7 @@ class DeclImplMatchPassTests(TestCase):
151
150
  """Parse micro jac file."""
152
151
  captured_output = io.StringIO()
153
152
  sys.stdout = captured_output
154
- Jac.jac_import(self.mach, "enumerations", base_path=self.fixture_abs_path("./"))
153
+ Jac.jac_import("enumerations", base_path=self.fixture_abs_path("./"))
155
154
  sys.stdout = sys.__stdout__
156
155
  stdout_value = captured_output.getvalue()
157
156
  self.assertEqual(stdout_value, "1\n")
@@ -7,7 +7,6 @@ import unittest
7
7
 
8
8
  import jaclang.compiler.unitree as uni
9
9
  from jaclang.cli import cli
10
- from jaclang.compiler.passes.main import CompilerMode as CMode
11
10
  from jaclang.compiler.program import JacProgram
12
11
  from jaclang.utils.test import TestCase
13
12
 
@@ -21,7 +20,7 @@ class ImportPassPassTests(TestCase):
21
20
 
22
21
  def test_pygen_jac_cli(self) -> None:
23
22
  """Basic test for pass."""
24
- (out := JacProgram()).compile(self.fixture_abs_path("base.jac"))
23
+ (out := JacProgram()).build(self.fixture_abs_path("base.jac"))
25
24
  self.assertFalse(out.errors_had)
26
25
  mod = out.mod.hub[self.fixture_abs_path("impl/imps.jac")]
27
26
  self.assertIn("56", str(mod.to_dict()))
@@ -38,7 +37,7 @@ class ImportPassPassTests(TestCase):
38
37
 
39
38
  def test_import_include_auto_impl(self) -> None:
40
39
  """Basic test for pass."""
41
- (prog := JacProgram()).compile(self.fixture_abs_path("incautoimpl.jac"))
40
+ (prog := JacProgram()).build(self.fixture_abs_path("incautoimpl.jac"))
42
41
  num_modules = len(list(prog.mod.hub.values())[1].impl_mod) + 1
43
42
  mod_names = [i.name for i in list(prog.mod.hub.values())[1].impl_mod]
44
43
  self.assertEqual(num_modules, 5)
@@ -50,7 +49,7 @@ class ImportPassPassTests(TestCase):
50
49
 
51
50
  def test_annexalbe_by_discovery(self) -> None:
52
51
  """Basic test for pass."""
53
- (prog := JacProgram()).compile(self.fixture_abs_path("incautoimpl.jac"))
52
+ (prog := JacProgram()).build(self.fixture_abs_path("incautoimpl.jac"))
54
53
  count = 0
55
54
  all_mods = prog.mod.hub.values()
56
55
  self.assertEqual(len(all_mods), 6)
@@ -66,10 +65,7 @@ class ImportPassPassTests(TestCase):
66
65
  @unittest.skip("TODO: Fix when we have the type checker")
67
66
  def test_py_raise_map(self) -> None:
68
67
  """Basic test for pass."""
69
- (build := JacProgram()).compile(
70
- self.fixture_abs_path("py_imp_test.jac"),
71
- mode=CMode.TYPECHECK,
72
- )
68
+ (build := JacProgram()).build(self.fixture_abs_path("py_imp_test.jac"))
73
69
  p = {
74
70
  "math": r"jaclang/vendor/mypy/typeshed/stdlib/math.pyi$",
75
71
  "pygame_mock": r"pygame_mock/__init__.pyi$",
@@ -91,9 +87,7 @@ class ImportPassPassTests(TestCase):
91
87
  @unittest.skip("TODO: Fix when we have the type checker")
92
88
  def test_py_raised_mods(self) -> None:
93
89
  """Basic test for pass."""
94
- (prog := JacProgram()).compile(
95
- self.fixture_abs_path("py_imp_test.jac"), mode=CMode.TYPECHECK
96
- )
90
+ (prog := JacProgram()).build(self.fixture_abs_path("py_imp_test.jac"))
97
91
  for i in list(
98
92
  filter(
99
93
  lambda x: x.is_raised_from_py,
@@ -125,13 +119,6 @@ class ImportPassPassTests(TestCase):
125
119
  self.assertIn("bar", stdout_value)
126
120
  self.assertIn("baz", stdout_value)
127
121
 
128
- def test_raise_syntax_error(self) -> None:
129
- """Test raise error on the parser , dont go to the next pass."""
130
- (state := JacProgram()).compile(self.fixture_abs_path("main_err.jac"))
131
- self.assertTrue(state.errors_had)
132
- self.assertEqual(len(state.errors_had), 1)
133
- self.assertIn("Syntax Error", state.errors_had[0].msg)
134
-
135
122
  def test_circular_import(self) -> None:
136
123
  """Test circular import."""
137
124
  (state := JacProgram()).compile(self.fixture_abs_path("circular_import.jac"))
@@ -6,9 +6,8 @@ import sys
6
6
  import types
7
7
 
8
8
  import jaclang.compiler.unitree as uni
9
- from jaclang.compiler.passes.main import CompilerMode as CMode, PyastGenPass
9
+ from jaclang.compiler.passes.main import PyastGenPass
10
10
  from jaclang.compiler.program import JacProgram
11
- from jaclang.runtimelib.machine import JacMachine
12
11
  from jaclang.utils.test import AstSyncTestMixin, TestCaseMicroSuite
13
12
 
14
13
 
@@ -53,7 +52,6 @@ class PyastGenPassTests(TestCaseMicroSuite, AstSyncTestMixin):
53
52
  sys.stdout = captured_output
54
53
  module = types.ModuleType("__main__")
55
54
  module.__dict__["__file__"] = code_gen.loc.mod_path
56
- module.__dict__["__jac_mach__"] = JacMachine()
57
55
  exec(prog, module.__dict__)
58
56
  sys.stdout = sys.__stdout__
59
57
  stdout_value = captured_output.getvalue()
@@ -123,9 +121,7 @@ class ValidateTreeParentTest(TestCaseMicroSuite):
123
121
 
124
122
  def micro_suite_test(self, filename: str) -> None:
125
123
  """Parse micro jac file."""
126
- code_gen = JacProgram().compile(
127
- self.fixture_abs_path(filename), mode=CMode.PARSE
128
- )
124
+ code_gen = JacProgram().compile(self.fixture_abs_path(filename))
129
125
  self.assertTrue(self.parent_scrub(code_gen))
130
126
  code_gen = JacProgram().compile(self.fixture_abs_path(filename))
131
127
  self.assertTrue(self.parent_scrub(code_gen))
@@ -1,7 +1,6 @@
1
1
  """Test sub node pass module."""
2
2
 
3
3
  from jaclang.compiler.passes import UniPass
4
- from jaclang.compiler.passes.main import CompilerMode as CMode
5
4
  from jaclang.compiler.program import JacProgram
6
5
  from jaclang.utils.test import TestCase
7
6
 
@@ -16,8 +15,7 @@ class SubNodePassTests(TestCase):
16
15
  def test_sub_node_pass(self) -> None:
17
16
  """Basic test for pass."""
18
17
  code_gen = (out := JacProgram()).compile(
19
- file_path=self.examples_abs_path("manual_code/circle.jac"),
20
- mode=CMode.PARSE,
18
+ file_path=self.examples_abs_path("manual_code/circle.jac")
21
19
  )
22
20
  for i in code_gen.kid[1].kid:
23
21
  for k, v in i._sub_node_tab.items():
@@ -2,7 +2,6 @@
2
2
 
3
3
  import os
4
4
 
5
- from jaclang.compiler.passes.main import CompilerMode as CMode
6
5
  from jaclang.compiler.program import JacProgram
7
6
  from jaclang.utils.test import TestCase
8
7
 
@@ -23,7 +22,7 @@ class SymTabLinkPassTests(TestCase):
23
22
  "symtab_link_tests",
24
23
  "no_dupls.jac",
25
24
  )
26
- mod = JacProgram().compile(file_path, mode=CMode.TYPECHECK)
25
+ mod = JacProgram().build(file_path)
27
26
  self.assertEqual(
28
27
  len(mod.sym_tab.names_in_scope.values()),
29
28
  3,
@@ -33,20 +32,24 @@ class SymTabLinkPassTests(TestCase):
33
32
  i,
34
33
  str(mod.sym_tab.names_in_scope.values()),
35
34
  )
36
- self.assertEqual(len(mod.sym_tab.names_in_scope["a"].uses), 2)
37
- self.assertEqual(
38
- len(
39
- list(
40
- mod.sym_tab.kid_scope[0]
41
- .kid_scope[0]
42
- .kid_scope[0]
43
- .kid_scope[0]
44
- .inherited_scope[0]
45
- .base_symbol_table.names_in_scope.values()
46
- )[0].uses,
47
- ),
48
- 3,
49
- )
35
+ # TODO: def use is called on single file so this breaks
36
+ # Def Use pass will go away with full type checking
37
+ # self.assertEqual(
38
+ # len(mod.sym_tab.names_in_scope["a"].uses), 4
39
+ # )
40
+ # self.assertEqual(
41
+ # len(
42
+ # list(
43
+ # mod.sym_tab.kid_scope[0]
44
+ # .kid_scope[0]
45
+ # .kid_scope[0]
46
+ # .kid_scope[0]
47
+ # .inherited_scope[0]
48
+ # .base_symbol_table.names_in_scope.values()
49
+ # )[0].uses,
50
+ # ),
51
+ # 3,
52
+ # )
50
53
 
51
54
  def test_package(self) -> None:
52
55
  """Test package."""
@@ -57,6 +60,6 @@ class SymTabLinkPassTests(TestCase):
57
60
  "main.jac",
58
61
  )
59
62
  prog = JacProgram()
60
- prog.compile(file_path, mode=CMode.COMPILE)
63
+ prog.compile(file_path)
61
64
  self.assertEqual(prog.errors_had, [])
62
65
  self.assertEqual(prog.warnings_had, [])