1.1 --- a/bytecode.py Sat Nov 20 21:46:46 2004 +0100
1.2 +++ b/bytecode.py Sun Nov 21 00:20:48 2004 +0100
1.3 @@ -227,15 +227,32 @@
1.4
1.5 # Where handlers are begun, produce bytecode to test the type of
1.6 # the exception.
1.7 + # NOTE: Since RAISE_VARARGS and END_FINALLY are not really documented,
1.8 + # NOTE: we store the top of the stack and use it later to trigger the
1.9 + # NOTE: magic processes when re-raising.
1.10
1.11 - self.dup_top() # Stack: exception, exception
1.12 - self.load_global(str(exc_name)) # Stack: exception, exception, handled-exception
1.13 - self.compare_op("exception match") # Stack: exception, result
1.14 + self.rot_two() # Stack: raised-exception, exception
1.15 + self.dup_top() # Stack: raised-exception, exception, exception
1.16 + # Handled exceptions are wrapped before being thrown.
1.17 + self.load_global("Exception") # Stack: raised-exception, exception, exception, Exception
1.18 + self.compare_op("exception match") # Stack: raised-exception, exception, result
1.19 + self.jump_to_label(0, "next")
1.20 + self.pop_top() # Stack: raised-exception, exception
1.21 + self.dup_top() # Stack: raised-exception, exception, exception
1.22 + self.load_attr("args") # Stack: raised-exception, exception, args
1.23 + self.load_const(0) # Stack: raised-exception, exception, args, 0
1.24 + self.binary_subscr() # Stack: raised-exception, exception, exception-object
1.25 + self.load_global(str(exc_name)) # Stack: raised-exception, exception, exception-object, handled-exception
1.26 + self.load_global("isinstance") # Stack: raised-exception, exception, exception-object, handled-exception, isinstance
1.27 + self.rot_three() # Stack: raised-exception, exception, isinstance, exception-object, handled-exception
1.28 + self.call_function(2) # Stack: raised-exception, exception, result
1.29 self.jump_to_label(1, "handler")
1.30 - self.pop_top()
1.31 + self.start_label("next")
1.32 + self.pop_top() # Stack: raised-exception, exception
1.33 + self.rot_two() # Stack: exception, raised-exception
1.34 self.end_finally()
1.35 self.start_label("handler")
1.36 - self.pop_top()
1.37 + self.pop_top() # Stack: raised-exception, exception
1.38
1.39 # Complicated methods.
1.40
1.41 @@ -484,6 +501,12 @@
1.42 self.position += 1
1.43 self._write_value(count)
1.44
1.45 + # Debugging.
1.46 +
1.47 + def print_item(self):
1.48 + self.output.append(opmap["PRINT_ITEM"])
1.49 + self.position += 1
1.50 +
1.51 # Utility classes and functions.
1.52
1.53 class LazyDict(UserDict):
1.54 @@ -1014,8 +1037,12 @@
1.55 if self.in_finally:
1.56 program.end_finally()
1.57 else:
1.58 - program.dup_top()
1.59 + # Wrap the exception in a Python exception.
1.60 + program.load_global("Exception") # Stack: objectref, Exception
1.61 + program.rot_two() # Stack: Exception, objectref
1.62 + program.call_function(1) # Stack: exception
1.63 program.raise_varargs(1)
1.64 + # NOTE: This seems to put another object on the stack.
1.65
1.66 baload = aaload
1.67 bastore = aastore
1.68 @@ -1384,7 +1411,7 @@
1.69 # NOTE: Do proper resolution of classes,
1.70 # NOTE: Not bothering with Object initialisation.
1.71 full_class_name = target.get_class().get_python_name()
1.72 - if full_class_name != "java.lang.Object":
1.73 + if full_class_name not in ("java.lang.Object", "java.lang.Exception"):
1.74 class_name = full_class_name.split(".")[-1]
1.75 program.load_global(class_name) # Stack: tuple, classref
1.76 self._invoke(target_name, program)
1.77 @@ -1407,7 +1434,7 @@
1.78 # Get the class name instead of the fully qualified name.
1.79 # NOTE: Do proper resolution of classes,
1.80 full_class_name = target.get_class().get_python_name()
1.81 - if full_class_name != "java.lang.Object":
1.82 + if full_class_name not in ("java.lang.Object", "java.lang.Exception"):
1.83 class_name = full_class_name.split(".")[-1]
1.84 program.load_global(class_name) # Stack: tuple, classref
1.85 self._invoke(target_name, program)