1.1 --- a/bytecode.py Sat Nov 13 23:17:20 2004 +0100
1.2 +++ b/bytecode.py Sat Nov 13 23:18:10 2004 +0100
1.3 @@ -420,6 +420,11 @@
1.4 self.position += 1
1.5 self.update_stack_depth(-1)
1.6
1.7 + def store_subscr(self):
1.8 + self.output.append(opmap["STORE_SUBSCR"])
1.9 + self.position += 1
1.10 + self.update_stack_depth(-3)
1.11 +
1.12 def unary_negative(self):
1.13 self.output.append(opmap["UNARY_NEGATIVE"])
1.14 self.position += 1
1.15 @@ -535,11 +540,14 @@
1.16 self.in_finally = 0
1.17 self.method = method
1.18
1.19 - # NOTE: Not guaranteed.
1.20 - if len(method.attributes) == 0:
1.21 + # NOTE: Potentially unreliable way of getting necessary information.
1.22 + code, exception_table = None, None
1.23 + for attribute in method.attributes:
1.24 + if isinstance(attribute, classfile.CodeAttributeInfo):
1.25 + code, exception_table = attribute.code, attribute.exception_table
1.26 + break
1.27 + if code is None:
1.28 return
1.29 - attribute = method.attributes[0]
1.30 - code, exception_table = attribute.code, attribute.exception_table
1.31
1.32 # Produce a structure which permits fast access to exception details.
1.33 exception_block_start = {}
1.34 @@ -1847,11 +1855,8 @@
1.35 if not real_methods.has_key(real_method_name):
1.36 real_methods[real_method_name] = []
1.37 real_methods[real_method_name].append((method, fn))
1.38 - # NOTE: Define superclasses properly.
1.39 - if str(self.class_file.super_class.get_name()) not in ("java/lang/Object", "java/lang/Exception"):
1.40 - bases = (global_names[str(self.class_file.super_class.get_python_name())],)
1.41 - else:
1.42 - bases = ()
1.43 + # Define superclasses.
1.44 + bases = self.get_base_classes(global_names)
1.45 # Define method dispatchers.
1.46 for real_method_name, methods in real_methods.items():
1.47 self.make_method(real_method_name, methods, global_names, namespace)
1.48 @@ -1862,6 +1867,30 @@
1.49 global_names[cls.__name__] = cls
1.50 return cls
1.51
1.52 + def get_base_classes(self, global_names):
1.53 +
1.54 + """
1.55 + Identify the superclass, then either load it from the given
1.56 + 'global_names' if available, or import the class from its parent module.
1.57 + Return a tuple containing all base classes (typically a single element
1.58 + tuple).
1.59 + """
1.60 +
1.61 + original_name = str(self.class_file.super_class.get_name())
1.62 + if original_name in ("java/lang/Object", "java/lang/Exception"):
1.63 + return ()
1.64 + else:
1.65 + full_class_name = str(self.class_file.super_class.get_python_name())
1.66 + class_name_parts = full_class_name.split(".")
1.67 + class_module_name = ".".join(class_name_parts[:-1])
1.68 + if class_module_name == "":
1.69 + class_module_name = "__this__"
1.70 + class_name = class_name_parts[-1]
1.71 + print "*", class_module_name, class_name
1.72 + class_module = __import__(class_module_name, global_names, {}, [class_name])
1.73 + base = getattr(class_module, class_name)
1.74 + return (base,)
1.75 +
1.76 def make_varnames(self, nlocals):
1.77
1.78 """