1.1 --- a/micropython/trans.py Sun Jun 13 02:24:35 2010 +0200
1.2 +++ b/micropython/trans.py Mon Jun 14 01:46:42 2010 +0200
1.3 @@ -59,12 +59,8 @@
1.4
1.5 "Return the scope for the given 'name'."
1.6
1.7 - if self.unit is not self.module and self.unit.has_key(name):
1.8 - return "local"
1.9 - elif self.module.has_key(name):
1.10 - return "global"
1.11 - else:
1.12 - return "builtins"
1.13 + attr, scope, from_name = self.unit._get_with_scope(name)
1.14 + return scope
1.15
1.16 def load_builtin(self, name, node):
1.17
1.18 @@ -1161,8 +1157,6 @@
1.19 # Get the expected scope of the name.
1.20
1.21 scope = getattr(node, "_scope", None) or self.get_scope(name)
1.22 -
1.23 - #print self.module.name, node.lineno, name, predicted_scope
1.24 self._generateName(name, scope, classes, node)
1.25
1.26 def _generateName(self, name, scope, classes, node):
1.27 @@ -1174,7 +1168,15 @@
1.28
1.29 NameInstruction, AddressInstruction, AddressContextInstruction = classes
1.30
1.31 - if scope == "local":
1.32 + # Handle names referring to constants.
1.33 +
1.34 + if scope == "constant":
1.35 + const = self.importer.get_predefined_constant(name)
1.36 + self.new_op(LoadConst(const))
1.37 +
1.38 + # Handle all other names.
1.39 +
1.40 + elif scope == "local":
1.41 unit = self.unit
1.42 if isinstance(unit, Function):
1.43 self.new_op(NameInstruction(unit.all_locals()[name]))
1.44 @@ -1200,7 +1202,8 @@
1.45 self.new_op(AddressInstruction(self.get_builtin(name, node)))
1.46
1.47 else:
1.48 - raise TranslateError("Program unit uses unknown name %r." % name)
1.49 + # NOTE: This may happen because a class attribute is optimised away.
1.50 + print "Program unit uses unknown name %r." % name
1.51
1.52 def _visitUnary(self, node):
1.53