simplify

Annotated lib/builtins.py

64:4ba865697143
2006-10-07 paulb Improved argument mismatch error.
paulb@22 1
#!/usr/bin/env python
paulb@22 2
paulb@22 3
"""
paulb@22 4
Simple built-in classes and functions.
paulb@22 5
paulb@22 6
Copyright (C) 2005, 2006 Paul Boddie <paul@boddie.org.uk>
paulb@22 7
paulb@22 8
This software is free software; you can redistribute it and/or
paulb@22 9
modify it under the terms of the GNU General Public License as
paulb@22 10
published by the Free Software Foundation; either version 2 of
paulb@22 11
the License, or (at your option) any later version.
paulb@22 12
paulb@22 13
This software is distributed in the hope that it will be useful,
paulb@22 14
but WITHOUT ANY WARRANTY; without even the implied warranty of
paulb@22 15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
paulb@22 16
GNU General Public License for more details.
paulb@22 17
paulb@22 18
You should have received a copy of the GNU General Public
paulb@22 19
License along with this library; see the file LICENCE.txt
paulb@22 20
If not, write to the Free Software Foundation, Inc.,
paulb@22 21
51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
paulb@22 22
paulb@22 23
--------
paulb@22 24
paulb@22 25
The docstring annotations have the following meanings:
paulb@22 26
paulb@22 27
    NAME            Indicates a "stable" name used by callers of a function
paulb@22 28
                    instead of a generated name which would distinguish
paulb@22 29
                    different specialisations.
paulb@22 30
paulb@22 31
    NATIVE          Means that the class or function body details are not
paulb@22 32
                    accurate representations of the actual code and should not
paulb@22 33
                    be generated by a compiler.
paulb@22 34
paulb@22 35
    INTERCHANGEABLE Indicates that instances of a class are not sufficiently or
paulb@22 36
                    meaningfully distinguishable from each other with regard to
paulb@22 37
                    instantiation.
paulb@22 38
paulb@22 39
    SPECIAL         Indicates that the compiler should try and optimise calls to
paulb@22 40
                    the annotated function.
paulb@22 41
paulb@22 42
    ATOMIC          Indicates that the class and its instance(s) cannot store
paulb@22 43
                    attributes, although some may be predefined (such as the
paulb@22 44
                    __true__ method).
paulb@22 45
paulb@22 46
--------
paulb@22 47
NATIVE
paulb@22 48
"""
paulb@22 49
paulb@22 50
class boolean:
paulb@22 51
    """
paulb@22 52
    NATIVE
paulb@22 53
    INTERCHANGEABLE
paulb@22 54
    """
paulb@22 55
    def __true__(self):
paulb@22 56
        return self
paulb@22 57
paulb@22 58
    def __str__(self):
paulb@22 59
        if self:
paulb@22 60
            return "True"
paulb@22 61
        else:
paulb@22 62
            return "False"
paulb@22 63
paulb@22 64
class int:
paulb@22 65
    """
paulb@22 66
    NATIVE
paulb@22 67
    INTERCHANGEABLE
paulb@22 68
    """
paulb@22 69
    def __iadd__(self, other):
paulb@22 70
        """
paulb@22 71
        NAME: IMPL.builtins.int.__iadd__
paulb@22 72
        NATIVE
paulb@22 73
        """
paulb@22 74
        if isinstance(other, int):
paulb@22 75
            return int()
paulb@22 76
        else:
paulb@55 77
            raise TypeError
paulb@22 78
paulb@22 79
    def __isub__(self, other):
paulb@22 80
        """
paulb@22 81
        NAME: IMPL.builtins.int.__isub__
paulb@22 82
        NATIVE
paulb@22 83
        """
paulb@22 84
        if isinstance(other, int):
paulb@22 85
            return int()
paulb@22 86
        else:
paulb@55 87
            raise TypeError
paulb@22 88
paulb@22 89
    def __add__(self, other):
paulb@22 90
        """
paulb@22 91
        NAME: IMPL.builtins.int.__add__
paulb@22 92
        NATIVE
paulb@22 93
        """
paulb@22 94
        if isinstance(other, int):
paulb@22 95
            return int()
paulb@22 96
        else:
paulb@55 97
            raise TypeError
paulb@22 98
paulb@22 99
    def __radd__(self, other):
paulb@22 100
        """
paulb@22 101
        NAME: IMPL.builtins.int.__radd__
paulb@22 102
        NATIVE
paulb@22 103
        """
paulb@22 104
        if isinstance(other, int):
paulb@22 105
            return int()
paulb@22 106
        else:
paulb@55 107
            raise TypeError
paulb@22 108
paulb@22 109
    def __sub__(self, other):
paulb@22 110
        """
paulb@22 111
        NAME: IMPL.builtins.int.__sub__
paulb@22 112
        NATIVE
paulb@22 113
        """
paulb@22 114
        if isinstance(other, int):
paulb@22 115
            return int()
paulb@22 116
        else:
paulb@55 117
            raise TypeError
paulb@22 118
paulb@22 119
    def __rsub__(self, other):
paulb@22 120
        """
paulb@22 121
        NAME: IMPL.builtins.int.__rsub__
paulb@22 122
        NATIVE
paulb@22 123
        """
paulb@22 124
        if isinstance(other, int):
paulb@22 125
            return int()
paulb@22 126
        else:
paulb@55 127
            raise TypeError
paulb@22 128
paulb@22 129
    def __mul__(self, other):
paulb@22 130
        """
paulb@22 131
        NAME: IMPL.builtins.int.__mul__
paulb@22 132
        NATIVE
paulb@22 133
        """
