jaclang 0.7.16__py3-none-any.whl → 0.7.18__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 +140 -77
- jaclang/compiler/absyntree.py +9 -4
- jaclang/compiler/constant.py +8 -8
- jaclang/compiler/parser.py +10 -2
- jaclang/compiler/passes/main/__init__.py +1 -1
- jaclang/compiler/passes/main/access_modifier_pass.py +96 -147
- jaclang/compiler/passes/main/fuse_typeinfo_pass.py +152 -50
- jaclang/compiler/passes/main/import_pass.py +88 -59
- jaclang/compiler/passes/main/py_collect_dep_pass.py +70 -0
- jaclang/compiler/passes/main/pyast_gen_pass.py +46 -6
- jaclang/compiler/passes/main/pyast_load_pass.py +1 -0
- jaclang/compiler/passes/main/pyjac_ast_link_pass.py +7 -0
- jaclang/compiler/passes/main/schedules.py +9 -2
- jaclang/compiler/passes/main/sym_tab_build_pass.py +9 -5
- jaclang/compiler/passes/main/tests/fixtures/autoimpl.empty.impl.jac +0 -0
- jaclang/compiler/passes/main/tests/fixtures/autoimpl.jac +1 -1
- jaclang/compiler/passes/main/tests/fixtures/py_imp_test.jac +29 -0
- jaclang/compiler/passes/main/tests/fixtures/pygame_mock/__init__.py +3 -0
- jaclang/compiler/passes/main/tests/fixtures/pygame_mock/color.py +3 -0
- jaclang/compiler/passes/main/tests/fixtures/pygame_mock/constants.py +5 -0
- jaclang/compiler/passes/main/tests/fixtures/pygame_mock/display.py +2 -0
- jaclang/compiler/passes/main/tests/test_import_pass.py +72 -13
- jaclang/compiler/passes/main/type_check_pass.py +15 -5
- jaclang/compiler/passes/tool/jac_formatter_pass.py +13 -3
- jaclang/compiler/passes/tool/tests/fixtures/corelib.jac +37 -41
- jaclang/compiler/passes/tool/tests/fixtures/corelib_fmt.jac +37 -41
- jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/access_mod_check.jac +27 -0
- jaclang/compiler/passes/utils/mypy_ast_build.py +45 -0
- jaclang/compiler/symtable.py +16 -11
- jaclang/compiler/tests/test_importer.py +17 -9
- jaclang/langserve/engine.py +64 -16
- jaclang/langserve/server.py +16 -1
- jaclang/langserve/tests/fixtures/import_include_statements.jac +3 -3
- jaclang/langserve/tests/fixtures/rename.jac +30 -0
- jaclang/langserve/tests/test_server.py +224 -6
- jaclang/langserve/utils.py +28 -98
- jaclang/plugin/builtin.py +8 -4
- jaclang/plugin/default.py +86 -64
- jaclang/plugin/feature.py +13 -13
- jaclang/plugin/spec.py +10 -11
- jaclang/plugin/tests/fixtures/other_root_access.jac +82 -0
- jaclang/plugin/tests/test_jaseci.py +414 -42
- jaclang/runtimelib/architype.py +481 -333
- jaclang/runtimelib/constructs.py +5 -8
- jaclang/runtimelib/context.py +89 -69
- jaclang/runtimelib/importer.py +16 -15
- jaclang/runtimelib/machine.py +66 -2
- jaclang/runtimelib/memory.py +134 -75
- jaclang/runtimelib/utils.py +17 -10
- jaclang/settings.py +2 -4
- jaclang/tests/fixtures/access_checker.jac +12 -17
- jaclang/tests/fixtures/access_modifier.jac +88 -33
- jaclang/tests/fixtures/baddy.jac +3 -0
- jaclang/tests/fixtures/bar.jac +34 -0
- jaclang/tests/fixtures/builtin_dotgen.jac +1 -0
- jaclang/tests/fixtures/edge_node_walk.jac +1 -1
- jaclang/tests/fixtures/edge_ops.jac +1 -1
- jaclang/tests/fixtures/edges_walk.jac +1 -1
- jaclang/tests/fixtures/foo.jac +43 -0
- jaclang/tests/fixtures/game1.jac +1 -1
- jaclang/tests/fixtures/gendot_bubble_sort.jac +1 -1
- jaclang/tests/fixtures/import.jac +9 -0
- jaclang/tests/fixtures/index_slice.jac +30 -0
- jaclang/tests/fixtures/objref.jac +12 -0
- jaclang/tests/fixtures/pyfunc_1.py +1 -1
- jaclang/tests/fixtures/pyfunc_2.py +2 -2
- jaclang/tests/fixtures/pygame_mock/__init__.py +3 -0
- jaclang/tests/fixtures/pygame_mock/color.py +3 -0
- jaclang/tests/fixtures/pygame_mock/constants.py +5 -0
- jaclang/tests/fixtures/pygame_mock/display.py +2 -0
- jaclang/tests/fixtures/pygame_mock/inner/__init__.py +0 -0
- jaclang/tests/fixtures/pygame_mock/inner/iner_mod.py +2 -0
- jaclang/tests/test_cli.py +49 -6
- jaclang/tests/test_language.py +126 -80
- jaclang/tests/test_reference.py +2 -9
- jaclang/utils/treeprinter.py +30 -3
- {jaclang-0.7.16.dist-info → jaclang-0.7.18.dist-info}/METADATA +3 -1
- {jaclang-0.7.16.dist-info → jaclang-0.7.18.dist-info}/RECORD +81 -59
- /jaclang/tests/fixtures/{err.test.jac → baddy.test.jac} +0 -0
- {jaclang-0.7.16.dist-info → jaclang-0.7.18.dist-info}/WHEEL +0 -0
- {jaclang-0.7.16.dist-info → jaclang-0.7.18.dist-info}/entry_points.txt +0 -0
jaclang/tests/test_language.py
CHANGED
|
@@ -12,8 +12,8 @@ from jaclang import jac_import
|
|
|
12
12
|
from jaclang.cli import cli
|
|
13
13
|
from jaclang.compiler.compile import jac_file_to_pass, jac_pass_to_pass, jac_str_to_pass
|
|
14
14
|
from jaclang.compiler.passes.main.schedules import py_code_gen_typed
|
|
15
|
-
from jaclang.
|
|
16
|
-
from jaclang.
|
|
15
|
+
from jaclang.runtimelib.context import SUPER_ROOT_ANCHOR
|
|
16
|
+
from jaclang.runtimelib.machine import JacMachine, JacProgram
|
|
17
17
|
from jaclang.utils.test import TestCase
|
|
18
18
|
|
|
19
19
|
|
|
@@ -22,15 +22,24 @@ class JacLanguageTests(TestCase):
|
|
|
22
22
|
|
|
23
23
|
def setUp(self) -> None:
|
|
24
24
|
"""Set up test."""
|
|
25
|
+
SUPER_ROOT_ANCHOR.edges.clear()
|
|
26
|
+
JacMachine(self.fixture_abs_path("./")).attach_program(
|
|
27
|
+
JacProgram(mod_bundle=None, bytecode=None)
|
|
28
|
+
)
|
|
25
29
|
return super().setUp()
|
|
26
30
|
|
|
31
|
+
def tearDown(self) -> None:
|
|
32
|
+
"""Tear down test."""
|
|
33
|
+
JacMachine.detach()
|
|
34
|
+
return super().tearDown()
|
|
35
|
+
|
|
27
36
|
def test_sub_abilities(self) -> None:
|
|
28
37
|
"""Basic test for pass."""
|
|
29
38
|
captured_output = io.StringIO()
|
|
30
39
|
sys.stdout = captured_output
|
|
31
40
|
|
|
32
41
|
# Execute the function
|
|
33
|
-
cli.run(self.fixture_abs_path("sub_abil_sep.jac"))
|
|
42
|
+
cli.run(self.fixture_abs_path("sub_abil_sep.jac"))
|
|
34
43
|
|
|
35
44
|
sys.stdout = sys.__stdout__
|
|
36
45
|
stdout_value = captured_output.getvalue()
|
|
@@ -60,7 +69,6 @@ class JacLanguageTests(TestCase):
|
|
|
60
69
|
|
|
61
70
|
def test_simple_jac_red(self) -> None:
|
|
62
71
|
"""Parse micro jac file."""
|
|
63
|
-
Jac.context().init_memory(base_path=self.examples_abs_path(""))
|
|
64
72
|
captured_output = io.StringIO()
|
|
65
73
|
sys.stdout = captured_output
|
|
66
74
|
jac_import("micro.simple_walk", base_path=self.examples_abs_path(""))
|
|
@@ -113,7 +121,6 @@ class JacLanguageTests(TestCase):
|
|
|
113
121
|
|
|
114
122
|
def test_ignore(self) -> None:
|
|
115
123
|
"""Parse micro jac file."""
|
|
116
|
-
Jac.get_root()._jac_.edges.clear()
|
|
117
124
|
captured_output = io.StringIO()
|
|
118
125
|
sys.stdout = captured_output
|
|
119
126
|
jac_import("ignore_dup", base_path=self.fixture_abs_path("./"))
|
|
@@ -152,7 +159,6 @@ class JacLanguageTests(TestCase):
|
|
|
152
159
|
|
|
153
160
|
def test_filter_compr(self) -> None:
|
|
154
161
|
"""Testing filter comprehension."""
|
|
155
|
-
Jac.context().init_memory(base_path=self.examples_abs_path("./"))
|
|
156
162
|
captured_output = io.StringIO()
|
|
157
163
|
sys.stdout = captured_output
|
|
158
164
|
jac_import(
|
|
@@ -208,8 +214,6 @@ class JacLanguageTests(TestCase):
|
|
|
208
214
|
|
|
209
215
|
def test_deep_imports(self) -> None:
|
|
210
216
|
"""Parse micro jac file."""
|
|
211
|
-
Jac.get_root()._jac_.edges.clear()
|
|
212
|
-
Jac.context().init_memory(base_path=self.fixture_abs_path("./"))
|
|
213
217
|
captured_output = io.StringIO()
|
|
214
218
|
sys.stdout = captured_output
|
|
215
219
|
|
|
@@ -220,8 +224,6 @@ class JacLanguageTests(TestCase):
|
|
|
220
224
|
|
|
221
225
|
def test_deep_imports_mods(self) -> None:
|
|
222
226
|
"""Parse micro jac file."""
|
|
223
|
-
import sys
|
|
224
|
-
|
|
225
227
|
targets = [
|
|
226
228
|
"deep",
|
|
227
229
|
"deep.deeper",
|
|
@@ -232,22 +234,14 @@ class JacLanguageTests(TestCase):
|
|
|
232
234
|
for i in targets:
|
|
233
235
|
if i in sys.modules:
|
|
234
236
|
del sys.modules[i]
|
|
235
|
-
Jac.get_root()._jac_.edges.clear()
|
|
236
|
-
Jac.context().init_memory(base_path=self.fixture_abs_path("./"))
|
|
237
|
-
captured_output = io.StringIO()
|
|
238
|
-
sys.stdout = captured_output
|
|
239
237
|
jac_import("deep_import_mods", base_path=self.fixture_abs_path("./"))
|
|
240
|
-
|
|
241
|
-
stdout_value = captured_output.getvalue()
|
|
242
|
-
mods = eval(stdout_value)
|
|
238
|
+
mods = JacMachine.get().loaded_modules.keys()
|
|
243
239
|
for i in targets:
|
|
244
240
|
self.assertIn(i, mods)
|
|
245
|
-
self.assertEqual(len([i for i in mods if i.startswith("deep")]),
|
|
241
|
+
self.assertEqual(len([i for i in mods if i.startswith("deep")]), 6)
|
|
246
242
|
|
|
247
243
|
def test_deep_outer_imports_one(self) -> None:
|
|
248
244
|
"""Parse micro jac file."""
|
|
249
|
-
Jac.get_root()._jac_.edges.clear()
|
|
250
|
-
Jac.context().init_memory(base_path=self.fixture_abs_path("./"))
|
|
251
245
|
captured_output = io.StringIO()
|
|
252
246
|
sys.stdout = captured_output
|
|
253
247
|
jac_import(
|
|
@@ -260,8 +254,6 @@ class JacLanguageTests(TestCase):
|
|
|
260
254
|
|
|
261
255
|
def test_deep_outer_imports_from_loc(self) -> None:
|
|
262
256
|
"""Parse micro jac file."""
|
|
263
|
-
Jac.get_root()._jac_.edges.clear()
|
|
264
|
-
Jac.context().init_memory(base_path=self.fixture_abs_path("./deep/deeper/"))
|
|
265
257
|
captured_output = io.StringIO()
|
|
266
258
|
sys.stdout = captured_output
|
|
267
259
|
os.chdir(self.fixture_abs_path("./deep/deeper/"))
|
|
@@ -273,7 +265,6 @@ class JacLanguageTests(TestCase):
|
|
|
273
265
|
|
|
274
266
|
# def test_second_deep_outer_imports(self) -> None:
|
|
275
267
|
# """Parse micro jac file."""
|
|
276
|
-
# Jac.get_root()._jac_.edges.clear()
|
|
277
268
|
# captured_output = io.StringIO()
|
|
278
269
|
# sys.stdout = captured_output
|
|
279
270
|
# jac_import(
|
|
@@ -286,7 +277,6 @@ class JacLanguageTests(TestCase):
|
|
|
286
277
|
|
|
287
278
|
def test_has_lambda_goodness(self) -> None:
|
|
288
279
|
"""Test has lambda_goodness."""
|
|
289
|
-
Jac.get_root()._jac_.edges.clear()
|
|
290
280
|
captured_output = io.StringIO()
|
|
291
281
|
sys.stdout = captured_output
|
|
292
282
|
jac_import("has_goodness", base_path=self.fixture_abs_path("./"))
|
|
@@ -297,7 +287,6 @@ class JacLanguageTests(TestCase):
|
|
|
297
287
|
|
|
298
288
|
def test_conn_assign_on_edges(self) -> None:
|
|
299
289
|
"""Test conn assign on edges."""
|
|
300
|
-
Jac.get_root()._jac_.edges.clear()
|
|
301
290
|
captured_output = io.StringIO()
|
|
302
291
|
sys.stdout = captured_output
|
|
303
292
|
jac_import("edge_ops", base_path=self.fixture_abs_path("./"))
|
|
@@ -309,7 +298,6 @@ class JacLanguageTests(TestCase):
|
|
|
309
298
|
|
|
310
299
|
def test_disconnect(self) -> None:
|
|
311
300
|
"""Test conn assign on edges."""
|
|
312
|
-
Jac.get_root()._jac_.edges.clear()
|
|
313
301
|
captured_output = io.StringIO()
|
|
314
302
|
sys.stdout = captured_output
|
|
315
303
|
jac_import("disconn", base_path=self.fixture_abs_path("./"))
|
|
@@ -327,7 +315,6 @@ class JacLanguageTests(TestCase):
|
|
|
327
315
|
|
|
328
316
|
def test_simple_archs(self) -> None:
|
|
329
317
|
"""Test conn assign on edges."""
|
|
330
|
-
Jac.get_root()._jac_.edges.clear()
|
|
331
318
|
captured_output = io.StringIO()
|
|
332
319
|
sys.stdout = captured_output
|
|
333
320
|
jac_import("simple_archs", base_path=self.fixture_abs_path("./"))
|
|
@@ -338,7 +325,6 @@ class JacLanguageTests(TestCase):
|
|
|
338
325
|
|
|
339
326
|
def test_edge_walk(self) -> None:
|
|
340
327
|
"""Test walking through edges."""
|
|
341
|
-
Jac.get_root()._jac_.edges.clear()
|
|
342
328
|
captured_output = io.StringIO()
|
|
343
329
|
sys.stdout = captured_output
|
|
344
330
|
jac_import("edges_walk", base_path=self.fixture_abs_path("./"))
|
|
@@ -352,7 +338,6 @@ class JacLanguageTests(TestCase):
|
|
|
352
338
|
|
|
353
339
|
def test_impl_grab(self) -> None:
|
|
354
340
|
"""Test walking through edges."""
|
|
355
|
-
Jac.get_root()._jac_.edges.clear()
|
|
356
341
|
captured_output = io.StringIO()
|
|
357
342
|
sys.stdout = captured_output
|
|
358
343
|
jac_import("impl_grab", base_path=self.fixture_abs_path("./"))
|
|
@@ -362,7 +347,6 @@ class JacLanguageTests(TestCase):
|
|
|
362
347
|
|
|
363
348
|
def test_tuple_of_tuple_assign(self) -> None:
|
|
364
349
|
"""Test walking through edges."""
|
|
365
|
-
Jac.get_root()._jac_.edges.clear()
|
|
366
350
|
captured_output = io.StringIO()
|
|
367
351
|
sys.stdout = captured_output
|
|
368
352
|
jac_import("tuplytuples", base_path=self.fixture_abs_path("./"))
|
|
@@ -375,7 +359,6 @@ class JacLanguageTests(TestCase):
|
|
|
375
359
|
|
|
376
360
|
def test_deferred_field(self) -> None:
|
|
377
361
|
"""Test walking through edges."""
|
|
378
|
-
Jac.get_root()._jac_.edges.clear()
|
|
379
362
|
captured_output = io.StringIO()
|
|
380
363
|
sys.stdout = captured_output
|
|
381
364
|
jac_import("deferred_field", base_path=self.fixture_abs_path("./"))
|
|
@@ -388,18 +371,15 @@ class JacLanguageTests(TestCase):
|
|
|
388
371
|
|
|
389
372
|
def test_gen_dot_builtin(self) -> None:
|
|
390
373
|
"""Test the dot gen of nodes and edges as a builtin."""
|
|
391
|
-
Jac.get_root()._jac_.edges.clear()
|
|
392
374
|
captured_output = io.StringIO()
|
|
393
375
|
sys.stdout = captured_output
|
|
394
376
|
jac_import("builtin_dotgen", base_path=self.fixture_abs_path("./"))
|
|
395
377
|
sys.stdout = sys.__stdout__
|
|
396
378
|
stdout_value = captured_output.getvalue()
|
|
397
|
-
|
|
398
|
-
self.assertEqual(stdout_value.count("True"), 14)
|
|
379
|
+
self.assertEqual(stdout_value.count("True"), 16)
|
|
399
380
|
|
|
400
381
|
def test_with_contexts(self) -> None:
|
|
401
382
|
"""Test walking through edges."""
|
|
402
|
-
Jac.get_root()._jac_.edges.clear()
|
|
403
383
|
captured_output = io.StringIO()
|
|
404
384
|
sys.stdout = captured_output
|
|
405
385
|
jac_import("with_context", base_path=self.fixture_abs_path("./"))
|
|
@@ -415,13 +395,9 @@ class JacLanguageTests(TestCase):
|
|
|
415
395
|
|
|
416
396
|
def test_typed_filter_compr(self) -> None:
|
|
417
397
|
"""Parse micro jac file."""
|
|
418
|
-
Jac.context().init_memory(base_path=self.examples_abs_path(""))
|
|
419
398
|
captured_output = io.StringIO()
|
|
420
399
|
sys.stdout = captured_output
|
|
421
|
-
jac_import(
|
|
422
|
-
"micro.typed_filter_compr",
|
|
423
|
-
base_path=self.examples_abs_path(""),
|
|
424
|
-
)
|
|
400
|
+
jac_import("micro.typed_filter_compr", base_path=self.examples_abs_path(""))
|
|
425
401
|
sys.stdout = sys.__stdout__
|
|
426
402
|
stdout_value = captured_output.getvalue()
|
|
427
403
|
self.assertIn(
|
|
@@ -433,7 +409,6 @@ class JacLanguageTests(TestCase):
|
|
|
433
409
|
|
|
434
410
|
def test_edge_node_walk(self) -> None:
|
|
435
411
|
"""Test walking through edges and nodes."""
|
|
436
|
-
Jac.get_root()._jac_.edges.clear()
|
|
437
412
|
captured_output = io.StringIO()
|
|
438
413
|
sys.stdout = captured_output
|
|
439
414
|
jac_import("edge_node_walk", base_path=self.fixture_abs_path("./"))
|
|
@@ -447,14 +422,12 @@ class JacLanguageTests(TestCase):
|
|
|
447
422
|
|
|
448
423
|
def test_annotation_tuple_issue(self) -> None:
|
|
449
424
|
"""Test conn assign on edges."""
|
|
450
|
-
Jac.get_root()._jac_.edges.clear()
|
|
451
425
|
mypass = jac_file_to_pass(self.fixture_abs_path("./slice_vals.jac"))
|
|
452
426
|
self.assertIn("Annotated[Str, INT, BLAH]", mypass.ir.gen.py)
|
|
453
427
|
self.assertIn("tuple[int, Optional[type], Optional[tuple]]", mypass.ir.gen.py)
|
|
454
428
|
|
|
455
429
|
def test_impl_decl_resolution_fix(self) -> None:
|
|
456
430
|
"""Test walking through edges and nodes."""
|
|
457
|
-
Jac.get_root()._jac_.edges.clear()
|
|
458
431
|
captured_output = io.StringIO()
|
|
459
432
|
sys.stdout = captured_output
|
|
460
433
|
jac_import("mtest", base_path=self.fixture_abs_path("./"))
|
|
@@ -496,12 +469,23 @@ class JacLanguageTests(TestCase):
|
|
|
496
469
|
|
|
497
470
|
def test_needs_import_1(self) -> None:
|
|
498
471
|
"""Test py ast to Jac ast conversion output."""
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
from jaclang.compiler.passes.main.schedules import
|
|
472
|
+
file_name = self.fixture_abs_path("pyfunc_1.py")
|
|
473
|
+
|
|
474
|
+
from jaclang.compiler.passes.main.schedules import py_code_gen_typed
|
|
475
|
+
from jaclang.compiler.passes.main.pyast_load_pass import PyastBuildPass
|
|
476
|
+
import ast as py_ast
|
|
502
477
|
import jaclang.compiler.absyntree as ast
|
|
503
478
|
|
|
504
|
-
|
|
479
|
+
with open(file_name, "r") as f:
|
|
480
|
+
parsed_ast = py_ast.parse(f.read())
|
|
481
|
+
try:
|
|
482
|
+
py_ast_build_pass = PyastBuildPass(
|
|
483
|
+
input_ir=ast.PythonModuleAst(parsed_ast, mod_path=file_name),
|
|
484
|
+
)
|
|
485
|
+
except Exception as e:
|
|
486
|
+
return f"Error While Jac to Py AST conversion: {e}"
|
|
487
|
+
|
|
488
|
+
ir = jac_pass_to_pass(py_ast_build_pass, schedule=py_code_gen_typed).ir
|
|
505
489
|
self.assertEqual(len(ir.get_all_sub_nodes(ast.Architype)), 7)
|
|
506
490
|
captured_output = io.StringIO()
|
|
507
491
|
sys.stdout = captured_output
|
|
@@ -509,7 +493,6 @@ class JacLanguageTests(TestCase):
|
|
|
509
493
|
sys.stdout = sys.__stdout__
|
|
510
494
|
stdout_value = captured_output.getvalue()
|
|
511
495
|
self.assertIn("pyfunc_1 imported", stdout_value)
|
|
512
|
-
settings.py_raise = False
|
|
513
496
|
|
|
514
497
|
def test_pyfunc_1(self) -> None:
|
|
515
498
|
"""Test py ast to Jac ast conversion."""
|
|
@@ -544,13 +527,26 @@ class JacLanguageTests(TestCase):
|
|
|
544
527
|
|
|
545
528
|
def test_needs_import_2(self) -> None:
|
|
546
529
|
"""Test py ast to Jac ast conversion output."""
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
from jaclang.compiler.passes.main.schedules import
|
|
530
|
+
file_name = self.fixture_abs_path("pyfunc_2.py")
|
|
531
|
+
|
|
532
|
+
from jaclang.compiler.passes.main.schedules import py_code_gen_typed
|
|
533
|
+
from jaclang.compiler.passes.main.pyast_load_pass import PyastBuildPass
|
|
534
|
+
import ast as py_ast
|
|
550
535
|
import jaclang.compiler.absyntree as ast
|
|
551
536
|
|
|
552
|
-
|
|
553
|
-
|
|
537
|
+
with open(file_name, "r") as f:
|
|
538
|
+
parsed_ast = py_ast.parse(f.read())
|
|
539
|
+
try:
|
|
540
|
+
py_ast_build_pass = PyastBuildPass(
|
|
541
|
+
input_ir=ast.PythonModuleAst(parsed_ast, mod_path=file_name),
|
|
542
|
+
)
|
|
543
|
+
except Exception as e:
|
|
544
|
+
return f"Error While Jac to Py AST conversion: {e}"
|
|
545
|
+
|
|
546
|
+
ir = jac_pass_to_pass(py_ast_build_pass, schedule=py_code_gen_typed).ir
|
|
547
|
+
self.assertEqual(
|
|
548
|
+
len(ir.get_all_sub_nodes(ast.Architype)), 8
|
|
549
|
+
) # Because of the Architype from math
|
|
554
550
|
captured_output = io.StringIO()
|
|
555
551
|
sys.stdout = captured_output
|
|
556
552
|
jac_import("needs_import_2", base_path=self.fixture_abs_path("./"))
|
|
@@ -558,7 +554,6 @@ class JacLanguageTests(TestCase):
|
|
|
558
554
|
stdout_value = captured_output.getvalue()
|
|
559
555
|
self.assertIn("pyfunc_2 imported", stdout_value)
|
|
560
556
|
self.assertEqual(stdout_value.count("<class 'bytes'>"), 3)
|
|
561
|
-
settings.py_raise = False
|
|
562
557
|
|
|
563
558
|
def test_pyfunc_2(self) -> None:
|
|
564
559
|
"""Test py ast to Jac ast conversion."""
|
|
@@ -580,20 +575,32 @@ class JacLanguageTests(TestCase):
|
|
|
580
575
|
|
|
581
576
|
def test_needs_import_3(self) -> None:
|
|
582
577
|
"""Test py ast to Jac ast conversion output."""
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
from jaclang.compiler.passes.main.schedules import
|
|
578
|
+
file_name = self.fixture_abs_path("pyfunc_3.py")
|
|
579
|
+
|
|
580
|
+
from jaclang.compiler.passes.main.schedules import py_code_gen_typed
|
|
581
|
+
from jaclang.compiler.passes.main.pyast_load_pass import PyastBuildPass
|
|
582
|
+
import ast as py_ast
|
|
586
583
|
import jaclang.compiler.absyntree as ast
|
|
587
584
|
|
|
588
|
-
|
|
589
|
-
|
|
585
|
+
with open(file_name, "r") as f:
|
|
586
|
+
parsed_ast = py_ast.parse(f.read())
|
|
587
|
+
try:
|
|
588
|
+
py_ast_build_pass = PyastBuildPass(
|
|
589
|
+
input_ir=ast.PythonModuleAst(parsed_ast, mod_path=file_name),
|
|
590
|
+
)
|
|
591
|
+
except Exception as e:
|
|
592
|
+
return f"Error While Jac to Py AST conversion: {e}"
|
|
593
|
+
|
|
594
|
+
ir = jac_pass_to_pass(py_ast_build_pass, schedule=py_code_gen_typed).ir
|
|
595
|
+
self.assertEqual(
|
|
596
|
+
len(ir.get_all_sub_nodes(ast.Architype)), 38
|
|
597
|
+
) # Because of the Architype from other imports
|
|
590
598
|
captured_output = io.StringIO()
|
|
591
599
|
sys.stdout = captured_output
|
|
592
600
|
jac_import("needs_import_3", base_path=self.fixture_abs_path("./"))
|
|
593
601
|
sys.stdout = sys.__stdout__
|
|
594
602
|
stdout_value = captured_output.getvalue()
|
|
595
603
|
self.assertIn("pyfunc_3 imported", stdout_value)
|
|
596
|
-
settings.py_raise = False
|
|
597
604
|
|
|
598
605
|
def test_pyfunc_3(self) -> None:
|
|
599
606
|
"""Test py ast to Jac ast conversion."""
|
|
@@ -708,11 +715,10 @@ class JacLanguageTests(TestCase):
|
|
|
708
715
|
|
|
709
716
|
def test_random_check(self) -> None:
|
|
710
717
|
"""Test py ast to Jac ast conversion output."""
|
|
711
|
-
settings.py_raise = True
|
|
712
|
-
|
|
713
718
|
from jaclang.compiler.passes.main import PyastBuildPass
|
|
714
719
|
import jaclang.compiler.absyntree as ast
|
|
715
720
|
import ast as py_ast
|
|
721
|
+
from jaclang.settings import settings
|
|
716
722
|
|
|
717
723
|
module_paths = ["random", "ast"]
|
|
718
724
|
for module_path in module_paths:
|
|
@@ -727,23 +733,21 @@ class JacLanguageTests(TestCase):
|
|
|
727
733
|
py_ast.parse(f.read()), mod_path=file_path
|
|
728
734
|
)
|
|
729
735
|
)
|
|
736
|
+
settings.print_py_raised_ast = True
|
|
730
737
|
ir = jac_pass_to_pass(jac_ast).ir
|
|
731
738
|
gen_ast = ir.pp()
|
|
732
739
|
if module_path == "random":
|
|
733
740
|
self.assertIn("ModulePath - statistics -", gen_ast)
|
|
734
741
|
else:
|
|
735
742
|
self.assertIn("+-- Name - NodeTransformer - Type: No", gen_ast)
|
|
736
|
-
settings.py_raise = False
|
|
737
743
|
|
|
738
744
|
def test_deep_py_load_imports(self) -> None: # we can get rid of this, isn't?
|
|
739
745
|
"""Test py ast to Jac ast conversion output."""
|
|
740
|
-
settings.py_raise = True
|
|
741
746
|
file_name = os.path.join(self.fixture_abs_path("./"), "random_check.jac")
|
|
742
747
|
from jaclang.compiler.passes.main.schedules import py_code_gen, PyImportPass
|
|
743
748
|
|
|
744
749
|
imp = jac_file_to_pass(file_name, schedule=py_code_gen, target=PyImportPass)
|
|
745
750
|
self.assertEqual(len(imp.import_table), 1)
|
|
746
|
-
settings.py_raise = False
|
|
747
751
|
|
|
748
752
|
def test_access_modifier(self) -> None:
|
|
749
753
|
"""Test for access tags working."""
|
|
@@ -755,29 +759,38 @@ class JacLanguageTests(TestCase):
|
|
|
755
759
|
)
|
|
756
760
|
sys.stdout = sys.__stdout__
|
|
757
761
|
stdout_value = captured_output.getvalue()
|
|
758
|
-
self.
|
|
759
|
-
self.assertIn('Can not access private variable "privmethod"', stdout_value)
|
|
760
|
-
self.assertIn('Can not access private variable "BankAccount"', stdout_value)
|
|
761
|
-
self.assertNotIn(" Name: ", stdout_value)
|
|
762
|
+
self.assertEqual(stdout_value.count("Invalid access"), 18)
|
|
762
763
|
|
|
763
764
|
def test_deep_convert(self) -> None:
|
|
764
765
|
"""Test py ast to Jac ast conversion output."""
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
from jaclang.compiler.passes.main.schedules import
|
|
766
|
+
file_name = self.fixture_abs_path("pyfunc_1.py")
|
|
767
|
+
|
|
768
|
+
from jaclang.compiler.passes.main.schedules import py_code_gen_typed
|
|
769
|
+
from jaclang.compiler.passes.main.pyast_load_pass import PyastBuildPass
|
|
770
|
+
import ast as py_ast
|
|
768
771
|
import jaclang.compiler.absyntree as ast
|
|
772
|
+
from jaclang.settings import settings
|
|
773
|
+
|
|
774
|
+
with open(file_name, "r") as f:
|
|
775
|
+
parsed_ast = py_ast.parse(f.read())
|
|
776
|
+
try:
|
|
777
|
+
py_ast_build_pass = PyastBuildPass(
|
|
778
|
+
input_ir=ast.PythonModuleAst(parsed_ast, mod_path=file_name),
|
|
779
|
+
)
|
|
780
|
+
except Exception as e:
|
|
781
|
+
return f"Error While Jac to Py AST conversion: {e}"
|
|
769
782
|
|
|
770
|
-
|
|
783
|
+
settings.print_py_raised_ast = True
|
|
784
|
+
ir = jac_pass_to_pass(py_ast_build_pass, schedule=py_code_gen_typed).ir
|
|
771
785
|
jac_ast = ir.pp()
|
|
772
786
|
self.assertIn(' | +-- String - "Loop compl', jac_ast)
|
|
773
|
-
self.assertEqual(len(ir.get_all_sub_nodes(ast.SubNodeList)),
|
|
787
|
+
self.assertEqual(len(ir.get_all_sub_nodes(ast.SubNodeList)), 269)
|
|
774
788
|
captured_output = io.StringIO()
|
|
775
789
|
sys.stdout = captured_output
|
|
776
790
|
jac_import("deep_convert", base_path=self.fixture_abs_path("./"))
|
|
777
791
|
sys.stdout = sys.__stdout__
|
|
778
792
|
stdout_value = captured_output.getvalue()
|
|
779
793
|
self.assertIn("Deep convo is imported", stdout_value)
|
|
780
|
-
settings.py_raise = settings.py_raise_deep = False
|
|
781
794
|
|
|
782
795
|
def test_override_walker_inherit(self) -> None:
|
|
783
796
|
"""Test py ast to Jac ast conversion output."""
|
|
@@ -790,7 +803,6 @@ class JacLanguageTests(TestCase):
|
|
|
790
803
|
|
|
791
804
|
def test_ds_type_check_pass(self) -> None:
|
|
792
805
|
"""Test conn assign on edges."""
|
|
793
|
-
Jac.get_root()._jac_.edges.clear()
|
|
794
806
|
mypass = jac_file_to_pass(
|
|
795
807
|
self.examples_abs_path("micro/simple_walk.jac"),
|
|
796
808
|
schedule=py_code_gen_typed,
|
|
@@ -800,7 +812,6 @@ class JacLanguageTests(TestCase):
|
|
|
800
812
|
|
|
801
813
|
def test_ds_type_check_pass2(self) -> None:
|
|
802
814
|
"""Test conn assign on edges."""
|
|
803
|
-
Jac.get_root()._jac_.edges.clear()
|
|
804
815
|
mypass = jac_file_to_pass(
|
|
805
816
|
self.examples_abs_path("guess_game/guess_game5.jac"),
|
|
806
817
|
schedule=py_code_gen_typed,
|
|
@@ -810,7 +821,6 @@ class JacLanguageTests(TestCase):
|
|
|
810
821
|
|
|
811
822
|
def test_circle_override1_type_check_pass(self) -> None:
|
|
812
823
|
"""Test conn assign on edges."""
|
|
813
|
-
Jac.get_root()._jac_.edges.clear()
|
|
814
824
|
mypass = jac_file_to_pass(
|
|
815
825
|
self.examples_abs_path("manual_code/circle.jac"),
|
|
816
826
|
schedule=py_code_gen_typed,
|
|
@@ -838,7 +848,6 @@ class JacLanguageTests(TestCase):
|
|
|
838
848
|
|
|
839
849
|
def test_multiline_single_tok(self) -> None:
|
|
840
850
|
"""Test conn assign on edges."""
|
|
841
|
-
Jac.get_root()._jac_.edges.clear()
|
|
842
851
|
mypass = jac_file_to_pass(self.fixture_abs_path("byllmissue.jac"))
|
|
843
852
|
self.assertIn("2:5 - 4:8", mypass.ir.pp())
|
|
844
853
|
|
|
@@ -868,7 +877,6 @@ class JacLanguageTests(TestCase):
|
|
|
868
877
|
)
|
|
869
878
|
table = None
|
|
870
879
|
for i in mypass.ir.sym_tab.kid:
|
|
871
|
-
print(i.name)
|
|
872
880
|
if i.name == "GuessTheNumberGame":
|
|
873
881
|
for j in i.kid:
|
|
874
882
|
if j.name == "play":
|
|
@@ -916,3 +924,41 @@ class JacLanguageTests(TestCase):
|
|
|
916
924
|
self.assertEqual("MyClass", stdout_value[0])
|
|
917
925
|
self.assertEqual("Hello, World1! Hello, World2!", stdout_value[1])
|
|
918
926
|
self.assertEqual("Hello, World! Hello, World22!", stdout_value[2])
|
|
927
|
+
|
|
928
|
+
def test_list_methods(self) -> None:
|
|
929
|
+
"""Test list_modules, list_walkers, list_nodes, and list_edges."""
|
|
930
|
+
captured_output = io.StringIO()
|
|
931
|
+
sys.stdout = captured_output
|
|
932
|
+
|
|
933
|
+
jac_import("foo", base_path=self.fixture_abs_path("."))
|
|
934
|
+
|
|
935
|
+
sys.stdout = sys.__stdout__
|
|
936
|
+
stdout_value = captured_output.getvalue()
|
|
937
|
+
|
|
938
|
+
self.assertIn(
|
|
939
|
+
"Module: foo",
|
|
940
|
+
stdout_value,
|
|
941
|
+
)
|
|
942
|
+
self.assertIn(
|
|
943
|
+
"Module: bar",
|
|
944
|
+
stdout_value,
|
|
945
|
+
)
|
|
946
|
+
self.assertIn(
|
|
947
|
+
"Walkers in bar:\n - Walker: bar_walk",
|
|
948
|
+
stdout_value,
|
|
949
|
+
)
|
|
950
|
+
self.assertIn("Nodes in bar:\n - Node: Item", stdout_value)
|
|
951
|
+
self.assertIn("Edges in bar:\n - Edge: Link", stdout_value)
|
|
952
|
+
self.assertIn("Item value: 0", stdout_value)
|
|
953
|
+
self.assertIn("Created 5 items.", stdout_value)
|
|
954
|
+
|
|
955
|
+
def test_object_ref_interface(self) -> None:
|
|
956
|
+
"""Test class method output."""
|
|
957
|
+
captured_output = io.StringIO()
|
|
958
|
+
sys.stdout = captured_output
|
|
959
|
+
cli.run(self.fixture_abs_path("objref.jac"))
|
|
960
|
+
sys.stdout = sys.__stdout__
|
|
961
|
+
stdout_value = captured_output.getvalue().split("\n")
|
|
962
|
+
self.assertEqual(len(stdout_value[0]), 32)
|
|
963
|
+
self.assertEqual("MyNode(value=0)", stdout_value[1])
|
|
964
|
+
self.assertEqual("valid: True", stdout_value[2])
|
jaclang/tests/test_reference.py
CHANGED
|
@@ -7,7 +7,7 @@ from typing import Callable, Optional
|
|
|
7
7
|
|
|
8
8
|
import jaclang
|
|
9
9
|
from jaclang.compiler.compile import jac_file_to_pass
|
|
10
|
-
from jaclang.
|
|
10
|
+
from jaclang.runtimelib.context import SUPER_ROOT_ANCHOR
|
|
11
11
|
from jaclang.utils.test import TestCase
|
|
12
12
|
|
|
13
13
|
|
|
@@ -52,13 +52,7 @@ class JacReferenceTests(TestCase):
|
|
|
52
52
|
"""Test file."""
|
|
53
53
|
|
|
54
54
|
def execute_and_capture_output(code: str | bytes, filename: str = "") -> str:
|
|
55
|
-
|
|
56
|
-
Jac.context().init_memory(
|
|
57
|
-
base_path=os.path.join(
|
|
58
|
-
os.path.dirname(os.path.dirname(jaclang.__file__)),
|
|
59
|
-
"examples/reference",
|
|
60
|
-
)
|
|
61
|
-
)
|
|
55
|
+
SUPER_ROOT_ANCHOR.edges.clear()
|
|
62
56
|
f = io.StringIO()
|
|
63
57
|
with redirect_stdout(f):
|
|
64
58
|
exec(
|
|
@@ -66,7 +60,6 @@ class JacReferenceTests(TestCase):
|
|
|
66
60
|
{
|
|
67
61
|
"__file__": filename,
|
|
68
62
|
"__name__": "__main__",
|
|
69
|
-
"__jac_mod_bundle__": None,
|
|
70
63
|
},
|
|
71
64
|
)
|
|
72
65
|
return f.getvalue()
|
jaclang/utils/treeprinter.py
CHANGED
|
@@ -10,7 +10,6 @@ from typing import Optional, TYPE_CHECKING
|
|
|
10
10
|
import jaclang.compiler.absyntree as ast
|
|
11
11
|
from jaclang.settings import settings
|
|
12
12
|
|
|
13
|
-
|
|
14
13
|
if TYPE_CHECKING:
|
|
15
14
|
from jaclang.compiler.absyntree import AstNode, SymbolTable
|
|
16
15
|
|
|
@@ -89,6 +88,8 @@ def print_ast_tree(
|
|
|
89
88
|
"""Recursively print ast tree."""
|
|
90
89
|
from jaclang.compiler.absyntree import AstSymbolNode, Token
|
|
91
90
|
|
|
91
|
+
print_py_raise: bool = settings.print_py_raised_ast
|
|
92
|
+
|
|
92
93
|
def __node_repr_in_tree(node: AstNode) -> str:
|
|
93
94
|
access = (
|
|
94
95
|
f"Access: {node.access.tag.value} ,"
|
|
@@ -116,6 +117,19 @@ def print_ast_tree(
|
|
|
116
117
|
return out
|
|
117
118
|
elif isinstance(node, Token):
|
|
118
119
|
return f"{node.__class__.__name__} - {node.value}, {access}"
|
|
120
|
+
elif (
|
|
121
|
+
isinstance(node, ast.Module)
|
|
122
|
+
and node.is_raised_from_py
|
|
123
|
+
and not print_py_raise
|
|
124
|
+
):
|
|
125
|
+
return f"{node.__class__.__name__} - PythonModuleRaised: {node.name}"
|
|
126
|
+
elif isinstance(node, (ast.ModuleItem, ast.ModulePath)):
|
|
127
|
+
out = (
|
|
128
|
+
f"{node.__class__.__name__} - {node.sym_name} - "
|
|
129
|
+
f"abs_path: {node.abs_path}"
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
return out
|
|
119
133
|
elif isinstance(node, AstSymbolNode):
|
|
120
134
|
out = (
|
|
121
135
|
f"{node.__class__.__name__} - {node.sym_name} - "
|
|
@@ -184,11 +198,24 @@ def print_ast_tree(
|
|
|
184
198
|
|
|
185
199
|
if isinstance(root, ast.AstNode):
|
|
186
200
|
tree_str = f"{root.loc}\t{markers}{__node_repr_in_tree(root)}\n"
|
|
187
|
-
|
|
188
|
-
|
|
201
|
+
if (
|
|
202
|
+
isinstance(root, ast.Module)
|
|
203
|
+
and root.is_raised_from_py
|
|
204
|
+
and not print_py_raise
|
|
205
|
+
):
|
|
206
|
+
kids: list[AstNode] = [
|
|
207
|
+
*filter(
|
|
208
|
+
lambda x: x.is_raised_from_py, root.get_all_sub_nodes(ast.Module)
|
|
209
|
+
)
|
|
210
|
+
]
|
|
211
|
+
else:
|
|
212
|
+
kids = root.kid
|
|
213
|
+
for i, child in enumerate(kids):
|
|
214
|
+
is_last = i == len(kids) - 1
|
|
189
215
|
tree_str += print_ast_tree(
|
|
190
216
|
child, marker, [*level_markers, not is_last], output_file, max_depth
|
|
191
217
|
)
|
|
218
|
+
|
|
192
219
|
elif isinstance(root, ast3.AST):
|
|
193
220
|
tree_str = (
|
|
194
221
|
f"{get_location_info(root)}\t{markers}{__node_repr_in_py_tree(root)}\n"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: jaclang
|
|
3
|
-
Version: 0.7.
|
|
3
|
+
Version: 0.7.18
|
|
4
4
|
Summary: Jac is a unique and powerful programming language that runs on top of Python, offering an unprecedented level of intelligence and intuitive understanding.
|
|
5
5
|
Home-page: https://jaseci.org
|
|
6
6
|
License: MIT
|
|
@@ -12,7 +12,9 @@ Classifier: License :: OSI Approved :: MIT License
|
|
|
12
12
|
Classifier: Programming Language :: Python :: 3
|
|
13
13
|
Classifier: Programming Language :: Python :: 3.11
|
|
14
14
|
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Provides-Extra: all
|
|
15
16
|
Provides-Extra: llm
|
|
17
|
+
Provides-Extra: streamlit
|
|
16
18
|
Project-URL: Documentation, https://jac-lang.org
|
|
17
19
|
Project-URL: Repository, https://github.com/Jaseci-Labs/jaclang
|
|
18
20
|
Description-Content-Type: text/markdown
|