jaclang 0.5.18__py3-none-any.whl → 0.6.1__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 +94 -5
- jaclang/cli/cmdreg.py +18 -6
- jaclang/compiler/__init__.py +12 -5
- jaclang/compiler/absyntree.py +4 -5
- jaclang/compiler/generated/jac_parser.py +2 -2
- jaclang/compiler/jac.lark +2 -2
- jaclang/compiler/parser.py +48 -8
- jaclang/compiler/passes/main/__init__.py +3 -2
- jaclang/compiler/passes/main/access_modifier_pass.py +173 -0
- jaclang/compiler/passes/main/def_impl_match_pass.py +4 -1
- jaclang/compiler/passes/main/fuse_typeinfo_pass.py +10 -7
- jaclang/compiler/passes/main/import_pass.py +70 -40
- jaclang/compiler/passes/main/pyast_gen_pass.py +47 -83
- jaclang/compiler/passes/main/pyast_load_pass.py +136 -73
- jaclang/compiler/passes/main/pyjac_ast_link_pass.py +218 -0
- jaclang/compiler/passes/main/pyout_pass.py +14 -13
- jaclang/compiler/passes/main/registry_pass.py +8 -3
- jaclang/compiler/passes/main/schedules.py +7 -3
- jaclang/compiler/passes/main/sym_tab_build_pass.py +32 -29
- jaclang/compiler/passes/main/tests/test_import_pass.py +13 -2
- jaclang/compiler/passes/tool/jac_formatter_pass.py +83 -21
- jaclang/compiler/passes/tool/tests/test_jac_format_pass.py +11 -4
- jaclang/compiler/passes/transform.py +2 -0
- jaclang/compiler/symtable.py +10 -3
- jaclang/compiler/tests/test_importer.py +9 -0
- jaclang/compiler/workspace.py +17 -5
- jaclang/core/aott.py +43 -63
- jaclang/core/construct.py +157 -21
- jaclang/core/importer.py +77 -65
- jaclang/core/llms/__init__.py +20 -0
- jaclang/core/llms/anthropic.py +61 -0
- jaclang/core/llms/base.py +206 -0
- jaclang/core/llms/groq.py +67 -0
- jaclang/core/llms/huggingface.py +73 -0
- jaclang/core/llms/ollama.py +78 -0
- jaclang/core/llms/openai.py +61 -0
- jaclang/core/llms/togetherai.py +60 -0
- jaclang/core/llms/utils.py +9 -0
- jaclang/core/memory.py +48 -0
- jaclang/core/shelve_storage.py +55 -0
- jaclang/core/utils.py +16 -1
- jaclang/plugin/__init__.py +1 -2
- jaclang/plugin/builtin.py +1 -1
- jaclang/plugin/default.py +134 -18
- jaclang/plugin/feature.py +35 -13
- jaclang/plugin/spec.py +52 -10
- jaclang/plugin/tests/test_jaseci.py +219 -0
- jaclang/settings.py +1 -1
- jaclang/utils/helpers.py +6 -2
- jaclang/utils/treeprinter.py +14 -6
- jaclang-0.6.1.dist-info/METADATA +17 -0
- {jaclang-0.5.18.dist-info → jaclang-0.6.1.dist-info}/RECORD +55 -42
- jaclang/core/llms.py +0 -111
- jaclang-0.5.18.dist-info/METADATA +0 -7
- {jaclang-0.5.18.dist-info → jaclang-0.6.1.dist-info}/WHEEL +0 -0
- {jaclang-0.5.18.dist-info → jaclang-0.6.1.dist-info}/entry_points.txt +0 -0
- {jaclang-0.5.18.dist-info → jaclang-0.6.1.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"""Shelve storage for persistence storage of jaclang runtime object."""
|
|
2
|
+
|
|
3
|
+
import shelve
|
|
4
|
+
from uuid import UUID
|
|
5
|
+
|
|
6
|
+
from jaclang.core.construct import Architype
|
|
7
|
+
from jaclang.core.memory import Memory
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class ShelveStorage(Memory):
|
|
11
|
+
"""Shelve storage for jaclang runtime object."""
|
|
12
|
+
|
|
13
|
+
storage: shelve.Shelf | None = None
|
|
14
|
+
|
|
15
|
+
def __init__(self, session: str = "") -> None:
|
|
16
|
+
"""Init shelve storage."""
|
|
17
|
+
super().__init__()
|
|
18
|
+
if session:
|
|
19
|
+
self.connect(session)
|
|
20
|
+
|
|
21
|
+
def get_obj_from_store(self, obj_id: UUID) -> Architype | None:
|
|
22
|
+
"""Get object from the underlying store."""
|
|
23
|
+
obj = super().get_obj_from_store(obj_id)
|
|
24
|
+
if obj is None and self.storage:
|
|
25
|
+
obj = self.storage.get(str(obj_id))
|
|
26
|
+
if obj is not None:
|
|
27
|
+
self.mem[obj_id] = obj
|
|
28
|
+
|
|
29
|
+
return obj
|
|
30
|
+
|
|
31
|
+
def has_obj_in_store(self, obj_id: UUID | str) -> bool:
|
|
32
|
+
"""Check if the object exists in the underlying store."""
|
|
33
|
+
return obj_id in self.mem or (
|
|
34
|
+
str(obj_id) in self.storage if self.storage else False
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
def commit(self) -> None:
|
|
38
|
+
"""Commit changes to persistent storage."""
|
|
39
|
+
if self.storage is not None:
|
|
40
|
+
for obj_id, obj in self.save_obj_list.items():
|
|
41
|
+
self.storage[str(obj_id)] = obj
|
|
42
|
+
self.save_obj_list.clear()
|
|
43
|
+
|
|
44
|
+
def connect(self, session: str) -> None:
|
|
45
|
+
"""Connect to storage."""
|
|
46
|
+
self.session = session
|
|
47
|
+
self.storage = shelve.open(session)
|
|
48
|
+
|
|
49
|
+
def close(self) -> None:
|
|
50
|
+
"""Close the storage."""
|
|
51
|
+
super().close()
|
|
52
|
+
self.commit()
|
|
53
|
+
if self.storage:
|
|
54
|
+
self.storage.close()
|
|
55
|
+
self.storage = None
|
jaclang/core/utils.py
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
import ast as ast3
|
|
6
|
-
|
|
6
|
+
import sys
|
|
7
|
+
from contextlib import contextmanager
|
|
8
|
+
from typing import Callable, Iterator, TYPE_CHECKING
|
|
7
9
|
|
|
8
10
|
import jaclang.compiler.absyntree as ast
|
|
9
11
|
from jaclang.core.registry import SemScope
|
|
@@ -12,6 +14,19 @@ if TYPE_CHECKING:
|
|
|
12
14
|
from jaclang.core.construct import NodeAnchor, NodeArchitype
|
|
13
15
|
|
|
14
16
|
|
|
17
|
+
@contextmanager
|
|
18
|
+
def sys_path_context(path: str) -> Iterator[None]:
|
|
19
|
+
"""Add a path to sys.path temporarily."""
|
|
20
|
+
novel_path = path not in sys.path
|
|
21
|
+
try:
|
|
22
|
+
if novel_path:
|
|
23
|
+
sys.path.append(path)
|
|
24
|
+
yield
|
|
25
|
+
finally:
|
|
26
|
+
if novel_path:
|
|
27
|
+
sys.path.remove(path)
|
|
28
|
+
|
|
29
|
+
|
|
15
30
|
def collect_node_connections(
|
|
16
31
|
current_node: NodeAnchor,
|
|
17
32
|
visited_nodes: set,
|
jaclang/plugin/__init__.py
CHANGED
jaclang/plugin/builtin.py
CHANGED
|
@@ -20,9 +20,9 @@ def dotgen(
|
|
|
20
20
|
dot_file: Optional[str] = None,
|
|
21
21
|
) -> str:
|
|
22
22
|
"""Print the dot graph."""
|
|
23
|
-
from jaclang.core.construct import root
|
|
24
23
|
from jaclang.plugin.feature import pm
|
|
25
24
|
|
|
25
|
+
root = pm.hook.get_root()
|
|
26
26
|
node = node if node is not None else root
|
|
27
27
|
depth = depth if depth is not None else -1
|
|
28
28
|
traverse = traverse if traverse is not None else False
|
jaclang/plugin/default.py
CHANGED
|
@@ -7,9 +7,11 @@ import html
|
|
|
7
7
|
import os
|
|
8
8
|
import pickle
|
|
9
9
|
import types
|
|
10
|
+
from contextvars import ContextVar
|
|
10
11
|
from dataclasses import field
|
|
11
12
|
from functools import wraps
|
|
12
13
|
from typing import Any, Callable, Optional, Type, Union
|
|
14
|
+
from uuid import UUID
|
|
13
15
|
|
|
14
16
|
from jaclang.compiler.absyntree import Module
|
|
15
17
|
from jaclang.compiler.constant import EdgeDir, colors
|
|
@@ -19,7 +21,6 @@ from jaclang.core.aott import (
|
|
|
19
21
|
get_all_type_explanations,
|
|
20
22
|
get_info_types,
|
|
21
23
|
get_object_string,
|
|
22
|
-
get_reasoning_output,
|
|
23
24
|
get_type_annotation,
|
|
24
25
|
)
|
|
25
26
|
from jaclang.core.construct import (
|
|
@@ -35,10 +36,11 @@ from jaclang.core.construct import (
|
|
|
35
36
|
Root,
|
|
36
37
|
WalkerAnchor,
|
|
37
38
|
WalkerArchitype,
|
|
38
|
-
root,
|
|
39
39
|
)
|
|
40
40
|
from jaclang.core.importer import jac_importer
|
|
41
|
+
from jaclang.core.memory import Memory
|
|
41
42
|
from jaclang.core.registry import SemInfo, SemRegistry, SemScope
|
|
43
|
+
from jaclang.core.shelve_storage import ShelveStorage
|
|
42
44
|
from jaclang.core.utils import traverse_graph
|
|
43
45
|
from jaclang.plugin.feature import JacFeature as Jac
|
|
44
46
|
from jaclang.plugin.spec import T
|
|
@@ -56,11 +58,10 @@ __all__ = [
|
|
|
56
58
|
"WalkerAnchor",
|
|
57
59
|
"NodeArchitype",
|
|
58
60
|
"EdgeArchitype",
|
|
61
|
+
"Root",
|
|
59
62
|
"WalkerArchitype",
|
|
60
63
|
"Architype",
|
|
61
64
|
"DSFunc",
|
|
62
|
-
"root",
|
|
63
|
-
"Root",
|
|
64
65
|
"jac_importer",
|
|
65
66
|
"T",
|
|
66
67
|
]
|
|
@@ -69,11 +70,95 @@ __all__ = [
|
|
|
69
70
|
hookimpl = pluggy.HookimplMarker("jac")
|
|
70
71
|
|
|
71
72
|
|
|
73
|
+
class ExecutionContext:
|
|
74
|
+
"""Default Execution Context implementation."""
|
|
75
|
+
|
|
76
|
+
mem: Optional[Memory]
|
|
77
|
+
root: Optional[Root]
|
|
78
|
+
|
|
79
|
+
def __init__(self) -> None:
|
|
80
|
+
super().__init__()
|
|
81
|
+
self.mem = ShelveStorage()
|
|
82
|
+
self.root = None
|
|
83
|
+
|
|
84
|
+
def init_memory(self, session: str = "") -> None:
|
|
85
|
+
if session:
|
|
86
|
+
self.mem = ShelveStorage(session)
|
|
87
|
+
else:
|
|
88
|
+
self.mem = Memory()
|
|
89
|
+
|
|
90
|
+
def get_root(self) -> Root:
|
|
91
|
+
if self.mem is None:
|
|
92
|
+
raise ValueError("Memory not initialized")
|
|
93
|
+
|
|
94
|
+
if not self.root:
|
|
95
|
+
root = self.mem.get_obj(UUID(int=0))
|
|
96
|
+
if root is None:
|
|
97
|
+
self.root = Root()
|
|
98
|
+
self.mem.save_obj(self.root, persistent=self.root._jac_.persistent)
|
|
99
|
+
elif not isinstance(root, Root):
|
|
100
|
+
raise ValueError(f"Invalid root object: {root}")
|
|
101
|
+
else:
|
|
102
|
+
self.root = root
|
|
103
|
+
return self.root
|
|
104
|
+
|
|
105
|
+
def get_obj(self, obj_id: UUID) -> Architype | None:
|
|
106
|
+
"""Get object from memory."""
|
|
107
|
+
if self.mem is None:
|
|
108
|
+
raise ValueError("Memory not initialized")
|
|
109
|
+
|
|
110
|
+
return self.mem.get_obj(obj_id)
|
|
111
|
+
|
|
112
|
+
def save_obj(self, item: Architype, persistent: bool) -> None:
|
|
113
|
+
"""Save object to memory."""
|
|
114
|
+
if self.mem is None:
|
|
115
|
+
raise ValueError("Memory not initialized")
|
|
116
|
+
|
|
117
|
+
self.mem.save_obj(item, persistent)
|
|
118
|
+
|
|
119
|
+
def reset(self) -> None:
|
|
120
|
+
"""Reset the execution context."""
|
|
121
|
+
if self.mem:
|
|
122
|
+
self.mem.close()
|
|
123
|
+
self.mem = None
|
|
124
|
+
self.root = None
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
ExecContext: ContextVar[ExecutionContext | None] = ContextVar(
|
|
128
|
+
"ExecutionContext", default=None
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
|
|
72
132
|
class JacFeatureDefaults:
|
|
73
133
|
"""Jac Feature."""
|
|
74
134
|
|
|
75
135
|
pm = pluggy.PluginManager("jac")
|
|
76
136
|
|
|
137
|
+
@staticmethod
|
|
138
|
+
@hookimpl
|
|
139
|
+
def context(session: str = "") -> ExecutionContext:
|
|
140
|
+
"""Get the execution context."""
|
|
141
|
+
ctx = ExecContext.get()
|
|
142
|
+
if ctx is None:
|
|
143
|
+
ctx = ExecutionContext()
|
|
144
|
+
ExecContext.set(ctx)
|
|
145
|
+
return ctx
|
|
146
|
+
|
|
147
|
+
@staticmethod
|
|
148
|
+
@hookimpl
|
|
149
|
+
def reset_context() -> None:
|
|
150
|
+
"""Reset the execution context."""
|
|
151
|
+
ctx = ExecContext.get()
|
|
152
|
+
if ctx:
|
|
153
|
+
ctx.reset()
|
|
154
|
+
ExecContext.set(None)
|
|
155
|
+
|
|
156
|
+
@staticmethod
|
|
157
|
+
@hookimpl
|
|
158
|
+
def memory_hook() -> Memory | None:
|
|
159
|
+
"""Return the memory hook."""
|
|
160
|
+
return Jac.context().mem
|
|
161
|
+
|
|
77
162
|
@staticmethod
|
|
78
163
|
@hookimpl
|
|
79
164
|
def make_architype(
|
|
@@ -378,6 +463,12 @@ class JacFeatureDefaults:
|
|
|
378
463
|
conn_edge = edge_spec()
|
|
379
464
|
edges.append(conn_edge)
|
|
380
465
|
i._jac_.connect_node(j, conn_edge)
|
|
466
|
+
|
|
467
|
+
if i._jac_.persistent or j._jac_.persistent:
|
|
468
|
+
conn_edge.save()
|
|
469
|
+
j.save()
|
|
470
|
+
i.save()
|
|
471
|
+
|
|
381
472
|
return right if not edges_only else edges
|
|
382
473
|
|
|
383
474
|
@staticmethod
|
|
@@ -428,9 +519,15 @@ class JacFeatureDefaults:
|
|
|
428
519
|
|
|
429
520
|
@staticmethod
|
|
430
521
|
@hookimpl
|
|
431
|
-
def get_root() ->
|
|
522
|
+
def get_root() -> Root:
|
|
432
523
|
"""Jac's assign comprehension feature."""
|
|
433
|
-
return
|
|
524
|
+
return Jac.context().get_root()
|
|
525
|
+
|
|
526
|
+
@staticmethod
|
|
527
|
+
@hookimpl
|
|
528
|
+
def get_root_type() -> Type[Root]:
|
|
529
|
+
"""Jac's root getter."""
|
|
530
|
+
return Root
|
|
434
531
|
|
|
435
532
|
@staticmethod
|
|
436
533
|
@hookimpl
|
|
@@ -587,11 +684,18 @@ class JacFeatureDefaults:
|
|
|
587
684
|
_scope = SemScope.get_scope_from_str(scope)
|
|
588
685
|
assert _scope is not None
|
|
589
686
|
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
687
|
+
method = model_params.pop("method") if "method" in model_params else "Normal"
|
|
688
|
+
available_methods = model.MTLLM_METHOD_PROMPTS.keys()
|
|
689
|
+
assert (
|
|
690
|
+
method in available_methods
|
|
691
|
+
), f"Invalid method: {method}. Select from {available_methods}"
|
|
692
|
+
|
|
693
|
+
context = (
|
|
694
|
+
"\n".join(model_params.pop("context")) if "context" in model_params else ""
|
|
695
|
+
)
|
|
593
696
|
|
|
594
697
|
type_collector: list = []
|
|
698
|
+
incl_info = [x for x in incl_info if not isinstance(x[1], type)]
|
|
595
699
|
information, collected_types = get_info_types(_scope, mod_registry, incl_info)
|
|
596
700
|
type_collector.extend(collected_types)
|
|
597
701
|
inputs_information_list = []
|
|
@@ -605,22 +709,34 @@ class JacFeatureDefaults:
|
|
|
605
709
|
|
|
606
710
|
output_information = f"{outputs[0]} ({outputs[1]})"
|
|
607
711
|
type_collector.extend(extract_non_primary_type(outputs[1]))
|
|
712
|
+
output_type_explanations = "\n".join(
|
|
713
|
+
list(
|
|
714
|
+
get_all_type_explanations(
|
|
715
|
+
extract_non_primary_type(outputs[1]), mod_registry
|
|
716
|
+
).values()
|
|
717
|
+
)
|
|
718
|
+
)
|
|
608
719
|
|
|
609
720
|
type_explanations_list = list(
|
|
610
721
|
get_all_type_explanations(type_collector, mod_registry).values()
|
|
611
722
|
)
|
|
612
723
|
type_explanations = "\n".join(type_explanations_list)
|
|
613
724
|
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
725
|
+
meaning_out = aott_raise(
|
|
726
|
+
model=model,
|
|
727
|
+
information=information,
|
|
728
|
+
inputs_information=inputs_information,
|
|
729
|
+
output_information=output_information,
|
|
730
|
+
type_explanations=type_explanations,
|
|
731
|
+
action=action,
|
|
732
|
+
context=context,
|
|
733
|
+
method=method,
|
|
734
|
+
tools=[],
|
|
735
|
+
model_params=model_params,
|
|
736
|
+
)
|
|
737
|
+
output = model.resolve_output(
|
|
738
|
+
meaning_out, outputs[0], outputs[1], output_type_explanations
|
|
621
739
|
)
|
|
622
|
-
meaning_out = model.__infer__(meaning_in, **model_params)
|
|
623
|
-
reasoning, output = get_reasoning_output(meaning_out)
|
|
624
740
|
return output
|
|
625
741
|
|
|
626
742
|
|
jaclang/plugin/feature.py
CHANGED
|
@@ -3,18 +3,22 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
import types
|
|
6
|
-
from typing import Any, Callable, Optional,
|
|
6
|
+
from typing import Any, Callable, Optional, TYPE_CHECKING, Type, Union
|
|
7
7
|
|
|
8
8
|
from jaclang.compiler.absyntree import Module
|
|
9
|
-
from jaclang.core.construct import (
|
|
10
|
-
Architype,
|
|
11
|
-
EdgeArchitype,
|
|
12
|
-
NodeArchitype,
|
|
13
|
-
Root,
|
|
14
|
-
WalkerArchitype,
|
|
15
|
-
)
|
|
16
9
|
from jaclang.plugin.spec import JacBuiltin, JacCmdSpec, JacFeatureSpec, T
|
|
17
10
|
|
|
11
|
+
if TYPE_CHECKING:
|
|
12
|
+
from jaclang.core.construct import (
|
|
13
|
+
Architype,
|
|
14
|
+
EdgeArchitype,
|
|
15
|
+
NodeArchitype,
|
|
16
|
+
WalkerArchitype,
|
|
17
|
+
Root,
|
|
18
|
+
)
|
|
19
|
+
from jaclang.plugin.default import ExecutionContext
|
|
20
|
+
from jaclang.core.memory import Memory
|
|
21
|
+
|
|
18
22
|
|
|
19
23
|
import pluggy
|
|
20
24
|
|
|
@@ -28,10 +32,23 @@ class JacFeature:
|
|
|
28
32
|
"""Jac Feature."""
|
|
29
33
|
|
|
30
34
|
import abc
|
|
31
|
-
from jaclang.plugin.spec import DSFunc
|
|
32
35
|
from jaclang.compiler.constant import EdgeDir
|
|
36
|
+
from jaclang.plugin.spec import DSFunc
|
|
37
|
+
|
|
38
|
+
@staticmethod
|
|
39
|
+
def context(session: str = "") -> ExecutionContext:
|
|
40
|
+
"""Create execution context."""
|
|
41
|
+
return pm.hook.context(session=session)
|
|
42
|
+
|
|
43
|
+
@staticmethod
|
|
44
|
+
def reset_context() -> None:
|
|
45
|
+
"""Reset execution context."""
|
|
46
|
+
return pm.hook.reset_context()
|
|
33
47
|
|
|
34
|
-
|
|
48
|
+
@staticmethod
|
|
49
|
+
def memory_hook() -> Memory | None:
|
|
50
|
+
"""Create memory abstraction."""
|
|
51
|
+
return pm.hook.memory_hook()
|
|
35
52
|
|
|
36
53
|
@staticmethod
|
|
37
54
|
def make_architype(
|
|
@@ -82,7 +99,7 @@ class JacFeature:
|
|
|
82
99
|
mdl_alias: Optional[str] = None,
|
|
83
100
|
override_name: Optional[str] = None,
|
|
84
101
|
mod_bundle: Optional[Module] = None,
|
|
85
|
-
lng: Optional[str] =
|
|
102
|
+
lng: Optional[str] = "jac",
|
|
86
103
|
items: Optional[dict[str, Union[str, bool]]] = None,
|
|
87
104
|
) -> Optional[types.ModuleType]:
|
|
88
105
|
"""Core Import Process."""
|
|
@@ -218,10 +235,15 @@ class JacFeature:
|
|
|
218
235
|
return pm.hook.assign_compr(target=target, attr_val=attr_val)
|
|
219
236
|
|
|
220
237
|
@staticmethod
|
|
221
|
-
def get_root() ->
|
|
222
|
-
"""Jac's
|
|
238
|
+
def get_root() -> Root:
|
|
239
|
+
"""Jac's root getter."""
|
|
223
240
|
return pm.hook.get_root()
|
|
224
241
|
|
|
242
|
+
@staticmethod
|
|
243
|
+
def get_root_type() -> Type[Root]:
|
|
244
|
+
"""Jac's root type getter."""
|
|
245
|
+
return pm.hook.get_root_type()
|
|
246
|
+
|
|
225
247
|
@staticmethod
|
|
226
248
|
def build_edge(
|
|
227
249
|
is_undirected: bool,
|
jaclang/plugin/spec.py
CHANGED
|
@@ -3,17 +3,21 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
import types
|
|
6
|
-
from
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from typing import Any, Callable, Optional, TYPE_CHECKING, Type, TypeVar, Union
|
|
7
8
|
|
|
8
9
|
from jaclang.compiler.absyntree import Module
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
|
|
11
|
+
if TYPE_CHECKING:
|
|
12
|
+
from jaclang.core.construct import EdgeArchitype, NodeArchitype
|
|
13
|
+
from jaclang.plugin.default import (
|
|
14
|
+
Architype,
|
|
15
|
+
EdgeDir,
|
|
16
|
+
ExecutionContext,
|
|
17
|
+
WalkerArchitype,
|
|
18
|
+
Root,
|
|
19
|
+
)
|
|
20
|
+
from jaclang.core.memory import Memory
|
|
17
21
|
|
|
18
22
|
import pluggy
|
|
19
23
|
|
|
@@ -22,9 +26,41 @@ hookspec = pluggy.HookspecMarker("jac")
|
|
|
22
26
|
T = TypeVar("T")
|
|
23
27
|
|
|
24
28
|
|
|
29
|
+
# TODO: DSFunc should be moved into jaclang/core
|
|
30
|
+
@dataclass(eq=False)
|
|
31
|
+
class DSFunc:
|
|
32
|
+
"""Data Spatial Function."""
|
|
33
|
+
|
|
34
|
+
name: str
|
|
35
|
+
trigger: type | types.UnionType | tuple[type | types.UnionType, ...] | None
|
|
36
|
+
func: Callable[[Any, Any], Any] | None = None
|
|
37
|
+
|
|
38
|
+
def resolve(self, cls: type) -> None:
|
|
39
|
+
"""Resolve the function."""
|
|
40
|
+
self.func = getattr(cls, self.name)
|
|
41
|
+
|
|
42
|
+
|
|
25
43
|
class JacFeatureSpec:
|
|
26
44
|
"""Jac Feature."""
|
|
27
45
|
|
|
46
|
+
@staticmethod
|
|
47
|
+
@hookspec(firstresult=True)
|
|
48
|
+
def context(session: str = "") -> ExecutionContext:
|
|
49
|
+
"""Get the execution context."""
|
|
50
|
+
raise NotImplementedError
|
|
51
|
+
|
|
52
|
+
@staticmethod
|
|
53
|
+
@hookspec(firstresult=True)
|
|
54
|
+
def reset_context() -> None:
|
|
55
|
+
"""Reset the execution context."""
|
|
56
|
+
raise NotImplementedError
|
|
57
|
+
|
|
58
|
+
@staticmethod
|
|
59
|
+
@hookspec(firstresult=True)
|
|
60
|
+
def memory_hook() -> Memory | None:
|
|
61
|
+
"""Create memory abstraction."""
|
|
62
|
+
raise NotImplementedError
|
|
63
|
+
|
|
28
64
|
@staticmethod
|
|
29
65
|
@hookspec(firstresult=True)
|
|
30
66
|
def make_architype(
|
|
@@ -198,7 +234,13 @@ class JacFeatureSpec:
|
|
|
198
234
|
|
|
199
235
|
@staticmethod
|
|
200
236
|
@hookspec(firstresult=True)
|
|
201
|
-
def get_root() ->
|
|
237
|
+
def get_root() -> Root:
|
|
238
|
+
"""Jac's root getter."""
|
|
239
|
+
raise NotImplementedError
|
|
240
|
+
|
|
241
|
+
@staticmethod
|
|
242
|
+
@hookspec(firstresult=True)
|
|
243
|
+
def get_root_type() -> Type[Root]:
|
|
202
244
|
"""Jac's root getter."""
|
|
203
245
|
raise NotImplementedError
|
|
204
246
|
|