1.1 --- a/rsvp.py Sun Feb 20 01:35:15 2011 +0100
1.2 +++ b/rsvp.py Sun Feb 20 19:31:50 2011 +0100
1.3 @@ -110,8 +110,13 @@
1.4 self.frame_stack = []
1.5 self.local_sp_stack = [0]
1.6 self.invocation_sp_stack = []
1.7 +
1.8 + # Exception handler stacks are used to reset the state of the main
1.9 + # stacks.
1.10 +
1.11 self.handler_stack = [len(self.memory) - 1] # final handler is the end of the code
1.12 self.handler_local_sp_stack = []
1.13 + self.handler_invocation_sp_stack = []
1.14 self.handler_pc_stack = []
1.15
1.16 # Registers.
1.17 @@ -747,14 +752,26 @@
1.18 def PushHandler(self):
1.19 self.handler_stack.append(self.operand)
1.20 self.handler_local_sp_stack.append(len(self.local_sp_stack))
1.21 + self.handler_invocation_sp_stack.append(len(self.invocation_sp_stack))
1.22 self.handler_pc_stack.append(len(self.pc_stack))
1.23
1.24 def PopHandler(self):
1.25 + nframes = self.operand
1.26 + # Get the new local frame pointer and PC stack references.
1.27 + local_sp_top = self.handler_local_sp_stack[-nframes]
1.28 + invocation_sp_top = self.handler_invocation_sp_stack[-nframes]
1.29 + pc_top = self.handler_pc_stack[-nframes]
1.30 # Reduce the local frame pointer stack to refer to the handler's frame.
1.31 - del self.local_sp_stack[self.handler_local_sp_stack.pop():]
1.32 + del self.local_sp_stack[local_sp_top:]
1.33 + # Reduce the invocation frame pointer stack to refer to an outer frame.
1.34 + del self.invocation_sp_stack[invocation_sp_top:]
1.35 # Reduce the PC stack to discard all superfluous return addresses.
1.36 - self.pc_stack = self.pc_stack[:self.handler_pc_stack.pop()]
1.37 - self.handler_stack.pop()
1.38 + del self.pc_stack[pc_top:]
1.39 + # Remove elements from the handler stacks.
1.40 + del self.handler_pc_stack[-nframes:]
1.41 + del self.handler_local_sp_stack[-nframes:]
1.42 + del self.handler_invocation_sp_stack[-nframes:]
1.43 + del self.handler_stack[-nframes:]
1.44
1.45 def CheckException(self):
1.46 self.status = self.exception is not None and self._CheckInstance(self.exception, self.value.ref)