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.

Author kaizhu
Recipients collinwinter, kaizhu
Date 2008-06-28.11:30:08
SpamBayes Score 0.0014977239
Marked as misclassified No
Message-id <1214652619.02.0.198443521566.issue3225@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2008-06-28 11:30:19kaizhusetspambayes_score: 0.00149772 -> 0.0014977239
recipients: + kaizhu, collinwinter
2008-06-28 11:30:19kaizhusetspambayes_score: 0.00149772 -> 0.00149772
messageid: <1214652619.02.0.198443521566.issue3225@psf.upfronthosting.co.za>
2008-06-28 11:30:17kaizhulinkissue3225 messages
2008-06-28 11:30:15kaizhucreate