[pypy-svn] r9049 - in pypy/dist/pypy/interpreter: . test
hpk at codespeak.net
hpk at codespeak.net
Thu Feb 10 16:54:13 CET 2005
Author: hpk
Date: Thu Feb 10 16:54:13 2005
New Revision: 9049
Modified:
pypy/dist/pypy/interpreter/baseobjspace.py
pypy/dist/pypy/interpreter/test/test_appinterp.py
Log:
revised hack and name. it now works like this:
space.appexec([w_value1, w_value2, ...], """
(value1, value2, ...):
...
return ...
""")
so 'appexec' becomes what app2interp should have been
from the beginning: a way for interp-level to quickly
do some work at applevel.
Modified: pypy/dist/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/dist/pypy/interpreter/baseobjspace.py (original)
+++ pypy/dist/pypy/interpreter/baseobjspace.py Thu Feb 10 16:54:13 2005
@@ -276,39 +276,34 @@
raise TypeError, 'space.exec_(): expected a string, code or PyCode object'
return statement.exec_code(self, w_globals, w_locals)
- def exec_with(self, source, **kwargs_w):
+ def appexec(self, posargs, source):
""" return value from executing given source at applevel with
given name=wrapped value parameters as its starting scope.
Note: EXPERIMENTAL.
"""
space = self
- pypyco,name2index = pypycodecache.getorbuild((space,source),
- buildpypycode, kwargs_w)
+ pypyco = pypycodecache.getorbuild((space,source), buildpypycode, posargs)
w_glob = space.newdict([])
frame = pypyco.create_frame(space, w_glob)
- for name, w_value in kwargs_w.items():
- i = name2index[name]
- frame.fastlocals_w[i] = w_value
+ frame.setfastscope(posargs)
return frame.run()
pypycodecache = Cache()
-def buildpypycode((space, source), kwargs_w):
+def buildpypycode((space, source), posargs):
""" NOT_RPYTHON """
# XXX will change once we have our own compiler
from pypy.interpreter.pycode import PyCode
from pypy.tool.pytestsupport import py # aehem
- names = kwargs_w.keys()
+ argdecl, source = source.split(':', 1)
+ argdecl = argdecl.strip()
+ if not argdecl.startswith('(') or not argdecl.endswith(')'):
+ raise SyntaxError("incorrect exec_with header\n%s" % source)
source = py.code.Source(source)
- source = source.putaround("def anon(%s):" % ", ".join(kwargs_w.keys()))
+ source = source.putaround("def anon%s:" % argdecl)
d = {}
exec source.compile() in d
newco = d['anon'].func_code
- pypyco = PyCode(space)._from_code(newco)
- varnames = list(pypyco.getvarnames())
- name2index = {}
- for name, w_value in kwargs_w.items():
- name2index[name] = varnames.index(name)
- return pypyco, name2index
+ return PyCode(space)._from_code(newco)
## Table describing the regular part of the interface of object spaces,
## namely all methods which only take w_ arguments and return a w_ result
Modified: pypy/dist/pypy/interpreter/test/test_appinterp.py
==============================================================================
--- pypy/dist/pypy/interpreter/test/test_appinterp.py (original)
+++ pypy/dist/pypy/interpreter/test/test_appinterp.py Thu Feb 10 16:54:13 2005
@@ -2,21 +2,23 @@
import py
def test_execwith_novars(space):
- val = space.exec_with("""
- return 42
+ val = space.appexec([], """
+ ():
+ return 42
""")
assert space.eq_w(val, space.wrap(42))
def test_execwith_withvars(space):
- val = space.exec_with("""
+ val = space.appexec([space.wrap(7)], """
+ (x):
y = 6 * x
return y
- """, x = space.wrap(7))
+ """)
assert space.eq_w(val, space.wrap(42))
-
def test_execwith_compile_error(space):
- excinfo = py.test.raises(SyntaxError, space.exec_with, """
+ excinfo = py.test.raises(SyntaxError, space.appexec, [], """
+ ():
y y
""")
assert str(excinfo).find('y y') != -1
More information about the Pypy-commit
mailing list