1.1 --- a/micropython/inspect.py Fri Sep 17 00:48:32 2010 +0200
1.2 +++ b/micropython/inspect.py Tue Sep 21 00:11:34 2010 +0200
1.3 @@ -347,8 +347,8 @@
1.4 # These are convenience methods which refer to the specific namespace's
1.5 # implementation of these operations.
1.6
1.7 - def new_branchpoint(self, is_loop=0):
1.8 - self.get_namespace()._new_branchpoint(is_loop)
1.9 + def new_branchpoint(self, loop_node=None):
1.10 + self.get_namespace()._new_branchpoint(loop_node)
1.11
1.12 def new_branch(self, node):
1.13 self.get_namespace()._new_branch(node)
1.14 @@ -356,8 +356,11 @@
1.15 def abandon_branch(self):
1.16 self.get_namespace()._abandon_branch()
1.17
1.18 - def suspend_branch(self):
1.19 - self.get_namespace()._suspend_branch()
1.20 + def suspend_broken_branch(self):
1.21 + self.get_namespace()._suspend_broken_branch()
1.22 +
1.23 + def suspend_continuing_branch(self):
1.24 + self.get_namespace()._suspend_continuing_branch()
1.25
1.26 def shelve_branch(self):
1.27 self.get_namespace()._shelve_branch()
1.28 @@ -365,8 +368,11 @@
1.29 def merge_branches(self):
1.30 self.get_namespace()._merge_branches()
1.31
1.32 - def resume_branches(self):
1.33 - self.get_namespace()._resume_branches()
1.34 + def resume_broken_branches(self):
1.35 + self.get_namespace()._resume_broken_branches()
1.36 +
1.37 + def resume_continuing_branches(self):
1.38 + self.get_namespace()._resume_continuing_branches()
1.39
1.40 def define_attribute_user(self, node):
1.41
1.42 @@ -407,10 +413,6 @@
1.43 self.NOP(node)
1.44 self.abandon_branch()
1.45
1.46 - def NOP_SUSPEND(self, node):
1.47 - self.NOP(node)
1.48 - self.suspend_branch()
1.49 -
1.50 def OP(self, node):
1.51 for n in node.getChildNodes():
1.52 self.dispatch(n)
1.53 @@ -664,7 +666,9 @@
1.54
1.55 visitBitxor = _visitBinary
1.56
1.57 - visitBreak = NOP_SUSPEND
1.58 + def visitBreak(self, node):
1.59 + self.NOP(node)
1.60 + self.suspend_broken_branch()
1.61
1.62 visitCallFunc = OP
1.63
1.64 @@ -773,7 +777,9 @@
1.65 self.use_name(self.importer.get_constant_type_name(node.value), node)
1.66 return self.importer.make_constant(node.value)
1.67
1.68 - visitContinue = NOP_ABANDON
1.69 + def visitContinue(self, node):
1.70 + self.NOP(node)
1.71 + self.suspend_continuing_branch()
1.72
1.73 visitDecorators = NOP
1.74
1.75 @@ -792,7 +798,7 @@
1.76 visitFloorDiv = _visitBinary
1.77
1.78 def visitFor(self, node):
1.79 - self.new_branchpoint(is_loop=1)
1.80 + self.new_branchpoint(node)
1.81
1.82 # Declare names which will be used by generated code.
1.83
1.84 @@ -811,10 +817,7 @@
1.85 self.new_branch(node)
1.86 self.dispatch(node.body)
1.87
1.88 - # Incorporate the else clause in the branch, if present.
1.89 -
1.90 - if node.else_ is not None:
1.91 - self.dispatch(node.else_)
1.92 + self.resume_continuing_branches()
1.93
1.94 self.shelve_branch()
1.95
1.96 @@ -834,7 +837,7 @@
1.97
1.98 # Any suspended branches from the loop can now be resumed.
1.99
1.100 - self.resume_branches()
1.101 + self.resume_broken_branches()
1.102
1.103 return None
1.104
1.105 @@ -1062,7 +1065,7 @@
1.106 visitUnarySub = _visitUnary
1.107
1.108 def visitWhile(self, node):
1.109 - self.new_branchpoint(is_loop=1)
1.110 + self.new_branchpoint(node)
1.111
1.112 # Propagate attribute usage to branches.
1.113
1.114 @@ -1075,6 +1078,9 @@
1.115
1.116 self.new_branch(node)
1.117 self.dispatch(node.body)
1.118 +
1.119 + self.resume_continuing_branches()
1.120 +
1.121 self.dispatch(node.test)
1.122 self.shelve_branch()
1.123
1.124 @@ -1094,7 +1100,7 @@
1.125
1.126 # Any suspended branches from the loop can now be resumed.
1.127
1.128 - self.resume_branches()
1.129 + self.resume_broken_branches()
1.130
1.131 return None
1.132