micropython

Annotated lib/builtins.py

239:db8334eb671f
2009-06-07 Paul Boddie Added generation of some built-in classes and functions where docstrings are provided. Added an implementation of the xrange class. Added a test of xrange and modified existing tests. Fixed augmented assignment code generation.
paul@61 1
#!/usr/bin/env python
paul@61 2
paul@61 3
"""
paul@61 4
Simple built-in classes and functions.
paul@61 5
paul@61 6
Copyright (C) 2005, 2006, 2007, 2008 Paul Boddie <paul@boddie.org.uk>
paul@61 7
paul@61 8
This program is free software; you can redistribute it and/or modify it under
paul@61 9
the terms of the GNU General Public License as published by the Free Software
paul@61 10
Foundation; either version 3 of the License, or (at your option) any later
paul@61 11
version.
paul@61 12
paul@61 13
This program is distributed in the hope that it will be useful, but WITHOUT
paul@61 14
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
paul@61 15
FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
paul@61 16
details.
paul@61 17
paul@61 18
You should have received a copy of the GNU General Public License along with
paul@61 19
this program.  If not, see <http://www.gnu.org/licenses/>.
paul@61 20
"""
paul@61 21
paul@61 22
class object:
paul@61 23
    def __init__(self): pass
paul@61 24
    def __bool__(self): pass
paul@61 25
    def __iadd__(self, other): pass
paul@61 26
paul@63 27
class basestring(object):
paul@63 28
    def __init__(self, x=None): pass
paul@63 29
    def __getitem__(self, index): pass
paul@63 30
    def __getslice__(self, start, end=None): pass
paul@63 31
    def __iadd__(self, other): pass
paul@63 32
    def __add__(self, other): pass
paul@63 33
    def __radd__(self, other): pass
paul@63 34
    def __mul__(self, other): pass
paul@203 35
    def __rmul__(self, other): pass
paul@63 36
    def __mod__(self, other): pass
paul@202 37
    def __rmod__(self, other): pass
paul@63 38
    def __lt__(self, other): pass
paul@63 39
    def __gt__(self, other): pass
paul@63 40
    def __le__(self, other): pass
paul@63 41
    def __ge__(self, other): pass
paul@63 42
    def __eq__(self, other): pass
paul@63 43
    def __ne__(self, other): pass
paul@63 44
    def __len__(self): pass
paul@63 45
    def __str__(self): pass
paul@63 46
    def __bool__(self): pass
paul@63 47
    def join(self, l): pass
paul@63 48
paul@63 49
class bool(object):
paul@61 50
    def __bool__(self): pass
paul@61 51
    def __str__(self): pass
paul@61 52
paul@63 53
class buffer(object):
paul@61 54
    def __init__(self, size): pass
paul@61 55
    def append(self, s): pass
paul@61 56
    def __str__(self): pass
paul@61 57
paul@63 58
class complex(object):
paul@63 59
    def __init__(self, real, imag=None): pass
paul@63 60
paul@63 61
class dict(object):
paul@61 62
    def __init__(self, *args): pass
paul@61 63
    def __setitem__(self, key, value): pass
paul@61 64
    def __getitem__(self, key): pass
paul@61 65
paul@63 66
class file(object):
paul@61 67
    def write(self, s): pass
paul@61 68
paul@63 69
class float(object):
paul@61 70
    def __init__(self, number_or_string=None): pass
paul@61 71
    def __iadd__(self, other): pass
paul@61 72
    def __isub__(self, other): pass
paul@61 73
    def __add__(self, other): pass
paul@61 74
    def __radd__(self, other): pass
paul@61 75
    def __sub__(self, other): pass
paul@61 76
    def __rsub__(self, other): pass
paul@61 77
    def __mul__(self, other): pass
paul@61 78
    def __rmul__(self, other): pass
paul@61 79
    def __div__(self, other): pass
paul@61 80
    def __rdiv__(self, other): pass
paul@61 81
    def __floordiv__(self, other): pass
paul@61 82
    def __rfloordiv__(self, other): pass
paul@61 83
    def __mod__(self, other): pass
paul@202 84
    def __rmod__(self, other): pass
paul@61 85
    def __pow__(self, other): pass
paul@61 86
    def __rpow__(self, other): pass
paul@61 87
    def __lt__(self, other): pass
paul@61 88
    def __gt__(self, other): pass
paul@61 89
    def __le__(self, other): pass
paul@61 90
    def __ge__(self, other): pass
