1.1 --- a/simplify.py Wed Feb 14 21:57:46 2007 +0100
1.2 +++ b/simplify.py Wed Feb 14 23:35:19 2007 +0100
1.3 @@ -546,7 +546,7 @@
1.4 method_names = self.comparison_methods[op_name]
1.5 if method_names:
1.6 first_name, alternative_name = method_names
1.7 - invocation = self._visitBinaryOp(new_op, previous, expr, first_name, alternative_name)
1.8 + invocation = self._visitBinaryCompareOp(new_op, previous, expr, first_name, alternative_name)
1.9
1.10 elif op_name == "is":
1.11 invocation = InvokeFunction(
1.12 @@ -1301,7 +1301,7 @@
1.13 else:
1.14 test = Conditional(
1.15 isolate_test=1,
1.16 - test=CheckExc(expr=LoadExc(), choices=self._visitTryExcept(spec))
1.17 + test=CheckType(expr=LoadExc(), choices=self._visitTryExcept(spec))
1.18 )
1.19 test.body = []
1.20
1.21 @@ -1430,6 +1430,95 @@
1.22 def _visitBinary(self, binary, left_name, right_name):
1.23 return self._visitBinaryOp(binary, self.dispatch(binary.left), self.dispatch(binary.right), left_name, right_name)
1.24
1.25 + def _visitBinaryCompareOp(self, binary, left, right, left_name, right_name):
1.26 +
1.27 + """
1.28 + Emulate the current mechanisms by producing nodes as follows:
1.29 +
1.30 + InvokeBlock -> Subprogram -> StoreTemp (expr) -> x.__lt__(y)
1.31 + Conditional (test) -> __is__(LoadTemp, NotImplemented)
1.32 + (body) -> ReleaseTemp
1.33 + StoreTemp (expr) -> y.__gt__(x)
1.34 + Conditional (test) -> __is__(LoadTemp, NotImplemented)
1.35 + (body) -> ReturnFromBlock (expr) -> False
1.36 + (else) -> ReturnFromBlock (expr) -> LoadTemp
1.37 + (else) -> ReturnFromBlock (expr) -> LoadTemp
1.38 + """
1.39 +
1.40 + subprogram = Subprogram(name=None, module=self.module, internal=1, returns_value=1, params=[], star=None, dstar=None)
1.41 + self.current_subprograms.append(subprogram)
1.42 +
1.43 + subprogram.code = [
1.44 + StoreTemp(
1.45 + expr=InvokeFunction(
1.46 + binary,
1.47 + expr=LoadAttr(expr=left, name=left_name),
1.48 + args=[right],
1.49 + star=None,
1.50 + dstar=None)
1.51 + ),
1.52 + Conditional(
1.53 + isolate_test=1,
1.54 + test=CheckType(
1.55 + expr=LoadTemp(), choices=[LoadName(name="NotImplementedType")]
1.56 + ),
1.57 + body=[
1.58 + ReleaseTemp(),
1.59 + StoreTemp(
1.60 + expr=InvokeFunction(
1.61 + binary,
1.62 + expr=LoadAttr(expr=right, name=right_name),
1.63 + args=[left],
1.64 + star=None,
1.65 + dstar=None)
1.66 + ),
1.67 + Conditional(
1.68 + isolate_test=1,
1.69 + test=CheckType(
1.70 + expr=LoadTemp(), choices=[LoadName(name="NotImplementedType")]
1.71 + ),
1.72 + body=[
1.73 + ReturnFromBlock(
1.74 + expr=LoadName(name="False")
1.75 + )
1.76 + ],
1.77 + else_=[
1.78 + CheckType(
1.79 + inverted=1, expr=LoadTemp(), choices=[LoadName(name="NotImplementedType")]
1.80 + ),
1.81 + ReturnFromBlock(
1.82 + expr=LoadTemp()
1.83 + )
1.84 + ]
1.85 + )
1.86 + ],
1.87 + else_=[
1.88 + CheckType(
1.89 + inverted=1, expr=LoadTemp(), choices=[LoadName(name="NotImplementedType")]
1.90 + ),
1.91 + ReturnFromBlock(
1.92 + expr=LoadTemp()
1.93 + )
1.94 + ]
1.95 + )
1.96 + ]
1.97 +
1.98 + self.current_subprograms.pop()
1.99 + self.subprograms.append(subprogram); self.subnames[subprogram.full_name()] = subprogram
1.100 +
1.101 + result = InvokeBlock(
1.102 + binary,
1.103 + produces_result=1,
1.104 + expr=LoadRef(ref=subprogram)
1.105 + )
1.106 +
1.107 + # Make nice annotations for the viewer.
1.108 +
1.109 + binary._left_call = subprogram.code[0].expr
1.110 + binary._right_call = subprogram.code[1].body[1].expr
1.111 +
1.112 + return result
1.113 +
1.114 def _visitBinaryOp(self, binary, left, right, left_name, right_name):
1.115
1.116 """
1.117 @@ -1437,7 +1526,7 @@
1.118
1.119 InvokeBlock -> Subprogram -> Try (body) -> ReturnFromBlock (expr) -> x.__add__(y)
1.120 (else)
1.121 - (handler) -> Conditional (test) -> CheckExc (expr) -> LoadExc
1.122 + (handler) -> Conditional (test) -> CheckType (expr) -> LoadExc
1.123 (choices) -> LoadName TypeError
1.124 (body) -> ReturnFromBlock (expr) -> y.__radd__(x)
1.125 (else)
1.126 @@ -1462,7 +1551,7 @@
1.127 finally_=[],
1.128 handler=[
1.129 Conditional(
1.130 - test=CheckExc(expr=LoadExc(), choices=[LoadName(name="TypeError")]),
1.131 + test=CheckType(expr=LoadExc(), choices=[LoadName(name="TypeError")]),
1.132 body=[
1.133 ReturnFromBlock(
1.134 expr=InvokeFunction(