Closed 54f903ae-9f23-46ad-88dd-da1ca57b7cf8 closed 15 years ago
this patch touches only Python/ceval.c.
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 PEP-3102 - keyword-only arguments
i wrote 2 small scripts which gives an interactive function 'compilepy3k' 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 PEP-3132 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
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.
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields: ```python assignee = None closed_at =
created_at =
labels = ['type-feature', 'expert-2to3']
title = 'backport python 3.0 language functionality to python 2.5 by adding 8 opcodes to ceval.c'
updated_at =
user = 'https://bugs.python.org/kaizhu'
```
bugs.python.org fields:
```python
activity =
actor = 'loewis'
assignee = 'collinwinter'
closed = True
closed_date =
closer = 'loewis'
components = ['2to3 (2.x to 3.x conversion tool)']
creation =
creator = 'kaizhu'
dependencies = []
files = ['10758']
hgrepos = []
issue_num = 3225
keywords = []
message_count = 2.0
messages = ['68873', '68874']
nosy_count = 3.0
nosy_names = ['loewis', 'collinwinter', 'kaizhu']
pr_nums = []
priority = 'normal'
resolution = 'rejected'
stage = None
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue3225'
versions = ['Python 2.5']
```