jaclang 0.8.0__py3-none-any.whl → 0.8.2__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 +6 -0
- jaclang/cli/cli.py +23 -50
- jaclang/compiler/codeinfo.py +0 -1
- jaclang/compiler/jac.lark +14 -22
- jaclang/compiler/larkparse/jac_parser.py +2 -2
- jaclang/compiler/parser.py +378 -531
- jaclang/compiler/passes/main/__init__.py +0 -14
- jaclang/compiler/passes/main/annex_pass.py +2 -8
- jaclang/compiler/passes/main/cfg_build_pass.py +39 -13
- jaclang/compiler/passes/main/def_impl_match_pass.py +14 -13
- jaclang/compiler/passes/main/def_use_pass.py +4 -7
- jaclang/compiler/passes/main/import_pass.py +6 -14
- jaclang/compiler/passes/main/inheritance_pass.py +2 -2
- jaclang/compiler/passes/main/pyast_gen_pass.py +428 -799
- jaclang/compiler/passes/main/pyast_load_pass.py +115 -311
- jaclang/compiler/passes/main/pyjac_ast_link_pass.py +8 -7
- jaclang/compiler/passes/main/sym_tab_build_pass.py +3 -3
- jaclang/compiler/passes/main/sym_tab_link_pass.py +6 -9
- jaclang/compiler/passes/main/tests/fixtures/symtab_link_tests/action/actions.jac +1 -5
- jaclang/compiler/passes/main/tests/fixtures/symtab_link_tests/main.jac +1 -8
- jaclang/compiler/passes/main/tests/test_cfg_build_pass.py +5 -9
- jaclang/compiler/passes/main/tests/test_decl_impl_match_pass.py +7 -8
- jaclang/compiler/passes/main/tests/test_import_pass.py +5 -18
- jaclang/compiler/passes/main/tests/test_pyast_gen_pass.py +2 -6
- jaclang/compiler/passes/main/tests/test_sub_node_pass.py +1 -3
- jaclang/compiler/passes/main/tests/test_sym_tab_link_pass.py +20 -17
- jaclang/compiler/passes/tool/doc_ir_gen_pass.py +425 -216
- jaclang/compiler/passes/tool/jac_formatter_pass.py +2 -0
- jaclang/compiler/passes/tool/tests/fixtures/archetype_frmt.jac +14 -0
- jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/triple_quoted_string.jac +5 -4
- jaclang/compiler/passes/tool/tests/fixtures/import_fmt.jac +6 -0
- jaclang/compiler/passes/tool/tests/fixtures/simple_walk_fmt.jac +3 -3
- jaclang/compiler/passes/tool/tests/fixtures/tagbreak.jac +9 -0
- jaclang/compiler/passes/tool/tests/test_jac_format_pass.py +18 -3
- jaclang/compiler/passes/tool/tests/test_unparse_validate.py +2 -2
- jaclang/compiler/program.py +22 -66
- jaclang/compiler/tests/fixtures/fam.jac +2 -2
- jaclang/compiler/tests/fixtures/pkg_import_lib/__init__.jac +1 -0
- jaclang/compiler/tests/fixtures/pkg_import_lib/sub/__init__.jac +1 -0
- jaclang/compiler/tests/fixtures/pkg_import_lib/sub/helper.jac +3 -0
- jaclang/compiler/tests/fixtures/pkg_import_lib/tools.jac +3 -0
- jaclang/compiler/tests/fixtures/pkg_import_lib_py/__init__.py +5 -0
- jaclang/compiler/tests/fixtures/pkg_import_lib_py/sub/__init__.py +3 -0
- jaclang/compiler/tests/fixtures/pkg_import_lib_py/sub/helper.jac +3 -0
- jaclang/compiler/tests/fixtures/pkg_import_lib_py/tools.jac +3 -0
- jaclang/compiler/tests/fixtures/pkg_import_main.jac +10 -0
- jaclang/compiler/tests/fixtures/pkg_import_main_py.jac +11 -0
- jaclang/compiler/tests/test_importer.py +30 -13
- jaclang/compiler/tests/test_parser.py +1 -0
- jaclang/compiler/unitree.py +488 -320
- jaclang/langserve/__init__.jac +1 -0
- jaclang/langserve/engine.jac +503 -0
- jaclang/langserve/sem_manager.jac +309 -0
- jaclang/langserve/server.jac +201 -0
- jaclang/langserve/tests/server_test/test_lang_serve.py +139 -48
- jaclang/langserve/tests/server_test/utils.py +35 -6
- jaclang/langserve/tests/session.jac +294 -0
- jaclang/langserve/tests/test_sem_tokens.py +2 -2
- jaclang/langserve/tests/test_server.py +8 -7
- jaclang/langserve/utils.jac +51 -30
- jaclang/runtimelib/archetype.py +128 -6
- jaclang/runtimelib/builtin.py +17 -14
- jaclang/runtimelib/importer.py +51 -76
- jaclang/runtimelib/machine.py +469 -305
- jaclang/runtimelib/meta_importer.py +86 -0
- jaclang/runtimelib/tests/fixtures/graph_purger.jac +24 -26
- jaclang/runtimelib/tests/fixtures/other_root_access.jac +25 -16
- jaclang/runtimelib/tests/fixtures/traversing_save.jac +7 -5
- jaclang/runtimelib/tests/test_jaseci.py +3 -1
- jaclang/runtimelib/utils.py +3 -3
- jaclang/tests/fixtures/arch_rel_import_creation.jac +23 -23
- jaclang/tests/fixtures/async_ability.jac +43 -10
- jaclang/tests/fixtures/async_function.jac +18 -0
- jaclang/tests/fixtures/async_walker.jac +17 -12
- jaclang/tests/fixtures/backward_edge_visit.jac +31 -0
- jaclang/tests/fixtures/builtin_printgraph.jac +85 -0
- jaclang/tests/fixtures/builtin_printgraph_json.jac +21 -0
- jaclang/tests/fixtures/builtin_printgraph_mermaid.jac +16 -0
- jaclang/tests/fixtures/chandra_bugs2.jac +20 -13
- jaclang/tests/fixtures/concurrency.jac +1 -1
- jaclang/tests/fixtures/create_dynamic_archetype.jac +25 -28
- jaclang/tests/fixtures/deep/deeper/deep_outer_import.jac +7 -4
- jaclang/tests/fixtures/deep/deeper/snd_lev.jac +2 -2
- jaclang/tests/fixtures/deep/deeper/snd_lev_dup.jac +6 -0
- jaclang/tests/fixtures/deep/one_lev.jac +2 -2
- jaclang/tests/fixtures/deep/one_lev_dup.jac +4 -3
- jaclang/tests/fixtures/dynamic_archetype.jac +19 -12
- jaclang/tests/fixtures/edge_ability.jac +49 -0
- jaclang/tests/fixtures/foo.jac +14 -22
- jaclang/tests/fixtures/guess_game.jac +1 -1
- jaclang/tests/fixtures/here_usage_error.jac +21 -0
- jaclang/tests/fixtures/here_visitor_usage.jac +21 -0
- jaclang/tests/fixtures/jac_from_py.py +1 -1
- jaclang/tests/fixtures/jp_importer.jac +6 -6
- jaclang/tests/fixtures/jp_importer_auto.jac +5 -3
- jaclang/tests/fixtures/node_del.jac +30 -36
- jaclang/tests/fixtures/unicode_strings.jac +24 -0
- jaclang/tests/fixtures/visit_traversal.jac +47 -0
- jaclang/tests/fixtures/walker_update.jac +5 -7
- jaclang/tests/test_cli.py +12 -7
- jaclang/tests/test_language.py +218 -145
- jaclang/tests/test_reference.py +9 -4
- jaclang/tests/test_typecheck.py +13 -26
- jaclang/utils/helpers.py +14 -6
- jaclang/utils/lang_tools.py +9 -8
- jaclang/utils/module_resolver.py +23 -0
- jaclang/utils/tests/test_lang_tools.py +2 -1
- jaclang/utils/treeprinter.py +3 -4
- {jaclang-0.8.0.dist-info → jaclang-0.8.2.dist-info}/METADATA +4 -3
- {jaclang-0.8.0.dist-info → jaclang-0.8.2.dist-info}/RECORD +112 -94
- {jaclang-0.8.0.dist-info → jaclang-0.8.2.dist-info}/WHEEL +1 -1
- jaclang/compiler/passes/main/tests/fixtures/main_err.jac +0 -6
- jaclang/compiler/passes/main/tests/fixtures/second_err.jac +0 -4
- jaclang/compiler/passes/tool/tests/fixtures/corelib.jac +0 -644
- jaclang/compiler/passes/tool/tests/test_doc_ir_gen_pass.py +0 -29
- jaclang/langserve/__init__.py +0 -1
- jaclang/langserve/engine.py +0 -553
- jaclang/langserve/sem_manager.py +0 -383
- jaclang/langserve/server.py +0 -167
- jaclang/langserve/tests/session.py +0 -255
- jaclang/tests/fixtures/builtin_dotgen.jac +0 -42
- jaclang/tests/fixtures/builtin_dotgen_json.jac +0 -21
- jaclang/tests/fixtures/deep/deeper/__init__.jac +0 -1
- {jaclang-0.8.0.dist-info → jaclang-0.8.2.dist-info}/entry_points.txt +0 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"""Jac meta path importer."""
|
|
2
|
+
|
|
3
|
+
import importlib.abc
|
|
4
|
+
import importlib.machinery
|
|
5
|
+
import importlib.util
|
|
6
|
+
import os
|
|
7
|
+
from types import ModuleType
|
|
8
|
+
from typing import Optional, Sequence
|
|
9
|
+
|
|
10
|
+
from jaclang.runtimelib.machine import JacMachine as Jac
|
|
11
|
+
from jaclang.runtimelib.machine import JacMachineInterface
|
|
12
|
+
from jaclang.utils.module_resolver import get_jac_search_paths
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class JacMetaImporter(importlib.abc.MetaPathFinder, importlib.abc.Loader):
|
|
16
|
+
"""Meta path importer to load .jac modules via Python's import system."""
|
|
17
|
+
|
|
18
|
+
def find_spec(
|
|
19
|
+
self,
|
|
20
|
+
fullname: str,
|
|
21
|
+
path: Optional[Sequence[str]] = None,
|
|
22
|
+
target: Optional[ModuleType] = None,
|
|
23
|
+
) -> Optional[importlib.machinery.ModuleSpec]:
|
|
24
|
+
"""Find the spec for the module."""
|
|
25
|
+
if path is None:
|
|
26
|
+
# Top-level import
|
|
27
|
+
paths_to_search = get_jac_search_paths()
|
|
28
|
+
module_path_parts = fullname.split(".")
|
|
29
|
+
else:
|
|
30
|
+
# Submodule import
|
|
31
|
+
paths_to_search = [*path]
|
|
32
|
+
module_path_parts = fullname.split(".")[-1:]
|
|
33
|
+
|
|
34
|
+
for search_path in paths_to_search:
|
|
35
|
+
candidate_path = os.path.join(search_path, *module_path_parts)
|
|
36
|
+
# Check for directory package
|
|
37
|
+
if os.path.isdir(candidate_path):
|
|
38
|
+
init_file = os.path.join(candidate_path, "__init__.jac")
|
|
39
|
+
if os.path.isfile(init_file):
|
|
40
|
+
return importlib.util.spec_from_file_location(
|
|
41
|
+
fullname,
|
|
42
|
+
init_file,
|
|
43
|
+
loader=self,
|
|
44
|
+
submodule_search_locations=[candidate_path],
|
|
45
|
+
)
|
|
46
|
+
# Check for .jac file
|
|
47
|
+
if os.path.isfile(candidate_path + ".jac"):
|
|
48
|
+
return importlib.util.spec_from_file_location(
|
|
49
|
+
fullname, candidate_path + ".jac", loader=self
|
|
50
|
+
)
|
|
51
|
+
return None
|
|
52
|
+
|
|
53
|
+
def create_module(
|
|
54
|
+
self, spec: importlib.machinery.ModuleSpec
|
|
55
|
+
) -> Optional[ModuleType]:
|
|
56
|
+
"""Create the module."""
|
|
57
|
+
return None # use default machinery
|
|
58
|
+
|
|
59
|
+
def exec_module(self, module: ModuleType) -> None:
|
|
60
|
+
"""Execute the module."""
|
|
61
|
+
if not module.__spec__ or not module.__spec__.origin:
|
|
62
|
+
raise ImportError(
|
|
63
|
+
f"Cannot find spec or origin for module {module.__name__}"
|
|
64
|
+
)
|
|
65
|
+
file_path = module.__spec__.origin
|
|
66
|
+
is_pkg = module.__spec__.submodule_search_locations is not None
|
|
67
|
+
|
|
68
|
+
if is_pkg:
|
|
69
|
+
codeobj = Jac.program.get_bytecode(full_target=file_path)
|
|
70
|
+
if codeobj:
|
|
71
|
+
exec(codeobj, module.__dict__)
|
|
72
|
+
JacMachineInterface.load_module(module.__name__, module)
|
|
73
|
+
return
|
|
74
|
+
|
|
75
|
+
base_path = os.path.dirname(file_path)
|
|
76
|
+
target = os.path.splitext(os.path.basename(file_path))[0]
|
|
77
|
+
ret = JacMachineInterface.jac_import(
|
|
78
|
+
target=target,
|
|
79
|
+
base_path=base_path,
|
|
80
|
+
override_name=module.__name__,
|
|
81
|
+
)
|
|
82
|
+
if ret:
|
|
83
|
+
loaded_module = ret[0]
|
|
84
|
+
module.__dict__.update(loaded_module.__dict__)
|
|
85
|
+
else:
|
|
86
|
+
raise ImportError(f"Unable to import {module.__name__}")
|
|
@@ -1,21 +1,26 @@
|
|
|
1
|
-
import from jaclang.runtimelib.machine {
|
|
1
|
+
import from jaclang.runtimelib.machine { JacMachine as Jac }
|
|
2
|
+
|
|
2
3
|
|
|
3
4
|
node A {
|
|
4
5
|
has id: int;
|
|
5
6
|
}
|
|
6
7
|
|
|
8
|
+
|
|
7
9
|
node B {
|
|
8
10
|
has id: int;
|
|
9
11
|
}
|
|
10
12
|
|
|
13
|
+
|
|
11
14
|
node C {
|
|
12
15
|
has id: int;
|
|
13
16
|
}
|
|
14
17
|
|
|
18
|
+
|
|
15
19
|
node D {
|
|
16
20
|
has id: int;
|
|
17
21
|
}
|
|
18
22
|
|
|
23
|
+
|
|
19
24
|
node E {
|
|
20
25
|
has id: int;
|
|
21
26
|
}
|
|
@@ -23,81 +28,74 @@ node E {
|
|
|
23
28
|
|
|
24
29
|
walker populate {
|
|
25
30
|
can setup1 with `root entry {
|
|
26
|
-
for i in range(2) {
|
|
27
|
-
here ++> A(id=i);
|
|
28
|
-
}
|
|
31
|
+
for i in range(2) { here ++> A(id=i); }
|
|
29
32
|
visit [-->];
|
|
30
33
|
}
|
|
31
|
-
|
|
34
|
+
|
|
32
35
|
can setup2 with A entry {
|
|
33
|
-
for i in range(2) {
|
|
34
|
-
here ++> B(id=i);
|
|
35
|
-
}
|
|
36
|
+
for i in range(2) { here ++> B(id=i); }
|
|
36
37
|
visit [-->];
|
|
37
38
|
}
|
|
38
|
-
|
|
39
|
+
|
|
39
40
|
can setup3 with B entry {
|
|
40
|
-
for i in range(2) {
|
|
41
|
-
here ++> C(id=i);
|
|
42
|
-
}
|
|
41
|
+
for i in range(2) { here ++> C(id=i); }
|
|
43
42
|
visit [-->];
|
|
44
43
|
}
|
|
45
|
-
|
|
44
|
+
|
|
46
45
|
can setup4 with C entry {
|
|
47
|
-
for i in range(2) {
|
|
48
|
-
here ++> D(id=i);
|
|
49
|
-
}
|
|
46
|
+
for i in range(2) { here ++> D(id=i); }
|
|
50
47
|
visit [-->];
|
|
51
48
|
}
|
|
52
|
-
|
|
49
|
+
|
|
53
50
|
can setup5 with D entry {
|
|
54
|
-
for i in range(2) {
|
|
55
|
-
here ++> E(id=i);
|
|
56
|
-
}
|
|
51
|
+
for i in range(2) { here ++> E(id=i); }
|
|
57
52
|
visit [-->];
|
|
58
53
|
}
|
|
59
54
|
}
|
|
60
55
|
|
|
56
|
+
|
|
61
57
|
walker traverse {
|
|
62
58
|
can enter1 with `root entry {
|
|
63
59
|
print(here);
|
|
64
60
|
visit [-->];
|
|
65
61
|
}
|
|
66
|
-
|
|
62
|
+
|
|
67
63
|
can enter2 with A entry {
|
|
68
64
|
print(here);
|
|
69
65
|
visit [-->];
|
|
70
66
|
}
|
|
71
|
-
|
|
67
|
+
|
|
72
68
|
can enter3 with B entry {
|
|
73
69
|
print(here);
|
|
74
70
|
visit [-->];
|
|
75
71
|
}
|
|
76
|
-
|
|
72
|
+
|
|
77
73
|
can enter4 with C entry {
|
|
78
74
|
print(here);
|
|
79
75
|
visit [-->];
|
|
80
76
|
}
|
|
81
|
-
|
|
77
|
+
|
|
82
78
|
can enter5 with D entry {
|
|
83
79
|
print(here);
|
|
84
80
|
visit [-->];
|
|
85
81
|
}
|
|
86
|
-
|
|
82
|
+
|
|
87
83
|
can enter6 with E entry {
|
|
88
84
|
print(here);
|
|
89
85
|
visit [-->];
|
|
90
86
|
}
|
|
91
87
|
}
|
|
92
88
|
|
|
89
|
+
|
|
93
90
|
walker purge {
|
|
94
91
|
can purge with `root entry {
|
|
95
92
|
print(Jac.reset_graph());
|
|
96
93
|
}
|
|
97
94
|
}
|
|
98
95
|
|
|
96
|
+
|
|
99
97
|
walker check {
|
|
100
98
|
can enter with `root entry {
|
|
101
99
|
print(len(Jac.get_context().mem.__shelf__.values()));
|
|
102
100
|
}
|
|
103
|
-
}
|
|
101
|
+
}
|
|
@@ -1,51 +1,57 @@
|
|
|
1
|
-
import from jaclang.runtimelib.machine {
|
|
2
|
-
import from jaclang.runtimelib.archetype {Anchor}
|
|
3
|
-
import from uuid {UUID}
|
|
1
|
+
import from jaclang.runtimelib.machine { JacMachine as Jac }
|
|
2
|
+
import from jaclang.runtimelib.archetype { Anchor }
|
|
3
|
+
import from uuid { UUID }
|
|
4
|
+
|
|
4
5
|
|
|
5
6
|
node A {
|
|
6
7
|
has val: int;
|
|
7
8
|
}
|
|
8
9
|
|
|
10
|
+
|
|
9
11
|
walker check_node {
|
|
10
12
|
can enter with `root entry {
|
|
11
13
|
visit [-->];
|
|
12
14
|
}
|
|
13
|
-
|
|
15
|
+
|
|
14
16
|
can enter2 with A entry {
|
|
15
17
|
print(here);
|
|
16
18
|
}
|
|
17
19
|
}
|
|
18
20
|
|
|
21
|
+
|
|
19
22
|
walker update_node {
|
|
20
23
|
has val: int;
|
|
21
|
-
|
|
24
|
+
|
|
22
25
|
can enter2 with A entry {
|
|
23
26
|
here.val = self.val;
|
|
24
27
|
}
|
|
25
28
|
}
|
|
26
29
|
|
|
30
|
+
|
|
27
31
|
walker update_target_node {
|
|
28
32
|
has val: int;
|
|
29
33
|
has node_id: str;
|
|
30
|
-
|
|
34
|
+
|
|
31
35
|
can enter with `root entry {
|
|
32
|
-
target_node = &(self.node_id);
|
|
36
|
+
target_node = & (self.node_id);
|
|
33
37
|
target_node.val = self.val;
|
|
34
38
|
}
|
|
35
39
|
}
|
|
36
40
|
|
|
41
|
+
|
|
37
42
|
walker update_node_forced {
|
|
38
43
|
has val: int;
|
|
39
|
-
|
|
44
|
+
|
|
40
45
|
can enter2 with A entry {
|
|
41
46
|
Jac.elevate_root();
|
|
42
47
|
here.val = self.val;
|
|
43
48
|
}
|
|
44
49
|
}
|
|
45
50
|
|
|
51
|
+
|
|
46
52
|
walker create_node {
|
|
47
53
|
has val: int;
|
|
48
|
-
|
|
54
|
+
|
|
49
55
|
can enter with `root entry {
|
|
50
56
|
a = A(val=self.val);
|
|
51
57
|
here ++> a;
|
|
@@ -53,6 +59,7 @@ walker create_node {
|
|
|
53
59
|
}
|
|
54
60
|
}
|
|
55
61
|
|
|
62
|
+
|
|
56
63
|
walker create_other_root {
|
|
57
64
|
can enter with `root entry {
|
|
58
65
|
other_root = `root().__jac__;
|
|
@@ -61,9 +68,10 @@ walker create_other_root {
|
|
|
61
68
|
}
|
|
62
69
|
}
|
|
63
70
|
|
|
64
|
-
walker allow_other_root_access {
|
|
65
|
-
has root_id: str, level: int | str = 1, via_all: bool = False;
|
|
66
71
|
|
|
72
|
+
walker allow_other_root_access {
|
|
73
|
+
has root_id: str , level: int | str = 1 , via_all: bool = False;
|
|
74
|
+
|
|
67
75
|
can enter_root with `root entry {
|
|
68
76
|
if self.via_all {
|
|
69
77
|
Jac.perm_grant(here, self.level);
|
|
@@ -71,7 +79,7 @@ walker allow_other_root_access {
|
|
|
71
79
|
Jac.allow_root(here, UUID(self.root_id), self.level);
|
|
72
80
|
}
|
|
73
81
|
}
|
|
74
|
-
|
|
82
|
+
|
|
75
83
|
can enter_nested with A entry {
|
|
76
84
|
if self.via_all {
|
|
77
85
|
Jac.perm_grant(here, self.level);
|
|
@@ -81,9 +89,10 @@ walker allow_other_root_access {
|
|
|
81
89
|
}
|
|
82
90
|
}
|
|
83
91
|
|
|
84
|
-
walker disallow_other_root_access {
|
|
85
|
-
has root_id: str, via_all: bool = False;
|
|
86
92
|
|
|
93
|
+
walker disallow_other_root_access {
|
|
94
|
+
has root_id: str , via_all: bool = False;
|
|
95
|
+
|
|
87
96
|
can enter_root with `root entry {
|
|
88
97
|
if self.via_all {
|
|
89
98
|
Jac.perm_revoke(here);
|
|
@@ -91,7 +100,7 @@ walker disallow_other_root_access {
|
|
|
91
100
|
Jac.disallow_root(here, UUID(self.root_id));
|
|
92
101
|
}
|
|
93
102
|
}
|
|
94
|
-
|
|
103
|
+
|
|
95
104
|
can enter_nested with A entry {
|
|
96
105
|
if self.via_all {
|
|
97
106
|
Jac.perm_revoke(here);
|
|
@@ -99,4 +108,4 @@ walker disallow_other_root_access {
|
|
|
99
108
|
Jac.disallow_root(here, UUID(self.root_id));
|
|
100
109
|
}
|
|
101
110
|
}
|
|
102
|
-
}
|
|
111
|
+
}
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
node A {}
|
|
2
2
|
node B {}
|
|
3
3
|
|
|
4
|
+
|
|
4
5
|
walker build {
|
|
5
6
|
can run with `root entry {
|
|
6
7
|
a = A();
|
|
7
|
-
a ++> B();
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
a ++> B();
|
|
9
|
+
# connecting two non persistent nodes
|
|
10
|
+
here ++> a;
|
|
10
11
|
}
|
|
11
12
|
}
|
|
12
13
|
|
|
14
|
+
|
|
13
15
|
walker view {
|
|
14
16
|
can run with `root entry {
|
|
15
|
-
print(
|
|
17
|
+
print(printgraph(here));
|
|
16
18
|
}
|
|
17
|
-
}
|
|
19
|
+
}
|
|
@@ -117,8 +117,8 @@ class TestJaseciPlugin(TestCase):
|
|
|
117
117
|
args=[],
|
|
118
118
|
)
|
|
119
119
|
output = self.capturedOutput.getvalue().strip()
|
|
120
|
-
self.assertEqual(output, "node a\nnode b")
|
|
121
120
|
self._del_session(session)
|
|
121
|
+
self.assertEqual(output, "node a\nnode b")
|
|
122
122
|
|
|
123
123
|
def test_get_edge(self) -> None:
|
|
124
124
|
"""Test get an edge object."""
|
|
@@ -818,6 +818,8 @@ class TestJaseciPlugin(TestCase):
|
|
|
818
818
|
)
|
|
819
819
|
self.assertEqual("None", self.capturedOutput.getvalue().strip())
|
|
820
820
|
|
|
821
|
+
self._del_session(session)
|
|
822
|
+
|
|
821
823
|
def test_traversing_save(self) -> None:
|
|
822
824
|
"""Test traversing save."""
|
|
823
825
|
global session
|
jaclang/runtimelib/utils.py
CHANGED
|
@@ -133,7 +133,7 @@ def extract_params(
|
|
|
133
133
|
include_info = []
|
|
134
134
|
exclude_info = []
|
|
135
135
|
if body.params:
|
|
136
|
-
for param in body.params
|
|
136
|
+
for param in body.params:
|
|
137
137
|
if isinstance(param, uni.KWPair) and isinstance(param.key, uni.Name):
|
|
138
138
|
key = param.key.value
|
|
139
139
|
value = param.value
|
|
@@ -153,7 +153,7 @@ def extract_params(
|
|
|
153
153
|
)
|
|
154
154
|
include_info.append((var_name, value.gen.py_ast[0]))
|
|
155
155
|
elif isinstance(value, uni.TupleVal) and value.values:
|
|
156
|
-
for i in value.values
|
|
156
|
+
for i in value.values:
|
|
157
157
|
var_name = (
|
|
158
158
|
i.right.value
|
|
159
159
|
if isinstance(i, uni.AtomTrailer)
|
|
@@ -175,7 +175,7 @@ def extract_params(
|
|
|
175
175
|
)
|
|
176
176
|
exclude_info.append((var_name, value.gen.py_ast[0]))
|
|
177
177
|
elif isinstance(value, uni.TupleVal) and value.values:
|
|
178
|
-
for i in value.values
|
|
178
|
+
for i in value.values:
|
|
179
179
|
var_name = (
|
|
180
180
|
i.right.value
|
|
181
181
|
if isinstance(i, uni.AtomTrailer)
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import from jaclang.runtimelib.machine {
|
|
1
|
+
import from jaclang.runtimelib.machine { JacMachine }
|
|
2
2
|
|
|
3
|
-
glob dynamic_module_source = """
|
|
4
|
-
import from .arch_create_util {UtilityNode}
|
|
5
3
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
here ++> UtilityNode(data=42);
|
|
10
|
-
visit [-->](`?UtilityNode);
|
|
11
|
-
}
|
|
4
|
+
glob dynamic_module_source =
|
|
5
|
+
"""
|
|
6
|
+
import from arch_create_util {UtilityNode}
|
|
12
7
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
8
|
+
walker DynamicWalker {
|
|
9
|
+
can start with entry {
|
|
10
|
+
print("DynamicWalker Started");
|
|
11
|
+
here ++> UtilityNode(data=42);
|
|
12
|
+
visit [-->](`?UtilityNode);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
def UtilityNode {
|
|
16
|
+
here.display_data();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
""";
|
|
18
20
|
|
|
19
|
-
with entry {
|
|
20
|
-
node_arch = JacMachineInterface.create_archetype_from_source(JacMachineInterface.py_get_jac_machine(),
|
|
21
|
-
dynamic_module_source,
|
|
22
|
-
module_name="dynamic_module"
|
|
23
|
-
);
|
|
24
|
-
walker_obj = JacMachineInterface.spawn_walker(JacMachineInterface.py_get_jac_machine(),
|
|
25
|
-
'DynamicWalker',
|
|
26
|
-
module_name="dynamic_module",
|
|
27
21
|
|
|
28
|
-
|
|
22
|
+
with entry {
|
|
23
|
+
node_arch =
|
|
24
|
+
JacMachine.create_archetype_from_source(
|
|
25
|
+
dynamic_module_source, module_name="dynamic_module"
|
|
26
|
+
);
|
|
27
|
+
walker_obj =
|
|
28
|
+
JacMachine.spawn_walker('DynamicWalker', module_name="dynamic_module", );
|
|
29
29
|
root spawn walker_obj;
|
|
30
30
|
}
|
|
@@ -1,18 +1,51 @@
|
|
|
1
1
|
import asyncio;
|
|
2
|
+
import from typing {Coroutine}
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
node MyNode {
|
|
5
|
+
has val:int;
|
|
6
|
+
|
|
7
|
+
can foo1 with MyWalker entry {
|
|
8
|
+
print("foo1");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async can foo2 with MyWalker entry {
|
|
12
|
+
print("foo2");
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
edge MyEdge {
|
|
17
|
+
has value:int;
|
|
7
18
|
}
|
|
8
19
|
|
|
9
|
-
async def
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
20
|
+
async def fun{
|
|
21
|
+
print("Async function");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async walker MyWalker {
|
|
25
|
+
has name:str;
|
|
26
|
+
|
|
27
|
+
async can do_print with MyNode entry {
|
|
28
|
+
print("I am here man", here);
|
|
29
|
+
visit [-->];
|
|
30
|
+
await fun();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
can foo3 with MyNode entry {
|
|
34
|
+
print("foo3");
|
|
35
|
+
}
|
|
14
36
|
}
|
|
15
37
|
|
|
16
38
|
with entry {
|
|
17
|
-
|
|
39
|
+
root ++> (node1:= MyNode(5));
|
|
40
|
+
node1 +>:MyEdge(100):+> MyNode(10);
|
|
41
|
+
node1 +>:MyEdge(200):+> MyNode(15);
|
|
42
|
+
walker1 = MyWalker("Mylife");
|
|
43
|
+
async def foo(w:W, a:A)-> None {
|
|
44
|
+
print("Let's start the task");
|
|
45
|
+
x = w spawn a;
|
|
46
|
+
print("It is Coroutine task", isinstance(x, Coroutine));
|
|
47
|
+
await x;
|
|
48
|
+
print("Coroutine task is completed");
|
|
49
|
+
}
|
|
50
|
+
asyncio.run(foo(walker1,node1));
|
|
18
51
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import asyncio;
|
|
2
|
+
|
|
3
|
+
async def say_hello(){
|
|
4
|
+
print("Hello");
|
|
5
|
+
await asyncio.sleep(1);
|
|
6
|
+
print("World!");
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async def main(){
|
|
10
|
+
await asyncio.gather(
|
|
11
|
+
say_hello(),
|
|
12
|
+
say_hello()
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
with entry {
|
|
17
|
+
asyncio.run(main());
|
|
18
|
+
}
|
|
@@ -1,23 +1,28 @@
|
|
|
1
1
|
import time;
|
|
2
|
+
import asyncio;
|
|
3
|
+
import from typing {Coroutine}
|
|
2
4
|
node A {
|
|
3
5
|
has val: int;
|
|
4
|
-
|
|
5
|
-
can do1 with W entry {
|
|
6
|
-
print("A Entry action ", self.val);
|
|
7
|
-
visit [self-->];
|
|
8
|
-
time.sleep(1);
|
|
9
|
-
}
|
|
10
6
|
}
|
|
11
7
|
|
|
12
8
|
async walker W {
|
|
13
9
|
has num: int;
|
|
10
|
+
|
|
11
|
+
async can do1 with A entry {
|
|
12
|
+
print("A Entry action ", here.val);
|
|
13
|
+
visit [here-->];
|
|
14
|
+
}
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
with entry {
|
|
17
18
|
root ++> (a1 := A(1)) ++> [a2 := A(2), a3 := A(3), a4 := A(4)];
|
|
18
|
-
w1
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
w1 = W(8);
|
|
20
|
+
async def foo(w:W, a:A)-> None {
|
|
21
|
+
print("Let's start the task");
|
|
22
|
+
x = w spawn a;
|
|
23
|
+
print("It is Coroutine task", isinstance(x, Coroutine));
|
|
24
|
+
await x;
|
|
25
|
+
print("Coroutine task is completed");
|
|
26
|
+
}
|
|
27
|
+
asyncio.run(foo(w1,a1));
|
|
28
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
node MyNode{
|
|
2
|
+
has val:int;
|
|
3
|
+
|
|
4
|
+
can do with MyWalker entry {
|
|
5
|
+
print( visitor,"from node", self);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
edge MyEdge {
|
|
10
|
+
has path:int;
|
|
11
|
+
|
|
12
|
+
can do with MyWalker entry {
|
|
13
|
+
print(visitor,"from edge",self);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
walker MyWalker {
|
|
18
|
+
can does with MyNode entry {
|
|
19
|
+
visit [edge <--];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
with entry {
|
|
24
|
+
n0 = MyNode(0);
|
|
25
|
+
n1 = MyNode(10);
|
|
26
|
+
root +>:MyEdge(0):+> n0 <+:MyEdge(1):<+ n1;
|
|
27
|
+
n1 <+:MyEdge(2):<+ MyNode(20);
|
|
28
|
+
n1 <+:MyEdge(3):<+ MyNode(30);
|
|
29
|
+
n1 <+:MyEdge(4):<+ MyNode(40);
|
|
30
|
+
MyWalker() spawn n0;
|
|
31
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
node a {
|
|
2
|
+
has val: int;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
edge Edge1 {
|
|
7
|
+
has val: int = 5;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
with entry {
|
|
12
|
+
end = root;
|
|
13
|
+
for i in range(0, 4) {
|
|
14
|
+
end ++> (end := [ a(val=i) for i in range(0, 3) ]);
|
|
15
|
+
}
|
|
16
|
+
x = [ a(val=i) for i in range(0, 3) ];
|
|
17
|
+
end = x[1];
|
|
18
|
+
for i in range(0, 8) {
|
|
19
|
+
locals()[chr(ord('b') + i)] = (values := [ a(val=j * i + 5.2 * i + 6) for j in range(0, 3) ]);
|
|
20
|
+
end ++> (end := values);
|
|
21
|
+
}
|
|
22
|
+
p = b[1];
|
|
23
|
+
for k in range(0, 10) {
|
|
24
|
+
p +>: Edge1 : val=6 :+> (p := a(val=k));
|
|
25
|
+
}
|
|
26
|
+
# b++>c;
|
|
27
|
+
# c++>b;
|
|
28
|
+
d1 = printgraph();
|
|
29
|
+
l1 = d1 |> len;
|
|
30
|
+
#generate dot for all connected with root
|
|
31
|
+
# d2=printgraph(b[1],Traverse=True,depth=20,bfs=False,node_limit=12);l2=d2|>len; #generate dot for all connected with root
|
|
32
|
+
d2 = printgraph(
|
|
33
|
+
b[1],
|
|
34
|
+
edge_type=["Edge1"],
|
|
35
|
+
depth=20,
|
|
36
|
+
traverse=True,
|
|
37
|
+
bfs=False,
|
|
38
|
+
node_limit=19
|
|
39
|
+
);
|
|
40
|
+
l2 = d2 |> len;
|
|
41
|
+
#generate dot for all connected with root
|
|
42
|
+
d3 = printgraph(b[2], edge_limit=5, depth=5);
|
|
43
|
+
l3 = d3 |> len;
|
|
44
|
+
#generate dot for all connected with b[1] node
|
|
45
|
+
d4 = printgraph(
|
|
46
|
+
b[1],
|
|
47
|
+
bfs=True,
|
|
48
|
+
edge_type=["Edge1"],
|
|
49
|
+
node_limit=100,
|
|
50
|
+
edge_limit=900,
|
|
51
|
+
depth=300
|
|
52
|
+
);
|
|
53
|
+
l4 = d4 |> len;
|
|
54
|
+
#generate dot from nodes with depth 3 connected with b[1] node
|
|
55
|
+
d5 = printgraph(b[1], node_limit=10, edge_limit=90);
|
|
56
|
+
l5 := d5 |> len;
|
|
57
|
+
#generate dot from nodes with depth 3 connected with b[1] node
|
|
58
|
+
print(
|
|
59
|
+
d1.count('a(val') == 12,
|
|
60
|
+
d1.count('#FFFFE0') == 3,
|
|
61
|
+
'Root' in d1,
|
|
62
|
+
d1.count('label=""') == 30
|
|
63
|
+
);
|
|
64
|
+
print(
|
|
65
|
+
d2.count('a(val') == 19,
|
|
66
|
+
d2.count('#F5E5FF') == 2,
|
|
67
|
+
'Edge1' not in d2,
|
|
68
|
+
d2.count('label=""') == 42
|
|
69
|
+
);
|
|
70
|
+
print(d3.count('a(val') == 6, d3.count('label=""') == 5, d3.count('#F5E5FF') == 1);
|
|
71
|
+
print(d4.count("a(val") == 25, d4.count('label=""') == 66, d4.count('#FFF0F') == 3);
|
|
72
|
+
print(d5.count("Edge1(val=6)") == 2, d5.count('label=""') == 24);
|
|
73
|
+
# print(l3<l2);
|
|
74
|
+
|
|
75
|
+
# print(d1);
|
|
76
|
+
|
|
77
|
+
# print(d2);
|
|
78
|
+
|
|
79
|
+
# print(d3);
|
|
80
|
+
|
|
81
|
+
# print(d4);
|
|
82
|
+
|
|
83
|
+
# print(printgraph(node=b[2],bfs=True,depth=3.96,edge_limit=12,node_limit=12.96));
|
|
84
|
+
|
|
85
|
+
}
|