1.1 --- a/micropython/inspect.py Mon Sep 13 23:52:01 2010 +0200
1.2 +++ b/micropython/inspect.py Thu Sep 16 20:02:26 2010 +0200
1.3 @@ -810,14 +810,18 @@
1.4
1.5 self.in_loop = in_loop
1.6
1.7 - # Maintain a separate branch for the else clause.
1.8 + # A null branch is used to record a path around the loop.
1.9
1.10 self.new_branch(node.else_ or NullBranch())
1.11 - if node.else_ is not None:
1.12 - self.dispatch(node.else_)
1.13 self.shelve_branch()
1.14
1.15 self.merge_branches()
1.16 +
1.17 + # The else clause is evaluated outside any branch.
1.18 +
1.19 + if node.else_ is not None:
1.20 + self.dispatch(node.else_)
1.21 +
1.22 return None
1.23
1.24 def visitFrom(self, node):
1.25 @@ -1051,34 +1055,29 @@
1.26 in_loop = self.in_loop
1.27 self.in_loop = 1
1.28
1.29 - # The test is evaluated initially.
1.30 + # The test is evaluated initially and again in the loop.
1.31
1.32 self.dispatch(node.test)
1.33
1.34 self.new_branch(node)
1.35 self.dispatch(node.body)
1.36 + self.dispatch(node.test)
1.37 + self.shelve_branch()
1.38
1.39 - # The test is evaluated again within the loop.
1.40 + self.in_loop = in_loop
1.41 +
1.42 + # A null branch is used to record a path around the loop.
1.43
1.44 - self.dispatch(node.test)
1.45 + self.new_branch(node.else_ or NullBranch())
1.46 + self.shelve_branch()
1.47
1.48 - # Incorporate the else clause in the branch, if present.
1.49 + self.merge_branches()
1.50 +
1.51 + # The else clause is evaluated outside any branch.
1.52
1.53 if node.else_ is not None:
1.54 self.dispatch(node.else_)
1.55
1.56 - self.shelve_branch()
1.57 -
1.58 - self.in_loop = in_loop
1.59 -
1.60 - # Maintain a branch for the else clause.
1.61 -
1.62 - self.new_branch(node.else_ or NullBranch())
1.63 - if node.else_ is not None:
1.64 - self.dispatch(node.else_)
1.65 - self.shelve_branch()
1.66 -
1.67 - self.merge_branches()
1.68 return None
1.69
1.70 visitWith = NOP