[pypy-svn] r16075 - in pypy/dist/pypy: module/__builtin__ translator

tismer at codespeak.net tismer at codespeak.net
Mon Aug 15 02:46:37 CEST 2005


Author: tismer
Date: Mon Aug 15 02:46:34 2005
New Revision: 16075

Modified:
   pypy/dist/pypy/module/__builtin__/app_complex.py
   pypy/dist/pypy/module/__builtin__/app_functional.py
   pypy/dist/pypy/translator/geninterplevel.py
Log:
modified gheninterplevel to support properties.
With a little hack of storing the property arguments
in the __doc__. Don't hesitate to give better proposals.
See app_complex how it worked.

App_complex is now enabled for interplevel.

app_functional could have been, but I get SomeObject--ness
in argument.fromshape. Something is not ok here.
I left it disabled, but kept the comments.

Modified: pypy/dist/pypy/module/__builtin__/app_complex.py
==============================================================================
--- pypy/dist/pypy/module/__builtin__/app_complex.py	(original)
+++ pypy/dist/pypy/module/__builtin__/app_complex.py	Mon Aug 15 02:46:34 2005
@@ -1,11 +1,13 @@
-# NOT_RPYTHON yet
 """
 Plain Python definition of the 'complex' type.
 """
 
 
 #XXX Hack: This float is supposed to overflow to inf
-OVERFLOWED_FLOAT = float("1e10000000000000000000000000000000")
+#OVERFLOWED_FLOAT = float("1e10000000000000000000000000000000")
+# but this would crash with marshal v.1.0
+OVERFLOWED_FLOAT = 1e200
+OVERFLOWED_FLOAT *= OVERFLOWED_FLOAT
 
 class complex(object):
     """complex(real[, imag]) -> complex number
@@ -376,5 +378,6 @@
 imag_slot = complex.imag
 
 # make the slots read-only
-complex.real = property(real_slot.__get__)
-complex.imag = property(imag_slot.__get__)
+# XXX added doc string as helper for geninterplevel (any other idea?)
+complex.real = property(real_slot.__get__, None, None, 'complex.real.__get__')
+complex.imag = property(imag_slot.__get__, None, None, 'complex.imag.__get__')

Modified: pypy/dist/pypy/module/__builtin__/app_functional.py
==============================================================================
--- pypy/dist/pypy/module/__builtin__/app_functional.py	(original)
+++ pypy/dist/pypy/module/__builtin__/app_functional.py	Mon Aug 15 02:46:34 2005
@@ -1,4 +1,5 @@
-# NOT_RPYTHON because yield is used
+# NOT_RPYTHON because it triggers an annotator error in fromshape
+# otherwise it could be geninterped.
 """
 Plain Python definition of the builtin functions oriented towards
 functional programming.
@@ -83,7 +84,7 @@
                 if not isinstance(c, str_type):
                     raise TypeError("can't filter %s to %s: __getitem__ returned different type", str_type.__name__, str_type.__name__)
                 res.append(c)
-        return str_type().join(res)
+        return str_type('').join(res) #added '' to make the annotator happy
         
     if function is None:
         res = [item for item in collection if item]

Modified: pypy/dist/pypy/translator/geninterplevel.py
==============================================================================
--- pypy/dist/pypy/translator/geninterplevel.py	(original)
+++ pypy/dist/pypy/translator/geninterplevel.py	Mon Aug 15 02:46:34 2005
@@ -77,7 +77,7 @@
 import pypy # __path__
 import py.path
 
-GI_VERSION = '1.1.12'  # bump this for substantial changes
+GI_VERSION = '1.1.13'  # bump this for substantial changes
 # ____________________________________________________________
 
 try:
@@ -528,7 +528,13 @@
         name = (name.replace('-', 'minus')
                     .replace('.', 'dot'))
         name = self.uniquename(name)
-        self.initcode.append1('%s = space.wrap(%r)' % (name, value))
+        # handle overflows
+        if value != 0.0 and 2*value == value:
+            self.initcode.append1('float_inf = 1e200\nfloat_inf *= float_inf')
+            sign = '-+'[value >= 0]
+            self.initcode.append('%s = space.wrap(%sfloat_inf)' % (name, sign))
+        else:
+            self.initcode.append('%s = space.wrap(%r)' % (name, value))
         return name
     
     def nameof_str(self, value):
@@ -842,7 +848,6 @@
         types.ClassType: 'space.w_classobj',
         types.MethodType: (eval_helper, "instancemethod",
             "type((lambda:42).__get__(42))"),
-        property: (eval_helper, "property", 'property'),
         type(Ellipsis): (eval_helper, 'EllipsisType', 'types.EllipsisType'),
         builtin_set: (eval_helper, "set", "set"),
         builtin_frozenset: (eval_helper, "frozenset", "frozenset"),
@@ -912,6 +917,23 @@
     nameof_method_descriptor  = nameof_member_descriptor
     nameof_wrapper_descriptor = nameof_member_descriptor
 
+    def nameof_property(self, prop):
+        origin = prop.__doc__ # XXX quite a hack
+        name = self.uniquename('gprop_' + origin)
+        if not origin:
+            raise ValueError("sorry, cannot build properties"
+                             " without a helper in __doc__")
+        # property is lazy loaded app-level as well, trigger it*s creation
+        self.initcode.append1('space.builtin.get("property") # pull it in')
+        globname = self.nameof(self.moddict)
+        self.initcode.append('space.setitem(%s, space.wrap("__builtins__"), '
+                             'space.builtin.w_dict)' % globname)
+        self.initcode.append('%s = space.eval("property(%s)", %s, %s)' %(
+            name, origin, globname, globname) )
+        self.initcode.append('space.delitem(%s, space.wrap("__builtins__"))'
+                             % globname)
+        return name
+
     def nameof_file(self, fil):
         if fil is sys.stdin:
             return 'space.sys.get("stdin")'
@@ -1294,9 +1316,10 @@
                     q = "elif"
                 link = exits[-1]
                 yield "else:"
-                yield "    assert %s == %s" % (self.expr(block.exitswitch,
-                                                    localscope),
-                                                    link.exitcase)
+                # debug only, creates lots of fluffy C code
+                ##yield "    assert %s == %s" % (self.expr(block.exitswitch,
+                ##                                    localscope),
+                ##                                    link.exitcase)
                 for op in self.gen_link(exits[-1], localscope, blocknum, block):
                     yield "    %s" % op
 



More information about the Pypy-commit mailing list