jaclang 0.4.6__py3-none-any.whl → 0.5.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.
- jaclang/__init__.py +5 -2
- jaclang/cli/cli.py +57 -10
- jaclang/cli/cmdreg.py +16 -9
- jaclang/compiler/__jac_gen__/jac_parser.py +11 -15
- jaclang/compiler/absyntree.py +53 -19
- jaclang/compiler/codeloc.py +3 -1
- jaclang/compiler/{transpiler.py → compile.py} +3 -2
- jaclang/compiler/constant.py +4 -0
- jaclang/compiler/parser.py +156 -108
- jaclang/compiler/passes/ir_pass.py +1 -0
- jaclang/compiler/passes/main/__init__.py +2 -1
- jaclang/compiler/passes/main/def_impl_match_pass.py +1 -0
- jaclang/compiler/passes/main/def_use_pass.py +1 -0
- jaclang/compiler/passes/main/import_pass.py +18 -18
- jaclang/compiler/passes/main/pyast_gen_pass.py +1228 -853
- jaclang/compiler/passes/main/pyast_load_pass.py +3 -1
- jaclang/compiler/passes/main/pybc_gen_pass.py +46 -0
- jaclang/compiler/passes/main/pyout_pass.py +6 -7
- jaclang/compiler/passes/main/schedules.py +5 -9
- jaclang/compiler/passes/main/sub_node_tab_pass.py +1 -0
- jaclang/compiler/passes/main/sym_tab_build_pass.py +21 -9
- jaclang/compiler/passes/main/tests/test_decl_def_match_pass.py +2 -1
- jaclang/compiler/passes/main/tests/test_def_use_pass.py +2 -1
- jaclang/compiler/passes/main/tests/test_import_pass.py +2 -1
- jaclang/compiler/passes/main/tests/test_pyast_build_pass.py +1 -0
- jaclang/compiler/passes/main/tests/test_pyast_gen_pass.py +15 -38
- jaclang/compiler/passes/main/tests/test_pybc_gen_pass.py +25 -0
- jaclang/compiler/passes/main/tests/test_sub_node_pass.py +1 -1
- jaclang/compiler/passes/main/tests/test_sym_tab_build_pass.py +2 -1
- jaclang/compiler/passes/main/tests/test_type_check_pass.py +17 -1
- jaclang/compiler/passes/main/type_check_pass.py +9 -6
- jaclang/compiler/passes/tool/__init__.py +1 -0
- jaclang/compiler/passes/tool/ast_printer_pass.py +1 -0
- jaclang/compiler/passes/tool/fuse_comments_pass.py +1 -1
- jaclang/compiler/passes/tool/jac_formatter_pass.py +69 -32
- jaclang/compiler/passes/tool/schedules.py +1 -0
- jaclang/compiler/passes/tool/sym_tab_printer_pass.py +1 -0
- jaclang/compiler/passes/tool/tests/test_ast_print_pass.py +2 -1
- jaclang/compiler/passes/tool/tests/test_fuse_comments_pass.py +1 -0
- jaclang/compiler/passes/tool/tests/test_jac_format_pass.py +4 -3
- jaclang/compiler/passes/tool/tests/test_symtab_print_pass.py +2 -1
- jaclang/compiler/passes/transform.py +1 -0
- jaclang/compiler/passes/utils/mypy_ast_build.py +203 -17
- jaclang/compiler/symtable.py +1 -0
- jaclang/compiler/tests/test_importer.py +3 -2
- jaclang/compiler/tests/test_parser.py +1 -0
- jaclang/compiler/tests/test_workspace.py +1 -0
- jaclang/compiler/workspace.py +18 -5
- jaclang/core/construct.py +9 -32
- jaclang/{compiler → core}/importer.py +95 -85
- jaclang/core/utils.py +17 -12
- jaclang/plugin/__init__.py +1 -0
- jaclang/plugin/default.py +145 -43
- jaclang/plugin/feature.py +65 -19
- jaclang/plugin/spec.py +56 -34
- jaclang/plugin/tests/test_features.py +9 -0
- jaclang/utils/helpers.py +1 -0
- jaclang/utils/lang_tools.py +13 -19
- jaclang/utils/tests/test_lang_tools.py +2 -1
- jaclang/utils/treeprinter.py +2 -1
- jaclang/vendor/lark/common.py +3 -1
- jaclang/vendor/lark/lexer.py +6 -12
- jaclang/vendor/lark/parsers/lalr_parser.py +1 -0
- jaclang/vendor/mypy/applytype.py +2 -1
- jaclang/vendor/mypy/binder.py +1 -1
- jaclang/vendor/mypy/build.py +7 -9
- jaclang/vendor/mypy/checker.py +57 -33
- jaclang/vendor/mypy/checkexpr.py +42 -29
- jaclang/vendor/mypy/checkmember.py +13 -1
- jaclang/vendor/mypy/checkpattern.py +1 -1
- jaclang/vendor/mypy/checkstrformat.py +2 -4
- jaclang/vendor/mypy/constraints.py +10 -5
- jaclang/vendor/mypy/dmypy_server.py +3 -3
- jaclang/vendor/mypy/dmypy_util.py +62 -3
- jaclang/vendor/mypy/errors.py +1 -1
- jaclang/vendor/mypy/evalexpr.py +1 -0
- jaclang/vendor/mypy/expandtype.py +29 -29
- jaclang/vendor/mypy/fastparse.py +51 -31
- jaclang/vendor/mypy/inspections.py +5 -3
- jaclang/vendor/mypy/join.py +4 -4
- jaclang/vendor/mypy/main.py +6 -6
- jaclang/vendor/mypy/message_registry.py +1 -2
- jaclang/vendor/mypy/messages.py +31 -23
- jaclang/vendor/mypy/metastore.py +1 -2
- jaclang/vendor/mypy/modulefinder.py +2 -22
- jaclang/vendor/mypy/nodes.py +22 -20
- jaclang/vendor/mypy/options.py +4 -0
- jaclang/vendor/mypy/parse.py +6 -2
- jaclang/vendor/mypy/patterns.py +6 -6
- jaclang/vendor/mypy/plugin.py +3 -1
- jaclang/vendor/mypy/plugins/attrs.py +52 -10
- jaclang/vendor/mypy/plugins/common.py +2 -1
- jaclang/vendor/mypy/plugins/enums.py +3 -2
- jaclang/vendor/mypy/plugins/functools.py +1 -0
- jaclang/vendor/mypy/renaming.py +1 -1
- jaclang/vendor/mypy/report.py +15 -15
- jaclang/vendor/mypy/semanal.py +22 -13
- jaclang/vendor/mypy/semanal_enum.py +1 -1
- jaclang/vendor/mypy/semanal_namedtuple.py +1 -2
- jaclang/vendor/mypy/semanal_shared.py +3 -6
- jaclang/vendor/mypy/semanal_typeddict.py +16 -5
- jaclang/vendor/mypy/server/astdiff.py +15 -9
- jaclang/vendor/mypy/server/astmerge.py +5 -5
- jaclang/vendor/mypy/stats.py +0 -5
- jaclang/vendor/mypy/stubdoc.py +1 -1
- jaclang/vendor/mypy/stubgen.py +12 -21
- jaclang/vendor/mypy/stubgenc.py +16 -8
- jaclang/vendor/mypy/stubtest.py +57 -48
- jaclang/vendor/mypy/stubutil.py +28 -15
- jaclang/vendor/mypy/subtypes.py +4 -4
- jaclang/vendor/mypy/test/helpers.py +2 -2
- jaclang/vendor/mypy/test/meta/test_parse_data.py +1 -0
- jaclang/vendor/mypy/test/meta/test_update_data.py +1 -0
- jaclang/vendor/mypy/test/testargs.py +1 -0
- jaclang/vendor/mypy/test/testcheck.py +4 -1
- jaclang/vendor/mypy/test/testconstraints.py +25 -7
- jaclang/vendor/mypy/test/testerrorstream.py +1 -0
- jaclang/vendor/mypy/test/testformatter.py +2 -2
- jaclang/vendor/mypy/test/testparse.py +6 -4
- jaclang/vendor/mypy/test/testpythoneval.py +1 -0
- jaclang/vendor/mypy/test/testreports.py +1 -0
- jaclang/vendor/mypy/test/teststubgen.py +1 -2
- jaclang/vendor/mypy/test/teststubtest.py +98 -4
- jaclang/vendor/mypy/test/testtypes.py +1 -1
- jaclang/vendor/mypy/test/testutil.py +22 -0
- jaclang/vendor/mypy/typeanal.py +302 -158
- jaclang/vendor/mypy/typeops.py +22 -13
- jaclang/vendor/mypy/types.py +33 -34
- jaclang/vendor/mypy/typestate.py +2 -2
- jaclang/vendor/mypy/util.py +7 -6
- jaclang/vendor/mypy/version.py +1 -1
- jaclang/vendor/mypyc/analysis/ircheck.py +1 -0
- jaclang/vendor/mypyc/codegen/emitfunc.py +5 -3
- jaclang/vendor/mypyc/codegen/emitmodule.py +12 -12
- jaclang/vendor/mypyc/codegen/emitwrapper.py +2 -2
- jaclang/vendor/mypyc/ir/class_ir.py +10 -6
- jaclang/vendor/mypyc/irbuild/builder.py +3 -4
- jaclang/vendor/mypyc/irbuild/function.py +5 -3
- jaclang/vendor/mypyc/irbuild/nonlocalcontrol.py +1 -2
- jaclang/vendor/mypyc/irbuild/prepare.py +6 -6
- jaclang/vendor/mypyc/primitives/registry.py +15 -5
- jaclang/vendor/mypyc/test/test_run.py +1 -2
- jaclang/vendor/mypyc/transform/uninit.py +3 -3
- jaclang/vendor/pluggy/_callers.py +1 -0
- jaclang/vendor/pluggy/_hooks.py +6 -10
- jaclang/vendor/pluggy/_result.py +1 -0
- jaclang/vendor/pluggy/_tracing.py +1 -0
- {jaclang-0.4.6.dist-info → jaclang-0.5.0.dist-info}/METADATA +1 -1
- {jaclang-0.4.6.dist-info → jaclang-0.5.0.dist-info}/RECORD +152 -150
- {jaclang-0.4.6.dist-info → jaclang-0.5.0.dist-info}/WHEEL +0 -0
- {jaclang-0.4.6.dist-info → jaclang-0.5.0.dist-info}/entry_points.txt +0 -0
- {jaclang-0.4.6.dist-info → jaclang-0.5.0.dist-info}/top_level.txt +0 -0
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
# type: ignore
|
|
1
2
|
"""Lark parser for Jac Lang."""
|
|
3
|
+
|
|
2
4
|
from __future__ import annotations
|
|
3
5
|
|
|
4
6
|
import ast as py_ast
|
|
@@ -69,7 +71,7 @@ class PyastBuildPass(Pass[ast.PythonModuleAst]):
|
|
|
69
71
|
is_imported=False,
|
|
70
72
|
kid=elements,
|
|
71
73
|
)
|
|
72
|
-
ret.gen.py_ast = node
|
|
74
|
+
ret.gen.py_ast = [node]
|
|
73
75
|
return self.nu(ret)
|
|
74
76
|
|
|
75
77
|
def proc_function_def(
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"""Connect Decls and Defs in AST.
|
|
2
|
+
|
|
3
|
+
This pass creates and manages compilation of Python code from the AST. This pass
|
|
4
|
+
also creates bytecode files from the Python code, and manages the caching of
|
|
5
|
+
relevant files.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import ast as ast3
|
|
9
|
+
import marshal
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
import jaclang.compiler.absyntree as ast
|
|
13
|
+
from jaclang.compiler.passes import Pass
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class PyBytecodeGenPass(Pass):
|
|
17
|
+
"""Python and bytecode file printing pass."""
|
|
18
|
+
|
|
19
|
+
def before_pass(self) -> None:
|
|
20
|
+
"""Before pass."""
|
|
21
|
+
return super().before_pass()
|
|
22
|
+
|
|
23
|
+
def enter_module(self, node: ast.Module) -> None:
|
|
24
|
+
"""Sub objects.
|
|
25
|
+
|
|
26
|
+
name: str,
|
|
27
|
+
doc: Token,
|
|
28
|
+
body: Optional['Elements'],
|
|
29
|
+
mod_path: str,
|
|
30
|
+
is_imported: bool,
|
|
31
|
+
sym_tab: Optional[SymbolTable],
|
|
32
|
+
"""
|
|
33
|
+
mods = [node] + self.get_all_sub_nodes(node, ast.Module)
|
|
34
|
+
for mod in mods:
|
|
35
|
+
if not mod.gen.py_ast or not isinstance(node.gen.py_ast[0], ast3.Module):
|
|
36
|
+
self.error(
|
|
37
|
+
f"Unable to find ast for module {node.loc.mod_path}.",
|
|
38
|
+
node,
|
|
39
|
+
)
|
|
40
|
+
continue
|
|
41
|
+
mod.gen.py_bytecode = marshal.dumps(
|
|
42
|
+
compile(
|
|
43
|
+
source=mod.gen.py_ast[0], filename=mod.loc.mod_path, mode="exec"
|
|
44
|
+
)
|
|
45
|
+
)
|
|
46
|
+
self.terminate()
|
|
@@ -4,8 +4,8 @@ This pass creates and manages compilation of Python code from the AST. This pass
|
|
|
4
4
|
also creates bytecode files from the Python code, and manages the caching of
|
|
5
5
|
relevant files.
|
|
6
6
|
"""
|
|
7
|
+
|
|
7
8
|
import ast as ast3
|
|
8
|
-
import marshal
|
|
9
9
|
import os
|
|
10
10
|
|
|
11
11
|
|
|
@@ -44,7 +44,7 @@ class PyOutPass(Pass):
|
|
|
44
44
|
) > os.path.getmtime(mod_path):
|
|
45
45
|
continue
|
|
46
46
|
self.gen_python(mod, out_path=out_path_py)
|
|
47
|
-
self.
|
|
47
|
+
self.dump_bytecode(mod, mod_path=mod_path, out_path=out_path_pyc)
|
|
48
48
|
self.terminate()
|
|
49
49
|
|
|
50
50
|
def gen_python(self, node: ast.Module, out_path: str) -> None:
|
|
@@ -53,15 +53,14 @@ class PyOutPass(Pass):
|
|
|
53
53
|
with open(out_path, "w") as f:
|
|
54
54
|
f.write(node.gen.py)
|
|
55
55
|
except Exception as e:
|
|
56
|
-
print(ast3.dump(node.gen.py_ast, indent=2))
|
|
56
|
+
print(ast3.dump(node.gen.py_ast[0], indent=2))
|
|
57
57
|
raise e
|
|
58
58
|
|
|
59
|
-
def
|
|
59
|
+
def dump_bytecode(self, node: ast.Module, mod_path: str, out_path: str) -> None:
|
|
60
60
|
"""Generate Python."""
|
|
61
|
-
if
|
|
62
|
-
codeobj = compile(source=node.gen.py_ast, filename=mod_path, mode="exec")
|
|
61
|
+
if node.gen.py_bytecode:
|
|
63
62
|
with open(out_path, "wb") as f:
|
|
64
|
-
|
|
63
|
+
f.write(node.gen.py_bytecode)
|
|
65
64
|
else:
|
|
66
65
|
self.error(
|
|
67
66
|
f"Soemthing went wrong with {node.loc.mod_path} compilation.", node
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
These are various pass schedules for the Jac compiler and static analysis.
|
|
4
4
|
"""
|
|
5
|
+
|
|
5
6
|
from __future__ import annotations
|
|
6
7
|
|
|
7
8
|
|
|
@@ -11,6 +12,7 @@ from .sym_tab_build_pass import SymTabBuildPass # noqa: I100
|
|
|
11
12
|
from .def_impl_match_pass import DeclDefMatchPass # noqa: I100
|
|
12
13
|
from .def_use_pass import DefUsePass # noqa: I100
|
|
13
14
|
from .pyout_pass import PyOutPass # noqa: I100
|
|
15
|
+
from .pybc_gen_pass import PyBytecodeGenPass # noqa: I100
|
|
14
16
|
from .pyast_gen_pass import PyastGenPass # noqa: I100
|
|
15
17
|
from .type_check_pass import JacTypeCheckPass # noqa: I100
|
|
16
18
|
|
|
@@ -21,14 +23,8 @@ py_code_gen = [
|
|
|
21
23
|
DeclDefMatchPass,
|
|
22
24
|
DefUsePass,
|
|
23
25
|
PyastGenPass,
|
|
26
|
+
PyBytecodeGenPass,
|
|
24
27
|
]
|
|
25
28
|
|
|
26
|
-
py_code_gen_typed = [
|
|
27
|
-
|
|
28
|
-
JacTypeCheckPass,
|
|
29
|
-
]
|
|
30
|
-
|
|
31
|
-
py_compiler = [
|
|
32
|
-
*py_code_gen,
|
|
33
|
-
PyOutPass,
|
|
34
|
-
]
|
|
29
|
+
py_code_gen_typed = [*py_code_gen, JacTypeCheckPass]
|
|
30
|
+
py_compiler = [*py_code_gen, PyOutPass]
|
|
@@ -4,6 +4,7 @@ This pass builds a table of subnodes for each node in the AST. This is used
|
|
|
4
4
|
for fast lookup of nodes of a certain type in the AST. This is just a utility
|
|
5
5
|
pass and is not required for any other pass to work.
|
|
6
6
|
"""
|
|
7
|
+
|
|
7
8
|
from copy import copy
|
|
8
9
|
from typing import Optional
|
|
9
10
|
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
This pass builds the symbol table tree for the Jaseci Ast. It also adds symbols
|
|
4
4
|
for globals, imports, architypes, and abilities declarations and definitions.
|
|
5
5
|
"""
|
|
6
|
+
|
|
6
7
|
import ast as ast3
|
|
7
8
|
import builtins
|
|
8
9
|
from typing import Optional, Sequence
|
|
@@ -379,26 +380,37 @@ class SymTabBuildPass(SymTabPass):
|
|
|
379
380
|
for i in node.items.items:
|
|
380
381
|
self.def_insert(i, single_use="import item")
|
|
381
382
|
elif node.is_absorb and node.lang.tag.value == "jac":
|
|
382
|
-
if not node.sub_module or not node.sub_module.sym_tab:
|
|
383
|
+
if not node.paths[0].sub_module or not node.paths[0].sub_module.sym_tab:
|
|
383
384
|
self.error(
|
|
384
|
-
f"Module {node.
|
|
385
|
+
f"Module {node.paths[0].path_str} not found to include *, or ICE occurred!"
|
|
385
386
|
)
|
|
386
387
|
else:
|
|
387
|
-
for v in node.sub_module.sym_tab.tab.values():
|
|
388
|
+
for v in node.paths[0].sub_module.sym_tab.tab.values():
|
|
388
389
|
self.def_insert(v.decl, table_override=self.cur_scope())
|
|
389
|
-
else:
|
|
390
|
-
self.def_insert(
|
|
391
|
-
node.path,
|
|
392
|
-
single_use="import",
|
|
393
|
-
)
|
|
394
390
|
|
|
395
391
|
def enter_module_path(self, node: ast.ModulePath) -> None:
|
|
396
392
|
"""Sub objects.
|
|
397
393
|
|
|
398
|
-
path:
|
|
394
|
+
path: Sequence[Token],
|
|
395
|
+
alias: Optional[Name],
|
|
396
|
+
sub_module: Optional[Module] = None,
|
|
399
397
|
"""
|
|
400
398
|
self.sync_node_to_scope(node)
|
|
401
399
|
|
|
400
|
+
def exit_module_path(self, node: ast.ModulePath) -> None:
|
|
401
|
+
"""Sub objects.
|
|
402
|
+
|
|
403
|
+
path: Sequence[Token],
|
|
404
|
+
alias: Optional[Name],
|
|
405
|
+
sub_module: Optional[Module] = None,
|
|
406
|
+
"""
|
|
407
|
+
if node.alias:
|
|
408
|
+
self.def_insert(node.alias, single_use="import")
|
|
409
|
+
elif isinstance(node.path[0], ast.Name):
|
|
410
|
+
self.def_insert(node.path[0])
|
|
411
|
+
else:
|
|
412
|
+
pass # Need to support pythonic import symbols with dots in it
|
|
413
|
+
|
|
402
414
|
def enter_module_item(self, node: ast.ModuleItem) -> None:
|
|
403
415
|
"""Sub objects.
|
|
404
416
|
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"""Test ast build pass module."""
|
|
2
|
+
|
|
2
3
|
import ast as ast3
|
|
3
4
|
import io
|
|
4
5
|
import sys
|
|
5
6
|
import types
|
|
6
7
|
|
|
7
8
|
import jaclang.compiler.absyntree as ast
|
|
9
|
+
from jaclang.compiler.compile import jac_file_to_pass
|
|
8
10
|
from jaclang.compiler.passes.main import PyastGenPass, SubNodeTabPass
|
|
9
|
-
from jaclang.compiler.transpiler import jac_file_to_pass
|
|
10
11
|
from jaclang.utils.test import AstSyncTestMixin, TestCaseMicroSuite
|
|
11
12
|
|
|
12
13
|
|
|
@@ -39,10 +40,6 @@ class PyastGenPassTests(TestCaseMicroSuite, AstSyncTestMixin):
|
|
|
39
40
|
target=PyastGenPass,
|
|
40
41
|
)
|
|
41
42
|
|
|
42
|
-
# if isinstance(code_gen.ir.gen.py_ast, ast3.AST):
|
|
43
|
-
# print(ast3.dump(code_gen.ir.gen.py_ast, indent=2))
|
|
44
|
-
# print(ast3.unparse(code_gen.ir.gen.py_ast))
|
|
45
|
-
# exec(compile(code_gen.ir.gen.py_ast, "<string>", "exec"))
|
|
46
43
|
self.assertFalse(code_gen.errors_had)
|
|
47
44
|
|
|
48
45
|
def test_circle_py_ast(self) -> None:
|
|
@@ -53,21 +50,10 @@ class PyastGenPassTests(TestCaseMicroSuite, AstSyncTestMixin):
|
|
|
53
50
|
)
|
|
54
51
|
import ast as ast3
|
|
55
52
|
|
|
56
|
-
if
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
# from_py_str = ast3.dump(from_py, indent=2)
|
|
61
|
-
# import difflib
|
|
62
|
-
|
|
63
|
-
# print(
|
|
64
|
-
# "\n".join(
|
|
65
|
-
# difflib.unified_diff(
|
|
66
|
-
# from_jac_str.splitlines(), from_py_str.splitlines(), n=0
|
|
67
|
-
# )
|
|
68
|
-
# )
|
|
69
|
-
# )
|
|
70
|
-
prog = compile(code_gen.ir.gen.py_ast, filename="<ast>", mode="exec")
|
|
53
|
+
if code_gen.ir.gen.py_ast and isinstance(
|
|
54
|
+
code_gen.ir.gen.py_ast[0], ast3.Module
|
|
55
|
+
):
|
|
56
|
+
prog = compile(code_gen.ir.gen.py_ast[0], filename="<ast>", mode="exec")
|
|
71
57
|
captured_output = io.StringIO()
|
|
72
58
|
sys.stdout = captured_output
|
|
73
59
|
module = types.ModuleType("__main__")
|
|
@@ -101,29 +87,20 @@ class PyastGenPassTests(TestCaseMicroSuite, AstSyncTestMixin):
|
|
|
101
87
|
code_gen = jac_file_to_pass(
|
|
102
88
|
self.fixture_abs_path(filename), target=PyastGenPass
|
|
103
89
|
)
|
|
104
|
-
from_jac_str = ast3.dump(code_gen.ir.gen.py_ast, indent=2)
|
|
105
|
-
from_jac = code_gen.ir.gen.py_ast
|
|
90
|
+
from_jac_str = ast3.dump(code_gen.ir.gen.py_ast[0], indent=2)
|
|
91
|
+
from_jac = code_gen.ir.gen.py_ast[0]
|
|
106
92
|
try:
|
|
107
|
-
# back_to_py = ast3.unparse(from_jac)
|
|
108
93
|
compile(from_jac, filename="<ast>", mode="exec")
|
|
109
94
|
except Exception as e:
|
|
110
95
|
print(from_jac_str)
|
|
111
96
|
raise e
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
# from_jac_str.splitlines(), from_py_str.splitlines(), n=6
|
|
120
|
-
# )
|
|
121
|
-
# )
|
|
122
|
-
# )
|
|
123
|
-
# if len(ast_to_list(from_jac)) != len(ast_to_list(from_py)):
|
|
124
|
-
# print(
|
|
125
|
-
# f"\n{filename} - AST node length diff: {len(ast_to_list(from_jac))} vs {len(ast_to_list(from_py))}"
|
|
126
|
-
# )
|
|
97
|
+
for i in ast3.walk(from_jac):
|
|
98
|
+
try:
|
|
99
|
+
if not isinstance(i, (ast3.Load, ast3.Store, ast3.Del)):
|
|
100
|
+
self.assertTrue(hasattr(i, "jac_link"))
|
|
101
|
+
except Exception as e:
|
|
102
|
+
print(filename, ast3.dump(i, indent=2))
|
|
103
|
+
raise e
|
|
127
104
|
self.assertTrue(self.parent_scrub(code_gen.ir))
|
|
128
105
|
self.assertGreater(len(from_jac_str), 10)
|
|
129
106
|
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""Test pass module."""
|
|
2
|
+
|
|
3
|
+
import marshal
|
|
4
|
+
|
|
5
|
+
from jaclang.compiler.compile import jac_file_to_pass
|
|
6
|
+
from jaclang.utils.test import TestCase
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class PyBytecodeGenPassTests(TestCase):
|
|
10
|
+
"""Test pass module."""
|
|
11
|
+
|
|
12
|
+
def setUp(self) -> None:
|
|
13
|
+
"""Set up test."""
|
|
14
|
+
return super().setUp()
|
|
15
|
+
|
|
16
|
+
def test_simple_bcgen(self) -> None:
|
|
17
|
+
"""Basic test for pass."""
|
|
18
|
+
jac_code = jac_file_to_pass(
|
|
19
|
+
file_path=self.fixture_abs_path("func.jac"),
|
|
20
|
+
)
|
|
21
|
+
try:
|
|
22
|
+
marshal.loads(jac_code.ir.gen.py_bytecode)
|
|
23
|
+
self.assertTrue(True)
|
|
24
|
+
except ValueError:
|
|
25
|
+
self.fail("Invalid bytecode generated")
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"""Test pass module."""
|
|
2
|
+
|
|
2
3
|
from typing import List
|
|
3
4
|
|
|
5
|
+
from jaclang.compiler.compile import jac_file_to_pass
|
|
4
6
|
from jaclang.compiler.passes.main.schedules import py_code_gen_typed
|
|
5
|
-
from jaclang.compiler.transpiler import jac_file_to_pass
|
|
6
7
|
from jaclang.utils.test import TestCase
|
|
7
8
|
|
|
8
9
|
|
|
@@ -31,3 +32,18 @@ class MypyTypeCheckPassTests(TestCase):
|
|
|
31
32
|
'(got "str", expected "int")',
|
|
32
33
|
]:
|
|
33
34
|
self.assertIn(i, errs + files)
|
|
35
|
+
|
|
36
|
+
def test_imported_module_typecheck(self) -> None:
|
|
37
|
+
"""Basic test for pass."""
|
|
38
|
+
type_checked = jac_file_to_pass(
|
|
39
|
+
file_path=self.fixture_abs_path("game1.jac"),
|
|
40
|
+
schedule=py_code_gen_typed,
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
errs = "\n".join([i.msg for i in type_checked.warnings_had])
|
|
44
|
+
files = "\n".join([i.loc.mod_path for i in type_checked.warnings_had])
|
|
45
|
+
|
|
46
|
+
for i in [
|
|
47
|
+
'Argument 2 to "is_pressed" of "Button" has incompatible type "int"; expected "str"',
|
|
48
|
+
]:
|
|
49
|
+
self.assertIn(i, errs + files)
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
This is used to call mypy type checking into Jac files by integrating
|
|
4
4
|
mypy apis into Jac and use jac py ast in it.
|
|
5
5
|
"""
|
|
6
|
+
|
|
6
7
|
import os
|
|
7
8
|
import pathlib
|
|
8
9
|
import sys
|
|
@@ -42,8 +43,8 @@ class JacTypeCheckPass(Pass):
|
|
|
42
43
|
|
|
43
44
|
def api(self) -> None:
|
|
44
45
|
"""Call mypy APIs to implement type checking in Jac."""
|
|
45
|
-
# Creating mypy api
|
|
46
|
-
options = myab.Options()
|
|
46
|
+
# Creating mypy api objects
|
|
47
|
+
options = myab.myb.Options()
|
|
47
48
|
errors = myab.Errors(self, options)
|
|
48
49
|
fs_cache = myab.FileSystemCache()
|
|
49
50
|
search_paths = myab.compute_search_paths([], options, str(self.__path))
|
|
@@ -66,16 +67,16 @@ class JacTypeCheckPass(Pass):
|
|
|
66
67
|
stderr=sys.stderr,
|
|
67
68
|
)
|
|
68
69
|
|
|
69
|
-
mypy_graph = {}
|
|
70
|
-
|
|
70
|
+
mypy_graph: myab.Graph = {}
|
|
71
|
+
new_modules = []
|
|
71
72
|
for module in self.__modules:
|
|
72
73
|
tree = myab.ASTConverter(
|
|
73
74
|
options=options,
|
|
74
75
|
is_stub=False,
|
|
75
76
|
errors=errors,
|
|
76
|
-
ignore_errors=False,
|
|
77
77
|
strip_function_bodies=False,
|
|
78
|
-
|
|
78
|
+
path=module.loc.mod_path,
|
|
79
|
+
).visit(module.gen.py_ast[0])
|
|
79
80
|
|
|
80
81
|
st = myab.State(
|
|
81
82
|
id=module.name,
|
|
@@ -86,6 +87,7 @@ class JacTypeCheckPass(Pass):
|
|
|
86
87
|
ast_override=tree,
|
|
87
88
|
)
|
|
88
89
|
mypy_graph[module.name] = st
|
|
90
|
+
new_modules.append(st)
|
|
89
91
|
|
|
90
92
|
graph = myab.load_graph(
|
|
91
93
|
[
|
|
@@ -96,6 +98,7 @@ class JacTypeCheckPass(Pass):
|
|
|
96
98
|
],
|
|
97
99
|
manager,
|
|
98
100
|
old_graph=mypy_graph,
|
|
101
|
+
new_modules=new_modules, # To parse the dependancies of modules
|
|
99
102
|
)
|
|
100
103
|
myab.process_graph(graph, manager)
|
|
101
104
|
myab.semantic_analysis_for_scc(graph, [self.__modules[0].name], errors)
|
|
@@ -27,7 +27,7 @@ class FuseCommentsPass(Pass):
|
|
|
27
27
|
"""Insert comment tokens into all_tokens."""
|
|
28
28
|
comment_stream = iter(self.comments) # Iterator for comments
|
|
29
29
|
code_stream = iter(self.all_tokens) # Iterator for code tokens
|
|
30
|
-
new_stream = [] # New stream to hold ordered tokens
|
|
30
|
+
new_stream: list[ast.AstNode] = [] # New stream to hold ordered tokens
|
|
31
31
|
|
|
32
32
|
try:
|
|
33
33
|
next_comment = next(comment_stream) # Get the first comment
|