[pypy-svn] r13944 - in pypy/dist/pypy/rpython: . test

tismer at codespeak.net tismer at codespeak.net
Sun Jun 26 14:54:20 CEST 2005


Author: tismer
Date: Sun Jun 26 14:54:19 2005
New Revision: 13944

Modified:
   pypy/dist/pypy/rpython/rstr.py
   pypy/dist/pypy/rpython/test/test_rstr.py
Log:
implemented char_mul

Modified: pypy/dist/pypy/rpython/rstr.py
==============================================================================
--- pypy/dist/pypy/rpython/rstr.py	(original)
+++ pypy/dist/pypy/rpython/rstr.py	Sun Jun 26 14:54:19 2005
@@ -307,7 +307,13 @@
 
     def rtype_method_isspace(_, hop):
         vlist = hop.inputargs(char_repr)
-        return hop.llops.gendirectcall(ll_char_isspace, vlist[0]) 
+        return hop.gendirectcall(ll_char_isspace, vlist[0])
+
+class __extend__(pairtype(CharRepr, IntegerRepr)):
+    
+    def rtype_mul(_, hop):
+        v_char, v_int = hop.inputargs(char_repr, Signed)
+        return hop.gendirectcall(ll_char_mul, v_char, v_int)
 
 class __extend__(pairtype(CharRepr, CharRepr)):
     def rtype_eq(_, hop): return _rtype_compare_template(hop, 'eq')
@@ -412,6 +418,14 @@
     c = ord(ch) 
     return 9 <= c <= 13 or c == 32 
 
+def ll_char_mul(ch, times):
+    newstr = malloc(STR, times)
+    j = 0
+    while j < times:
+        newstr.chars[j] = ch
+        j += 1
+    return newstr
+
 def ll_strlen(s):
     return len(s.chars)
 

Modified: pypy/dist/pypy/rpython/test/test_rstr.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rstr.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rstr.py	Sun Jun 26 14:54:19 2005
@@ -90,6 +90,16 @@
     res = interpret(lambda c1, c2: c1 <= c2,  ['z', 'a'])
     assert res is False
 
+def test_char_mul():
+    def fn(c, mul):
+        s = c * mul
+        res = 0
+        for i in range(len(s)):
+            res = res*10 + ord(s[i]) - ord('0')
+        return res
+    res = interpret(fn, ['3', 5])
+    assert res == 33333
+
 def test_str_compare():
     def fn(i, j):
         s1 = ['one', 'two']



More information about the Pypy-commit mailing list