[pypy-svn] r77324 - in pypy/branch/jit-str/pypy: jit/codewriter jit/codewriter/test rpython/lltypesystem

arigo at codespeak.net arigo at codespeak.net
Fri Sep 24 09:54:03 CEST 2010


Author: arigo
Date: Fri Sep 24 09:54:01 2010
New Revision: 77324

Modified:
   pypy/branch/jit-str/pypy/jit/codewriter/effectinfo.py
   pypy/branch/jit-str/pypy/jit/codewriter/jtransform.py
   pypy/branch/jit-str/pypy/jit/codewriter/test/test_jtransform.py
   pypy/branch/jit-str/pypy/rpython/lltypesystem/rstr.py
Log:
Simplify the OS_STR_SLICE_xyz specs; we can keep only one, the most
general version.


Modified: pypy/branch/jit-str/pypy/jit/codewriter/effectinfo.py
==============================================================================
--- pypy/branch/jit-str/pypy/jit/codewriter/effectinfo.py	(original)
+++ pypy/branch/jit-str/pypy/jit/codewriter/effectinfo.py	Fri Sep 24 09:54:01 2010
@@ -19,13 +19,9 @@
     OS_NONE                     = 0    # normal case, no oopspec
     OS_ARRAYCOPY                = 1    # "list.ll_arraycopy"
     OS_STR_CONCAT               = 2    # "stroruni.concat"
