[pypy-svn] rev 1099 - pypy/trunk/doc
lac at codespeak.net
lac at codespeak.net
Mon Jul 7 14:56:31 CEST 2003
Date: Mon Jul 7 14:56:31 2003
New Revision: 1099
More fixes. Now what to say about Annotate Space ?!
--- pypy/trunk/doc/oscon2003-paper.txt (original)
+++ pypy/trunk/doc/oscon2003-paper.txt Mon Jul 7 14:56:31 2003
@@ -270,20 +270,20 @@
The Trivial Object Space
-A PyPy interpreter using the TrivialObjectSpace is an interpreter with
-its own main loop (written in Python), and nothing else. This main
-loop manipulates real Python objects and all operations are done
-directly on the Python objects. For example, "1" really means "1" and
-when the interpreter encounters the BINARY_ADD bytecode instructions
-the TrivialObjectSpace will just add two real Python objects together
-using Python's "+". The same for lists, dictionaries, classes... We
-just use Python's own.
+A PyPy interpreter using the Trivial Object Space is an
+interpreter with its own main loop (written in Python), and nothing
+else. This main loop manipulates real Python objects and all
+operations are done directly on the Python objects. For example, "1"
+really means "1" and when the interpreter encounters the BINARY_ADD
+bytecode instructions the Trivial Object Space will just add two real
+Python objects together using Python's "+". The same for lists,
+dictionaries, classes ... we just use Python's own. Delegate Object
+Space might have been a better name for this Object Space.
This Object Space is only useful for testing the concept of Object Spaces,
and our interpreter, or even interpreting different kinds of bytecodes.
-This is already done; it is funny to watch "dis.dis" disassembling itself
+This is already implemented; it is funny to watch *dis.dis* disassembling
+itself painfully slowly.
Getting this to work was a goal of the Hildesheim Sprint February 16-23.
It demonstrated that our Object Space Concept was viable, and that our
@@ -291,34 +291,46 @@
The Standard Object Space
The Standard Object Space is the object space that works just like
Python's, that is, the object space whose black boxes are real Python
-objects that work as expected. This is where the bulk of the work in
-PyPy has been done to date. Getting the Standard Object Space to
+objects that work as expected. Getting the Standard Object Space to
work was a goal of the Gothenburg Sprint May 24 - 31.
-Specifically we needed to get this code:
+The Standard Object Space defines an abstract parent class, W_Object,
+and a bunch of subclasses like W_IntObject, W_ListObject, and so on. A
+wrapped object (a *black box* for the interpreter main loop) is thus
+an instance of one of these classes. When the main loop invokes an
+operation, say the addition, between two wrapped objects w1 and w2,
+the StandardObjectSpace does some internal dispatching (similar to
+"Object/ abstract.c" in CPython) and invokes a method of the proper
+W_XyzObject class that can do the operation. The operation itself is
+done with the primitives allowed by Restricted Python. The result is
+constructed as a wrapped object again.
+The following was our first trivial program::
-aStr = 'hello world'
+ ### our first trivial program ###
+ aStr = 'hello world'
+ print len(aStr)
to run. We needed types and builtins to work. This ran, slowly.
-Then we added strings. Getting this code to work was the second
+We began testing and adding types and builtins.
- ### a trivial program to test strings, lists, functions and methods ###
+Getting this code to work was the second goal.::
+ ### a trivial program to test strings, lists, functions and methods ###
- return s1 + s2
+ return s1 + s2
str = "an interesting string"
str2 = 'another::string::xxx::y:aa'
str3 = addstr(str,str2)
- arr = oscon2003-paper.txt
+ arr = 
for word in str.split():
- if word in str2.split('::'):
+ if word in str2.split('::'):
print "str + str2 = ", str3
@@ -327,64 +339,41 @@
By the end of the Sprint we produced our first Python program that
ran under PyPy which simply 'did something we wanted to do' and wasn't
-an artificial goal. Specifically, it calculated the share in foodbill
-for each of the 9 Sprint participants.
-### the first use of PyPy as a tool to do something else ### [#]_
+an artificial goal. It calculated the week long foodbill, and divided
+the result by the 9 Sprint participants.::
-slips=[(1, 'Kals MatMarkn', 6150, 'Chutney for Curry', 'dinner Saturday'),
- (2, 'Kals MatMarkn', 32000, 'Spaghetti, Beer', 'dinner Monday'),
- (2, 'Kals MatMarkn', -810, 'Deposit on Beer Bottles', 'various'),
- (3, 'Fram', 7700, 'Rice and Curry Spice', 'dinner Saturday'),
- (23, 'Fram', 2975, 'Potatoes', '3.5 kg @ 8.50SEK'),
- (23, 'Fram', 1421, 'Peas', 'Thursday dinner'),
-print (reduce(lambda x, y: x+y, [t for t in slips], 0))/900 [#]_
-Pypy said: 603. Dinner for a week cost 603 Swedish Krona -- or approximately
-50$ US. So if we can't have world domination, or get our Object Space
-to work, a new career in Sprint cost control beckons. :-)
-3. The Annotate Object Space
-The Annotate Object Space is the next goal. It is an example of an
-ObjectSpace that differs a lot from StandardObjectSpace. We have to
-translate the Python code we have into C code. This is the sine qua
-non condition for our work to be actually usable. Quite unexpectedly,
-the major piece of the translator is itself an object space, the
-AnnotateObjectSpace. Its goal is to run any Python code and produce C
-code in the background as it does so.
-Specifically, we take our PyPy interpreter with the Annotate Object
-Space instead of the Standard Object Space, and run that, asking it to
-interpret our generated bytecode. A wrapped object is now the name of
-a variable in the C program we are emitting, for example:
-The add method in the Annotate Object Space takes two variable
-names, x and y, and emits the C code z = x + y; where z is a new variable
-name which is returned as the result of add. (We will actually need to
-make the wrapped objects a bit more elaborate so that we can also record,
-besides the C variable name, its basic type).
-At the time of this writing, it is not clear whether this is too
-ambitious a goal for the Third Sprint, held in Louvain-la-Neuve,
-Belgium (near Brussels), June 21 - 24 .
+ ### the first real PyPy Program ### [#]_
+ slips=[(1, 'Kals MatMarkn', 6150, 'Chutney for Curry', 'dinner Saturday'),
+ (2, 'Kals MatMarkn', 32000, 'Spaghetti, Beer', 'dinner Monday'),
+ (2, 'Kals MatMarkn', -810, 'Deposit on Beer Bottles', 'various'),
+ (3, 'Fram', 7700, 'Rice and Curry Spice', 'dinner Saturday'),
+ ( ... )
+ (23, 'Fram', 2975, 'Potatoes', '3.5 kg @ 8.50SEK'),
+ (23, 'Fram', 1421, 'Peas', 'Thursday dinner'),]
+ print (reduce(lambda x, y: x+y, [t for t in slips], 0))/900 [#]_
+Pypy said: 603 SEK, or appoximately 50 USD. Don't believe people who
+tell you that Sprints are too expensive to hold.
+The Annotation Object Space
+Our third Sprint was held at Louvain-la-Neuve, Belgium (near
+Brussels), June 21 - 24. Great progress was made with the The
+Annotation Object Space, and began abstract, symbolic interpretation.
-More details on how we actually do this stuff.
-A crucial concept is Multimethods (yanked from the wiki)
+Current plans are to get the Annotation Object Space to emit Pyrex.
Interpreter-level classes correspond to implementations of
application-level types. The hierarchy among the classes used for the
implementations is convenient for implementation purposes. It is not
related to any application-level type hierarchy.
Multimethods dispatch by looking in a set of registered
functions. Each registered function has a signature, which defines
which object implementation classes are accepted at the corresponding
@@ -399,7 +388,6 @@
argument. For example it should not be stored in a data structure, nor
be queried for type, nor be used for another multimethod dispatch --
the only thing you should do is read and write its internal data.
-[[FIXME: discuss w/Samuele & Armin]]
For example, 'getattr(obj, attr)' is implemented with a W_StringObject
second argument when all it needs is just the name of the attr, and
@@ -407,6 +395,7 @@
Delegation is a transparent convertion mechanism between object
implementations. The convertion can give a result of a different type
@@ -423,7 +412,7 @@
the process might require some work.
Types are implemented by the class W_TypeObject. This is where
inheritance and the Method Resolution Order are defined, and where
attribute look-ups are done.
@@ -440,7 +429,7 @@
W_UserObject -> int delegator.
Specifics of multimethods
Multimethods dispatch more-specific-first, left-to-right (i.e. if
there is an exact match for the first argument it will always be tried
@@ -457,7 +446,7 @@
they return an object of an already-seen class.
The register() method of multimethods adds a function to its database
of functions, with the given signature. A function that raises
FailedToImplement causes the next match to be tried.
@@ -472,7 +461,7 @@
A priority ordering between delegators is used. See objspace.PRIORITY_*.
The code in multimethod.py is not supposed to be read by the
translator-to-C. Special optimized code will be generated instead
(typically some kind of precomputed dispatch tables).
@@ -482,7 +471,7 @@
the chaining and loop detection can be done in advance.
Multimethods are visible to user code as (bound or unbound) methods
defined for the corresponding types. (At some point built-in functions
like len() and the operator.xxx() should really directly map to the
@@ -504,6 +493,10 @@
Some multimethods can also be sliced along their second argument,
e.g. for __radd__().
+<Write me please>
.. [#] The PyPy homespage: http://www.codespeak.net/pypy/
.. [#] See for instance, *lunacy* http://www.nightmare.com/~rushing/lunacy/
.. [#] The Squeak homespage: http://www.squeak.org/
More information about the Pypy-commit