[pypy-svn] r15350 - in pypy/dist/pypy: interpreter interpreter/test translator/goal

pedronis at codespeak.net pedronis at codespeak.net
Fri Jul 29 15:45:01 CEST 2005


Author: pedronis
Date: Fri Jul 29 15:44:57 2005
New Revision: 15350

Modified:
   pypy/dist/pypy/interpreter/baseobjspace.py
   pypy/dist/pypy/interpreter/gateway.py
   pypy/dist/pypy/interpreter/test/test_appinterp.py
   pypy/dist/pypy/interpreter/test/test_gateway.py
   pypy/dist/pypy/translator/goal/targetpypymain.py
Log:
use_geninterp is now an option (can be set as a keyword arg) on the spaces



Modified: pypy/dist/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/dist/pypy/interpreter/baseobjspace.py	(original)
+++ pypy/dist/pypy/interpreter/baseobjspace.py	Fri Jul 29 15:44:57 2005
@@ -109,6 +109,7 @@
                  parser="recparser", 
                  compiler="pyparse",
                  translating=False,
+                 use_geninterp=True,
                  **kw
                  ): 
         "NOT_RPYTHON: Basic initialization of objects."
@@ -123,6 +124,7 @@
         self.options.compiler = compiler 
         self.options.usemodules = usemodules 
         self.options.translating = translating
+        self.options.use_geninterp = use_geninterp
         self.setoptions(**kw)
         self.initialize()
 

Modified: pypy/dist/pypy/interpreter/gateway.py
==============================================================================
--- pypy/dist/pypy/interpreter/gateway.py	(original)
+++ pypy/dist/pypy/interpreter/gateway.py	Fri Jul 29 15:44:57 2005
@@ -508,7 +508,6 @@
     name at app-level."""
 
     hidden_applevel = True
-    use_geninterp = True    # change this to disable geninterp globally
 
     def __init__(self, source, filename = None, modname = '__builtin__'):
         self.filename = filename
@@ -517,7 +516,9 @@
         # look at the first three lines for a NOT_RPYTHON tag
         first = "\n".join(source.split("\n", 3)[:3])
         if "NOT_RPYTHON" in first:
-            self.use_geninterp = False
+            self.can_use_geninterp = False
+        else:
+            self.can_use_geninterp = True
 
     def getwdict(self, space):
         return space.fromcache(ApplevelCache).getorbuild(self)
@@ -562,7 +563,7 @@
 
     def build(self, app):
         "NOT_RPYTHON.  Called indirectly by Applevel.getwdict()."
-        if app.use_geninterp:
+        if self.space.options.use_geninterp and app.can_use_geninterp:
             return PyPyCacheDir.build_applevelinterp_dict(app, self.space)
         else:
             return build_applevel_dict(app, self.space)
@@ -731,13 +732,11 @@
     def getwdict(self, space):    # no cache
         return build_applevel_dict(self, space)
 
-if ApplevelClass.use_geninterp:
-    class applevelinterp_temp(ApplevelClass):
-        hidden_applevel = False
-        def getwdict(self, space):   # no cache
-            return PyPyCacheDir.build_applevelinterp_dict(self, space)
-else:
-    applevelinterp_temp = applevel_temp
+
+class applevelinterp_temp(ApplevelClass):
+    hidden_applevel = False
+    def getwdict(self, space):   # no cache
+        return PyPyCacheDir.build_applevelinterp_dict(self, space)
 
 # app2interp_temp is used for testing mainly
 def app2interp_temp(func, applevel_temp=applevel_temp):

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	Fri Jul 29 15:44:57 2005
@@ -1,6 +1,6 @@
 
 import py
-from pypy.interpreter.gateway import appdef, ApplevelClass
+from pypy.interpreter.gateway import appdef, ApplevelClass, applevel_temp, applevelinterp_temp
 
 def test_execwith_novars(space): 
     val = space.appexec([], """ 
@@ -70,29 +70,27 @@
     w_result = app(space) 
     assert space.eq_w(w_result, space.wrap(42))
 
-def test_applevel_functions(space, use_geninterp=False):
-    app = ApplevelClass('''
+def test_applevel_functions(space, applevel_temp = applevel_temp):
+    app = applevel_temp('''
         def f(x, y):
             return x-y
         def g(x, y):
             return f(y, x)
     ''')
-    app.use_geninterp &= use_geninterp
     g = app.interphook('g')
     w_res = g(space, space.wrap(10), space.wrap(1))
     assert space.eq_w(w_res, space.wrap(-9))
 
 def test_applevelinterp_functions(space):
-    test_applevel_functions(space, use_geninterp=True)
+    test_applevel_functions(space, applevel_temp = applevelinterp_temp)
 
-def test_applevel_class(space, use_geninterp=False):
-    app = ApplevelClass('''
+def test_applevel_class(space, applevel_temp = applevel_temp):
+    app = applevel_temp('''
         class C: 
             clsattr = 42 
             def __init__(self, x=13): 
                 self.attr = x 
     ''')
-    app.use_geninterp &= use_geninterp
     C = app.interphook('C')
     c = C(space, space.wrap(17)) 
     w_attr = space.getattr(c, space.wrap('clsattr'))
@@ -101,7 +99,7 @@
     assert space.eq_w(w_clsattr, space.wrap(17))
 
 def test_applevelinterp_class(space):
-    test_applevel_class(space, use_geninterp=True)
+    test_applevel_class(space, applevel_temp = applevelinterp_temp)
 
 def app_test_something_at_app_level(): 
     x = 2

Modified: pypy/dist/pypy/interpreter/test/test_gateway.py
==============================================================================
--- pypy/dist/pypy/interpreter/test/test_gateway.py	(original)
+++ pypy/dist/pypy/interpreter/test/test_gateway.py	Fri Jul 29 15:44:57 2005
@@ -76,6 +76,13 @@
             return a+b
         g3 = gateway.app2interp_temp(app_g3)
         assert self.space.eq_w(g3(self.space, w('foo'), w('bar')), w('foobar'))
+
+    def test_app2interp1(self):
+        w = self.space.wrap
+        def noapp_g3(a, b):
+            return a+b
+        g3 = gateway.app2interp_temp(noapp_g3, gateway.applevel_temp)
+        assert self.space.eq_w(g3(self.space, w('foo'), w('bar')), w('foobar'))
         
     def test_app2interp2(self):
         """same but using transformed code"""

Modified: pypy/dist/pypy/translator/goal/targetpypymain.py
==============================================================================
--- pypy/dist/pypy/translator/goal/targetpypymain.py	(original)
+++ pypy/dist/pypy/translator/goal/targetpypymain.py	Fri Jul 29 15:44:57 2005
@@ -37,11 +37,10 @@
     # disable geninterp for now -- we have faaar toooo much interp-level code
     # for the poor translator already
     # XXX why can't I enable this? crashes the annotator!
-    gateway.ApplevelClass.use_geninterp = False
-
     space = StdObjSpace(nofaking=True,
                         compiler="pyparseapp",
-                        translating=True)
+                        translating=True,
+                        use_geninterp=False)
 
     # manually imports app_main.py
     filename = os.path.join(this_dir, 'app_main.py')



More information about the Pypy-commit mailing list