micropython

lib/builtins.py

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