[pypy-svn] r9134 - pypy/branch/dist-interpapp/pypy/interpreter
hpk at codespeak.net
hpk at codespeak.net
Fri Feb 11 18:08:18 CET 2005
Author: hpk
Date: Fri Feb 11 18:08:18 2005
New Revision: 9134
Modified:
pypy/branch/dist-interpapp/pypy/interpreter/baseobjspace.py
pypy/branch/dist-interpapp/pypy/interpreter/gateway.py
Log:
simplified appexec() signature by allowing
a function name to be optionally specified
in the sourcecode string aka:
func = appdef("""func(x,1):
...
""")
Modified: pypy/branch/dist-interpapp/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/branch/dist-interpapp/pypy/interpreter/baseobjspace.py (original)
+++ pypy/branch/dist-interpapp/pypy/interpreter/baseobjspace.py Fri Feb 11 18:08:18 2005
@@ -277,29 +277,33 @@
raise TypeError, 'space.exec_(): expected a string, code or PyCode object'
return statement.exec_code(self, w_globals, w_locals)
- def appexec(self, posargs_w, source, funcname="anon"):
+ def appexec(self, posargs_w, source):
""" return value from executing given source at applevel with
given name=wrapped value parameters as its starting scope.
Note: EXPERIMENTAL.
"""
space = self
- pypyco = space.loadfromcache((source, funcname), buildpypycode,
- self._codecache)
+ pypyco = space.loadfromcache((source), buildpypycode, self._codecache)
w_glob = space.newdict([])
frame = pypyco.create_frame(space, w_glob)
frame.setfastscope(posargs_w)
return frame.run()
pypycodecache = Cache()
-def buildpypycode((source, funcname), space):
+def buildpypycode(source, space):
""" NOT_RPYTHON """
# XXX will change once we have our own compiler
from pypy.interpreter.pycode import PyCode
from pypy.tool.pytestsupport import py # aehem
argdecl, source = source.split(':', 1)
argdecl = argdecl.strip()
+ i = argdecl.find('(')
+ if i >0:
+ funcname, argdecl = argdecl[:i], argdecl[i:]
+ else:
+ funcname = 'anon'
if not argdecl.startswith('(') or not argdecl.endswith(')'):
- raise SyntaxError("incorrect exec_with header\n%s" % source)
+ raise SyntaxError("incorrect appexec header\n%s" % source)
source = py.code.Source(source)
source = source.putaround("def %s%s:" % (funcname, argdecl))
d = {}
Modified: pypy/branch/dist-interpapp/pypy/interpreter/gateway.py
==============================================================================
--- pypy/branch/dist-interpapp/pypy/interpreter/gateway.py (original)
+++ pypy/branch/dist-interpapp/pypy/interpreter/gateway.py Fri Feb 11 18:08:18 2005
@@ -624,7 +624,7 @@
# SOME MESS AHEAD !
# construct the special app source passed to appexec
- appsource = py.code.Source(source).strip().putaround("(%s):" % fastscope)
+ appsource = py.code.Source(source).strip().putaround("%s(%s):" % (funcname, fastscope))
sourcelines = ["def %(funcname)s(space, %(wfuncdecl)s):" % locals()]
sourcelines.extend(defaulthandlingsource.indent().lines)
sourcelines.append(
@@ -632,10 +632,11 @@
for line in appsource.indent().indent().lines:
line = line.replace("\\", r"\\").replace("'", r"\'")
sourcelines.append(line)
- sourcelines.append( "''', funcname=%r)" % funcname)
+ sourcelines.append("''')")
source = py.code.Source()
source.lines = sourcelines
glob = {}
+ print str(source)
exec source.compile() in glob
return glob[funcname]
More information about the Pypy-commit
mailing list