paulb@22 134
        if isinstance(other, int):
paulb@22 135
            return int()
paulb@22 136
        else:
paulb@55 137
            raise TypeError
paulb@22 138
paulb@22 139
    def __rmul__(self, other):
paulb@22 140
        """
paulb@22 141
        NAME: IMPL.builtins.int.__rmul__
paulb@22 142
        NATIVE
paulb@22 143
        """
paulb@22 144
        if isinstance(other, int):
paulb@22 145
            return int()
paulb@22 146
        else:
paulb@55 147
            raise TypeError
paulb@22 148
paulb@22 149
    def __div__(self, other):
paulb@22 150
        """
paulb@22 151
        NAME: IMPL.builtins.int.__div__
paulb@22 152
        NATIVE
paulb@22 153
        """
paulb@22 154
        if isinstance(other, int):
paulb@22 155
            return int()
paulb@22 156
        else:
paulb@55 157
            raise TypeError
paulb@22 158
paulb@22 159
    def __rdiv__(self, other):
paulb@22 160
        """
paulb@22 161
        NAME: IMPL.builtins.int.__rdiv__
paulb@22 162
        NATIVE
paulb@22 163
        """
paulb@22 164
        if isinstance(other, int):
paulb@22 165
            return int()
paulb@22 166
        else:
paulb@55 167
            raise TypeError
paulb@22 168
paulb@22 169
    def __pow__(self, other):
paulb@22 170
        """
paulb@22 171
        NAME: IMPL.builtins.int.__pow__
paulb@22 172
        NATIVE
paulb@22 173
        """
paulb@22 174
        if isinstance(other, int):
paulb@22 175
            return int()
paulb@22 176
        else:
paulb@55 177
            raise TypeError
paulb@22 178
paulb@22 179
    def __lt__(self, other):
paulb@22 180
        """
paulb@22 181
        NAME: IMPL.builtins.int.__lt__
paulb@22 182
        NATIVE
paulb@22 183
        """
paulb@22 184
        if isinstance(other, int):
paulb@22 185
            return boolean()
paulb@22 186
        else:
paulb@55 187
            raise TypeError
paulb@22 188
paulb@22 189
    def __gt__(self, other):
paulb@22 190
        """
paulb@22 191
        NAME: IMPL.builtins.int.__gt__
paulb@22 192
        NATIVE
paulb@22 193
        """
paulb@22 194
        if isinstance(other, int):
paulb@22 195
            return boolean()
paulb@22 196
        else:
paulb@55 197
            raise TypeError
paulb@22 198
paulb@22 199
    def __le__(self, other):
paulb@22 200
        """
paulb@22 201
        NAME: IMPL.builtins.int.__le__
paulb@22 202
        NATIVE
paulb@22 203
        """
paulb@22 204
        if isinstance(other, int):
paulb@22 205
            return boolean()
paulb@22 206
        else:
paulb@55 207
            raise TypeError
paulb@22 208
paulb@22 209
    def __ge__(self, other):
paulb@22 210
        """
paulb@22 211
        NAME: IMPL.builtins.int.__ge__
paulb@22 212
        NATIVE
paulb@22 213
        """
paulb@22 214
        if isinstance(other, int):
paulb@22 215
            return boolean()
paulb@22 216
        else:
paulb@55 217
            raise TypeError
paulb@22 218
paulb@22 219
    def __eq__(self, other):
paulb@22 220
        """
paulb@22 221
        NAME: IMPL.builtins.int.__eq__
paulb@22 222
        NATIVE
paulb@22 223
        """
paulb@22 224
        if isinstance(other, int):
paulb@22 225
            return boolean()
paulb@22 226
        else:
paulb@55 227
            raise TypeError
paulb@22 228
paulb@22 229
    def __ne__(self, other):
paulb@22 230
        """
paulb@22 231
        NAME: IMPL.builtins.int.__ne__
paulb@22 232
        NATIVE
paulb@22 233
        """
paulb@22 234
        if isinstance(other, int):
paulb@22 235
            return boolean()
paulb@22 236
        else:
paulb@55 237
            raise TypeError
paulb@22 238
paulb@22 239
    def __neg__(self):
paulb@22 240
        """
paulb@22 241
        NAME: IMPL.builtins.int.__neg__
paulb@22 242
        NATIVE
paulb@22 243
        """
paulb@22 244
        return int()
paulb@22 245
paulb@22 246
    def __pos__(self):
paulb@22 247
        return self
paulb@22 248
paulb@22 249
    def __str__(self):
paulb@22 250
        """
paulb@22 251
        NAME: IMPL.builtins.int.__str__
paulb@22 252
        NATIVE
paulb@22 253
        """
paulb@22 254
        return string()
paulb@22 255
paulb@22 256
    def __true__(self):
paulb@22 257
        return self != 0
paulb@22 258
paulb@22 259
class long:
paulb@22 260
    """
paulb@22 261
    NATIVE
paulb@22 262
    INTERCHANGEABLE
paulb@22 263
    """
paulb@22 264
    def __iadd__(self, other):
paulb@22 265
        """
paulb@22 266
        NAME: IMPL.builtins.long.__iadd__
paulb@22 267
        NATIVE
paulb@22 268
        """
paulb@22 269
        if isinstance(other, int):
paulb@22 270
            return long()
paulb@22 271
        elif isinstance(other, long):
paulb@22 272
            return long()
paulb@22 273
        else:
paulb@55 274
            raise TypeError
