[pypy-svn] r49863 - in pypy/dist/pypy: interpreter interpreter/test module/__builtin__ objspace objspace/flow objspace/std objspace/std/test

arigo at codespeak.net arigo at codespeak.net
Mon Dec 17 11:02:37 CET 2007


Author: arigo
Date: Mon Dec 17 11:02:36 2007
New Revision: 49863

Added:
   pypy/dist/pypy/objspace/std/callmethod.py
      - copied, changed from r49862, pypy/dist/pypy/interpreter/callmethod.py
   pypy/dist/pypy/objspace/std/test/test_callmethod.py
      - copied, changed from r49862, pypy/dist/pypy/interpreter/test/test_callmethod.py
Removed:
   pypy/dist/pypy/interpreter/callmethod.py
   pypy/dist/pypy/interpreter/test/test_callmethod.py
Modified:
   pypy/dist/pypy/interpreter/baseobjspace.py
   pypy/dist/pypy/interpreter/pyopcode.py
   pypy/dist/pypy/module/__builtin__/descriptor.py
   pypy/dist/pypy/objspace/descroperation.py
   pypy/dist/pypy/objspace/flow/flowcontext.py
   pypy/dist/pypy/objspace/std/objspace.py
Log:
Use a nicer approach for the fallback of the CALL_METHOD opcode,
based on the one used for CALL_LIKELY_BUILTIN.  This required
moving callmethod to the stdobjspace, which makes some sense
anyway.


Modified: pypy/dist/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/dist/pypy/interpreter/baseobjspace.py	(original)
+++ pypy/dist/pypy/interpreter/baseobjspace.py	Mon Dec 17 11:02:36 2007
@@ -181,10 +181,8 @@
             config = get_pypy_config(translating=False)
         self.config = config
 
-        # import extra modules for side-effects, possibly based on config
+        # import extra modules for side-effects
         import pypy.interpreter.nestedscope     # register *_DEREF bytecodes
-        if self.config.objspace.opcodes.CALL_METHOD:
-            import pypy.interpreter.callmethod  # register *_METHOD bytecodes
 
         self.interned_strings = {}
         self.pending_actions = []

Modified: pypy/dist/pypy/interpreter/pyopcode.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyopcode.py	(original)
+++ pypy/dist/pypy/interpreter/pyopcode.py	Mon Dec 17 11:02:36 2007
@@ -931,6 +931,25 @@
             f.dropvalues(nargs)
         f.pushvalue(w_result)
 
+    def LOOKUP_METHOD(f, nameindex, *ignored):
+        # overridden by faster version in the standard object space.
+        space = f.space
+        w_obj = f.popvalue()
+        w_name = f.getname_w(nameindex)
+        w_value = space.getattr(w_obj, w_name)
+        f.pushvalue(w_value)
+        #f.pushvalue(None)
+
+    def CALL_METHOD(f, nargs, *ignored):
+        # overridden by faster version in the standard object space.
+        # 'nargs' is the argument count excluding the implicit 'self'
+        w_callable = f.peekvalue(nargs)
+        try:
+            w_result = f.space.call_valuestack(w_callable, nargs, f)
+        finally:
+            f.dropvalues(nargs + 1)
+        f.pushvalue(w_result)
+
 ##     def EXTENDED_ARG(f, oparg, *ignored):
 ##         opcode = f.nextop()
 ##         oparg = oparg<<16 | f.nextarg()

Modified: pypy/dist/pypy/module/__builtin__/descriptor.py
==============================================================================
--- pypy/dist/pypy/module/__builtin__/descriptor.py	(original)
+++ pypy/dist/pypy/module/__builtin__/descriptor.py	Mon Dec 17 11:02:36 2007
@@ -4,7 +4,7 @@
      Arguments
 from pypy.interpreter.gateway import interp2app
 from pypy.interpreter.error import OperationError
-from pypy.interpreter.callmethod import object_getattribute
+from pypy.objspace.descroperation import object_getattribute
 from pypy.interpreter.function import StaticMethod, ClassMethod
 from pypy.interpreter.typedef import GetSetProperty, descr_get_dict, \
      descr_set_dict, interp_attrproperty_w

