|
@@ -584,7 +584,6 @@ class DefineFunctionInstruction(VariableInstruction):
|
|
|
def generate_python_def(self, code_generator):
|
|
|
"""Generates a Python statement that executes this instruction.
|
|
|
The statement is appended immediately to the code generator."""
|
|
|
-
|
|
|
code_generator.append_line('def %s(%s):' % (
|
|
|
code_generator.get_result_name(self), ', '.join(self.parameter_list)))
|
|
|
code_generator.increase_indentation()
|
|
@@ -647,22 +646,55 @@ class LoadMemberInstruction(Instruction):
|
|
|
|
|
|
def has_definition(self):
|
|
|
"""Tells if this instruction requires a definition."""
|
|
|
- return False
|
|
|
+ return self.container.has_definition()
|
|
|
|
|
|
def simplify(self):
|
|
|
return LoadMemberInstruction(
|
|
|
self.container.simplify(), self.member_name)
|
|
|
|
|
|
+ def generate_python_def(self, code_generator):
|
|
|
+ """Generates a Python statement that executes this instruction.
|
|
|
+ The statement is appended immediately to the code generator."""
|
|
|
+ self.container.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."""
|
|
|
- if self.container.has_definition():
|
|
|
- self.container.generate_python_def(code_generator)
|
|
|
-
|
|
|
return "%s.%s" % (
|
|
|
self.container.generate_python_use(code_generator),
|
|
|
self.member_name)
|
|
|
|
|
|
+class StoreMemberInstruction(Instruction):
|
|
|
+ """An instruction that stores a value in a container member."""
|
|
|
+ def __init__(self, container, member_name, value):
|
|
|
+ Instruction.__init__(self)
|
|
|
+ self.container = container
|
|
|
+ self.member_name = member_name
|
|
|
+ self.value = value
|
|
|
+
|
|
|
+ def has_definition(self):
|
|
|
+ """Tells if this instruction requires a definition."""
|
|
|
+ return True
|
|
|
+
|
|
|
+ def has_result(self):
|
|
|
+ """Tells if this instruction computes a result."""
|
|
|
+ return False
|
|
|
+
|
|
|
+ def simplify(self):
|
|
|
+ """Applies basic simplification to this instruction and its children."""
|
|
|
+ return StoreMemberInstruction(
|
|
|
+ self.container.simplify(), self.member_name, self.value.simplify())
|
|
|
+
|
|
|
+ def generate_python_def(self, code_generator):
|
|
|
+ """Generates a Python statement that executes this instruction.
|
|
|
+ The statement is appended immediately to the code generator."""
|
|
|
+ if self.container.has_definition():
|
|
|
+ self.container.generate_python_def(code_generator)
|
|
|
+ code_generator.append_line('%s.%s = %s' % (
|
|
|
+ self.container.generate_python_use(code_generator),
|
|
|
+ self.member_name,
|
|
|
+ self.value.generate_python_use(code_generator)))
|
|
|
+
|
|
|
class NopInstruction(Instruction):
|
|
|
"""A nop instruction, which allows for the kernel's thread of execution to be interrupted."""
|
|
|
|