paulb@22 275
paulb@22 276
    def __isub__(self, other):
paulb@22 277
        """
paulb@22 278
        NAME: IMPL.builtins.long.__isub__
paulb@22 279
        NATIVE
paulb@22 280
        """
paulb@22 281
        if isinstance(other, int):
paulb@22 282
            return long()
paulb@22 283
        elif isinstance(other, long):
paulb@22 284
            return long()
paulb@22 285
        else:
paulb@55 286
            raise TypeError
paulb@22 287
paulb@22 288
    def __add__(self, other):
paulb@22 289
        """
paulb@22 290
        NAME: IMPL.builtins.long.__add__
paulb@22 291
        NATIVE
paulb@22 292
        """
paulb@22 293
        if isinstance(other, int):
paulb@22 294
            return long()
paulb@22 295
        elif isinstance(other, long):
paulb@22 296
            return long()
paulb@22 297
        else:
paulb@55 298
            raise TypeError
paulb@22 299
paulb@22 300
    def __radd__(self, other):
paulb@22 301
        """
paulb@22 302
        NAME: IMPL.builtins.long.__radd__
paulb@22 303
        NATIVE
paulb@22 304
        """
paulb@22 305
        if isinstance(other, int):
paulb@22 306
            return long()
paulb@22 307
        elif isinstance(other, long):
paulb@22 308
            return long()
paulb@22 309
        else:
paulb@55 310
            raise TypeError
paulb@22 311
paulb@22 312
    def __sub__(self, other):
paulb@22 313
        """
paulb@22 314
        NAME: IMPL.builtins.long.__sub__
paulb@22 315
        NATIVE
paulb@22 316
        """
paulb@22 317
        if isinstance(other, int):
paulb@22 318
            return long()
paulb@22 319
        elif isinstance(other, long):
paulb@22 320
            return long()
paulb@22 321
        else:
paulb@55 322
            raise TypeError
paulb@22 323
paulb@22 324
    def __rsub__(self, other):
paulb@22 325
        """
paulb@22 326
        NAME: IMPL.builtins.long.__rsub__
paulb@22 327
        NATIVE
paulb@22 328
        """
paulb@22 329
        if isinstance(other, int):
paulb@22 330
            return long()
paulb@22 331
        elif isinstance(other, long):
paulb@22 332
            return long()
paulb@22 333
        else:
paulb@55 334
            raise TypeError
paulb@22 335
paulb@22 336
    def __lt__(self, other):
paulb@22 337
        """
paulb@22 338
        NAME: IMPL.builtins.long.__lt__
paulb@22 339
        NATIVE
paulb@22 340
        """
paulb@22 341
        if isinstance(other, int):
paulb@22 342
            return boolean()
paulb@22 343
        elif isinstance(other, long):
paulb@22 344
            return boolean()
paulb@22 345
        else:
paulb@55 346
            raise TypeError
paulb@22 347
paulb@22 348
    def __gt__(self, other):
paulb@22 349
        """
paulb@22 350
        NAME: IMPL.builtins.long.__gt__
paulb@22 351
        NATIVE
paulb@22 352
        """
paulb@22 353
        if isinstance(other, int):
paulb@22 354
            return boolean()
paulb@22 355
        elif isinstance(other, long):
paulb@22 356
            return boolean()
paulb@22 357
        else:
paulb@55 358
            raise TypeError
paulb@22 359
paulb@22 360
    def __le__(self, other):
paulb@22 361
        """
paulb@22 362
        NAME: IMPL.builtins.long.__le__
paulb@22 363
        NATIVE
paulb@22 364
        """
paulb@22 365
        if isinstance(other, int):
paulb@22 366
            return boolean()
paulb@22 367
        elif isinstance(other, long):
paulb@22 368
            return boolean()
paulb@22 369
        else:
paulb@55 370
            raise TypeError
paulb@22 371
paulb@22 372
    def __ge__(self, other):
paulb@22 373
        """
paulb@22 374
        NAME: IMPL.builtins.long.__ge__
paulb@22 375
        NATIVE
paulb@22 376
        """
paulb@22 377
        if isinstance(other, int):
paulb@22 378
            return boolean()
paulb@22 379
        elif isinstance(other, long):
paulb@22 380
            return boolean()
paulb@22 381
        else:
paulb@55 382
            raise TypeError
paulb@22 383
paulb@22 384
    def __eq__(self, other):
paulb@22 385
        """
paulb@22 386
        NAME: IMPL.builtins.long.__eq__
paulb@22 387
        NATIVE
paulb@22 388
        """
paulb@22 389
        if isinstance(other, int):
paulb@22 390
            return boolean()
paulb@22 391
        elif isinstance(other, long):
paulb@22 392
            return boolean()
paulb@22 393
        else:
paulb@55 394
            raise TypeError
paulb@22 395
paulb@22 396
    def __ne__(self, other):
paulb@22 397
        """
paulb@22 398
        NAME: IMPL.builtins.long.__ne__
paulb@22 399
        NATIVE
paulb@22 400
        """
paulb@22 401
        if isinstance(other, int):
paulb@22 402
            return boolean()
paulb@22 403
        elif isinstance(other, long):
paulb@22 404
            return boolean()
paulb@22 405
        else:
paulb@55 406
            raise TypeError
paulb@22 407
paulb@22 408
    def __neg__(self):
paulb@22 409
        """
paulb@22 410
        NAME: IMPL.builtins.long.__neg__
paulb@22 411
        NATIVE
paulb@22 412
        """
paulb@22 413
        return long()
