1.1 --- a/lib/builtins.py Sat Nov 25 00:40:21 2006 +0100
1.2 +++ b/lib/builtins.py Sat Nov 25 01:36:18 2006 +0100
1.3 @@ -22,11 +22,13 @@
1.4 """
1.5
1.6 class object:
1.7 - def __true__(self):
1.8 + def __bool__(self):
1.9 + # NOTE: Should really test for __len__ and then resort to False.
1.10 + # NOTE: See the reference: 3.3.1 Basic customization
1.11 return False
1.12
1.13 -class boolean:
1.14 - def __true__(self):
1.15 +class bool:
1.16 + def __bool__(self):
1.17 return self
1.18
1.19 def __str__(self):
1.20 @@ -104,37 +106,37 @@
1.21
1.22 def __lt__(self, other):
1.23 if isinstance(other, int):
1.24 - return boolean()
1.25 + return bool()
1.26 else:
1.27 raise TypeError
1.28
1.29 def __gt__(self, other):
1.30 if isinstance(other, int):
1.31 - return boolean()
1.32 + return bool()
1.33 else:
1.34 raise TypeError
1.35
1.36 def __le__(self, other):
1.37 if isinstance(other, int):
1.38 - return boolean()
1.39 + return bool()
1.40 else:
1.41 raise TypeError
1.42
1.43 def __ge__(self, other):
1.44 if isinstance(other, int):
1.45 - return boolean()
1.46 + return bool()
1.47 else:
1.48 raise TypeError
1.49
1.50 def __eq__(self, other):
1.51 if isinstance(other, int):
1.52 - return boolean()
1.53 + return bool()
1.54 else:
1.55 raise TypeError
1.56
1.57 def __ne__(self, other):
1.58 if isinstance(other, int):
1.59 - return boolean()
1.60 + return bool()
1.61 else:
1.62 raise TypeError
1.63
1.64 @@ -147,7 +149,7 @@
1.65 def __str__(self):
1.66 return string()
1.67
1.68 - def __true__(self):
1.69 + def __bool__(self):
1.70 return self != 0
1.71
1.72 class long:
1.73 @@ -201,49 +203,49 @@
1.74
1.75 def __lt__(self, other):
1.76 if isinstance(other, int):
1.77 - return boolean()
1.78 + return bool()
1.79 elif isinstance(other, long):
1.80 - return boolean()
1.81 + return bool()
1.82 else:
1.83 raise TypeError
1.84
1.85 def __gt__(self, other):
1.86 if isinstance(other, int):
1.87 - return boolean()
1.88 + return bool()
1.89 elif isinstance(other, long):
1.90 - return boolean()
1.91 + return bool()
1.92 else:
1.93 raise TypeError
1.94
1.95 def __le__(self, other):
1.96 if isinstance(other, int):
1.97 - return boolean()
1.98 + return bool()
1.99 elif isinstance(other, long):
1.100 - return boolean()
1.101 + return bool()
1.102 else:
1.103 raise TypeError
1.104
1.105 def __ge__(self, other):
1.106 if isinstance(other, int):
1.107 - return boolean()
1.108 + return bool()
1.109 elif isinstance(other, long):
1.110 - return boolean()
1.111 + return bool()
1.112 else:
1.113 raise TypeError
1.114
1.115 def __eq__(self, other):
1.116 if isinstance(other, int):
1.117 - return boolean()
1.118 + return bool()
1.119 elif isinstance(other, long):
1.120 - return boolean()
1.121 + return bool()
1.122 else:
1.123 raise TypeError
1.124
1.125 def __ne__(self, other):
1.126 if isinstance(other, int):
1.127 - return boolean()
1.128 + return bool()
1.129 elif isinstance(other, long):
1.130 - return boolean()
1.131 + return bool()
1.132 else:
1.133 raise TypeError
1.134
1.135 @@ -256,7 +258,7 @@
1.136 def __str__(self):
1.137 return string()
1.138
1.139 - def __true__(self):
1.140 + def __bool__(self):
1.141 return self != 0
1.142
1.143 class float:
1.144 @@ -382,61 +384,61 @@
1.145
1.146 def __lt__(self, other):
1.147 if isinstance(other, int):
1.148 - return boolean()
1.149 + return bool()
1.150 elif isinstance(other, long):
1.151 - return boolean()
1.152 + return bool()
1.153 elif isinstance(other, float):
1.154 - return boolean()
1.155 + return bool()
1.156 else:
1.157 raise TypeError
1.158
1.159 def __gt__(self, other):
1.160 if isinstance(other, int):
1.161 - return boolean()
1.162 + return bool()
1.163 elif isinstance(other, long):
1.164 - return boolean()
1.165 + return bool()
1.166 elif isinstance(other, float):
1.167 - return boolean()
1.168 + return bool()
1.169 else:
1.170 raise TypeError
1.171
1.172 def __le__(self, other):
1.173 if isinstance(other, int):
1.174 - return boolean()
1.175 + return bool()
1.176 elif isinstance(other, long):
1.177 - return boolean()
1.178 + return bool()
1.179 elif isinstance(other, float):
1.180 - return boolean()
1.181 + return bool()
1.182 else:
1.183 raise TypeError
1.184
1.185 def __ge__(self, other):
1.186 if isinstance(other, int):
1.187 - return boolean()
1.188 + return bool()
1.189 elif isinstance(other, long):
1.190 - return boolean()
1.191 + return bool()
1.192 elif isinstance(other, float):
1.193 - return boolean()
1.194 + return bool()
1.195 else:
1.196 raise TypeError
1.197
1.198 def __eq__(self, other):
1.199 if isinstance(other, int):
1.200 - return boolean()
1.201 + return bool()
1.202 elif isinstance(other, long):
1.203 - return boolean()
1.204 + return bool()
1.205 elif isinstance(other, float):
1.206 - return boolean()
1.207 + return bool()
1.208 else:
1.209 raise TypeError
1.210
1.211 def __ne__(self, other):
1.212 if isinstance(other, int):
1.213 - return boolean()
1.214 + return bool()
1.215 elif isinstance(other, long):
1.216 - return boolean()
1.217 + return bool()
1.218 elif isinstance(other, float):
1.219 - return boolean()
1.220 + return bool()
1.221 else:
1.222 raise TypeError
1.223
1.224 @@ -449,7 +451,7 @@
1.225 def __str__(self):
1.226 return string()
1.227
1.228 - def __true__(self):
1.229 + def __bool__(self):
1.230 return self != 0
1.231
1.232 class str:
1.233 @@ -474,7 +476,7 @@
1.234 def __str__(self):
1.235 return self
1.236
1.237 - def __true__(self):
1.238 + def __bool__(self):
1.239 return self.__len__() != 0
1.240
1.241 def join(self, l):
1.242 @@ -611,7 +613,7 @@
1.243 def __iter__(self):
1.244 return listiterator(self)
1.245
1.246 - def __true__(self):
1.247 + def __bool__(self):
1.248 return self.__len__() != 0
1.249
1.250 class listiterator:
1.251 @@ -627,8 +629,8 @@
1.252 else:
1.253 raise StopIteration
1.254
1.255 - def __true__(self):
1.256 - return boolean()
1.257 + def __bool__(self):
1.258 + return bool()
1.259
1.260 class tuple:
1.261 def __init__(self, *args):
1.262 @@ -703,7 +705,7 @@
1.263 def __iter__(self):
1.264 return tupleiterator(self)
1.265
1.266 - def __true__(self):
1.267 + def __bool__(self):
1.268 return self.__len__() != 0
1.269
1.270 class tupleiterator:
1.271 @@ -719,8 +721,8 @@
1.272 else:
1.273 raise StopIteration
1.274
1.275 - def __true__(self):
1.276 - return boolean()
1.277 + def __bool__(self):
1.278 + return bool()
1.279
1.280 class dict:
1.281 pass
1.282 @@ -741,7 +743,7 @@
1.283 pass
1.284
1.285 class none:
1.286 - def __true__(self):
1.287 + def __bool__(self):
1.288 return False
1.289
1.290 def __str__(self):
1.291 @@ -770,10 +772,10 @@
1.292 # General functions.
1.293
1.294 def isinstance(obj, cls):
1.295 - return boolean()
1.296 + return bool()
1.297
1.298 def issubclass(cls1, cls2):
1.299 - return boolean()
1.300 + return bool()
1.301
1.302 def len(x):
1.303 return x.__len__()
1.304 @@ -807,20 +809,20 @@
1.305
1.306 # Special values.
1.307
1.308 -True = boolean()
1.309 -False = boolean()
1.310 +True = bool()
1.311 +False = bool()
1.312 None = none()
1.313 Undefined = undefined()
1.314
1.315 # Special functions. These all operate on references at run-time.
1.316
1.317 def __is__(a, b):
1.318 - return boolean()
1.319 + return bool()
1.320
1.321 def __is_not__(a, b):
1.322 - return boolean()
1.323 + return bool()
1.324
1.325 def __not__(a):
1.326 - return boolean()
1.327 + return bool()
1.328
1.329 # vim: tabstop=4 expandtab shiftwidth=4
2.1 --- a/simplify.py Sat Nov 25 00:40:21 2006 +0100
2.2 +++ b/simplify.py Sat Nov 25 01:36:18 2006 +0100
2.3 @@ -277,7 +277,7 @@
2.4 results = nodes = []
2.5
2.6 # Produce something like...
2.7 - # expr.__true__() ? body
2.8 + # expr.__bool__() ? body
2.9
2.10 first = 1
2.11 for compare, stmt in if_.tests:
2.12 @@ -288,7 +288,7 @@
2.13 test=InvokeFunction(
2.14 expr=LoadAttr(
2.15 expr=self.dispatch(compare),
2.16 - name="__true__"
2.17 + name="__bool__"
2.18 ),
2.19 args=[],
2.20 star=None,
2.21 @@ -534,7 +534,7 @@
2.22
2.23 if node is not last:
2.24 nodes.append(StoreTemp(expr=expr))
2.25 - #invocation = InvokeFunction(expr=LoadAttr(expr=LoadTemp(), name="__true__"), args=[], star=None, dstar=None)
2.26 + #invocation = InvokeFunction(expr=LoadAttr(expr=LoadTemp(), name="__bool__"), args=[], star=None, dstar=None)
2.27 test = Conditional(test=self._visitNot(LoadTemp()), body=[Return(expr=LoadTemp())])
2.28 nodes.append(test)
2.29
2.30 @@ -594,7 +594,7 @@
2.31
2.32 if node is not last:
2.33 nodes.append(StoreTemp(expr=expr))
2.34 - invocation = InvokeFunction(expr=LoadAttr(expr=LoadTemp(), name="__true__"), args=[], star=None, dstar=None)
2.35 + invocation = InvokeFunction(expr=LoadAttr(expr=LoadTemp(), name="__bool__"), args=[], star=None, dstar=None)
2.36 test = Conditional(test=invocation, body=[Return(expr=LoadTemp())])
2.37 nodes.append(test)
2.38
2.39 @@ -626,7 +626,7 @@
2.40 invocation = InvokeFunction(
2.41 expr=LoadAttr(
2.42 expr=expr,
2.43 - name="__true__"
2.44 + name="__bool__"
2.45 ),
2.46 args=[],
2.47 star=None,
2.48 @@ -1195,7 +1195,7 @@
2.49 # Include a conditional statement in the subprogram.
2.50
2.51 test = Conditional(else_=[])
2.52 - test.test = InvokeFunction(expr=LoadAttr(expr=self.dispatch(while_.test), name="__true__"), args=[], star=None, dstar=None)
2.53 + test.test = InvokeFunction(expr=LoadAttr(expr=self.dispatch(while_.test), name="__bool__"), args=[], star=None, dstar=None)
2.54
2.55 # Inside the conditional, add a recursive invocation to the subprogram
2.56 # if the test condition was satisfied.