[pypy-svn] r9122 - pypy/branch/dist-interpapp/pypy/interpreter
hpk at codespeak.net
hpk at codespeak.net
Fri Feb 11 16:06:06 CET 2005
Author: hpk
Date: Fri Feb 11 16:06:06 2005
New Revision: 9122
Modified:
pypy/branch/dist-interpapp/pypy/interpreter/gateway.py
Log:
intermediate checkin of the try to use appexec
which is mainly a string-formatting problem now :-)
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 16:06:06 2005
@@ -610,7 +610,7 @@
assert source.startswith("def "), "can only transform functions"
source = source[4:]
funcdecl, source = source.strip().split(':', 1)
- newco = preparesource(source, funcdecl)
+ #newco = preparesource(source, funcdecl)
funcname, decl = funcdecl.split('(', 1)
if overridename is not None:
funcname = overridename
@@ -618,21 +618,25 @@
funcname = funcname.strip()
decl = decl.strip()[:-1]
wfuncdecl, wfastscope, defaulthandlingsource = specialargparse(decl)
- source = py.code.Source("""\
- def %s(space, %s):
- # HERE we inject the defaultargs-handling below
- pypyco = PyCode(space)._from_code(newco)
- w_glob = space.newdict([])
- frame = pypyco.create_frame(space, w_glob)
- frame.setfastscope([%s])
- return frame.run()
- """ % (funcname, wfuncdecl, wfastscope))
- source.lines[1:2] = defaulthandlingsource.indent().lines
+
+ # get rid of w_
+ fastscope = ", ".join([x.strip()[2:] for x in wfastscope.split(',')])
+
+ # construct the special app source passed to appexec
+ appsource = py.code.Source(source).strip().putaround("(%s):" % fastscope, "")
+ sourcelines = ["def %(funcname)s(space, %(wfuncdecl)s):" % locals()]
+ sourcelines.extend(defaulthandlingsource.indent().lines)
+ sourcelines.append(
+ " return space.appexec([%(wfastscope)s], '''" % locals())
+ for line in appsource.indent().indent().lines:
+ line = line.replace("'''", "\'\'\'")
+ sourcelines.append(line)
+ sourcelines.append( "''')")
+ source = py.code.Source()
+ source.lines = sourcelines
+ #source = py.code.Source(sourcelines)
print str(source)
- glob = {
- 'newco' : newco,
- 'PyCode': PyCode,
- }
+ glob = {}
exec source.compile() in glob
return glob[funcname]
More information about the Pypy-commit
mailing list