jaclang 0.8.1__py3-none-any.whl → 0.8.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/__init__.py +6 -0
- jaclang/cli/cli.py +21 -50
- jaclang/compiler/codeinfo.py +0 -1
- jaclang/compiler/constant.py +2 -0
- jaclang/compiler/jac.lark +17 -10
- jaclang/compiler/larkparse/jac_parser.py +2 -2
- jaclang/compiler/parser.py +34 -10
- jaclang/compiler/passes/main/__init__.py +2 -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 +246 -592
- jaclang/compiler/passes/main/sem_def_match_pass.py +67 -0
- jaclang/compiler/passes/main/sym_tab_build_pass.py +8 -0
- jaclang/compiler/passes/main/sym_tab_link_pass.py +2 -5
- jaclang/compiler/passes/main/tests/fixtures/sem_def_match.impl.jac +12 -0
- jaclang/compiler/passes/main/tests/fixtures/sem_def_match.jac +31 -0
- 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_sem_def_match_pass.py +38 -0
- 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 +259 -106
- 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/has_frmt.jac +13 -0
- 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 +25 -3
- jaclang/compiler/passes/tool/tests/test_unparse_validate.py +2 -2
- jaclang/compiler/program.py +23 -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 +88 -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.3.dist-info}/METADATA +1 -1
- {jaclang-0.8.1.dist-info → jaclang-0.8.3.dist-info}/RECORD +79 -72
- 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.3.dist-info}/WHEEL +0 -0
- {jaclang-0.8.1.dist-info → jaclang-0.8.3.dist-info}/entry_points.txt +0 -0
|
@@ -1,644 +0,0 @@
|
|
|
1
|
-
"""Jac's Key Elemental Abstractions"""
|
|
2
|
-
|
|
3
|
-
import #* what abou this *# from datetime { datetime }
|
|
4
|
-
import from uuid { UUID, uuid4 } # This is a comment
|
|
5
|
-
import from jaclang.compiler.constant { EdgeDir }
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import from jaclang.plugin { Archetype, ArchetypeProtocol, ArchetypeProtocol3 as MyArch, DSFunc, ArchetypeProtocol, ArchetypeProtocol3, DSFunc, AbsRootHook, hookimpl }
|
|
10
|
-
import jaclang.compiler.constant;
|
|
11
|
-
|
|
12
|
-
import jaclang.compiler;
|
|
13
|
-
|
|
14
|
-
enum AccessMode;
|
|
15
|
-
def DoSomething(name: str) -> str;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"I'm a doc"
|
|
19
|
-
impl Memory.get_obj
|
|
20
|
-
(caller_id: UUID, item_id: UUID, override: bool=False, doc: bool=False) -> Element {
|
|
21
|
-
ret = item_id |> self.index.get;
|
|
22
|
-
if override or (ret is not None and caller_id |> ret.__is_readable) {
|
|
23
|
-
return ret;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
@deco
|
|
28
|
-
def func_name(name: str) -> str { #* blah*#
|
|
29
|
-
|
|
30
|
-
def #* This is a comment *# inner_func(name: str) -> str {
|
|
31
|
-
x = y = 5;
|
|
32
|
-
print(name); # This is a comment
|
|
33
|
-
if (True) {
|
|
34
|
-
return name;
|
|
35
|
-
} elif (True) {
|
|
36
|
-
return name;
|
|
37
|
-
} else {
|
|
38
|
-
return name;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return inner_func(name);
|
|
42
|
-
}
|
|
43
|
-
with entry {
|
|
44
|
-
name = '90';
|
|
45
|
-
enum age { days = 12 }
|
|
46
|
-
print(f'{name}');
|
|
47
|
-
print(f"hello {f'{name.upper()}'} {name}");
|
|
48
|
-
print(f"hello{{escaped curly brace}} {f'{age.days.to_bytes()}'} {name}");
|
|
49
|
-
print(f'{name}');
|
|
50
|
-
print(f'{name}');
|
|
51
|
-
print(f"hello{{escaped curly brace}} {f'{name}'} {name}");
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
obj Memory {
|
|
56
|
-
has index: dict[UUID, Element] = {},
|
|
57
|
-
save_queue: list[Element] = [];
|
|
58
|
-
#* Main Accessors *#
|
|
59
|
-
def get_obj(caller_id: UUID, item_id: UUID, override: bool=False) -> Element;
|
|
60
|
-
def has_obj(item_id: UUID) -> bool;
|
|
61
|
-
def save_obj(caller_id: UUID, item: Element);
|
|
62
|
-
def del_obj(caller_id: UUID, item: Element);
|
|
63
|
-
#* Utility Functions *#
|
|
64
|
-
|
|
65
|
-
def get_object_distribution -> dict;
|
|
66
|
-
def get_mem_size -> float;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
obj ExecutionContext {
|
|
70
|
-
has master: Master = :> uuid4,
|
|
71
|
-
memory: Memory = Memory();
|
|
72
|
-
|
|
73
|
-
def reset;
|
|
74
|
-
def get_root() -> Archetype;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
"Global Execution Context, should be monkey patched by the user."
|
|
78
|
-
glob exec_ctx = ExecutionContext();
|
|
79
|
-
glob exec_ctx2 = ExecutionContext();
|
|
80
|
-
|
|
81
|
-
obj Anchor(ArchetypeProtocol) {
|
|
82
|
-
has ob: object,
|
|
83
|
-
ds_entry_funcs: list[DSFunc],
|
|
84
|
-
ds_exit_funcs: list[DSFunc],
|
|
85
|
-
jid: UUID = :> uuid4,
|
|
86
|
-
timestamp: datetime = :> datetime.now,
|
|
87
|
-
persist: bool = False,
|
|
88
|
-
access_mode: AccessMode = AccessMode.PRIVATE,
|
|
89
|
-
rw_access: set = :> set,
|
|
90
|
-
ro_access: set = :> set,
|
|
91
|
-
owner_id: UUID = exec_ctx.master,
|
|
92
|
-
mem: Memory = exec_ctx.memory;
|
|
93
|
-
static def on_entry(cls: type, triggers: list[type]);
|
|
94
|
-
static def on_exit(cls: type, triggers: list[type]);
|
|
95
|
-
def make_public_ro;
|
|
96
|
-
def make_public_rw;
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
def make_private;
|
|
100
|
-
def is_public_ro -> bool;
|
|
101
|
-
def is_public_rw -> bool;
|
|
102
|
-
def is_private -> bool;
|
|
103
|
-
def is_readable(caller_id: UUID) -> bool;
|
|
104
|
-
def is_writable(caller_id: UUID) -> bool;
|
|
105
|
-
def give_access(caller_id: UUID, read_write: bool=False);
|
|
106
|
-
def revoke_access(caller_id: UUID);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
obj NodeAnchor(Anchor) {
|
|
110
|
-
has edges: dict[EdgeDir, list[Edge]] = {EdgeDir.IN: [], EdgeDir.OUT: []};
|
|
111
|
-
|
|
112
|
-
def connect_node(nd: Node, edg: Edge) -> Node;
|
|
113
|
-
def edges_to_nodes(dir: EdgeDir) -> list[Node];
|
|
114
|
-
def __call__(walk: Walker);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
obj EdgeAnchor(Anchor) {
|
|
118
|
-
has source: Node = None,
|
|
119
|
-
target: Node = None,
|
|
120
|
-
dir: EdgeDir = None;
|
|
121
|
-
|
|
122
|
-
def apply_dir(dir: EdgeDir) -> Edge;
|
|
123
|
-
def attach(src: Node, trg: Node) -> Edge;
|
|
124
|
-
def __call__(walk: Walker);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
obj WalkerAnchor(Anchor) {
|
|
128
|
-
has path: list[Node] = [],
|
|
129
|
-
next: list[Node] = [],
|
|
130
|
-
ignores: list[Node] = [],
|
|
131
|
-
disengaged: bool = False;
|
|
132
|
-
|
|
133
|
-
def visit_node(nds: list[Node] | list[Edge] | Node | Edge);
|
|
134
|
-
def ignore_node(nds: list[Node] | list[Edge] | Node | Edge);
|
|
135
|
-
def disengage_now;
|
|
136
|
-
def __call__(nd: Node);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
obj Root(AbsRootHook) {
|
|
140
|
-
has __jac__: NodeAnchor | None = None;
|
|
141
|
-
|
|
142
|
-
def postinit {
|
|
143
|
-
self.__jac__ = NodeAnchor(self, ds_entry_funcs=[], ds_exit_funcs=[]);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
obj GenericEdge(ArchetypeProtocol) {
|
|
148
|
-
has __jac__: EdgeAnchor | None = None;
|
|
149
|
-
|
|
150
|
-
def postinit {
|
|
151
|
-
self.__jac__ = EdgeAnchor(self, ds_entry_funcs=[], ds_exit_funcs=[]);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
obj Master {
|
|
156
|
-
has __jac__: Anchor | None = None;
|
|
157
|
-
has root_node: Root = Root(Root);
|
|
158
|
-
|
|
159
|
-
def postinit {
|
|
160
|
-
self.__jac__ = Anchor(self);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
obj JacPlugin {
|
|
165
|
-
@hookimpl
|
|
166
|
-
static def bind_archetype(arch: AT, arch_type: str, on_entry: list[str], on_exit: list[str]) -> bool;
|
|
167
|
-
@hookimpl
|
|
168
|
-
static def get_root() -> Archetype;
|
|
169
|
-
@hookimpl
|
|
170
|
-
static def build_edge(edge_spec: tuple[int, Optional[tuple], Optional[tuple]]) -> Archetype;
|
|
171
|
-
@hookimpl
|
|
172
|
-
static def connect(left: T, right: T, edge_spec: tuple[int, Optional[type], Optional[tuple]]) -> Archetype;
|
|
173
|
-
@hookimpl
|
|
174
|
-
static def visit_node(walker_obj: Any, expr: Any) -> bool;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
impl Memory.get_obj
|
|
178
|
-
(caller_id: UUID, item_id: UUID, override: bool=False) -> Element {
|
|
179
|
-
ret = item_id |> self.index.get;
|
|
180
|
-
if override or (ret is not None and caller_id |> ret.__is_readable) {
|
|
181
|
-
return ret;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
impl Memory.has_obj
|
|
186
|
-
(item_id: UUID) -> bool {
|
|
187
|
-
return item_id in self.index;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
impl Memory.save_obj
|
|
191
|
-
(caller_id: UUID, item: Element) {
|
|
192
|
-
if caller_id |> item.is_writable {
|
|
193
|
-
self.index[item.id] = item;
|
|
194
|
-
if item._persist {
|
|
195
|
-
item |> self.save_obj_list.add;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
self.mem[item.id] = item;
|
|
199
|
-
if item._persist {
|
|
200
|
-
item |> self.save_obj_list.add;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
impl Memory.del_obj
|
|
205
|
-
(caller_id: UUID, item: Element) {
|
|
206
|
-
if caller_id |> item.is_writable {
|
|
207
|
-
self.index.pop(item.id);
|
|
208
|
-
if item._persist {
|
|
209
|
-
item |> self.save_obj_list.remove;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
impl Memory.get_object_distribution -> dict {
|
|
215
|
-
dist = {};
|
|
216
|
-
for i in |> self.index.keys {
|
|
217
|
-
t = self.index[i] |> type;
|
|
218
|
-
if t in dist {
|
|
219
|
-
dist[t] += 1;
|
|
220
|
-
} else {
|
|
221
|
-
dist[t] = 1;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
return dist;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
impl Memory.get_mem_size -> float {
|
|
228
|
-
return (self.index |> sys.getsizeof) / 1024.0;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
impl ExecutionContext.get_root() {
|
|
232
|
-
if self.master :> type == UUID {
|
|
233
|
-
self.master = Master();
|
|
234
|
-
}
|
|
235
|
-
return self.master.root_node;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
impl ExecutionContext.reset {
|
|
239
|
-
self.init();
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
"""Implementation for Jac's Element Abstractions"""
|
|
243
|
-
impl AccessMode {
|
|
244
|
-
READ_ONLY,
|
|
245
|
-
READ_WRITE,
|
|
246
|
-
PRIVATE
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
impl Anchor.make_public_ro {
|
|
250
|
-
self.__jinfo.access_mode = AccessMode.READ_ONLY;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
impl Anchor.make_public_rw {
|
|
254
|
-
self.__jinfo.access_mode = AccessMode.READ_WRITE;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
impl Anchor.make_private {
|
|
258
|
-
self.__jinfo.access_mode = AccessMode.PRIVATE;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
impl Anchor.is_public_ro -> bool {
|
|
262
|
-
return self.__jinfo.access_mode == AccessMode.READ_ONLY;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
impl Anchor.is_public_rw -> bool {
|
|
266
|
-
return self.__jinfo.access_mode == AccessMode.READ_WRITE;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
impl Anchor.is_private -> bool {
|
|
270
|
-
return self.__jinfo.access_mode == AccessMode.PRIVATE;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
impl Anchor.is_readable
|
|
274
|
-
(caller_id: UUID) -> bool {
|
|
275
|
-
return (caller_id == self.owner_id
|
|
276
|
-
or |> self.is_public_read
|
|
277
|
-
or caller_id in self.ro_access
|
|
278
|
-
or caller_id in self.rw_access);
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
impl Anchor.is_writable
|
|
282
|
-
(caller_id: UUID) -> bool {
|
|
283
|
-
return (caller_id == self.owner_id or |> self.is_public_write or caller_id in self.rw_access);
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
impl Anchor.give_access
|
|
287
|
-
(caller_id: UUID, read_write: bool=False) {
|
|
288
|
-
if read_write {
|
|
289
|
-
caller_id |> self.rw_access.add;
|
|
290
|
-
} else {
|
|
291
|
-
caller_id |> add.>ro_access.>self;
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
impl Anchor.revoke_access
|
|
296
|
-
(caller_id: UUID) {
|
|
297
|
-
caller_id |> self.ro_access.discard;
|
|
298
|
-
caller_id |> self.rw_access.discard;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
impl Anchor.on_entry
|
|
302
|
-
(cls: type, triggers: list) {
|
|
303
|
-
def decorator(func: callable) -> callable {
|
|
304
|
-
cls.ds_entry_funcs.append(
|
|
305
|
-
{'types': triggers, 'func': func}
|
|
306
|
-
);
|
|
307
|
-
def wrapper(*args: list, **kwargs: dict) -> callable {
|
|
308
|
-
return func(*args, **kwargs);
|
|
309
|
-
}
|
|
310
|
-
return wrapper;
|
|
311
|
-
}
|
|
312
|
-
return decorator;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
impl Anchor.on_exit
|
|
316
|
-
(cls: type, triggers: list) {
|
|
317
|
-
def decorator(func: callable) -> callable {
|
|
318
|
-
cls.ds_exit_funcs.append(
|
|
319
|
-
{'types': triggers, 'func': func}
|
|
320
|
-
);
|
|
321
|
-
def wrapper(*args: list, **kwargs: dict) -> callable {
|
|
322
|
-
return func(*args, **kwargs);
|
|
323
|
-
}
|
|
324
|
-
return wrapper;
|
|
325
|
-
}
|
|
326
|
-
return decorator;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
impl NodeAnchor.connect_node
|
|
330
|
-
(nd: NodeInterface, edg: EdgeInterface) -> Node {
|
|
331
|
-
edg.attach(self, nd);
|
|
332
|
-
return self;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
impl NodeAnchor.edges_to_nodes
|
|
336
|
-
(dir: EdgeDir) -> list[Node] {
|
|
337
|
-
ret_nodes = [];
|
|
338
|
-
if dir in [EdgeDir.OUT, EdgeDir.ANY] {
|
|
339
|
-
for i in self.edges[EdgeDir.OUT] {
|
|
340
|
-
ret_nodes.append(i.target);
|
|
341
|
-
}
|
|
342
|
-
} elif dir in [EdgeDir.IN, EdgeDir.ANY] {
|
|
343
|
-
for i in self.edges[EdgeDir.IN] {
|
|
344
|
-
ret_nodes.append(i.source);
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
return ret_nodes;
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
impl EdgeAnchor.apply_dir
|
|
351
|
-
(dir: EdgeDir) -> Edge {
|
|
352
|
-
self.dir = dir;
|
|
353
|
-
return self;
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
impl EdgeAnchor.attach
|
|
357
|
-
(src: NodeInterface, trg: NodeInterface) -> Edge {
|
|
358
|
-
if self.dir == EdgeDir.IN {
|
|
359
|
-
self.source = trg;
|
|
360
|
-
self.target = src;
|
|
361
|
-
self :> src.edges[EdgeDir.IN].append;
|
|
362
|
-
self :> trg.edges[EdgeDir.OUT].append;
|
|
363
|
-
} else {
|
|
364
|
-
self.source = src;
|
|
365
|
-
self.target = trg;
|
|
366
|
-
self :> src.edges[EdgeDir.OUT].append;
|
|
367
|
-
self :> trg.edges[EdgeDir.IN].append;
|
|
368
|
-
}
|
|
369
|
-
return self;
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
impl WalkerAnchor.visit_node
|
|
373
|
-
(nds: list[Node] | list[Edge] | Node | Edge) {
|
|
374
|
-
if isinstance(nds, list) {
|
|
375
|
-
for i in nds {
|
|
376
|
-
if (i not in self.ignores) {
|
|
377
|
-
i :> self.next.append;
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
} elif nds not in self.ignores {
|
|
381
|
-
nds :> self.next.append;
|
|
382
|
-
}
|
|
383
|
-
return len(nds) if isinstance(nds, list) else 1;
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
impl WalkerAnchor.ignore_node
|
|
387
|
-
(nds: list[Node] | list[Edge] | Node | Edge) {
|
|
388
|
-
if isinstance(nds, list) {
|
|
389
|
-
for i in nds {
|
|
390
|
-
i :> self.ignores.append;
|
|
391
|
-
}
|
|
392
|
-
} else {
|
|
393
|
-
nds :> self.ignores.append;
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
impl WalkerAnchor.disengage_now {
|
|
398
|
-
self.next = [];
|
|
399
|
-
self.disengaged = True;
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
impl NodeAnchor.__call__
|
|
403
|
-
(walk: object) {
|
|
404
|
-
if not isinstance(walk.__jac__, WalkerAnchor) {
|
|
405
|
-
raise TypeError("Argument must be a Walker instance");
|
|
406
|
-
}
|
|
407
|
-
walk(self);
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
impl EdgeAnchor.__call__
|
|
411
|
-
(walk: EdgeInterface) {
|
|
412
|
-
if not isinstance(walk.__jac__, WalkerAnchor) {
|
|
413
|
-
raise TypeError("Argument must be a Walker instance");
|
|
414
|
-
}
|
|
415
|
-
walk(self.__jac__.target);
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
impl WalkerAnchor.__call__
|
|
419
|
-
(nd: NodeInterface) {
|
|
420
|
-
self.path = [];
|
|
421
|
-
self.next = [nd];
|
|
422
|
-
while len(self.next) {
|
|
423
|
-
nd = self.next.pop(0);
|
|
424
|
-
print(nd.__class__.__name__, self.ds_entry_funcs);
|
|
425
|
-
for i in nd.ds_entry_funcs {
|
|
426
|
-
if isinstance(self.ob, i.trigger) {
|
|
427
|
-
i.func(nd.ob, self);
|
|
428
|
-
}
|
|
429
|
-
if self.disengaged {
|
|
430
|
-
return;
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
for i in self.ds_entry_funcs {
|
|
434
|
-
if isinstance(nd.ob, i.trigger) {
|
|
435
|
-
i.func(self.ob, nd);
|
|
436
|
-
}
|
|
437
|
-
if self.disengaged {
|
|
438
|
-
return;
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
for i in self.ds_exit_funcs {
|
|
442
|
-
if isinstance(nd.ob, i.trigger) {
|
|
443
|
-
i.func(self.ob, nd);
|
|
444
|
-
}
|
|
445
|
-
if self.disengaged {
|
|
446
|
-
return;
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
for i in nd.ds_exit_funcs {
|
|
450
|
-
if isinstance(self.ob, i.trigger) {
|
|
451
|
-
i.func(nd.ob, self);
|
|
452
|
-
}
|
|
453
|
-
if self.disengaged {
|
|
454
|
-
return;
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
nd :> self.path.append;
|
|
458
|
-
}
|
|
459
|
-
self.ignores = [];
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
impl JacPlugin.bind_archetype
|
|
463
|
-
(arch: AT, arch_type: str, on_entry: list[DSFunc], on_exit: list[DSFunc]) -> bool {
|
|
464
|
-
match arch_type {
|
|
465
|
-
case 'obj':
|
|
466
|
-
arch.__jac__ = Anchor(
|
|
467
|
-
ob=arch,
|
|
468
|
-
ds_entry_funcs=on_entry,
|
|
469
|
-
ds_exit_funcs=on_exit
|
|
470
|
-
);
|
|
471
|
-
case 'node':
|
|
472
|
-
arch.__jac__ = NodeAnchor(
|
|
473
|
-
ob=arch,
|
|
474
|
-
ds_entry_funcs=on_entry,
|
|
475
|
-
ds_exit_funcs=on_exit
|
|
476
|
-
);
|
|
477
|
-
case 'edge':
|
|
478
|
-
arch.__jac__ = EdgeAnchor(
|
|
479
|
-
ob=arch,
|
|
480
|
-
ds_entry_funcs=on_entry,
|
|
481
|
-
ds_exit_funcs=on_exit
|
|
482
|
-
);
|
|
483
|
-
case 'walker':
|
|
484
|
-
arch.__jac__ = WalkerAnchor(
|
|
485
|
-
ob=arch,
|
|
486
|
-
ds_entry_funcs=on_entry,
|
|
487
|
-
ds_exit_funcs=on_exit
|
|
488
|
-
);
|
|
489
|
-
case _:
|
|
490
|
-
raise ("Invalid archetype type") :> TypeError;
|
|
491
|
-
}
|
|
492
|
-
return True;
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
impl JacPlugin.get_root() -> None {
|
|
496
|
-
return exec_ctx.get_root();
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
impl JacPlugin.build_edge
|
|
500
|
-
(edge_spec: tuple[int, Optional[type], Optional[tuple]]) -> Archetype {
|
|
501
|
-
if (not edge_spec[1]) {
|
|
502
|
-
edg_type = GenericEdge;
|
|
503
|
-
} else {
|
|
504
|
-
edg_type = edge_spec[1];
|
|
505
|
-
}
|
|
506
|
-
edg = edg_type(*(edge_spec[2])) if edge_spec[2] else edg_type();
|
|
507
|
-
edg.__jac__.apply_dir(edge_spec[0]);
|
|
508
|
-
return edg;
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
impl JacPlugin.connect
|
|
512
|
-
(left: T, right: T, edge_spec: tuple[int, Optional[type], Optional[tuple]]) -> Archetype {
|
|
513
|
-
edg = JacPlugin.build_edge(edge_spec);
|
|
514
|
-
left.connect_node(right.__jac__, edg.__jac__);
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
impl JacPlugin.visit_node
|
|
518
|
-
(walker_obj: Any, expr: Any) -> bool {
|
|
519
|
-
return walker_obj.__jac__.visit_node(expr);
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
glob expected_area = 78.53981633974483;
|
|
523
|
-
|
|
524
|
-
test a1 {
|
|
525
|
-
check assertAlmostEqual(calculate_area(RAD), expected_area);
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
test a2 {
|
|
529
|
-
c = Circle(RAD);
|
|
530
|
-
check assertAlmostEqual(c.area(), expected_area);
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
test a3 {
|
|
534
|
-
c = Circle(RAD);
|
|
535
|
-
check assertEqual(c.shape_type, ShapeType.CIRCLE);
|
|
536
|
-
}
|
|
537
|
-
with entry{
|
|
538
|
-
|
|
539
|
-
# try and finally stmt
|
|
540
|
-
try{
|
|
541
|
-
print("try block");
|
|
542
|
-
}finally{
|
|
543
|
-
print("finally block");
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
# try except else finally
|
|
549
|
-
'''Docstring for the try block''';
|
|
550
|
-
try{
|
|
551
|
-
print("try block");
|
|
552
|
-
}
|
|
553
|
-
# except{
|
|
554
|
-
# print("except block");
|
|
555
|
-
# }
|
|
556
|
-
|
|
557
|
-
# except_def: KW_EXCEPT expression (KW_AS NAME)? code_block
|
|
558
|
-
# is there any intention why here we compulsorily need to write type of exception in
|
|
559
|
-
|
|
560
|
-
except exception{
|
|
561
|
-
print("Hi from except block");
|
|
562
|
-
print("Hello from except block");
|
|
563
|
-
}
|
|
564
|
-
else{
|
|
565
|
-
print("Hi from else block");
|
|
566
|
-
print("Hello from else block");
|
|
567
|
-
}
|
|
568
|
-
finally{
|
|
569
|
-
print("Hi from finally block");
|
|
570
|
-
print("Hello finally block");
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
with entry{
|
|
577
|
-
root spawn W();
|
|
578
|
-
print([root-->-->(`?A)]);
|
|
579
|
-
print([root--> --> -->(`?A)]);
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
"""
|
|
583
|
-
Object instantiation and method invocation occur within the with entry { ... } block.
|
|
584
|
-
"""
|
|
585
|
-
with entry {
|
|
586
|
-
game = GuessTheNumberGame();
|
|
587
|
-
game.play();
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
with entry{
|
|
594
|
-
|
|
595
|
-
# try and finally stmt
|
|
596
|
-
try{
|
|
597
|
-
print("try block");
|
|
598
|
-
}finally{
|
|
599
|
-
print("finally block");
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
# try except else finally
|
|
605
|
-
'''Doc string of try except else finally.''';
|
|
606
|
-
try{
|
|
607
|
-
print("try block");
|
|
608
|
-
}
|
|
609
|
-
# except{
|
|
610
|
-
# print("except block");
|
|
611
|
-
# }
|
|
612
|
-
|
|
613
|
-
# except_def: KW_EXCEPT expression (KW_AS NAME)? code_block
|
|
614
|
-
# is there any intention why here we compulsorily need to write type of exception in
|
|
615
|
-
|
|
616
|
-
except exception{
|
|
617
|
-
;
|
|
618
|
-
;
|
|
619
|
-
}
|
|
620
|
-
else{
|
|
621
|
-
;
|
|
622
|
-
;
|
|
623
|
-
}
|
|
624
|
-
finally{
|
|
625
|
-
;
|
|
626
|
-
;
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
with entry{
|
|
633
|
-
root spawn W();
|
|
634
|
-
print([root-->-->(`?A)]);
|
|
635
|
-
print([root--> --> -->(`?A)]);
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
"""
|
|
639
|
-
Object instantiation and method invocation occur within the with entry { ... } block.
|
|
640
|
-
"""
|
|
641
|
-
with entry {
|
|
642
|
-
game = GuessTheNumberGame();
|
|
643
|
-
game.play();
|
|
644
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"""Test ast build pass module."""
|
|
2
|
-
|
|
3
|
-
import ast as ast3
|
|
4
|
-
import os
|
|
5
|
-
from difflib import unified_diff
|
|
6
|
-
|
|
7
|
-
import jaclang.compiler.unitree as uni
|
|
8
|
-
from jaclang.compiler.passes.tool import DocIRGenPass
|
|
9
|
-
from jaclang.compiler.program import JacProgram
|
|
10
|
-
from jaclang.utils.helpers import add_line_numbers
|
|
11
|
-
from jaclang.utils.test import AstSyncTestMixin, TestCase
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
class DocIrGenPassTests(TestCase, AstSyncTestMixin):
|
|
15
|
-
"""Test pass module."""
|
|
16
|
-
|
|
17
|
-
TargetPass = DocIRGenPass
|
|
18
|
-
|
|
19
|
-
def test_corelib_fmt(self) -> None:
|
|
20
|
-
"""Parse micro jac file."""
|
|
21
|
-
code_gen_format = JacProgram.jac_file_formatter(
|
|
22
|
-
self.fixture_abs_path("corelib.jac"))
|
|
23
|
-
print(code_gen_format)
|
|
24
|
-
|
|
25
|
-
def test_circle_fmt(self) -> None:
|
|
26
|
-
"""Parse micro jac file."""
|
|
27
|
-
code_gen_format = JacProgram.jac_file_formatter(
|
|
28
|
-
self.examples_abs_path("manual_code/circle.jac"))
|
|
29
|
-
print(code_gen_format)
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import snd_lev;
|
|
File without changes
|
|
File without changes
|