jaclang 0.7.14__py3-none-any.whl → 0.7.17__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 +147 -77
- jaclang/cli/cmdreg.py +9 -12
- jaclang/compiler/__init__.py +19 -53
- jaclang/compiler/absyntree.py +94 -16
- jaclang/compiler/constant.py +8 -8
- jaclang/compiler/jac.lark +4 -3
- jaclang/compiler/parser.py +41 -25
- jaclang/compiler/passes/ir_pass.py +4 -13
- 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 +155 -54
- jaclang/compiler/passes/main/import_pass.py +99 -75
- jaclang/compiler/passes/main/py_collect_dep_pass.py +70 -0
- jaclang/compiler/passes/main/pyast_gen_pass.py +328 -565
- jaclang/compiler/passes/main/pyast_load_pass.py +33 -6
- jaclang/compiler/passes/main/pyjac_ast_link_pass.py +7 -0
- jaclang/compiler/passes/main/registry_pass.py +37 -3
- jaclang/compiler/passes/main/schedules.py +9 -2
- jaclang/compiler/passes/main/sym_tab_build_pass.py +10 -6
- jaclang/compiler/passes/main/tests/__init__.py +1 -1
- 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 +22 -5
- jaclang/compiler/passes/tool/jac_formatter_pass.py +135 -89
- jaclang/compiler/passes/tool/tests/fixtures/corelib.jac +37 -41
- jaclang/compiler/passes/tool/tests/fixtures/corelib_fmt.jac +37 -42
- jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/access_mod_check.jac +27 -0
- jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/architype_test.jac +13 -0
- jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/comment_alignment.jac +11 -0
- jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/comments.jac +13 -0
- jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/decorator_stack.jac +37 -0
- jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/esc_keywords.jac +5 -0
- jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/long_names.jac +19 -0
- jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/triple_quoted_string.jac +6 -0
- jaclang/compiler/passes/tool/tests/test_jac_format_pass.py +11 -0
- jaclang/compiler/passes/tool/tests/test_unparse_validate.py +33 -39
- jaclang/compiler/passes/transform.py +4 -0
- jaclang/compiler/passes/utils/mypy_ast_build.py +45 -0
- jaclang/compiler/semtable.py +31 -7
- jaclang/compiler/symtable.py +16 -11
- jaclang/compiler/tests/test_importer.py +25 -10
- jaclang/langserve/engine.py +104 -118
- jaclang/langserve/sem_manager.py +379 -0
- jaclang/langserve/server.py +24 -11
- jaclang/langserve/tests/fixtures/base_module_structure.jac +27 -6
- jaclang/langserve/tests/fixtures/circle.jac +3 -3
- jaclang/langserve/tests/fixtures/circle_err.jac +3 -3
- jaclang/langserve/tests/fixtures/circle_pure.test.jac +3 -3
- jaclang/langserve/tests/fixtures/import_include_statements.jac +1 -1
- jaclang/langserve/tests/fixtures/rename.jac +30 -0
- jaclang/langserve/tests/test_sem_tokens.py +277 -0
- jaclang/langserve/tests/test_server.py +287 -17
- jaclang/langserve/utils.py +184 -98
- jaclang/plugin/builtin.py +1 -1
- jaclang/plugin/default.py +288 -92
- jaclang/plugin/feature.py +65 -27
- jaclang/plugin/spec.py +62 -23
- jaclang/plugin/tests/fixtures/other_root_access.jac +82 -0
- jaclang/plugin/tests/test_jaseci.py +414 -42
- jaclang/runtimelib/architype.py +650 -0
- jaclang/{core → runtimelib}/constructs.py +5 -8
- jaclang/{core → runtimelib}/context.py +86 -59
- jaclang/runtimelib/importer.py +361 -0
- jaclang/runtimelib/machine.py +158 -0
- jaclang/runtimelib/memory.py +158 -0
- jaclang/{core → runtimelib}/utils.py +30 -15
- jaclang/settings.py +5 -4
- jaclang/tests/fixtures/abc.jac +3 -3
- 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/baddy.test.jac +3 -0
- jaclang/tests/fixtures/bar.jac +34 -0
- jaclang/tests/fixtures/byllmissue.jac +1 -5
- jaclang/tests/fixtures/chandra_bugs2.jac +11 -10
- jaclang/tests/fixtures/cls_method.jac +41 -0
- jaclang/tests/fixtures/dblhello.jac +6 -0
- jaclang/tests/fixtures/deep/one_lev.jac +3 -3
- jaclang/tests/fixtures/deep/one_lev_dup.jac +2 -3
- jaclang/tests/fixtures/deep_import_mods.jac +13 -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/err.impl.jac +3 -0
- jaclang/tests/fixtures/err.jac +4 -2
- jaclang/tests/fixtures/err_runtime.jac +15 -0
- jaclang/tests/fixtures/foo.jac +43 -0
- jaclang/tests/fixtures/gendot_bubble_sort.jac +1 -1
- jaclang/tests/fixtures/hello.jac +4 -0
- jaclang/tests/fixtures/impl_grab.impl.jac +2 -1
- jaclang/tests/fixtures/impl_grab.jac +4 -1
- jaclang/tests/fixtures/import.jac +9 -0
- jaclang/tests/fixtures/index_slice.jac +30 -0
- jaclang/tests/fixtures/jp_importer_auto.jac +14 -0
- jaclang/tests/fixtures/maxfail_run_test.jac +4 -4
- jaclang/tests/fixtures/needs_import.jac +2 -2
- jaclang/tests/fixtures/pyfunc_1.py +1 -1
- jaclang/tests/fixtures/pyfunc_2.py +5 -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/fixtures/registry.jac +9 -0
- jaclang/tests/fixtures/run_test.jac +4 -4
- jaclang/tests/fixtures/semstr.jac +1 -4
- jaclang/tests/fixtures/simple_archs.jac +1 -1
- jaclang/tests/test_cli.py +109 -3
- jaclang/tests/test_language.py +170 -68
- jaclang/tests/test_reference.py +2 -3
- jaclang/utils/helpers.py +45 -21
- jaclang/utils/test.py +9 -0
- jaclang/utils/treeprinter.py +30 -7
- {jaclang-0.7.14.dist-info → jaclang-0.7.17.dist-info}/METADATA +3 -2
- {jaclang-0.7.14.dist-info → jaclang-0.7.17.dist-info}/RECORD +126 -90
- jaclang/core/architype.py +0 -502
- jaclang/core/importer.py +0 -344
- jaclang/core/memory.py +0 -99
- jaclang/tests/fixtures/aott_raise.jac +0 -25
- jaclang/tests/fixtures/package_import.jac +0 -6
- /jaclang/{core → runtimelib}/__init__.py +0 -0
- /jaclang/{core → runtimelib}/test.py +0 -0
- {jaclang-0.7.14.dist-info → jaclang-0.7.17.dist-info}/WHEEL +0 -0
- {jaclang-0.7.14.dist-info → jaclang-0.7.17.dist-info}/entry_points.txt +0 -0
jaclang/plugin/feature.py
CHANGED
|
@@ -2,21 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
+
import ast as ast3
|
|
5
6
|
import types
|
|
6
|
-
from typing import Any, Callable, Optional, Type, TypeAlias, Union
|
|
7
|
+
from typing import Any, Callable, Mapping, Optional, Sequence, Type, TypeAlias, Union
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
from jaclang.
|
|
9
|
+
import jaclang.compiler.absyntree as ast
|
|
10
|
+
from jaclang.compiler.passes.main.pyast_gen_pass import PyastGenPass
|
|
11
|
+
from jaclang.plugin.spec import JacBuiltin, JacCmdSpec, JacFeatureSpec, P, T
|
|
12
|
+
from jaclang.runtimelib.constructs import (
|
|
10
13
|
Architype,
|
|
11
14
|
EdgeArchitype,
|
|
12
|
-
|
|
15
|
+
NodeAnchor,
|
|
13
16
|
NodeArchitype,
|
|
14
17
|
Root,
|
|
15
18
|
WalkerArchitype,
|
|
16
19
|
)
|
|
17
|
-
from jaclang.
|
|
18
|
-
from jaclang.plugin.spec import JacBuiltin, JacCmdSpec, JacFeatureSpec, T
|
|
19
|
-
|
|
20
|
+
from jaclang.runtimelib.context import ExecutionContext
|
|
20
21
|
|
|
21
22
|
import pluggy
|
|
22
23
|
|
|
@@ -29,10 +30,11 @@ pm.add_hookspecs(JacBuiltin)
|
|
|
29
30
|
class JacFeature:
|
|
30
31
|
"""Jac Feature."""
|
|
31
32
|
|
|
32
|
-
import
|
|
33
|
-
from jaclang.
|
|
34
|
-
from jaclang.core.constructs import DSFunc
|
|
33
|
+
from jaclang.compiler.constant import EdgeDir as EdgeDirType
|
|
34
|
+
from jaclang.runtimelib.constructs import DSFunc as DSFuncType
|
|
35
35
|
|
|
36
|
+
EdgeDir: TypeAlias = EdgeDirType
|
|
37
|
+
DSFunc: TypeAlias = DSFuncType
|
|
36
38
|
RootType: TypeAlias = Root
|
|
37
39
|
Obj: TypeAlias = Architype
|
|
38
40
|
Node: TypeAlias = NodeArchitype
|
|
@@ -40,19 +42,9 @@ class JacFeature:
|
|
|
40
42
|
Walker: TypeAlias = WalkerArchitype
|
|
41
43
|
|
|
42
44
|
@staticmethod
|
|
43
|
-
def
|
|
44
|
-
"""
|
|
45
|
-
return pm.hook.
|
|
46
|
-
|
|
47
|
-
@staticmethod
|
|
48
|
-
def reset_context() -> None:
|
|
49
|
-
"""Reset execution context."""
|
|
50
|
-
return pm.hook.reset_context()
|
|
51
|
-
|
|
52
|
-
@staticmethod
|
|
53
|
-
def memory_hook() -> Memory | None:
|
|
54
|
-
"""Create memory abstraction."""
|
|
55
|
-
return pm.hook.memory_hook()
|
|
45
|
+
def get_context() -> ExecutionContext:
|
|
46
|
+
"""Get current execution context."""
|
|
47
|
+
return pm.hook.get_context()
|
|
56
48
|
|
|
57
49
|
@staticmethod
|
|
58
50
|
def make_architype(
|
|
@@ -94,6 +86,13 @@ class JacFeature:
|
|
|
94
86
|
"""Create a walker architype."""
|
|
95
87
|
return pm.hook.make_walker(on_entry=on_entry, on_exit=on_exit)
|
|
96
88
|
|
|
89
|
+
@staticmethod
|
|
90
|
+
def impl_patch_filename(
|
|
91
|
+
file_loc: str,
|
|
92
|
+
) -> Callable[[Callable[P, T]], Callable[P, T]]:
|
|
93
|
+
"""Update impl file location."""
|
|
94
|
+
return pm.hook.impl_patch_filename(file_loc=file_loc)
|
|
95
|
+
|
|
97
96
|
@staticmethod
|
|
98
97
|
def jac_import(
|
|
99
98
|
target: str,
|
|
@@ -102,9 +101,9 @@ class JacFeature:
|
|
|
102
101
|
cachable: bool = True,
|
|
103
102
|
mdl_alias: Optional[str] = None,
|
|
104
103
|
override_name: Optional[str] = None,
|
|
105
|
-
mod_bundle: Optional[Module | str] = None,
|
|
106
104
|
lng: Optional[str] = "jac",
|
|
107
105
|
items: Optional[dict[str, Union[str, Optional[str]]]] = None,
|
|
106
|
+
reload_module: Optional[bool] = False,
|
|
108
107
|
) -> tuple[types.ModuleType, ...]:
|
|
109
108
|
"""Core Import Process."""
|
|
110
109
|
return pm.hook.jac_import(
|
|
@@ -114,9 +113,9 @@ class JacFeature:
|
|
|
114
113
|
cachable=cachable,
|
|
115
114
|
mdl_alias=mdl_alias,
|
|
116
115
|
override_name=override_name,
|
|
117
|
-
mod_bundle=mod_bundle,
|
|
118
116
|
lng=lng,
|
|
119
117
|
items=items,
|
|
118
|
+
reload_module=reload_module,
|
|
120
119
|
)
|
|
121
120
|
|
|
122
121
|
@staticmethod
|
|
@@ -217,7 +216,7 @@ class JacFeature:
|
|
|
217
216
|
def connect(
|
|
218
217
|
left: NodeArchitype | list[NodeArchitype],
|
|
219
218
|
right: NodeArchitype | list[NodeArchitype],
|
|
220
|
-
edge_spec: Callable[[], EdgeArchitype],
|
|
219
|
+
edge_spec: Callable[[NodeAnchor, NodeAnchor], EdgeArchitype],
|
|
221
220
|
edges_only: bool = False,
|
|
222
221
|
) -> list[NodeArchitype] | list[EdgeArchitype]:
|
|
223
222
|
"""Jac's connect operator feature.
|
|
@@ -265,7 +264,7 @@ class JacFeature:
|
|
|
265
264
|
is_undirected: bool,
|
|
266
265
|
conn_type: Optional[Type[EdgeArchitype] | EdgeArchitype],
|
|
267
266
|
conn_assign: Optional[tuple[tuple, tuple]],
|
|
268
|
-
) -> Callable[[], EdgeArchitype]:
|
|
267
|
+
) -> Callable[[NodeAnchor, NodeAnchor], EdgeArchitype]:
|
|
269
268
|
"""Jac's root getter."""
|
|
270
269
|
return pm.hook.build_edge(
|
|
271
270
|
is_undirected=is_undirected, conn_type=conn_type, conn_assign=conn_assign
|
|
@@ -301,6 +300,8 @@ class JacFeature:
|
|
|
301
300
|
inputs: list[tuple[str, str, str, Any]],
|
|
302
301
|
outputs: tuple,
|
|
303
302
|
action: str,
|
|
303
|
+
_globals: dict,
|
|
304
|
+
_locals: Mapping,
|
|
304
305
|
) -> Any: # noqa: ANN401
|
|
305
306
|
"""Jac's with_llm feature."""
|
|
306
307
|
return pm.hook.with_llm(
|
|
@@ -313,8 +314,45 @@ class JacFeature:
|
|
|
313
314
|
inputs=inputs,
|
|
314
315
|
outputs=outputs,
|
|
315
316
|
action=action,
|
|
317
|
+
_globals=_globals,
|
|
318
|
+
_locals=_locals,
|
|
316
319
|
)
|
|
317
320
|
|
|
321
|
+
@staticmethod
|
|
322
|
+
def gen_llm_body(_pass: PyastGenPass, node: ast.Ability) -> list[ast3.AST]:
|
|
323
|
+
"""Generate the by LLM body."""
|
|
324
|
+
return pm.hook.gen_llm_body(_pass=_pass, node=node)
|
|
325
|
+
|
|
326
|
+
@staticmethod
|
|
327
|
+
def by_llm_call(
|
|
328
|
+
_pass: PyastGenPass,
|
|
329
|
+
model: ast3.AST,
|
|
330
|
+
model_params: dict[str, ast.Expr],
|
|
331
|
+
scope: ast3.AST,
|
|
332
|
+
inputs: Sequence[Optional[ast3.AST]],
|
|
333
|
+
outputs: Sequence[Optional[ast3.AST]] | ast3.Call,
|
|
334
|
+
action: Optional[ast3.AST],
|
|
335
|
+
include_info: list[tuple[str, ast3.AST]],
|
|
336
|
+
exclude_info: list[tuple[str, ast3.AST]],
|
|
337
|
+
) -> ast3.Call:
|
|
338
|
+
"""Return the LLM Call, e.g. _Jac.with_llm()."""
|
|
339
|
+
return pm.hook.by_llm_call(
|
|
340
|
+
_pass=_pass,
|
|
341
|
+
model=model,
|
|
342
|
+
model_params=model_params,
|
|
343
|
+
scope=scope,
|
|
344
|
+
inputs=inputs,
|
|
345
|
+
outputs=outputs,
|
|
346
|
+
action=action,
|
|
347
|
+
include_info=include_info,
|
|
348
|
+
exclude_info=exclude_info,
|
|
349
|
+
)
|
|
350
|
+
|
|
351
|
+
@staticmethod
|
|
352
|
+
def get_by_llm_call_args(_pass: PyastGenPass, node: ast.FuncCall) -> dict:
|
|
353
|
+
"""Get the by LLM call args."""
|
|
354
|
+
return pm.hook.get_by_llm_call_args(_pass=_pass, node=node)
|
|
355
|
+
|
|
318
356
|
|
|
319
357
|
class JacCmd:
|
|
320
358
|
"""Jac CLI command."""
|
jaclang/plugin/spec.py
CHANGED
|
@@ -2,28 +2,41 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
+
import ast as ast3
|
|
5
6
|
import types
|
|
6
|
-
from typing import
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
from typing import (
|
|
8
|
+
Any,
|
|
9
|
+
Callable,
|
|
10
|
+
Mapping,
|
|
11
|
+
Optional,
|
|
12
|
+
ParamSpec,
|
|
13
|
+
Sequence,
|
|
14
|
+
TYPE_CHECKING,
|
|
15
|
+
Type,
|
|
16
|
+
TypeVar,
|
|
17
|
+
Union,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
import jaclang.compiler.absyntree as ast
|
|
21
|
+
from jaclang.compiler.passes.main.pyast_gen_pass import PyastGenPass
|
|
9
22
|
|
|
10
23
|
if TYPE_CHECKING:
|
|
11
|
-
from jaclang.core.constructs import EdgeArchitype, NodeArchitype
|
|
12
24
|
from jaclang.plugin.default import (
|
|
13
25
|
Architype,
|
|
14
26
|
EdgeDir,
|
|
15
|
-
ExecutionContext,
|
|
16
27
|
WalkerArchitype,
|
|
17
28
|
Root,
|
|
18
29
|
DSFunc,
|
|
19
30
|
)
|
|
20
|
-
from jaclang.
|
|
31
|
+
from jaclang.runtimelib.constructs import EdgeArchitype, NodeAnchor, NodeArchitype
|
|
32
|
+
from jaclang.runtimelib.context import ExecutionContext
|
|
21
33
|
|
|
22
34
|
import pluggy
|
|
23
35
|
|
|
24
36
|
hookspec = pluggy.HookspecMarker("jac")
|
|
25
37
|
|
|
26
38
|
T = TypeVar("T")
|
|
39
|
+
P = ParamSpec("P")
|
|
27
40
|
|
|
28
41
|
|
|
29
42
|
class JacFeatureSpec:
|
|
@@ -31,20 +44,8 @@ class JacFeatureSpec:
|
|
|
31
44
|
|
|
32
45
|
@staticmethod
|
|
33
46
|
@hookspec(firstresult=True)
|
|
34
|
-
def
|
|
35
|
-
"""Get
|
|
36
|
-
raise NotImplementedError
|
|
37
|
-
|
|
38
|
-
@staticmethod
|
|
39
|
-
@hookspec(firstresult=True)
|
|
40
|
-
def reset_context() -> None:
|
|
41
|
-
"""Reset the execution context."""
|
|
42
|
-
raise NotImplementedError
|
|
43
|
-
|
|
44
|
-
@staticmethod
|
|
45
|
-
@hookspec(firstresult=True)
|
|
46
|
-
def memory_hook() -> Memory | None:
|
|
47
|
-
"""Create memory abstraction."""
|
|
47
|
+
def get_context() -> ExecutionContext:
|
|
48
|
+
"""Get current execution context."""
|
|
48
49
|
raise NotImplementedError
|
|
49
50
|
|
|
50
51
|
@staticmethod
|
|
@@ -90,6 +91,14 @@ class JacFeatureSpec:
|
|
|
90
91
|
"""Create a walker architype."""
|
|
91
92
|
raise NotImplementedError
|
|
92
93
|
|
|
94
|
+
@staticmethod
|
|
95
|
+
@hookspec(firstresult=True)
|
|
96
|
+
def impl_patch_filename(
|
|
97
|
+
file_loc: str,
|
|
98
|
+
) -> Callable[[Callable[P, T]], Callable[P, T]]:
|
|
99
|
+
"""Update impl file location."""
|
|
100
|
+
raise NotImplementedError
|
|
101
|
+
|
|
93
102
|
@staticmethod
|
|
94
103
|
@hookspec(firstresult=True)
|
|
95
104
|
def jac_import(
|
|
@@ -99,9 +108,9 @@ class JacFeatureSpec:
|
|
|
99
108
|
cachable: bool,
|
|
100
109
|
mdl_alias: Optional[str],
|
|
101
110
|
override_name: Optional[str],
|
|
102
|
-
mod_bundle: Optional[Module | str],
|
|
103
111
|
lng: Optional[str],
|
|
104
112
|
items: Optional[dict[str, Union[str, Optional[str]]]],
|
|
113
|
+
reload_module: Optional[bool],
|
|
105
114
|
) -> tuple[types.ModuleType, ...]:
|
|
106
115
|
"""Core Import Process."""
|
|
107
116
|
raise NotImplementedError
|
|
@@ -202,7 +211,7 @@ class JacFeatureSpec:
|
|
|
202
211
|
def connect(
|
|
203
212
|
left: NodeArchitype | list[NodeArchitype],
|
|
204
213
|
right: NodeArchitype | list[NodeArchitype],
|
|
205
|
-
edge_spec: Callable[[], EdgeArchitype],
|
|
214
|
+
edge_spec: Callable[[NodeAnchor, NodeAnchor], EdgeArchitype],
|
|
206
215
|
edges_only: bool,
|
|
207
216
|
) -> list[NodeArchitype] | list[EdgeArchitype]:
|
|
208
217
|
"""Jac's connect operator feature.
|
|
@@ -248,7 +257,7 @@ class JacFeatureSpec:
|
|
|
248
257
|
is_undirected: bool,
|
|
249
258
|
conn_type: Optional[Type[EdgeArchitype] | EdgeArchitype],
|
|
250
259
|
conn_assign: Optional[tuple[tuple, tuple]],
|
|
251
|
-
) -> Callable[[], EdgeArchitype]:
|
|
260
|
+
) -> Callable[[NodeAnchor, NodeAnchor], EdgeArchitype]:
|
|
252
261
|
"""Jac's root getter."""
|
|
253
262
|
raise NotImplementedError
|
|
254
263
|
|
|
@@ -283,10 +292,40 @@ class JacFeatureSpec:
|
|
|
283
292
|
inputs: list[tuple[str, str, str, Any]],
|
|
284
293
|
outputs: tuple,
|
|
285
294
|
action: str,
|
|
295
|
+
_globals: dict,
|
|
296
|
+
_locals: Mapping,
|
|
286
297
|
) -> Any: # noqa: ANN401
|
|
287
298
|
"""Jac's with_llm stmt feature."""
|
|
288
299
|
raise NotImplementedError
|
|
289
300
|
|
|
301
|
+
@staticmethod
|
|
302
|
+
@hookspec(firstresult=True)
|
|
303
|
+
def gen_llm_body(_pass: PyastGenPass, node: ast.Ability) -> list[ast3.AST]:
|
|
304
|
+
"""Generate the by LLM body."""
|
|
305
|
+
raise NotImplementedError
|
|
306
|
+
|
|
307
|
+
@staticmethod
|
|
308
|
+
@hookspec(firstresult=True)
|
|
309
|
+
def by_llm_call(
|
|
310
|
+
_pass: PyastGenPass,
|
|
311
|
+
model: ast3.AST,
|
|
312
|
+
model_params: dict[str, ast.Expr],
|
|
313
|
+
scope: ast3.AST,
|
|
314
|
+
inputs: Sequence[Optional[ast3.AST]],
|
|
315
|
+
outputs: Sequence[Optional[ast3.AST]] | ast3.Call,
|
|
316
|
+
action: Optional[ast3.AST],
|
|
317
|
+
include_info: list[tuple[str, ast3.AST]],
|
|
318
|
+
exclude_info: list[tuple[str, ast3.AST]],
|
|
319
|
+
) -> ast3.Call:
|
|
320
|
+
"""Return the LLM Call, e.g. _Jac.with_llm()."""
|
|
321
|
+
raise NotImplementedError
|
|
322
|
+
|
|
323
|
+
@staticmethod
|
|
324
|
+
@hookspec(firstresult=True)
|
|
325
|
+
def get_by_llm_call_args(_pass: PyastGenPass, node: ast.FuncCall) -> dict:
|
|
326
|
+
"""Get the by LLM call args."""
|
|
327
|
+
raise NotImplementedError
|
|
328
|
+
|
|
290
329
|
|
|
291
330
|
class JacBuiltin:
|
|
292
331
|
"""Jac Builtins."""
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import:py from jaclang.runtimelib.architype {Anchor}
|
|
2
|
+
import:py from uuid {UUID}
|
|
3
|
+
|
|
4
|
+
node A {
|
|
5
|
+
has val: int;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
walker check_node {
|
|
9
|
+
can enter with `root entry {
|
|
10
|
+
visit [-->];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
can enter2 with A entry {
|
|
14
|
+
print(here);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
walker update_node {
|
|
19
|
+
has val: int;
|
|
20
|
+
|
|
21
|
+
can enter2 with A entry {
|
|
22
|
+
here.val = self.val;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
walker create_node {
|
|
27
|
+
has val: int;
|
|
28
|
+
|
|
29
|
+
can enter with `root entry {
|
|
30
|
+
a = A(val=self.val);
|
|
31
|
+
here ++> a;
|
|
32
|
+
print(a.__jac__.id);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
walker create_other_root {
|
|
37
|
+
can enter with `root entry {
|
|
38
|
+
other_root = `root().__jac__;
|
|
39
|
+
other_root.save();
|
|
40
|
+
print(other_root.id);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
walker allow_other_root_access {
|
|
45
|
+
has root_id: str, level: int | str = 1, via_all: bool = False;
|
|
46
|
+
|
|
47
|
+
can enter_root with `root entry {
|
|
48
|
+
if self.via_all {
|
|
49
|
+
here.__jac__.unrestrict(self.level);
|
|
50
|
+
} else {
|
|
51
|
+
here.__jac__.allow_root(UUID(self.root_id), self.level);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
can enter_nested with A entry {
|
|
56
|
+
if self.via_all {
|
|
57
|
+
here.__jac__.unrestrict(self.level);
|
|
58
|
+
} else {
|
|
59
|
+
here.__jac__.allow_root(UUID(self.root_id), self.level);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
walker disallow_other_root_access {
|
|
65
|
+
has root_id: str, via_all: bool = False;
|
|
66
|
+
|
|
67
|
+
can enter_root with `root entry {
|
|
68
|
+
if self.via_all {
|
|
69
|
+
here.__jac__.restrict();
|
|
70
|
+
} else {
|
|
71
|
+
here.__jac__.disallow_root(UUID(self.root_id));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
can enter_nested with A entry {
|
|
76
|
+
if self.via_all {
|
|
77
|
+
here.__jac__.restrict();
|
|
78
|
+
} else {
|
|
79
|
+
here.__jac__.disallow_root(UUID(self.root_id));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|