[pypy-svn] r13946 - in pypy/dist/pypy: annotation rpython translator/c/test

mwh at codespeak.net mwh at codespeak.net
Sun Jun 26 15:06:47 CEST 2005


Author: mwh
Date: Sun Jun 26 15:06:44 2005
New Revision: 13946

Modified:
   pypy/dist/pypy/annotation/model.py
   pypy/dist/pypy/rpython/lltype.py
   pypy/dist/pypy/rpython/rfloat.py
   pypy/dist/pypy/translator/c/test/test_typed.py
Log:
c-ish cheating float str, fixes to annotation, lltype to allow calling
external pointer in ll helpers. test.
 


Modified: pypy/dist/pypy/annotation/model.py
==============================================================================
--- pypy/dist/pypy/annotation/model.py	(original)
+++ pypy/dist/pypy/annotation/model.py	Sun Jun 26 15:06:44 2005
@@ -429,7 +429,10 @@
 
 def ll_to_annotation(v):
     if v is None:
-        raise ValueError, "cannot retrieve Void low-level type value"
+        # i think we can only get here in the case of void-returning
+        # functions
+        from bookkeeper import getbookkeeper
+        return getbookkeeper().immutablevalue(None)
     return lltype_to_annotation(lltype.typeOf(v))
 
 # ____________________________________________________________

Modified: pypy/dist/pypy/rpython/lltype.py
==============================================================================
--- pypy/dist/pypy/rpython/lltype.py	(original)
+++ pypy/dist/pypy/rpython/lltype.py	Sun Jun 26 15:06:44 2005
@@ -237,7 +237,7 @@
 
     def _container_example(self):
         def ex(*args):
-            return self.RESULT._example()
+            return self.RESULT._defl()
         return _func(self, _callable=ex)
 
 class OpaqueType(ContainerType):

Modified: pypy/dist/pypy/rpython/rfloat.py
==============================================================================
--- pypy/dist/pypy/rpython/rfloat.py	(original)
+++ pypy/dist/pypy/rpython/rfloat.py	Sun Jun 26 15:06:44 2005
@@ -1,10 +1,12 @@
 from pypy.annotation.pairtype import pairtype
 from pypy.annotation import model as annmodel
-from pypy.rpython.lltype import Signed, Unsigned, Bool, Float, Void
+from pypy.rpython.lltype import Signed, Unsigned, Bool, Float, Void, Ptr
 from pypy.rpython.rmodel import Repr, TyperError, FloatRepr
 from pypy.rpython.rmodel import IntegerRepr, BoolRepr
 from pypy.rpython.robject import PyObjRepr, pyobj_repr
-
+from pypy.rpython.lltype import PyObject, Array, Char
+from pypy.rpython.rstr import STR
+from pypy.rpython.lltype import functionptr, FuncType, malloc
 
 debug = False
 
@@ -121,6 +123,34 @@
 
     rtype_float = rtype_pos
 
+    def ll_str(f, repr):
+        pyfloat = pyfloat_fromdouble_ptr(f)
+        pystring = pyobject_str_ptr(pyfloat)
+        stringsize = pystring_size_ptr(pystring)
+
+        ret = malloc(STR, stringsize)
+
+        tollchararray_ptr(pystring, ret.chars)
+
+        return ret
+        
+    ll_str = staticmethod(ll_str)
+
+PyObjectPtr = Ptr(PyObject)
+
+pystring_size_ptr = functionptr(FuncType([PyObjectPtr], Signed),
+                                "PyString_Size",
+                                external="C")
+pyfloat_fromdouble_ptr = functionptr(FuncType([Float], PyObjectPtr),
+                                     "PyFloat_FromDouble",
+                                     external="C")
+pyobject_str_ptr = functionptr(FuncType([PyObjectPtr], PyObjectPtr),
+                               "PyObject_Str",
+                               external="C")
+tollchararray_ptr = functionptr(FuncType([PyObjectPtr, Ptr(Array(Char))], Void),
+                                "PyString_ToLLCharArray",
+                                external="C")
+    
 #
 # _________________________ Conversions _________________________
 

Modified: pypy/dist/pypy/translator/c/test/test_typed.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_typed.py	(original)
+++ pypy/dist/pypy/translator/c/test/test_typed.py	Sun Jun 26 15:06:44 2005
@@ -293,4 +293,10 @@
             return str(i)
         f = self.getcompiled(fn)
         assert f(1) == fn(1)
+
+    def test_float2int(self):
+        def fn(i=float):
+            return str(i)
+        f = self.getcompiled(fn)
+        assert f(1.0) == fn(1.0)
         



More information about the Pypy-commit mailing list