paulb@22 414
paulb@22 415
    def __pos__(self):
paulb@22 416
        return self
paulb@22 417
paulb@22 418
    def __str__(self):
paulb@22 419
        """
paulb@22 420
        NAME: IMPL.builtins.long.__str__
paulb@22 421
        NATIVE
paulb@22 422
        """
paulb@22 423
        return string()
paulb@22 424
paulb@22 425
    def __true__(self):
paulb@22 426
        return self != 0
paulb@22 427
paulb@22 428
class float:
paulb@22 429
    """
paulb@22 430
    NATIVE
paulb@22 431
    INTERCHANGEABLE
paulb@22 432
    """
paulb@22 433
    def __iadd__(self, other):
paulb@22 434
        """
paulb@22 435
        NAME: IMPL.builtins.float.__iadd__
paulb@22 436
        NATIVE
paulb@22 437
        """
paulb@22 438
        if isinstance(other, int):
paulb@22 439
            return float()
paulb@22 440
        elif isinstance(other, long):
paulb@22 441
            return float()
paulb@22 442
        elif isinstance(other, float):
paulb@22 443
            return float()
paulb@22 444
        else:
paulb@55 445
            raise TypeError
paulb@22 446
paulb@22 447
    def __isub__(self, other):
paulb@22 448
        """
paulb@22 449
        NAME: IMPL.builtins.float.__isub__
paulb@22 450
        NATIVE
paulb@22 451
        """
paulb@22 452
        if isinstance(other, int):
paulb@22 453
            return float()
paulb@22 454
        elif isinstance(other, long):
paulb@22 455
            return float()
paulb@22 456
        elif isinstance(other, float):
paulb@22 457
            return float()
paulb@22 458
        else:
paulb@55 459
            raise TypeError
paulb@22 460
paulb@22 461
    def __add__(self, other):
paulb@22 462
        """
paulb@22 463
        NAME: IMPL.builtins.float.__add__
paulb@22 464
        NATIVE
paulb@22 465
        """
paulb@22 466
        if isinstance(other, int):
paulb@22 467
            return float()
paulb@22 468
        elif isinstance(other, long):
paulb@22 469
            return float()
paulb@22 470
        elif isinstance(other, float):
paulb@22 471
            return float()
paulb@22 472
        else:
paulb@55 473
            raise TypeError
paulb@22 474
paulb@22 475
    def __radd__(self, other):
paulb@22 476
        """
paulb@22 477
        NAME: IMPL.builtins.float.__radd__
paulb@22 478
        NATIVE
paulb@22 479
        """
paulb@22 480
        if isinstance(other, int):
paulb@22 481
            return float()
paulb@22 482
        elif isinstance(other, long):
paulb@22 483
            return float()
paulb@22 484
        elif isinstance(other, float):
paulb@22 485
            return float()
paulb@22 486
        else:
paulb@55 487
            raise TypeError
paulb@22 488
paulb@22 489
    def __sub__(self, other):
paulb@22 490
        """
paulb@22 491
        NAME: IMPL.builtins.float.__sub__
paulb@22 492
        NATIVE
paulb@22 493
        """
paulb@22 494
        if isinstance(other, int):
paulb@22 495
            return float()
paulb@22 496
        elif isinstance(other, long):
paulb@22 497
            return float()
paulb@22 498
        elif isinstance(other, float):
paulb@22 499
            return float()
paulb@22 500
        else:
paulb@55 501
            raise TypeError
paulb@22 502
paulb@22 503
    def __rsub__(self, other):
paulb@22 504
        """
paulb@22 505
        NAME: IMPL.builtins.float.__rsub__
paulb@22 506
        NATIVE
paulb@22 507
        """
paulb@22 508
        if isinstance(other, int):
paulb@22 509
            return float()
paulb@22 510
        elif isinstance(other, long):
paulb@22 511
            return float()
paulb@22 512
        elif isinstance(other, float):
paulb@22 513
            return float()
paulb@22 514
        else:
paulb@55 515
            raise TypeError
paulb@22 516
paulb@22 517
    def __mul__(self, other):
paulb@22 518
        """
paulb@22 519
        NAME: IMPL.builtins.float.__mul__
paulb@22 520
        NATIVE
paulb@22 521
        """
paulb@22 522
        if isinstance(other, int):
paulb@22 523
            return float()
paulb@22 524
        elif isinstance(other, long):
paulb@22 525
            return float()
paulb@22 526
        elif isinstance(other, float):
paulb@22 527
            return float()
paulb@22 528
        else:
paulb@55 529
            raise TypeError
paulb@22 530
paulb@22 531
    def __rmul__(self, other):
paulb@22 532
        """
paulb@22 533
        NAME: IMPL.builtins.float.__rmul__
paulb@22 534
        NATIVE
paulb@22 535
        """
paulb@22 536
        if isinstance(other, int):
paulb@22 537
            return float()
paulb@22 538
        elif isinstance(other, long):
paulb@22 539
            return float()
paulb@22 540
        elif isinstance(other, float):
paulb@22 541
            return float()
paulb@22 542
        else:
paulb@55 543
            raise TypeError
paulb@22 544
paulb@22 545
    def __div__(self, other):
paulb@22 546
        """
paulb@22 547
        NAME: IMPL.builtins.float.__div__
paulb@22 548
        NATIVE
paulb@22 549
        """
paulb@22 550
        if isinstance(other, int):
paulb@22 551
            return float()
paulb@22 552
        elif isinstance(other, long):
paulb@22 553
            return float()
paulb@22 554
        elif isinstance(other, float):
