jaclang 0.7.22__py3-none-any.whl → 0.7.24__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.

Files changed (33) hide show
  1. jaclang/__init__.py +5 -10
  2. jaclang/cli/cli.py +4 -1
  3. jaclang/compiler/absyntree.py +6 -4
  4. jaclang/compiler/parser.py +4 -2
  5. jaclang/compiler/passes/main/tests/fixtures/fstrings.jac +2 -0
  6. jaclang/compiler/passes/main/type_check_pass.py +8 -6
  7. jaclang/plugin/builtin.py +3 -3
  8. jaclang/plugin/default.py +588 -206
  9. jaclang/plugin/feature.py +274 -99
  10. jaclang/plugin/plugin.md +471 -0
  11. jaclang/plugin/spec.py +231 -86
  12. jaclang/plugin/tests/fixtures/other_root_access.jac +9 -9
  13. jaclang/plugin/tests/test_features.py +2 -2
  14. jaclang/runtimelib/architype.py +1 -370
  15. jaclang/runtimelib/constructs.py +2 -0
  16. jaclang/runtimelib/context.py +2 -4
  17. jaclang/runtimelib/machine.py +57 -0
  18. jaclang/runtimelib/memory.py +2 -4
  19. jaclang/settings.py +3 -0
  20. jaclang/tests/fixtures/arch_create_util.jac +7 -0
  21. jaclang/tests/fixtures/arch_rel_import_creation.jac +30 -0
  22. jaclang/tests/fixtures/builtin_dotgen.jac +6 -6
  23. jaclang/tests/fixtures/create_dynamic_architype.jac +35 -0
  24. jaclang/tests/fixtures/edge_node_walk.jac +1 -1
  25. jaclang/tests/fixtures/edges_walk.jac +1 -1
  26. jaclang/tests/fixtures/enum_inside_archtype.jac +16 -11
  27. jaclang/tests/fixtures/gendot_bubble_sort.jac +1 -1
  28. jaclang/tests/fixtures/visit_order.jac +20 -0
  29. jaclang/tests/test_language.py +55 -1
  30. {jaclang-0.7.22.dist-info → jaclang-0.7.24.dist-info}/METADATA +2 -1
  31. {jaclang-0.7.22.dist-info → jaclang-0.7.24.dist-info}/RECORD +33 -28
  32. {jaclang-0.7.22.dist-info → jaclang-0.7.24.dist-info}/WHEEL +1 -1
  33. {jaclang-0.7.22.dist-info → jaclang-0.7.24.dist-info}/entry_points.txt +0 -0
jaclang/plugin/spec.py CHANGED
@@ -11,37 +11,233 @@ from typing import (
11
11
  Optional,
12
12
  ParamSpec,
13
13
  Sequence,
14
- TYPE_CHECKING,
15
14
  Type,
16
15
  TypeVar,
17
16
  Union,
18
17
  )
18
+ from uuid import UUID
19
19
 
20
- import jaclang.compiler.absyntree as ast
20
+ from jaclang.compiler import absyntree as ast
21
+ from jaclang.compiler.constant import EdgeDir
21
22
  from jaclang.compiler.passes.main.pyast_gen_pass import PyastGenPass
22
-
23
- if TYPE_CHECKING:
24
- from jaclang.plugin.default import (
25
- Architype,
26
- EdgeDir,
27
- WalkerArchitype,
28
- Root,
29
- DSFunc,
30
- )
31
- from jaclang.runtimelib.constructs import EdgeArchitype, NodeAnchor, NodeArchitype
32
- from jaclang.runtimelib.context import ExecutionContext
23
+ from jaclang.runtimelib.constructs import (
24
+ AccessLevel,
25
+ Anchor,
26
+ Architype,
27
+ DSFunc,
28
+ EdgeAnchor,
29
+ EdgeArchitype,
30
+ NodeAnchor,
31
+ NodeArchitype,
32
+ Root,
33
+ WalkerArchitype,
34
+ )
35
+ from jaclang.runtimelib.context import ExecutionContext
33
36
 
