jaclang 0.7.23__py3-none-any.whl → 0.7.26__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 +46 -29
- jaclang/compiler/__init__.py +2 -2
- jaclang/compiler/absyntree.py +114 -66
- jaclang/compiler/codeloc.py +7 -2
- jaclang/compiler/compile.py +10 -3
- jaclang/compiler/jac.lark +4 -1
- jaclang/compiler/parser.py +63 -43
- jaclang/compiler/passes/ir_pass.py +2 -2
- jaclang/compiler/passes/main/def_impl_match_pass.py +83 -0
- jaclang/compiler/passes/main/def_use_pass.py +1 -2
- jaclang/compiler/passes/main/fuse_typeinfo_pass.py +146 -123
- jaclang/compiler/passes/main/import_pass.py +6 -2
- jaclang/compiler/passes/main/pyast_gen_pass.py +46 -20
- jaclang/compiler/passes/main/pyast_load_pass.py +56 -41
- jaclang/compiler/passes/main/pyjac_ast_link_pass.py +7 -7
- jaclang/compiler/passes/main/registry_pass.py +3 -12
- jaclang/compiler/passes/main/sym_tab_build_pass.py +1 -2
- jaclang/compiler/passes/main/tests/fixtures/defn_decl_mismatch.jac +19 -0
- jaclang/compiler/passes/main/tests/fixtures/fstrings.jac +2 -0
- jaclang/compiler/passes/main/tests/fixtures/uninitialized_hasvars.jac +26 -0
- jaclang/compiler/passes/main/tests/test_decl_def_match_pass.py +66 -0
- jaclang/compiler/passes/main/tests/test_def_use_pass.py +3 -3
- jaclang/compiler/passes/main/tests/test_registry_pass.py +2 -10
- jaclang/compiler/passes/main/tests/test_type_check_pass.py +1 -1
- jaclang/compiler/passes/tool/jac_formatter_pass.py +2 -2
- jaclang/compiler/passes/tool/tests/fixtures/corelib.jac +3 -3
- jaclang/compiler/passes/tool/tests/fixtures/corelib_fmt.jac +3 -3
- jaclang/compiler/passes/transform.py +27 -3
- jaclang/compiler/passes/utils/mypy_ast_build.py +246 -26
- jaclang/compiler/symtable.py +6 -0
- jaclang/compiler/tests/test_importer.py +2 -2
- jaclang/compiler/tests/test_parser.py +7 -1
- jaclang/langserve/engine.py +14 -12
- jaclang/langserve/server.py +7 -2
- jaclang/langserve/tests/test_server.py +1 -1
- jaclang/langserve/utils.py +17 -3
- jaclang/plugin/default.py +80 -43
- jaclang/plugin/feature.py +12 -2
- jaclang/plugin/plugin.md +471 -0
- jaclang/plugin/spec.py +14 -1
- jaclang/plugin/tests/fixtures/graph_purger.jac +101 -0
- jaclang/plugin/tests/fixtures/other_root_access.jac +9 -0
- jaclang/plugin/tests/test_jaseci.py +126 -6
- jaclang/runtimelib/architype.py +12 -1
- jaclang/runtimelib/context.py +2 -0
- jaclang/runtimelib/importer.py +7 -2
- jaclang/runtimelib/machine.py +21 -6
- jaclang/runtimelib/memory.py +5 -1
- jaclang/settings.py +3 -0
- jaclang/tests/fixtures/architype_def_bug.jac +17 -0
- jaclang/tests/fixtures/builtin_dotgen.jac +6 -6
- jaclang/tests/fixtures/decl_defn_param_name.jac +19 -0
- jaclang/tests/fixtures/enum_inside_archtype.jac +16 -11
- jaclang/tests/fixtures/expr_type.jac +54 -0
- jaclang/tests/fixtures/glob_multivar_statement.jac +15 -0
- jaclang/tests/fixtures/multi_dim_array_split.jac +19 -0
- jaclang/tests/fixtures/registry.jac +20 -8
- jaclang/tests/foo/__init__.jac +0 -0
- jaclang/tests/main.jac +2 -0
- jaclang/tests/test_cli.py +86 -4
- jaclang/tests/test_language.py +104 -27
- jaclang/utils/helpers.py +92 -14
- jaclang/utils/lang_tools.py +6 -2
- jaclang/utils/treeprinter.py +4 -2
- {jaclang-0.7.23.dist-info → jaclang-0.7.26.dist-info}/METADATA +2 -1
- {jaclang-0.7.23.dist-info → jaclang-0.7.26.dist-info}/RECORD +68 -57
- {jaclang-0.7.23.dist-info → jaclang-0.7.26.dist-info}/WHEEL +1 -1
- {jaclang-0.7.23.dist-info → jaclang-0.7.26.dist-info}/entry_points.txt +0 -0
jaclang/cli/cli.py
CHANGED
|
@@ -6,6 +6,7 @@ import marshal
|
|
|
6
6
|
import os
|
|
7
7
|
import pickle
|
|
8
8
|
import shutil
|
|
9
|
+
import sys
|
|
9
10
|
import types
|
|
10
11
|
from typing import Optional
|
|
11
12
|
|
|
@@ -38,7 +39,10 @@ def format(path: str, outfile: str = "", debug: bool = False) -> None:
|
|
|
38
39
|
def format_file(filename: str) -> None:
|
|
39
40
|
code_gen_format = jac_file_to_pass(filename, schedule=format_pass)
|
|
40
41
|
if code_gen_format.errors_had:
|
|
41
|
-
print(
|
|
42
|
+
print(
|
|
43
|
+
f"Errors occurred while formatting the file {filename}.",
|
|
44
|
+
file=sys.stderr,
|
|
45
|
+
)
|
|
42
46
|
elif debug:
|
|
43
47
|
print(code_gen_format.ir.gen.jac)
|
|
44
48
|
elif outfile:
|
|
@@ -52,7 +56,7 @@ def format(path: str, outfile: str = "", debug: bool = False) -> None:
|
|
|
52
56
|
if os.path.exists(path):
|
|
53
57
|
format_file(path)
|
|
54
58
|
else:
|
|
55
|
-
print("File does not exist.")
|
|
59
|
+
print("File does not exist.", file=sys.stderr)
|
|
56
60
|
elif os.path.isdir(path):
|
|
57
61
|
count = 0
|
|
58
62
|
for root, _, files in os.walk(path):
|
|
@@ -61,9 +65,9 @@ def format(path: str, outfile: str = "", debug: bool = False) -> None:
|
|
|
61
65
|
file_path = os.path.join(root, file)
|
|
62
66
|
format_file(file_path)
|
|
63
67
|
count += 1
|
|
64
|
-
print(f"Formatted {count} '.jac' files.")
|
|
68
|
+
print(f"Formatted {count} '.jac' files.", file=sys.stderr)
|
|
65
69
|
else:
|
|
66
|
-
print("Not a .jac file or directory.")
|
|
70
|
+
print("Not a .jac file or directory.", file=sys.stderr)
|
|
67
71
|
|
|
68
72
|
|
|
69
73
|
@cmd_registry.register
|
|
@@ -89,23 +93,30 @@ def run(
|
|
|
89
93
|
jctx = ExecutionContext.create(session=session)
|
|
90
94
|
|
|
91
95
|
if filename.endswith(".jac"):
|
|
92
|
-
|
|
93
|
-
target=mod,
|
|
94
|
-
base_path=base,
|
|
95
|
-
cachable=cache,
|
|
96
|
-
override_name="__main__" if main else None,
|
|
97
|
-
)
|
|
98
|
-
elif filename.endswith(".jir"):
|
|
99
|
-
with open(filename, "rb") as f:
|
|
100
|
-
JacMachine(base).attach_program(
|
|
101
|
-
JacProgram(mod_bundle=pickle.load(f), bytecode=None)
|
|
102
|
-
)
|
|
96
|
+
try:
|
|
103
97
|
jac_import(
|
|
104
98
|
target=mod,
|
|
105
99
|
base_path=base,
|
|
106
100
|
cachable=cache,
|
|
107
101
|
override_name="__main__" if main else None,
|
|
108
102
|
)
|
|
103
|
+
except Exception as e:
|
|
104
|
+
print(e, file=sys.stderr)
|
|
105
|
+
elif filename.endswith(".jir"):
|
|
106
|
+
try:
|
|
107
|
+
with open(filename, "rb") as f:
|
|
108
|
+
JacMachine(base).attach_program(
|
|
109
|
+
JacProgram(mod_bundle=pickle.load(f), bytecode=None, sem_ir=None)
|
|
110
|
+
)
|
|
111
|
+
jac_import(
|
|
112
|
+
target=mod,
|
|
113
|
+
base_path=base,
|
|
114
|
+
cachable=cache,
|
|
115
|
+
override_name="__main__" if main else None,
|
|
116
|
+
)
|
|
117
|
+
except Exception as e:
|
|
118
|
+
print(e, file=sys.stderr)
|
|
119
|
+
|
|
109
120
|
else:
|
|
110
121
|
jctx.close()
|
|
111
122
|
JacMachine.detach()
|
|
@@ -145,7 +156,7 @@ def get_object(
|
|
|
145
156
|
elif filename.endswith(".jir"):
|
|
146
157
|
with open(filename, "rb") as f:
|
|
147
158
|
JacMachine(base).attach_program(
|
|
148
|
-
JacProgram(mod_bundle=pickle.load(f), bytecode=None)
|
|
159
|
+
JacProgram(mod_bundle=pickle.load(f), bytecode=None, sem_ir=None)
|
|
149
160
|
)
|
|
150
161
|
jac_import(
|
|
151
162
|
target=mod,
|
|
@@ -163,7 +174,7 @@ def get_object(
|
|
|
163
174
|
if obj:
|
|
164
175
|
data = obj.__jac__.__getstate__()
|
|
165
176
|
else:
|
|
166
|
-
print(f"Object with id {id} not found.")
|
|
177
|
+
print(f"Object with id {id} not found.", file=sys.stderr)
|
|
167
178
|
|
|
168
179
|
jctx.close()
|
|
169
180
|
JacMachine.detach()
|
|
@@ -183,7 +194,7 @@ def build(filename: str) -> None:
|
|
|
183
194
|
with open(filename[:-4] + ".jir", "wb") as f:
|
|
184
195
|
pickle.dump(out.ir, f)
|
|
185
196
|
else:
|
|
186
|
-
print("Not a .jac file.")
|
|
197
|
+
print("Not a .jac file.", file=sys.stderr)
|
|
187
198
|
|
|
188
199
|
|
|
189
200
|
@cmd_registry.register
|
|
@@ -202,10 +213,10 @@ def check(filename: str, print_errs: bool = True) -> None:
|
|
|
202
213
|
warnings = len(out.warnings_had)
|
|
203
214
|
if print_errs:
|
|
204
215
|
for e in out.errors_had:
|
|
205
|
-
print("Error:", e)
|
|
216
|
+
print("Error:", e, file=sys.stderr)
|
|
206
217
|
print(f"Errors: {errs}, Warnings: {warnings}")
|
|
207
218
|
else:
|
|
208
|
-
print("Not a .jac file.")
|
|
219
|
+
print("Not a .jac file.", file=sys.stderr)
|
|
209
220
|
|
|
210
221
|
|
|
211
222
|
@cmd_registry.register
|
|
@@ -262,7 +273,7 @@ def enter(
|
|
|
262
273
|
elif filename.endswith(".jir"):
|
|
263
274
|
with open(filename, "rb") as f:
|
|
264
275
|
JacMachine(base).attach_program(
|
|
265
|
-
JacProgram(mod_bundle=pickle.load(f), bytecode=None)
|
|
276
|
+
JacProgram(mod_bundle=pickle.load(f), bytecode=None, sem_ir=None)
|
|
266
277
|
)
|
|
267
278
|
ret_module = jac_import(
|
|
268
279
|
target=mod,
|
|
@@ -278,7 +289,7 @@ def enter(
|
|
|
278
289
|
if ret_module:
|
|
279
290
|
(loaded_mod,) = ret_module
|
|
280
291
|
if not loaded_mod:
|
|
281
|
-
print("Errors occurred while importing the module.")
|
|
292
|
+
print("Errors occurred while importing the module.", file=sys.stderr)
|
|
282
293
|
else:
|
|
283
294
|
architype = getattr(loaded_mod, entrypoint)(*args)
|
|
284
295
|
|
|
@@ -344,10 +355,12 @@ def tool(tool: str, args: Optional[list] = None) -> None:
|
|
|
344
355
|
else:
|
|
345
356
|
print(getattr(AstTool(), tool)())
|
|
346
357
|
except Exception as e:
|
|
347
|
-
print(
|
|
358
|
+
print(
|
|
359
|
+
f"Error while running ast tool {tool}, check args: {e}", file=sys.stderr
|
|
360
|
+
)
|
|
348
361
|
raise e
|
|
349
362
|
else:
|
|
350
|
-
print(f"Ast tool {tool} not found.")
|
|
363
|
+
print(f"Ast tool {tool} not found.", file=sys.stderr)
|
|
351
364
|
|
|
352
365
|
|
|
353
366
|
@cmd_registry.register
|
|
@@ -385,9 +398,9 @@ def debug(filename: str, main: bool = True, cache: bool = False) -> None:
|
|
|
385
398
|
db.runcall(func)
|
|
386
399
|
print("Done debugging.")
|
|
387
400
|
else:
|
|
388
|
-
print(f"Error while generating bytecode in {filename}.")
|
|
401
|
+
print(f"Error while generating bytecode in {filename}.", file=sys.stderr)
|
|
389
402
|
else:
|
|
390
|
-
print("Not a .jac file.")
|
|
403
|
+
print("Not a .jac file.", file=sys.stderr)
|
|
391
404
|
|
|
392
405
|
|
|
393
406
|
@cmd_registry.register
|
|
@@ -458,7 +471,7 @@ def dot(
|
|
|
458
471
|
file.write(graph)
|
|
459
472
|
print(f">>> Graph content saved to {os.path.join(os.getcwd(), file_name)}")
|
|
460
473
|
else:
|
|
461
|
-
print("Not a .jac file.")
|
|
474
|
+
print("Not a .jac file.", file=sys.stderr)
|
|
462
475
|
|
|
463
476
|
jctx.close()
|
|
464
477
|
|
|
@@ -471,8 +484,12 @@ def py2jac(filename: str) -> None:
|
|
|
471
484
|
"""
|
|
472
485
|
if filename.endswith(".py"):
|
|
473
486
|
with open(filename, "r") as f:
|
|
487
|
+
file_source = f.read()
|
|
474
488
|
code = PyastBuildPass(
|
|
475
|
-
input_ir=ast.PythonModuleAst(
|
|
489
|
+
input_ir=ast.PythonModuleAst(
|
|
490
|
+
ast3.parse(file_source),
|
|
491
|
+
orig_src=ast.JacSource(file_source, filename),
|
|
492
|
+
),
|
|
476
493
|
).ir.unparse()
|
|
477
494
|
print(code)
|
|
478
495
|
else:
|
|
@@ -490,7 +507,7 @@ def jac2py(filename: str) -> None:
|
|
|
490
507
|
code = jac_file_to_pass(file_path=filename).ir.gen.py
|
|
491
508
|
print(code)
|
|
492
509
|
else:
|
|
493
|
-
print("Not a .jac file.")
|
|
510
|
+
print("Not a .jac file.", file=sys.stderr)
|
|
494
511
|
|
|
495
512
|
|
|
496
513
|
def start_cli() -> None:
|
jaclang/compiler/__init__.py
CHANGED
|
@@ -59,7 +59,7 @@ TOKEN_MAP.update(
|
|
|
59
59
|
"KW_OR": "|", "ARROW_BI": "<-->", "ARROW_L": "<--",
|
|
60
60
|
"ARROW_R": "-->", "ARROW_L_P1": "<-:", "ARROW_R_P2": ":->",
|
|
61
61
|
"ARROW_L_P2": ":-", "ARROW_R_P1": "-:", "CARROW_BI": "<++>",
|
|
62
|
-
"
|
|
62
|
+
"CARROW_L_P1": "<+:", "RSHIFT_EQ": ">>=", "ELLIPSIS": "...",
|
|
63
63
|
"CARROW_R_P2": ":+>", "CARROW_L_P2": ":+", "CARROW_R_P1": "+:",
|
|
64
64
|
"PIPE_FWD": "|>", "PIPE_BKWD": "<|", "A_PIPE_FWD": ":>",
|
|
65
65
|
"A_PIPE_BKWD": "<:", "DOT_FWD": ".>", "STAR_POW": "**",
|
|
@@ -68,7 +68,7 @@ TOKEN_MAP.update(
|
|
|
68
68
|
"STAR_POW_EQ": "**=", "MUL_EQ": "*=", "FLOOR_DIV_EQ": "//=",
|
|
69
69
|
"DIV_EQ": "/=", "MOD_EQ": "%=", "BW_AND_EQ": "&=",
|
|
70
70
|
"BW_OR_EQ": "|=", "BW_XOR_EQ": "^=", "BW_NOT_EQ": "~=",
|
|
71
|
-
"LSHIFT_EQ": "<<=",
|
|
71
|
+
"LSHIFT_EQ": "<<=",
|
|
72
72
|
}
|
|
73
73
|
)
|
|
74
74
|
# fmt: on
|