|
@@ -372,6 +372,37 @@ class BinaryInstruction(Instruction):
|
|
|
else:
|
|
|
code_generator.append_line('pass')
|
|
|
|
|
|
+class UnaryInstruction(Instruction):
|
|
|
+ """An instruction that performs a unary operation."""
|
|
|
+ def __init__(self, operator, operand):
|
|
|
+ Instruction.__init__(self)
|
|
|
+ self.operator = operator
|
|
|
+ self.operand = operand
|
|
|
+
|
|
|
+ def has_definition(self):
|
|
|
+ """Tells if this instruction requires a definition."""
|
|
|
+ return self.operator.has_definition()
|
|
|
+
|
|
|
+ def simplify(self):
|
|
|
+ """Applies basic simplification to this instruction and its children."""
|
|
|
+ simple_operator = self.operator.simplify()
|
|
|
+ return UnaryInstruction(self.operator, simple_operator)
|
|
|
+
|
|
|
+ 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)' % (
|
|
|
+ self.operator,
|
|
|
+ self.operand.generate_python_use(code_generator))
|
|
|
+
|
|
|
+ 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.operator.has_definition():
|
|
|
+ self.operator.generate_python_def(code_generator)
|
|
|
+ else:
|
|
|
+ code_generator.append_line('pass')
|
|
|
+
|
|
|
class LoopInstruction(VoidInstruction):
|
|
|
"""Represents a loop-instruction, which loops until broken."""
|
|
|
|