34
37
  import pluggy
35
38
 
36
39
  hookspec = pluggy.HookspecMarker("jac")
40
+ plugin_manager = pluggy.PluginManager("jac")
37
41
 
38
42
  T = TypeVar("T")
39
43
  P = ParamSpec("P")
40
44
 
41
45
 
42
- class JacFeatureSpec:
46
+ class JacAccessValidationSpec:
47
+ """Jac Access Validation Specs."""
48
+
49
+ @staticmethod
50
+ @hookspec(firstresult=True)
51
+ def allow_root(
52
+ architype: Architype, root_id: UUID, level: AccessLevel | int | str
53
+ ) -> None:
54
+ """Allow all access from target root graph to current Architype."""
55
+ raise NotImplementedError
56
+
57
+ @staticmethod
58
+ @hookspec(firstresult=True)
59
+ def disallow_root(
60
+ architype: Architype, root_id: UUID, level: AccessLevel | int | str
61
+ ) -> None:
62
+ """Disallow all access from target root graph to current Architype."""
63
+ raise NotImplementedError
64
+
65
+ @staticmethod
66
+ @hookspec(firstresult=True)
67
+ def unrestrict(architype: Architype, level: AccessLevel | int | str) -> None:
68
+ """Allow everyone to access current Architype."""
69
+ raise NotImplementedError
70
+
71
+ @staticmethod
72
+ @hookspec(firstresult=True)
73
+ def restrict(architype: Architype) -> None:
74
+ """Disallow others to access current Architype."""
75
+ raise NotImplementedError
76
+
77
+ @staticmethod
78
+ @hookspec(firstresult=True)
79
+ def check_read_access(to: Anchor) -> bool:
80
+ """Read Access Validation."""
81
+ raise NotImplementedError
82
+
83
+ @staticmethod
84
+ @hookspec(firstresult=True)
85
+ def check_connect_access(to: Anchor) -> bool:
86
+ """Write Access Validation."""
87
+ raise NotImplementedError
88
+
89
+ @staticmethod
90
+ @hookspec(firstresult=True)
91
+ def check_write_access(to: Anchor) -> bool:
92
+ """Write Access Validation."""
93
+ raise NotImplementedError
94
+
95
+ @staticmethod
96
+ @hookspec(firstresult=True)
97
+ def check_access_level(to: Anchor) -> AccessLevel:
98
+ """Access validation."""
99
+ raise NotImplementedError
100
+
101
+
102
+ class JacNodeSpec:
103
+ """Jac Node Operations."""
104
+
105
+ @staticmethod
106
+ @hookspec(firstresult=True)
107
+ def node_dot(node: NodeArchitype, dot_file: Optional[str]) -> str:
108
+ """Generate Dot file for visualizing nodes and edges."""
109
+ raise NotImplementedError
110
+
111
+ @staticmethod
112
+ @hookspec(firstresult=True)
113
+ def get_edges(
114
+ node: NodeAnchor,
115
+ dir: EdgeDir,
116
+ filter_func: Optional[Callable[[list[EdgeArchitype]], list[EdgeArchitype]]],
117
+ target_obj: Optional[list[NodeArchitype]],
118
+ ) -> list[EdgeArchitype]:
119
+ """Get edges connected to this node."""
120
+ raise NotImplementedError
121
+
122
+ @staticmethod
123
+ @hookspec(firstresult=True)
124
+ def edges_to_nodes(
125
+ node: NodeAnchor,
126
+ dir: EdgeDir,
127
+ filter_func: Optional[Callable[[list[EdgeArchitype]], list[EdgeArchitype]]],
128
+ target_obj: Optional[list[NodeArchitype]],
129
+ ) -> list[NodeArchitype]:
130
+ """Get set of nodes connected to this node."""
131
+ raise NotImplementedError
132
+
133
+ @staticmethod
134
+ @hookspec(firstresult=True)
135
+ def remove_edge(node: NodeAnchor, edge: EdgeAnchor) -> None:
136
+ """Remove reference without checking sync status."""
137
+ raise NotImplementedError
138
+
139
+
140
+ class JacEdgeSpec:
141
+ """Jac Edge Operations."""
142
+
143
+ @staticmethod
144
+ @hookspec(firstresult=True)
145
+ def detach(edge: EdgeAnchor) -> None:
146
+ """Detach edge from nodes."""
147
+ raise NotImplementedError
148
+
149
+
150
+ class JacWalkerSpec:
151
+ """Jac Edge Operations."""
152
+
153
+ @staticmethod
154
+ @hookspec(firstresult=True)
155
+ def visit_node(
156
+ walker: WalkerArchitype,
157
+ expr: (
158
+ list[NodeArchitype | EdgeArchitype]
159
+ | list[NodeArchitype]
160
+ | list[EdgeArchitype]
161
+ | NodeArchitype
162
+ | EdgeArchitype
163
+ ),
164
+ ) -> bool: # noqa: ANN401
165
+ """Jac's visit stmt feature."""
166
+ raise NotImplementedError
167
+
168
+ @staticmethod
169
+ @hookspec(firstresult=True)
170
+ def ignore(
171
+ walker: WalkerArchitype,
172
+ expr: (
173
+ list[NodeArchitype | EdgeArchitype]
174
+ | list[NodeArchitype]
175
+ | list[EdgeArchitype]
176
+ | NodeArchitype
177
+ | EdgeArchitype
178
+ ),
179
+ ) -> bool:
180
+ """Jac's ignore stmt feature."""
181
+ raise NotImplementedError
182
+
183
+ @staticmethod
184
+ @hookspec(firstresult=True)
185
+ def spawn_call(op1: Architype, op2: Architype) -> WalkerArchitype:
186
+ """Invoke data spatial call."""
187
+ raise NotImplementedError
188
+
189
+ @staticmethod
190
+ @hookspec(firstresult=True)
191
+ def disengage(walker: WalkerArchitype) -> bool:
192
+ """Jac's disengage stmt feature."""
193
+ raise NotImplementedError
194
+
195
+
196
+ class JacBuiltinSpec:
197
+ """Jac Builtins."""
198
+
199
+ @staticmethod
200
+ @hookspec(firstresult=True)
201
+ def dotgen(
202
+ node: NodeArchitype,
203
+ depth: int,
204
+ traverse: bool,
205
+ edge_type: Optional[list[str]],
206
+ bfs: bool,
207
+ edge_limit: int,
208
+ node_limit: int,
209
+ dot_file: Optional[str],
210
+ ) -> str:
211
+ """Print the dot graph."""
212
+ raise NotImplementedError
213
+
214
+
215
+ class JacCmdSpec:
216
+ """Jac CLI command."""
217
+
218
+ @staticmethod
219
+ @hookspec
220
+ def create_cmd() -> None:
221
+ """Create Jac CLI cmds."""
222
+ raise NotImplementedError
223
+
224
+
225
+ class JacFeatureSpec(
226
+ JacAccessValidationSpec,
227
+ JacNodeSpec,
228
+ JacEdgeSpec,
229
+ JacWalkerSpec,
230
+ JacBuiltinSpec,
231
+ JacCmdSpec,
232
+ ):
43
233
  """Jac Feature."""