Modified: pypy/dist/pypy/objspace/descroperation.py
==============================================================================
--- pypy/dist/pypy/objspace/descroperation.py	(original)
+++ pypy/dist/pypy/objspace/descroperation.py	Mon Dec 17 11:02:36 2007
@@ -6,6 +6,13 @@
 from pypy.interpreter.typedef import default_identity_hash
 from pypy.tool.sourcetools import compile2, func_with_new_name
 
+def object_getattribute(space):
+    "Utility that returns the app-level descriptor object.__getattribute__."
+    w_src, w_getattribute = space.lookup_in_type_where(space.w_object,
+                                                       '__getattribute__')
+    return w_getattribute
+object_getattribute._annspecialcase_ = 'specialize:memo'
+
 def raiseattrerror(space, w_obj, name, w_descr=None):
     w_type = space.type(w_obj)
     typename = w_type.getname(space, '?')

Modified: pypy/dist/pypy/objspace/flow/flowcontext.py
==============================================================================
--- pypy/dist/pypy/objspace/flow/flowcontext.py	(original)
+++ pypy/dist/pypy/objspace/flow/flowcontext.py	Mon Dec 17 11:02:36 2007
@@ -19,24 +19,6 @@
         self.block = block
         self.currentstate = currentstate
 
-class PyFrame(pyframe.PyFrame):
-    def LOOKUP_METHOD(f, nameindex, *ignored):
-        space = f.space
-        w_obj = f.popvalue()
-        w_name = f.getname_w(nameindex)
-        w_value = space.getattr(w_obj, w_name)
-        f.pushvalue(w_value)
-        #f.pushvalue(None)
-
-    def CALL_METHOD(f, nargs, *ignored):
-        # 'nargs' is the argument count excluding the implicit 'self'
-        w_callable = f.peekvalue(nargs)
-        try:
-            w_result = f.space.call_valuestack(w_callable, nargs, f)
-        finally:
-            f.dropvalues(nargs + 1)
-        f.pushvalue(w_result)
-
 class SpamBlock(Block):
     # make slots optional, for debugging
     if hasattr(Block, '__slots__'):
@@ -236,7 +218,7 @@
         # create an empty frame suitable for the code object
         # while ignoring any operation like the creation of the locals dict
         self.recorder = []
-        frame = PyFrame(self.space, self.code,
+        frame = pyframe.PyFrame(self.space, self.code,
                                 self.w_globals, self.closure)
         frame.last_instr = 0
         return frame

Modified: pypy/dist/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/dist/pypy/objspace/std/objspace.py	(original)
+++ pypy/dist/pypy/objspace/std/objspace.py	Mon Dec 17 11:02:36 2007
@@ -134,6 +134,12 @@
                         f.dropvalues(nargs)
                     f.pushvalue(w_result)
 
+            if self.config.objspace.opcodes.CALL_METHOD:
+                # def LOOKUP_METHOD(...):
+                from pypy.objspace.std.callmethod import LOOKUP_METHOD
+                # def CALL_METHOD(...):
+                from pypy.objspace.std.callmethod import CALL_METHOD
+
             if self.config.objspace.std.logspaceoptypes:
                 _space_op_types = []
                 for name, func in pyframe.PyFrame.__dict__.iteritems():
@@ -606,6 +612,13 @@
         else:
             self.setitem(w_obj, w_key, w_value)
 
+    def call_method(self, w_obj, methname, *arg_w):
+        if self.config.objspace.opcodes.CALL_METHOD:
+            from pypy.objspace.std.callmethod import call_method_opt
+            return call_method_opt(self, w_obj, methname, *arg_w)
+        else:
+            return ObjSpace.call_method(self, w_obj, methname, *arg_w)
+
     # support for the deprecated __getslice__, __setslice__, __delslice__
 
     def getslice(self, w_obj, w_start, w_stop):



More information about the Pypy-commit mailing list