paulb@22 555
            return float()
paulb@22 556
        else:
paulb@55 557
            raise TypeError
paulb@22 558
paulb@22 559
    def __rdiv__(self, other):
paulb@22 560
        """
paulb@22 561
        NAME: IMPL.builtins.float.__rdiv__
paulb@22 562
        NATIVE
paulb@22 563
        """
paulb@22 564
        if isinstance(other, int):
paulb@22 565
            return float()
paulb@22 566
        elif isinstance(other, long):
paulb@22 567
            return float()
paulb@22 568
        elif isinstance(other, float):
paulb@22 569
            return float()
paulb@22 570
        else:
paulb@55 571
            raise TypeError
paulb@22 572
paulb@22 573
    def __pow__(self, other):
paulb@22 574
        """
paulb@22 575
        NAME: IMPL.builtins.float.__pow__
paulb@22 576
        NATIVE
paulb@22 577
        """
paulb@22 578
        if isinstance(other, int):
paulb@22 579
            return float()
paulb@22 580
        elif isinstance(other, long):
paulb@22 581
            return float()
paulb@22 582
        elif isinstance(other, float):
paulb@22 583
            return float()
paulb@22 584
        else:
paulb@55 585
            raise TypeError
paulb@22 586
paulb@22 587
    def __rpow__(self, other):
paulb@22 588
        """
paulb@22 589
        NAME: IMPL.builtins.float.__rpow__
paulb@22 590
        NATIVE
paulb@22 591
        """
paulb@22 592
        if isinstance(other, int):
paulb@22 593
            return float()
paulb@22 594
        elif isinstance(other, long):
paulb@22 595
            return float()
paulb@22 596
        elif isinstance(other, float):
paulb@22 597
            return float()
paulb@22 598
        else:
paulb@55 599
            raise TypeError
paulb@22 600
paulb@22 601
    def __lt__(self, other):
paulb@22 602
        """
paulb@22 603
        NAME: IMPL.builtins.float.__lt__
paulb@22 604
        NATIVE
paulb@22 605
        """
paulb@22 606
        if isinstance(other, int):
paulb@22 607
            return boolean()
paulb@22 608
        elif isinstance(other, long):
paulb@22 609
            return boolean()
paulb@22 610
        elif isinstance(other, float):
paulb@22 611
            return boolean()
paulb@22 612
        else:
paulb@55 613
            raise TypeError
paulb@22 614
paulb@22 615
    def __gt__(self, other):
paulb@22 616
        """
paulb@22 617
        NAME: IMPL.builtins.float.__gt__
paulb@22 618
        NATIVE
paulb@22 619
        """
paulb@22 620
        if isinstance(other, int):
paulb@22 621
            return boolean()
paulb@22 622
        elif isinstance(other, long):
paulb@22 623
            return boolean()
paulb@22 624
        elif isinstance(other, float):
paulb@22 625
            return boolean()
paulb@22 626
        else:
paulb@55 627
            raise TypeError
paulb@22 628
paulb@22 629
    def __le__(self, other):
paulb@22 630
        """
paulb@22 631
        NAME: IMPL.builtins.float.__le__
paulb@22 632
        NATIVE
paulb@22 633
        """
paulb@22 634
        if isinstance(other, int):
paulb@22 635
            return boolean()
paulb@22 636
        elif isinstance(other, long):
paulb@22 637
            return boolean()
paulb@22 638
        elif isinstance(other, float):
paulb@22 639
            return boolean()
paulb@22 640
        else:
paulb@55 641
            raise TypeError
paulb@22 642
paulb@22 643
    def __ge__(self, other):
paulb@22 644
        """
paulb@22 645
        NAME: IMPL.builtins.float.__ge__
paulb@22 646
        NATIVE
paulb@22 647
        """
paulb@22 648
        if isinstance(other, int):
paulb@22 649
            return boolean()
paulb@22 650
        elif isinstance(other, long):
paulb@22 651
            return boolean()
paulb@22 652
        elif isinstance(other, float):
paulb@22 653
            return boolean()
paulb@22 654
        else:
paulb@55 655
            raise TypeError
paulb@22 656
paulb@22 657
    def __eq__(self, other):
paulb@22 658
        """
paulb@22 659
        NAME: IMPL.builtins.float.__eq__
paulb@22 660
        NATIVE
paulb@22 661
        """
paulb@22 662
        if isinstance(other, int):
paulb@22 663
            return boolean()
paulb@22 664
        elif isinstance(other, long):
paulb@22 665
            return boolean()
paulb@22 666
        elif isinstance(other, float):
paulb@22 667
            return boolean()
paulb@22 668
        else:
paulb@55 669
            raise TypeError
paulb@22 670
paulb@22 671
    def __ne__(self, other):
paulb@22 672
        """
paulb@22 673
        NAME: IMPL.builtins.float.__ne__
paulb@22 674
        NATIVE
paulb@22 675
        """
paulb@22 676
        if isinstance(other, int):
paulb@22 677
            return boolean()
paulb@22 678
        elif isinstance(other, long):
paulb@22 679
            return boolean()
paulb@22 680
        elif isinstance(other, float):
paulb@22 681
            return boolean()
paulb@22 682
        else:
paulb@55 683
            raise TypeError
paulb@22 684
paulb@22 685
    def __neg__(self):
paulb@22 686
        """
paulb@22 687
        NAME: IMPL.builtins.float.__neg__
paulb@22 688
        NATIVE
paulb@22 689
        """
paulb@22 690
        return float()
