jaclang 0.5.8__py3-none-any.whl → 0.5.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 +58 -0
- jaclang/compiler/__init__.py +53 -0
- jaclang/compiler/absyntree.py +218 -174
- jaclang/compiler/parser.py +3 -0
- jaclang/compiler/passes/ir_pass.py +18 -0
- jaclang/compiler/passes/main/__init__.py +2 -0
- jaclang/compiler/passes/main/pyast_gen_pass.py +239 -34
- jaclang/compiler/passes/main/registry_pass.py +126 -0
- jaclang/compiler/passes/main/schedules.py +2 -0
- jaclang/compiler/passes/main/tests/test_registry_pass.py +39 -0
- jaclang/compiler/passes/tool/tests/test_unparse_validate.py +28 -6
- jaclang/core/aott.py +193 -28
- jaclang/core/construct.py +7 -2
- jaclang/core/registry.py +115 -0
- jaclang/core/utils.py +25 -0
- jaclang/plugin/default.py +57 -13
- jaclang/plugin/feature.py +6 -2
- jaclang/plugin/spec.py +4 -2
- jaclang/utils/helpers.py +41 -3
- jaclang/utils/lang_tools.py +2 -37
- {jaclang-0.5.8.dist-info → jaclang-0.5.9.dist-info}/METADATA +1 -1
- {jaclang-0.5.8.dist-info → jaclang-0.5.9.dist-info}/RECORD +25 -24
- jaclang/compiler/__jac_gen__/__init__.py +0 -0
- jaclang/compiler/__jac_gen__/jac_parser.py +0 -4069
- {jaclang-0.5.8.dist-info → jaclang-0.5.9.dist-info}/WHEEL +0 -0
- {jaclang-0.5.8.dist-info → jaclang-0.5.9.dist-info}/entry_points.txt +0 -0
- {jaclang-0.5.8.dist-info → jaclang-0.5.9.dist-info}/top_level.txt +0 -0
jaclang/cli/cli.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"""Command line interface tool for the Jac language."""
|
|
2
2
|
|
|
3
|
+
import importlib
|
|
3
4
|
import marshal
|
|
4
5
|
import os
|
|
5
6
|
import pickle
|
|
@@ -13,6 +14,7 @@ from jaclang.compiler.compile import jac_file_to_pass
|
|
|
13
14
|
from jaclang.compiler.constant import Constants
|
|
14
15
|
from jaclang.compiler.passes.main.schedules import py_code_gen_typed
|
|
15
16
|
from jaclang.compiler.passes.tool.schedules import format_pass
|
|
17
|
+
from jaclang.plugin.builtin import dotgen
|
|
16
18
|
from jaclang.plugin.feature import JacCmd as Cmd
|
|
17
19
|
from jaclang.plugin.feature import JacFeature as Jac
|
|
18
20
|
from jaclang.utils.helpers import debugger as db
|
|
@@ -232,6 +234,62 @@ def debug(filename: str, main: bool = True, cache: bool = False) -> None:
|
|
|
232
234
|
print("Not a .jac file.")
|
|
233
235
|
|
|
234
236
|
|
|
237
|
+
@cmd_registry.register
|
|
238
|
+
def graph(
|
|
239
|
+
filename: str,
|
|
240
|
+
initial: str = "",
|
|
241
|
+
depth: int = -1,
|
|
242
|
+
traverse: bool = False,
|
|
243
|
+
connection: list[str] = [], # noqa: B006
|
|
244
|
+
bfs: bool = False,
|
|
245
|
+
edge_limit: int = 512,
|
|
246
|
+
node_limit: int = 512,
|
|
247
|
+
saveto: str = "",
|
|
248
|
+
) -> None:
|
|
249
|
+
"""Generate and Visualize a graph based on the specified .jac file contents and parameters.
|
|
250
|
+
|
|
251
|
+
:param filename: The name of the file to generate the graph from.
|
|
252
|
+
:param initial: The initial node for graph traversal (default is root node).
|
|
253
|
+
:param depth: The maximum depth for graph traversal (-1 for unlimited depth, default is -1).
|
|
254
|
+
:param traverse: Flag to indicate whether to traverse the graph (default is False).
|
|
255
|
+
:param connection: List of node connections(edge type) to include in the graph (default is an empty list).
|
|
256
|
+
:param bfs: Flag to indicate whether to use breadth-first search for traversal (default is False).
|
|
257
|
+
:param edge_limit: The maximum number of edges allowed in the graph.
|
|
258
|
+
:param node_limit: The maximum number of nodes allowed in the graph.
|
|
259
|
+
:param saveto: Path to save the generated graph.
|
|
260
|
+
"""
|
|
261
|
+
base, mod = os.path.split(filename)
|
|
262
|
+
base = base if base else "./"
|
|
263
|
+
mod = mod[:-4]
|
|
264
|
+
if filename.endswith(".jac"):
|
|
265
|
+
jac_import(
|
|
266
|
+
target=mod,
|
|
267
|
+
base_path=base,
|
|
268
|
+
)
|
|
269
|
+
module = importlib.import_module(mod)
|
|
270
|
+
globals().update(vars(module))
|
|
271
|
+
try:
|
|
272
|
+
node = globals().get(initial, eval(initial)) if initial else None
|
|
273
|
+
graph = dotgen(
|
|
274
|
+
node=node,
|
|
275
|
+
depth=depth,
|
|
276
|
+
traverse=traverse,
|
|
277
|
+
edge_type=connection,
|
|
278
|
+
bfs=bfs,
|
|
279
|
+
edge_limit=edge_limit,
|
|
280
|
+
node_limit=node_limit,
|
|
281
|
+
)
|
|
282
|
+
except Exception as e:
|
|
283
|
+
print(f"Error while generating graph: {e}")
|
|
284
|
+
return
|
|
285
|
+
file_name = saveto if saveto else f"{mod}.dot"
|
|
286
|
+
with open(file_name, "w") as file:
|
|
287
|
+
file.write(graph)
|
|
288
|
+
print(f">>> Graph content saved to {os.path.join(os.getcwd(), file_name)}")
|
|
289
|
+
else:
|
|
290
|
+
print("Not a .jac file.")
|
|
291
|
+
|
|
292
|
+
|
|
235
293
|
def start_cli() -> None:
|
|
236
294
|
"""
|
|
237
295
|
Start the command line interface.
|
jaclang/compiler/__init__.py
CHANGED
|
@@ -8,6 +8,7 @@ import sys
|
|
|
8
8
|
cur_dir = os.path.dirname(__file__)
|
|
9
9
|
if not os.path.exists(os.path.join(cur_dir, "__jac_gen__", "jac_parser.py")):
|
|
10
10
|
from jaclang.vendor.lark.tools import standalone
|
|
11
|
+
from jaclang.utils.helpers import auto_generate_refs
|
|
11
12
|
|
|
12
13
|
os.makedirs(os.path.join(cur_dir, "__jac_gen__"), exist_ok=True)
|
|
13
14
|
with open(os.path.join(cur_dir, "__jac_gen__", "__init__.py"), "w"):
|
|
@@ -22,6 +23,8 @@ if not os.path.exists(os.path.join(cur_dir, "__jac_gen__", "jac_parser.py")):
|
|
|
22
23
|
]
|
|
23
24
|
standalone.main() # type: ignore
|
|
24
25
|
sys.argv = save_argv
|
|
26
|
+
auto_generate_refs()
|
|
27
|
+
|
|
25
28
|
|
|
26
29
|
from .__jac_gen__ import jac_parser as jac_lark # noqa: E402
|
|
27
30
|
|
|
@@ -32,4 +35,54 @@ TOKEN_MAP = {
|
|
|
32
35
|
x.name: x.pattern.value
|
|
33
36
|
for x in jac_lark.Lark_StandAlone().parser.lexer_conf.terminals
|
|
34
37
|
}
|
|
38
|
+
|
|
39
|
+
TOKEN_MAP.update(
|
|
40
|
+
{
|
|
41
|
+
"CARROW_L": "<++",
|
|
42
|
+
"CARROW_R": "++>",
|
|
43
|
+
"GLOBAL_OP": ":global:",
|
|
44
|
+
"NONLOCAL_OP": ":nonlocal:",
|
|
45
|
+
"WALKER_OP": ":walker:",
|
|
46
|
+
"NODE_OP": ":node:",
|
|
47
|
+
"EDGE_OP": ":edge:",
|
|
48
|
+
"CLASS_OP": ":class:",
|
|
49
|
+
"OBJECT_OP": ":obj:",
|
|
50
|
+
"TYPE_OP": "`",
|
|
51
|
+
"ABILITY_OP": ":can:",
|
|
52
|
+
"ELVIS_OP": "?:",
|
|
53
|
+
"NULL_OK": "?",
|
|
54
|
+
"KW_OR": "|",
|
|
55
|
+
"ARROW_BI": "<-->",
|
|
56
|
+
"ARROW_L": "<--",
|
|
57
|
+
"ARROW_R": "-->",
|
|
58
|
+
"ARROW_L_P1": "<-:",
|
|
59
|
+
"ARROW_R_P2": ":->",
|
|
60
|
+
"ARROW_L_P2": ":-",
|
|
61
|
+
"ARROW_R_P1": "-:",
|
|
62
|
+
"CARROW_BI": "<++>",
|
|
63
|
+
"CARROW_L": "<++",
|
|
64
|
+
"CARROW_R": "++>",
|
|
65
|
+
"CARROW_L_P1": "<+:",
|
|
66
|
+
"CARROW_R_P2": ":+>",
|
|
67
|
+
"CARROW_L_P2": ":+",
|
|
68
|
+
"CARROW_R_P1": "+:",
|
|
69
|
+
"PIPE_FWD": "|>",
|
|
70
|
+
"PIPE_BKWD": "<|",
|
|
71
|
+
"A_PIPE_FWD": ":>",
|
|
72
|
+
"A_PIPE_BKWD": "<:",
|
|
73
|
+
"DOT_FWD": ".>",
|
|
74
|
+
"STAR_POW_EQ": "**=",
|
|
75
|
+
"MUL_EQ": "*=",
|
|
76
|
+
"FLOOR_DIV_EQ": "//=",
|
|
77
|
+
"DIV_EQ": "/=",
|
|
78
|
+
"BW_OR_EQ": "|=",
|
|
79
|
+
"BW_XOR_EQ": "^=",
|
|
80
|
+
"STAR_POW": "**",
|
|
81
|
+
"STAR_MUL": "*",
|
|
82
|
+
"FLOOR_DIV": "//",
|
|
83
|
+
"DIV": "/",
|
|
84
|
+
}
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
|
|
35
88
|
__all__ = ["jac_lark", "TOKEN_MAP"]
|