[pypy-svn] r9545 - pypy/dist/pypy/interpreter

pedronis at codespeak.net pedronis at codespeak.net
Tue Mar 1 15:36:58 CET 2005


Author: pedronis
Date: Tue Mar  1 15:36:58 2005
New Revision: 9545

Modified:
   pypy/dist/pypy/interpreter/pycode.py
Log:
don't use multiple inheritance for frame impls



Modified: pypy/dist/pypy/interpreter/pycode.py
==============================================================================
--- pypy/dist/pypy/interpreter/pycode.py	(original)
+++ pypy/dist/pypy/interpreter/pycode.py	Tue Mar  1 15:36:58 2005
@@ -44,6 +44,28 @@
         kwargname = None
     return argnames, varargname, kwargname
 
+
+NESTED    = 1
+GENERATOR = 2
+
+frame_classes = {}
+
+def frame_class(choose):
+    if frame_classes:
+        return frame_classes[choose]
+    else:
+        from pypy.interpreter.pyopcode import PyInterpFrame
+        from pypy.interpreter.nestedscope import PyNestedScopeFrame
+        from pypy.interpreter.generator import GeneratorFrame
+
+        frame_classes[0]                = PyInterpFrame
+        frame_classes[NESTED]           = PyNestedScopeFrame
+        frame_classes[GENERATOR]        = type('PyGeneratorFrame', (PyInterpFrame,),
+                                               GeneratorFrame.__dict__.copy())
+        frame_classes[NESTED|GENERATOR] = type('PyNestedScopeGeneratorFrame', (PyNestedScopeFrame,),
+                                               GeneratorFrame.__dict__.copy())
+        return frame_classes[choose]
+
 class PyCode(eval.Code):
     "CPython-style code objects."
     
@@ -117,13 +139,12 @@
     def create_frame(self, space, w_globals, closure=None):
         "Create an empty PyFrame suitable for this code object."
         # select the appropriate kind of frame
-        from pypy.interpreter.pyopcode import PyInterpFrame as Frame
+        choose = 0
         if self.co_cellvars or self.co_freevars:
-            from pypy.interpreter.nestedscope import PyNestedScopeFrame as F
-            Frame = enhanceclass(Frame, F)
+            choose |= NESTED
         if self.co_flags & CO_GENERATOR:
-            from pypy.interpreter.generator import GeneratorFrame as F
-            Frame = enhanceclass(Frame, F)
+            choose |= GENERATOR
+        Frame = frame_class(choose)
         return Frame(space, self, w_globals, closure)
 
     signature = cpython_code_signature
@@ -224,17 +245,3 @@
             code.co_cellvars = unpack_str_tuple(space, w_cellvars)
         return space.wrap(code)
     descr_code__new__.unwrap_spec = unwrap_spec 
-
-    
-def _really_enhanceclass(key, stuff):
-    return type("Mixed", key, {})
-
-def enhanceclass(baseclass, newclass, cache=Cache()):
-    # this is a bit too dynamic for RPython, but it looks nice
-    # and I assume that we can easily change it into a static
-    # pre-computed table
-    if issubclass(newclass, baseclass):
-        return newclass
-    else:
-        return cache.getorbuild((newclass, baseclass),
-                                _really_enhanceclass, None)



More information about the Pypy-commit mailing list