jaclang 0.8.1__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 +21 -50
- jaclang/compiler/codeinfo.py +0 -1
- jaclang/compiler/jac.lark +12 -10
- jaclang/compiler/larkparse/jac_parser.py +2 -2
- jaclang/compiler/parser.py +18 -10
- 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 +38 -12
- jaclang/compiler/passes/main/import_pass.py +3 -11
- jaclang/compiler/passes/main/pyast_gen_pass.py +243 -592
- jaclang/compiler/passes/main/sym_tab_link_pass.py +2 -5
- jaclang/compiler/passes/main/tests/test_cfg_build_pass.py +2 -8
- 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 +237 -105
- 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 +21 -60
- jaclang/compiler/tests/fixtures/pkg_import_lib_py/__init__.py +2 -8
- jaclang/compiler/tests/fixtures/pkg_import_lib_py/sub/__init__.py +1 -5
- jaclang/compiler/tests/test_importer.py +10 -13
- jaclang/compiler/unitree.py +32 -16
- jaclang/langserve/__init__.jac +1 -1
- jaclang/langserve/engine.jac +113 -108
- jaclang/langserve/server.jac +17 -2
- jaclang/langserve/tests/server_test/test_lang_serve.py +138 -46
- jaclang/langserve/tests/server_test/utils.py +35 -9
- jaclang/langserve/tests/test_sem_tokens.py +1 -1
- jaclang/langserve/tests/test_server.py +3 -7
- jaclang/runtimelib/archetype.py +127 -5
- jaclang/runtimelib/importer.py +51 -94
- jaclang/runtimelib/machine.py +391 -268
- 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/test_jaseci.py +3 -1
- 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/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/foo.jac +14 -22
- 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/unicode_strings.jac +24 -0
- jaclang/tests/fixtures/walker_update.jac +5 -7
- jaclang/tests/test_language.py +138 -140
- jaclang/tests/test_reference.py +9 -4
- jaclang/tests/test_typecheck.py +13 -26
- jaclang/utils/lang_tools.py +7 -5
- jaclang/utils/module_resolver.py +23 -0
- {jaclang-0.8.1.dist-info → jaclang-0.8.2.dist-info}/METADATA +1 -1
- {jaclang-0.8.1.dist-info → jaclang-0.8.2.dist-info}/RECORD +72 -70
- 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/tests/fixtures/deep/deeper/__init__.jac +0 -1
- {jaclang-0.8.1.dist-info → jaclang-0.8.2.dist-info}/WHEEL +0 -0
- {jaclang-0.8.1.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
|
+
}
|
|
@@ -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
|
|
@@ -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
|
+
}
|
|
@@ -1,35 +1,32 @@
|
|
|
1
|
-
import from jaclang.runtimelib.machine {
|
|
1
|
+
import from jaclang.runtimelib.machine { JacMachine }
|
|
2
2
|
# Dynamically create a node archetype
|
|
3
|
-
glob source_code =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
3
|
+
glob source_code =
|
|
4
|
+
"""
|
|
5
|
+
node dynamic_node {
|
|
6
|
+
has value:int;
|
|
7
|
+
can print_value with entry {
|
|
8
|
+
print("Dynamic Node Value:", f'{self.value}');
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
""";
|
|
11
12
|
|
|
12
13
|
# Create a new walker archetype dynamically
|
|
13
|
-
glob walker_code =
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
14
|
+
glob walker_code =
|
|
15
|
+
"""
|
|
16
|
+
walker dynamic_walker {
|
|
17
|
+
can visit_nodes with entry {
|
|
18
|
+
visit [-->];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
""";
|
|
20
22
|
|
|
21
|
-
with entry {
|
|
22
|
-
node_arch = JacMachineInterface.create_archetype_from_source(JacMachineInterface.py_get_jac_machine(), source_code);
|
|
23
|
-
walker_arch = JacMachineInterface.create_archetype_from_source(JacMachineInterface.py_get_jac_machine(), walker_code);
|
|
24
23
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
walker_obj =
|
|
31
|
-
'dynamic_walker',
|
|
32
|
-
module_name=walker_arch.__name__
|
|
33
|
-
);
|
|
24
|
+
with entry {
|
|
25
|
+
node_arch = JacMachine.create_archetype_from_source(source_code);
|
|
26
|
+
walker_arch = JacMachine.create_archetype_from_source(walker_code);
|
|
27
|
+
node_obj =
|
|
28
|
+
JacMachine.spawn_node('dynamic_node', {'value' : 99 } , node_arch.__name__);
|
|
29
|
+
walker_obj =
|
|
30
|
+
JacMachine.spawn_walker('dynamic_walker', module_name=walker_arch.__name__);
|
|
34
31
|
node_obj spawn walker_obj;
|
|
35
32
|
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import from
|
|
2
|
-
import from
|
|
1
|
+
import from jaclang.tests.fixtures.deep.one_lev_dup { olprint }
|
|
2
|
+
import from jaclang.tests.fixtures.needs_import_dup { my_print , pyfunc }
|
|
3
|
+
|
|
3
4
|
|
|
4
5
|
with entry {
|
|
5
6
|
# print(olpyprint());
|
|
6
|
-
print(
|
|
7
|
+
print(
|
|
8
|
+
olprint()
|
|
9
|
+
);
|
|
7
10
|
print(my_print(pyfunc));
|
|
8
|
-
}
|
|
11
|
+
}
|