|
@@ -813,6 +813,63 @@ class DictionaryLiteralInstruction(Instruction):
|
|
def __repr__(self):
|
|
def __repr__(self):
|
|
return "DictionaryLiteralInstruction(%r)" % self.key_value_pairs
|
|
return "DictionaryLiteralInstruction(%r)" % self.key_value_pairs
|
|
|
|
|
|
|
|
+class ListSliceInstruction(Instruction):
|
|
|
|
+ """Slices a list."""
|
|
|
|
+ def __init__(self, seq, start, end, step):
|
|
|
|
+ Instruction.__init__(self)
|
|
|
|
+ self.seq = seq
|
|
|
|
+ self.start = start
|
|
|
|
+ self.end = end
|
|
|
|
+ self.step = step
|
|
|
|
+
|
|
|
|
+ def get_children(self):
|
|
|
|
+ """Gets this instruction's sequence of child instructions."""
|
|
|
|
+ all_items = (self.seq, self.start, self.end, self.step)
|
|
|
|
+ return [item for item in all_items if item is not None]
|
|
|
|
+
|
|
|
|
+ def create(self, new_children):
|
|
|
|
+ """Creates a new instruction of this type from the given sequence of child instructions."""
|
|
|
|
+ # pylint: disable=I0011,E1120
|
|
|
|
+ args = []
|
|
|
|
+ i = 0
|
|
|
|
+ for old_item in (self.seq, self.start, self.end, self.step):
|
|
|
|
+ if old_item is None:
|
|
|
|
+ args.append(None)
|
|
|
|
+ else:
|
|
|
|
+ args.append(new_children[i])
|
|
|
|
+ i += 1
|
|
|
|
+
|
|
|
|
+ assert len(new_children) == i
|
|
|
|
+ assert len(args) == 4
|
|
|
|
+ return ListSliceInstruction(*args)
|
|
|
|
+
|
|
|
|
+ def has_definition_impl(self):
|
|
|
|
+ """Tells if this instruction requires a definition."""
|
|
|
|
+ return any([item.has_definition() for item in self.get_children()])
|
|
|
|
+
|
|
|
|
+ def has_result_temporary(self):
|
|
|
|
+ """Tells if this instruction stores its result in a temporary."""
|
|
|
|
+ return False
|
|
|
|
+
|
|
|
|
+ def generate_python_def(self, code_generator):
|
|
|
|
+ """Generates a Python statement that executes this instruction.
|
|
|
|
+ The statement is appended immediately to the code generator."""
|
|
|
|
+ for item in self.get_children():
|
|
|
|
+ if item.has_definition():
|
|
|
|
+ item.generate_python_def(code_generator)
|
|
|
|
+
|
|
|
|
+ def generate_python_use(self, code_generator):
|
|
|
|
+ """Generates a Python expression that retrieves this instruction's
|
|
|
|
+ result. The expression is returned as a string."""
|
|
|
|
+ return '%s[%s:%s:%s]' % (
|
|
|
|
+ self.seq.generate_python_use(code_generator),
|
|
|
|
+ '' if self.start is None else self.start.generate_python_use(code_generator),
|
|
|
|
+ '' if self.end is None else self.end.generate_python_use(code_generator),
|
|
|
|
+ '' if self.step is None else self.step.generate_python_use(code_generator))
|
|
|
|
+
|
|
|
|
+ def __repr__(self):
|
|
|
|
+ return "ListSliceInstruction(%r, %r, %r, %r)" % (self.seq, self.start, self.end, self.step)
|
|
|
|
+
|
|
class StateInstruction(Instruction):
|
|
class StateInstruction(Instruction):
|
|
"""An instruction that accesses the modelverse state."""
|
|
"""An instruction that accesses the modelverse state."""
|
|
def get_result_type_impl(self):
|
|
def get_result_type_impl(self):
|
|
@@ -1290,6 +1347,20 @@ class ReadDictionaryEdgeInstruction(StateInstruction):
|
|
"""Gets this state instruction's argument list."""
|
|
"""Gets this state instruction's argument list."""
|
|
return [self.node_id, self.key]
|
|
return [self.node_id, self.key]
|
|
|
|
|
|
|
|
+class ReadDictionaryKeysInstruction(StateInstruction):
|
|
|
|
+ """An instruction that reads all keys from a dictionary."""
|
|
|
|
+ def __init__(self, node_id):
|
|
|
|
+ StateInstruction.__init__(self)
|
|
|
|
+ self.node_id = node_id
|
|
|
|
+
|
|
|
|
+ def get_opcode(self):
|
|
|
|
+ """Gets the opcode for this state instruction."""
|
|
|
|
+ return "RDK"
|
|
|
|
+
|
|
|
|
+ def get_arguments(self):
|
|
|
|
+ """Gets this state instruction's argument list."""
|
|
|
|
+ return [self.node_id]
|
|
|
|
+
|
|
class ReadEdgeInstruction(StateInstruction):
|
|
class ReadEdgeInstruction(StateInstruction):
|
|
"""An instruction that reads an edge."""
|
|
"""An instruction that reads an edge."""
|
|
def __init__(self, node_id):
|
|
def __init__(self, node_id):
|