aboutsummaryrefslogtreecommitdiff
blob: b85488aa5b29c7d8f27c27804f06cf03548c5df7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
=================================
PyPython Trivial Object Space
=================================

The easiest way to implement an Object Space is to represent a Python object with itself.

A PyPy interpreter using the Trivial Object Space is an interpreter with its own main loop (written in Python), but 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.

Of course you cannot do this if the goal is to write PyPy in such a way that it doesn't rely on a real underlying Python implementation like CPython. Still, it works, and it has its own uses, like testing our interpreter, or even interpreting a different kind of bytecode -- for example, it could probably be used to emulate generators in any Python version. (That would be quite slow, however.)

(This is already done; it is funny to watch "dis.dis" disassembling itself painfully slowly :-) )

See StandardObjectSpace_ for the rest of the story.

-------------------------------------------------------------------

.. _StandardObjectSpace: stdobjspace.html