Author: Maciej Fijalkowski <[email protected]>
Branch:
Changeset: r51078:b67e65d709e1
Date: 2012-01-06 20:00 +0200
http://bitbucket.org/pypy/pypy/changeset/b67e65d709e1/
Log: make coding guide a bit more up to date when it comes to RPython
definition
diff --git a/pypy/doc/coding-guide.rst b/pypy/doc/coding-guide.rst
--- a/pypy/doc/coding-guide.rst
+++ b/pypy/doc/coding-guide.rst
@@ -175,15 +175,15 @@
RPython
=================
-RPython Definition, not
------------------------
+RPython Definition
+------------------
-The list and exact details of the "RPython" restrictions are a somewhat
-evolving topic. In particular, we have no formal language definition
-as we find it more practical to discuss and evolve the set of
-restrictions while working on the whole program analysis. If you
-have any questions about the restrictions below then please feel
-free to mail us at pypy-dev at codespeak net.
+RPython is a restricted subset of Python that is amenable to static analysis.
+Although there are additions to the language and some things might surprisingly
+work, this is a rough list of restrictions that should be considered. Note
+that there are tons of special cased restrictions that you'll encounter
+as you go. The exact definition is "RPython is everything that our translation
+toolchain can accept" :)
.. _`wrapped object`: coding-guide.html#wrapping-rules
@@ -198,7 +198,7 @@
contain both a string and a int must be avoided. It is allowed to
mix None (basically with the role of a null pointer) with many other
types: `wrapped objects`, class instances, lists, dicts, strings, etc.
- but *not* with int and floats.
+ but *not* with int, floats or tuples.
**constants**
@@ -209,9 +209,12 @@
have this restriction, so if you need mutable global state, store it
in the attributes of some prebuilt singleton instance.
+
+
**control structures**
- all allowed but yield, ``for`` loops restricted to builtin types
+ all allowed, ``for`` loops restricted to builtin types, generators
+ very restricted.
**range**
@@ -226,7 +229,8 @@
**generators**
- generators are not supported.
+ generators are supported, but their exact scope is very limited. you can't
+ merge two different generator in one control point.
**exceptions**
@@ -245,22 +249,27 @@
**strings**
- a lot of, but not all string methods are supported. Indexes can be
+ a lot of, but not all string methods are supported and those that are
+ supported, not necesarilly accept all arguments. Indexes can be
negative. In case they are not, then you get slightly more efficient
code if the translator can prove that they are non-negative. When
slicing a string it is necessary to prove that the slice start and
- stop indexes are non-negative.
+ stop indexes are non-negative. There is no implicit str-to-unicode cast
+ anywhere.
**tuples**
no variable-length tuples; use them to store or return pairs or n-tuples of
- values. Each combination of types for elements and length constitute a
separate
- and not mixable type.
+ values. Each combination of types for elements and length constitute
+ a separate and not mixable type.
**lists**
lists are used as an allocated array. Lists are over-allocated, so
list.append()
- is reasonably fast. Negative or out-of-bound indexes are only allowed for
the
+ is reasonably fast. However, if you use a fixed-size list, the code
+ is more efficient. Annotator can figure out most of the time that your
+ list is fixed-size, even when you use list comprehension.
+ Negative or out-of-bound indexes are only allowed for the
most common operations, as follows:
- *indexing*:
@@ -287,16 +296,14 @@
**dicts**
- dicts with a unique key type only, provided it is hashable.
- String keys have been the only allowed key types for a while, but this was
generalized.
- After some re-optimization,
- the implementation could safely decide that all string dict keys should be
interned.
+ dicts with a unique key type only, provided it is hashable. Custom
+ hash functions and custom equality will not be honored.
+ Use ``pypy.rlib.objectmodel.r_dict`` for custom hash functions.
**list comprehensions**
- may be used to create allocated, initialized arrays.
- After list over-allocation was introduced, there is no longer any
restriction.
+ May be used to create allocated, initialized arrays.
**functions**
@@ -334,9 +341,7 @@
**objects**
- in PyPy, wrapped objects are borrowed from the object space. Just like
- in CPython, code that needs e.g. a dictionary can use a wrapped dict
- and the object space operations on it.
+ Normal rules apply.
This layout makes the number of types to take care about quite limited.
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit