1.1 --- a/micropython/ast.py Thu Apr 17 23:04:50 2008 +0200
1.2 +++ b/micropython/ast.py Mon Apr 21 00:13:09 2008 +0200
1.3 @@ -448,7 +448,7 @@
1.4 "Make the invocation and tidy up afterwards."
1.5
1.6 self.new_op(LoadCallable()) # uses the start of the frame to get the callable
1.7 - self.new_op(Jump())
1.8 + self.new_op(JumpWithFrame())
1.9
1.10 # NOTE: Exception handling required.
1.11
1.12 @@ -823,7 +823,9 @@
1.13
1.14 else:
1.15 self.dispatch(node.code)
1.16 - self.new_op(Return())
1.17 + if not isinstance(self.last_op(), Return):
1.18 + self.dispatch(compiler.ast.Name("None"))
1.19 + self.new_op(Return())
1.20
1.21 def visitGenExpr(self, node): pass
1.22
1.23 @@ -904,6 +906,8 @@
1.24 def visitReturn(self, node):
1.25 if node.value is not None:
1.26 self.dispatch(node.value)
1.27 + else:
1.28 + self.dispatch(compiler.ast.Name("None"))
1.29 self.new_op(Return())
1.30
1.31 def visitRightShift(self, node): pass
1.32 @@ -932,21 +936,32 @@
1.33
1.34 self.add_exception_labels(handler_label, exit_label)
1.35
1.36 + # Try...
1.37 + # Produce the code, then jump to the exit.
1.38 +
1.39 self.dispatch(node.body)
1.40 self.new_op(Jump(exit_label))
1.41
1.42 + # Start of handlers.
1.43 +
1.44 self.set_label(handler_label)
1.45 for name, assignment, handler in node.handlers:
1.46 next_label = self.new_label()
1.47
1.48 + # Test the given exception against the current exception.
1.49 +
1.50 if name is not None:
1.51 self.dispatch(name)
1.52 self.new_op(CheckException())
1.53 self.new_op(JumpIfFalse(next_label))
1.54
1.55 + # Handle assignment to exception variable.
1.56 +
1.57 if assignment is not None:
1.58 self.dispatch(assignment)
1.59
1.60 + # Produce the handler code, then jump to the exit.
1.61 +
1.62 self.dispatch(handler)
1.63 self.new_op(Jump(exit_label))
1.64