paulb@22 691
paulb@22 692
    def __pos__(self):
paulb@22 693
        return self
paulb@22 694
paulb@22 695
    def __str__(self):
paulb@22 696
        """
paulb@22 697
        NAME: IMPL.builtins.float.__str__
paulb@22 698
        NATIVE
paulb@22 699
        """
paulb@22 700
        return string()
paulb@22 701
paulb@22 702
    def __true__(self):
paulb@22 703
        return self != 0
paulb@22 704
paulb@22 705
class string:
paulb@22 706
    """
paulb@22 707
    NATIVE
paulb@22 708
    INTERCHANGEABLE
paulb@22 709
    """
paulb@22 710
    def __add__(self, other):
paulb@22 711
        """
paulb@22 712
        NAME: IMPL.builtins.string.__add__
paulb@22 713
        NATIVE
paulb@22 714
        """
paulb@22 715
        if isinstance(other, string):
paulb@22 716
            return string()
paulb@22 717
        else:
paulb@55 718
            raise TypeError
paulb@22 719
paulb@22 720
    def __radd__(self, other):
paulb@22 721
        """
paulb@22 722
        NAME: IMPL.builtins.string.__radd__
paulb@22 723
        NATIVE
paulb@22 724
        """
paulb@22 725
        if isinstance(other, string):
paulb@22 726
            return string()
paulb@22 727
        else:
paulb@55 728
            raise TypeError
paulb@22 729
paulb@22 730
    def __len__(self):
paulb@22 731
        """
paulb@22 732
        NAME: IMPL.builtins.string.__len__
paulb@22 733
        NATIVE
paulb@22 734
        """
paulb@22 735
        return int()
paulb@22 736
paulb@22 737
    def __str__(self):
paulb@22 738
        return self
paulb@22 739
paulb@22 740
    def __true__(self):
paulb@22 741
        return self.__len__() != 0
paulb@22 742
paulb@22 743
    def join(self, l):
paulb@22 744
        total = 0
paulb@22 745
        first = 1
paulb@22 746
        self_len = self.__len__()
paulb@22 747
        for i in l:
paulb@22 748
            if not first:
paulb@22 749
                total += self_len
paulb@22 750
            total += len(str(i))
paulb@22 751
            first = 0
paulb@22 752
        b = buffer(total)
paulb@22 753
        first = 1
paulb@22 754
        for i in l:
paulb@22 755
            if not first:
paulb@22 756
                b.append(self)
paulb@22 757
            b.append(str(i))
paulb@22 758
            first = 0
paulb@22 759
        s = str(b)
paulb@22 760
        return s
paulb@22 761
paulb@22 762
class buffer:
paulb@22 763
    """
paulb@22 764
    NATIVE
paulb@22 765
    INTERCHANGEABLE
paulb@22 766
    """
paulb@22 767
    def __init__(self, size):
paulb@22 768
        """
paulb@22 769
        NAME: IMPL.builtins.buffer.__init__
paulb@22 770
        NATIVE
paulb@22 771
        """
paulb@22 772
        if not isinstance(size, int):
paulb@55 773
            raise TypeError
paulb@22 774
paulb@22 775
    def append(self, s):
paulb@22 776
        """
paulb@22 777
        NAME: IMPL.builtins.buffer.append
paulb@22 778
        NATIVE
paulb@22 779
        """
paulb@22 780
        if not isinstance(s, string):
paulb@55 781
            raise TypeError
paulb@22 782
        pass
paulb@22 783
paulb@22 784
    def __str__(self):
paulb@22 785
        """
paulb@22 786
        NAME: IMPL.builtins.buffer.__str__
paulb@22 787
        NATIVE
paulb@22 788
        """
paulb@22 789
        return string()
paulb@22 790
paulb@22 791
class list:
paulb@22 792
    def __init__(self):
paulb@22 793
        self.next = None
paulb@22 794
        self.last = self
paulb@22 795
paulb@22 796
    def __getitem__(self, index):
paulb@22 797
        i = 0
paulb@22 798
        n = self
paulb@22 799
        # NOTE: Support negative indices using last.
paulb@22 800
        while i < index and n.next is not None:
paulb@22 801
            n = n.next
paulb@22 802
            i += 1
paulb@22 803
        if n.next is not None:
paulb@22 804
            return n.value
paulb@22 805
        else:
paulb@22 806
            raise IndexError() # NOTE: Make this compliant with Python!
paulb@22 807
paulb@22 808
    def __setitem__(self, index, value):
paulb@22 809
        i = 0
paulb@22 810
        n = self
paulb@22 811
        # NOTE: Support negative indices using last.
paulb@22 812
        while i < index and n.next is not None:
paulb@22 813
            n = n.next
paulb@22 814
            i += 1
paulb@22 815
        if n.next is not None:
paulb@22 816
            n.value = value
paulb@22 817
        else:
paulb@22 818
            raise IndexError() # NOTE: Make this compliant with Python!
paulb@22 819
paulb@22 820
    def __getslice__(self, start, end=None):
paulb@22 821
        slice = []
paulb@22 822
        i = 0
paulb@22 823
        n = self
paulb@22 824
        # NOTE: Support negative indices using last.
paulb@22 825
        while (end is None or i < end) and n.next is not None:
paulb@22 826
            if i >= start:
paulb@22 827
                slice.append(n.value)
paulb@22 828
            n = n.next
paulb@22 829
            i += 1
paulb@22 830
        return slice
paulb@22 831
paulb@22 832
    def __setslice__(self, start, end, slice):