-    OS_STR_SLICE_STARTONLY      = 3    # "stroruni.slice_startonly"
-    OS_STR_SLICE_STARTSTOP      = 4    # "stroruni.slice_startstop"
-    OS_STR_SLICE_MINUSONE       = 5    # "stroruni.slice_minusone"
-    OS_UNI_CONCAT               = 82   # "stroruni.concat" (+80)
-    OS_UNI_SLICE_STARTONLY      = 83   # "stroruni.slice_startonly" (+80)
-    OS_UNI_SLICE_STARTSTOP      = 84   # "stroruni.slice_startstop" (+80)
-    OS_UNI_SLICE_MINUSONE       = 85   # "stroruni.slice_minusone" (+80)
+    OS_STR_SLICE                = 3    # "stroruni.slice"
+    OS_UNI_CONCAT               = 4    # "stroruni.concat"
+    OS_UNI_SLICE                = 5    # "stroruni.slice"
 
     def __new__(cls, readonly_descrs_fields,
                 write_descrs_fields, write_descrs_arrays,

Modified: pypy/branch/jit-str/pypy/jit/codewriter/jtransform.py
==============================================================================
--- pypy/branch/jit-str/pypy/jit/codewriter/jtransform.py	(original)
+++ pypy/branch/jit-str/pypy/jit/codewriter/jtransform.py	Fri Sep 24 09:54:01 2010
@@ -1043,18 +1043,15 @@
         return op1
 
     def _handle_stroruni_call(self, op, oopspec_name, args):
-        dict = {"stroruni.concat":          EffectInfo.OS_STR_CONCAT,
-                "stroruni.slice_startonly": EffectInfo.OS_STR_SLICE_STARTONLY,
-                "stroruni.slice_startstop": EffectInfo.OS_STR_SLICE_STARTSTOP,
-                "stroruni.slice_minusone":  EffectInfo.OS_STR_SLICE_MINUSONE}
-        base = dict[oopspec_name]
         if args[0].concretetype.TO == rstr.STR:
-            offset = 0
+            dict = {"stroruni.concat": EffectInfo.OS_STR_CONCAT,
+                    "stroruni.slice":  EffectInfo.OS_STR_SLICE}
         elif args[0].concretetype.TO == rstr.UNICODE:
-            offset = 80
+            dict = {"stroruni.concat": EffectInfo.OS_UNI_CONCAT,
+                    "stroruni.slice":  EffectInfo.OS_UNI_SLICE}
         else:
             assert 0, "args[0].concretetype must be STR or UNICODE"
-        return self._handle_oopspec_call(op, args, base + offset)
+        return self._handle_oopspec_call(op, args, dict[oopspec_name])
 
     # ----------
     # VirtualRefs.

Modified: pypy/branch/jit-str/pypy/jit/codewriter/test/test_jtransform.py
==============================================================================
--- pypy/branch/jit-str/pypy/jit/codewriter/test/test_jtransform.py	(original)
+++ pypy/branch/jit-str/pypy/jit/codewriter/test/test_jtransform.py	Fri Sep 24 09:54:01 2010
@@ -724,67 +724,48 @@
     assert got[0] == op1.args[1]    # the calldescr
     assert heaptracker.int2adr(got[1]) == llmemory.cast_ptr_to_adr(func)
 
-def test_str_stringslice_startonly():
+def test_str_slice():
     # test that the oopspec is present and correctly transformed
     PSTR = lltype.Ptr(rstr.STR)
     INT = lltype.Signed
-    FUNC = lltype.FuncType([PSTR, INT], PSTR)
-    func = lltype.functionptr(FUNC, 'll_stringslice_startonly',
-                             _callable=rstr.LLHelpers.ll_stringslice_startonly)
+    FUNC = lltype.FuncType([PSTR, INT, INT], PSTR)
+    func = lltype.functionptr(FUNC, '_ll_stringslice',
+                            _callable=rstr.LLHelpers._ll_stringslice)
     v1 = varoftype(PSTR)
     v2 = varoftype(INT)
-    v3 = varoftype(PSTR)
-    op = SpaceOperation('direct_call', [const(func), v1, v2], v3)
+    v3 = varoftype(INT)
+    v4 = varoftype(PSTR)
+    op = SpaceOperation('direct_call', [const(func), v1, v2, v3], v4)
     tr = Transformer(FakeCPU(), FakeBuiltinCallControl())
     op1 = tr.rewrite_operation(op)
     assert op1.opname == 'residual_call_ir_r'
     assert op1.args[0].value == func
-    assert op1.args[1] == 'calldescr-%d' % (
-        effectinfo.EffectInfo.OS_STR_SLICE_STARTONLY)
-    assert op1.args[2] == ListOfKind('int', [v2])
+    assert op1.args[1] == 'calldescr-%d' % effectinfo.EffectInfo.OS_STR_SLICE
+    assert op1.args[2] == ListOfKind('int', [v2, v3])
     assert op1.args[3] == ListOfKind('ref', [v1])
-    assert op1.result == v3
+    assert op1.result == v4
 
-def test_str_stringslice_startstop():
+def test_unicode_slice():
     # test that the oopspec is present and correctly transformed
-    PSTR = lltype.Ptr(rstr.STR)
+    PUNICODE = lltype.Ptr(rstr.UNICODE)
     INT = lltype.Signed
-    FUNC = lltype.FuncType([PSTR, INT, INT], PSTR)
-    func = lltype.functionptr(FUNC, '_ll_stringslice_startstop',
-                            _callable=rstr.LLHelpers._ll_stringslice_startstop)
-    v1 = varoftype(PSTR)
+    FUNC = lltype.FuncType([PUNICODE, INT, INT], PUNICODE)
+    func = lltype.functionptr(FUNC, '_ll_stringslice',
+                            _callable=rstr.LLHelpers._ll_stringslice)
+    v1 = varoftype(PUNICODE)
     v2 = varoftype(INT)
     v3 = varoftype(INT)
-    v4 = varoftype(PSTR)
+    v4 = varoftype(PUNICODE)
     op = SpaceOperation('direct_call', [const(func), v1, v2, v3], v4)
     tr = Transformer(FakeCPU(), FakeBuiltinCallControl())
     op1 = tr.rewrite_operation(op)
     assert op1.opname == 'residual_call_ir_r'
     assert op1.args[0].value == func
-    assert op1.args[1] == 'calldescr-%d' % (
-        effectinfo.EffectInfo.OS_STR_SLICE_STARTSTOP)
+    assert op1.args[1] == 'calldescr-%d' % effectinfo.EffectInfo.OS_UNI_SLICE
     assert op1.args[2] == ListOfKind('int', [v2, v3])
     assert op1.args[3] == ListOfKind('ref', [v1])
     assert op1.result == v4
 
-def test_str_stringslice_minusone():
-    # test that the oopspec is present and correctly transformed
-    PSTR = lltype.Ptr(rstr.STR)
-    FUNC = lltype.FuncType([PSTR], PSTR)
-    func = lltype.functionptr(FUNC, 'll_stringslice_minusone',
-                              _callable=rstr.LLHelpers.ll_stringslice_minusone)
-    v1 = varoftype(PSTR)
-    v2 = varoftype(PSTR)
-    op = SpaceOperation('direct_call', [const(func), v1], v2)
-    tr = Transformer(FakeCPU(), FakeBuiltinCallControl())
-    op1 = tr.rewrite_operation(op)
-    assert op1.opname == 'residual_call_r_r'
-    assert op1.args[0].value == func
-    assert op1.args[1] == 'calldescr-%d' % (
-        effectinfo.EffectInfo.OS_STR_SLICE_MINUSONE)
-    assert op1.args[2] == ListOfKind('ref', [v1])
-    assert op1.result == v2
-
 def test_list_ll_arraycopy():
     from pypy.rlib.rgc import ll_arraycopy
     LIST = lltype.GcArray(lltype.Signed)

Modified: pypy/branch/jit-str/pypy/rpython/lltypesystem/rstr.py
==============================================================================
--- pypy/branch/jit-str/pypy/rpython/lltypesystem/rstr.py	(original)
+++ pypy/branch/jit-str/pypy/rpython/lltypesystem/rstr.py	Fri Sep 24 09:54:01 2010
@@ -693,25 +693,25 @@
             i += 1
         return result
 
+    def _ll_stringslice(s1, start, stop):
+        newstr = s1.malloc(stop - start)
+        assert start >= 0
+        lgt = stop - start
+        assert lgt >= 0
+        s1.copy_contents(s1, newstr, start, 0, lgt)
+        return newstr
+    _ll_stringslice.oopspec = 'stroruni.slice(s1, start, stop)'
+
     def ll_stringslice_startonly(s1, start):
         len1 = len(s1.chars)
+        if we_are_jitted():
+            return LLHelpers._ll_stringslice(s1, start, len1)
         newstr = s1.malloc(len1 - start)
         lgt = len1 - start
         assert lgt >= 0
         assert start >= 0
         s1.copy_contents(s1, newstr, start, 0, lgt)
         return newstr
-    ll_stringslice_startonly.oopspec = 'stroruni.slice_startonly(s1, start)'
-
-    def _ll_stringslice_startstop(s1, start, stop):
-        newstr = s1.malloc(stop - start)
-        assert start >= 0
-        lgt = stop - start
-        assert lgt >= 0
-        s1.copy_contents(s1, newstr, start, 0, lgt)
-        return newstr
-    _ll_stringslice_startstop.oopspec = ('stroruni.slice_startstop(s1, '
-                                             'start, stop)')
 
     def ll_stringslice_startstop(s1, start, stop):
         if we_are_jitted():
@@ -722,15 +722,16 @@
                 if start == 0:
                     return s1
                 stop = len(s1.chars)
-        return LLHelpers._ll_stringslice_startstop(s1, start, stop)
+        return LLHelpers._ll_stringslice(s1, start, stop)
 
     def ll_stringslice_minusone(s1):
         newlen = len(s1.chars) - 1
+        if we_are_jitted():
+            return LLHelpers._ll_stringslice(s1, 0, newlen)
         newstr = s1.malloc(newlen)
         assert newlen >= 0
         s1.copy_contents(s1, newstr, 0, 0, newlen)
         return newstr
-    ll_stringslice_minusone.oopspec = 'stroruni.slice_minusone(s1)'
 
     def ll_split_chr(LIST, s, c):
         chars = s.chars



More information about the Pypy-commit mailing list