1.1 --- a/micropython/ast.py Sat May 30 20:30:28 2009 +0200
1.2 +++ b/micropython/ast.py Sun May 31 18:44:40 2009 +0200
1.3 @@ -783,6 +783,7 @@
1.4
1.5 # Skip the handler where the call was successful.
1.6
1.7 + self.new_op(PopHandler())
1.8 self.new_op(Jump(end_handler_block))
1.9
1.10 # Enter the exception handler.
1.11 @@ -803,9 +804,10 @@
1.12
1.13 self.new_op(RaiseException())
1.14
1.15 - # After the handler.
1.16 + # After the handler, clear the exception.
1.17
1.18 self.set_block(end_handler_block)
1.19 + self.new_op(ClearException())
1.20
1.21 # Assign to the target.
1.22
1.23 @@ -839,26 +841,31 @@
1.24
1.25 def visitIf(self, node):
1.26 first = 1
1.27 + next_block = None
1.28 exit_block = self.new_block()
1.29
1.30 clauses = node.tests + [(None, node.else_)]
1.31 - last_clause = clauses[-1]
1.32
1.33 for clause in clauses:
1.34 test, body = clause
1.35 if body is None:
1.36 break
1.37 +
1.38 if not first:
1.39 - self.set_block(next_block)
1.40 + self.new_op(Jump(exit_block)) # finish last body
1.41 + self.set_block(next_block) # start next test
1.42 + next_block = None
1.43 +
1.44 if test is not None:
1.45 self.dispatch(test)
1.46 next_block = self.new_block()
1.47 self.new_op(JumpIfFalse(next_block))
1.48 +
1.49 self.dispatch(body)
1.50 - if clause is not last_clause:
1.51 - self.new_op(Jump(exit_block))
1.52 + first = 0
1.53
1.54 - first = 0
1.55 + if next_block is not None:
1.56 + self.set_block(next_block)
1.57
1.58 self.set_block(exit_block)
1.59
1.60 @@ -921,7 +928,6 @@
1.61 # Start of handlers.
1.62
1.63 self.set_block(handler_block)
1.64 -
1.65 self.new_op(PopHandler())
1.66
1.67 for name, assignment, handler in node.handlers:
1.68 @@ -964,7 +970,10 @@
1.69
1.70 self.dispatch(node.else_)
1.71
1.72 + # Clear the exception.
1.73 +
1.74 self.set_block(exit_block)
1.75 + self.new_op(ClearException())
1.76 self.drop_exception_blocks()
1.77
1.78 def visitTryFinally(self, node): raise TranslationNotImplementedError(self.module.full_name(), node, "TryFinally")