# HG changeset patch # User paulb@localhost.localdomain # Date 1164411621 -3600 # Node ID 793337218643d146342a6353413ad2e6827f60e4 # Parent 1e13a8230404b5b057043022f02aec2a33d979cb Introduced more sophisticated Not node construction, incorporating __true__ calls where necessary. Added the object class to the builtins module, adding it automatically to the base class list of any class not having any superclasses itself. Suppressed object class display where classes have no other superclasses. diff -r 1e13a8230404 -r 793337218643 lib/builtins.py --- a/lib/builtins.py Tue Nov 14 23:42:21 2006 +0100 +++ b/lib/builtins.py Sat Nov 25 00:40:21 2006 +0100 @@ -21,6 +21,10 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA """ +class object: + def __true__(self): + return False + class boolean: def __true__(self): return self @@ -801,8 +805,7 @@ i -= 1 return result -# Special values. None of these definitions should be generated by the compiler. -# All such definitions should be made in the underlying implementation. +# Special values. True = boolean() False = boolean() diff -r 1e13a8230404 -r 793337218643 simplify.py --- a/simplify.py Tue Nov 14 23:42:21 2006 +0100 +++ b/simplify.py Sat Nov 25 00:40:21 2006 +0100 @@ -451,8 +451,8 @@ dstar=None) elif op_name == "is not": - invocation = Not( - expr=InvokeFunction( + invocation = self._visitNot( + InvokeFunction( expr=LoadName(name="__is__"), args=[previous, expr], star=None, @@ -469,7 +469,7 @@ if op is not last: nodes.append( Conditional( - test=Not(expr=LoadTemp()), + test=self._visitNot(LoadTemp()), body=[Return(expr=LoadTemp())]) ) @@ -534,8 +534,8 @@ if node is not last: nodes.append(StoreTemp(expr=expr)) - invocation = InvokeFunction(expr=LoadAttr(expr=LoadTemp(), name="__true__"), args=[], star=None, dstar=None) - test = Conditional(test=Not(expr=invocation), body=[Return(expr=LoadTemp())]) + #invocation = InvokeFunction(expr=LoadAttr(expr=LoadTemp(), name="__true__"), args=[], star=None, dstar=None) + test = Conditional(test=self._visitNot(LoadTemp()), body=[Return(expr=LoadTemp())]) nodes.append(test) # Put subsequent operations in the else section of this conditional. @@ -622,19 +622,24 @@ result.expr = LoadRef(ref=subprogram) return result + def _visitNot(self, expr, not_=None): + invocation = InvokeFunction( + expr=LoadAttr( + expr=expr, + name="__true__" + ), + args=[], + star=None, + dstar=None + ) + if not_ is not None: + result = Not(not_, 1, expr=invocation) + else: + result = Not(expr=invocation) + return result + def visitNot(self, not_): - result = Not(not_, 1, - expr=InvokeFunction( - expr=LoadAttr( - expr=self.dispatch(not_.expr), - name="__true__" - ), - args=[], - star=None, - dstar=None - ) - ) - return result + return self._visitNot(self.dispatch(not_.expr), not_) # Operators. @@ -1020,7 +1025,15 @@ # Invocation and subprogram transformations. def visitClass(self, class_): - structure = Class(name=class_.name, module=self.module, bases=self.dispatches(class_.bases)) + + # Add "object" if the class is not "object" and has an empty bases list. + + if class_.name != "object" and not class_.bases: + bases = [compiler.ast.Name("object")] + else: + bases = class_.bases + + structure = Class(name=class_.name, module=self.module, bases=self.dispatches(bases)) self.structures.append(structure) # Make a subprogram which initialises the class structure. diff -r 1e13a8230404 -r 793337218643 viewer.py --- a/viewer.py Tue Nov 14 23:42:21 2006 +0100 +++ b/viewer.py Sat Nov 25 00:40:21 2006 +0100 @@ -248,7 +248,10 @@ self._popup_end() self._name_end() bases = structure.bases - if bases: + + # Suppress the "object" class appearing alone. + + if bases and not (len(bases) == 1 and bases[0].name == "object"): self.stream.write("(") first = 1 for base in bases: @@ -262,6 +265,7 @@ self._name_end() first = 0 self.stream.write(")") + self.stream.write(":\n") self._comment(self._text(structure.full_name())) self.stream.write("\n")