jaclang 0.3.0__py3-none-any.whl → 0.3.3__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/__init__.py +2 -1
- jaclang/core/__init__.py +4 -4
- jaclang/core/__jac_gen__/corelib.py +243 -27
- jaclang/core/corelib.jac +323 -7
- jaclang/jac/__jac_gen__/jac_parser.py +1 -1
- {jaclang-0.3.0.dist-info → jaclang-0.3.3.dist-info}/METADATA +1 -1
- {jaclang-0.3.0.dist-info → jaclang-0.3.3.dist-info}/RECORD +10 -12
- jaclang/core/__jac_gen__/corelib_impl.py +0 -220
- jaclang/core/corelib_impl.jac +0 -317
- {jaclang-0.3.0.dist-info → jaclang-0.3.3.dist-info}/WHEEL +0 -0
- {jaclang-0.3.0.dist-info → jaclang-0.3.3.dist-info}/entry_points.txt +0 -0
- {jaclang-0.3.0.dist-info → jaclang-0.3.3.dist-info}/top_level.txt +0 -0
jaclang/core/corelib.jac
CHANGED
|
@@ -5,9 +5,6 @@ import:py from uuid, UUID, uuid4;
|
|
|
5
5
|
import:py from jaclang.jac.constant, EdgeDir;
|
|
6
6
|
import:py from jaclang.jac.plugin, Architype, AbsRootHook, hookimpl;
|
|
7
7
|
|
|
8
|
-
include:jac corelib_impl;
|
|
9
|
-
|
|
10
|
-
|
|
11
8
|
enum AccessMode;
|
|
12
9
|
|
|
13
10
|
obj Memory {
|
|
@@ -38,7 +35,8 @@ obj ExecutionContext {
|
|
|
38
35
|
glob exec_ctx = ExecutionContext();
|
|
39
36
|
|
|
40
37
|
obj ElementInterface {
|
|
41
|
-
has
|
|
38
|
+
has ob: object,
|
|
39
|
+
jid: UUID = :>uuid4,
|
|
42
40
|
timestamp: datetime = :>datetime.now,
|
|
43
41
|
persist: bool = False,
|
|
44
42
|
access_mode: AccessMode = AccessMode.PRIVATE,
|
|
@@ -100,16 +98,334 @@ obj WalkerInterface:DataSpatialInterface: {
|
|
|
100
98
|
can __call__(nd: Node);
|
|
101
99
|
}
|
|
102
100
|
obj Root:AbsRootHook: {
|
|
103
|
-
has _jac_: NodeInterface;
|
|
104
101
|
has RootType: type;
|
|
102
|
+
has _jac_: NodeInterface|None = None;
|
|
103
|
+
can <pi> {
|
|
104
|
+
<self>._jac_ = NodeInterface(<self>);
|
|
105
|
+
}
|
|
105
106
|
}
|
|
106
107
|
|
|
107
108
|
obj Master {
|
|
108
|
-
has _jac_: ElementInterface =
|
|
109
|
-
has root_node: Root = Root(
|
|
109
|
+
has _jac_: ElementInterface|None = None;
|
|
110
|
+
has root_node: Root = Root(Root);
|
|
111
|
+
can <pi> {
|
|
112
|
+
<self>._jac_ = ElementInterface(<self>);
|
|
113
|
+
}
|
|
110
114
|
}
|
|
111
115
|
|
|
112
116
|
obj JacPlugin {
|
|
117
|
+
@hookimpl
|
|
113
118
|
static can bind_architype(arch: AT, arch_type: str) -> bool;
|
|
119
|
+
@hookimpl
|
|
114
120
|
static can get_root() -> Architype;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
:obj:Memory:can:get_obj
|
|
124
|
+
(caller_id: UUID, item_id: UUID, override: bool = False) -> Element {
|
|
125
|
+
ret = item_id |> <self>.index.get;
|
|
126
|
+
if override or (ret is not None and caller_id |> ret.__is_readable) {
|
|
127
|
+
return ret;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
:obj:Memory:can:has_obj
|
|
132
|
+
(item_id: UUID) -> bool {
|
|
133
|
+
return item_id in <self>.index;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
:obj:Memory:can:save_obj
|
|
137
|
+
(caller_id: UUID, item: Element) {
|
|
138
|
+
if caller_id |> item.is_writable {
|
|
139
|
+
<self>.index[item.id] = item;
|
|
140
|
+
if item._persist {
|
|
141
|
+
item |> <self>.save_obj_list.add;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
<self>.mem[item.id] = item;
|
|
145
|
+
if item._persist {
|
|
146
|
+
item |> <self>.save_obj_list.add;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
:obj:Memory:can:del_obj
|
|
151
|
+
(caller_id: UUID, item: Element) {
|
|
152
|
+
if caller_id |> item.is_writable {
|
|
153
|
+
<self>.index.pop(item.id);
|
|
154
|
+
if item._persist {
|
|
155
|
+
item |> <self>.save_obj_list.remove;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
:obj:Memory:can:get_object_distribution -> dict {
|
|
161
|
+
dist = {};
|
|
162
|
+
for i in |> <self>.index.keys {
|
|
163
|
+
t = <self>.index[i] |> type;
|
|
164
|
+
if t in dist {
|
|
165
|
+
dist[t] += 1;
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
dist[t] = 1;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return dist;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
:obj:Memory:can:get_mem_size -> float {
|
|
175
|
+
return (<self>.index |> sys.getsizeof) / 1024.0;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
:obj:ExecutionContext:c:get_root
|
|
179
|
+
() {
|
|
180
|
+
if <self>.master :> type == UUID {
|
|
181
|
+
<self>.master = Master();
|
|
182
|
+
}
|
|
183
|
+
return <self>.master.root_node;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
:obj:ExecutionContext:c:reset {
|
|
187
|
+
<self>.<init>();
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
"""Implementation for Jac's Element Abstractions"""
|
|
191
|
+
|
|
192
|
+
:enum:AccessMode {
|
|
193
|
+
READ_ONLY,
|
|
194
|
+
READ_WRITE,
|
|
195
|
+
PRIVATE
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
:obj:ElementInterface:can:make_public_ro {
|
|
199
|
+
<self>.__jinfo.access_mode = AccessMode.READ_ONLY;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
:obj:ElementInterface:can:make_public_rw {
|
|
203
|
+
<self>.__jinfo.access_mode = AccessMode.READ_WRITE;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
:obj:ElementInterface:can:make_private {
|
|
207
|
+
<self>.__jinfo.access_mode = AccessMode.PRIVATE;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
:obj:ElementInterface:can:is_public_ro -> bool {
|
|
211
|
+
return <self>.__jinfo.access_mode == AccessMode.READ_ONLY;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
:obj:ElementInterface:can:is_public_rw -> bool {
|
|
215
|
+
return <self>.__jinfo.access_mode == AccessMode.READ_WRITE;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
:obj:ElementInterface:can:is_private -> bool {
|
|
219
|
+
return <self>.__jinfo.access_mode == AccessMode.PRIVATE;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
:obj:ElementInterface:can:is_readable
|
|
223
|
+
(caller_id: UUID) -> bool {
|
|
224
|
+
return (
|
|
225
|
+
caller_id == <self>.owner_id
|
|
226
|
+
or |> <self>.is_public_read
|
|
227
|
+
or caller_id in <self>.ro_access
|
|
228
|
+
or caller_id in <self>.rw_access
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
:obj:ElementInterface:can:is_writable
|
|
233
|
+
(caller_id: UUID) -> bool {
|
|
234
|
+
return (
|
|
235
|
+
caller_id == <self>.owner_id
|
|
236
|
+
or |> <self>.is_public_write
|
|
237
|
+
or caller_id in <self>.rw_access
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
:obj:ElementInterface:can:give_access
|
|
242
|
+
(caller_id: UUID, read_write: bool = False) {
|
|
243
|
+
if read_write {
|
|
244
|
+
caller_id |> <self>.rw_access.add;
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
caller_id |> add .> ro_access .> <self>;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
:obj:ElementInterface:can:revoke_access
|
|
252
|
+
(caller_id: UUID) {
|
|
253
|
+
caller_id |> <self>.ro_access.discard;
|
|
254
|
+
caller_id |> <self>.rw_access.discard;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
:obj:DataSpatialInterface:can:on_entry
|
|
259
|
+
(cls: type, triggers: list) {
|
|
260
|
+
can decorator(func: callable) -> callable {
|
|
261
|
+
cls.ds_entry_funcs.append({'types': triggers, 'func': func});
|
|
262
|
+
can wrapper(*args: list, **kwargs: dict) -> callable {
|
|
263
|
+
return func(*args, **kwargs);
|
|
264
|
+
}
|
|
265
|
+
return wrapper;
|
|
266
|
+
}
|
|
267
|
+
return decorator;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
:obj:DataSpatialInterface:can:on_exit
|
|
271
|
+
(cls: type, triggers: list) {
|
|
272
|
+
can decorator(func: callable) -> callable {
|
|
273
|
+
cls.ds_exit_funcs.append({'types': triggers, 'func': func});
|
|
274
|
+
can wrapper(*args: list, **kwargs: dict) -> callable {
|
|
275
|
+
return func(*args, **kwargs);
|
|
276
|
+
}
|
|
277
|
+
return wrapper;
|
|
278
|
+
}
|
|
279
|
+
return decorator;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
:obj:NodeInterface:can:connect_node
|
|
283
|
+
(nd: Node, edg: Edge) -> Node {
|
|
284
|
+
(<self>.py_obj, nd) :> edg.attach;
|
|
285
|
+
return <self>;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
:obj:NodeInterface:can:edges_to_nodes
|
|
289
|
+
(dir: EdgeDir) -> list[Node] {
|
|
290
|
+
ret_nodes = [];
|
|
291
|
+
if dir in [EdgeDir.OUT, EdgeDir.ANY] {
|
|
292
|
+
for i in <self>.edges[EdgeDir.OUT] {
|
|
293
|
+
ret_nodes.append(i.target);
|
|
294
|
+
}
|
|
295
|
+
} elif dir in [EdgeDir.IN, EdgeDir.ANY] {
|
|
296
|
+
for i in <self>.edges[EdgeDir.IN] {
|
|
297
|
+
ret_nodes.append(i.source);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
return ret_nodes;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
:obj:EdgeInterface:can:apply_dir
|
|
304
|
+
(dir: EdgeDir) -> Edge {
|
|
305
|
+
<self>.dir = dir;
|
|
306
|
+
return <self>;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
:obj:EdgeInterface:can:attach
|
|
310
|
+
(src: Node, trg: Node) -> Edge {
|
|
311
|
+
if <self>.dir == EdgeDir.IN {
|
|
312
|
+
<self>.source = trg;
|
|
313
|
+
<self>.target = src;
|
|
314
|
+
<self> :> src._jac_.edges[EdgeDir.IN].append;
|
|
315
|
+
<self> :> trg._jac_.edges[EdgeDir.OUT].append;
|
|
316
|
+
} else {
|
|
317
|
+
<self>.source = src;
|
|
318
|
+
<self>.target = trg;
|
|
319
|
+
<self> :> src._jac_.edges[EdgeDir.OUT].append;
|
|
320
|
+
<self> :> trg._jac_.edges[EdgeDir.IN].append;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
return <self>;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
:obj:WalkerInterface:can:visit_node
|
|
327
|
+
(nds: list[Node]|list[Edge]|Node|Edge) {
|
|
328
|
+
if isinstance(nds, list) {
|
|
329
|
+
for i in nds {
|
|
330
|
+
if(i not in <self>.ignores) { i :> <self>.next.append; }
|
|
331
|
+
}
|
|
332
|
+
} elif nds not in <self>.ignores { nds :> <self>.next.append; }
|
|
333
|
+
return len(nds) if isinstance(nds, list) else 1;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
:obj:WalkerInterface:can:ignore_node
|
|
337
|
+
(nds: list[Node]|list[Edge]|Node|Edge) {
|
|
338
|
+
if isinstance(nds, list) {
|
|
339
|
+
for i in nds {
|
|
340
|
+
i :> <self>.ignores.append;
|
|
341
|
+
}
|
|
342
|
+
} else { nds :> <self>.ignores.append; }
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
:obj:WalkerInterface:can:disengage_now {
|
|
346
|
+
<self>.next = [];
|
|
347
|
+
<self>.disengaged = True;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
:obj:NodeInterface:can:__call__
|
|
352
|
+
(walk: object) {
|
|
353
|
+
if not isinstance(walk._jac_, WalkerInterface) {
|
|
354
|
+
raise TypeError("Argument must be a Walker instance");
|
|
355
|
+
}
|
|
356
|
+
walk(<self>);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
:obj:EdgeInterface:can:__call__
|
|
361
|
+
(walk: Walker) {
|
|
362
|
+
if not (walk, Walker) :> isinstance {
|
|
363
|
+
raise ("Argument must be a Walker instance") :> TypeError;
|
|
364
|
+
}
|
|
365
|
+
<self>._jac_.target :> walk;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
:obj:WalkerInterface:can:__call__
|
|
369
|
+
(nd: Node) {
|
|
370
|
+
<self>.path = [];
|
|
371
|
+
<self>.next = [nd];
|
|
372
|
+
walker_type = <self>.__class__.__name__;
|
|
373
|
+
while <self>.next :> len {
|
|
374
|
+
nd = 0 :> <self>.next.pop;
|
|
375
|
+
node_type = nd.__class__.__name__;
|
|
376
|
+
|
|
377
|
+
for i in nd.ds_entry_funcs {
|
|
378
|
+
if i['func'].__qualname__.split(".")[0] == node_type and
|
|
379
|
+
<self>:>type in i['types'] {
|
|
380
|
+
(nd, <self>) :> i['func'];
|
|
381
|
+
}
|
|
382
|
+
if <self>.disengaged {return;}
|
|
383
|
+
}
|
|
384
|
+
for i in <self>.ds_entry_funcs {
|
|
385
|
+
if i['func'].__qualname__.split(".")[0] == walker_type and
|
|
386
|
+
(nd:>type in i['types'] or nd in i['types']) { # if nd==root direct chec
|
|
387
|
+
i['func'](<self>, nd);
|
|
388
|
+
}
|
|
389
|
+
if <self>.disengaged {return;}
|
|
390
|
+
}
|
|
391
|
+
for i in <self>.ds_exit_funcs {
|
|
392
|
+
if i['func'].__qualname__.split(".")[0] == walker_type and
|
|
393
|
+
(nd:>type in i['types'] or nd in i['types']) {
|
|
394
|
+
i['func'](<self>, nd);
|
|
395
|
+
}
|
|
396
|
+
if <self>.disengaged {return;}
|
|
397
|
+
}
|
|
398
|
+
for i in nd.ds_exit_funcs {
|
|
399
|
+
if i['func'].__qualname__.split(".")[0] == node_type and
|
|
400
|
+
<self>:>type in i['types'] {
|
|
401
|
+
(nd, <self>) :> i['func'];
|
|
402
|
+
}
|
|
403
|
+
if <self>.disengaged {return;}
|
|
404
|
+
}
|
|
405
|
+
nd :> <self>.path.append;
|
|
406
|
+
}
|
|
407
|
+
<self>.ignores=[];
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
:obj:JacPlugin:can:bind_architype
|
|
412
|
+
(arch: AT, arch_type: str) -> bool {
|
|
413
|
+
match arch_type {
|
|
414
|
+
case 'obj':
|
|
415
|
+
arch._jac_ = ObjectInterface(arch);
|
|
416
|
+
case 'node':
|
|
417
|
+
arch._jac_ = NodeInterface(arch);
|
|
418
|
+
case 'edge':
|
|
419
|
+
arch._jac_ = EdgeInterface(arch);
|
|
420
|
+
case 'walker':
|
|
421
|
+
arch._jac_ = WalkerInterface(arch);
|
|
422
|
+
case _:
|
|
423
|
+
raise ("Invalid archetype type") :> TypeError;
|
|
424
|
+
}
|
|
425
|
+
return True;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
:obj:JacPlugin:can:get_root
|
|
429
|
+
() -> None {
|
|
430
|
+
return exec_ctx.get_root();
|
|
115
431
|
}
|