1.1 --- a/lib/builtins.py Sat Oct 21 02:53:36 2006 +0200
1.2 +++ b/lib/builtins.py Sat Oct 21 02:54:10 2006 +0200
1.3 @@ -19,39 +19,9 @@
1.4 License along with this library; see the file LICENCE.txt
1.5 If not, write to the Free Software Foundation, Inc.,
1.6 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
1.7 -
1.8 ---------
1.9 -
1.10 -The docstring annotations have the following meanings:
1.11 -
1.12 - NAME Indicates a "stable" name used by callers of a function
1.13 - instead of a generated name which would distinguish
1.14 - different specialisations.
1.15 -
1.16 - NATIVE Means that the class or function body details are not
1.17 - accurate representations of the actual code and should not
1.18 - be generated by a compiler.
1.19 -
1.20 - INTERCHANGEABLE Indicates that instances of a class are not sufficiently or
1.21 - meaningfully distinguishable from each other with regard to
1.22 - instantiation.
1.23 -
1.24 - SPECIAL Indicates that the compiler should try and optimise calls to
1.25 - the annotated function.
1.26 -
1.27 - ATOMIC Indicates that the class and its instance(s) cannot store
1.28 - attributes, although some may be predefined (such as the
1.29 - __true__ method).
1.30 -
1.31 ---------
1.32 -NATIVE
1.33 """
1.34
1.35 class boolean:
1.36 - """
1.37 - NATIVE
1.38 - INTERCHANGEABLE
1.39 - """
1.40 def __true__(self):
1.41 return self
1.42
1.43 @@ -62,210 +32,122 @@
1.44 return "False"
1.45
1.46 class int:
1.47 - """
1.48 - NATIVE
1.49 - INTERCHANGEABLE
1.50 - """
1.51 def __iadd__(self, other):
1.52 - """
1.53 - NAME: IMPL.builtins.int.__iadd__
1.54 - NATIVE
1.55 - """
1.56 if isinstance(other, int):
1.57 return int()
1.58 else:
1.59 raise TypeError
1.60
1.61 def __isub__(self, other):
1.62 - """
1.63 - NAME: IMPL.builtins.int.__isub__
1.64 - NATIVE
1.65 - """
1.66 if isinstance(other, int):
1.67 return int()
1.68 else:
1.69 raise TypeError
1.70
1.71 def __add__(self, other):
1.72 - """
1.73 - NAME: IMPL.builtins.int.__add__
1.74 - NATIVE
1.75 - """
1.76 if isinstance(other, int):
1.77 return int()
1.78 else:
1.79 raise TypeError
1.80
1.81 def __radd__(self, other):
1.82 - """
1.83 - NAME: IMPL.builtins.int.__radd__
1.84 - NATIVE
1.85 - """
1.86 if isinstance(other, int):
1.87 return int()
1.88 else:
1.89 raise TypeError
1.90
1.91 def __sub__(self, other):
1.92 - """
1.93 - NAME: IMPL.builtins.int.__sub__
1.94 - NATIVE
1.95 - """
1.96 if isinstance(other, int):
1.97 return int()
1.98 else:
1.99 raise TypeError
1.100
1.101 def __rsub__(self, other):
1.102 - """
1.103 - NAME: IMPL.builtins.int.__rsub__
1.104 - NATIVE
1.105 - """
1.106 if isinstance(other, int):
1.107 return int()
1.108 else:
1.109 raise TypeError
1.110
1.111 def __mul__(self, other):
1.112 - """
1.113 - NAME: IMPL.builtins.int.__mul__
1.114 - NATIVE
1.115 - """
1.116 if isinstance(other, int):
1.117 return int()
1.118 else:
1.119 raise TypeError
1.120
1.121 def __rmul__(self, other):
1.122 - """
1.123 - NAME: IMPL.builtins.int.__rmul__
1.124 - NATIVE
1.125 - """
1.126 if isinstance(other, int):
1.127 return int()
1.128 else:
1.129 raise TypeError
1.130
1.131 def __div__(self, other):
1.132 - """
1.133 - NAME: IMPL.builtins.int.__div__
1.134 - NATIVE
1.135 - """
1.136 if isinstance(other, int):
1.137 return int()
1.138 else:
1.139 raise TypeError
1.140
1.141 def __rdiv__(self, other):
1.142 - """
1.143 - NAME: IMPL.builtins.int.__rdiv__
1.144 - NATIVE
1.145 - """
1.146 if isinstance(other, int):
1.147 return int()
1.148 else:
1.149 raise TypeError
1.150
1.151 def __pow__(self, other):
1.152 - """
1.153 - NAME: IMPL.builtins.int.__pow__
1.154 - NATIVE
1.155 - """
1.156 if isinstance(other, int):
1.157 return int()
1.158 else:
1.159 raise TypeError
1.160
1.161 def __lt__(self, other):
1.162 - """
1.163 - NAME: IMPL.builtins.int.__lt__
1.164 - NATIVE
1.165 - """
1.166 if isinstance(other, int):
1.167 return boolean()
1.168 else:
1.169 raise TypeError
1.170
1.171 def __gt__(self, other):
1.172 - """
1.173 - NAME: IMPL.builtins.int.__gt__
1.174 - NATIVE
1.175 - """
1.176 if isinstance(other, int):
1.177 return boolean()
1.178 else:
1.179 raise TypeError
1.180
1.181 def __le__(self, other):
1.182 - """
1.183 - NAME: IMPL.builtins.int.__le__
1.184 - NATIVE
1.185 - """
1.186 if isinstance(other, int):
1.187 return boolean()
1.188 else:
1.189 raise TypeError
1.190
1.191 def __ge__(self, other):
1.192 - """
1.193 - NAME: IMPL.builtins.int.__ge__
1.194 - NATIVE
1.195 - """
1.196 if isinstance(other, int):
1.197 return boolean()
1.198 else:
1.199 raise TypeError
1.200
1.201 def __eq__(self, other):
1.202 - """
1.203 - NAME: IMPL.builtins.int.__eq__
1.204 - NATIVE
1.205 - """
1.206 if isinstance(other, int):
1.207 return boolean()
1.208 else:
1.209 raise TypeError
1.210
1.211 def __ne__(self, other):
1.212 - """
1.213 - NAME: IMPL.builtins.int.__ne__
1.214 - NATIVE
1.215 - """
1.216 if isinstance(other, int):
1.217 return boolean()
1.218 else:
1.219 raise TypeError
1.220
1.221 def __neg__(self):
1.222 - """
1.223 - NAME: IMPL.builtins.int.__neg__
1.224 - NATIVE
1.225 - """
1.226 return int()
1.227
1.228 def __pos__(self):
1.229 return self
1.230
1.231 def __str__(self):
1.232 - """
1.233 - NAME: IMPL.builtins.int.__str__
1.234 - NATIVE
1.235 - """
1.236 return string()
1.237
1.238 def __true__(self):
1.239 return self != 0
1.240
1.241 class long:
1.242 - """
1.243 - NATIVE
1.244 - INTERCHANGEABLE
1.245 - """
1.246 def __iadd__(self, other):
1.247 - """
1.248 - NAME: IMPL.builtins.long.__iadd__
1.249 - NATIVE
1.250 - """
1.251 if isinstance(other, int):
1.252 return long()
1.253 elif isinstance(other, long):
1.254 @@ -274,10 +156,6 @@
1.255 raise TypeError
1.256
1.257 def __isub__(self, other):
1.258 - """
1.259 - NAME: IMPL.builtins.long.__isub__
1.260 - NATIVE
1.261 - """
1.262 if isinstance(other, int):
1.263 return long()
1.264 elif isinstance(other, long):
1.265 @@ -286,10 +164,6 @@
1.266 raise TypeError
1.267
1.268 def __add__(self, other):
1.269 - """
1.270 - NAME: IMPL.builtins.long.__add__
1.271 - NATIVE
1.272 - """
1.273 if isinstance(other, int):
1.274 return long()
1.275 elif isinstance(other, long):
1.276 @@ -298,10 +172,6 @@
1.277 raise TypeError
1.278
1.279 def __radd__(self, other):
1.280 - """
1.281 - NAME: IMPL.builtins.long.__radd__
1.282 - NATIVE
1.283 - """
1.284 if isinstance(other, int):
1.285 return long()
1.286 elif isinstance(other, long):
1.287 @@ -310,10 +180,6 @@
1.288 raise TypeError
1.289
1.290 def __sub__(self, other):
1.291 - """
1.292 - NAME: IMPL.builtins.long.__sub__
1.293 - NATIVE
1.294 - """
1.295 if isinstance(other, int):
1.296 return long()
1.297 elif isinstance(other, long):
1.298 @@ -322,10 +188,6 @@
1.299 raise TypeError
1.300
1.301 def __rsub__(self, other):
1.302 - """
1.303 - NAME: IMPL.builtins.long.__rsub__
1.304 - NATIVE
1.305 - """
1.306 if isinstance(other, int):
1.307 return long()
1.308 elif isinstance(other, long):
1.309 @@ -334,10 +196,6 @@
1.310 raise TypeError
1.311
1.312 def __lt__(self, other):
1.313 - """
1.314 - NAME: IMPL.builtins.long.__lt__
1.315 - NATIVE
1.316 - """
1.317 if isinstance(other, int):
1.318 return boolean()
1.319 elif isinstance(other, long):
1.320 @@ -346,10 +204,6 @@
1.321 raise TypeError
1.322
1.323 def __gt__(self, other):
1.324 - """
1.325 - NAME: IMPL.builtins.long.__gt__
1.326 - NATIVE
1.327 - """
1.328 if isinstance(other, int):
1.329 return boolean()
1.330 elif isinstance(other, long):
1.331 @@ -358,10 +212,6 @@
1.332 raise TypeError
1.333
1.334 def __le__(self, other):
1.335 - """
1.336 - NAME: IMPL.builtins.long.__le__
1.337 - NATIVE
1.338 - """
1.339 if isinstance(other, int):
1.340 return boolean()
1.341 elif isinstance(other, long):
1.342 @@ -370,10 +220,6 @@
1.343 raise TypeError
1.344
1.345 def __ge__(self, other):
1.346 - """
1.347 - NAME: IMPL.builtins.long.__ge__
1.348 - NATIVE
1.349 - """
1.350 if isinstance(other, int):
1.351 return boolean()
1.352 elif isinstance(other, long):
1.353 @@ -382,10 +228,6 @@
1.354 raise TypeError
1.355
1.356 def __eq__(self, other):
1.357 - """
1.358 - NAME: IMPL.builtins.long.__eq__
1.359 - NATIVE
1.360 - """
1.361 if isinstance(other, int):
1.362 return boolean()
1.363 elif isinstance(other, long):
1.364 @@ -394,10 +236,6 @@
1.365 raise TypeError
1.366
1.367 def __ne__(self, other):
1.368 - """
1.369 - NAME: IMPL.builtins.long.__ne__
1.370 - NATIVE
1.371 - """
1.372 if isinstance(other, int):
1.373 return boolean()
1.374 elif isinstance(other, long):
1.375 @@ -406,35 +244,19 @@
1.376 raise TypeError
1.377
1.378 def __neg__(self):
1.379 - """
1.380 - NAME: IMPL.builtins.long.__neg__
1.381 - NATIVE
1.382 - """
1.383 return long()
1.384
1.385 def __pos__(self):
1.386 return self
1.387
1.388 def __str__(self):
1.389 - """
1.390 - NAME: IMPL.builtins.long.__str__
1.391 - NATIVE
1.392 - """
1.393 return string()
1.394
1.395 def __true__(self):
1.396 return self != 0
1.397
1.398 class float:
1.399 - """
1.400 - NATIVE
1.401 - INTERCHANGEABLE
1.402 - """
1.403 def __iadd__(self, other):
1.404 - """
1.405 - NAME: IMPL.builtins.float.__iadd__
1.406 - NATIVE
1.407 - """
1.408 if isinstance(other, int):
1.409 return float()
1.410 elif isinstance(other, long):
1.411 @@ -445,10 +267,6 @@
1.412 raise TypeError
1.413
1.414 def __isub__(self, other):
1.415 - """
1.416 - NAME: IMPL.builtins.float.__isub__
1.417 - NATIVE
1.418 - """
1.419 if isinstance(other, int):
1.420 return float()
1.421 elif isinstance(other, long):
1.422 @@ -459,10 +277,6 @@
1.423 raise TypeError
1.424
1.425 def __add__(self, other):
1.426 - """
1.427 - NAME: IMPL.builtins.float.__add__
1.428 - NATIVE
1.429 - """
1.430 if isinstance(other, int):
1.431 return float()
1.432 elif isinstance(other, long):
1.433 @@ -473,10 +287,6 @@
1.434 raise TypeError
1.435
1.436 def __radd__(self, other):
1.437 - """
1.438 - NAME: IMPL.builtins.float.__radd__
1.439 - NATIVE
1.440 - """
1.441 if isinstance(other, int):
1.442 return float()
1.443 elif isinstance(other, long):
1.444 @@ -487,10 +297,6 @@
1.445 raise TypeError
1.446
1.447 def __sub__(self, other):
1.448 - """
1.449 - NAME: IMPL.builtins.float.__sub__
1.450 - NATIVE
1.451 - """
1.452 if isinstance(other, int):
1.453 return float()
1.454 elif isinstance(other, long):
1.455 @@ -501,10 +307,6 @@
1.456 raise TypeError
1.457
1.458 def __rsub__(self, other):
1.459 - """
1.460 - NAME: IMPL.builtins.float.__rsub__
1.461 - NATIVE
1.462 - """
1.463 if isinstance(other, int):
1.464 return float()
1.465 elif isinstance(other, long):
1.466 @@ -515,10 +317,6 @@
1.467 raise TypeError
1.468
1.469 def __mul__(self, other):
1.470 - """
1.471 - NAME: IMPL.builtins.float.__mul__
1.472 - NATIVE
1.473 - """
1.474 if isinstance(other, int):
1.475 return float()
1.476 elif isinstance(other, long):
1.477 @@ -529,10 +327,6 @@
1.478 raise TypeError
1.479
1.480 def __rmul__(self, other):
1.481 - """
1.482 - NAME: IMPL.builtins.float.__rmul__
1.483 - NATIVE
1.484 - """
1.485 if isinstance(other, int):
1.486 return float()
1.487 elif isinstance(other, long):
1.488 @@ -543,10 +337,6 @@
1.489 raise TypeError
1.490
1.491 def __div__(self, other):
1.492 - """
1.493 - NAME: IMPL.builtins.float.__div__
1.494 - NATIVE
1.495 - """
1.496 if isinstance(other, int):
1.497 return float()
1.498 elif isinstance(other, long):
1.499 @@ -557,10 +347,6 @@
1.500 raise TypeError
1.501
1.502 def __rdiv__(self, other):
1.503 - """
1.504 - NAME: IMPL.builtins.float.__rdiv__
1.505 - NATIVE
1.506 - """
1.507 if isinstance(other, int):
1.508 return float()
1.509 elif isinstance(other, long):
1.510 @@ -571,10 +357,6 @@
1.511 raise TypeError
1.512
1.513 def __pow__(self, other):
1.514 - """
1.515 - NAME: IMPL.builtins.float.__pow__
1.516 - NATIVE
1.517 - """
1.518 if isinstance(other, int):
1.519 return float()
1.520 elif isinstance(other, long):
1.521 @@ -585,10 +367,6 @@
1.522 raise TypeError
1.523
1.524 def __rpow__(self, other):
1.525 - """
1.526 - NAME: IMPL.builtins.float.__rpow__
1.527 - NATIVE
1.528 - """
1.529 if isinstance(other, int):
1.530 return float()
1.531 elif isinstance(other, long):
1.532 @@ -599,10 +377,6 @@
1.533 raise TypeError
1.534
1.535 def __lt__(self, other):
1.536 - """
1.537 - NAME: IMPL.builtins.float.__lt__
1.538 - NATIVE
1.539 - """
1.540 if isinstance(other, int):
1.541 return boolean()
1.542 elif isinstance(other, long):
1.543 @@ -613,10 +387,6 @@
1.544 raise TypeError
1.545
1.546 def __gt__(self, other):
1.547 - """
1.548 - NAME: IMPL.builtins.float.__gt__
1.549 - NATIVE
1.550 - """
1.551 if isinstance(other, int):
1.552 return boolean()
1.553 elif isinstance(other, long):
1.554 @@ -627,10 +397,6 @@
1.555 raise TypeError
1.556
1.557 def __le__(self, other):
1.558 - """
1.559 - NAME: IMPL.builtins.float.__le__
1.560 - NATIVE
1.561 - """
1.562 if isinstance(other, int):
1.563 return boolean()
1.564 elif isinstance(other, long):
1.565 @@ -641,10 +407,6 @@
1.566 raise TypeError
1.567
1.568 def __ge__(self, other):
1.569 - """
1.570 - NAME: IMPL.builtins.float.__ge__
1.571 - NATIVE
1.572 - """
1.573 if isinstance(other, int):
1.574 return boolean()
1.575 elif isinstance(other, long):
1.576 @@ -655,10 +417,6 @@
1.577 raise TypeError
1.578
1.579 def __eq__(self, other):
1.580 - """
1.581 - NAME: IMPL.builtins.float.__eq__
1.582 - NATIVE
1.583 - """
1.584 if isinstance(other, int):
1.585 return boolean()
1.586 elif isinstance(other, long):
1.587 @@ -669,10 +427,6 @@
1.588 raise TypeError
1.589
1.590 def __ne__(self, other):
1.591 - """
1.592 - NAME: IMPL.builtins.float.__ne__
1.593 - NATIVE
1.594 - """
1.595 if isinstance(other, int):
1.596 return boolean()
1.597 elif isinstance(other, long):
1.598 @@ -683,55 +437,31 @@
1.599 raise TypeError
1.600
1.601 def __neg__(self):
1.602 - """
1.603 - NAME: IMPL.builtins.float.__neg__
1.604 - NATIVE
1.605 - """
1.606 return float()
1.607
1.608 def __pos__(self):
1.609 return self
1.610
1.611 def __str__(self):
1.612 - """
1.613 - NAME: IMPL.builtins.float.__str__
1.614 - NATIVE
1.615 - """
1.616 return string()
1.617
1.618 def __true__(self):
1.619 return self != 0
1.620
1.621 class string:
1.622 - """
1.623 - NATIVE
1.624 - INTERCHANGEABLE
1.625 - """
1.626 def __add__(self, other):
1.627 - """
1.628 - NAME: IMPL.builtins.string.__add__
1.629 - NATIVE
1.630 - """
1.631 if isinstance(other, string):
1.632 return string()
1.633 else:
1.634 raise TypeError
1.635
1.636 def __radd__(self, other):
1.637 - """
1.638 - NAME: IMPL.builtins.string.__radd__
1.639 - NATIVE
1.640 - """
1.641 if isinstance(other, string):
1.642 return string()
1.643 else:
1.644 raise TypeError
1.645
1.646 def __len__(self):
1.647 - """
1.648 - NAME: IMPL.builtins.string.__len__
1.649 - NATIVE
1.650 - """
1.651 return int()
1.652
1.653 def __str__(self):
1.654 @@ -760,38 +490,24 @@
1.655 return s
1.656
1.657 class buffer:
1.658 - """
1.659 - NATIVE
1.660 - INTERCHANGEABLE
1.661 - """
1.662 def __init__(self, size):
1.663 - """
1.664 - NAME: IMPL.builtins.buffer.__init__
1.665 - NATIVE
1.666 - """
1.667 if not isinstance(size, int):
1.668 raise TypeError
1.669
1.670 def append(self, s):
1.671 - """
1.672 - NAME: IMPL.builtins.buffer.append
1.673 - NATIVE
1.674 - """
1.675 if not isinstance(s, string):
1.676 raise TypeError
1.677 pass
1.678
1.679 def __str__(self):
1.680 - """
1.681 - NAME: IMPL.builtins.buffer.__str__
1.682 - NATIVE
1.683 - """
1.684 return string()
1.685
1.686 class list:
1.687 - def __init__(self):
1.688 + def __init__(self, *args):
1.689 self.next = None
1.690 self.last = self
1.691 + for arg in args:
1.692 + self.append(arg)
1.693
1.694 def __getitem__(self, index):
1.695 i = 0
1.696 @@ -900,10 +616,6 @@
1.697 raise StopIteration
1.698
1.699 def __true__(self):
1.700 - """
1.701 - NAME: IMPL.builtins.int.__true__
1.702 - NATIVE
1.703 - """
1.704 return boolean()
1.705
1.706 class tuple:
1.707 @@ -996,10 +708,6 @@
1.708 raise StopIteration
1.709
1.710 def __true__(self):
1.711 - """
1.712 - NAME: IMPL.builtins.int.__true__
1.713 - NATIVE
1.714 - """
1.715 return boolean()
1.716
1.717 class dict:
1.718 @@ -1021,11 +729,6 @@
1.719 pass
1.720
1.721 class none:
1.722 - """
1.723 - NATIVE
1.724 - INTERCHANGEABLE
1.725 - ATOMIC
1.726 - """
1.727 def __true__(self):
1.728 return False
1.729
1.730 @@ -1033,27 +736,12 @@
1.731 return "None"
1.732
1.733 class undefined:
1.734 - """
1.735 - NATIVE
1.736 - INTERCHANGEABLE
1.737 - ATOMIC
1.738 - """
1.739 pass
1.740
1.741 def isinstance(obj, cls):
1.742 - """
1.743 - NAME: IMPL.builtins.isinstance
1.744 - NATIVE
1.745 - SPECIAL
1.746 - """
1.747 return boolean()
1.748
1.749 def issubclass(cls1, cls2):
1.750 - """
1.751 - NAME: IMPL.builtins.isinstance
1.752 - NATIVE
1.753 - SPECIAL
1.754 - """
1.755 return boolean()
1.756
1.757 def len(x):
1.758 @@ -1097,24 +785,12 @@
1.759 # Special functions. These all operate on references at run-time.
1.760
1.761 def __is__(a, b):
1.762 - """
1.763 - NAME: IMPL.builtins.__is__
1.764 - NATIVE
1.765 - """
1.766 return boolean()
1.767
1.768 def __is_not__(a, b):
1.769 - """
1.770 - NAME: IMPL.builtins.__is_not__
1.771 - NATIVE
1.772 - """
1.773 return boolean()
1.774
1.775 def __not__(a):
1.776 - """
1.777 - NAME: IMPL.builtins.__not__
1.778 - NATIVE
1.779 - """
1.780 return boolean()
1.781
1.782 # vim: tabstop=4 expandtab shiftwidth=4