This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: backport python 3.0 language functionality to python 2.5 by adding 8 opcodes to ceval.c
Type: enhancement Stage:
Components: 2to3 (2.x to 3.x conversion tool) Versions: Python 2.5
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: collinwinter Nosy List: collinwinter, kaizhu, loewis
Priority: normal Keywords:

Created on 2008-06-28 11:30 by kaizhu, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
ceval.c kaizhu, 2008-06-28 11:30 Python 2.5.2 ceval.c patched by adding 8 new opcodes to PyEval_EvalFrameEx
Messages (2)
msg68873 - (view) Author: kai zhu (kaizhu) Date: 2008-06-28 11:30
this patch touches only Python/ceval.c.

1. the only existing thing it modifies is PyEval_EvalFrameEx (adds 8
extra cases for the new 3.0 opcodes, doesn't mess w/ any of the existing
ones, or anything else as a matter of fact)

2. that, plus it defines (the new opcodes)
#define SET_ADD 17            
#define STORE_MAP 54          
#define STORE_LOCALS 69       
#define LOAD_BUILD_CLASS 34   
#define MAKE_BYTES 35         
#define POP_EXCEPT 36         
#define UNPACK_EX 94          
#define BUILD_SET 109         
and some backported vars & helper functions

only 2 contiguous areas of ceval.c is patched (1. & 2. - areas are
delimited by the comments '// py3k')

this simple patch seems sufficient in theory to allow the interpreter to
natively execute most of 3.0's language syntax (nonlocal, print,
extended unpacking... have been tested to work)
*the one exception being pep3102 - keyword-only arguments

i wrote 2 small scripts which gives an interactive function
'compile_py3k' similar to __builtin__.compile except it works only for
3.0 syntax.  it doesn't actually compile, but rather cheats by querying
it to a python 3.0 server via pipe io.

here is an interactive demonstration of my script:

example demonstrating pep3132 extended unpacking syntax: a,b,*c = 1,2,3,4

Python 2.5.2 (r252:60911, Jun 27 2008, 21:19:51)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

>>> import py3to2
py3to2 server restarting with io: (4, 5)
py3to2 server: Python 3.0b1 (r30b1:64395, Jun 24 2008, 21:53:55)
py3to2 server: [GCC 3.4.6 20060404 (Red Hat 3.4.6-9)] on linux2
py3to2 server: Type "help", "copyright", "credits" or "license" for more
information.
py3to2 server: 

>>> src = "a,b,*c = 1,2,3,4"
>>> codeobject = py3to2.compile_py3k(src,"","exec")
  1           0 LOAD_CONST               5 ((1, 2, 3, 4))
              3 UNPACK_EX_py3k           2
              6 STORE_NAME               0 (a)
              9 STORE_NAME               1 (b)
             12 STORE_NAME               2 (c)
             15 LOAD_CONST               4 (None)
             18 RETURN_VALUE

>>> exec(codeobject); print "a=%s, b=%s, c=%s"%(a,b,c)
a=1, b=2, c=[3, 4]
>>>

u can go c
http://pypi.python.org/pypi?name=py3to2&version=20080628&:action=display
for more info

anyway, i think it would b a great boost for python 3.0 (which i think
is very cool) if developers can test/develop it under the robust 2.5
environment.  this patch plus some scripts could go a long way in making
that happen
msg68874 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2008-06-28 12:03
Sorry, but adding new feature into the 2.5.3 release (or any later 2.5
release) is unacceptable; the feature list of 2.5 was frozen in 2006
(when the first beta release of 2.5 was made). Thus, I'm rejecting the
patch.
History
Date User Action Args
2022-04-11 14:56:35adminsetgithub: 47475
2008-06-28 12:03:13loewissetstatus: open -> closed
nosy: + loewis
resolution: rejected
messages: + msg68874
2008-06-28 11:30:18kaizhucreate