44
234
 
235
+ @staticmethod
236
+ @hookspec(firstresult=True)
237
+ def setup() -> None:
238
+ """Set Class References."""
239
+ raise NotImplementedError
240
+
45
241
  @staticmethod
46
242
  @hookspec(firstresult=True)
47
243
  def get_context() -> ExecutionContext:
@@ -51,13 +247,13 @@ class JacFeatureSpec:
51
247
  @staticmethod
52
248
  @hookspec(firstresult=True)
53
249
  def get_object(id: str) -> Architype | None:
54
- """Get object given id.."""
250
+ """Get object by id."""
55
251
  raise NotImplementedError
56
252
 
57
253
  @staticmethod
58
254
  @hookspec(firstresult=True)
59
255
  def object_ref(obj: Architype) -> str:
60
- """Get object given id.."""
256
+ """Get object's id."""
61
257
  raise NotImplementedError
62
258
 
63
259
  @staticmethod
@@ -160,52 +356,10 @@ class JacFeatureSpec:
160
356
 
161
357
  @staticmethod
162
358
  @hookspec(firstresult=True)
163
- def spawn_call(op1: Architype, op2: Architype) -> WalkerArchitype:
164
- """Jac's spawn operator feature."""
165
- raise NotImplementedError
166
-
167
- @staticmethod
168
- @hookspec(firstresult=True)
169
- def report(expr: Any) -> Any: # noqa: ANN401
359
+ def report(expr: Any, custom: bool) -> None: # noqa: ANN401
170
360
  """Jac's report stmt feature."""
