jaclang 0.8.7__py3-none-any.whl → 0.8.9__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.
- jaclang/cli/cli.py +77 -29
- jaclang/cli/cmdreg.py +44 -0
- jaclang/compiler/constant.py +6 -2
- jaclang/compiler/jac.lark +37 -47
- jaclang/compiler/larkparse/jac_parser.py +2 -2
- jaclang/compiler/parser.py +356 -61
- jaclang/compiler/passes/main/__init__.py +2 -4
- jaclang/compiler/passes/main/def_use_pass.py +1 -4
- jaclang/compiler/passes/main/predynamo_pass.py +221 -0
- jaclang/compiler/passes/main/pyast_gen_pass.py +221 -135
- jaclang/compiler/passes/main/pyast_load_pass.py +54 -20
- jaclang/compiler/passes/main/sym_tab_build_pass.py +1 -1
- jaclang/compiler/passes/main/tests/fixtures/checker/import_sym.jac +2 -0
- jaclang/compiler/passes/main/tests/fixtures/checker/import_sym_test.jac +6 -0
- jaclang/compiler/passes/main/tests/fixtures/checker/imported_sym.jac +5 -0
- jaclang/compiler/passes/main/tests/fixtures/checker_arg_param_match.jac +37 -0
- jaclang/compiler/passes/main/tests/fixtures/checker_arity.jac +18 -0
- jaclang/compiler/passes/main/tests/fixtures/checker_cat_is_animal.jac +18 -0
- jaclang/compiler/passes/main/tests/fixtures/checker_float.jac +7 -0
- jaclang/compiler/passes/main/tests/fixtures/checker_param_types.jac +11 -0
- jaclang/compiler/passes/main/tests/fixtures/checker_self_type.jac +9 -0
- jaclang/compiler/passes/main/tests/fixtures/checker_sym_inherit.jac +42 -0
- jaclang/compiler/passes/main/tests/fixtures/predynamo_fix3.jac +43 -0
- jaclang/compiler/passes/main/tests/fixtures/predynamo_where_assign.jac +13 -0
- jaclang/compiler/passes/main/tests/fixtures/predynamo_where_return.jac +11 -0
- jaclang/compiler/passes/main/tests/test_checker_pass.py +190 -0
- jaclang/compiler/passes/main/tests/test_predynamo_pass.py +56 -0
- jaclang/compiler/passes/main/type_checker_pass.py +29 -73
- jaclang/compiler/passes/tool/doc_ir_gen_pass.py +302 -58
- jaclang/compiler/passes/tool/jac_formatter_pass.py +119 -69
- jaclang/compiler/passes/tool/tests/fixtures/corelib_fmt.jac +3 -3
- jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/triple_quoted_string.jac +4 -5
- jaclang/compiler/passes/tool/tests/fixtures/import_fmt.jac +7 -1
- jaclang/compiler/passes/tool/tests/fixtures/tagbreak.jac +276 -10
- jaclang/compiler/passes/transform.py +12 -8
- jaclang/compiler/program.py +19 -7
- jaclang/compiler/tests/fixtures/jac_import_py_files.py +4 -0
- jaclang/compiler/tests/fixtures/jac_module.jac +3 -0
- jaclang/compiler/tests/fixtures/multiple_syntax_errors.jac +10 -0
- jaclang/compiler/tests/fixtures/python_module.py +1 -0
- jaclang/compiler/tests/test_importer.py +39 -0
- jaclang/compiler/tests/test_parser.py +49 -0
- jaclang/compiler/type_system/type_evaluator.jac +959 -0
- jaclang/compiler/type_system/type_utils.py +246 -0
- jaclang/compiler/type_system/types.py +58 -2
- jaclang/compiler/unitree.py +102 -107
- jaclang/langserve/engine.jac +138 -159
- jaclang/langserve/server.jac +25 -1
- jaclang/langserve/tests/fixtures/circle.jac +3 -3
- jaclang/langserve/tests/fixtures/circle_err.jac +3 -3
- jaclang/langserve/tests/fixtures/circle_pure.test.jac +3 -3
- jaclang/langserve/tests/fixtures/completion_test_err.jac +10 -0
- jaclang/langserve/tests/server_test/circle_template.jac +80 -0
- jaclang/langserve/tests/server_test/glob_template.jac +4 -0
- jaclang/langserve/tests/server_test/test_lang_serve.py +154 -309
- jaclang/langserve/tests/server_test/utils.py +153 -116
- jaclang/langserve/tests/test_server.py +21 -84
- jaclang/langserve/utils.jac +12 -15
- jaclang/lib.py +17 -0
- jaclang/runtimelib/archetype.py +25 -25
- jaclang/runtimelib/constructs.py +2 -2
- jaclang/runtimelib/machine.py +63 -46
- jaclang/runtimelib/meta_importer.py +27 -1
- jaclang/runtimelib/tests/fixtures/custom_access_validation.jac +1 -1
- jaclang/runtimelib/tests/fixtures/savable_object.jac +2 -2
- jaclang/settings.py +19 -16
- jaclang/tests/fixtures/abc_check.jac +3 -3
- jaclang/tests/fixtures/arch_rel_import_creation.jac +12 -12
- jaclang/tests/fixtures/attr_pattern_case.jac +18 -0
- jaclang/tests/fixtures/chandra_bugs2.jac +3 -3
- jaclang/tests/fixtures/create_dynamic_archetype.jac +13 -13
- jaclang/tests/fixtures/funccall_genexpr.jac +7 -0
- jaclang/tests/fixtures/funccall_genexpr.py +5 -0
- jaclang/tests/fixtures/maxfail_run_test.jac +4 -4
- jaclang/tests/fixtures/params/param_syntax_err.jac +9 -0
- jaclang/tests/fixtures/params/test_complex_params.jac +42 -0
- jaclang/tests/fixtures/params/test_failing_kwonly.jac +207 -0
- jaclang/tests/fixtures/params/test_failing_posonly.jac +116 -0
- jaclang/tests/fixtures/params/test_failing_varargs.jac +300 -0
- jaclang/tests/fixtures/params/test_kwonly_params.jac +29 -0
- jaclang/tests/fixtures/py2jac_params.py +8 -0
- jaclang/tests/fixtures/run_test.jac +4 -4
- jaclang/tests/test_cli.py +159 -7
- jaclang/tests/test_language.py +213 -38
- jaclang/tests/test_reference.py +3 -1
- jaclang/utils/helpers.py +67 -6
- jaclang/utils/module_resolver.py +10 -0
- jaclang/utils/test.py +8 -0
- jaclang/utils/tests/test_lang_tools.py +4 -15
- jaclang/utils/treeprinter.py +0 -18
- {jaclang-0.8.7.dist-info → jaclang-0.8.9.dist-info}/METADATA +1 -2
- {jaclang-0.8.7.dist-info → jaclang-0.8.9.dist-info}/RECORD +95 -65
- {jaclang-0.8.7.dist-info → jaclang-0.8.9.dist-info}/WHEEL +1 -1
- jaclang/compiler/passes/main/inheritance_pass.py +0 -131
- jaclang/compiler/type_system/type_evaluator.py +0 -560
- jaclang/langserve/dev_engine.jac +0 -645
- jaclang/langserve/dev_server.jac +0 -201
- /jaclang/{langserve/tests/server_test/code_test.py → tests/fixtures/py2jac_empty.py} +0 -0
- {jaclang-0.8.7.dist-info → jaclang-0.8.9.dist-info}/entry_points.txt +0 -0
jaclang/compiler/program.py
CHANGED
|
@@ -5,7 +5,7 @@ from __future__ import annotations
|
|
|
5
5
|
import ast as py_ast
|
|
6
6
|
import marshal
|
|
7
7
|
import types
|
|
8
|
-
from typing import Optional
|
|
8
|
+
from typing import Optional, TYPE_CHECKING
|
|
9
9
|
|
|
10
10
|
import jaclang.compiler.unitree as uni
|
|
11
11
|
from jaclang.compiler.parser import JacParser
|
|
@@ -15,16 +15,15 @@ from jaclang.compiler.passes.main import (
|
|
|
15
15
|
CFGBuildPass,
|
|
16
16
|
DeclImplMatchPass,
|
|
17
17
|
DefUsePass,
|
|
18
|
-
InheritancePass,
|
|
19
18
|
JacAnnexPass,
|
|
20
19
|
JacImportDepsPass,
|
|
20
|
+
PreDynamoPass,
|
|
21
21
|
PyBytecodeGenPass,
|
|
22
22
|
PyJacAstLinkPass,
|
|
23
23
|
PyastBuildPass,
|
|
24
24
|
PyastGenPass,
|
|
25
25
|
SemDefMatchPass,
|
|
26
26
|
SymTabBuildPass,
|
|
27
|
-
SymTabLinkPass,
|
|
28
27
|
Transform,
|
|
29
28
|
TypeCheckPass,
|
|
30
29
|
)
|
|
@@ -34,8 +33,12 @@ from jaclang.compiler.passes.tool import (
|
|
|
34
33
|
JacFormatPass,
|
|
35
34
|
)
|
|
36
35
|
from jaclang.runtimelib.utils import read_file_with_encoding
|
|
36
|
+
from jaclang.settings import settings
|
|
37
37
|
from jaclang.utils.log import logging
|
|
38
38
|
|
|
39
|
+
if TYPE_CHECKING:
|
|
40
|
+
from jaclang.compiler.type_system.type_evaluator import TypeEvaluator
|
|
41
|
+
|
|
39
42
|
|
|
40
43
|
logger = logging.getLogger(__name__)
|
|
41
44
|
|
|
@@ -45,7 +48,6 @@ ir_gen_sched = [
|
|
|
45
48
|
DefUsePass,
|
|
46
49
|
SemDefMatchPass,
|
|
47
50
|
CFGBuildPass,
|
|
48
|
-
InheritancePass,
|
|
49
51
|
]
|
|
50
52
|
type_check_sched: list = [
|
|
51
53
|
TypeCheckPass,
|
|
@@ -67,6 +69,15 @@ class JacProgram:
|
|
|
67
69
|
self.py_raise_map: dict[str, str] = {}
|
|
68
70
|
self.errors_had: list[Alert] = []
|
|
69
71
|
self.warnings_had: list[Alert] = []
|
|
72
|
+
self.type_evaluator: TypeEvaluator | None = None
|
|
73
|
+
|
|
74
|
+
def get_type_evaluator(self) -> TypeEvaluator:
|
|
75
|
+
"""Return the type evaluator."""
|
|
76
|
+
from jaclang.compiler.type_system.type_evaluator import TypeEvaluator
|
|
77
|
+
|
|
78
|
+
if not self.type_evaluator:
|
|
79
|
+
self.type_evaluator = TypeEvaluator(program=self)
|
|
80
|
+
return self.type_evaluator
|
|
70
81
|
|
|
71
82
|
def get_bytecode(self, full_target: str) -> Optional[types.CodeType]:
|
|
72
83
|
"""Get the bytecode for a specific module."""
|
|
@@ -120,7 +131,10 @@ class JacProgram:
|
|
|
120
131
|
self.run_schedule(mod=mod_targ, passes=ir_gen_sched)
|
|
121
132
|
if type_check:
|
|
122
133
|
self.run_schedule(mod=mod_targ, passes=type_check_sched)
|
|
123
|
-
|
|
134
|
+
# If the module has syntax errors, we skip code generation.
|
|
135
|
+
if (not mod_targ.has_syntax_errors) and (not no_cgen):
|
|
136
|
+
if settings.predynamo_pass and PreDynamoPass not in py_code_gen:
|
|
137
|
+
py_code_gen.insert(0, PreDynamoPass)
|
|
124
138
|
self.run_schedule(mod=mod_targ, passes=py_code_gen)
|
|
125
139
|
return mod_targ
|
|
126
140
|
|
|
@@ -137,8 +151,6 @@ class JacProgram:
|
|
|
137
151
|
"""Convert a Jac file to an AST."""
|
|
138
152
|
mod_targ = self.compile(file_path, use_str, type_check=type_check)
|
|
139
153
|
JacImportDepsPass(ir_in=mod_targ, prog=self)
|
|
140
|
-
for mod in self.mod.hub.values():
|
|
141
|
-
SymTabLinkPass(ir_in=mod, prog=self)
|
|
142
154
|
for mod in self.mod.hub.values():
|
|
143
155
|
DefUsePass(mod, prog=self)
|
|
144
156
|
return mod_targ
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
print("Hello from Python module!")
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"""Tests for Jac Loader."""
|
|
2
2
|
|
|
3
3
|
import io
|
|
4
|
+
import os
|
|
4
5
|
import sys
|
|
5
6
|
|
|
6
7
|
from jaclang import JacMachine as Jac
|
|
@@ -8,6 +9,7 @@ from jaclang.cli import cli
|
|
|
8
9
|
from jaclang.compiler.program import JacProgram
|
|
9
10
|
from jaclang.runtimelib.machine import JacMachineInterface
|
|
10
11
|
from jaclang.utils.test import TestCase
|
|
12
|
+
from jaclang.settings import settings
|
|
11
13
|
|
|
12
14
|
|
|
13
15
|
class TestLoader(TestCase):
|
|
@@ -128,3 +130,40 @@ class TestLoader(TestCase):
|
|
|
128
130
|
self.assertIn("Helper function called", stdout_value)
|
|
129
131
|
self.assertIn("Tool function executed", stdout_value)
|
|
130
132
|
self.assertIn("pkg_import_lib_py.glob_var_lib", stdout_value)
|
|
133
|
+
|
|
134
|
+
def test_jac_import_py_files(self) -> None:
|
|
135
|
+
"""Test importing Python files using Jac import system."""
|
|
136
|
+
captured_output = io.StringIO()
|
|
137
|
+
sys.stdout = captured_output
|
|
138
|
+
os.environ["JAC_PYFILE_RAISE"] = "True"
|
|
139
|
+
settings.load_env_vars()
|
|
140
|
+
original_cwd = os.getcwd()
|
|
141
|
+
try:
|
|
142
|
+
os.chdir(os.path.dirname(self.fixture_abs_path("jac_import_py_files.py")))
|
|
143
|
+
Jac.set_base_path(self.fixture_abs_path("jac_import_py_files.py"))
|
|
144
|
+
JacMachineInterface.attach_program(
|
|
145
|
+
program:=JacProgram(),
|
|
146
|
+
)
|
|
147
|
+
Jac.jac_import("jac_import_py_files", base_path=self.fixture_abs_path("jac_import_py_files.py"), lng="py")
|
|
148
|
+
cli.run(self.fixture_abs_path("jac_import_py_files.py"))
|
|
149
|
+
sys.stdout = sys.__stdout__
|
|
150
|
+
stdout_value = captured_output.getvalue()
|
|
151
|
+
self.assertIn("This is main test file for jac import of python files", stdout_value)
|
|
152
|
+
self.assertIn("python_module <jaclang.compiler.unitree.Module object", str(program.mod.hub))
|
|
153
|
+
self.assertIn("jac_module <jaclang.compiler.unitree.Module object", str(program.mod.hub))
|
|
154
|
+
os.environ["JAC_PYFILE_RAISE"] = "false"
|
|
155
|
+
settings.load_env_vars()
|
|
156
|
+
os.chdir(os.path.dirname(self.fixture_abs_path("jac_import_py_files.py")))
|
|
157
|
+
Jac.set_base_path(self.fixture_abs_path("jac_import_py_files.py"))
|
|
158
|
+
JacMachineInterface.attach_program(
|
|
159
|
+
program:=JacProgram(),
|
|
160
|
+
)
|
|
161
|
+
Jac.jac_import("jac_import_py_files", base_path=self.fixture_abs_path("jac_import_py_files.py"), lng="py")
|
|
162
|
+
cli.run(self.fixture_abs_path("jac_import_py_files.py"))
|
|
163
|
+
sys.stdout = sys.__stdout__
|
|
164
|
+
stdout_value = captured_output.getvalue()
|
|
165
|
+
self.assertIn("This is main test file for jac import of python files", stdout_value)
|
|
166
|
+
self.assertNotIn("python_module <jaclang.compiler.unitree.Module object", str(program.mod.hub))
|
|
167
|
+
self.assertNotIn("jac_module <jaclang.compiler.unitree.Module object", str(program.mod.hub))
|
|
168
|
+
finally:
|
|
169
|
+
os.chdir(original_cwd)
|
|
@@ -179,5 +179,54 @@ class TestLarkParser(TestCaseMicroSuite):
|
|
|
179
179
|
prog.compile(self.fixture_abs_path("codegentext.jac"))
|
|
180
180
|
self.assertFalse(prog.errors_had)
|
|
181
181
|
|
|
182
|
+
def test_param_syntax(self) -> None:
|
|
183
|
+
"""Parse param syntax jac file."""
|
|
184
|
+
captured_output = io.StringIO()
|
|
185
|
+
sys.stdout = captured_output
|
|
186
|
+
prog = JacProgram()
|
|
187
|
+
prog.compile(self.lang_fixture_abs_path("params/param_syntax_err.jac"))
|
|
188
|
+
sys.stdout = sys.__stdout__
|
|
189
|
+
self.assertEqual(len(prog.errors_had), 8)
|
|
190
|
+
|
|
191
|
+
def test_multiple_syntax_errors(self) -> None:
|
|
192
|
+
"""Parse param syntax jac file."""
|
|
193
|
+
captured_output = io.StringIO()
|
|
194
|
+
sys.stdout = captured_output
|
|
195
|
+
prog = JacProgram()
|
|
196
|
+
prog.compile(self.fixture_abs_path("multiple_syntax_errors.jac"))
|
|
197
|
+
sys.stdout = sys.__stdout__
|
|
198
|
+
self.assertEqual(len(prog.errors_had), 3)
|
|
199
|
+
expected_errors = [
|
|
200
|
+
"""
|
|
201
|
+
Missing RPAREN
|
|
202
|
+
with entry {
|
|
203
|
+
foo = Foo(;
|
|
204
|
+
^
|
|
205
|
+
func(foo bar)
|
|
206
|
+
foo.bar;
|
|
207
|
+
""",
|
|
208
|
+
"""
|
|
209
|
+
Missing COMMA
|
|
210
|
+
with entry {
|
|
211
|
+
foo = Foo(;
|
|
212
|
+
func(foo bar)
|
|
213
|
+
^^^
|
|
214
|
+
foo.bar;
|
|
215
|
+
}
|
|
216
|
+
""",
|
|
217
|
+
"""
|
|
218
|
+
Missing SEMI
|
|
219
|
+
foo = Foo(;
|
|
220
|
+
func(foo bar)
|
|
221
|
+
foo.bar;
|
|
222
|
+
^^^
|
|
223
|
+
}
|
|
224
|
+
"""
|
|
225
|
+
]
|
|
226
|
+
for idx, alrt in enumerate(prog.errors_had):
|
|
227
|
+
pretty = alrt.pretty_print()
|
|
228
|
+
for line in expected_errors[idx].strip().split("\n"):
|
|
229
|
+
line = line.strip()
|
|
230
|
+
self.assertIn(line, pretty)
|
|
182
231
|
|
|
183
232
|
TestLarkParser.self_attach_micro_tests()
|