It would be a big step forward for RPython if shedskin could compile
RPython programs (RPython as PyPy defines it). Currently there are
some incompatibilities between RPython and ShedSkin-restricted-
Python. The main difference is shedskin not supporting: longer mixed
tuples, *args, and not supporting `assert isinstance`.
There is no comprehensive plain english list of what RPython is, here
is a draft.
RPython rule1: All globals and class-level attributes are constants.
. Muteable globals are not recommended by ShedSkin because if
used as an extension module changes to globals will not be reflected
in CPython.
. PyPy considers globals to always be constant, including class-
level attributes.
RPython rule2: Tuples may contain mixed types, but it should be
avoided.
. ShedSkin limits mixed tuples to length two
. PyPy can not use a loop to iterate over mixed tuples
* RPython1.+ should try to solve these problems in both ShedSkin and
PyPy
RPython rule3: Dicts and lists must contain compatible types
(homogeneous).
. ShedSkin and PyPy common rule
RPython rule4: Class attributes are accessed by class name.
. ShedSkin requirement
RPython rule5: No reflection (getattr, hasattr, etc..)
. PyPy allows for limited getattr, hasattr.., but only if the
string is concrete.
. ShedSkin has no support.
RPython rule6: No runtime evaluation.
. Neither ShedSkin or PyPy support eval or exec
RPython rule7: No **keywordargs
. Neither ShedSkin or PyPy support **kw
RPython rule 8: No passing of references to methods (functions are
ok).
. ShedSkin requirement
RPython rule 9: For instances to be of a compatible type, they must
inherit from a common base class.
. ShedSkin and PyPy requirement
RPython rule 10: For compatible instances stored in the same list, but
of different subclasses, to call methods with incompatible signatures
or access attributes unique to the subclass, the type must be asserted
first:
assert isinstance(a,MySubClass)
. PyPy requirement
. works with ShedSkin?
RPython rule 11: The *assert isinstance* statement acts like a cast in
C/C++, turning `SomeObject` into the real subclass instance. This
solves problems like in rule10, and in other cases where an instance
of uncertian type must be passed to a function that expects a certian
type.
RPython rule 12: No overloading, except for __init__ and __del__.
. ShedSkin allows for all overloading except for __iter__ and
__call__
. PyPy requirement
*RPython 1.+, would be nice to lift some of this limitation in PyPy,
how hard is this problem?
RPython rule 13: Base classes should define dummy functions.
. Prevents method `demotion` in PyPy
RPython rule 14: Attribute variables should be of consistent type in
all subclasses. Do not create a subclass that redefines the type of
an attribute.
. Required by PyPy
RPython rule 15: The calling and return signature of a function must
not change. The types of function arguments must always be the same
to each function call. Only `None` can be intermixed. Function
returns must always have the same type.
. Required by PyPy
. Required by ShedSkin?
RPython rule 16: Its not recommended to define subclasses with like-
named functions that have different signatures. Casting by `assert
isinstance` is the work around that allows this rule to be bent.
. Required by PyPy
. Supported by ShedSkin?
On Sep 9, 4:29 am, Mark Dufour <
mark.duf...@gmail.com> wrote: