[pypy-svn] r29921 - in pypy/dist/pypy: objspace/flow rpython/memory tool translator

arigo at codespeak.net arigo at codespeak.net
Mon Jul 10 18:36:20 CEST 2006


Author: arigo
Date: Mon Jul 10 18:36:17 2006
New Revision: 29921

Modified:
   pypy/dist/pypy/objspace/flow/objspace.py
   pypy/dist/pypy/rpython/memory/lladdress.py
   pypy/dist/pypy/tool/uid.py
   pypy/dist/pypy/translator/geninterplevel.py
Log:
Some more hacks, mostly in geninterplevel.py, to make py.py at least
start up when run inside pypy-c.  It doesn't work well enough yet,
though.



Modified: pypy/dist/pypy/objspace/flow/objspace.py
==============================================================================
--- pypy/dist/pypy/objspace/flow/objspace.py	(original)
+++ pypy/dist/pypy/objspace/flow/objspace.py	Mon Jul 10 18:36:17 2006
@@ -16,8 +16,11 @@
 class WrapException(Exception):
     """Attempted wrapping of a type that cannot sanely appear in flow graph or during its construction"""
 
-# method-wrappers
-method_wrapper = type(complex.real.__get__)
+# method-wrappers have not enough introspection in CPython
+if hasattr(complex.real.__get__, 'im_self'):
+    type_with_bad_introspection = None     # on top of PyPy
+else:
+    type_with_bad_introspection = type(complex.real.__get__)
 
 
 # ______________________________________________________________________
@@ -114,7 +117,7 @@
             raise TypeError("already wrapped: " + repr(obj))
         # method-wrapper have ill-defined comparison and introspection
         # to appear in a flow graph
-        if type(obj) is method_wrapper:
+        if type(obj) is type_with_bad_introspection:
             raise WrapException
         return Constant(obj)
 

Modified: pypy/dist/pypy/rpython/memory/lladdress.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/lladdress.py	(original)
+++ pypy/dist/pypy/rpython/memory/lladdress.py	Mon Jul 10 18:36:17 2006
@@ -105,8 +105,8 @@
     convert_to = str
 
 class _address_accessor(_accessor):
-    format = "P"
-    size = struct.calcsize("P")
+    from pypy.tool.uid import HUGEVAL_FMT as format
+    from pypy.tool.uid import HUGEVAL_BYTES as size
     convert_from = _address
     convert_to = staticmethod(lambda addr: addr.intaddress)
 

Modified: pypy/dist/pypy/tool/uid.py
==============================================================================
--- pypy/dist/pypy/tool/uid.py	(original)
+++ pypy/dist/pypy/tool/uid.py	Mon Jul 10 18:36:17 2006
@@ -3,11 +3,14 @@
 # This is temporary hack to run PyPy on PyPy
 # until PyPy's struct module handle P format character.
 try:
+    HUGEVAL_FMT   = 'P'
     HUGEVAL_BYTES = struct.calcsize('P')
 except struct.error:
     if sys.maxint <= 2147483647:
+        HUGEVAL_FMT   = 'l'
         HUGEVAL_BYTES = 4
     else:
+        HUGEVAL_FMT   = 'q'
         HUGEVAL_BYTES = 8
 
 HUGEVAL = 256 ** HUGEVAL_BYTES

Modified: pypy/dist/pypy/translator/geninterplevel.py
==============================================================================
--- pypy/dist/pypy/translator/geninterplevel.py	(original)
+++ pypy/dist/pypy/translator/geninterplevel.py	Mon Jul 10 18:36:17 2006
@@ -589,6 +589,9 @@
     def nameof_function(self, func, namehint=''):
         if hasattr(func, 'geninterplevel_name'):
             return func.geninterplevel_name(self)
+        if func.func_globals is None:
+            # built-in functions on top of PyPy
+            return self.nameof_builtin_function(func)
 
         printable_name = '(%s:%d) %s' % (
             self.trans_funcname(func.func_globals.get('__name__', '?')),
@@ -615,6 +618,9 @@
         return name
 
     def nameof_instancemethod(self, meth):
+        if meth.im_func.func_globals is None:
+            # built-in methods (bound or not) on top of PyPy
+            return self.nameof_builtin_method(meth)
         if meth.im_self is None:
             # no error checking here
             return self.nameof(meth.im_func, namehint="%s_" % meth.im_class.__name__)
@@ -691,36 +697,51 @@
         
     def nameof_builtin_function_or_method(self, func):
         if func.__self__ is None:
-            # builtin function
-            if id(func) in self.builtin_ids:
-                func = self.builtin_ids[id(func)]
-                return "(space.builtin.get(space.str_w(%s)))" % self.nameof(func.__name__)
-            # where does it come from? Python2.2 doesn't have func.__module__
-            for modname, module in sys.modules.items():
-                if hasattr(module, '__file__'):
-                    if (module.__file__.endswith('.py') or
-                        module.__file__.endswith('.pyc') or
-                        module.__file__.endswith('.pyo')):
-                        continue    # skip non-builtin modules
-                if func is getattr(module, func.__name__, None):
-                    break
-            else:
-                raise Exception, '%r not found in any built-in module' % (func,)
-            #if modname == '__builtin__':
-            #    # be lazy
-            #    return "(space.builtin.get(space.str_w(%s)))" % self.nameof(func.__name__)
-            if modname == 'sys':
-                # be lazy
-                return "(space.sys.get(space.str_w(%s)))" % self.nameof(func.__name__)                
-            else:
-                name = self.uniquename('gbltin_' + func.__name__)
-                self.initcode.append1('%s = space.getattr(%s, %s)' % (
-                    name, self.nameof(module), self.nameof(func.__name__)))
+            return self.nameof_builtin_function(func)
+        else:
+            return self.nameof_builtin_method(func)
+
+    def nameof_builtin_function(self, func):
+        # builtin function
+        if id(func) in self.builtin_ids:
+            func = self.builtin_ids[id(func)]
+            return "(space.builtin.get(space.str_w(%s)))" % self.nameof(func.__name__)
+        # where does it come from? Python2.2 doesn't have func.__module__
+        for modname, module in sys.modules.items():
+            if hasattr(module, '__file__'):
+                if (module.__file__.endswith('.py') or
+                    module.__file__.endswith('.pyc') or
+                    module.__file__.endswith('.pyo')):
+                    continue    # skip non-builtin modules
+            if func is getattr(module, func.__name__, None):
+                break
+        else:
+            raise Exception, '%r not found in any built-in module' % (func,)
+        #if modname == '__builtin__':
+        #    # be lazy
+        #    return "(space.builtin.get(space.str_w(%s)))" % self.nameof(func.__name__)
+        if modname == 'sys':
+            # be lazy
+            return "(space.sys.get(space.str_w(%s)))" % self.nameof(func.__name__)                
+        else:
+            name = self.uniquename('gbltin_' + func.__name__)
+            self.initcode.append1('%s = space.getattr(%s, %s)' % (
+                name, self.nameof(module), self.nameof(func.__name__)))
+        return name
+
+    def nameof_builtin_method(self, meth):
+        try:
+            im_self = meth.__self__
+        except AttributeError:
+            im_self = meth.im_self    # on top of PyPy
+        if im_self is None:
+            # builtin unbound method (only on top of PyPy)
+            name = self.nameof_wrapper_descriptor(meth)
         else:
             # builtin (bound) method
-            name = self.uniquename('gbltinmethod_' + func.__name__)
+            name = self.uniquename('gbltinmethod_' + meth.__name__)
             self.initcode.append1('%s = space.getattr(%s, %s)' % (
-                name, self.nameof(func.__self__), self.nameof(func.__name__)))
+                name, self.nameof(im_self), self.nameof(meth.__name__)))
         return name
 
     def nameof_classobj(self, cls):
@@ -921,10 +942,13 @@
     # strange prebuilt instances below, don't look too closely
     # XXX oh well.
     def nameof_member_descriptor(self, md):
+        try:
+            im_class = md.__objclass__
+        except AttributeError:
+            im_class = md.im_class    # on top of PyPy
         name = self.uniquename('gdescriptor_%s_%s' % (
-            md.__objclass__.__name__, md.__name__))
-        cls = self.nameof(md.__objclass__)
-        # do I need to take the dict and then getitem???
+            im_class.__name__, md.__name__))
+        cls = self.nameof(im_class)
         self.initcode.append1('%s = space.getattr(%s, %s)' %
                                 (name, cls, self.nameof(md.__name__)))
         return name



More information about the Pypy-commit mailing list