paulb@22 833
        i = 0
paulb@22 834
        n = self
paulb@22 835
        j = 0
paulb@22 836
        p = slice
paulb@22 837
        # NOTE: Support negative indices using last.
paulb@22 838
        # NOTE: Support appending when start >= len(self).
paulb@22 839
        while i < end and n is not None and p is not None:
paulb@22 840
            if i >= start:
paulb@22 841
                n.value = p.value
paulb@22 842
                p = p.next
paulb@22 843
                j += 1
paulb@22 844
            n = n.next
paulb@22 845
            i += 1
paulb@22 846
paulb@22 847
    def append(self, value):
paulb@22 848
        n = self.last
paulb@22 849
        n.value = value
paulb@22 850
        n.next = self.__class__()
paulb@22 851
        self.last = n.next
paulb@22 852
paulb@22 853
    def __len__(self):
paulb@22 854
        i = 0
paulb@22 855
        n = self
paulb@22 856
        while n.next is not None:
paulb@22 857
            n = n.next
paulb@22 858
            i += 1
paulb@22 859
        return i
paulb@22 860
paulb@22 861
    def __add__(self, other):
paulb@22 862
        result = self.__class__()
paulb@22 863
        for value in self:
paulb@22 864
            result.append(value)
paulb@22 865
        for value in other:
paulb@22 866
            result.append(value)
paulb@22 867
        return result
paulb@22 868
paulb@22 869
    def __str__(self):
paulb@22 870
        output = ["["]
paulb@22 871
        n = self
paulb@22 872
        first = 1
paulb@22 873
        while n.next is not None:
paulb@22 874
            if not first:
paulb@22 875
                output.append(", ")
paulb@22 876
            else:
paulb@22 877
                first = 0
paulb@22 878
            output.append(str(n.value))
paulb@22 879
            n = n.next
paulb@22 880
        output.append("]")
paulb@22 881
        return "".join(output)
paulb@22 882
paulb@22 883
    def __iter__(self):
paulb@22 884
        return listiterator(self)
paulb@22 885
paulb@22 886
    def __true__(self):
paulb@22 887
        return self.__len__() != 0
paulb@22 888
paulb@22 889
class listiterator:
paulb@22 890
    def __init__(self, l):
paulb@22 891
        self.l = l
paulb@22 892
paulb@22 893
    def next(self):
paulb@22 894
        l = self.l
paulb@22 895
        next = l.next
paulb@22 896
        if next is not None:
paulb@22 897
            self.l = next
paulb@22 898
            return l.value
paulb@22 899
        else:
paulb@55 900
            raise StopIteration
paulb@22 901
paulb@22 902
    def __true__(self):
paulb@22 903
        """
paulb@22 904
        NAME: IMPL.builtins.int.__true__
paulb@22 905
        NATIVE
paulb@22 906
        """
paulb@22 907
        return boolean()
paulb@22 908
paulb@22 909
class tuple:
paulb@22 910
    def __init__(self):
paulb@22 911
        self.next = None
paulb@22 912
        self.last = self
paulb@22 913
paulb@22 914
    def __getitem__(self, index):
paulb@22 915
        i = 0
paulb@22 916
        n = self
paulb@22 917
        # NOTE: Support negative indices using last.
paulb@22 918
        while i < index and n.next is not None:
paulb@22 919
            n = n.next
paulb@22 920
            i += 1
paulb@22 921
        if n.next is not None:
paulb@22 922
            return n.value
paulb@22 923
        else:
paulb@22 924
            raise IndexError() # NOTE: Make this compliant with Python!
paulb@22 925
paulb@22 926
    def __getslice__(self, start, end=None):
paulb@22 927
        # NOTE: Should probably return a tuple.
paulb@22 928
        slice = []
paulb@22 929
        i = 0
paulb@22 930
        n = self
paulb@22 931
        # NOTE: Support negative indices using last.
paulb@22 932
        while (end is None or i < end) and n.next is not None:
paulb@22 933
            if i >= start:
paulb@22 934
                slice.append(n.value)
paulb@22 935
            n = n.next
paulb@22 936
            i += 1
paulb@22 937
        return slice
paulb@22 938
paulb@22 939
    # NOTE: The append method should be internal at most.
paulb@22 940
paulb@22 941
    def append(self, value):
paulb@22 942
        n = self.last
paulb@22 943
        n.value = value
paulb@22 944
        n.next = self.__class__()
paulb@22 945
        self.last = n.next
paulb@22 946
paulb@22 947
    def __len__(self):
paulb@22 948
        i = 0
paulb@22 949
        n = self
paulb@22 950
        while n.next is not None:
paulb@22 951
            n = n.next
paulb@22 952
            i += 1
paulb@22 953
        return i
paulb@22 954
paulb@22 955
    def __add__(self, other):
paulb@22 956
        result = self.__class__()
paulb@22 957
        for value in self:
paulb@22 958
            result.append(value)
paulb@22 959
        for value in other:
paulb@22 960
            result.append(value)
paulb@22 961
        return result
paulb@22 962
paulb@22 963
    def __str__(self):
paulb@22 964
        output = ["("]
paulb@22 965
        n = self
paulb@22 966
        first = 1
paulb@22 967
        while n.next is not None:
paulb@22 968
            if not first:
paulb@22 969
                output.append(", ")
paulb@22 970
            else:
paulb@22 971
                first = 0
paulb@22 972
            output.append(str(n.value))
paulb@22 973
            n = n.next
paulb@22 974
        output.append(")")
paulb@22 975
        return "".join(output)
