1.1 --- a/micropython/trans.py Sat Jun 12 03:04:08 2010 +0200
1.2 +++ b/micropython/trans.py Sat Jun 12 21:33:36 2010 +0200
1.3 @@ -59,7 +59,7 @@
1.4
1.5 "Return the scope for the given 'name'."
1.6
1.7 - if self.unit.has_key(name):
1.8 + if self.unit is not self.module and self.unit.has_key(name):
1.9 return "local"
1.10 elif self.module.has_key(name):
1.11 return "global"
1.12 @@ -89,9 +89,9 @@
1.13 try:
1.14 return self.builtins[name]
1.15 except KeyError:
1.16 - raise TranslateError(self.module.full_name(), node, "No __builtins__ definition is available for name %r." % name)
1.17 + raise TranslateError("No __builtins__ definition is available for name %r." % name)
1.18 else:
1.19 - raise TranslateError(self.module.full_name(), node, "No __builtins__ module is available for name %r." % name)
1.20 + raise TranslateError("No __builtins__ module is available for name %r." % name)
1.21
1.22 # Code feature methods.
1.23
1.24 @@ -425,15 +425,14 @@
1.25 try:
1.26 attr = self.objtable.access(target_name, attrname)
1.27 except TableError, exc:
1.28 - raise TranslateError(self.module.full_name(), node, exc.args[0])
1.29 + raise TranslateError(exc.args[0])
1.30
1.31 # Produce a suitable instruction.
1.32
1.33 if AddressInstruction is not None:
1.34 self.replace_active_value(AddressInstruction(attr))
1.35 else:
1.36 - raise TranslateError(self.module.full_name(), node,
1.37 - "Storing of class or module attribute %r via an object is not permitted." % attrname)
1.38 + raise TranslateError("Storing of class or module attribute %r via an object is not permitted." % attrname)
1.39
1.40 return
1.41
1.42 @@ -472,8 +471,7 @@
1.43 if AddressContextInstruction is not None:
1.44 self.new_op(AddressContextInstruction(attr))
1.45 else:
1.46 - raise TranslateError(self.module.full_name(), node,
1.47 - "Storing of class attribute %r via self not permitted." % attrname)
1.48 + raise TranslateError("Storing of class attribute %r via self not permitted." % attrname)
1.49
1.50 # Preserve the context if the class attribute comes from an
1.51 # incompatible class.
1.52 @@ -485,8 +483,7 @@
1.53 if AddressInstruction is not None:
1.54 self.new_op(AddressInstruction(attr))
1.55 else:
1.56 - raise TranslateError(self.module.full_name(), node,
1.57 - "Storing of class attribute %r via self not permitted." % attrname)
1.58 + raise TranslateError("Storing of class attribute %r via self not permitted." % attrname)
1.59
1.60 # Otherwise, test for a suitable context at run-time.
1.61
1.62 @@ -497,8 +494,7 @@
1.63 if AddressContextCondInstruction is not None:
1.64 self.new_op(AddressContextCondInstruction(attr))
1.65 else:
1.66 - raise TranslateError(self.module.full_name(), node,
1.67 - "Storing of class attribute %r via self not permitted." % attrname)
1.68 + raise TranslateError("Storing of class attribute %r via self not permitted." % attrname)
1.69
1.70 return
1.71
1.72 @@ -540,8 +536,7 @@
1.73 elif AttrInstruction is not None and not attr.is_static_attribute():
1.74 self.new_op(AttrInstruction(attr))
1.75 else:
1.76 - raise TranslateError(self.module.full_name(), node,
1.77 - "Storing of class or module attribute %r via an object is not permitted." % attrname)
1.78 + raise TranslateError("Storing of class or module attribute %r via an object is not permitted." % attrname)
1.79
1.80 return
1.81
1.82 @@ -555,8 +550,7 @@
1.83 # If this error arises on generated code, check the names_used
1.84 # attribute on the Importer.
1.85
1.86 - raise TranslateError(self.module.full_name(), node,
1.87 - "No attribute entry exists for name %r." % attrname)
1.88 + raise TranslateError("No attribute entry exists for name %r." % attrname)
1.89
1.90 # NOTE: Test for class vs. instance attributes, generating
1.91 # NOTE: context-related instructions.
1.92 @@ -785,8 +779,7 @@
1.93 # Test for illegal conditions.
1.94
1.95 if pos in employed_positions:
1.96 - raise TranslateError(self.module.full_name(), node,
1.97 - "Keyword argument %r overwrites parameter %r." % (arg.name, pos))
1.98 + raise TranslateError("Keyword argument %r overwrites parameter %r." % (arg.name, pos))
1.99
1.100 employed_positions.add(pos)
1.101
1.102 @@ -857,7 +850,7 @@
1.103
1.104 for i in range(ncontext, nargs_min):
1.105 if i not in employed_positions:
1.106 - raise TranslateError(self.module.full_name(), node,
1.107 + raise TranslateError(
1.108 "Argument %r not supplied for %r: need at least %d argument(s)." % (i+1, target.name, nargs_min))
1.109
1.110 nargs = frame_pos
1.111 @@ -878,7 +871,7 @@
1.112 # allowed.
1.113
1.114 elif nargs > nargs_max:
1.115 - raise TranslateError(self.module.full_name(), node,
1.116 + raise TranslateError(
1.117 "Too many arguments for %r: need at most %d argument(s)." % (target.name, nargs_max))
1.118
1.119 else:
1.120 @@ -1165,14 +1158,11 @@
1.121
1.122 name = node.name
1.123
1.124 - # Transfer scope information if this was set during inspection.
1.125 + # Get the expected scope of the name.
1.126
1.127 - if hasattr(node, "_scope"):
1.128 - scope = node._scope
1.129 - else:
1.130 - scope = self.get_scope(name)
1.131 + scope = self.get_scope(name)
1.132
1.133 - #print self.module.name, node.lineno, name, scope
1.134 + #print self.module.name, node.lineno, name, predicted_scope
1.135 self._generateName(name, scope, classes, node)
1.136
1.137 def _generateName(self, name, scope, classes, node):
1.138 @@ -1197,20 +1187,20 @@
1.139 elif isinstance(unit, Module):
1.140 self.new_op(AddressInstruction(unit.module_attributes()[name]))
1.141 else:
1.142 - raise TranslateError(self.module.full_name(), node, "Program unit %r has no local %r." % (unit, name))
1.143 + raise TranslateError("Program unit has no local %r." % name)
1.144
1.145 elif scope == "global":
1.146 globals = self.module.module_attributes()
1.147 if globals.has_key(name):
1.148 self.new_op(AddressInstruction(globals[name]))
1.149 else:
1.150 - raise TranslateError(self.module.full_name(), node, "Module %r has no attribute %r." % (self.module, name))
1.151 + raise TranslateError("Module has no attribute %r." % name)
1.152
1.153 elif scope == "builtins":
1.154 self.new_op(AddressInstruction(self.get_builtin(name, node)))
1.155
1.156 else:
1.157 - raise TranslateError(self.module.full_name(), node, "Program unit %r uses unknown name %r." % (self.unit, name))
1.158 + raise TranslateError("Program unit uses unknown name %r." % name)
1.159
1.160 def _visitUnary(self, node):
1.161