paul@61 91
    def __eq__(self, other): pass
paul@61 92
    def __ne__(self, other): pass
paul@61 93
    def __neg__(self): pass
paul@61 94
    def __pos__(self): pass
paul@61 95
    def __str__(self): pass
paul@61 96
    def __bool__(self): pass
paul@61 97
paul@63 98
class frozenset(object):
paul@63 99
    def __init__(self, iterable): pass
paul@63 100
paul@137 101
class function(object):
paul@137 102
    pass
paul@137 103
paul@63 104
class int(object):
paul@61 105
    def __init__(self, number_or_string=None): pass
paul@61 106
    def __iadd__(self, other): pass
paul@61 107
    def __isub__(self, other): pass
paul@61 108
    def __add__(self, other): pass
paul@61 109
    def __radd__(self, other): pass
paul@61 110
    def __sub__(self, other): pass
paul@61 111
    def __rsub__(self, other): pass
paul@61 112
    def __mul__(self, other): pass
paul@61 113
    def __rmul__(self, other): pass
paul@61 114
    def __div__(self, other): pass
paul@61 115
    def __rdiv__(self, other): pass
paul@61 116
    def __floordiv__(self, other): pass
paul@61 117
    def __rfloordiv__(self, other): pass
paul@61 118
    def __mod__(self, other): pass
paul@202 119
    def __rmod__(self, other): pass
paul@61 120
    def __pow__(self, other): pass
paul@202 121
    def __rpow__(self, other): pass
paul@61 122
    def __and__(self, other): pass
paul@61 123
    def __rand__(self, other): pass
paul@61 124
    def __or__(self, other): pass
paul@61 125
    def __ror__(self, other): pass
paul@61 126
    def __xor__(self, other): pass
paul@61 127
    def __rxor__(self, other): pass
paul@61 128
    def __lt__(self, other): pass
paul@61 129
    def __gt__(self, other): pass
paul@61 130
    def __le__(self, other): pass
paul@61 131
    def __ge__(self, other): pass
paul@61 132
    def __eq__(self, other): pass
paul@61 133
    def __ne__(self, other): pass
paul@61 134
    def __neg__(self): pass
paul@61 135
    def __pos__(self): pass
paul@61 136
    def __str__(self): pass
paul@61 137
    def __bool__(self): pass
paul@61 138
paul@63 139
class list(object):
paul@61 140
    def __init__(self, args=()): pass
paul@61 141
    def __getitem__(self, index): pass
paul@61 142
    def __setitem__(self, index, value): pass
paul@61 143
    def __getslice__(self, start, end=None): pass
paul@61 144
    def __setslice__(self, start, end, slice): pass
paul@61 145
    def append(self, value): pass
paul@61 146
    def __len__(self): pass
paul@61 147
    def __add__(self, other): pass
paul@61 148
    def __iadd__(self, other): pass
paul@61 149
    def __str__(self): pass
paul@61 150
    def __iter__(self): pass
paul@61 151
    def __bool__(self): pass
paul@61 152
paul@63 153
class long(object):
paul@61 154
    def __init__(self, number_or_string=None): pass
paul@61 155
    def __iadd__(self, other): pass
paul@61 156
    def __isub__(self, other): pass
paul@61 157
    def __add__(self, other): pass
paul@61 158
    def __radd__(self, other): pass
paul@61 159
    def __sub__(self, other): pass
paul@61 160
    def __rsub__(self, other): pass
paul@61 161
    def __mul__(self, other): pass
paul@61 162
    def __rmul__(self, other): pass
paul@61 163
    def __div__(self, other): pass
paul@61 164
    def __rdiv__(self, other): pass
paul@61 165
    def __floordiv__(self, other): pass
paul@61 166
    def __rfloordiv__(self, other): pass
paul@61 167
    def __and__(self, other): pass
paul@61 168
    def __rand__(self, other): pass
paul@61 169
    def __or__(self, other): pass
paul@61 170
    def __ror__(self, other): pass
paul@61 171
    def __xor__(self, other): pass
paul@61 172
    def __rxor__(self, other): pass
paul@61 173
    def __lt__(self, other): pass
paul@61 174
    def __gt__(self, other): pass
paul@61 175
    def __le__(self, other): pass
paul@61 176
    def __ge__(self, other): pass
paul@61 177
    def __eq__(self, other): pass
paul@61 178
    def __ne__(self, other): pass
paul@61 179
    def __neg__(self): pass
