[pypy-svn] r35716 - in pypy/dist/pypy: rpython/lltypesystem/module rpython/module rpython/module/test rpython/ootypesystem/module translator/c

pedronis at codespeak.net pedronis at codespeak.net
Thu Dec 14 02:04:43 CET 2006


Author: pedronis
Date: Thu Dec 14 02:04:40 2006
New Revision: 35716

Modified:
   pypy/dist/pypy/rpython/lltypesystem/module/ll_strtod.py
   pypy/dist/pypy/rpython/module/ll_strtod.py
   pypy/dist/pypy/rpython/module/test/test_ll_strtod.py
   pypy/dist/pypy/rpython/ootypesystem/module/ll_strtod.py
   pypy/dist/pypy/translator/c/extfunc.py
Log:
preparation for float(string):

for consistency make parts_to_float a suggested primitive for oo backend too.



Modified: pypy/dist/pypy/rpython/lltypesystem/module/ll_strtod.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/module/ll_strtod.py	(original)
+++ pypy/dist/pypy/rpython/lltypesystem/module/ll_strtod.py	Thu Dec 14 02:04:40 2006
@@ -7,3 +7,11 @@
         return LLSupport.to_rstr(rarithmetic.formatd(LLSupport.from_rstr(fmt), x))
     ll_strtod_formatd.suggested_primitive = True
     ll_strtod_formatd = staticmethod(ll_strtod_formatd)
+
+    def ll_strtod_parts_to_float(sign, beforept, afterpt, exponent):
+        return rarithmetic.parts_to_float(LLSupport.from_rstr(sign),
+                                          LLSupport.from_rstr(beforept),
+                                          LLSupport.from_rstr(afterpt),
+                                          LLSupport.from_rstr(exponent))
+    ll_strtod_parts_to_float.suggested_primitive = True
+    ll_strtod_parts_to_float = staticmethod(ll_strtod_parts_to_float)

Modified: pypy/dist/pypy/rpython/module/ll_strtod.py
==============================================================================
--- pypy/dist/pypy/rpython/module/ll_strtod.py	(original)
+++ pypy/dist/pypy/rpython/module/ll_strtod.py	Thu Dec 14 02:04:40 2006
@@ -1,12 +1,3 @@
-# string -> float helper
-from pypy.rlib import rarithmetic
-from pypy.rpython.module.support import LLSupport, ll_strcpy
 
 
-def ll_strtod_parts_to_float(sign, beforept, afterpt, exponent):
-    return rarithmetic.parts_to_float(LLSupport.from_rstr(sign),
-                                      LLSupport.from_rstr(beforept),
-                                      LLSupport.from_rstr(afterpt),
-                                      LLSupport.from_rstr(exponent))
-ll_strtod_parts_to_float.suggested_primitive = True
 

Modified: pypy/dist/pypy/rpython/module/test/test_ll_strtod.py
==============================================================================
--- pypy/dist/pypy/rpython/module/test/test_ll_strtod.py	(original)
+++ pypy/dist/pypy/rpython/module/test/test_ll_strtod.py	Thu Dec 14 02:04:40 2006
@@ -1,23 +1,36 @@
+import py
 
-from pypy.rpython.module.ll_strtod import ll_strtod_parts_to_float
-from pypy.rpython.module.support import LLSupport
-from pypy.rpython.lltypesystem.module.ll_strtod import Implementation
-
-
-def test_parts_to_float():
-    data = [
-    (("","1","","")     , 1.0),
-    (("-","1","","")    , -1.0),
-    (("-","1","5","")   , -1.5),
-    (("-","1","5","2")  , -1.5e2),
-    (("-","1","5","+2") , -1.5e2),
-    (("-","1","5","-2") , -1.5e-2),
-    ]
-
-    for parts, val in data:
-        assert ll_strtod_parts_to_float(*map(LLSupport.to_rstr, parts)) == val
+class BaseTest(object):
     