171
361
  raise NotImplementedError
172
362
 
173
- @staticmethod
174
- @hookspec(firstresult=True)
175
- def ignore(
176
- walker: WalkerArchitype,
177
- expr: (
178
- list[NodeArchitype | EdgeArchitype]
179
- | list[NodeArchitype]
180
- | list[EdgeArchitype]
181
- | NodeArchitype
182
- | EdgeArchitype
183
- ),
184
- ) -> bool:
185
- """Jac's ignore stmt feature."""
186
- raise NotImplementedError
187
-
188
- @staticmethod
189
- @hookspec(firstresult=True)
190
- def visit_node(
191
- walker: WalkerArchitype,
192
- expr: (
193
- list[NodeArchitype | EdgeArchitype]
194
- | list[NodeArchitype]
195
- | list[EdgeArchitype]
196
- | NodeArchitype
197
- | EdgeArchitype
198
- ),
199
- ) -> bool: # noqa: ANN401
200
- """Jac's visit stmt feature."""
201
- raise NotImplementedError
202
-
203
- @staticmethod
204
- @hookspec(firstresult=True)
205
- def disengage(walker: WalkerArchitype) -> bool: # noqa: ANN401
206
- """Jac's disengage stmt feature."""
207
- raise NotImplementedError
208
-
209
363
  @staticmethod
210
364
  @hookspec(firstresult=True)
