[pypy-svn] r35956 - in pypy/dist/pypy: interpreter objspace/std

mwh at codespeak.net mwh at codespeak.net
Fri Dec 22 15:46:57 CET 2006


Author: mwh
Date: Fri Dec 22 15:46:55 2006
New Revision: 35956

Modified:
   pypy/dist/pypy/interpreter/baseobjspace.py
   pypy/dist/pypy/interpreter/eval.py
   pypy/dist/pypy/interpreter/gateway.py
   pypy/dist/pypy/interpreter/pycode.py
   pypy/dist/pypy/objspace/std/fake.py
   pypy/dist/pypy/objspace/std/objspace.py
Log:
move frame creation onto the space


Modified: pypy/dist/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/dist/pypy/interpreter/baseobjspace.py	(original)
+++ pypy/dist/pypy/interpreter/baseobjspace.py	Fri Dec 22 15:46:55 2006
@@ -404,6 +404,11 @@
             self.default_compiler = compiler
             return compiler
 
+    def createframe(self, code, w_globals, closure=None):
+        "Create an empty PyFrame suitable for this code object."
+        from pypy.interpreter import pyframe
+        return pyframe.PyFrame(self, code, w_globals, closure)
+
     # Following is a friendly interface to common object space operations
     # that can be defined in term of more primitive ones.  Subclasses
     # may also override specific functions for performance.

Modified: pypy/dist/pypy/interpreter/eval.py
==============================================================================
--- pypy/dist/pypy/interpreter/eval.py	(original)
+++ pypy/dist/pypy/interpreter/eval.py	Fri Dec 22 15:46:55 2006
@@ -15,13 +15,10 @@
     def __init__(self, co_name):
         self.co_name = co_name
 
-    def create_frame(self, space, w_globals, closure=None):
-        "Create an empty frame object suitable for evaluation of this code."
-        raise TypeError, "abstract"
-
     def exec_code(self, space, w_globals, w_locals):
         "Implements the 'exec' statement."
-        frame = self.create_frame(space, w_globals, None)
+        # this should be on PyCode?
+        frame = space.createframe(self, w_globals, None)
         frame.setdictscope(w_locals)
         return frame.run()
 
@@ -52,8 +49,8 @@
         return None
 
     def funcrun(self, func, args):
-        frame = self.create_frame(func.space, func.w_func_globals,
-                                  func.closure)
+        frame = func.space.createframe(self, func.w_func_globals,
+                                        func.closure)
         sig = self.signature()
         scope_w = args.parse(func.name, sig, func.defs_w)
         frame.setfastscope(scope_w)

Modified: pypy/dist/pypy/interpreter/gateway.py
==============================================================================
--- pypy/dist/pypy/interpreter/gateway.py	(original)
+++ pypy/dist/pypy/interpreter/gateway.py	Fri Dec 22 15:46:55 2006
@@ -438,9 +438,6 @@
                 self.__class__ = globals()['BuiltinCode%d' % arity]
                 setattr(self, 'fastfunc_%d' % arity, fastfunc)
 
-    def create_frame(self, space, w_globals, closure=None):
-        raise NotImplementedError
-
     def signature(self):
         return self.sig
 

Modified: pypy/dist/pypy/interpreter/pycode.py
==============================================================================
--- pypy/dist/pypy/interpreter/pycode.py	(original)
+++ pypy/dist/pypy/interpreter/pycode.py	Fri Dec 22 15:46:55 2006
@@ -172,14 +172,14 @@
 
     def fastcall_0(self, space, w_func):
         if self.do_fastcall == 0:
