# HG changeset patch # User Paul Boddie # Date 1100100217 -3600 # Node ID cdfdf58bec4cb5aa49207053fdd4c98c557fb073 # Parent 50db0817ceeb016b64d148b584e6843084a62604 Changed get_name to get_python_name in most remaining places of relevance. Fixed invokespecial to get the method's class directly rather than erroneously use self.__classes__. Added simple base class definition. diff -r 50db0817ceeb -r cdfdf58bec4c bytecode.py --- a/bytecode.py Wed Nov 10 16:00:09 2004 +0100 +++ b/bytecode.py Wed Nov 10 16:23:37 2004 +0100 @@ -905,7 +905,7 @@ def checkcast(self, arguments, program): index = (arguments[0] << 8) + arguments[1] - target_name = self.class_file.constants[index - 1].get_name() + target_name = self.class_file.constants[index - 1].get_python_name() # NOTE: Using the string version of the name which may contain incompatible characters. target_components = str(target_name).split("/") @@ -1210,7 +1210,7 @@ def instanceof(self, arguments, program): index = (arguments[0] << 8) + arguments[1] - target_name = self.class_file.constants[index - 1].get_name() + target_name = self.class_file.constants[index - 1].get_python_name() # NOTE: Using the string version of the name which may contain incompatible characters. target_components = str(target_name).split("/") @@ -1252,11 +1252,12 @@ count = len(target.get_descriptor()[0]) # Check for the method name and invoke superclasses where appropriate. - if str(self.method.get_name()) == "": + if str(self.method.get_python_name()) == "__init__": program.build_tuple(count + 1) # Stack: tuple - # NOTE: Assume that local 0 is always self. - program.load_fast(0) # Stack: tuple, objectref - program.load_attr("__class__") # Stack: tuple, classref + # Must use the actual class. + # NOTE: Verify this. + program.load_global(str(self.class_file.this_class.get_python_name())) + # Stack: tuple, classref program.load_attr("__bases__") # Stack: tuple, bases program.dup_top() # Stack: tuple, bases, bases program.load_global("len") # Stack: tuple, bases, bases, len @@ -1525,7 +1526,7 @@ # This operation is considered to be the same as the calling of the # initialisation method of the given class with no arguments. index = (arguments[0] << 8) + arguments[1] - target_name = self.class_file.constants[index - 1].get_name() + target_name = self.class_file.constants[index - 1].get_python_name() # NOTE: Using the string version of the name which may contain incompatible characters. program.load_global(str(target_name)) # NOTE: Unlike Java, we do not provide an object reference. Instead, a @@ -1656,7 +1657,11 @@ fn = new.function(code, global_names) namespace[method_name] = fn # NOTE: Define superclasses properly. - cls = new.classobj(str(c.this_class.get_name()), (), namespace) + if str(c.super_class.get_name()) not in ("java/lang/Object", "java/lang/Exception"): + bases = (global_names[str(c.super_class.get_python_name())],) + else: + bases = () + cls = new.classobj(str(c.this_class.get_python_name()), bases, namespace) global_names[cls.__name__] = cls # vim: tabstop=4 expandtab shiftwidth=4