paul@61 180
    def __pos__(self): pass
paul@61 181
    def __str__(self): pass
paul@61 182
    def __bool__(self): pass
paul@61 183
paul@63 184
class set(object):
paul@63 185
    def __init__(self, iterable): pass
paul@61 186
paul@63 187
class slice(object):
paul@61 188
    def __init__(self, start_or_end, end=None, step=None): pass
paul@61 189
paul@63 190
class str(basestring):
paul@63 191
    pass
paul@61 192
paul@63 193
class type(object):
paul@63 194
    pass
paul@63 195
paul@63 196
class tuple(object):
paul@61 197
    def __init__(self, args): pass
paul@61 198
    def __getitem__(self, index): pass
paul@61 199
    def __getslice__(self, start, end=None): pass
paul@61 200
    def __len__(self): pass
paul@61 201
    def __add__(self, other): pass
paul@61 202
    def __str__(self): pass
paul@61 203
    def __iter__(self): pass
paul@61 204
    def __bool__(self): pass
paul@61 205
paul@63 206
class unicode(basestring):
paul@63 207
    pass
paul@63 208
paul@63 209
class xrange(object):
paul@239 210
paul@239 211
    "Implementation of xrange."
paul@239 212
paul@239 213
    def __init__(self, start_or_end, end=None, step=1):
paul@239 214
paul@239 215
        "Initialise the xrange with the given 'start_or_end', 'end' and 'step'."
paul@239 216
paul@239 217
        if end is None:
paul@239 218
            self.start = 0
paul@239 219
            self.end = start_or_end
paul@239 220
        else:
paul@239 221
            self.start = start_or_end
paul@239 222
            self.end = end
paul@239 223
paul@239 224
        self.step = step
paul@239 225
        self.current = self.start
paul@239 226
paul@239 227
    def __iter__(self):
paul@239 228
paul@239 229
        "Return an iterator, currently self."
paul@239 230
paul@239 231
        return self
paul@239 232
paul@239 233
    def next(self):
paul@239 234
paul@239 235
        "Return the next item or raise a StopIteration exception."
paul@239 236
paul@239 237
        if self.step < 0 and self.current <= self.end or self.step > 0 and self.current >= self.end:
paul@239 238
            raise StopIteration
paul@239 239
paul@239 240
        current = self.current
paul@239 241
        self.current += self.step
paul@239 242
        return current
paul@61 243
paul@63 244
# Exceptions and warnings.
paul@63 245
paul@63 246
class BaseException(object):
paul@235 247
    def __init__(self, *args):
paul@235 248
        self.args = args