paulb@22 976
paulb@22 977
    def __iter__(self):
paulb@22 978
        return tupleiterator(self)
paulb@22 979
paulb@22 980
    def __true__(self):
paulb@22 981
        return self.__len__() != 0
paulb@22 982
paulb@22 983
class tupleiterator:
paulb@22 984
    def __init__(self, l):
paulb@22 985
        self.l = l
paulb@22 986
paulb@22 987
    def next(self):
paulb@22 988
        l = self.l
paulb@22 989
        next = l.next
paulb@22 990
        if next is not None:
paulb@22 991
            self.l = next
paulb@22 992
            return l.value
paulb@22 993
        else:
paulb@55 994
            raise StopIteration
paulb@22 995
paulb@22 996
    def __true__(self):
paulb@22 997
        """
paulb@22 998
        NAME: IMPL.builtins.int.__true__
paulb@22 999
        NATIVE
paulb@22 1000
        """
paulb@22 1001
        return boolean()
paulb@22 1002
paulb@54 1003
class dict:
paulb@54 1004
    pass
paulb@54 1005
paulb@22 1006
class Exception:
paulb@22 1007
    pass
paulb@22 1008
paulb@22 1009
class StopIteration(Exception):
paulb@22 1010
    pass
paulb@22 1011
paulb@22 1012
class IndexError(Exception):
paulb@22 1013
    pass
paulb@22 1014
paulb@22 1015
class AttributeError(Exception):
paulb@22 1016
    pass
paulb@22 1017
paulb@22 1018
class TypeError(Exception):
paulb@22 1019
    pass
paulb@22 1020
paulb@22 1021
class none:
paulb@22 1022
    """
paulb@22 1023
    NATIVE
paulb@22 1024
    INTERCHANGEABLE
paulb@22 1025
    ATOMIC
paulb@22 1026
    """
paulb@22 1027
    def __true__(self):
paulb@22 1028
        return False
paulb@22 1029
paulb@22 1030
    def __str__(self):
paulb@22 1031
        return "None"
paulb@22 1032
paulb@22 1033
class undefined:
paulb@22 1034
    """
paulb@22 1035
    NATIVE
paulb@22 1036
    INTERCHANGEABLE
paulb@22 1037
    ATOMIC
paulb@22 1038
    """
paulb@22 1039
    pass
paulb@22 1040
paulb@22 1041
def isinstance(obj, cls):
paulb@22 1042
    """
paulb@22 1043
    NAME: IMPL.builtins.isinstance
paulb@22 1044
    NATIVE
paulb@22 1045
    SPECIAL
paulb@22 1046
    """
paulb@22 1047
    return boolean()
paulb@22 1048
paulb@22 1049
def issubclass(cls1, cls2):
paulb@22 1050
    """
paulb@22 1051
    NAME: IMPL.builtins.isinstance
paulb@22 1052
    NATIVE
paulb@22 1053
    SPECIAL
paulb@22 1054
    """
paulb@22 1055
    return boolean()
paulb@22 1056
paulb@22 1057
def len(x):
paulb@22 1058
    return x.__len__()
paulb@22 1059
paulb@22 1060
def max(*l):
paulb@22 1061
    max_so_far = l[0]
paulb@22 1062
    for i in l[1:]:
paulb@22 1063
        if i > max_so_far:
paulb@22 1064
            max_so_far = i
paulb@22 1065
    return max_so_far
paulb@22 1066
paulb@22 1067
def str(x):
paulb@22 1068
    return x.__str__()
paulb@22 1069
paulb@22 1070
class xrange:
paulb@22 1071
    def __init__(self, start, end, step=1):
paulb@22 1072
        self.start = start
paulb@22 1073
        self.end = end
paulb@22 1074
        self.step = step
paulb@22 1075
        self.current = start
paulb@22 1076
paulb@22 1077
    def __iter__(self):
paulb@22 1078
        return self
paulb@22 1079
paulb@22 1080
    def next(self):
paulb@22 1081
        if self.current >= self.end:
paulb@55 1082
            raise StopIteration
paulb@22 1083
        current = self.current
paulb@22 1084
        self.current += self.step
paulb@22 1085
        return current
paulb@22 1086
paulb@22 1087
# Special values. None of these definitions should be generated by the compiler.
paulb@22 1088
# All such definitions should be made in the underlying implementation.
paulb@22 1089
paulb@22 1090
True = boolean()
paulb@22 1091
False = boolean()
paulb@22 1092
None = none()
paulb@22 1093
Undefined = undefined()
paulb@22 1094
paulb@22 1095
# Special functions. These all operate on references at run-time.
paulb@22 1096
paulb@22 1097
def __is__(a, b):
paulb@22 1098
    """
paulb@22 1099
    NAME: IMPL.builtins.__is__
paulb@22 1100
    NATIVE
paulb@22 1101
    """
paulb@22 1102
    return boolean()
paulb@22 1103
paulb@22 1104
def __is_not__(a, b):
paulb@22 1105
    """
paulb@22 1106
    NAME: IMPL.builtins.__is_not__
paulb@22 1107
    NATIVE
paulb@22 1108
    """
paulb@22 1109
    return boolean()
paulb@22 1110
paulb@22 1111
def __not__(a):
paulb@22 1112
    """
paulb@22 1113
    NAME: IMPL.builtins.__not__
paulb@22 1114
    NATIVE
paulb@22 1115
    """
paulb@22 1116
    return boolean()
paulb@22 1117
paulb@22 1118
# vim: tabstop=4 expandtab shiftwidth=4