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.
- 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.5.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 -117
- jaseci/extens/act_lib/elastic.py +0 -87
- jaseci/extens/act_lib/file.py +0 -76
- jaseci/extens/act_lib/file_handler.py +0 -189
- jaseci/extens/act_lib/internal.py +0 -18
- jaseci/extens/act_lib/jaseci.py +0 -61
- jaseci/extens/act_lib/mail.py +0 -10
- jaseci/extens/act_lib/maths.py +0 -168
- jaseci/extens/act_lib/net.py +0 -191
- jaseci/extens/act_lib/rand.py +0 -82
- jaseci/extens/act_lib/regex.py +0 -85
- jaseci/extens/act_lib/request.py +0 -169
- jaseci/extens/act_lib/std.py +0 -235
- jaseci/extens/act_lib/storage.py +0 -53
- jaseci/extens/act_lib/stripe.py +0 -337
- jaseci/extens/act_lib/task.py +0 -13
- 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 -79
- jaseci/extens/act_lib/vector.py +0 -157
- jaseci/extens/act_lib/webtool.py +0 -28
- jaseci/extens/act_lib/zip.py +0 -33
- jaseci/extens/api/__init__.py +0 -0
- jaseci/extens/api/actions_api.py +0 -170
- jaseci/extens/api/alias_api.py +0 -139
- jaseci/extens/api/architype_api.py +0 -196
- jaseci/extens/api/config_api.py +0 -129
- jaseci/extens/api/global_api.py +0 -84
- jaseci/extens/api/graph_api.py +0 -167
- jaseci/extens/api/health_api.py +0 -20
- jaseci/extens/api/interface.py +0 -268
- jaseci/extens/api/jac_api.py +0 -171
- jaseci/extens/api/jsorc_api.py +0 -316
- jaseci/extens/api/logger_api.py +0 -89
- jaseci/extens/api/master_api.py +0 -133
- jaseci/extens/api/object_api.py +0 -101
- jaseci/extens/api/prometheus_api.py +0 -74
- jaseci/extens/api/queue_api.py +0 -140
- jaseci/extens/api/sentinel_api.py +0 -270
- jaseci/extens/api/super_api.py +0 -64
- 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 -144
- jaseci/extens/api/walker_api.py +0 -298
- jaseci/extens/api/webhook_api.py +0 -74
- 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 -214
- jaseci/jac/interpreter/interp.py +0 -1783
- jaseci/jac/interpreter/sentinel_interp.py +0 -257
- jaseci/jac/interpreter/tests/__init__.py +0 -0
- jaseci/jac/interpreter/tests/test_interp.py +0 -42
- jaseci/jac/interpreter/walker_interp.py +0 -248
- 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 -152
- 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 -119
- 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 -85
- jaseci/jac/machine/jac_value.py +0 -226
- jaseci/jac/machine/machine_state.py +0 -383
- 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 -364
- jaseci/jsorc/manifests/__init__.py +0 -0
- jaseci/jsorc/manifests/database.yaml +0 -109
- jaseci/jsorc/manifests/elastic.yaml +0 -6024
- 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 -139
- jaseci/jsorc/remote_actions.py +0 -157
- 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 -93
- jaseci/prim/architype.py +0 -89
- jaseci/prim/edge.py +0 -172
- jaseci/prim/element.py +0 -233
- jaseci/prim/graph.py +0 -26
- jaseci/prim/master.py +0 -64
- jaseci/prim/node.py +0 -532
- jaseci/prim/obj_mixins.py +0 -235
- jaseci/prim/sentinel.py +0 -281
- 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 -516
- 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 -168
- 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.5.dist-info/LICENSE +0 -21
- jaseci-1.4.2.5.dist-info/METADATA +0 -39
- jaseci-1.4.2.5.dist-info/RECORD +0 -184
- jaseci-1.4.2.5.dist-info/entry_points.txt +0 -3
- jaseci-1.4.2.5.dist-info/top_level.txt +0 -1
jaseci/jac/jac_set.py
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Jac's set class for Jaseci
|
|
3
|
-
|
|
4
|
-
Adds relevant operators to id_list for operations on sets of nodes and edges
|
|
5
|
-
"""
|
|
6
|
-
# from jaseci.utils.id_list import id_list
|
|
7
|
-
from jaseci.utils.utils import logger
|
|
8
|
-
from jaseci.prim.element import Element
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class JacSet(list):
|
|
12
|
-
"""
|
|
13
|
-
Jac set class for operations in Jac lang
|
|
14
|
-
(keeps append ordering and no dups)
|
|
15
|
-
"""
|
|
16
|
-
|
|
17
|
-
def __init__(self, in_list=None):
|
|
18
|
-
if in_list:
|
|
19
|
-
for i in in_list:
|
|
20
|
-
if i not in self:
|
|
21
|
-
self.append(i)
|
|
22
|
-
|
|
23
|
-
def append(self, item):
|
|
24
|
-
if not isinstance(item, Element) or not hasattr(item, "anchor_value"):
|
|
25
|
-
logger.error(f"Invalid {type(item)} object {item} to be added to jac_set!")
|
|
26
|
-
elif item not in self:
|
|
27
|
-
list.append(self, item)
|
|
28
|
-
|
|
29
|
-
def add_obj(self, item: Element):
|
|
30
|
-
if item not in self:
|
|
31
|
-
self.append(item)
|
|
32
|
-
|
|
33
|
-
def obj_list(self):
|
|
34
|
-
return self
|
|
35
|
-
|
|
36
|
-
def __lt__(self, other):
|
|
37
|
-
"""Returns reduced set where anchor value evals to other"""
|
|
38
|
-
ret = JacSet()
|
|
39
|
-
for i in self:
|
|
40
|
-
if i.anchor_value() < other:
|
|
41
|
-
ret.add_obj(i)
|
|
42
|
-
return ret
|
|
43
|
-
|
|
44
|
-
def __gt__(self, other):
|
|
45
|
-
"""Returns reduced set where anchor value evals to other"""
|
|
46
|
-
ret = JacSet()
|
|
47
|
-
for i in self:
|
|
48
|
-
if i.anchor_value() > other:
|
|
49
|
-
ret.add_obj(i)
|
|
50
|
-
return ret
|
|
51
|
-
|
|
52
|
-
def __le__(self, other):
|
|
53
|
-
"""Returns reduced set where anchor value evals to other"""
|
|
54
|
-
ret = JacSet()
|
|
55
|
-
for i in self:
|
|
56
|
-
if i.anchor_value() <= other:
|
|
57
|
-
ret.add_obj(i)
|
|
58
|
-
return ret
|
|
59
|
-
|
|
60
|
-
def __ge__(self, other):
|
|
61
|
-
"""Returns reduced set where anchor value evals to other"""
|
|
62
|
-
ret = JacSet()
|
|
63
|
-
for i in self:
|
|
64
|
-
if i.anchor_value() >= other:
|
|
65
|
-
ret.add_obj(i)
|
|
66
|
-
return ret
|
|
67
|
-
|
|
68
|
-
def __eq__(self, other):
|
|
69
|
-
"""Returns reduced set where anchor value evals to other"""
|
|
70
|
-
ret = JacSet()
|
|
71
|
-
for i in self:
|
|
72
|
-
if i.anchor_value() == other:
|
|
73
|
-
ret.add_obj(i)
|
|
74
|
-
return ret
|
|
75
|
-
|
|
76
|
-
def __ne__(self, other):
|
|
77
|
-
"""Returns reduced set where anchor value evals to other"""
|
|
78
|
-
ret = JacSet()
|
|
79
|
-
for i in self:
|
|
80
|
-
if i.anchor_value() != other:
|
|
81
|
-
ret.add_obj(i)
|
|
82
|
-
return ret
|
|
83
|
-
|
|
84
|
-
def __add__(self, other):
|
|
85
|
-
"""Returns new set with operation applied"""
|
|
86
|
-
ret = JacSet()
|
|
87
|
-
for i in self:
|
|
88
|
-
ret.add_obj(i)
|
|
89
|
-
for i in other:
|
|
90
|
-
if i not in ret:
|
|
91
|
-
ret.add_obj(i)
|
|
92
|
-
return ret
|
|
93
|
-
|
|
94
|
-
def __sub__(self, other):
|
|
95
|
-
"""Returns new set with operation applied"""
|
|
96
|
-
ret = JacSet()
|
|
97
|
-
for i in self:
|
|
98
|
-
if i not in other:
|
|
99
|
-
ret.add_obj(i)
|
|
100
|
-
return ret
|
|
101
|
-
|
|
102
|
-
def __mul__(self, other):
|
|
103
|
-
"""Returns new set with operation applied, mul is intersection"""
|
|
104
|
-
ret = JacSet()
|
|
105
|
-
for i in self:
|
|
106
|
-
if i in other:
|
|
107
|
-
ret.add_obj(i)
|
|
108
|
-
return ret
|
|
109
|
-
|
|
110
|
-
def __truediv__(self, other):
|
|
111
|
-
"""Returns new set with operation applied, div is 'outersection'"""
|
|
112
|
-
ret = JacSet()
|
|
113
|
-
for i in self:
|
|
114
|
-
if i not in other:
|
|
115
|
-
ret.add_obj(i)
|
|
116
|
-
for i in other:
|
|
117
|
-
if i not in self:
|
|
118
|
-
ret.add_obj(i)
|
|
119
|
-
return ret
|
jaseci/jac/jsci_vm/__init__.py
DELETED
|
File without changes
|
jaseci/jac/jsci_vm/disasm.py
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
from jaseci.jac.jsci_vm.op_codes import JsCmp, JsOp, JsType, type_map
|
|
2
|
-
from jaseci.jac.jsci_vm.inst_ptr import InstPtr, from_bytes
|
|
3
|
-
from jaseci.utils.utils import logger
|
|
4
|
-
from base64 import b64decode
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class DisAsm(InstPtr):
|
|
8
|
-
def __init__(self):
|
|
9
|
-
InstPtr.__init__(self)
|
|
10
|
-
self._asm = []
|
|
11
|
-
|
|
12
|
-
def disassemble(self, bytecode, to_screen=True, log_out=False):
|
|
13
|
-
if type(bytecode) == str:
|
|
14
|
-
bytecode = b64decode(bytecode.encode())
|
|
15
|
-
self._bytecode = bytearray(bytecode)
|
|
16
|
-
try:
|
|
17
|
-
while self._ip < len(self._bytecode):
|
|
18
|
-
op = JsOp(self._bytecode[self._ip])
|
|
19
|
-
if hasattr(self, f"dis_{op.name}"):
|
|
20
|
-
getattr(self, f"dis_{op.name}")()
|
|
21
|
-
else:
|
|
22
|
-
self._asm.append([op.name])
|
|
23
|
-
self._ip += 1
|
|
24
|
-
self.print() if to_screen else None
|
|
25
|
-
self.log() if log_out else None
|
|
26
|
-
return self._asm
|
|
27
|
-
except Exception:
|
|
28
|
-
logger.error(f"Disassembly Failed on Following Bytecode: {self._bytecode}")
|
|
29
|
-
self.print() if to_screen else None
|
|
30
|
-
self.log() if log_out else None
|
|
31
|
-
|
|
32
|
-
def print(self):
|
|
33
|
-
for i in self._asm:
|
|
34
|
-
print(*i)
|
|
35
|
-
|
|
36
|
-
def log(self):
|
|
37
|
-
for i in self._asm:
|
|
38
|
-
logger.info(str(i))
|
|
39
|
-
|
|
40
|
-
def op_COMPARE(self): # noqa
|
|
41
|
-
ctyp = JsCmp(self.offset(1))
|
|
42
|
-
self._asm.append([self.cur_op(), ctyp.name])
|
|
43
|
-
self._ip += 1
|
|
44
|
-
|
|
45
|
-
def op_INCREMENT(self): # noqa
|
|
46
|
-
ityp = JsCmp(self.offset(1))
|
|
47
|
-
self._asm.append([self.cur_op(), ityp.name])
|
|
48
|
-
self._ip += 1
|
|
49
|
-
|
|
50
|
-
def dis_LOAD_CONST(self): # noqa
|
|
51
|
-
typ = JsType(self.offset(1))
|
|
52
|
-
operand2 = self.offset(2)
|
|
53
|
-
val = None
|
|
54
|
-
if typ in [JsType.TYPE]:
|
|
55
|
-
self._asm.append([self.cur_op(), typ.name, JsType(operand2).name])
|
|
56
|
-
self._ip += 2
|
|
57
|
-
elif typ in [JsType.INT]:
|
|
58
|
-
val = from_bytes(type_map[typ], self.offset(3, operand2))
|
|
59
|
-
self._asm.append([self.cur_op(), typ.name, operand2, val])
|
|
60
|
-
self._ip += 2 + operand2
|
|
61
|
-
elif typ in [JsType.STRING]:
|
|
62
|
-
str_len = from_bytes(type_map[JsType.INT], self.offset(3, operand2))
|
|
63
|
-
val = from_bytes(type_map[typ], self.offset(3 + operand2, str_len))
|
|
64
|
-
self._asm.append([self.cur_op(), typ.name, operand2, str_len, val])
|
|
65
|
-
self._ip += 2 + operand2 + str_len
|
|
66
|
-
elif typ in [JsType.FLOAT]:
|
|
67
|
-
val = from_bytes(float, self.offset(2, 8))
|
|
68
|
-
self._asm.append([self.cur_op(), typ.name, val])
|
|
69
|
-
self._ip += 1 + 8
|
|
70
|
-
elif typ in [JsType.BOOL]:
|
|
71
|
-
val = bool(self.offset(2))
|
|
72
|
-
self._asm.append([self.cur_op(), typ.name, val])
|
|
73
|
-
self._ip += 1 + 1
|
|
74
|
-
|
|
75
|
-
def dis_LOAD_VAR(self): # noqa
|
|
76
|
-
name = from_bytes(str, self.offset(2, self.offset(1)))
|
|
77
|
-
self._asm.append([self.cur_op(), self.offset(1), name])
|
|
78
|
-
self._ip += 1 + self.offset(1)
|
|
79
|
-
|
|
80
|
-
def dis_CREATE_VAR(self): # noqa
|
|
81
|
-
name = from_bytes(str, self.offset(2, self.offset(1)))
|
|
82
|
-
self._asm.append([self.cur_op(), self.offset(1), name])
|
|
83
|
-
self._ip += 1 + self.offset(1)
|
|
84
|
-
|
|
85
|
-
def dis_DEBUG_INFO(self): # noqa
|
|
86
|
-
byte_len_l = self.offset(1)
|
|
87
|
-
line = from_bytes(int, self.offset(2, byte_len_l))
|
|
88
|
-
f_offset = byte_len_l + 2
|
|
89
|
-
byte_len_f = self.offset(f_offset)
|
|
90
|
-
jacfile = (
|
|
91
|
-
from_bytes(str, self.offset(f_offset + 1, byte_len_f)) if byte_len_f else 0
|
|
92
|
-
)
|
|
93
|
-
self._asm.append([self.cur_op(), byte_len_l, line, byte_len_f, jacfile])
|
|
94
|
-
self._ip += 2 + byte_len_l + byte_len_f
|
jaseci/jac/jsci_vm/inst_ptr.py
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
from jaseci.jac.jsci_vm.op_codes import JsOp
|
|
2
|
-
from struct import unpack
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
def from_bytes(typ, val):
|
|
6
|
-
if typ == str:
|
|
7
|
-
if val is None:
|
|
8
|
-
return ""
|
|
9
|
-
return val.decode("unicode_escape")
|
|
10
|
-
if typ == float:
|
|
11
|
-
return unpack("d", val)[0]
|
|
12
|
-
else:
|
|
13
|
-
if val is None:
|
|
14
|
-
return 0
|
|
15
|
-
return typ.from_bytes(val, "little")
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
class InstPtr:
|
|
19
|
-
def __init__(self):
|
|
20
|
-
self._ip = 0
|
|
21
|
-
self._bytecode = None
|
|
22
|
-
|
|
23
|
-
def offset(self, delta, range=None):
|
|
24
|
-
if range == 0:
|
|
25
|
-
return None
|
|
26
|
-
elif range is not None:
|
|
27
|
-
return self._bytecode[self._ip + delta : self._ip + delta + range]
|
|
28
|
-
return self._bytecode[self._ip + delta]
|
|
29
|
-
|
|
30
|
-
def cur_op(self):
|
|
31
|
-
return JsOp(self.offset(0)).name
|
jaseci/jac/jsci_vm/machine.py
DELETED
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
from jaseci.jac.jsci_vm.op_codes import JsCmp, JsOp, JsType, type_map, cmp_op_map
|
|
2
|
-
from jaseci.jac.machine.machine_state import MachineState
|
|
3
|
-
from jaseci.jac.jsci_vm.inst_ptr import InstPtr, from_bytes
|
|
4
|
-
from jaseci.jac.machine.jac_value import JacValue
|
|
5
|
-
from jaseci.jac.jsci_vm.disasm import DisAsm
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class Stack(object):
|
|
9
|
-
def __init__(self):
|
|
10
|
-
self._stk = []
|
|
11
|
-
|
|
12
|
-
def stack_is_empty(self) -> bool:
|
|
13
|
-
return len(self._stk) == 0
|
|
14
|
-
|
|
15
|
-
def pop(self):
|
|
16
|
-
if self.stack_is_empty():
|
|
17
|
-
raise Exception("JaseciMachine stack is empty")
|
|
18
|
-
return self._stk.pop()
|
|
19
|
-
|
|
20
|
-
def push(self, value):
|
|
21
|
-
self._stk.append(value)
|
|
22
|
-
|
|
23
|
-
def peak_stack(self, count=0):
|
|
24
|
-
if not count:
|
|
25
|
-
print(list(reversed(self._stk)))
|
|
26
|
-
else:
|
|
27
|
-
print(list(reversed(self._stk))[0:count])
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
class VirtualMachine(MachineState, Stack, InstPtr):
|
|
31
|
-
def __init__(self, **kwargs):
|
|
32
|
-
Stack.__init__(self)
|
|
33
|
-
InstPtr.__init__(self)
|
|
34
|
-
MachineState.__init__(self, **kwargs)
|
|
35
|
-
self._op = self.build_op_call()
|
|
36
|
-
self._op_id = id(self)
|
|
37
|
-
|
|
38
|
-
def reset_vm(self):
|
|
39
|
-
Stack.__init__(self)
|
|
40
|
-
InstPtr.__init__(self)
|
|
41
|
-
if id(self) != self._op_id:
|
|
42
|
-
self._op = self.build_op_call()
|
|
43
|
-
|
|
44
|
-
def build_op_call(self):
|
|
45
|
-
op_map = {}
|
|
46
|
-
for op in JsOp:
|
|
47
|
-
op_map[op] = getattr(self, f"op_{op.name}")
|
|
48
|
-
return op_map
|
|
49
|
-
|
|
50
|
-
def run_bytecode(self, bytecode):
|
|
51
|
-
self.reset_vm()
|
|
52
|
-
self._bytecode = bytearray(bytecode)
|
|
53
|
-
try:
|
|
54
|
-
while self._ip < len(self._bytecode):
|
|
55
|
-
self._op[self._bytecode[self._ip]]()
|
|
56
|
-
self._ip += 1
|
|
57
|
-
except Exception as e:
|
|
58
|
-
self.disassemble(print_out=False, log_out=True)
|
|
59
|
-
raise e
|
|
60
|
-
|
|
61
|
-
def disassemble(self, print_out=True, log_out=False):
|
|
62
|
-
return DisAsm().disassemble(self._bytecode, print_out, log_out)
|
|
63
|
-
|
|
64
|
-
def op_PUSH_SCOPE(self): # noqa
|
|
65
|
-
pass
|
|
66
|
-
|
|
67
|
-
def op_POP_SCOPE(self): # noqa
|
|
68
|
-
pass
|
|
69
|
-
|
|
70
|
-
def op_ADD(self): # noqa
|
|
71
|
-
val = self.pop()
|
|
72
|
-
val.value = val.value + self.pop().value
|
|
73
|
-
self.push(val)
|
|
74
|
-
|
|
75
|
-
def op_SUBTRACT(self): # noqa
|
|
76
|
-
val = self.pop()
|
|
77
|
-
val.value = val.value - self.pop().value
|
|
78
|
-
self.push(val)
|
|
79
|
-
|
|
80
|
-
def op_MULTIPLY(self): # noqa
|
|
81
|
-
val = self.pop()
|
|
82
|
-
val.value = val.value * self.pop().value
|
|
83
|
-
self.push(val)
|
|
84
|
-
|
|
85
|
-
def op_DIVIDE(self): # noqa
|
|
86
|
-
val = self.pop()
|
|
87
|
-
val.value = val.value / self.pop().value
|
|
88
|
-
self.push(val)
|
|
89
|
-
|
|
90
|
-
def op_MODULO(self): # noqa
|
|
91
|
-
val = self.pop()
|
|
92
|
-
val.value = val.value % self.pop().value
|
|
93
|
-
self.push(val)
|
|
94
|
-
|
|
95
|
-
def op_POWER(self): # noqa
|
|
96
|
-
val = self.pop()
|
|
97
|
-
val.value = val.value ** self.pop().value
|
|
98
|
-
self.push(val)
|
|
99
|
-
|
|
100
|
-
def op_NEGATE(self): # noqa
|
|
101
|
-
val = self.pop()
|
|
102
|
-
val.value = -(val.value)
|
|
103
|
-
self.push(val)
|
|
104
|
-
|
|
105
|
-
def op_COMPARE(self): # noqa
|
|
106
|
-
ctyp = JsCmp(self.offset(1))
|
|
107
|
-
val = self.pop()
|
|
108
|
-
val.value = (
|
|
109
|
-
cmp_op_map[ctyp](val.value, self.pop().value)
|
|
110
|
-
if ctyp != JsCmp.NOT
|
|
111
|
-
else cmp_op_map[ctyp](val.value)
|
|
112
|
-
)
|
|
113
|
-
self.push(val)
|
|
114
|
-
self._ip += 1
|
|
115
|
-
|
|
116
|
-
def op_AND(self): # noqa
|
|
117
|
-
val = self.pop()
|
|
118
|
-
val.value = val.value and self.pop().value
|
|
119
|
-
self.push(val)
|
|
120
|
-
|
|
121
|
-
def op_OR(self): # noqa
|
|
122
|
-
val = self.pop()
|
|
123
|
-
val.value = val.value or self.pop().value
|
|
124
|
-
self.push(val)
|
|
125
|
-
|
|
126
|
-
def op_ASSIGN(self): # noqa
|
|
127
|
-
dest = self.pop()
|
|
128
|
-
self.perform_assignment(dest, self.pop())
|
|
129
|
-
|
|
130
|
-
def op_COPY_FIELDS(self): # noqa
|
|
131
|
-
dest = self.pop()
|
|
132
|
-
self.perform_copy_fields(dest, self.pop())
|
|
133
|
-
|
|
134
|
-
def op_INCREMENT(self): # noqa
|
|
135
|
-
ityp = JsCmp(self.offset(1))
|
|
136
|
-
dest = self.pop()
|
|
137
|
-
self.perform_increment(dest, self.pop(), ityp)
|
|
138
|
-
self._ip += 1
|
|
139
|
-
|
|
140
|
-
def op_LOAD_CONST(self): # noqa
|
|
141
|
-
typ = JsType(self.offset(1))
|
|
142
|
-
operand2 = self.offset(2)
|
|
143
|
-
if typ in [JsType.TYPE]:
|
|
144
|
-
val = type_map[JsType(operand2)]
|
|
145
|
-
self._ip += 2
|
|
146
|
-
elif typ in [JsType.INT]:
|
|
147
|
-
val = from_bytes(type_map[typ], self.offset(3, operand2))
|
|
148
|
-
self._ip += 2 + operand2
|
|
149
|
-
elif typ in [JsType.STRING]:
|
|
150
|
-
str_len = from_bytes(type_map[JsType.INT], self.offset(3, operand2))
|
|
151
|
-
val = from_bytes(type_map[typ], self.offset(3 + operand2, str_len))
|
|
152
|
-
self._ip += 2 + operand2 + str_len
|
|
153
|
-
elif typ in [JsType.FLOAT]:
|
|
154
|
-
val = from_bytes(float, self.offset(2, 8))
|
|
155
|
-
self._ip += 1 + 8
|
|
156
|
-
elif typ in [JsType.BOOL]:
|
|
157
|
-
val = bool(self.offset(2))
|
|
158
|
-
self._ip += 1 + 1
|
|
159
|
-
self.push(JacValue(self, value=val))
|
|
160
|
-
|
|
161
|
-
def op_LOAD_VAR(self): # noqa
|
|
162
|
-
name = from_bytes(str, self.offset(2, self.offset(1)))
|
|
163
|
-
self.load_variable(name)
|
|
164
|
-
self._ip += 1 + self.offset(1)
|
|
165
|
-
|
|
166
|
-
def op_CREATE_VAR(self): # noqa
|
|
167
|
-
name = from_bytes(str, self.offset(2, self.offset(1)))
|
|
168
|
-
self.load_variable(name, assign_mode=True)
|
|
169
|
-
self._ip += 1 + self.offset(1)
|
|
170
|
-
|
|
171
|
-
def op_REPORT(self): # noqa
|
|
172
|
-
self.report.append(self.pop())
|
|
173
|
-
|
|
174
|
-
def op_ACTION_CALL(self): # noqa
|
|
175
|
-
pass
|
|
176
|
-
|
|
177
|
-
def op_DEBUG_INFO(self): # noqa
|
|
178
|
-
byte_len_l = self.offset(1)
|
|
179
|
-
line = from_bytes(int, self.offset(2, byte_len_l))
|
|
180
|
-
f_offset = byte_len_l + 2
|
|
181
|
-
byte_len_f = self.offset(f_offset)
|
|
182
|
-
jacfile = (
|
|
183
|
-
from_bytes(str, self.offset(f_offset + 1, byte_len_f))
|
|
184
|
-
if byte_len_f
|
|
185
|
-
else self._cur_jac_ast.loc[2]
|
|
186
|
-
)
|
|
187
|
-
self._ip += 2 + byte_len_l + byte_len_f
|
|
188
|
-
self._cur_jac_ast.loc = [line, 0, jacfile, {}]
|
jaseci/jac/jsci_vm/op_codes.py
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
from enum import IntEnum, auto
|
|
2
|
-
from jaseci.prim.edge import Edge
|
|
3
|
-
from jaseci.prim.node import Node
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class JsOp(IntEnum):
|
|
7
|
-
PUSH_SCOPE = auto()
|
|
8
|
-
POP_SCOPE = auto()
|
|
9
|
-
ADD = auto()
|
|
10
|
-
SUBTRACT = auto()
|
|
11
|
-
MULTIPLY = auto()
|
|
12
|
-
DIVIDE = auto()
|
|
13
|
-
MODULO = auto()
|
|
14
|
-
POWER = auto()
|
|
15
|
-
NEGATE = auto()
|
|
16
|
-
COMPARE = auto()
|
|
17
|
-
AND = auto()
|
|
18
|
-
OR = auto()
|
|
19
|
-
ASSIGN = auto()
|
|
20
|
-
COPY_FIELDS = auto()
|
|
21
|
-
REPORT = auto()
|
|
22
|
-
ACTION_CALL = auto()
|
|
23
|
-
INCREMENT = auto() # [type]
|
|
24
|
-
LOAD_CONST = auto() # [type, bytes, (val)] / [type, (val)] / [type=type, type]
|
|
25
|
-
LOAD_VAR = auto() # [bytes, (name)]
|
|
26
|
-
CREATE_VAR = auto() # [bytes, (name)]
|
|
27
|
-
DEBUG_INFO = auto() # [bytes, line, bytes, (jacfile)]
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
class JsType(IntEnum):
|
|
31
|
-
TYPE = auto()
|
|
32
|
-
INT = auto()
|
|
33
|
-
FLOAT = auto()
|
|
34
|
-
STRING = auto()
|
|
35
|
-
LIST = auto()
|
|
36
|
-
DICT = auto()
|
|
37
|
-
BOOL = auto()
|
|
38
|
-
NULL = auto()
|
|
39
|
-
NODE = auto()
|
|
40
|
-
EDGE = auto()
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
class JsCmp(IntEnum):
|
|
44
|
-
EE = auto()
|
|
45
|
-
LT = auto()
|
|
46
|
-
GT = auto()
|
|
47
|
-
LTE = auto()
|
|
48
|
-
GTE = auto()
|
|
49
|
-
NE = auto()
|
|
50
|
-
IN = auto()
|
|
51
|
-
NIN = auto()
|
|
52
|
-
NOT = auto()
|
|
53
|
-
PEQ = auto()
|
|
54
|
-
MEQ = auto()
|
|
55
|
-
TEQ = auto()
|
|
56
|
-
DEQ = auto()
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
type_map = {
|
|
60
|
-
JsType.TYPE: type,
|
|
61
|
-
JsType.INT: int,
|
|
62
|
-
JsType.FLOAT: float,
|
|
63
|
-
JsType.STRING: str,
|
|
64
|
-
JsType.LIST: list,
|
|
65
|
-
JsType.DICT: dict,
|
|
66
|
-
JsType.BOOL: bool,
|
|
67
|
-
JsType.NULL: None,
|
|
68
|
-
JsType.NODE: Node,
|
|
69
|
-
JsType.EDGE: Edge,
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
cmp_op_map = {
|
|
73
|
-
JsCmp.NOT: lambda val: not val,
|
|
74
|
-
JsCmp.EE: lambda v1, v2: v1 == v2,
|
|
75
|
-
JsCmp.LT: lambda v1, v2: v1 < v2,
|
|
76
|
-
JsCmp.GT: lambda v1, v2: v1 > v2,
|
|
77
|
-
JsCmp.LTE: lambda v1, v2: v1 <= v2,
|
|
78
|
-
JsCmp.GTE: lambda v1, v2: v1 >= v2,
|
|
79
|
-
JsCmp.NE: lambda v1, v2: v1 != v2,
|
|
80
|
-
JsCmp.IN: lambda v1, v2: v1 in v2,
|
|
81
|
-
JsCmp.NIN: lambda v1, v2: v1 not in v2,
|
|
82
|
-
}
|
|
File without changes
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
from jaseci.utils.test_core import CoreTest
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
class TestCodegen(CoreTest):
|
|
5
|
-
"""Unit tests for Jac Walker APIs"""
|
|
6
|
-
|
|
7
|
-
fixture_src = __file__
|
|
8
|
-
|
|
9
|
-
def test_simple_codegen(self):
|
|
10
|
-
ret = self.call(
|
|
11
|
-
self.mast,
|
|
12
|
-
["sentinel_register", {"code": self.load_jac("simple.jac")}],
|
|
13
|
-
)
|
|
14
|
-
# self.log(ret)
|
|
15
|
-
ret = self.call(self.mast, ["walker_run", {"name": "most_basic"}])
|
|
16
|
-
# self.log(ret)
|
|
17
|
-
# from jaseci.jac.ir.passes import PrinterPass
|
|
18
|
-
# PrinterPass(self.mast.active_snt()._jac_ast).run()
|
|
19
|
-
self.assertEqual(ret["report"][0], 5004)
|
|
20
|
-
self.assertEqual(ret["report"][1], 1)
|
|
21
|
-
self.assertEqual(ret["report"][2], "ab")
|
|
22
|
-
self.assertEqual(ret["report"][3], {"base": 5, "test": 5})
|
|
23
|
-
self.assertEqual(ret["report"][4], {"a": 3, "b": 55, "c": 311})
|
|
24
|
-
|
|
25
|
-
def test_unicode(self):
|
|
26
|
-
ret = self.call(
|
|
27
|
-
self.mast,
|
|
28
|
-
["sentinel_register", {"code": self.load_jac("unicode.jac")}],
|
|
29
|
-
)
|
|
30
|
-
ret = self.call(self.mast, ["walker_run", {"name": "unicode"}])
|
|
31
|
-
self.assertEqual(len(ret["report"]), 1)
|
jaseci/jac/machine/__init__.py
DELETED
|
File without changes
|
jaseci/jac/machine/jac_scope.py
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Variable scope manager for Jac
|
|
3
|
-
|
|
4
|
-
Utility for all runtime interaction with variables in different scopes
|
|
5
|
-
"""
|
|
6
|
-
from jaseci.jac.machine.jac_value import JacValue
|
|
7
|
-
from jaseci.jsorc.live_actions import get_global_actions
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class JacScope:
|
|
11
|
-
def __init__(self, parent, name, has_obj=None, here=None, visitor=None):
|
|
12
|
-
self.parent = parent
|
|
13
|
-
self.name = name
|
|
14
|
-
self.local_scope = {}
|
|
15
|
-
self.has_obj = has_obj if has_obj else self
|
|
16
|
-
self.context = {}
|
|
17
|
-
self.action_sets = []
|
|
18
|
-
self._start_time = 0 # For profiling
|
|
19
|
-
self._total_time = 0 # For profiling
|
|
20
|
-
self._cum_start_time = None
|
|
21
|
-
self.set_refs(here, visitor)
|
|
22
|
-
self.setup_actions()
|
|
23
|
-
|
|
24
|
-
def setup_actions(self):
|
|
25
|
-
allactions = []
|
|
26
|
-
for i in self.action_sets:
|
|
27
|
-
allactions += i.obj_list()
|
|
28
|
-
self.action_sets = get_global_actions()
|
|
29
|
-
for i in allactions:
|
|
30
|
-
self.add_action(i)
|
|
31
|
-
|
|
32
|
-
def add_action(self, act):
|
|
33
|
-
group = act.name.split(".")[0]
|
|
34
|
-
if "." in act.name:
|
|
35
|
-
if group not in self.action_sets.keys():
|
|
36
|
-
self.action_sets[group] = {}
|
|
37
|
-
action = act.name.split(".")[1]
|
|
38
|
-
self.action_sets[group][action] = act
|
|
39
|
-
else:
|
|
40
|
-
self.action_sets[group] = act
|
|
41
|
-
|
|
42
|
-
def set_refs(self, here, visitor):
|
|
43
|
-
self.local_scope["here"] = here
|
|
44
|
-
self.local_scope["visitor"] = visitor
|
|
45
|
-
self.action_sets = []
|
|
46
|
-
if here:
|
|
47
|
-
self.action_sets += [here.get_architype().get_all_abilities()]
|
|
48
|
-
if visitor:
|
|
49
|
-
self.action_sets += [visitor.get_architype().get_all_abilities()]
|
|
50
|
-
|
|
51
|
-
def get_refs(self):
|
|
52
|
-
return {
|
|
53
|
-
"here": self.local_scope["here"],
|
|
54
|
-
"visitor": self.local_scope["visitor"],
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
def here(self):
|
|
58
|
-
return self.local_scope["here"]
|
|
59
|
-
|
|
60
|
-
def visitor(self):
|
|
61
|
-
return self.local_scope["visitor"]
|
|
62
|
-
|
|
63
|
-
def find_live_attr(self, name, allow_read_only=True):
|
|
64
|
-
"""Finds binding for variable if not in standard scope"""
|
|
65
|
-
# check if var is in walker's context
|
|
66
|
-
if "context" in self.has_obj.__dict__ and name in self.has_obj.context.keys():
|
|
67
|
-
return JacValue(self.parent, ctx=self.has_obj, name=name)
|
|
68
|
-
elif name in self.action_sets.keys():
|
|
69
|
-
return JacValue(self.parent, ctx=self.action_sets, name=name)
|
|
70
|
-
return None
|
|
71
|
-
|
|
72
|
-
def get_live_var(self, name, create_mode=False):
|
|
73
|
-
"""Returns live variable"""
|
|
74
|
-
found = None
|
|
75
|
-
# Lock for variable in various locations
|
|
76
|
-
if name in self.local_scope.keys():
|
|
77
|
-
found = JacValue(self.parent, ctx=self.local_scope, name=name)
|
|
78
|
-
else:
|
|
79
|
-
found = self.find_live_attr(name)
|
|
80
|
-
if found is None and create_mode:
|
|
81
|
-
self.local_scope[name] = None
|
|
82
|
-
return JacValue(self.parent, ctx=self.local_scope, name=name)
|
|
83
|
-
if found:
|
|
84
|
-
return found
|
|
85
|
-
return None
|