-            frame = self.create_frame(space, w_func.w_func_globals,
+            frame = space.createframe(self, w_func.w_func_globals,
                                       w_func.closure)
             return frame.run()
         return None
 
     def fastcall_1(self, space, w_func, w_arg):
         if self.do_fastcall == 1:
-            frame = self.create_frame(space, w_func.w_func_globals,
+            frame = space.createframe(self, w_func.w_func_globals,
                                       w_func.closure)
             frame.fastlocals_w[0] = w_arg # frame.setfastscope([w_arg])
             return frame.run()
@@ -187,7 +187,7 @@
 
     def fastcall_2(self, space, w_func, w_arg1, w_arg2):
         if self.do_fastcall == 2:
-            frame = self.create_frame(space, w_func.w_func_globals,
+            frame = space.createframe(self, w_func.w_func_globals,
                                       w_func.closure)
             frame.fastlocals_w[0] = w_arg1 # frame.setfastscope([w_arg])
             frame.fastlocals_w[1] = w_arg2
@@ -196,8 +196,8 @@
 
     def fastcall_3(self, space, w_func, w_arg1, w_arg2, w_arg3):
         if self.do_fastcall == 3:
-            frame = self.create_frame(space, w_func.w_func_globals,
-                                      w_func.closure)
+            frame = space.createframe(self, w_func.w_func_globals,
+                                       w_func.closure)
             frame.fastlocals_w[0] = w_arg1 # frame.setfastscope([w_arg])
             frame.fastlocals_w[1] = w_arg2 
             frame.fastlocals_w[2] = w_arg3 
@@ -206,8 +206,8 @@
 
     def fastcall_4(self, space, w_func, w_arg1, w_arg2, w_arg3, w_arg4):
         if self.do_fastcall == 4:
-            frame = self.create_frame(space, w_func.w_func_globals,
-                                      w_func.closure)
+            frame = space.createframe(self, w_func.w_func_globals,
+                                       w_func.closure)
             frame.fastlocals_w[0] = w_arg1 # frame.setfastscope([w_arg])
             frame.fastlocals_w[1] = w_arg2 
             frame.fastlocals_w[2] = w_arg3 
@@ -216,7 +216,7 @@
         return None
 
     def funcrun(self, func, args):
-        frame = self.create_frame(self.space, func.w_func_globals,
+        frame = self.space.createframe(self, func.w_func_globals,
                                   func.closure)
         sig = self._signature
         # speed hack
@@ -225,11 +225,6 @@
         frame.init_cells()
         return frame.run()
 
-    def create_frame(self, space, w_globals, closure=None):
-        "Create an empty PyFrame suitable for this code object."
-        from pypy.interpreter import pyframe
-        return pyframe.PyFrame(space, self, w_globals, closure)
-
     def getvarnames(self):
         return self.co_varnames
 

Modified: pypy/dist/pypy/objspace/std/fake.py
==============================================================================
--- pypy/dist/pypy/objspace/std/fake.py	(original)
+++ pypy/dist/pypy/objspace/std/fake.py	Fri Dec 22 15:46:55 2006
@@ -134,8 +134,6 @@
         eval.Code.__init__(self, getattr(cpy_callable, '__name__', '?'))
         self.cpy_callable = cpy_callable
         assert callable(cpy_callable), cpy_callable
-    def create_frame(self, space, w_globals, closure=None):
-        return CPythonFakeFrame(space, self, w_globals)
     def signature(self):
         return [], 'args', 'kwds'
 

Modified: pypy/dist/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/dist/pypy/objspace/std/objspace.py	(original)
+++ pypy/dist/pypy/objspace/std/objspace.py	Fri Dec 22 15:46:55 2006
@@ -12,6 +12,7 @@
 from pypy.objspace.descroperation import DescrOperation
 from pypy.objspace.std import stdtypedef
 from pypy.rlib.rarithmetic import base_int
+from pypy.rlib.objectmodel import we_are_translated
 import sys
 import os
 import __builtin__
@@ -227,6 +228,13 @@
         ec._py_repr = self.newdict()
         return ec
 
+    def createframe(self, code, w_globals, closure=None):
+        from pypy.objspace.std.fake import CPythonFakeCode, CPythonFakeFrame
+        if not we_are_translated() and isinstance(code, CPythonFakeCode):
+            return CPythonFakeFrame(self, code, w_globals)
+        else:
+            return ObjSpace.createframe(self, code, w_globals, closure)
+
     def gettypefor(self, cls):
         return self.gettypeobject(cls.typedef)
 



More information about the Pypy-commit mailing list