paul@61 249
paul@63 250
class Exception(BaseException): pass
paul@63 251
class Warning(object): pass
paul@61 252
paul@63 253
class ArithmeticError(Exception): pass
paul@63 254
class AssertionError(Exception): pass
paul@63 255
class AttributeError(Exception): pass
paul@63 256
class DeprecationWarning(Exception): pass
paul@63 257
class EOFError(Exception): pass
paul@63 258
class EnvironmentError(Exception): pass
paul@63 259
class FloatingPointError(Exception): pass
paul@63 260
class FutureWarning(Warning): pass
paul@63 261
class GeneratorExit(Exception): pass
paul@63 262
class ImportError(Exception): pass
paul@63 263
class ImportWarning(Warning): pass
paul@63 264
class IndentationError(Exception): pass
paul@63 265
class IndexError(Exception): pass
paul@216 266
class IOError(Exception): pass
paul@63 267
class KeyError(Exception): pass
paul@63 268
class KeyboardInterrupt(Exception): pass
paul@63 269
class LookupError(Exception): pass
paul@63 270
class MemoryError(Exception): pass
paul@63 271
class NameError(Exception): pass
paul@63 272
class NotImplementedError(Exception): pass
paul@63 273
class OSError(Exception): pass
paul@63 274
class OverflowError(Exception): pass
paul@63 275
class PendingDeprecationWarning(Warning): pass
paul@63 276
class ReferenceError(Exception): pass
paul@63 277
class RuntimeError(Exception): pass
paul@63 278
class RuntimeWarning(Warning): pass
paul@63 279
class StandardError(Exception): pass
paul@63 280
class StopIteration(Exception): pass
paul@63 281
class SyntaxError(Exception): pass
paul@63 282
class SyntaxWarning(Warning): pass
paul@63 283
class SystemError(Exception): pass
paul@63 284
class SystemExit(Exception): pass
paul@63 285
class TabError(Exception): pass
paul@63 286
class TypeError(Exception): pass
paul@63 287
class UnboundLocalError(Exception): pass
paul@63 288
class UnicodeDecodeError(Exception): pass
paul@63 289
class UnicodeEncodeError(Exception): pass
paul@63 290
class UnicodeError(Exception): pass
paul@63 291
class UnicodeTranslateError(Exception): pass
paul@63 292
class UnicodeWarning(Warning): pass
paul@63 293
class UserWarning(Warning): pass
paul@63 294
class ValueError(Exception): pass
paul@63 295
class ZeroDivisionError(Exception): pass
paul@61 296
paul@63 297
# Various types.
paul@63 298
paul@203 299
#class ellipsis: pass
paul@146 300
class NoneType: pass
paul@63 301
class NotImplementedType: pass
paul@61 302
paul@63 303
# General functions.
paul@63 304
# NOTE: Some of these are actually provided by classes in CPython.
paul@63 305
# NOTE: We may refuse to support some of these in practice, such as...
paul@63 306
# NOTE: super, reload.
paul@63 307
paul@63 308
def __import__(name, globals=None, locals=None, fromlist=None, level=-1): pass
paul@63 309
def abs(number): pass
paul@63 310
def all(iterable): pass
paul@63 311
def any(iterable): pass
paul@63 312
def callable(obj): pass
paul@63 313
def chr(i): pass
paul@63 314
def classmethod(function): pass
paul@63 315
def cmp(x, y): pass
paul@63 316
def compile(source, filename, mode, flags=None, dont_inherit=None): pass
paul@63 317
def delattr(obj, name): pass
paul@63 318
def dir(obj=None): pass
paul@63 319
def divmod(x, y): pass
paul@63 320
def enumerate(iterable): pass
paul@63 321
def eval(source, globals=None, locals=None): pass
paul@63 322
def execfile(filename, globals=None, locals=None): pass
paul@63 323
def filter(function, sequence): pass
paul@63 324
def getattr(obj, name, default=None): pass
paul@63 325
def globals(): pass
paul@63 326
def hasattr(obj, name): pass
paul@63 327
def hash(obj): pass
paul@213 328
def help(*args): pass
paul@63 329
def hex(number): pass
paul@63 330
def id(obj): pass
paul@63 331
def input(prompt=None): pass
paul@63 332
def isinstance(obj, cls_or_tuple): pass
paul@63 333
def issubclass(obj, cls_or_tuple): pass
paul@63 334
def iter(collection_or_callable, sentinel=None): pass
paul@63 335
def len(obj): pass
paul@63 336
def locals(): pass
paul@63 337
def map(function, *args): pass
paul@213 338
def max(*args): pass
paul@213 339
def min(*args): pass
paul@63 340
def oct(number): pass
paul@63 341
def open(name, mode=None, buffering=None): pass
paul@63 342
def ord(c): pass
paul@63 343
def pow(x, y, z=None): pass
paul@63 344
def property(fget=None, fset=None, fdel=None, doc=None): pass
paul@63 345
def range(start_or_end, end=None, step=None): pass
paul@63 346
def raw_input(prompt=None): pass
paul@63 347
def reduce(function, sequence, initial=None): pass
paul@63 348
def reload(module): pass
paul@63 349
def repr(obj): pass
paul@63 350
def reversed(sequence): pass
paul@63 351
def round(number, ndigits=None): pass
paul@63 352
def setattr(obj, name, value): pass
paul@63 353
def sorted(iterable, cmp=None, key=None, reverse=False): pass
paul@63 354
def staticmethod(function): pass
paul@63 355
def sum(sequence, start=0): pass
paul@63 356
def super(*args): pass
paul@63 357
def unichr(i): pass
paul@63 358
def vars(obj=None): pass
paul@63 359
def zip(*args): pass
paul@63 360
paul@167 361
# Reference some names to ensure their existence. This should be everything
paul@167 362
# mentioned in a get_builtin or load_builtin call. Instances from this module
paul@167 363
# should be predefined constants.
paul@167 364
paul@167 365
function
paul@167 366
AttributeError
paul@167 367
StopIteration
paul@167 368
TypeError
paul@216 369
IndexError
paul@203 370
paul@203 371
list
paul@203 372
tuple
paul@203 373
#xrange
paul@203 374
#ellipsis
paul@203 375
#bool
paul@167 376
paul@61 377
# vim: tabstop=4 expandtab shiftwidth=4