Skip to content

Commit

Permalink
[MINOR]: Support destroy element on ability
Browse files Browse the repository at this point in the history
  • Loading branch information
amadolid committed Oct 10, 2023
1 parent 7bbb2b5 commit d70aa58
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions jaseci_core/jaseci/jac/interpreter/interp.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,24 @@ def run_destroy_action(self, jac_ast):
"""
destroy_action: KW_DESTROY expression SEMI;
"""
from jaseci.prim.ability import Ability

kid = self.set_cur_ast(jac_ast)
self.run_expression(kid[1])
result = self.pop()

destroy_node_ids = None
if isinstance(self, Ability):
# currently, only walker process destroy_node_ids
# ability should be able to trigger destroy but still connected to current walker
destroy_node_ids = self._jac_scope.local_scope["visitor"].destroy_node_ids
else:
destroy_node_ids = self.destroy_node_ids

if isinstance(result.value, Element):
self.destroy_node_ids.add_obj(result.value)
destroy_node_ids.add_obj(result.value)
elif isinstance(result.value, JacSet):
self.destroy_node_ids.add_obj_list(result.value)
destroy_node_ids.add_obj_list(result.value)
result.self_destruct(kid[1])

def run_report_action(self, jac_ast):
Expand Down

0 comments on commit d70aa58

Please sign in to comment.