[pypy-svn] r9096 - in pypy/branch/dist-interpapp/pypy: interpreter interpreter/test tool
hpk at codespeak.net
hpk at codespeak.net
Fri Feb 11 00:42:32 CET 2005
Author: hpk
Date: Fri Feb 11 00:42:32 2005
New Revision: 9096
Added:
pypy/branch/dist-interpapp/pypy/tool/getpy.py
Modified:
pypy/branch/dist-interpapp/pypy/interpreter/gateway.py
pypy/branch/dist-interpapp/pypy/interpreter/test/test_appinterp.py
Log:
make appdef an almost wholesale substitute for app2interp:
you can pass in cpython-functions which are basically
looked up via inspect.getsource() and then fed into the
normal appdef code.
also make py more easily importable from interpreter/
(there is a conflict with py.py :-)
note that the py lib is only used at code-definition /
construction time. The translator should not see
the py lib accessed.
allowed
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 00:42:32 2005
@@ -19,6 +19,8 @@
from pypy.interpreter.baseobjspace import W_Root,ObjSpace,Wrappable
from pypy.interpreter.argument import Arguments
from pypy.tool.cache import Cache
+# internal non-translatable parts:
+from pypy.tool.getpy import py # XXX from interpreter/ we get py.py
NoneNotWrapped = object()
@@ -647,7 +649,7 @@
#
def preparesource(source, funcdecl):
- from pypy.tool.pytestsupport import py
+ """ NOT_RPYTHON """
source = py.code.Source(source)
source = source.putaround("def %s:" % funcdecl)
d = {}
@@ -656,9 +658,14 @@
assert i != -1
return d[funcdecl[:i]].func_code
-def appdef(funcdecl, source):
+def appdef(source):
+ """ NOT_RPYTHON """
from pypy.interpreter.pycode import PyCode
- from pypy.tool.pytestsupport import py
+ if not isinstance(source, str):
+ source = str(py.code.Source(source).strip())
+ assert source.startswith("def "), "can only transform functions"
+ source = source[4:]
+ funcdecl, source = str(source).split(':', 1)
newco = preparesource(source, funcdecl)
funcname, decl = funcdecl.split('(', 1)
decl = decl.strip()[:-1]
@@ -682,11 +689,13 @@
return glob[funcname]
def specialargparse(decl):
- from pypy.tool.pytestsupport import py # for code generation
+ """ NOT_RPYTHON """
wfuncargs = []
wfastnames = []
defaultargs = []
for name in decl.split(','):
+ if not name.strip():
+ continue
name = "w_%s" % name.strip()
if '=' in name:
name, value = name.split('=')
Modified: pypy/branch/dist-interpapp/pypy/interpreter/test/test_appinterp.py
==============================================================================
--- pypy/branch/dist-interpapp/pypy/interpreter/test/test_appinterp.py (original)
+++ pypy/branch/dist-interpapp/pypy/interpreter/test/test_appinterp.py Fri Feb 11 00:42:32 2005
@@ -25,7 +25,7 @@
assert str(excinfo).find('y y') != -1
def test_simple_applevel(space):
- app = appdef("app(x,y)", """
+ app = appdef("""app(x,y):
return x + y
""")
assert app.func_name == 'app'
@@ -33,10 +33,27 @@
assert space.eq_w(w_result, space.wrap(42))
def test_applevel_withdefault(space):
- app = appdef("app(x,y=1)", """
+ app = appdef("""app(x,y=1):
return x + y
""")
assert app.func_name == 'app'
w_result = app(space, space.wrap(41))
assert space.eq_w(w_result, space.wrap(42))
+def test_applevel_noargs(space):
+ app = appdef("""app():
+ return 42
+ """)
+ assert app.func_name == 'app'
+ w_result = app(space)
+ assert space.eq_w(w_result, space.wrap(42))
+
+def somefunc(arg2=42):
+ return arg2
+
+def test_app2interp_somefunc(space):
+ app = appdef(somefunc)
+ w_result = app(space)
+ assert space.eq_w(w_result, space.wrap(42))
+
+
Added: pypy/branch/dist-interpapp/pypy/tool/getpy.py
==============================================================================
--- (empty file)
+++ pypy/branch/dist-interpapp/pypy/tool/getpy.py Fri Feb 11 00:42:32 2005
@@ -0,0 +1 @@
+import py
More information about the Pypy-commit
mailing list