1.1 --- a/simplify.py Tue Nov 14 23:42:21 2006 +0100
1.2 +++ b/simplify.py Sat Nov 25 00:40:21 2006 +0100
1.3 @@ -451,8 +451,8 @@
1.4 dstar=None)
1.5
1.6 elif op_name == "is not":
1.7 - invocation = Not(
1.8 - expr=InvokeFunction(
1.9 + invocation = self._visitNot(
1.10 + InvokeFunction(
1.11 expr=LoadName(name="__is__"),
1.12 args=[previous, expr],
1.13 star=None,
1.14 @@ -469,7 +469,7 @@
1.15 if op is not last:
1.16 nodes.append(
1.17 Conditional(
1.18 - test=Not(expr=LoadTemp()),
1.19 + test=self._visitNot(LoadTemp()),
1.20 body=[Return(expr=LoadTemp())])
1.21 )
1.22
1.23 @@ -534,8 +534,8 @@
1.24
1.25 if node is not last:
1.26 nodes.append(StoreTemp(expr=expr))
1.27 - invocation = InvokeFunction(expr=LoadAttr(expr=LoadTemp(), name="__true__"), args=[], star=None, dstar=None)
1.28 - test = Conditional(test=Not(expr=invocation), body=[Return(expr=LoadTemp())])
1.29 + #invocation = InvokeFunction(expr=LoadAttr(expr=LoadTemp(), name="__true__"), args=[], star=None, dstar=None)
1.30 + test = Conditional(test=self._visitNot(LoadTemp()), body=[Return(expr=LoadTemp())])
1.31 nodes.append(test)
1.32
1.33 # Put subsequent operations in the else section of this conditional.
1.34 @@ -622,19 +622,24 @@
1.35 result.expr = LoadRef(ref=subprogram)
1.36 return result
1.37
1.38 + def _visitNot(self, expr, not_=None):
1.39 + invocation = InvokeFunction(
1.40 + expr=LoadAttr(
1.41 + expr=expr,
1.42 + name="__true__"
1.43 + ),
1.44 + args=[],
1.45 + star=None,
1.46 + dstar=None
1.47 + )
1.48 + if not_ is not None:
1.49 + result = Not(not_, 1, expr=invocation)
1.50 + else:
1.51 + result = Not(expr=invocation)
1.52 + return result
1.53 +
1.54 def visitNot(self, not_):
1.55 - result = Not(not_, 1,
1.56 - expr=InvokeFunction(
1.57 - expr=LoadAttr(
1.58 - expr=self.dispatch(not_.expr),
1.59 - name="__true__"
1.60 - ),
1.61 - args=[],
1.62 - star=None,
1.63 - dstar=None
1.64 - )
1.65 - )
1.66 - return result
1.67 + return self._visitNot(self.dispatch(not_.expr), not_)
1.68
1.69 # Operators.
1.70
1.71 @@ -1020,7 +1025,15 @@
1.72 # Invocation and subprogram transformations.
1.73
1.74 def visitClass(self, class_):
1.75 - structure = Class(name=class_.name, module=self.module, bases=self.dispatches(class_.bases))
1.76 +
1.77 + # Add "object" if the class is not "object" and has an empty bases list.
1.78 +
1.79 + if class_.name != "object" and not class_.bases:
1.80 + bases = [compiler.ast.Name("object")]
1.81 + else:
1.82 + bases = class_.bases
1.83 +
1.84 + structure = Class(name=class_.name, module=self.module, bases=self.dispatches(bases))
1.85 self.structures.append(structure)
1.86
1.87 # Make a subprogram which initialises the class structure.