# HG changeset patch # User Paul Boddie # Date 1276304648 -7200 # Node ID 475fd98986d900d668fbff6a5d35660c7000a941 # Parent d2231267c5576da1a042a8978eb073fe7f53be59 Fixed the listiterator.next method to raise an exception instance. Added a tuple.__iter__ implementation. Removed "__init__" from the names_always_used list, introducing it into the attribute coverage mechanism. Fixed unknown name detection in the translation code. Fixed an example where globals were used before being defined. diff -r d2231267c557 -r 475fd98986d9 lib/builtins.py --- a/lib/builtins.py Sat Jun 12 02:47:03 2010 +0200 +++ b/lib/builtins.py Sat Jun 12 03:04:08 2010 +0200 @@ -197,7 +197,7 @@ self.i += 1 return value except IndexError: - raise StopIteration + raise StopIteration() class long(object): def __init__(self, number_or_string=None): pass @@ -249,9 +249,14 @@ def __len__(self): pass def __add__(self, other): pass def __str__(self): pass - def __iter__(self): pass def __bool__(self): pass + def __iter__(self): + + "Return an iterator." + + return listiterator(self) + class unicode(basestring): pass diff -r d2231267c557 -r 475fd98986d9 micropython/__init__.py --- a/micropython/__init__.py Sat Jun 12 02:47:03 2010 +0200 +++ b/micropython/__init__.py Sat Jun 12 03:04:08 2010 +0200 @@ -334,7 +334,7 @@ } names_always_used = [ - "bool", "__init__", "__call__", "__bool__" + "bool", "__call__", "__bool__" ] def __init__(self, path=None, verbose=0, optimisations=None): @@ -542,6 +542,7 @@ # in this initialiser. if "__init__" in objtable.table.get(from_name, []): + self.use_attribute(from_name, "__init__") self._collect_attributes(from_name + ".__init__", objtable) # Constant accounting. diff -r d2231267c557 -r 475fd98986d9 micropython/trans.py --- a/micropython/trans.py Sat Jun 12 02:47:03 2010 +0200 +++ b/micropython/trans.py Sat Jun 12 03:04:08 2010 +0200 @@ -1206,8 +1206,11 @@ else: raise TranslateError(self.module.full_name(), node, "Module %r has no attribute %r." % (self.module, name)) + elif scope == "builtins": + self.new_op(AddressInstruction(self.get_builtin(name, node))) + else: - self.new_op(AddressInstruction(self.get_builtin(name, node))) + raise TranslateError(self.module.full_name(), node, "Program unit %r uses unknown name %r." % (self.unit, name)) def _visitUnary(self, node): diff -r d2231267c557 -r 475fd98986d9 tests/op_add_default.py --- a/tests/op_add_default.py Sat Jun 12 02:47:03 2010 +0200 +++ b/tests/op_add_default.py Sat Jun 12 03:04:08 2010 +0200 @@ -1,10 +1,11 @@ #!/usr/bin/env python +a = 10 # used in f default +b = 20 # used in f default + def f(a, b, c=a+b): return a + b + c -a = 10 # used in f default -b = 20 # used in f default result_33 = f(1, 2) # vim: tabstop=4 expandtab shiftwidth=4