[pypy-svn] r62588 - in pypy/branch/pyjitpl5/pypy/jit/backend/llgraph: . test

arigo at codespeak.net arigo at codespeak.net
Thu Mar 5 16:11:45 CET 2009


Author: arigo
Date: Thu Mar  5 16:11:43 2009
New Revision: 62588

Modified:
   pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/llimpl.py
   pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/runner.py
   pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/test/test_llgraph.py
Log:
Two more operations.


Modified: pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/llimpl.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/llimpl.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/llimpl.py	Thu Mar  5 16:11:43 2009
@@ -887,6 +887,14 @@
     array = array._obj.container
     return array.getlength()
 
+def do_strlen(string):
+    str = lltype.cast_opaque_ptr(lltype.Ptr(rstr.STR), string)
+    return len(str.chars)
+
+def do_strgetitem(string, index):
+    str = lltype.cast_opaque_ptr(lltype.Ptr(rstr.STR), string)
+    return ord(str.chars[index])
+
 # ____________________________________________________________
 
 
@@ -969,3 +977,5 @@
 setannotation(cast_int_to_adr, annmodel.SomeAddress())
 
 setannotation(do_arraylen_gc, annmodel.SomeInteger())
+setannotation(do_strlen, annmodel.SomeInteger())
+setannotation(do_strgetitem, annmodel.SomeInteger())

Modified: pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/runner.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/runner.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/runner.py	Thu Mar  5 16:11:43 2009
@@ -313,6 +313,15 @@
         array = args[0].getptr_base()
         return history.BoxInt(llimpl.do_arraylen_gc(array))
 
+    def do_strlen(cpu, args):
+        string = args[0].getptr_base()
+        return history.BoxInt(llimpl.do_strlen(string))
+
+    def do_strgetitem(cpu, args):
+        string = args[0].getptr_base()
+        index = args[1].getint()
+        return history.BoxInt(llimpl.do_strgetitem(string, index))
+
 
 class GuardFailed(object):
     returns = False

Modified: pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/test/test_llgraph.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/test/test_llgraph.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/test/test_llgraph.py	Thu Mar  5 16:11:43 2009
@@ -1,5 +1,5 @@
 import py
-from pypy.rpython.lltypesystem import lltype, llmemory
+from pypy.rpython.lltypesystem import lltype, llmemory, rstr
 from pypy.rpython.test.test_llinterp import interpret
 from pypy.rlib.unroll import unrolling_iterable
 
@@ -156,9 +156,20 @@
 
     def test_do_operations(self):
         cpu = CPU(None)
+        #
         A = lltype.GcArray(lltype.Signed)
         a = lltype.malloc(A, 5)
         descrbox = ConstInt(cpu.arraydescrof(A))
         x = cpu.do_arraylen_gc(
             [BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, a)), descrbox])
         assert x.value == 5
+        #
+        s = rstr.mallocstr(6)
+        x = cpu.do_strlen(
+            [BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, s))])
+        assert x.value == 6
+        #
+        s.chars[3] = 'X'
+        x = cpu.do_strgetitem(
+            [BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, s)), BoxInt(3)])
+        assert x.value == ord('X')



More information about the Pypy-commit mailing list