jaseci 1.4.2.6__py3-none-any.whl → 2.0.0__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 jaseci might be problematic. Click here for more details.
- jaseci/__init__.py +3 -37
- jaseci-2.0.0.dist-info/METADATA +65 -0
- jaseci-2.0.0.dist-info/RECORD +4 -0
- {jaseci-1.4.2.6.dist-info → jaseci-2.0.0.dist-info}/WHEEL +1 -2
- jaseci/VERSION +0 -1
- jaseci/cli_tools/__init__.py +0 -0
- jaseci/cli_tools/book_tools.py +0 -457
- jaseci/cli_tools/jsctl.py +0 -500
- jaseci/cli_tools/tests/__init__.py +0 -0
- jaseci/cli_tools/tests/test_jsctl.py +0 -556
- jaseci/extens/__init__.py +0 -0
- jaseci/extens/act_lib/__init__.py +0 -0
- jaseci/extens/act_lib/date.py +0 -118
- jaseci/extens/act_lib/elastic.py +0 -87
- jaseci/extens/act_lib/file.py +0 -77
- jaseci/extens/act_lib/file_handler.py +0 -190
- jaseci/extens/act_lib/internal.py +0 -19
- jaseci/extens/act_lib/jaseci.py +0 -62
- jaseci/extens/act_lib/mail.py +0 -10
- jaseci/extens/act_lib/maths.py +0 -168
- jaseci/extens/act_lib/net.py +0 -192
- jaseci/extens/act_lib/rand.py +0 -83
- jaseci/extens/act_lib/regex.py +0 -85
- jaseci/extens/act_lib/request.py +0 -170
- jaseci/extens/act_lib/std.py +0 -236
- jaseci/extens/act_lib/storage.py +0 -53
- jaseci/extens/act_lib/stripe.py +0 -338
- jaseci/extens/act_lib/task.py +0 -14
- jaseci/extens/act_lib/tests/__init__.py +0 -0
- jaseci/extens/act_lib/tests/std_test_code.py +0 -37
- jaseci/extens/act_lib/tests/test_date.py +0 -26
- jaseci/extens/act_lib/tests/test_elastic.py +0 -159
- jaseci/extens/act_lib/tests/test_file.py +0 -116
- jaseci/extens/act_lib/tests/test_file_lib.py +0 -40
- jaseci/extens/act_lib/tests/test_mail_lib.py +0 -33
- jaseci/extens/act_lib/tests/test_maths.py +0 -147
- jaseci/extens/act_lib/tests/test_net_lib.py +0 -62
- jaseci/extens/act_lib/tests/test_regex.py +0 -61
- jaseci/extens/act_lib/tests/test_std.py +0 -51
- jaseci/extens/act_lib/tests/test_std_lib.py +0 -36
- jaseci/extens/act_lib/tests/test_url.py +0 -32
- jaseci/extens/act_lib/tests/test_vector.py +0 -36
- jaseci/extens/act_lib/tests/test_webtool.py +0 -44
- jaseci/extens/act_lib/tests/test_zlib.py +0 -24
- jaseci/extens/act_lib/url.py +0 -80
- jaseci/extens/act_lib/vector.py +0 -158
- jaseci/extens/act_lib/webtool.py +0 -29
- jaseci/extens/act_lib/zip.py +0 -34
- jaseci/extens/api/__init__.py +0 -0
- jaseci/extens/api/actions_api.py +0 -171
- jaseci/extens/api/alias_api.py +0 -140
- jaseci/extens/api/architype_api.py +0 -197
- jaseci/extens/api/config_api.py +0 -129
- jaseci/extens/api/global_api.py +0 -85
- jaseci/extens/api/graph_api.py +0 -168
- jaseci/extens/api/health_api.py +0 -21
- jaseci/extens/api/interface.py +0 -269
- jaseci/extens/api/jac_api.py +0 -172
- jaseci/extens/api/jsorc_api.py +0 -317
- jaseci/extens/api/logger_api.py +0 -90
- jaseci/extens/api/master_api.py +0 -134
- jaseci/extens/api/object_api.py +0 -102
- jaseci/extens/api/prometheus_api.py +0 -75
- jaseci/extens/api/queue_api.py +0 -141
- jaseci/extens/api/sentinel_api.py +0 -271
- jaseci/extens/api/share_api.py +0 -64
- jaseci/extens/api/super_api.py +0 -65
- jaseci/extens/api/tests/__init__.py +0 -0
- jaseci/extens/api/tests/test_architype_api.py +0 -66
- jaseci/extens/api/tests/test_global_api.py +0 -179
- jaseci/extens/api/tests/test_graph_api.py +0 -64
- jaseci/extens/api/tests/test_logger_api.py +0 -43
- jaseci/extens/api/tests/test_object_api.py +0 -20
- jaseci/extens/api/tests/test_sentinel_api.py +0 -66
- jaseci/extens/api/tests/test_uncommon.py +0 -107
- jaseci/extens/api/tests/test_user_api.py +0 -32
- jaseci/extens/api/tests/test_walker_api.py +0 -316
- jaseci/extens/api/user_api.py +0 -166
- jaseci/extens/api/walker_api.py +0 -299
- jaseci/extens/api/webhook_api.py +0 -77
- jaseci/extens/svc/__init__.py +0 -0
- jaseci/extens/svc/elastic_svc.py +0 -366
- jaseci/extens/svc/kube_svc.py +0 -432
- jaseci/extens/svc/mail_svc.py +0 -156
- jaseci/extens/svc/prome_svc.py +0 -378
- jaseci/extens/svc/redis_svc.py +0 -63
- jaseci/extens/svc/storage_svc.py +0 -193
- jaseci/extens/svc/stripe_svc.py +0 -51
- jaseci/extens/svc/task_svc.py +0 -155
- jaseci/extens/svc/tasks.py +0 -302
- jaseci/jac/__init__.py +0 -0
- jaseci/jac/interpreter/__init__.py +0 -0
- jaseci/jac/interpreter/architype_interp.py +0 -219
- jaseci/jac/interpreter/interp.py +0 -1784
- jaseci/jac/interpreter/sentinel_interp.py +0 -260
- jaseci/jac/interpreter/tests/__init__.py +0 -0
- jaseci/jac/interpreter/tests/test_interp.py +0 -42
- jaseci/jac/interpreter/walker_interp.py +0 -249
- jaseci/jac/ir/__init__.py +0 -0
- jaseci/jac/ir/ast.py +0 -73
- jaseci/jac/ir/ast_builder.py +0 -249
- jaseci/jac/ir/jac_code.py +0 -151
- jaseci/jac/ir/passes/__init__.py +0 -6
- jaseci/jac/ir/passes/ast_prune_pass.py +0 -9
- jaseci/jac/ir/passes/codegen_pass.py +0 -244
- jaseci/jac/ir/passes/ir_pass.py +0 -29
- jaseci/jac/ir/passes/printer_pass.py +0 -23
- jaseci/jac/ir/passes/pt_prune_pass.py +0 -29
- jaseci/jac/ir/passes/schedule.py +0 -23
- jaseci/jac/ir/passes/stats_pass.py +0 -16
- jaseci/jac/jac.g4 +0 -450
- jaseci/jac/jac_parse/__init__.py +0 -0
- jaseci/jac/jac_parse/jacLexer.py +0 -809
- jaseci/jac/jac_parse/jacListener.py +0 -853
- jaseci/jac/jac_parse/jacParser.py +0 -9192
- jaseci/jac/jac_set.py +0 -120
- jaseci/jac/jsci_vm/__init__.py +0 -0
- jaseci/jac/jsci_vm/disasm.py +0 -94
- jaseci/jac/jsci_vm/inst_ptr.py +0 -31
- jaseci/jac/jsci_vm/machine.py +0 -188
- jaseci/jac/jsci_vm/op_codes.py +0 -82
- jaseci/jac/jsci_vm/tests/__init__.py +0 -0
- jaseci/jac/jsci_vm/tests/test_codegen.py +0 -31
- jaseci/jac/machine/__init__.py +0 -0
- jaseci/jac/machine/jac_scope.py +0 -86
- jaseci/jac/machine/jac_value.py +0 -227
- jaseci/jac/machine/machine_state.py +0 -386
- jaseci/jac/tests/__init__.py +0 -0
- jaseci/jac/tests/book_code.py +0 -624
- jaseci/jac/tests/test_book.py +0 -380
- jaseci/jac/tests/test_lang_14.py +0 -49
- jaseci/jsorc/__init__.py +0 -7
- jaseci/jsorc/jsorc.py +0 -642
- jaseci/jsorc/jsorc_settings.py +0 -211
- jaseci/jsorc/jsorc_utils.py +0 -298
- jaseci/jsorc/live_actions.py +0 -365
- jaseci/jsorc/manifests/__init__.py +0 -0
- jaseci/jsorc/manifests/database.yaml +0 -109
- jaseci/jsorc/manifests/elastic.yaml +0 -6029
- jaseci/jsorc/manifests/prometheus.yaml +0 -1383
- jaseci/jsorc/manifests/redis.yaml +0 -64
- jaseci/jsorc/memory.py +0 -258
- jaseci/jsorc/redis.py +0 -140
- jaseci/jsorc/remote_actions.py +0 -158
- jaseci/jsorc/tests/__init__.py +0 -0
- jaseci/jsorc/tests/test_actions.py +0 -542
- jaseci/jsorc/tests/test_jsorc.py +0 -112
- jaseci/prim/__init__.py +0 -0
- jaseci/prim/ability.py +0 -94
- jaseci/prim/architype.py +0 -90
- jaseci/prim/edge.py +0 -173
- jaseci/prim/element.py +0 -233
- jaseci/prim/graph.py +0 -27
- jaseci/prim/master.py +0 -67
- jaseci/prim/node.py +0 -533
- jaseci/prim/obj_mixins.py +0 -238
- jaseci/prim/sentinel.py +0 -282
- jaseci/prim/super_master.py +0 -31
- jaseci/prim/walker.py +0 -261
- jaseci/svc/__init__.py +0 -0
- jaseci/tests/__init__.py +0 -0
- jaseci/tests/infer.py +0 -39
- jaseci/tests/jac_test_code.py +0 -1293
- jaseci/tests/jac_test_progs.py +0 -774
- jaseci/tests/test_core.py +0 -153
- jaseci/tests/test_jac.py +0 -824
- jaseci/tests/test_node.py +0 -89
- jaseci/tests/test_progs.py +0 -702
- jaseci/tests/test_stack.py +0 -220
- jaseci/tests/test_stripe.py +0 -225
- jaseci/utils/__init__.py +0 -0
- jaseci/utils/actions/__init__.py +0 -0
- jaseci/utils/actions/actions_manager.py +0 -254
- jaseci/utils/actions/actions_optimizer.py +0 -517
- jaseci/utils/actions/actions_state.py +0 -95
- jaseci/utils/file_handler.py +0 -171
- jaseci/utils/gprof2dot.py +0 -3786
- jaseci/utils/id_list.py +0 -169
- jaseci/utils/json_handler.py +0 -70
- jaseci/utils/log_utils.py +0 -57
- jaseci/utils/test_core.py +0 -62
- jaseci/utils/utils.py +0 -387
- jaseci-1.4.2.6.dist-info/LICENSE +0 -21
- jaseci-1.4.2.6.dist-info/METADATA +0 -39
- jaseci-1.4.2.6.dist-info/RECORD +0 -185
- jaseci-1.4.2.6.dist-info/entry_points.txt +0 -3
- jaseci-1.4.2.6.dist-info/top_level.txt +0 -1
|
@@ -1,260 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Sentinel interpreter for jac code in AST form
|
|
3
|
-
|
|
4
|
-
This interpreter should be inhereted from the class that manages state
|
|
5
|
-
referenced through self.
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
from jaseci.prim.architype import Architype
|
|
9
|
-
from jaseci.jac.interpreter.interp import Interp
|
|
10
|
-
from jaseci.utils.utils import parse_str_token
|
|
11
|
-
from jaseci.jac.ir.jac_code import jac_ast_to_ir
|
|
12
|
-
from jaseci.jac.machine.jac_scope import JacScope
|
|
13
|
-
from jaseci.prim.ability import Ability
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
class SentinelInterp(Interp):
|
|
17
|
-
"""Jac interpreter mixin for objects that will execute Jac code"""
|
|
18
|
-
|
|
19
|
-
def run_start(self, jac_ast):
|
|
20
|
-
"""
|
|
21
|
-
start: ver_label? element* EOF;
|
|
22
|
-
"""
|
|
23
|
-
kid = self.set_cur_ast(jac_ast)
|
|
24
|
-
if kid[0].name == "ver_label":
|
|
25
|
-
self.run_ver_label(kid[0])
|
|
26
|
-
for i in kid:
|
|
27
|
-
self.run_element(i)
|
|
28
|
-
|
|
29
|
-
def run_ver_label(self, jac_ast):
|
|
30
|
-
"""
|
|
31
|
-
ver_label: 'version' COLON STRING;
|
|
32
|
-
"""
|
|
33
|
-
kid = self.set_cur_ast(jac_ast)
|
|
34
|
-
self.version = parse_str_token(kid[2].token_text())
|
|
35
|
-
|
|
36
|
-
def run_element(self, jac_ast):
|
|
37
|
-
"""
|
|
38
|
-
element: global_var | architype | test;
|
|
39
|
-
"""
|
|
40
|
-
kid = self.set_cur_ast(jac_ast)
|
|
41
|
-
if kid[0].name == "global_var":
|
|
42
|
-
self.load_global_var(kid[0])
|
|
43
|
-
elif kid[0].name == "architype":
|
|
44
|
-
self.load_architype(kid[0])
|
|
45
|
-
elif kid[0].name == "test":
|
|
46
|
-
self.load_test(kid[0])
|
|
47
|
-
|
|
48
|
-
def load_global_var(self, jac_ast):
|
|
49
|
-
"""
|
|
50
|
-
global_var:
|
|
51
|
-
KW_GLOBAL NAME EQ expression (COMMA NAME EQ expression)* SEMI;
|
|
52
|
-
"""
|
|
53
|
-
kid = self.set_cur_ast(jac_ast)
|
|
54
|
-
kid = kid[1:]
|
|
55
|
-
while kid[0].name == "NAME":
|
|
56
|
-
const_name = kid[0].token_text()
|
|
57
|
-
if const_name in self.global_vars:
|
|
58
|
-
self.rt_error(f"Global {const_name} already defined!", kid[0])
|
|
59
|
-
else:
|
|
60
|
-
self.run_expression(kid[2])
|
|
61
|
-
self.global_vars[const_name] = self.pop().value
|
|
62
|
-
kid = kid[4:] if kid[3].name == "COMMA" else kid[3:]
|
|
63
|
-
|
|
64
|
-
def load_architype(self, jac_ast):
|
|
65
|
-
"""
|
|
66
|
-
architype:
|
|
67
|
-
KW_NODE NAME (COLON NAME)* (COLON INT)? attr_block
|
|
68
|
-
| KW_EDGE NAME (COLON NAME)* attr_block
|
|
69
|
-
| KW_GRAPH NAME graph_block
|
|
70
|
-
| KW_ASYNC? KW_WALKER NAME namespaces? walker_block;
|
|
71
|
-
"""
|
|
72
|
-
kid = self.set_cur_ast(jac_ast)
|
|
73
|
-
|
|
74
|
-
is_async = kid[0].name == "KW_ASYNC" and bool(kid.pop(0))
|
|
75
|
-
|
|
76
|
-
name = kid[1].token_text()
|
|
77
|
-
kind = kid[0].token_text()
|
|
78
|
-
arch = Architype(
|
|
79
|
-
m_id=self._m_id,
|
|
80
|
-
h=self._h,
|
|
81
|
-
code_ir=jac_ast,
|
|
82
|
-
name=name,
|
|
83
|
-
kind=kind,
|
|
84
|
-
is_async=is_async,
|
|
85
|
-
parent=self,
|
|
86
|
-
)
|
|
87
|
-
|
|
88
|
-
if len(kid) > 2 and kid[2].name == "COLON":
|
|
89
|
-
for i in kid[2:]:
|
|
90
|
-
if i.name == "NAME":
|
|
91
|
-
arch.super_archs.append(i.token_text())
|
|
92
|
-
if self.arch_ids.has_obj_by_name(arch.name, kind=arch.kind):
|
|
93
|
-
self.arch_ids.destroy_obj_by_name(arch.name, kind=arch.kind)
|
|
94
|
-
self.arch_ids.add_obj(arch)
|
|
95
|
-
self.arch_has_preproc(kid[-1], arch)
|
|
96
|
-
self.arch_can_compile(kid[-1], arch)
|
|
97
|
-
return arch
|
|
98
|
-
|
|
99
|
-
# Note: Sentinels only registers the attr_stmts
|
|
100
|
-
|
|
101
|
-
def arch_has_preproc(self, jac_ast, arch):
|
|
102
|
-
"""Helper function to statically compile can stmts for arch"""
|
|
103
|
-
kid = self.set_cur_ast(jac_ast)
|
|
104
|
-
if jac_ast.name in ["attr_block", "walker_block"]:
|
|
105
|
-
for i in kid:
|
|
106
|
-
if i.name == "attr_stmt" and i.kid[0].name == "has_stmt":
|
|
107
|
-
for j in i.kid[0].kid:
|
|
108
|
-
if j.name == "has_assign":
|
|
109
|
-
has_kid = j.kid
|
|
110
|
-
is_private = False
|
|
111
|
-
is_anchor = False
|
|
112
|
-
if has_kid[0].name == "KW_PRIVATE":
|
|
113
|
-
has_kid = has_kid[1:]
|
|
114
|
-
is_private = True
|
|
115
|
-
if has_kid[0].name == "KW_ANCHOR":
|
|
116
|
-
has_kid = has_kid[1:]
|
|
117
|
-
is_anchor = True
|
|
118
|
-
var_name = has_kid[0].token_text()
|
|
119
|
-
if is_private:
|
|
120
|
-
arch.private_vars.append(var_name)
|
|
121
|
-
if is_anchor and arch.anchor_var is None:
|
|
122
|
-
arch.anchor_var = var_name
|
|
123
|
-
arch.has_vars.append(var_name)
|
|
124
|
-
arch.save()
|
|
125
|
-
|
|
126
|
-
def arch_can_compile(self, jac_ast, arch):
|
|
127
|
-
"""Helper function to statically compile can stmts for arch"""
|
|
128
|
-
kid = self.set_cur_ast(jac_ast)
|
|
129
|
-
self.push_scope(
|
|
130
|
-
JacScope(parent=self, name=f"a_cgen:{jac_ast.loc_str()}", has_obj=None)
|
|
131
|
-
)
|
|
132
|
-
if jac_ast.name in ["attr_block", "walker_block"]:
|
|
133
|
-
for i in kid:
|
|
134
|
-
if i.name == "attr_stmt" and i.kid[0].name == "can_stmt":
|
|
135
|
-
self.run_can_stmt(i.kid[0], arch)
|
|
136
|
-
elif jac_ast.name == "graph_block":
|
|
137
|
-
self.run_can_block(jac_ast.kid[2], arch)
|
|
138
|
-
self.pop_scope()
|
|
139
|
-
|
|
140
|
-
def run_can_block(self, jac_ast, arch):
|
|
141
|
-
"""
|
|
142
|
-
can_block: (can_stmt)*;
|
|
143
|
-
"""
|
|
144
|
-
kid = self.set_cur_ast(jac_ast)
|
|
145
|
-
for i in kid:
|
|
146
|
-
if i.name == "can_stmt":
|
|
147
|
-
self.run_can_stmt(i, arch)
|
|
148
|
-
|
|
149
|
-
def run_can_stmt(self, jac_ast, obj):
|
|
150
|
-
"""
|
|
151
|
-
can_stmt:
|
|
152
|
-
KW_CAN dotted_name (preset_in_out event_clause)? (
|
|
153
|
-
COMMA dotted_name (preset_in_out event_clause)?
|
|
154
|
-
)* SEMI
|
|
155
|
-
| KW_CAN NAME event_clause? code_block;
|
|
156
|
-
"""
|
|
157
|
-
kid = self.set_cur_ast(jac_ast)
|
|
158
|
-
kid = kid[1:]
|
|
159
|
-
ir = None
|
|
160
|
-
while True:
|
|
161
|
-
action_type = "activity"
|
|
162
|
-
access_list = None
|
|
163
|
-
preset_in_out = None
|
|
164
|
-
if kid[0].name == "NAME":
|
|
165
|
-
action_name = kid[0].token_text()
|
|
166
|
-
else:
|
|
167
|
-
action_name = self.run_dotted_name(kid[0])
|
|
168
|
-
kid = kid[1:]
|
|
169
|
-
if len(kid) > 0 and kid[0].name == "preset_in_out":
|
|
170
|
-
preset_in_out = jac_ast_to_ir(kid[0])
|
|
171
|
-
kid = kid[1:]
|
|
172
|
-
if len(kid) > 0 and kid[0].name == "event_clause":
|
|
173
|
-
action_type, access_list = self.run_event_clause(kid[0])
|
|
174
|
-
kid = kid[1:]
|
|
175
|
-
if kid[0].name != "code_block":
|
|
176
|
-
self.check_builtin_action(action_name, jac_ast)
|
|
177
|
-
else:
|
|
178
|
-
ir = kid[0]
|
|
179
|
-
getattr(obj, f"{action_type}_ability_ids").add_obj(
|
|
180
|
-
Ability(
|
|
181
|
-
m_id=self._m_id,
|
|
182
|
-
h=self._h,
|
|
183
|
-
name=action_name,
|
|
184
|
-
kind="ability",
|
|
185
|
-
code_ir=ir,
|
|
186
|
-
preset_in_out=preset_in_out,
|
|
187
|
-
access_list=access_list,
|
|
188
|
-
parent=self,
|
|
189
|
-
)
|
|
190
|
-
)
|
|
191
|
-
if not len(kid) or kid[0].name != "COMMA":
|
|
192
|
-
break
|
|
193
|
-
else:
|
|
194
|
-
kid = kid[1:]
|
|
195
|
-
|
|
196
|
-
def run_event_clause(self, jac_ast):
|
|
197
|
-
"""
|
|
198
|
-
event_clause:
|
|
199
|
-
KW_WITH name_list? (KW_ENTRY | KW_EXIT | KW_ACTIVITY);
|
|
200
|
-
"""
|
|
201
|
-
kid = self.set_cur_ast(jac_ast)
|
|
202
|
-
nl = []
|
|
203
|
-
if kid[1].name == "name_list":
|
|
204
|
-
nl = self.run_name_list(kid[1])
|
|
205
|
-
return kid[-1].token_text(), nl
|
|
206
|
-
|
|
207
|
-
def load_test(self, jac_ast):
|
|
208
|
-
"""
|
|
209
|
-
test:
|
|
210
|
-
KW_TEST NAME? multistring KW_WITH (
|
|
211
|
-
graph_ref
|
|
212
|
-
| KW_GRAPH graph_block
|
|
213
|
-
) KW_BY (
|
|
214
|
-
(walker_ref spawn_ctx? (code_block | SEMI))
|
|
215
|
-
| KW_WALKER walker_block
|
|
216
|
-
);
|
|
217
|
-
"""
|
|
218
|
-
kid = self.set_cur_ast(jac_ast)
|
|
219
|
-
(
|
|
220
|
-
self.run_multistring(kid[2])
|
|
221
|
-
if kid[1].name == "NAME"
|
|
222
|
-
else self.run_multistring(kid[1])
|
|
223
|
-
)
|
|
224
|
-
testcase = {
|
|
225
|
-
"name": kid[1].token_text() if kid[1].name == "NAME" else "",
|
|
226
|
-
"title": self.pop().value,
|
|
227
|
-
"graph_ref": None,
|
|
228
|
-
"graph_block": None,
|
|
229
|
-
"walker_ref": None,
|
|
230
|
-
"spawn_ctx": None,
|
|
231
|
-
"assert_block": None,
|
|
232
|
-
"walker_block": None,
|
|
233
|
-
"outcome": None,
|
|
234
|
-
}
|
|
235
|
-
kid = kid[4:] if kid[1].name == "NAME" else kid[3:]
|
|
236
|
-
if kid[0].name == "graph_ref":
|
|
237
|
-
graph_name = kid[0].kid[-1].token_text()
|
|
238
|
-
if not self.arch_ids.has_obj_by_name(graph_name, kind="graph"):
|
|
239
|
-
self.rt_error(f"Graph {graph_name} not found!", kid[0])
|
|
240
|
-
testcase["graph_ref"] = graph_name
|
|
241
|
-
else:
|
|
242
|
-
kid = kid[1:]
|
|
243
|
-
testcase["graph_block"] = jac_ast_to_ir(kid[0])
|
|
244
|
-
kid = kid[2:]
|
|
245
|
-
if kid[0].name == "walker_ref":
|
|
246
|
-
walker_name = kid[0].kid[-1].token_text()
|
|
247
|
-
if not self.arch_ids.has_obj_by_name(name=walker_name, kind="walker"):
|
|
248
|
-
self.rt_error(f"Walker {walker_name} not found!", kid[0])
|
|
249
|
-
testcase["walker_ref"] = walker_name
|
|
250
|
-
kid = kid[1:]
|
|
251
|
-
if kid[0].name == "spawn_ctx":
|
|
252
|
-
testcase["spawn_ctx"] = jac_ast_to_ir(kid[0])
|
|
253
|
-
kid = kid[1:]
|
|
254
|
-
if kid[0].name == "code_block":
|
|
255
|
-
testcase["assert_block"] = jac_ast_to_ir(kid[0])
|
|
256
|
-
else:
|
|
257
|
-
kid = kid[1:]
|
|
258
|
-
testcase["walker_block"] = jac_ast_to_ir(kid[0])
|
|
259
|
-
|
|
260
|
-
self.testcases.append(testcase)
|
|
File without changes
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
from jaseci.utils.test_core import CoreTest
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
class InterpreterTest(CoreTest):
|
|
5
|
-
"""Unit tests for Jac Interpreter / Language features"""
|
|
6
|
-
|
|
7
|
-
fixture_src = __file__
|
|
8
|
-
|
|
9
|
-
def test_quick_check(self):
|
|
10
|
-
ret = self.call(
|
|
11
|
-
self.mast,
|
|
12
|
-
["sentinel_register", {"code": self.load_jac("lang_features.jac")}],
|
|
13
|
-
)
|
|
14
|
-
ret = self.call(self.mast, ["walker_run", {"name": "quick_check"}])
|
|
15
|
-
self.assertEqual(ret["report"][0], "edge5")
|
|
16
|
-
|
|
17
|
-
def test_has_var_plucking(self):
|
|
18
|
-
ret = self.call(
|
|
19
|
-
self.mast,
|
|
20
|
-
["sentinel_register", {"code": self.load_jac("lang_features.jac")}],
|
|
21
|
-
)
|
|
22
|
-
ret = self.call(self.mast, ["walker_run", {"name": "has_var_plucking"}])
|
|
23
|
-
self.assertEqual(
|
|
24
|
-
ret["report"], [["node0", "node1", "node2"], ["edge0", "edge1", "edge2"]]
|
|
25
|
-
)
|
|
26
|
-
|
|
27
|
-
def test_deref_adaptive(self):
|
|
28
|
-
ret = self.call(
|
|
29
|
-
self.mast,
|
|
30
|
-
["sentinel_register", {"code": self.load_jac("lang_features.jac")}],
|
|
31
|
-
)
|
|
32
|
-
ret = self.call(self.mast, ["walker_run", {"name": "deref_adaptive"}])
|
|
33
|
-
self.assertTrue(ret["report"][0].startswith("junk and stuff"))
|
|
34
|
-
self.assertEqual(ret["report"][1], {"name": "node0"})
|
|
35
|
-
|
|
36
|
-
def test_deref_of_element_fails(self):
|
|
37
|
-
ret = self.call(
|
|
38
|
-
self.mast,
|
|
39
|
-
["sentinel_register", {"code": self.load_jac("lang_features.jac")}],
|
|
40
|
-
)
|
|
41
|
-
ret = self.call(self.mast, ["walker_run", {"name": "deref_of_element_fails"}])
|
|
42
|
-
self.assertFalse(ret["success"])
|
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Walker interpreter for jac code in AST form
|
|
3
|
-
|
|
4
|
-
This interpreter should be inhereted from the class that manages state
|
|
5
|
-
referenced through self.
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
from jaseci.prim.node import Node
|
|
9
|
-
from jaseci.jac.interpreter.interp import Interp
|
|
10
|
-
from jaseci.jac.jac_set import JacSet
|
|
11
|
-
from jaseci.jac.machine.jac_scope import JacScope
|
|
12
|
-
from jaseci.jac.ir.jac_code import jac_ir_to_ast
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
class WalkerInterp(Interp):
|
|
16
|
-
"""Jac interpreter mixin for objects that will execute Jac code"""
|
|
17
|
-
|
|
18
|
-
# Walker only executes statements, sentinels handle attr_stmts
|
|
19
|
-
|
|
20
|
-
def run_walker(self, jac_ast):
|
|
21
|
-
"""
|
|
22
|
-
walker: KW_ASYNC? KW_WALKER NAME namespaces? walker_block;
|
|
23
|
-
"""
|
|
24
|
-
kid = self.set_cur_ast(jac_ast)
|
|
25
|
-
self.scope_and_run(
|
|
26
|
-
jac_ast if jac_ast.name == "walker_block" else kid[-1],
|
|
27
|
-
self.run_walker_block,
|
|
28
|
-
scope_name=f"w_run:{jac_ast.loc_str()}",
|
|
29
|
-
)
|
|
30
|
-
|
|
31
|
-
def run_walker_block(self, jac_ast):
|
|
32
|
-
"""
|
|
33
|
-
walker_block:
|
|
34
|
-
LBRACE attr_stmt* walk_entry_block? (
|
|
35
|
-
statement
|
|
36
|
-
| walk_activity_block
|
|
37
|
-
)* walk_exit_block? RBRACE;
|
|
38
|
-
"""
|
|
39
|
-
kid = self.set_cur_ast(jac_ast)
|
|
40
|
-
act_list = self.current_node.get_architype().get_entry_abilities()
|
|
41
|
-
self.auto_trigger_node_actions(act_list=act_list)
|
|
42
|
-
|
|
43
|
-
for i in kid:
|
|
44
|
-
if i.name == "walk_entry_block":
|
|
45
|
-
self.run_walk_entry_block(i)
|
|
46
|
-
if i.name == "statement":
|
|
47
|
-
self.run_statement(i)
|
|
48
|
-
if i.name == "walk_activity_block":
|
|
49
|
-
self.run_walk_activity_block(i)
|
|
50
|
-
|
|
51
|
-
act_list = self.current_node.get_architype().get_exit_abilities()
|
|
52
|
-
self.auto_trigger_node_actions(act_list=act_list)
|
|
53
|
-
|
|
54
|
-
if not self.yielded and kid[-2].name == "walk_exit_block":
|
|
55
|
-
self.run_walk_exit_block(kid[-2])
|
|
56
|
-
|
|
57
|
-
def run_node_ctx_block(self, jac_ast):
|
|
58
|
-
"""
|
|
59
|
-
node_ctx_block: name_list code_block;
|
|
60
|
-
"""
|
|
61
|
-
kid = self.set_cur_ast(jac_ast)
|
|
62
|
-
for i in self.run_name_list(kid[0]):
|
|
63
|
-
if self.current_node.get_architype().is_instance(i):
|
|
64
|
-
self.run_code_block(kid[1])
|
|
65
|
-
return
|
|
66
|
-
|
|
67
|
-
def run_walk_entry_block(self, jac_ast):
|
|
68
|
-
"""
|
|
69
|
-
walk_entry_block: KW_WITH KW_ENTRY code_block;
|
|
70
|
-
"""
|
|
71
|
-
kid = self.set_cur_ast(jac_ast)
|
|
72
|
-
if self.current_step == 0:
|
|
73
|
-
self.in_entry_exit = True
|
|
74
|
-
self.run_code_block(kid[2])
|
|
75
|
-
self.in_entry_exit = False
|
|
76
|
-
|
|
77
|
-
def run_walk_exit_block(self, jac_ast):
|
|
78
|
-
"""
|
|
79
|
-
walk_exit_block: KW_WITH KW_EXIT code_block;
|
|
80
|
-
"""
|
|
81
|
-
kid = self.set_cur_ast(jac_ast)
|
|
82
|
-
self._stopped = None
|
|
83
|
-
if len(self.next_node_ids) == 0:
|
|
84
|
-
self.in_entry_exit = True
|
|
85
|
-
self.run_code_block(kid[2])
|
|
86
|
-
self.in_entry_exit = False
|
|
87
|
-
|
|
88
|
-
def run_walk_activity_block(self, jac_ast):
|
|
89
|
-
"""
|
|
90
|
-
walk_activity_block: KW_WITH KW_ACTIVITY code_block;
|
|
91
|
-
"""
|
|
92
|
-
kid = self.set_cur_ast(jac_ast)
|
|
93
|
-
self.run_code_block(kid[2])
|
|
94
|
-
|
|
95
|
-
def run_walker_action(self, jac_ast):
|
|
96
|
-
"""
|
|
97
|
-
walker_action:
|
|
98
|
-
ignore_action
|
|
99
|
-
| take_action
|
|
100
|
-
| disengage_action
|
|
101
|
-
| yield_action;
|
|
102
|
-
"""
|
|
103
|
-
kid = self.set_cur_ast(jac_ast)
|
|
104
|
-
expr_func = getattr(self, f"run_{kid[0].name}")
|
|
105
|
-
expr_func(kid[0])
|
|
106
|
-
|
|
107
|
-
def run_ignore_action(self, jac_ast):
|
|
108
|
-
"""
|
|
109
|
-
ignore_action: KW_IGNORE expression SEMI;
|
|
110
|
-
"""
|
|
111
|
-
kid = self.set_cur_ast(jac_ast)
|
|
112
|
-
self.run_expression(kid[1])
|
|
113
|
-
result = self.pop().value
|
|
114
|
-
if isinstance(result, Node):
|
|
115
|
-
self.ignore_node_ids.add_obj(result)
|
|
116
|
-
elif isinstance(result, JacSet):
|
|
117
|
-
self.ignore_node_ids.add_obj_list(result)
|
|
118
|
-
else:
|
|
119
|
-
self.rt_error(f"{result} is not ignorable type (i.e., nodes)", kid[1])
|
|
120
|
-
|
|
121
|
-
def run_take_action(self, jac_ast):
|
|
122
|
-
"""
|
|
123
|
-
take_action:
|
|
124
|
-
KW_TAKE (COLON NAME)? expression (SEMI | else_stmt);
|
|
125
|
-
"""
|
|
126
|
-
kid = self.set_cur_ast(jac_ast)
|
|
127
|
-
style = "b"
|
|
128
|
-
if kid[1].name == "COLON":
|
|
129
|
-
style = kid[2].token_text()
|
|
130
|
-
kid = kid[2:]
|
|
131
|
-
self.run_expression(kid[1])
|
|
132
|
-
result = self.pop().value
|
|
133
|
-
before = len(self.next_node_ids)
|
|
134
|
-
if isinstance(result, Node):
|
|
135
|
-
if style in ["b", "bfs"]:
|
|
136
|
-
self.next_node_ids.add_obj(result, allow_dups=True)
|
|
137
|
-
elif style in ["d", "dfs"]:
|
|
138
|
-
self.next_node_ids.add_obj(result, push_front=True, allow_dups=True)
|
|
139
|
-
else:
|
|
140
|
-
self.rt_error(f"{style} is invalid take operation", kid[0])
|
|
141
|
-
elif isinstance(result, JacSet):
|
|
142
|
-
if style in ["b", "bfs"]:
|
|
143
|
-
self.next_node_ids.add_obj_list(result, allow_dups=True)
|
|
144
|
-
elif style in ["d", "dfs"]:
|
|
145
|
-
self.next_node_ids.add_obj_list(
|
|
146
|
-
result, push_front=True, allow_dups=True
|
|
147
|
-
)
|
|
148
|
-
else:
|
|
149
|
-
self.rt_error(f"{style} is invalid take operation", kid[0])
|
|
150
|
-
elif result:
|
|
151
|
-
self.rt_error(f"{result} is not destination type (i.e., nodes)", kid[1])
|
|
152
|
-
after = len(self.next_node_ids)
|
|
153
|
-
if before >= after and kid[2].name == "else_stmt":
|
|
154
|
-
self.run_else_stmt(kid[2])
|
|
155
|
-
after = len(self.next_node_ids)
|
|
156
|
-
|
|
157
|
-
def run_disengage_action(self, jac_ast):
|
|
158
|
-
"""
|
|
159
|
-
disengage_action: KW_DISENGAGE (report_action | SEMI);
|
|
160
|
-
"""
|
|
161
|
-
kid = self.set_cur_ast(jac_ast)
|
|
162
|
-
if kid[1].name == "report_action":
|
|
163
|
-
self.run_report_action(kid[1])
|
|
164
|
-
self._stopped = "stop"
|
|
165
|
-
self.next_node_ids.remove_all()
|
|
166
|
-
|
|
167
|
-
def run_yield_action(self, jac_ast):
|
|
168
|
-
"""
|
|
169
|
-
yield_action:
|
|
170
|
-
KW_YIELD (
|
|
171
|
-
report_action
|
|
172
|
-
| disengage_action
|
|
173
|
-
| take_action
|
|
174
|
-
| SEMI
|
|
175
|
-
);
|
|
176
|
-
"""
|
|
177
|
-
kid = self.set_cur_ast(jac_ast)
|
|
178
|
-
if len(kid) and kid[1].name != "SEMI":
|
|
179
|
-
expr_func = getattr(self, f"run_{kid[1].name}")
|
|
180
|
-
expr_func(kid[1])
|
|
181
|
-
self.yield_walk()
|
|
182
|
-
|
|
183
|
-
def run_preset_in_out(self, jac_ast, act):
|
|
184
|
-
"""
|
|
185
|
-
preset_in_out:
|
|
186
|
-
DBL_COLON param_list? (DBL_COLON | COLON_OUT expression);
|
|
187
|
-
|
|
188
|
-
obj: The node or edge with preset
|
|
189
|
-
act: The action associated with preset
|
|
190
|
-
"""
|
|
191
|
-
kid = self.set_cur_ast(jac_ast)
|
|
192
|
-
param_list = {"args": [], "kwargs": []}
|
|
193
|
-
self.push_scope(
|
|
194
|
-
JacScope(
|
|
195
|
-
parent=self,
|
|
196
|
-
name=f"p_in_out:{jac_ast.loc_str()}",
|
|
197
|
-
has_obj=self.current_node,
|
|
198
|
-
here=self.current_node,
|
|
199
|
-
visitor=self,
|
|
200
|
-
)
|
|
201
|
-
)
|
|
202
|
-
|
|
203
|
-
if kid[1].name == "param_list":
|
|
204
|
-
param_list = self.run_param_list(kid[1]).value
|
|
205
|
-
try:
|
|
206
|
-
result = act.run_action(param_list, self._jac_scope, self, jac_ast)
|
|
207
|
-
except Exception as e:
|
|
208
|
-
self.rt_error(e, jac_ast)
|
|
209
|
-
if kid[-1].name == "expression":
|
|
210
|
-
self.run_expression(kid[-1])
|
|
211
|
-
dest = self.pop()
|
|
212
|
-
dest.value = result
|
|
213
|
-
dest.write(kid[-1])
|
|
214
|
-
self.pop_scope()
|
|
215
|
-
|
|
216
|
-
# Helper Functions ##################
|
|
217
|
-
def auto_trigger_node_actions(self, act_list):
|
|
218
|
-
already_executed = [] # handles inhereted duplicates, (overriding)
|
|
219
|
-
nd = self.current_node
|
|
220
|
-
for i in act_list.obj_list():
|
|
221
|
-
if (
|
|
222
|
-
i.access_list
|
|
223
|
-
and self.name not in i.access_list
|
|
224
|
-
or i.name in already_executed
|
|
225
|
-
):
|
|
226
|
-
continue
|
|
227
|
-
if i.preset_in_out:
|
|
228
|
-
self.run_preset_in_out(jac_ir_to_ast(i.preset_in_out), i)
|
|
229
|
-
else:
|
|
230
|
-
self.call_ability(nd=nd, name=i.name, act_list=act_list)
|
|
231
|
-
if not i.preset_in_out: # All preset in and outs get executed
|
|
232
|
-
already_executed.append(i.name)
|
|
233
|
-
|
|
234
|
-
def scope_and_run(self, jac_ast, run_func, scope_name):
|
|
235
|
-
"""
|
|
236
|
-
Helper to run ast elements with execution scope added
|
|
237
|
-
(Useful for running arbitrary code blocks as one-offs)
|
|
238
|
-
"""
|
|
239
|
-
self.push_scope(
|
|
240
|
-
JacScope(
|
|
241
|
-
parent=self,
|
|
242
|
-
name=scope_name,
|
|
243
|
-
has_obj=self,
|
|
244
|
-
here=self.current_node,
|
|
245
|
-
visitor=self,
|
|
246
|
-
)
|
|
247
|
-
)
|
|
248
|
-
run_func(jac_ast)
|
|
249
|
-
self.pop_scope()
|
jaseci/jac/ir/__init__.py
DELETED
|
File without changes
|
jaseci/jac/ir/ast.py
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
AST for Jac
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
|
-
from jaseci.utils.utils import logger
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class Ast:
|
|
9
|
-
"""
|
|
10
|
-
AST Nodes
|
|
11
|
-
"""
|
|
12
|
-
|
|
13
|
-
def __init__(
|
|
14
|
-
self,
|
|
15
|
-
mod_name,
|
|
16
|
-
):
|
|
17
|
-
self.name = "unparsed"
|
|
18
|
-
self.kid = []
|
|
19
|
-
self.loc = [
|
|
20
|
-
0,
|
|
21
|
-
0,
|
|
22
|
-
mod_name if mod_name is not None else "@default",
|
|
23
|
-
{},
|
|
24
|
-
] # line, col, module, tokens
|
|
25
|
-
|
|
26
|
-
def is_terminal(self):
|
|
27
|
-
"""Returns true if node is a terminal"""
|
|
28
|
-
return len(self.loc[3].keys())
|
|
29
|
-
|
|
30
|
-
def token(self):
|
|
31
|
-
if not self.is_terminal():
|
|
32
|
-
logger.error(str(f"Non terminals (rules) don't have token info - {self}"))
|
|
33
|
-
return None
|
|
34
|
-
else:
|
|
35
|
-
return self.loc[3]["token"]
|
|
36
|
-
|
|
37
|
-
def token_text(self):
|
|
38
|
-
if self.is_terminal():
|
|
39
|
-
return self.token()["text"]
|
|
40
|
-
|
|
41
|
-
def token_symbol(self):
|
|
42
|
-
if self.is_terminal():
|
|
43
|
-
return self.token()["symbol"]
|
|
44
|
-
|
|
45
|
-
def loc_str(self):
|
|
46
|
-
return f"{self.loc[2]}:{self.loc[0]}"
|
|
47
|
-
|
|
48
|
-
def __str__(self):
|
|
49
|
-
res = f"{self.name}:{self.loc[2]}:{self.loc[0]}:{self.loc[1]}:"
|
|
50
|
-
if self.is_terminal():
|
|
51
|
-
res += f':{self.loc[3]["token"]["text"]}'
|
|
52
|
-
return res
|
|
53
|
-
|
|
54
|
-
def __repr__(self):
|
|
55
|
-
return self.__str__()
|
|
56
|
-
|
|
57
|
-
def get_tokens(self):
|
|
58
|
-
"""Return list of all tokens derived from this ast node"""
|
|
59
|
-
tokens = []
|
|
60
|
-
if "token" in self.loc[3]:
|
|
61
|
-
tokens.append(self.loc[3]["token"])
|
|
62
|
-
return tokens
|
|
63
|
-
else:
|
|
64
|
-
for i in self.kid:
|
|
65
|
-
tokens = tokens + i.get_tokens()
|
|
66
|
-
return tokens
|
|
67
|
-
|
|
68
|
-
def get_text(self):
|
|
69
|
-
"""Get source text for this node"""
|
|
70
|
-
ret = ""
|
|
71
|
-
for i in self.get_tokens():
|
|
72
|
-
ret += f"{i['text']} "
|
|
73
|
-
return ret
|