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

arigo at codespeak.net arigo at codespeak.net
Thu Mar 5 16:39:42 CET 2009


Author: arigo
Date: Thu Mar  5 16:39:40 2009
New Revision: 62590

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:
getfield_gc.


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:39:40 2009
@@ -910,6 +910,18 @@
     array = array._obj.container
     return cast_to_ptr(array.getitem(index))
 
+def do_getfield_gc_int(struct, fielddesc, memocast):
+    STRUCT, fieldname = symbolic.TokenToField[fielddesc/2]
+    ptr = lltype.cast_opaque_ptr(lltype.Ptr(STRUCT), struct)
+    x = getattr(ptr, fieldname)
+    return cast_to_int(x, memocast)
+
+def do_getfield_gc_ptr(struct, fielddesc):
+    STRUCT, fieldname = symbolic.TokenToField[fielddesc/2]
+    ptr = lltype.cast_opaque_ptr(lltype.Ptr(STRUCT), struct)
+    x = getattr(ptr, fieldname)
+    return cast_to_ptr(x)
+
 # ____________________________________________________________
 
 
@@ -996,3 +1008,5 @@
 setannotation(do_strgetitem, annmodel.SomeInteger())
 setannotation(do_getarrayitem_gc_int, annmodel.SomeInteger())
 setannotation(do_getarrayitem_gc_ptr, annmodel.SomePtr(llmemory.GCREF))
+setannotation(do_getfield_gc_int, annmodel.SomeInteger())
+setannotation(do_getfield_gc_ptr, annmodel.SomePtr(llmemory.GCREF))

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:39:40 2009
@@ -332,6 +332,17 @@
             return history.BoxInt(llimpl.do_getarrayitem_gc_int(array, index,
                                                                self.memo_cast))
 
+    def do_getfield_gc(self, args):
+        struct = args[0].getptr_base()
+        fielddescr = args[1].getint()
+        if self.typefor(fielddescr) == 'ptr':
+            return history.BoxPtr(llimpl.do_getfield_gc_ptr(struct,
+                                                            fielddescr))
+        else:
+            return history.BoxInt(llimpl.do_getfield_gc_int(struct,
+                                                            fielddescr,
+                                                            self.memo_cast))
+
 
 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:39:40 2009
@@ -177,6 +177,7 @@
         x = cpu.do_getarrayitem_gc(
             [BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, b)), descrbox_B,
              BoxInt(3)])
+        assert isinstance(x, BoxPtr)
         assert x.getptr(lltype.Ptr(A)) == a
         #
         s = rstr.mallocstr(6)
@@ -188,3 +189,20 @@
         x = cpu.do_strgetitem(
             [BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, s)), BoxInt(3)])
         assert x.value == ord('X')
+        #
+        S = lltype.GcStruct('S', ('x', lltype.Char), ('y', lltype.Ptr(A)))
+        descrfld_x = cpu.fielddescrof(S, 'x')
+        s = lltype.malloc(S)
+        s.x = 'Z'
+        x = cpu.do_getfield_gc(
+            [BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, s)),
+             BoxInt(descrfld_x)])
+        assert x.value == ord('Z')
+        #
+        descrfld_y = cpu.fielddescrof(S, 'y')
+        s.y = a
+        x = cpu.do_getfield_gc(
+            [BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, s)),
+             BoxInt(descrfld_y)])
+        assert isinstance(x, BoxPtr)
+        assert x.getptr(lltype.Ptr(A)) == a



More information about the Pypy-commit mailing list