jaseci 1.4.2.5__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.

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