[pypy-svn] r74463 - in pypy/branch/blackhole-improvement/pypy/jit/codewriter: . test

arigo at codespeak.net arigo at codespeak.net
Mon May 10 14:57:30 CEST 2010


Author: arigo
Date: Mon May 10 14:57:28 2010
New Revision: 74463

Modified:
   pypy/branch/blackhole-improvement/pypy/jit/codewriter/jtransform.py
   pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_jtransform.py
Log:
getinteriorarraysize.


Modified: pypy/branch/blackhole-improvement/pypy/jit/codewriter/jtransform.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/codewriter/jtransform.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/jtransform.py	Mon May 10 14:57:28 2010
@@ -430,6 +430,18 @@
             sizedescr = self.cpu.sizeof(STRUCT)
             return SpaceOperation('new', [sizedescr], op.result)
 
+    def rewrite_op_getinteriorarraysize(self, op):
+        # only supports strings and unicodes
+        assert len(op.args) == 2
+        assert op.args[1].value == 'chars'
+        optype = op.args[0].concretetype
+        if optype == lltype.Ptr(rstr.STR):
+            opname = "strlen"
+        else:
+            assert optype == lltype.Ptr(rstr.UNICODE)
+            opname = "unicodelen"
+        return SpaceOperation(opname, [op.args[0]], op.result)
+
     def rewrite_op_getinteriorfield(self, op):
         # only supports strings and unicodes
         assert len(op.args) == 3

Modified: pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_jtransform.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_jtransform.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_jtransform.py	Mon May 10 14:57:28 2010
@@ -405,6 +405,28 @@
     assert op1.opname == 'int_is_true'
     assert op1.args == [v1]
 
+def test_str_getinteriorarraysize():
+    v = varoftype(lltype.Ptr(rstr.STR))
+    v_result = varoftype(lltype.Signed)
+    op = SpaceOperation('getinteriorarraysize',
+                        [v, Constant('chars', lltype.Void)],
+                        v_result)
+    op1 = Transformer().rewrite_operation(op)
+    assert op1.opname == 'strlen'
+    assert op1.args == [v]
+    assert op1.result == v_result
+
+def test_unicode_getinteriorarraysize():
+    v = varoftype(lltype.Ptr(rstr.UNICODE))
+    v_result = varoftype(lltype.Signed)
+    op = SpaceOperation('getinteriorarraysize',
+                        [v, Constant('chars', lltype.Void)],
+                        v_result)
+    op1 = Transformer().rewrite_operation(op)
+    assert op1.opname == 'unicodelen'
+    assert op1.args == [v]
+    assert op1.result == v_result
+
 def test_str_getinteriorfield():
     v = varoftype(lltype.Ptr(rstr.STR))
     v_index = varoftype(lltype.Signed)



More information about the Pypy-commit mailing list