211
365
  def edge_ref(
@@ -273,6 +427,22 @@ class JacFeatureSpec:
273
427
  """Jac's root getter."""
274
428
  raise NotImplementedError
275
429
 
430
+ @staticmethod
431
+ @hookspec(firstresult=True)
432
+ def save(
433
+ obj: Architype | Anchor,
434
+ ) -> None:
435
+ """Destroy object."""
436
+ raise NotImplementedError
437
+
438
+ @staticmethod
439
+ @hookspec(firstresult=True)
440
+ def destroy(
441
+ obj: Architype | Anchor,
442
+ ) -> None:
443
+ """Destroy object."""
444
+ raise NotImplementedError
445
+
276
446
  @staticmethod
277
447
  @hookspec(firstresult=True)
278
448
  def get_semstr_type(
@@ -288,6 +458,7 @@ class JacFeatureSpec:
288
458
  raise NotImplementedError
289
459
 
290
460
  @staticmethod
461
+ @hookspec(firstresult=True)
291
462
  def get_sem_type(file_loc: str, attr: str) -> tuple[str | None, str | None]:
292
463
  """Jac's get_semstr_type feature."""
293
464
  raise NotImplementedError
@@ -339,30 +510,4 @@ class JacFeatureSpec:
339
510
  raise NotImplementedError
340
511
 
341
512
 
342
- class JacBuiltin:
343
- """Jac Builtins."""
344
-
345
- @staticmethod
346
- @hookspec(firstresult=True)
347
- def dotgen(
348
- node: NodeArchitype,
349
- depth: int,
350
- traverse: bool,
351
- edge_type: list[str],
352
- bfs: bool,
353
- edge_limit: int,
354
- node_limit: int,
355
- dot_file: Optional[str],
356
- ) -> str:
357
- """Print the dot graph."""
358
- raise NotImplementedError
359
-
360
-
361
- class JacCmdSpec:
362
- """Jac CLI command."""
363
-
364
- @staticmethod
365
- @hookspec
366
- def create_cmd() -> None:
367
- """Create Jac CLI cmds."""
368
- raise NotImplementedError
513
+ plugin_manager.add_hookspecs(JacFeatureSpec)
@@ -36,7 +36,7 @@ walker create_node {
36
36
  walker create_other_root {
37
37
  can enter with `root entry {
38
38
  other_root = `root().__jac__;
39
- other_root.save();
39
+ Jac.save(other_root);
40
40
  print(other_root.id);
41
41
  }
42
42
  }
@@ -46,17 +46,17 @@ walker allow_other_root_access {
46
46
 
47
47
  can enter_root with `root entry {
48
48
  if self.via_all {
49
- here.__jac__.unrestrict(self.level);
49
+ Jac.unrestrict(here, self.level);
50
50
  } else {
51
- here.__jac__.allow_root(UUID(self.root_id), self.level);
51
+ Jac.allow_root(here, UUID(self.root_id), self.level);
52
52
  }
53
53
  }
54
54
 
55
55
  can enter_nested with A entry {
56
56
  if self.via_all {
57
- here.__jac__.unrestrict(self.level);
57
+ Jac.unrestrict(here, self.level);
58
58
  } else {
59
- here.__jac__.allow_root(UUID(self.root_id), self.level);
59
+ Jac.allow_root(here, UUID(self.root_id), self.level);
60
60
  }
61
61
  }
62
62
  }
@@ -66,17 +66,17 @@ walker disallow_other_root_access {
66
66
 
67
67
  can enter_root with `root entry {
68
68
  if self.via_all {
69
- here.__jac__.restrict();
69
+ Jac.restrict(here);
70
70
  } else {
71
- here.__jac__.disallow_root(UUID(self.root_id));
71
+ Jac.disallow_root(here, UUID(self.root_id));
72
72
  }
73
73
  }
74
74
 
75
75
  can enter_nested with A entry {
76
76
  if self.via_all {
77
- here.__jac__.restrict();
77
+ Jac.restrict(here);
78
78
  } else {
79
- here.__jac__.disallow_root(UUID(self.root_id));
79
+ Jac.disallow_root(here, UUID(self.root_id));
80
80
  }
81
81
  }
82
82
  }
@@ -3,7 +3,7 @@
3
3
  import inspect
4
4
  from typing import List, Type
5
5
 
6
- from jaclang.plugin.default import JacFeatureDefaults
6
+ from jaclang.plugin.default import JacFeatureImpl
7
7
  from jaclang.plugin.feature import JacFeature
8
8
  from jaclang.plugin.spec import JacFeatureSpec
9
9
  from jaclang.utils.test import TestCase
@@ -46,7 +46,7 @@ class TestFeatures(TestCase):
46
46
  """Test if JacFeature, JacFeatureDefaults, and JacFeatureSpec have synced methods."""
47
47
  # Get methods of each class
48
48
  jac_feature_methods = self.get_methods(JacFeature)
49
- jac_feature_defaults_methods = self.get_methods(JacFeatureDefaults)
49
+ jac_feature_defaults_methods = self.get_methods(JacFeatureImpl)
50
50
  jac_feature_spec_methods = self.get_methods(JacFeatureSpec)
51
51
 
52
52
  # Check if all methods are the same in all classes