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

mwh at codespeak.net mwh at codespeak.net
Sun Jun 26 11:19:24 CEST 2005


Author: mwh
Date: Sun Jun 26 11:19:22 2005
New Revision: 13916

Modified:
   pypy/dist/pypy/rpython/rint.py
   pypy/dist/pypy/rpython/rstr.py
   pypy/dist/pypy/translator/c/test/test_typed.py
Log:
small tweaks so codes that uses string formatting and converts ints to strings
translates to code that actually compiles.

with these changes, demo/bpnn.py on my machine compiles and runs (woohoo! --
although demo/bpnn.py on my machine is a bit hacked and in particular doesn't
have any print statements in it any more).

there is something "a bit odd" in the area of integer division, int_div operations
get emitted sometimes, which there is no backend support for.  I'll pester arigo &
pedronis about this when they wake up :)


Modified: pypy/dist/pypy/rpython/rint.py
==============================================================================
--- pypy/dist/pypy/rpython/rint.py	(original)
+++ pypy/dist/pypy/rpython/rint.py	Sun Jun 26 11:19:22 2005
@@ -303,7 +303,7 @@
     else:
         while i:
             temp[len] = chr(i%10+ord('0'))
-            i /= 10
+            i //= 10
             len += 1
     len += sign
     result = malloc(STR, len)
@@ -336,7 +336,7 @@
     else:
         while i:
             temp[len] = hex_chars[i%16]
-            i /= 16
+            i //= 16
             len += 1
     len += sign
     if addPrefix:

Modified: pypy/dist/pypy/rpython/rstr.py
==============================================================================
--- pypy/dist/pypy/rpython/rstr.py	(original)
+++ pypy/dist/pypy/rpython/rstr.py	Sun Jun 26 11:19:22 2005
@@ -218,7 +218,7 @@
     assert s_str.is_constant()
     s = s_str.const
     things = parse_fmt_string(s)
-    size = inputconst(Void, len(things))
+    size = inputconst(Signed, len(things)) # could be unsigned?
     TEMP = GcArray(Ptr(STR))
     cTEMP = inputconst(Void, TEMP)
     vtemp = hop.genop("malloc_varsize", [cTEMP, size],

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 11:19:22 2005
@@ -281,3 +281,16 @@
             return exp(f)
         f = self.getcompiled(fn)
         assert f(1.0) == exp(1.0)
+
+    def test_stringformatting(self):
+        def fn(i=int):
+            return "you said %d, you did"%i
+        f = self.getcompiled(fn)
+        assert f(1) == fn(1)
+
+    def test_str2int(self):
+        def fn(i=int):
+            return str(i)
+        f = self.getcompiled(fn)
+        assert f(1) == fn(1)
+        



More information about the Pypy-commit mailing list