1.1 --- a/lib/builtins.py Tue Nov 14 23:42:21 2006 +0100
1.2 +++ b/lib/builtins.py Sat Nov 25 00:40:21 2006 +0100
1.3 @@ -21,6 +21,10 @@
1.4 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
1.5 """
1.6
1.7 +class object:
1.8 + def __true__(self):
1.9 + return False
1.10 +
1.11 class boolean:
1.12 def __true__(self):
1.13 return self
1.14 @@ -801,8 +805,7 @@
1.15 i -= 1
1.16 return result
1.17
1.18 -# Special values. None of these definitions should be generated by the compiler.
1.19 -# All such definitions should be made in the underlying implementation.
1.20 +# Special values.
1.21
1.22 True = boolean()
1.23 False = boolean()
2.1 --- a/simplify.py Tue Nov 14 23:42:21 2006 +0100
2.2 +++ b/simplify.py Sat Nov 25 00:40:21 2006 +0100
2.3 @@ -451,8 +451,8 @@
2.4 dstar=None)
2.5
2.6 elif op_name == "is not":
2.7 - invocation = Not(
2.8 - expr=InvokeFunction(
2.9 + invocation = self._visitNot(
2.10 + InvokeFunction(
2.11 expr=LoadName(name="__is__"),
2.12 args=[previous, expr],
2.13 star=None,
2.14 @@ -469,7 +469,7 @@
2.15 if op is not last:
2.16 nodes.append(
2.17 Conditional(
2.18 - test=Not(expr=LoadTemp()),
2.19 + test=self._visitNot(LoadTemp()),
2.20 body=[Return(expr=LoadTemp())])
2.21 )
2.22
2.23 @@ -534,8 +534,8 @@
2.24
2.25 if node is not last:
2.26 nodes.append(StoreTemp(expr=expr))
2.27 - invocation = InvokeFunction(expr=LoadAttr(expr=LoadTemp(), name="__true__"), args=[], star=None, dstar=None)
2.28 - test = Conditional(test=Not(expr=invocation), body=[Return(expr=LoadTemp())])
2.29 + #invocation = InvokeFunction(expr=LoadAttr(expr=LoadTemp(), name="__true__"), args=[], star=None, dstar=None)
2.30 + test = Conditional(test=self._visitNot(LoadTemp()), body=[Return(expr=LoadTemp())])
2.31 nodes.append(test)
2.32
2.33 # Put subsequent operations in the else section of this conditional.
2.34 @@ -622,19 +622,24 @@
2.35 result.expr = LoadRef(ref=subprogram)
2.36 return result
2.37
2.38 + def _visitNot(self, expr, not_=None):
2.39 + invocation = InvokeFunction(
2.40 + expr=LoadAttr(
2.41 + expr=expr,
2.42 + name="__true__"
2.43 + ),
2.44 + args=[],
2.45 + star=None,
2.46 + dstar=None
2.47 + )
2.48 + if not_ is not None:
2.49 + result = Not(not_, 1, expr=invocation)
2.50 + else:
2.51 + result = Not(expr=invocation)
2.52 + return result
2.53 +
2.54 def visitNot(self, not_):
2.55 - result = Not(not_, 1,
2.56 - expr=InvokeFunction(
2.57 - expr=LoadAttr(
2.58 - expr=self.dispatch(not_.expr),
2.59 - name="__true__"
2.60 - ),
2.61 - args=[],
2.62 - star=None,
2.63 - dstar=None
2.64 - )
2.65 - )
2.66 - return result
2.67 + return self._visitNot(self.dispatch(not_.expr), not_)
2.68
2.69 # Operators.
2.70
2.71 @@ -1020,7 +1025,15 @@
2.72 # Invocation and subprogram transformations.
2.73
2.74 def visitClass(self, class_):
2.75 - structure = Class(name=class_.name, module=self.module, bases=self.dispatches(class_.bases))
2.76 +
2.77 + # Add "object" if the class is not "object" and has an empty bases list.
2.78 +
2.79 + if class_.name != "object" and not class_.bases:
2.80 + bases = [compiler.ast.Name("object")]
2.81 + else:
2.82 + bases = class_.bases
2.83 +
2.84 + structure = Class(name=class_.name, module=self.module, bases=self.dispatches(bases))
2.85 self.structures.append(structure)
2.86
2.87 # Make a subprogram which initialises the class structure.
3.1 --- a/viewer.py Tue Nov 14 23:42:21 2006 +0100
3.2 +++ b/viewer.py Sat Nov 25 00:40:21 2006 +0100
3.3 @@ -248,7 +248,10 @@
3.4 self._popup_end()
3.5 self._name_end()
3.6 bases = structure.bases
3.7 - if bases:
3.8 +
3.9 + # Suppress the "object" class appearing alone.
3.10 +
3.11 + if bases and not (len(bases) == 1 and bases[0].name == "object"):
3.12 self.stream.write("(")
3.13 first = 1
3.14 for base in bases:
3.15 @@ -262,6 +265,7 @@
3.16 self._name_end()
3.17 first = 0
3.18 self.stream.write(")")
3.19 +
3.20 self.stream.write(":\n")
3.21 self._comment(self._text(structure.full_name()))
3.22 self.stream.write("</div>\n")