|
@@ -75,21 +75,20 @@ class Instruction(object):
|
|
|
def __str__(self):
|
|
|
code_generator = PythonGenerator()
|
|
|
self.generate_python_def(code_generator)
|
|
|
- return code_generator.code
|
|
|
+ return str(code_generator)
|
|
|
|
|
|
class PythonGenerator(object):
|
|
|
"""Generates Python code from instructions."""
|
|
|
|
|
|
def __init__(self):
|
|
|
- self.code = ''
|
|
|
+ self.code = []
|
|
|
self.indentation_string = ' ' * 4
|
|
|
self.indentation = 0
|
|
|
self.result_value_dict = {}
|
|
|
|
|
|
def append(self, text):
|
|
|
"""Appends the given string to this code generator."""
|
|
|
-
|
|
|
- self.code += text
|
|
|
+ self.code.append(text)
|
|
|
|
|
|
def append_indentation(self):
|
|
|
"""Appends indentation to the code generator."""
|
|
@@ -160,6 +159,9 @@ class PythonGenerator(object):
|
|
|
opcode,
|
|
|
', '.join([arg_i.generate_python_use(self) for arg_i in args])))
|
|
|
|
|
|
+ def __str__(self):
|
|
|
+ return ''.join(self.code)
|
|
|
+
|
|
|
class VoidInstruction(Instruction):
|
|
|
"""A base class for instructions that do not return a value."""
|
|
|
|