1.1 --- a/micropython/ast.py Sun Jun 26 23:54:37 2011 +0200
1.2 +++ b/micropython/ast.py Sat Jul 02 02:41:33 2011 +0200
1.3 @@ -19,18 +19,18 @@
1.4 this program. If not, see <http://www.gnu.org/licenses/>.
1.5 """
1.6
1.7 -from micropython.opt import Optimiser
1.8 from micropython.common import *
1.9 from micropython.data import *
1.10 from micropython.rsvp import *
1.11 from micropython.trans import Helper
1.12 +from micropython.code import Assembler
1.13 import compiler.ast
1.14
1.15 # Program visitors.
1.16
1.17 -class Translation(ASTVisitor, Helper):
1.18 +class Translation(ASTVisitor, Assembler, Helper):
1.19
1.20 - "A translated module."
1.21 + "A module translator."
1.22
1.23 # Attribute access instructions, for use with the appropriate handlers.
1.24
1.25 @@ -53,6 +53,7 @@
1.26 """
1.27
1.28 ASTVisitor.__init__(self)
1.29 + Assembler.__init__(self, program.optimisations)
1.30 self.visitor = self
1.31 self.module = module
1.32
1.33 @@ -64,54 +65,18 @@
1.34 self.importer = self.program.get_importer()
1.35 self.builtins = self.importer.modules.get("__builtins__")
1.36
1.37 - # Optimisation.
1.38 -
1.39 - self.optimiser = Optimiser(self, program.optimisations)
1.40 -
1.41 - # The current unit being translated.
1.42 -
1.43 - self.unit = None
1.44 + # Status flags.
1.45
1.46 - # The temporary storage used by the current assignment expression.
1.47 -
1.48 - self.expr_temp = []
1.49 -
1.50 - # Wiring within the code.
1.51 -
1.52 - self.labels = {}
1.53 - self.label_number = 0
1.54 - self.loop_blocks = []
1.55 - self.exception_blocks = []
1.56 self.in_exception_handler = 0
1.57 self.in_assignment = 0 # for slicing and subscript
1.58
1.59 + # Reset the assembler.
1.60 +
1.61 self.reset()
1.62
1.63 def __repr__(self):
1.64 return "Translation(%r)" % self.module
1.65
1.66 - def reset(self):
1.67 -
1.68 - "Reset the state of the translator."
1.69 -
1.70 - # The code itself. This is limited to the code for a particular block
1.71 - # being processed.
1.72 -
1.73 - self.blocks = []
1.74 -
1.75 - # Information about temporary values.
1.76 -
1.77 - self.temp_positions = set()
1.78 - self.max_temp_position = -1
1.79 -
1.80 - # Information about instructions which construct frames.
1.81 -
1.82 - self.frame_makers = []
1.83 -
1.84 - # Optimiser state must be reset for each unit.
1.85 -
1.86 - self.optimiser.reset()
1.87 -
1.88 def get_module_code(self):
1.89
1.90 """