jaclang 0.7.18__py3-none-any.whl → 0.7.20__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 +2 -2
- jaclang/compiler/absyntree.py +1 -1
- jaclang/compiler/parser.py +1 -1
- jaclang/compiler/passes/ir_pass.py +2 -0
- jaclang/compiler/passes/main/__init__.py +1 -1
- jaclang/compiler/passes/main/fuse_typeinfo_pass.py +50 -13
- jaclang/compiler/passes/main/import_pass.py +29 -1
- jaclang/compiler/passes/main/py_collect_dep_pass.py +8 -0
- jaclang/compiler/passes/main/registry_pass.py +4 -0
- jaclang/compiler/passes/main/sym_tab_build_pass.py +0 -18
- jaclang/compiler/passes/main/tests/fixtures/mod_type_assign.jac +7 -0
- jaclang/compiler/passes/main/tests/fixtures/pygame_mock/__init__.pyi +3 -0
- jaclang/compiler/passes/main/tests/test_import_pass.py +10 -10
- jaclang/compiler/passes/main/tests/test_type_check_pass.py +1 -1
- jaclang/compiler/passes/main/tests/test_typeinfo_pass.py +23 -1
- jaclang/compiler/passes/main/type_check_pass.py +4 -4
- jaclang/compiler/passes/tool/jac_formatter_pass.py +58 -30
- jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/line_spacing.jac +57 -0
- jaclang/compiler/semtable.py +4 -4
- jaclang/compiler/symtable.py +5 -0
- jaclang/langserve/engine.py +68 -7
- jaclang/langserve/tests/test_server.py +3 -3
- jaclang/langserve/utils.py +0 -113
- jaclang/plugin/tests/test_jaseci.py +23 -4
- jaclang/runtimelib/importer.py +3 -0
- jaclang/runtimelib/machine.py +45 -3
- jaclang/runtimelib/memory.py +1 -1
- jaclang/settings.py +4 -0
- jaclang/stubs/jaclang/__init__.pyi +5 -0
- jaclang/stubs/jaclang/cli/__init__.pyi +0 -0
- jaclang/stubs/jaclang/cli/cli.pyi +58 -0
- jaclang/stubs/jaclang/cli/cmdreg.pyi +32 -0
- jaclang/stubs/jaclang/compiler/__init__.pyi +6 -0
- jaclang/stubs/jaclang/compiler/absyntree.pyi +1248 -0
- jaclang/stubs/jaclang/compiler/codeloc.pyi +45 -0
- jaclang/stubs/jaclang/compiler/compile.pyi +29 -0
- jaclang/stubs/jaclang/compiler/constant.pyi +287 -0
- jaclang/stubs/jaclang/compiler/generated/__init__.pyi +0 -0
- jaclang/stubs/jaclang/compiler/generated/jac_parser.pyi +898 -0
- jaclang/stubs/jaclang/compiler/parser.pyi +266 -0
- jaclang/stubs/jaclang/compiler/passes/__init__.pyi +3 -0
- jaclang/stubs/jaclang/compiler/passes/ir_pass.pyi +40 -0
- jaclang/stubs/jaclang/compiler/passes/main/__init__.pyi +27 -0
- jaclang/stubs/jaclang/compiler/passes/main/access_modifier_pass.pyi +23 -0
- jaclang/stubs/jaclang/compiler/passes/main/def_impl_match_pass.pyi +12 -0
- jaclang/stubs/jaclang/compiler/passes/main/def_use_pass.pyi +31 -0
- jaclang/stubs/jaclang/compiler/passes/main/fuse_typeinfo_pass.pyi +66 -0
- jaclang/stubs/jaclang/compiler/passes/main/import_pass.pyi +34 -0
- jaclang/stubs/jaclang/compiler/passes/main/pyast_gen_pass.pyi +178 -0
- jaclang/stubs/jaclang/compiler/passes/main/pyast_load_pass.pyi +135 -0
- jaclang/stubs/jaclang/compiler/passes/main/pybc_gen_pass.pyi +6 -0
- jaclang/stubs/jaclang/compiler/passes/main/pyjac_ast_link_pass.pyi +22 -0
- jaclang/stubs/jaclang/compiler/passes/main/pyout_pass.pyi +9 -0
- jaclang/stubs/jaclang/compiler/passes/main/registry_pass.pyi +15 -0
- jaclang/stubs/jaclang/compiler/passes/main/schedules.pyi +19 -0
- jaclang/stubs/jaclang/compiler/passes/main/sub_node_tab_pass.pyi +6 -0
- jaclang/stubs/jaclang/compiler/passes/main/sym_tab_build_pass.pyi +147 -0
- jaclang/stubs/jaclang/compiler/passes/main/type_check_pass.pyi +11 -0
- jaclang/stubs/jaclang/compiler/passes/tool/__init__.pyi +4 -0
- jaclang/stubs/jaclang/compiler/passes/tool/fuse_comments_pass.pyi +12 -0
- jaclang/stubs/jaclang/compiler/passes/tool/jac_formatter_pass.pyi +134 -0
- jaclang/stubs/jaclang/compiler/passes/tool/schedules.pyi +11 -0
- jaclang/stubs/jaclang/compiler/passes/transform.pyi +28 -0
- jaclang/stubs/jaclang/compiler/passes/utils/__init__.pyi +0 -0
- jaclang/stubs/jaclang/compiler/passes/utils/mypy_ast_build.pyi +151 -0
- jaclang/stubs/jaclang/compiler/semtable.pyi +35 -0
- jaclang/stubs/jaclang/compiler/symtable.pyi +65 -0
- jaclang/stubs/jaclang/langserve/__init__.pyi +0 -0
- jaclang/stubs/jaclang/langserve/engine.pyi +73 -0
- jaclang/stubs/jaclang/langserve/sem_manager.pyi +89 -0
- jaclang/stubs/jaclang/langserve/server.pyi +38 -0
- jaclang/stubs/jaclang/langserve/utils.pyi +55 -0
- jaclang/stubs/jaclang/plugin/__init__.pyi +3 -0
- jaclang/stubs/jaclang/plugin/builtin.pyi +12 -0
- jaclang/stubs/jaclang/plugin/default.pyi +202 -0
- jaclang/stubs/jaclang/plugin/feature.pyi +176 -0
- jaclang/stubs/jaclang/plugin/spec.pyi +181 -0
- jaclang/stubs/jaclang/runtimelib/__init__.pyi +0 -0
- jaclang/stubs/jaclang/runtimelib/architype.pyi +133 -0
- jaclang/stubs/jaclang/runtimelib/constructs.pyi +41 -0
- jaclang/stubs/jaclang/runtimelib/context.pyi +48 -0
- jaclang/stubs/jaclang/runtimelib/importer.pyi +104 -0
- jaclang/stubs/jaclang/runtimelib/machine.pyi +6 -0
- jaclang/stubs/jaclang/runtimelib/memory.pyi +26 -0
- jaclang/stubs/jaclang/runtimelib/utils.pyi +35 -0
- jaclang/stubs/jaclang/settings.pyi +35 -0
- jaclang/stubs/jaclang/utils/__init__.pyi +0 -0
- jaclang/stubs/jaclang/utils/helpers.pyi +18 -0
- jaclang/stubs/jaclang/utils/lang_tools.pyi +43 -0
- jaclang/stubs/jaclang/utils/log.pyi +3 -0
- jaclang/stubs/jaclang/utils/treeprinter.pyi +47 -0
- jaclang/tests/fixtures/bar.jac +1 -1
- jaclang/tests/fixtures/builtins_test.jac +16 -0
- jaclang/tests/fixtures/foo.jac +0 -1
- jaclang/tests/fixtures/match_multi_ex.jac +12 -0
- jaclang/tests/fixtures/walker_update.jac +19 -0
- jaclang/tests/test_cli.py +29 -2
- jaclang/tests/test_language.py +70 -2
- jaclang/utils/treeprinter.py +1 -1
- {jaclang-0.7.18.dist-info → jaclang-0.7.20.dist-info}/METADATA +4 -2
- {jaclang-0.7.18.dist-info → jaclang-0.7.20.dist-info}/RECORD +103 -34
- {jaclang-0.7.18.dist-info → jaclang-0.7.20.dist-info}/WHEEL +0 -0
- {jaclang-0.7.18.dist-info → jaclang-0.7.20.dist-info}/entry_points.txt +0 -0
jaclang/cli/cli.py
CHANGED
|
@@ -429,8 +429,8 @@ def dot(
|
|
|
429
429
|
|
|
430
430
|
if filename.endswith(".jac"):
|
|
431
431
|
jac_machine = JacMachine(base)
|
|
432
|
-
jac_import(target=mod, base_path=base)
|
|
433
|
-
module = jac_machine.loaded_modules.get(
|
|
432
|
+
jac_import(target=mod, base_path=base, override_name="__main__")
|
|
433
|
+
module = jac_machine.loaded_modules.get("__main__")
|
|
434
434
|
globals().update(vars(module))
|
|
435
435
|
try:
|
|
436
436
|
node = globals().get(initial, eval(initial)) if initial else None
|
jaclang/compiler/absyntree.py
CHANGED
jaclang/compiler/parser.py
CHANGED
|
@@ -3587,7 +3587,7 @@ class JacParser(Pass):
|
|
|
3587
3587
|
match_case_block: KW_CASE pattern_seq (KW_IF expression)? COLON statement_list
|
|
3588
3588
|
"""
|
|
3589
3589
|
pattern = kid[1]
|
|
3590
|
-
guard = kid[3] if
|
|
3590
|
+
guard = kid[3] if isinstance(kid[3], ast.Expr) else None
|
|
3591
3591
|
stmts = [i for i in kid if isinstance(i, ast.CodeBlockStmt)]
|
|
3592
3592
|
if isinstance(pattern, ast.MatchPattern) and isinstance(
|
|
3593
3593
|
guard, (ast.Expr, type(None))
|
|
@@ -6,6 +6,7 @@ mypy apis into Jac and use jac py ast in it.
|
|
|
6
6
|
|
|
7
7
|
from __future__ import annotations
|
|
8
8
|
|
|
9
|
+
import re
|
|
9
10
|
from typing import Callable, Optional, TypeVar
|
|
10
11
|
|
|
11
12
|
import jaclang.compiler.absyntree as ast
|
|
@@ -46,24 +47,24 @@ class FuseTypeInfoPass(Pass):
|
|
|
46
47
|
)
|
|
47
48
|
|
|
48
49
|
def __set_sym_table_link(self, node: ast.AstSymbolNode) -> None:
|
|
49
|
-
typ = node.sym_type.split(".")
|
|
50
50
|
typ_sym_table = self.ir.sym_tab
|
|
51
|
+
assert isinstance(self.ir, ast.Module)
|
|
51
52
|
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
sym_type = node.sym_type
|
|
54
|
+
if re.match(r"builtins.(list|dict|tuple)", sym_type):
|
|
55
|
+
sym_type = re.sub(r"\[.*\]", "", sym_type)
|
|
56
|
+
|
|
57
|
+
typ = sym_type.split(".")
|
|
54
58
|
|
|
55
59
|
if node.sym_type == "types.ModuleType" and node.sym:
|
|
56
60
|
node.name_spec.type_sym_tab = node.sym.parent_tab.find_scope(node.sym_name)
|
|
57
61
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
f = typ_sym_table.find_scope(i)
|
|
65
|
-
if f:
|
|
66
|
-
typ_sym_table = f
|
|
62
|
+
for i in typ:
|
|
63
|
+
if i == self.ir.name:
|
|
64
|
+
continue
|
|
65
|
+
f = typ_sym_table.find_scope(i)
|
|
66
|
+
if f:
|
|
67
|
+
typ_sym_table = f
|
|
67
68
|
|
|
68
69
|
if typ_sym_table != self.ir.sym_tab:
|
|
69
70
|
node.name_spec.type_sym_tab = typ_sym_table
|
|
@@ -144,6 +145,11 @@ class FuseTypeInfoPass(Pass):
|
|
|
144
145
|
self.__set_sym_table_link(node)
|
|
145
146
|
self.__collect_python_dependencies(node)
|
|
146
147
|
|
|
148
|
+
# Special handing for BuiltinType
|
|
149
|
+
elif isinstance(node, ast.BuiltinType):
|
|
150
|
+
func(self, node) # type: ignore
|
|
151
|
+
self.__set_sym_table_link(node)
|
|
152
|
+
|
|
147
153
|
# Jac node doesn't have mypy nodes linked to it
|
|
148
154
|
else:
|
|
149
155
|
self.__debug_print(
|
|
@@ -209,10 +215,21 @@ class FuseTypeInfoPass(Pass):
|
|
|
209
215
|
f"{type(mypy_node)}"
|
|
210
216
|
)
|
|
211
217
|
|
|
218
|
+
def __check_builltin_symbol(self, node: ast.NameAtom) -> None:
|
|
219
|
+
if isinstance(node.parent, ast.AtomTrailer) and node is node.parent.right:
|
|
220
|
+
return
|
|
221
|
+
builtins_sym_tab = self.ir.sym_tab.find_scope("builtins")
|
|
222
|
+
assert builtins_sym_tab is not None
|
|
223
|
+
builtins_sym = builtins_sym_tab.lookup(node.sym_name)
|
|
224
|
+
if builtins_sym:
|
|
225
|
+
node.name_spec._sym = builtins_sym
|
|
226
|
+
|
|
212
227
|
@__handle_node
|
|
213
228
|
def enter_name(self, node: ast.NameAtom) -> None:
|
|
214
229
|
"""Pass handler for name nodes."""
|
|
215
230
|
self.__collect_type_from_symbol(node)
|
|
231
|
+
if node.sym is None:
|
|
232
|
+
self.__check_builltin_symbol(node)
|
|
216
233
|
|
|
217
234
|
@__handle_node
|
|
218
235
|
def enter_module_path(self, node: ast.ModulePath) -> None:
|
|
@@ -423,7 +440,8 @@ class FuseTypeInfoPass(Pass):
|
|
|
423
440
|
@__handle_node
|
|
424
441
|
def enter_builtin_type(self, node: ast.BuiltinType) -> None:
|
|
425
442
|
"""Pass handler for BuiltinType nodes."""
|
|
426
|
-
self.
|
|
443
|
+
self.__check_builltin_symbol(node)
|
|
444
|
+
node.name_spec.sym_type = f"builtins.{node.sym_name}"
|
|
427
445
|
|
|
428
446
|
def get_type_from_instance(
|
|
429
447
|
self, node: ast.AstSymbolNode, mypy_type: MypyTypes.Instance
|
|
@@ -483,6 +501,21 @@ class FuseTypeInfoPass(Pass):
|
|
|
483
501
|
if self_obj.type_sym_tab and isinstance(right_obj, ast.AstSymbolNode):
|
|
484
502
|
self_obj.type_sym_tab.def_insert(right_obj)
|
|
485
503
|
|
|
504
|
+
# Support adding the correct type symbol table in case of ModuleType
|
|
505
|
+
# This will only work for target=Val & target1=target2=val and
|
|
506
|
+
# target is a moduleType
|
|
507
|
+
# it won't work in case of
|
|
508
|
+
# - target1, target2 = Val1, Val2 <-- tuples need more attention
|
|
509
|
+
# - target = a.b.c <-- will be fixed after thakee's PR
|
|
510
|
+
# - a.b.c = val <-- will be fixed after thakee's PR
|
|
511
|
+
for target in node.target.items:
|
|
512
|
+
if (
|
|
513
|
+
isinstance(target, ast.Name)
|
|
514
|
+
and target.sym_type == "types.ModuleType"
|
|
515
|
+
and isinstance(node.value, ast.Name)
|
|
516
|
+
):
|
|
517
|
+
target.type_sym_tab = node.value.type_sym_tab
|
|
518
|
+
|
|
486
519
|
def expand_atom_trailer(self, node_list: list[ast.AstNode]) -> list[ast.AstNode]:
|
|
487
520
|
"""Expand the atom trailer object in a list of AstNode."""
|
|
488
521
|
out: list[ast.AstNode] = []
|
|
@@ -552,6 +585,10 @@ class FuseTypeInfoPass(Pass):
|
|
|
552
585
|
type_symtab: Optional[SymbolTable] = self.ir.sym_tab
|
|
553
586
|
assert isinstance(self.ir, ast.Module)
|
|
554
587
|
assert isinstance(type_symtab, SymbolTable)
|
|
588
|
+
|
|
589
|
+
if re.match(r"builtins.(list|dict|tuple)", node_type):
|
|
590
|
+
node_type = re.sub(r"\[.*\]", "", node_type)
|
|
591
|
+
|
|
555
592
|
for j in node_type.split("."):
|
|
556
593
|
if j == self.ir.name:
|
|
557
594
|
continue
|
|
@@ -7,12 +7,14 @@ symbols are available for matching.
|
|
|
7
7
|
|
|
8
8
|
import ast as py_ast
|
|
9
9
|
import os
|
|
10
|
+
import pathlib
|
|
10
11
|
from typing import Optional
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
import jaclang.compiler.absyntree as ast
|
|
14
15
|
from jaclang.compiler.passes import Pass
|
|
15
16
|
from jaclang.compiler.passes.main import SubNodeTabPass, SymTabBuildPass
|
|
17
|
+
from jaclang.settings import settings
|
|
16
18
|
from jaclang.utils.log import logging
|
|
17
19
|
|
|
18
20
|
|
|
@@ -105,7 +107,7 @@ class JacImportPass(Pass):
|
|
|
105
107
|
or test_folder == os.path.dirname(cur_file)
|
|
106
108
|
) and cur_file.endswith(".test.jac"):
|
|
107
109
|
mod = self.import_jac_mod_from_file(cur_file)
|
|
108
|
-
if mod:
|
|
110
|
+
if mod and not settings.ignore_test_annex:
|
|
109
111
|
node.test_mod.append(mod)
|
|
110
112
|
node.add_kids_right([mod], pos_update=False)
|
|
111
113
|
mod.parent = node
|
|
@@ -199,6 +201,7 @@ class PyImportPass(JacImportPass):
|
|
|
199
201
|
def before_pass(self) -> None:
|
|
200
202
|
"""Only run pass if settings are set to raise python."""
|
|
201
203
|
super().before_pass()
|
|
204
|
+
self.__load_builtins()
|
|
202
205
|
|
|
203
206
|
def __get_current_module(self, node: ast.AstNode) -> str:
|
|
204
207
|
parent = node.find_parent_of_type(ast.Module)
|
|
@@ -295,6 +298,31 @@ class PyImportPass(JacImportPass):
|
|
|
295
298
|
raise e
|
|
296
299
|
return None
|
|
297
300
|
|
|
301
|
+
def __load_builtins(self) -> None:
|
|
302
|
+
"""Pyraise builtins to help with builtins auto complete."""
|
|
303
|
+
from jaclang.compiler.passes.main import PyastBuildPass
|
|
304
|
+
|
|
305
|
+
assert isinstance(self.ir, ast.Module)
|
|
306
|
+
|
|
307
|
+
file_to_raise = str(
|
|
308
|
+
pathlib.Path(os.path.dirname(__file__)).parent.parent.parent
|
|
309
|
+
/ "vendor"
|
|
310
|
+
/ "mypy"
|
|
311
|
+
/ "typeshed"
|
|
312
|
+
/ "stdlib"
|
|
313
|
+
/ "builtins.pyi"
|
|
314
|
+
)
|
|
315
|
+
with open(file_to_raise, "r", encoding="utf-8") as f:
|
|
316
|
+
mod = PyastBuildPass(
|
|
317
|
+
input_ir=ast.PythonModuleAst(
|
|
318
|
+
py_ast.parse(f.read()), mod_path=file_to_raise
|
|
319
|
+
),
|
|
320
|
+
).ir
|
|
321
|
+
mod.parent = self.ir
|
|
322
|
+
SubNodeTabPass(input_ir=mod, prior=self)
|
|
323
|
+
SymTabBuildPass(input_ir=mod, prior=self)
|
|
324
|
+
mod.parent = None
|
|
325
|
+
|
|
298
326
|
def annex_impl(self, node: ast.Module) -> None:
|
|
299
327
|
"""Annex impl and test modules."""
|
|
300
328
|
return None
|
|
@@ -7,6 +7,8 @@ that are only relevant to actual references source from Jac code.
|
|
|
7
7
|
from __future__ import annotations
|
|
8
8
|
|
|
9
9
|
|
|
10
|
+
import os
|
|
11
|
+
|
|
10
12
|
import jaclang.compiler.absyntree as ast
|
|
11
13
|
from jaclang.compiler.passes import Pass
|
|
12
14
|
from jaclang.settings import settings
|
|
@@ -28,11 +30,15 @@ class PyCollectDepsPass(Pass):
|
|
|
28
30
|
if not isinstance(node, ast.AstSymbolNode):
|
|
29
31
|
return
|
|
30
32
|
|
|
33
|
+
# Adding the path of the file related to the py import
|
|
31
34
|
path: str = ""
|
|
32
35
|
if isinstance(node, ast.ModulePath):
|
|
33
36
|
if node.path:
|
|
34
37
|
path = ".".join([i.value for i in node.path])
|
|
35
38
|
node.abs_path = self.ir.py_mod_dep_map.get(path)
|
|
39
|
+
if node.abs_path and os.path.isfile(node.abs_path.replace(".pyi", ".py")):
|
|
40
|
+
node.abs_path = node.abs_path.replace(".pyi", ".py")
|
|
41
|
+
|
|
36
42
|
elif isinstance(node, ast.ModuleItem):
|
|
37
43
|
imp = node.parent_of_type(ast.Import)
|
|
38
44
|
mod_path_node = imp.get_all_sub_nodes(ast.ModulePath)[0]
|
|
@@ -40,6 +46,8 @@ class PyCollectDepsPass(Pass):
|
|
|
40
46
|
path = ".".join([i.value for i in mod_path_node.path])
|
|
41
47
|
path += f".{node.name.value}"
|
|
42
48
|
node.abs_path = self.ir.py_mod_dep_map.get(path)
|
|
49
|
+
if node.abs_path and os.path.isfile(node.abs_path.replace(".pyi", ".py")):
|
|
50
|
+
node.abs_path = node.abs_path.replace(".pyi", ".py")
|
|
43
51
|
|
|
44
52
|
if len(node.gen.mypy_ast) == 0:
|
|
45
53
|
return
|
|
@@ -14,6 +14,7 @@ from jaclang.compiler.constant import Constants as Con
|
|
|
14
14
|
from jaclang.compiler.passes import Pass
|
|
15
15
|
from jaclang.compiler.semtable import SemInfo, SemRegistry
|
|
16
16
|
from jaclang.runtimelib.utils import get_sem_scope
|
|
17
|
+
from jaclang.settings import settings
|
|
17
18
|
|
|
18
19
|
|
|
19
20
|
class RegistryPass(Pass):
|
|
@@ -23,6 +24,9 @@ class RegistryPass(Pass):
|
|
|
23
24
|
|
|
24
25
|
def enter_module(self, node: ast.Module) -> None:
|
|
25
26
|
"""Create registry for each module."""
|
|
27
|
+
if settings.disable_mtllm:
|
|
28
|
+
self.terminate()
|
|
29
|
+
return None
|
|
26
30
|
node.registry = SemRegistry()
|
|
27
31
|
self.modules_visited.append(node)
|
|
28
32
|
|
|
@@ -4,10 +4,7 @@ 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 builtins
|
|
8
|
-
|
|
9
7
|
import jaclang.compiler.absyntree as ast
|
|
10
|
-
from jaclang.compiler.constant import Tokens as Tok
|
|
11
8
|
from jaclang.compiler.passes import Pass
|
|
12
9
|
from jaclang.compiler.symtable import SymbolTable
|
|
13
10
|
|
|
@@ -54,21 +51,6 @@ class SymTabBuildPass(Pass):
|
|
|
54
51
|
"""
|
|
55
52
|
self.push_scope(node.name, node)
|
|
56
53
|
self.sync_node_to_scope(node)
|
|
57
|
-
for obj in dir(builtins):
|
|
58
|
-
builtin = ast.Name(
|
|
59
|
-
file_path=node.loc.mod_path,
|
|
60
|
-
name=Tok.NAME,
|
|
61
|
-
value=str(obj),
|
|
62
|
-
line=0,
|
|
63
|
-
end_line=0,
|
|
64
|
-
col_start=0,
|
|
65
|
-
col_end=0,
|
|
66
|
-
pos_start=0,
|
|
67
|
-
pos_end=0,
|
|
68
|
-
)
|
|
69
|
-
self.sync_node_to_scope(builtin)
|
|
70
|
-
builtin.sym_tab.def_insert(builtin)
|
|
71
|
-
# self.def_insert(ast.Name.gen_stub_from_node(node.name, "root"))
|
|
72
54
|
|
|
73
55
|
def exit_module(self, node: ast.Module) -> None:
|
|
74
56
|
"""Sub objects.
|
|
@@ -70,19 +70,19 @@ class ImportPassPassTests(TestCase):
|
|
|
70
70
|
)
|
|
71
71
|
assert isinstance(build.ir, ast.Module)
|
|
72
72
|
p = {
|
|
73
|
-
"math": "jaclang/
|
|
74
|
-
"pygame_mock": "pygame_mock/__init__.
|
|
75
|
-
"pygame_mock.color": "pygame_mock/color.py",
|
|
76
|
-
"pygame_mock.constants": "pygame_mock/constants.py",
|
|
77
|
-
"argparse": "jaclang/vendor/mypy/typeshed/stdlib/argparse.pyi",
|
|
78
|
-
"builtins": "jaclang/vendor/mypy/typeshed/stdlib/builtins.pyi",
|
|
79
|
-
"pygame_mock.display": "pygame_mock/display.py",
|
|
80
|
-
"os": "jaclang/vendor/mypy/typeshed/stdlib/os/__init__.pyi",
|
|
81
|
-
"genericpath": "jaclang/vendor/mypy/typeshed/stdlib/genericpath.pyi",
|
|
73
|
+
"math": r"jaclang/vendor/mypy/typeshed/stdlib/math.pyi$",
|
|
74
|
+
"pygame_mock": r"pygame_mock/__init__.pyi$",
|
|
75
|
+
"pygame_mock.color": r"pygame_mock/color.py$",
|
|
76
|
+
"pygame_mock.constants": r"pygame_mock/constants.py$",
|
|
77
|
+
"argparse": r"jaclang/vendor/mypy/typeshed/stdlib/argparse.pyi$",
|
|
78
|
+
"builtins": r"jaclang/vendor/mypy/typeshed/stdlib/builtins.pyi$",
|
|
79
|
+
"pygame_mock.display": r"pygame_mock/display.py$",
|
|
80
|
+
"os": r"jaclang/vendor/mypy/typeshed/stdlib/os/__init__.pyi$",
|
|
81
|
+
"genericpath": r"jaclang/vendor/mypy/typeshed/stdlib/genericpath.pyi$",
|
|
82
82
|
}
|
|
83
83
|
for i in p:
|
|
84
84
|
self.assertIn(i, build.ir.py_raise_map)
|
|
85
|
-
self.
|
|
85
|
+
self.assertRegex(re.sub(r".*fixtures/", "", build.ir.py_raise_map[i]), p[i])
|
|
86
86
|
|
|
87
87
|
def test_py_raised_mods(self) -> None:
|
|
88
88
|
"""Basic test for pass."""
|
|
@@ -59,6 +59,6 @@ class MypyTypeCheckPassTests(TestCase):
|
|
|
59
59
|
self.assertIn("HasVar - species - Type: builtins.str", out)
|
|
60
60
|
self.assertIn("myDog - Type: type_info.Dog", out)
|
|
61
61
|
self.assertIn("Body - Type: type_info.Dog.Body", out)
|
|
62
|
-
self.assertEqual(out.count("Type: builtins.str"),
|
|
62
|
+
self.assertEqual(out.count("Type: builtins.str"), 34)
|
|
63
63
|
for i in lis:
|
|
64
64
|
self.assertNotIn(i, out)
|
|
@@ -1,7 +1,29 @@
|
|
|
1
1
|
"""Test pass module."""
|
|
2
2
|
|
|
3
|
+
from jaclang.compiler.compile import jac_file_to_pass
|
|
4
|
+
from jaclang.compiler.passes.main.fuse_typeinfo_pass import FuseTypeInfoPass
|
|
5
|
+
from jaclang.compiler.passes.main.schedules import py_code_gen_typed
|
|
3
6
|
from jaclang.utils.test import TestCase
|
|
4
7
|
|
|
5
8
|
|
|
6
9
|
class TestFuseTypeInfo(TestCase):
|
|
7
|
-
"""Test
|
|
10
|
+
"""Test FuseTypeInfoPass module."""
|
|
11
|
+
|
|
12
|
+
def setUp(self) -> None:
|
|
13
|
+
"""Set up test."""
|
|
14
|
+
return super().setUp()
|
|
15
|
+
|
|
16
|
+
def test_mod_type_assign(self) -> None:
|
|
17
|
+
"""Test module type assignment."""
|
|
18
|
+
gen_ast = jac_file_to_pass(
|
|
19
|
+
self.fixture_abs_path("mod_type_assign.jac"),
|
|
20
|
+
FuseTypeInfoPass,
|
|
21
|
+
schedule=py_code_gen_typed,
|
|
22
|
+
).ir.pp()
|
|
23
|
+
type_info_list = [
|
|
24
|
+
"kl - Type: types.ModuleType, SymbolTable: blip",
|
|
25
|
+
"l1 - Type: types.ModuleType, SymbolTable: blip",
|
|
26
|
+
"l2 - Type: types.ModuleType, SymbolTable: blip",
|
|
27
|
+
]
|
|
28
|
+
for type_info in type_info_list:
|
|
29
|
+
self.assertIn(type_info, str(gen_ast))
|
|
@@ -51,10 +51,10 @@ class JacTypeCheckPass(Pass):
|
|
|
51
51
|
options.ignore_missing_imports = True
|
|
52
52
|
options.cache_dir = Con.JAC_MYPY_CACHE
|
|
53
53
|
options.mypy_path = [
|
|
54
|
-
str(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
)
|
|
54
|
+
# str( # TODO: Remove me, this was the wrong way to point to stubs
|
|
55
|
+
# pathlib.Path(os.path.dirname(__file__)).parent.parent.parent.parent
|
|
56
|
+
# / "stubs"
|
|
57
|
+
# )
|
|
58
58
|
]
|
|
59
59
|
if top_module_path != "":
|
|
60
60
|
options.mypy_path.append(top_module_path)
|
|
@@ -126,11 +126,14 @@ class JacFormatPass(Pass):
|
|
|
126
126
|
last_element = None
|
|
127
127
|
for counter, i in enumerate(node.body):
|
|
128
128
|
counter += 1
|
|
129
|
+
if last_element and (
|
|
130
|
+
i.loc.first_line - last_element.loc.last_line > 1
|
|
131
|
+
and not last_element.gen.jac.endswith("\n\n")
|
|
132
|
+
):
|
|
133
|
+
self.emit_ln(node, "")
|
|
129
134
|
if isinstance(i, ast.Import):
|
|
130
135
|
self.emit_ln(node, i.gen.jac)
|
|
131
136
|
else:
|
|
132
|
-
if isinstance(last_element, ast.Import):
|
|
133
|
-
self.emit_ln(node, "")
|
|
134
137
|
if last_element and (
|
|
135
138
|
isinstance(i, ast.Architype)
|
|
136
139
|
and isinstance(last_element, ast.Architype)
|
|
@@ -140,21 +143,6 @@ class JacFormatPass(Pass):
|
|
|
140
143
|
self.emit_ln(node, "")
|
|
141
144
|
self.emit_ln(node, i.gen.jac)
|
|
142
145
|
|
|
143
|
-
if counter <= len(node.body) - 1:
|
|
144
|
-
if (
|
|
145
|
-
isinstance(i, ast.Ability)
|
|
146
|
-
and isinstance(node.body[counter], ast.Ability)
|
|
147
|
-
and i.gen.jac.endswith(";")
|
|
148
|
-
or (
|
|
149
|
-
isinstance(i, ast.Architype)
|
|
150
|
-
and len(node.body[counter].kid[-1].kid) == 2
|
|
151
|
-
and len(node.body[counter - 1].kid[-1].kid) == 2
|
|
152
|
-
)
|
|
153
|
-
and node.gen.jac.endswith("\n")
|
|
154
|
-
):
|
|
155
|
-
self.emit(node, "")
|
|
156
|
-
else:
|
|
157
|
-
self.emit_ln(node, "")
|
|
158
146
|
last_element = i
|
|
159
147
|
|
|
160
148
|
def exit_global_vars(self, node: ast.GlobalVars) -> None:
|
|
@@ -222,6 +210,20 @@ class JacFormatPass(Pass):
|
|
|
222
210
|
"""
|
|
223
211
|
prev_token = None
|
|
224
212
|
for stmt in node.kid:
|
|
213
|
+
line_emiited = False
|
|
214
|
+
if prev_token and stmt.loc.first_line - prev_token.loc.last_line > 1:
|
|
215
|
+
if (
|
|
216
|
+
stmt.kid
|
|
217
|
+
and isinstance(stmt.kid[-1], ast.SubNodeList)
|
|
218
|
+
and not isinstance(stmt.kid[-1].kid[-1], ast.CommentToken)
|
|
219
|
+
):
|
|
220
|
+
self.emit(node, "")
|
|
221
|
+
|
|
222
|
+
else:
|
|
223
|
+
line_emiited = True
|
|
224
|
+
self.indent_level -= 1
|
|
225
|
+
self.emit_ln(node, "")
|
|
226
|
+
self.indent_level += 1
|
|
225
227
|
if isinstance(node.parent, (ast.EnumDef, ast.Enum)) and stmt.gen.jac == ",":
|
|
226
228
|
self.indent_level -= 1
|
|
227
229
|
self.emit_ln(node, f"{stmt.gen.jac}")
|
|
@@ -266,9 +268,10 @@ class JacFormatPass(Pass):
|
|
|
266
268
|
self.indent_level += 1
|
|
267
269
|
else:
|
|
268
270
|
self.emit(node, f" {stmt.gen.jac}")
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
271
|
+
if not line_emiited:
|
|
272
|
+
self.indent_level -= 1
|
|
273
|
+
self.emit_ln(node, "")
|
|
274
|
+
self.indent_level += 1
|
|
272
275
|
else:
|
|
273
276
|
if not node.gen.jac.endswith("\n"):
|
|
274
277
|
self.indent_level -= 1
|
|
@@ -279,12 +282,21 @@ class JacFormatPass(Pass):
|
|
|
279
282
|
if prev_token and isinstance(prev_token, ast.Ability):
|
|
280
283
|
self.emit(node, f"{stmt.gen.jac}")
|
|
281
284
|
else:
|
|
282
|
-
self.
|
|
283
|
-
if
|
|
285
|
+
token_before = self.token_before(stmt)
|
|
286
|
+
if (
|
|
287
|
+
token_before is not None
|
|
288
|
+
and isinstance(token_before, ast.Token)
|
|
289
|
+
and token_before.name == Tok.LBRACE
|
|
290
|
+
and stmt.loc.first_line - token_before.loc.last_line > 1
|
|
291
|
+
):
|
|
284
292
|
self.indent_level -= 1
|
|
285
|
-
self.emit_ln(stmt, "")
|
|
286
293
|
self.emit_ln(node, "")
|
|
287
294
|
self.indent_level += 1
|
|
295
|
+
self.emit(node, stmt.gen.jac)
|
|
296
|
+
self.indent_level -= 1
|
|
297
|
+
self.emit_ln(stmt, "")
|
|
298
|
+
self.emit_ln(node, "")
|
|
299
|
+
self.indent_level += 1
|
|
288
300
|
elif stmt.gen.jac == ",":
|
|
289
301
|
self.emit(node, f"{stmt.value} ")
|
|
290
302
|
elif stmt.value == "=":
|
|
@@ -304,10 +316,29 @@ class JacFormatPass(Pass):
|
|
|
304
316
|
isinstance(prev_token, ast.Ability)
|
|
305
317
|
and isinstance(stmt, (ast.Ability, ast.AbilityDef))
|
|
306
318
|
):
|
|
307
|
-
if
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
319
|
+
if (
|
|
320
|
+
not isinstance(prev_token.kid[-1], ast.CommentToken)
|
|
321
|
+
and not line_emiited
|
|
322
|
+
):
|
|
323
|
+
if (
|
|
324
|
+
prev_token.kid
|
|
325
|
+
and isinstance(prev_token.kid[-1], ast.SubNodeList)
|
|
326
|
+
and isinstance(prev_token.kid[-1].kid[-1], ast.CommentToken)
|
|
327
|
+
):
|
|
328
|
+
if (
|
|
329
|
+
prev_token
|
|
330
|
+
and stmt.loc.first_line - prev_token.kid[-1].kid[-1].line_no
|
|
331
|
+
> 1
|
|
332
|
+
):
|
|
333
|
+
self.indent_level -= 1
|
|
334
|
+
self.emit_ln(node, "")
|
|
335
|
+
self.indent_level += 1
|
|
336
|
+
else:
|
|
337
|
+
self.emit(node, "")
|
|
338
|
+
else:
|
|
339
|
+
self.indent_level -= 1
|
|
340
|
+
self.emit_ln(node, "")
|
|
341
|
+
self.indent_level += 1
|
|
311
342
|
self.emit(node, stmt.gen.jac)
|
|
312
343
|
else:
|
|
313
344
|
if prev_token and prev_token.gen.jac.strip() == "{":
|
|
@@ -907,8 +938,6 @@ class JacFormatPass(Pass):
|
|
|
907
938
|
"""Check if the length of the current generated code exceeds the max line length."""
|
|
908
939
|
if max_line_length == 0:
|
|
909
940
|
max_line_length = self.MAX_LINE_LENGTH
|
|
910
|
-
# print(content)
|
|
911
|
-
# print(len(content))
|
|
912
941
|
return len(content) > max_line_length
|
|
913
942
|
|
|
914
943
|
def exit_binary_expr(self, node: ast.BinaryExpr) -> None:
|
|
@@ -958,7 +987,6 @@ class JacFormatPass(Pass):
|
|
|
958
987
|
self.error(
|
|
959
988
|
f"Binary operator {node.op.value} not supported in bootstrap Jac"
|
|
960
989
|
)
|
|
961
|
-
# print(node.gen)
|
|
962
990
|
if isinstance(
|
|
963
991
|
node.kid[-1], (ast.Semi, ast.CommentToken)
|
|
964
992
|
) and not node.gen.jac.endswith("\n"):
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import:py math;
|
|
2
|
+
|
|
3
|
+
glob RAD = 5;
|
|
4
|
+
|
|
5
|
+
glob DIA = 10;
|
|
6
|
+
|
|
7
|
+
# this comment is for walker
|
|
8
|
+
|
|
9
|
+
walker decorator_walk {
|
|
10
|
+
can hash(func: Any) {
|
|
11
|
+
can inner(a: Any) {
|
|
12
|
+
print(("#" * 20));
|
|
13
|
+
func(a);
|
|
14
|
+
print(("#" * 20));
|
|
15
|
+
}
|
|
16
|
+
return inner;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
can exclaim(func: Any) {
|
|
20
|
+
can inner(b: Any) {
|
|
21
|
+
print(("!" * 20));
|
|
22
|
+
func(b);
|
|
23
|
+
print(("!" * 20));
|
|
24
|
+
}
|
|
25
|
+
return inner;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
can tilde(func: Any) {
|
|
29
|
+
can inner(c: Any) {
|
|
30
|
+
print(("~" * 20));
|
|
31
|
+
func(c);
|
|
32
|
+
print(("~" * 20));
|
|
33
|
+
}
|
|
34
|
+
return inner;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
can greeter(name: Any) {
|
|
38
|
+
print("Hello, " + name + "!");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
# Entry point for the walker
|
|
42
|
+
|
|
43
|
+
can start with entry {
|
|
44
|
+
|
|
45
|
+
# Apply decorators to greeter
|
|
46
|
+
decorated_greeter = hash(exclaim(tilde(greeter)));
|
|
47
|
+
|
|
48
|
+
# Call the decorated greeter function
|
|
49
|
+
decorated_greeter("World");
|
|
50
|
+
|
|
51
|
+
# this is another comment
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
with entry {
|
|
56
|
+
root spawn decorator_walk();
|
|
57
|
+
}
|
jaclang/compiler/semtable.py
CHANGED
|
@@ -19,13 +19,13 @@ class SemInfo:
|
|
|
19
19
|
self,
|
|
20
20
|
node: ast.AstNode,
|
|
21
21
|
name: str,
|
|
22
|
-
|
|
22
|
+
type_str: Optional[str] = None,
|
|
23
23
|
semstr: str = "",
|
|
24
24
|
) -> None:
|
|
25
25
|
"""Initialize the class."""
|
|
26
|
-
self.
|
|
26
|
+
self.node_type = type(node)
|
|
27
27
|
self.name = name
|
|
28
|
-
self.type =
|
|
28
|
+
self.type = type_str
|
|
29
29
|
self.semstr = semstr
|
|
30
30
|
|
|
31
31
|
def __repr__(self) -> str:
|
|
@@ -40,7 +40,7 @@ class SemInfo:
|
|
|
40
40
|
self_scope = str(scope) + f".{self.name}({self.type})"
|
|
41
41
|
_, children = sem_registry.lookup(scope=SemScope.get_scope_from_str(self_scope))
|
|
42
42
|
if filter and children and isinstance(children, list):
|
|
43
|
-
return [i for i in children if
|
|
43
|
+
return [i for i in children if i.node_type == filter]
|
|
44
44
|
return children if children and isinstance(children, list) else []
|
|
45
45
|
|
|
46
46
|
|
jaclang/compiler/symtable.py
CHANGED
|
@@ -54,6 +54,11 @@ class Symbol:
|
|
|
54
54
|
out.reverse()
|
|
55
55
|
return ".".join(out)
|
|
56
56
|
|
|
57
|
+
@property
|
|
58
|
+
def fetch_sym_tab(self) -> Optional[SymbolTable]:
|
|
59
|
+
"""Get symbol table."""
|
|
60
|
+
return self.parent_tab.find_scope(self.sym_name)
|
|
61
|
+
|
|
57
62
|
def add_defn(self, node: ast.NameAtom) -> None:
|
|
58
63
|
"""Add defn."""
|
|
59
64
|
self.defn.append(node)
|