1.1 --- a/micropython/inspect.py Sat Jun 12 21:39:53 2010 +0200
1.2 +++ b/micropython/inspect.py Sat Jun 12 23:09:30 2010 +0200
1.3 @@ -280,12 +280,15 @@
1.4
1.5 # Or store locally.
1.6
1.7 - elif self.namespaces[-1].used_in_scope(name, "global"):
1.8 - raise InspectError("Name %r already used as global." % name)
1.9 - elif self.namespaces[-1].used_in_scope(name, "builtins"):
1.10 - raise InspectError("Name %r already used as a built-in." % name)
1.11 else:
1.12 - self.namespaces[-1].set(name, obj, not self.in_loop)
1.13 + locals = self.namespaces[-1]
1.14 +
1.15 + if locals.used_in_scope(name, "global") and not name in locals.globals:
1.16 + raise InspectError("Name %r already used as global." % name)
1.17 + elif locals.used_in_scope(name, "builtins"):
1.18 + raise InspectError("Name %r already used as a built-in." % name)
1.19 + else:
1.20 + locals.set(name, obj, not self.in_loop)
1.21
1.22 def store_lambda(self, obj):
1.23
1.24 @@ -724,8 +727,8 @@
1.25
1.26 in_loop = self.in_loop
1.27 self.in_loop = 1
1.28 + self.dispatch(node.list)
1.29 self.dispatch(node.assign)
1.30 - self.dispatch(node.list)
1.31
1.32 # Enter the loop.
1.33 # Propagate attribute usage to branches.
1.34 @@ -884,9 +887,37 @@
1.35
1.36 visitList = OP
1.37
1.38 - visitListComp = OP
1.39 + def visitListComp(self, node):
1.40 + for qual in node.quals:
1.41 + self.dispatch(qual)
1.42 + self.dispatch(node.expr)
1.43 +
1.44 + def visitListCompFor(self, node):
1.45 + self.new_branchpoint()
1.46 +
1.47 + # Declare names which will be used by generated code.
1.48 +
1.49 + self.use_name("__iter__", node.list)
1.50 + self.use_name("next")
1.51
1.52 - visitListCompFor = NOP
1.53 + in_loop = self.in_loop
1.54 + self.in_loop = 1
1.55 + self.dispatch(node.list)
1.56 + self.dispatch(node.assign)
1.57 +
1.58 + # Enter the loop.
1.59 + # Propagate attribute usage to branches.
1.60 +
1.61 + self.new_branch()
1.62 +
1.63 + for if_ in node.ifs:
1.64 + self.dispatch(if_)
1.65 +
1.66 + self.shelve_branch()
1.67 + self.in_loop = in_loop
1.68 +
1.69 + self.merge_branches()
1.70 + return None
1.71
1.72 visitListCompIf = NOP
1.73