1.1 --- a/micropython/ast.py Tue Oct 28 01:08:06 2008 +0100
1.2 +++ b/micropython/ast.py Sat Nov 08 21:15:11 2008 +0100
1.3 @@ -42,11 +42,11 @@
1.4 name_load_instructions = (LoadName, LoadAddress)
1.5 name_store_instructions = (StoreName, StoreAddress)
1.6
1.7 - def __init__(self, module, importer, optimisations=None):
1.8 + def __init__(self, module, importer):
1.9
1.10 """
1.11 - Initialise the translation with an inspected 'module', the 'importer'
1.12 - and optional 'optimisations'.
1.13 + Initialise the translation with an inspected 'module' and the module
1.14 + 'importer'.
1.15 """
1.16
1.17 ASTVisitor.__init__(self)
1.18 @@ -62,7 +62,7 @@
1.19
1.20 # Optimisation.
1.21
1.22 - self.optimiser = Optimiser(self, optimisations)
1.23 + self.optimiser = Optimiser(self, importer.optimisations)
1.24
1.25 # The current unit being translated.
1.26
1.27 @@ -211,6 +211,9 @@
1.28 else:
1.29 return "builtins"
1.30
1.31 + def get_predefined_constant(self, name):
1.32 + return self.module.constant_values[self.module.predefined_constants[name]]
1.33 +
1.34 def load_builtin(self, name, node):
1.35
1.36 "Generate an instruction loading 'name' for the given 'node'."
1.37 @@ -624,6 +627,8 @@
1.38 t = self.optimiser.optimise_known_target()
1.39 if t:
1.40 target, context = t
1.41 + if isinstance(target, Instance): # lambda object
1.42 + target, context = None, None
1.43 else:
1.44 target, context = None, None
1.45
1.46 @@ -1188,7 +1193,7 @@
1.47 # Test for NotImplemented.
1.48 # Don't actually raise an exception.
1.49
1.50 - self.new_op(TestIdentityAddress(self.get_builtin("NotImplemented", node)))
1.51 + self.new_op(TestIdentityAddress(self.get_predefined_constant("NotImplemented")))
1.52 self.new_op(JumpIfTrue(next_method_block))
1.53 self.new_op(Jump(end_block))
1.54
1.55 @@ -1523,8 +1528,8 @@
1.56 def visitListCompIf(self, node): raise TranslationNotImplementedError(self.module.full_name(), node, "ListCompIf")
1.57
1.58 def visitName(self, node):
1.59 - if node.name == "None":
1.60 - const = self.module.constant_values[None]
1.61 + if self.module.predefined_constants.has_key(node.name):
1.62 + const = self.module.constant_values[self.module.predefined_constants[node.name]]
1.63 self.new_op(LoadConst(const))
1.64 else:
1.65 self._visitName(node, self.name_load_instructions)
1.66 @@ -1642,6 +1647,8 @@
1.67 self.discard_temp(temp2)
1.68
1.69 def visitClass(self, node):
1.70 + if not node.unit.referenced:
1.71 + return
1.72
1.73 # Store the name.
1.74
1.75 @@ -1664,6 +1671,8 @@
1.76 def visitFrom(self, node): pass
1.77
1.78 def visitFunction(self, node):
1.79 + if not node.unit.referenced and not node.unit.is_method():
1.80 + return
1.81
1.82 # Only store the name when visiting this node from outside.
1.83