+    def test_parts_to_float(self):
+        #py.test.skip("wip")
+        Support = self.Support
+        Impl = self.Implementation
+        
+        data = [
+        (("","1","","")     , 1.0),
+        (("-","1","","")    , -1.0),
+        (("-","1","5","")   , -1.5),
+        (("-","1","5","2")  , -1.5e2),
+        (("-","1","5","+2") , -1.5e2),
+        (("-","1","5","-2") , -1.5e-2),
+        ]
+
+        for parts, val in data:
+            assert Impl.ll_strtod_parts_to_float(*map(Support.to_rstr, parts)) == val
+
+
+    def test_formatd(self):
+        Support = self.Support
+        Impl = self.Implementation
+        
+        res = Impl.ll_strtod_formatd(Support.to_rstr("%.2f"), 1.5)
+        assert Support.from_rstr(res) == "1.50"
+
+class TestLL(BaseTest):
+    from pypy.rpython.module.support import LLSupport as Support
+    from pypy.rpython.lltypesystem.module.ll_strtod import Implementation
 
-def test_formatd():
-    res = Implementation.ll_strtod_formatd(LLSupport.to_rstr("%.2f"), 1.5)
-    assert LLSupport.from_rstr(res) == "1.50"
+class TestOO(BaseTest):
+    from pypy.rpython.module.support import OOSupport as Support
+    from pypy.rpython.ootypesystem.module.ll_strtod import Implementation

Modified: pypy/dist/pypy/rpython/ootypesystem/module/ll_strtod.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/module/ll_strtod.py	(original)
+++ pypy/dist/pypy/rpython/ootypesystem/module/ll_strtod.py	Thu Dec 14 02:04:40 2006
@@ -8,3 +8,11 @@
     def ll_strtod_formatd(cls, fmt, x):
         return cls.to_rstr(rarithmetic.formatd(cls.from_rstr(fmt), x))
     ll_strtod_formatd.suggested_primitive = True
+
+
+    def ll_strtod_parts_to_float(cls, sign, beforept, afterpt, exponent):
+        return rarithmetic.parts_to_float(cls.from_rstr(sign),
+                                          cls.from_rstr(beforept),
+                                          cls.from_rstr(afterpt),
+                                          cls.from_rstr(exponent))
+    ll_strtod_parts_to_float.suggested_primitive = True

Modified: pypy/dist/pypy/translator/c/extfunc.py
==============================================================================
--- pypy/dist/pypy/translator/c/extfunc.py	(original)
+++ pypy/dist/pypy/translator/c/extfunc.py	Thu Dec 14 02:04:40 2006
@@ -5,14 +5,14 @@
 from pypy.rpython.lltypesystem.rstr import STR, mallocstr
 from pypy.rpython.lltypesystem import rstr
 from pypy.rpython.lltypesystem import rlist
-from pypy.rpython.module import ll_time, ll_math, ll_strtod
+from pypy.rpython.module import ll_time, ll_math
 from pypy.rpython.module import ll_stackless, ll_stack
 from pypy.rpython.module.support import ll_execve
 from pypy.rpython.lltypesystem.module.ll_os import STAT_RESULT, PIPE_RESULT
 from pypy.rpython.lltypesystem.module.ll_os import WAITPID_RESULT
 from pypy.rpython.lltypesystem.module.ll_os import Implementation as impl
 from pypy.rpython.lltypesystem.module import ll_math as ll_math2
-from pypy.rpython.lltypesystem.module import ll_strtod as ll_strtod2
+from pypy.rpython.lltypesystem.module import ll_strtod
 from pypy.rlib import ros
 
 try:
@@ -74,9 +74,9 @@
     ll_math.ll_math_ldexp: 'LL_math_ldexp',
     ll_math2.Implementation.ll_math_modf.im_func:  'LL_math_modf',
     ll_math.ll_math_hypot: 'LL_math_hypot',
-    ll_strtod.ll_strtod_parts_to_float:
+    ll_strtod.Implementation.ll_strtod_parts_to_float:
         'LL_strtod_parts_to_float',
-    ll_strtod2.Implementation.ll_strtod_formatd:
+    ll_strtod.Implementation.ll_strtod_formatd:
         'LL_strtod_formatd',
     ll_stackless.ll_stackless_switch:             'LL_stackless_switch',
     ll_stackless.ll_stackless_stack_frames_depth: 'LL_stackless_stack_frames_depth',



More information about the Pypy-commit mailing list