# HG changeset patch # User Paul Boddie # Date 1244414977 -7200 # Node ID edb8a3f00e899ce2771e0a00fcc2d2ba94fa9989 # Parent c93dcf98ca1b3b9cf4e1d01a78fc7e6507e343f6 Introduced the removal of all explicitly defined methods from removed classes in the InspectedModule.vacuum method when applying optimisations. Added notes about exceptions, statistics about program size, and comments about functions as methods. diff -r c93dcf98ca1b -r edb8a3f00e89 docs/exceptions.txt --- a/docs/exceptions.txt Sun Jun 07 22:55:59 2009 +0200 +++ b/docs/exceptions.txt Mon Jun 08 00:49:37 2009 +0200 @@ -9,6 +9,9 @@ is raised in any handling of the exception, or upon exit of a handler where the active exception has been caught (thus resetting the active exception). +NOTE: Currently, if classes are used with "raise" statements, no instantiation +NOTE: of such classes occurs. This should be remedied. + Instructions ------------ diff -r c93dcf98ca1b -r edb8a3f00e89 micropython/__init__.py --- a/micropython/__init__.py Sun Jun 07 22:55:59 2009 +0200 +++ b/micropython/__init__.py Mon Jun 08 00:49:37 2009 +0200 @@ -279,8 +279,6 @@ assert item.location == len(self.raw_code) self.raw_code += item.as_raw(objtable, paramtable) - # Using classcode, attrcode, codeaddr, codedetails, instance. - elif isinstance(item, micropython.data.Class): assert item.instance_template_location == len(self.raw_code) self.raw_code += item.as_raw(objtable, paramtable, diff -r c93dcf98ca1b -r edb8a3f00e89 micropython/data.py --- a/micropython/data.py Sun Jun 07 22:55:59 2009 +0200 +++ b/micropython/data.py Mon Jun 08 00:49:37 2009 +0200 @@ -1066,7 +1066,9 @@ def is_method(self): - "Return whether this function is a method." + """ + Return whether this function is a method explicitly defined in a class. + """ return isinstance(self.parent, Class) diff -r c93dcf98ca1b -r edb8a3f00e89 micropython/inspect.py --- a/micropython/inspect.py Sun Jun 07 22:55:59 2009 +0200 +++ b/micropython/inspect.py Mon Jun 08 00:49:37 2009 +0200 @@ -176,9 +176,11 @@ names. """ - for name, value in self.items(): + # Remove unreferenced objects. - if self.should_optimise_unused_objects(): + if self.should_optimise_unused_objects(): + + for name, value in self.items(): # Remove entries for unreferenced objects. # This, due to the nature of the referenced attribute, assumes @@ -198,10 +200,6 @@ else: del self[name] - # Remove unreferenced objects. - - if self.should_optimise_unused_objects(): - all_objects = list(self.all_objects) for obj in all_objects: @@ -212,21 +210,33 @@ isinstance(obj, Class)) and not obj.referenced: self.all_objects.remove(obj) + obj_was_removed = 1 + + else: + obj_was_removed = 0 # Remove unused entries from classes plus associated methods. if isinstance(obj, Class): for name, attr in obj.class_attributes().items(): - # Methods can only be deleted if they are the only - # assigned object to the class and are unreferenced. + # In removed classes, all explicitly defined methods can + # be removed. - if name not in self.importer.names_used and \ + # In other classes, methods can only be removed if they + # are the only assigned object to the class for a + # particular attribute and are unreferenced. + + if obj_was_removed and isinstance(attr.get_value(), Function) and attr.get_value().is_method() or \ + name not in self.importer.names_used and \ attr.assignments == 1 and isinstance(attr.get_value(), Function) and \ attr.get_value().is_method() and not attr.get_value().referenced: - self.all_objects.remove(attr.get_value()) - del obj[name] + method = attr.get_value() + + if method in self.all_objects: + self.all_objects.remove(method) + del obj[name] def finalise(self): diff -r c93dcf98ca1b -r edb8a3f00e89 rsvp.py --- a/rsvp.py Sun Jun 07 22:55:59 2009 +0200 +++ b/rsvp.py Mon Jun 08 00:49:37 2009 +0200 @@ -940,8 +940,11 @@ pass native_functions = { + + # Native method implementations: + "__builtins__.int.__add__" : builtins_int_add, - "__builtins__.int.__radd__" : builtins_int_add, # NOTE: To be made distinct. + "__builtins__.int.__radd__" : builtins_int_add, # NOTE: To be made distinct. "__builtins__.int.__iadd__" : builtins_int_add, "__builtins__.int.__bool__" : builtins_int_bool, "__builtins__.int.__neg__" : builtins_int_neg, @@ -952,10 +955,13 @@ "__builtins__.int.__eq__" : builtins_int_eq, "__builtins__.int.__ne__" : builtins_int_ne, "__builtins__.bool.__bool__" : builtins_bool_bool, + "__builtins__.list.__getitem__" : builtins_list_getitem, + "__builtins__.object.__init__" : builtins_object_init, # NOTE: A no-operation. + "__builtins__.BaseException.__init__" : builtins_object_init, # NOTE: To be made distinct, potentially in the builtins module. + + # Native instantiators: + "__builtins__.list" : builtins_list_new, - "__builtins__.list.__getitem__" : builtins_list_getitem, - "__builtins__.object.__init__" : builtins_object_init, - "__builtins__.BaseException.__init__" : builtins_object_init, # NOTE: To be made distinct. } # Convenience functions. @@ -976,6 +982,7 @@ false_constant = importer.get_constant(False).location rm = RSVPMachine(rc, objlist, paramlist, true_constant, false_constant, debug=debug) rm.pc = program.code_location + print "Returning program occupying %d locations." % len(rm.memory) return rm # vim: tabstop=4 expandtab shiftwidth=4